Skip to content

Commit

Permalink
improve storage of form settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippImhof committed Nov 11, 2024
1 parent 3f5ea70 commit e4a4ac7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
8 changes: 4 additions & 4 deletions essaydownload_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ protected function standard_preference_fields(MoodleQuickForm $mform) {
* @return void
*/
protected function pdf_layout_fields(MoodleQuickForm $mform) {
$mform->addElement('select', 'page', get_string('page', 'quiz_essaydownload'), [
$mform->addElement('select', 'pageformat', get_string('page', 'quiz_essaydownload'), [
'a4' => get_string('pagea4', 'quiz_essaydownload'),
'letter' => get_string('pageletter', 'quiz_essaydownload'),
]);
$mform->setType('page', PARAM_ALPHA);
$mform->setDefault('page', 'a4');
$mform->disabledIf('page', 'fileformat', 'neq', 'pdf');
$mform->setType('pageformat', PARAM_ALPHANUM);
$mform->setDefault('pageformat', 'a4');
$mform->disabledIf('pageformat', 'fileformat', 'neq', 'pdf');

$margingroup = [];
$margingroup[] = $mform->createElement('text', 'marginleft', '', ['size' => 3]);
Expand Down
28 changes: 17 additions & 11 deletions essaydownload_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,29 @@ public function setup_from_user_preferences() {
public function update_user_preferences() {
set_user_preference('quiz_essaydownload_attachments', $this->attachments);
set_user_preference('quiz_essaydownload_fileformat', $this->fileformat);
set_user_preference('quiz_essaydownload_fixremfontsize', $this->fixremfontsize);
set_user_preference('quiz_essaydownload_flatarchive', $this->flatarchive);
set_user_preference('quiz_essaydownload_font', $this->font);
set_user_preference('quiz_essaydownload_fontsize', $this->fontsize);
set_user_preference('quiz_essaydownload_groupby', $this->groupby);
set_user_preference('quiz_essaydownload_includefooter', $this->includefooter);
set_user_preference('quiz_essaydownload_includestats', $this->includestats);
set_user_preference('quiz_essaydownload_linespacing', $this->linespacing);
set_user_preference('quiz_essaydownload_marginbottom', $this->marginbottom);
set_user_preference('quiz_essaydownload_marginleft', $this->marginleft);
set_user_preference('quiz_essaydownload_marginright', $this->marginright);
set_user_preference('quiz_essaydownload_margintop', $this->margintop);
set_user_preference('quiz_essaydownload_nameordering', $this->nameordering);
set_user_preference('quiz_essaydownload_pageformat', $this->pageformat);
set_user_preference('quiz_essaydownload_questiontext', $this->questiontext);
set_user_preference('quiz_essaydownload_shortennames', $this->shortennames);
set_user_preference('quiz_essaydownload_source', $this->source);

// The following settings should only be stored, if the user creates PDF files, because if they
// don't, the corresponding fields will be disabled and have no values, so the user pref would
// be removed and thus the field would not be pre-filled next time.
if ($this->fileformat === 'pdf') {
set_user_preference('quiz_essaydownload_fixremfontsize', $this->fixremfontsize);
set_user_preference('quiz_essaydownload_font', $this->font);
set_user_preference('quiz_essaydownload_fontsize', $this->fontsize);
set_user_preference('quiz_essaydownload_includefooter', $this->includefooter);
set_user_preference('quiz_essaydownload_linespacing', $this->linespacing);
set_user_preference('quiz_essaydownload_marginbottom', $this->marginbottom);
set_user_preference('quiz_essaydownload_marginleft', $this->marginleft);
set_user_preference('quiz_essaydownload_marginright', $this->marginright);
set_user_preference('quiz_essaydownload_margintop', $this->margintop);
set_user_preference('quiz_essaydownload_pageformat', $this->pageformat);
set_user_preference('quiz_essaydownload_source', $this->source);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/form.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Feature: Validation and display of the form
When I set the field "fileformat" to "txt"
Then the "source" "select" should be disabled
And the "fixremfontsize" "field" should be disabled
And the "page" "select" should be disabled
And the "pageformat" "select" should be disabled
And the "marginleft" "field" should be disabled
And the "marginright" "field" should be disabled
And the "margintop" "field" should be disabled
Expand Down
44 changes: 21 additions & 23 deletions tests/report_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,50 +1024,48 @@ public function test_txt_when_input_is_html(): void {
* Provide data to test the Atto workaround. First line is the expected output,
* second line is the input.
*
* @return array
* @return \Generator
*/
public static function provide_texts_with_rem_font_span(): array {
return [
'nothing' => [
public static function provide_texts_with_rem_font_span(): \Generator {
yield 'nothing' => [
'foo bar',
'foo bar',
],
'one span not font-size' => [
];
yield 'one span not font-size' => [
'foo <span>bli</span> bar',
'foo <span>bli</span> bar',
],
'one span with font-size not rem' => [
];
yield 'one span with font-size not rem' => [
'foo <span style="font-size: 15px;">bli</span> bar',
'foo <span style="font-size: 15px;">bli</span> bar',
],
'one span with font-size rem' => [
];
yield 'one span with font-size rem' => [
'foo <span style="font-size: 90%;">bli</span> bar',
'foo <span style="font-size: 0.9rem;">bli</span> bar',
],
'one span with font-size rem and other attributes' => [
];
yield 'one span with font-size rem and other attributes' => [
'foo <span strangeattribute="yes" style="font-size: 90%;" anotherthing>bli</span> bar',
'foo <span strangeattribute="yes" style="font-size: 0.9rem;" anotherthing>bli</span> bar',
],
'one span with font-size rem and other properties' => [
];
yield 'one span with font-size rem and other properties' => [
'foo <span style="text-align: left; font-size: 90%; some-obscure-property: true;">bli</span> bar',
'foo <span style="text-align: left; font-size: 0.9rem; some-obscure-property: true;">bli</span> bar',
],
'one span with font-size rem, uppercase' => [
];
yield 'one span with font-size rem, uppercase' => [
'foo <SPAN style="font-size: 90%;">bli</SPAN> bar',
'foo <SPAN style="font-size: 0.9rem;">bli</SPAN> bar',
],
'one span with font-size rem, single quote' => [
];
yield 'one span with font-size rem, single quote' => [
"foo <span style='font-size: 90%;'>bli</span> bar",
"foo <span style='font-size: 0.9rem;'>bli</span> bar",
],
'two spans with font-size rem' => [
];
yield 'two spans with font-size rem' => [
'foo <span style="font-size: 90%;">bli</span> goo <span style="font-size: 75%;">dip</span> bar',
'foo <span style="font-size: 0.9rem;">bli</span> goo <span style="font-size: 0.75rem;">dip</span> bar',
],
'one span font-size rem with whitespace' => [
];
yield 'one span font-size rem with whitespace' => [
'foo <span style = "font-size: 90%;">bli</span> bar',
'foo <span style = "font-size: 0.9 rem;">bli</span> bar',
],
];
}

Expand Down

0 comments on commit e4a4ac7

Please sign in to comment.