From 12b33ad85e2b92b5d637ce851d1f1d84c0d6b32d Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 12 Nov 2018 14:54:36 +0800 Subject: [PATCH 1/1] MDL-63488 grade: Add tests for format_feedback --- grade/tests/export_test.php | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 grade/tests/export_test.php diff --git a/grade/tests/export_test.php b/grade/tests/export_test.php new file mode 100644 index 00000000000..9a16a712bb8 --- /dev/null +++ b/grade/tests/export_test.php @@ -0,0 +1,106 @@ +. + +/** + * Unit tests for grade/report/lib.php. + * + * @package core_grades + * @category phpunit + * @copyright Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot.'/grade/lib.php'); +require_once($CFG->dirroot.'/grade/export/lib.php'); + +/** + * A test class used to test grade_report, the abstract grade report parent class + */ +class core_grade_export_test extends advanced_testcase { + + /** + * Ensure that feedback is correct formatted. + * + * @dataProvider format_feedback_provider + * @param string $input The input string to test + * @param int $inputformat The format of the input string + * @param string $expected The expected result of the format. + */ + public function test_format_feedback($input, $inputformat, $expected) { + $feedback = $this->getMockForAbstractClass( + \grade_export::class, + [], + '', + false + ); + + $this->assertEquals( + $expected, + $feedback->format_feedback((object) [ + 'feedback' => $input, + 'feedbackformat' => $inputformat, + ]) + ); + } + + /** + * Data provider for the format_feedback tests. + * + * @return array + */ + public function format_feedback_provider() : array { + return [ + 'Basic string (PLAIN)' => [ + 'This is an example string', + FORMAT_PLAIN, + 'This is an example string', + ], + 'Basic string (HTML)' => [ + '

This is an example string

', + FORMAT_HTML, + 'This is an example string', + ], + 'Has image (HTML)' => [ + '

See this reference:

', + FORMAT_HTML, + 'See this reference: ', + ], + 'Has image and more (HTML)' => [ + '

See for reference

', + FORMAT_HTML, + 'See for reference', + ], + 'Has video and more (HTML)' => [ + '

See for reference

', + FORMAT_HTML, + 'See video of a duck for reference', + ], + 'Multiple videos (HTML)' => [ + '

See and for reference

', + FORMAT_HTML, + 'See video of a duck and video of a cat for reference', + ], + 'HTML Looking tags in PLAIN' => [ + 'The way you have written the ', + FORMAT_PLAIN, + 'The way you have written the ', + ], + ]; + } +} -- 2.17.0