Skip to content

Commit

Permalink
MDL-69863 tool_brickfield: ensuring lang string independence.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchurchward authored and stronk7 committed May 4, 2021
1 parent c6c7c28 commit 11dcd41
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 65 deletions.
21 changes: 12 additions & 9 deletions admin/tool/brickfield/classes/accessibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,33 @@ public static function get_capability_name(string $capability): string {
}

/**
* Get the relevant title with extra value concatenated on.
* Get the relevant title.
* @param local\tool\filter $filter
* @param int $countdata
* @param string $extra
* @return string
* @throws \coding_exception
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function get_title(local\tool\filter $filter, int $countdata, string $extra = ''): string {
public static function get_title(local\tool\filter $filter, int $countdata): string {
global $DB;

$tmp = new \stdClass();
$tmp->count = $countdata;
$langstr = 'title' . $filter->tab . 'partial';

if ($filter->courseid != 0) {
$thiscourse = get_fast_modinfo($filter->courseid)->get_course();
return get_string('course') . ': ' . $thiscourse->fullname . $extra;
$tmp->type = get_string('course');
$tmp->name = $thiscourse->fullname;
} else if ($filter->categoryid != 0) {
$category = $DB->get_record('course_categories', ['id' => $filter->categoryid]);
$tmp = new \stdClass();
$tmp->catname = $category->name;
$tmp->count = $countdata;
return get_string('allcoursescat', manager::PLUGINNAME, $tmp) . $extra;
$tmp->type = get_string('category');
$tmp->name = $category->name;
} else {
return get_string('allcourses', manager::PLUGINNAME, $countdata) . $extra;
$langstr = 'title' . $filter->tab . 'all';
}
return get_string($langstr, manager::PLUGINNAME, $tmp);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public function display(\stdClass $data, filter $filter): string {
$templatedata = new \stdClass();

// Set up the page information for the template.
$templatedata->title = get_string('titlepertarget', manager::PLUGINNAME) . ' : ' .
accessibility::get_title($filter, $data->countdata);
$templatedata->title = accessibility::get_title($filter, $data->countdata);
$templatedata->chartdesc = get_string('pagedesc:pertarget', manager::PLUGINNAME);
$templatedata->chartdesctitle = get_string('pagedesctitle:pertarget', manager::PLUGINNAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function display(\stdClass $data, filter $filter): string {
$templatedata = new \stdClass();

// Set up the page information for the external renderer.
$templatedata->title = get_string('titlepertype', manager::PLUGINNAME) . ' : ' .
accessibility::get_title($filter, $data->countdata);
$templatedata->title = accessibility::get_title($filter, $data->countdata);
$templatedata->chartdesc = get_string('pagedesc:checktype', manager::PLUGINNAME);
$templatedata->chartdesctitle = get_string('pagedesctitle:checktype', manager::PLUGINNAME);

Expand Down
3 changes: 1 addition & 2 deletions admin/tool/brickfield/classes/output/errors/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public function display(\stdClass $data, filter $filter): string {
);

// Set up a table of data for the template.
$templatedata->pagetitle = get_string('titleerrors', manager::PLUGINNAME) . ' : ' .
accessibility::get_title($filter, $data->countdata);
$templatedata->pagetitle = accessibility::get_title($filter, $data->countdata);

if (count($data->errordata) == 0) {
$templatedata->noerrorsfound = get_string('noerrorsfound', manager::PLUGINNAME);
Expand Down
24 changes: 13 additions & 11 deletions admin/tool/brickfield/classes/output/printable/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public function display(\stdClass $data, filter $filter): string {

$div1 = \html_writer::div($this->pix_icon('f/award',
get_string('totalactivities', manager::PLUGINNAME), manager::PLUGINNAME).
get_string('totalactivities', manager::PLUGINNAME) . ': ' . $data->combodata['total'], '',
get_string('totalactivitiescount', manager::PLUGINNAME, $data->combodata['total']), '',
['class' => 'col-sm-3'.$css]);
$div2 = \html_writer::div($this->pix_icon('f/done2',
get_string('passed', manager::PLUGINNAME), manager::PLUGINNAME).
get_string('passed', manager::PLUGINNAME) . ': ' . $data->combodata['passed'], '',
get_string('passedcount', manager::PLUGINNAME, $data->combodata['passed']), '',
['class' => 'col-sm-3'.$css]);
$div3 = \html_writer::div($this->pix_icon('f/error',
get_string('failed', manager::PLUGINNAME), manager::PLUGINNAME).
get_string('failed', manager::PLUGINNAME) . ': ' . $data->combodata['failed'], '',
get_string('failedcount', manager::PLUGINNAME, $data->combodata['failed']), '',
['class' => 'col-sm-3'.$css]);
$out .= \html_writer::div($div1.$div2.$div3, '', ['id' => 'rowa', 'class' => 'row h4']);

Expand Down Expand Up @@ -170,8 +170,7 @@ public function display(\stdClass $data, filter $filter): string {
$str4 .= \html_writer::table($table, true);
$out .= \html_writer::div($str4, '', ['class' => 'col-sm-4']);

$str5 = \html_writer::tag('h4', get_string('titleerrors', manager::PLUGINNAME) .
get_string('titleerrorscount', manager::PLUGINNAME, $data->errordetailscount));
$str5 = \html_writer::tag('h4', get_string('titleerrorscount', manager::PLUGINNAME, $data->errordetailscount));
$table = new \html_table();
$table->head = [
get_string('tbltarget', manager::PLUGINNAME),
Expand Down Expand Up @@ -255,16 +254,19 @@ public function pdf_renderer(\stdClass $data, filter $filter) {
<tr>
<td>
<img src="' . $this->image_path() . 'tachometer-alt-solid.svg" width="15" height="15">' .
' <td style="line-height: 10px;"> '.get_string('totalactivities', manager::PLUGINNAME) . ': ' .
$data->combodata['total'] .'</td></td>
' <td style="line-height: 10px;"> ' .
get_string('totalactivitiescount', manager::PLUGINNAME, $data->combodata['total']) .
'</td></td>
<td>
<img src="' . $this->image_path() . 'check-square-regular.svg" width="15" height="15">' .
' <td style="line-height: 10px;"> '.get_string('passed', manager::PLUGINNAME) . ': ' .
$data->combodata['passed'] .'</td></td>
' <td style="line-height: 10px;"> ' .
get_string('passedcount', manager::PLUGINNAME, $data->combodata['passed']) .
'</td></td>
<td>
<img src="' . $this->image_path() . 'times-circle-regular.svg" width="15" height="15">' .
' <td style="line-height: 10px;"> '.get_string('failed', manager::PLUGINNAME) . ': ' .
$data->combodata['failed'] .'</td></td>
' <td style="line-height: 10px;"> ' .
get_string('failedcount', manager::PLUGINNAME, $data->combodata['failed']) .
'</td></td>
</tr>
</table>';

Expand Down
31 changes: 15 additions & 16 deletions admin/tool/brickfield/lang/en/tool_brickfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
$string['eventreport_downloaded'] = 'Accessibility summary downloaded';
$string['eventreport_downloadeddesc'] = 'Accessibility summary was downloaded for course id {$a}.';
$string['failed'] = 'Failed';
$string['failedcount'] = 'Failed: {$a}';
$string['tools'] = 'Go to reports';
$string['formcorrectlysubmitted'] = 'Check Process successfully added';
$string['formdescription'] = 'This will add a new check process record which will run as a scheduled task';
Expand Down Expand Up @@ -125,6 +126,7 @@
$string['pagedesctitle:checktype'] = 'Content types explained';
$string['pagedesctitle:pertarget'] = 'Activity breakdown explained';
$string['passed'] = 'Passed';
$string['passedcount'] = 'Passed: {$a}';
$string['passrate'] = 'Pass rate: {$a}%';
$string['perpage'] = 'Items to show per page';
$string['privacy:metadata'] = 'The Accessibility checks report plugin does not store any personal data.';
Expand Down Expand Up @@ -182,27 +184,24 @@
$string['tblupdateto'] = 'Update to';
$string['termsandconditions'] = '<p>These are the terms and conditions you agree to... blah blah...</p>';
$string['termsandconditionslink'] = 'terms and conditions';
$string['titleerrors'] = 'Error details';
$string['titleerrorscount'] = '&nbsp;(Showing first {$a} errors)';
$string['titlepercategory'] = 'Course activities pass rate % per top category';
$string['titlepercategoryamount'] = 'Course activities failed per top category';
$string['titlepercheck'] = 'Total errors per check';
$string['titlepercourse'] = 'Course activities pass rate % per course';
$string['titlepercourseamount'] = 'Course activities failed per course';
$string['titlepertag'] = 'Course activities pass rate % per tag';
$string['titlepertagamount'] = 'Course activities failed per tag';
$string['titlepertag2'] = 'Shows data related to globally configured tags only';
$string['titlepertarget'] = 'Results per activity';
$string['titlepertype'] = 'Results per content type';
$string['titleresults'] = 'Overview Summary';
$string['titleerrorscount'] = 'Error details:&nbsp;(Showing first {$a} errors)';
$string['titleactivityresultsall'] = 'Results per activity: All reviewed courses ({$a->count} courses)';
$string['titleactivityresultspartial'] = 'Results per activity: {$a->type} {$a->name}';
$string['titleall'] = 'Error details: All reviewed courses ({$a->count} courses)';
$string['titlechecktyperesultsall'] = 'Results per content type: All reviewed courses ({$a->count} courses)';
$string['titlechecktyperesultspartial'] = 'Results per content type: {$a->type} {$a->name}';
$string['titleerrorsall'] = 'Error details: All reviewed courses ({$a->count} courses)';
$string['titleerrorspartial'] = 'Error details: {$a->type} {$a->name}';
$string['titlepartial'] = 'Error details: {$a->type} {$a->name}';
$string['titleprintableall'] = '{$a->type} {$a->name}';
$string['titleprintablepartial'] = '{$a->type} {$a->name}';
$string['toptargets'] = 'Failed activities';
$string['toperrors'] = 'Top errors';
$string['totalactivities'] = 'Total activities';
$string['totalactivitiescount'] = 'Total activities: {$a}';
$string['totalareas'] = 'Total areas';
$string['totalerrors'] = 'Total errors';
$string['totalgrouperrors'] = 'Total (sum) errors per content type';
$string['totaltargetinstances'] = 'Total instances per activity';
$string['totaltargeterrors'] = 'Total (sum) errors per activity';
$string['updatesummarydata'] = 'Update site summarydata';
$string['messageprovider:warningcheckid'] = 'Warning of invalid checkids';
$string['warningcheckidbody'] = 'There is an issue with a Brickfield check
Expand Down Expand Up @@ -249,7 +248,7 @@
$string['activated'] = 'The plugin is activated and ready to use.';
$string['activationform'] = 'Brickfield registration';
$string['activationheader'] = 'Brickfield Activation';
$string['activationinfo'] = 'In order to use this plugin, you must be registered, or have a valid code for this platform. If you are not already registered, please {$a}register your details</a>. <br />After registration, <b>you will then have online access to the keys</b> that you must submit in this form.';
$string['activationinfo'] = 'In order to use this plugin, you must be registered, or have a valid code for this platform. If you are not already registered, please {$a}register your details</a>. <br />After registration, <b>you will then have online access to the keys</b> that you must submit in this form. <br />Registration validation is then triggered by running the Accessibility toolkit cron scheduled tasks.';
$string['automatedsentdaily'] = '';
$string['country'] = 'Country';
$string['country_help'] = 'Country of the site';
Expand Down
16 changes: 5 additions & 11 deletions admin/tool/brickfield/tests/accessibility_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,22 @@ public function test_get_title() {

// Testing the else statement.
$output = $object->get_title($filter, 0);
$this->assertEquals($output, 'All reviewed courses (0)');
$this->assertEquals($output, 'Error details: All reviewed courses (0 courses)');
$output = $object->get_title($filter, 5);
$this->assertEquals($output, 'All reviewed courses (5)');
$output = $object->get_title($filter, 0, ' extra text');
$this->assertEquals($output, 'All reviewed courses (0) extra text');
$this->assertEquals($output, 'Error details: All reviewed courses (5 courses)');

// Testing the if statement.
$filter->courseid = 1;
$output = $object->get_title($filter, 0);
$this->assertEquals($output, 'Course: PHPUnit test site');
$output = $object->get_title($filter, 1, ' extra text');
$this->assertEquals($output, 'Course: PHPUnit test site extra text');
$this->assertEquals($output, 'Error details: Course PHPUnit test site');

// Testing the else if statement.
$filter->categoryid = 1;
$filter->courseid = 0;
$output = $object->get_title($filter, 0);
$this->assertEquals($output, 'All reviewed courses for category Miscellaneous (0)');
$this->assertEquals($output, 'Error details: Category Miscellaneous');
$output = $object->get_title($filter, 2);
$this->assertEquals($output, 'All reviewed courses for category Miscellaneous (2)');
$output = $object->get_title($filter, 3, ' extra text');
$this->assertEquals($output, 'All reviewed courses for category Miscellaneous (3) extra text');
$this->assertEquals($output, 'Error details: Category Miscellaneous');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/brickfield/tests/activityresults_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public function test_get_output() {
$this->resetAfterTest();

$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'tab', 3, 4);
$filter = new filter(1, $category->id, 'activityresults', 3, 4);
$filter->courseids = [];

$object = new activityresults();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertIsString($output);
$this->assertStringContainsString('Results per activity :', $output);
$this->assertStringContainsString('Results per activity:', $output);
}
}
10 changes: 5 additions & 5 deletions admin/tool/brickfield/tests/behat/accessresults.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ Feature: Brickfield activityresults
And I run the scheduled task "\tool_brickfield\task\bulk_process_courses"
And I run the scheduled task "\tool_brickfield\task\bulk_process_caches"
And I navigate to "Accessibility toolkit" in current page administration
And I should see "Error details : Course: Course 1"
And I should see "Error details: Course Course 1"
And I should see "Overall page content length"
And I should see "\"Bold\" (b) elements should not be used"
And I should see "Link text should be descriptive"
And I follow "Activity breakdown"
Then I should see "Results per activity : Course: Course 1"
Then I should see "Results per activity: Course Course 1"
And I navigate to "Plugins > Admin tools > Accessibility > Brickfield registration" in site administration
And I set the field "id_key" to "123456789012345678901234567890ab"
And I set the field "id_hash" to "ab123456789012345678901234567890"
And I press "Activate"
And I navigate to "Plugins > Admin tools > Accessibility > Go to reports" in site administration
And I should see "Error details : All reviewed courses (2)"
And I should see "Error details: All reviewed courses (2 courses)"
And I follow "Activity breakdown"
Then I should see "Results per activity : All reviewed courses (2)"
Then I should see "Results per activity: All reviewed courses (2 courses)"
And I follow "Content types"
Then I should see "Results per content type : All reviewed courses (2)"
Then I should see "Results per content type: All reviewed courses (2 courses)"
2 changes: 1 addition & 1 deletion admin/tool/brickfield/tests/checktyperesults_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function test_get_output() {
$object->get_data();
$output = $object->get_output();
$this->assertIsString($output);
$this->assertStringContainsString('Results per content type :', $output);
$this->assertStringContainsString('Results per content type:', $output);
}
}
4 changes: 2 additions & 2 deletions admin/tool/brickfield/tests/errors_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public function test_get_output() {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();

$filter = new filter(1, $category->id, 'tab', 3, 4);
$filter = new filter(1, $category->id, 'errors', 3, 4);
$filter->courseids = [];

$object = new errors();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertIsString($output);
$this->assertStringContainsString('Error details :', $output);
$this->assertStringContainsString('Error details:', $output);
}
}
4 changes: 2 additions & 2 deletions admin/tool/brickfield/tests/printable_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public function test_get_output() {
$object = new printable();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertStringContainsString('<h3>Course: PHPUnit test site</h3><div id=', $output);
$this->assertStringContainsString('<h3>Course PHPUnit test site</h3><div id=', $output);

$filter->target = '';
$object = new printable();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertStringContainsString('<h3>Course: PHPUnit test site</h3><a href=', $output);
$this->assertStringContainsString('<h3>Course PHPUnit test site</h3><a href=', $output);

$filter->target = 'html';
$object = new printable();
Expand Down

0 comments on commit 11dcd41

Please sign in to comment.