Skip to content

Commit

Permalink
MDL-40759 icons: Update unit tests
Browse files Browse the repository at this point in the history
Match the expected output for unit tests.
  • Loading branch information
Damyon Wiese committed Mar 17, 2017
1 parent 3c88507 commit 0b77281
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
3 changes: 1 addition & 2 deletions filter/emoticon/tests/filter_test.php
Expand Up @@ -54,8 +54,7 @@ public function test_filter_emoticon_formats() {
$this->assertEquals($expected, $filter->filter('(grr)', $options));

// And texts matching target formats are filtered.
$expected = '<img class="emoticon" alt="angry" title="angry"'.
' src="http://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/angry" />';
$expected = '<i class="icon fa s/angry fa-fw emoticon" aria-hidden="true" title=""></i><span class="sr-only"></span>';
$options = array('originalformat' => FORMAT_HTML); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
$this->assertEquals($expected, $filter->filter('(grr)', $options));
}
Expand Down
9 changes: 6 additions & 3 deletions lib/tests/filter_manager_test.php
Expand Up @@ -54,7 +54,8 @@ protected function filter_text($text, $skipfilters) {
public function test_filter_normal() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertRegExp('~^<p><img class="emoticon" alt="smile" ([^>]+)></p>$~',
$this->assertRegExp('~^<p><i class="icon fa s/smiley fa-fw emoticon" aria-hidden="true" title=""></i>' .
'<span class="sr-only"></span></p>$~',
$this->filter_text('<p>:-)</p>', array()));
}

Expand All @@ -68,15 +69,17 @@ public function test_one_filter_disabled() {
public function test_disabling_other_filter_does_not_break_it() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertRegExp('~^<p><img class="emoticon" alt="smile" ([^>]+)></p>$~',
$this->assertRegExp('~^<p><i class="icon fa s/smiley fa-fw emoticon" aria-hidden="true" title=""></i>' .
'<span class="sr-only"></span></p>$~',
$this->filter_text('<p>:-)</p>', array('urltolink')));
}

public function test_one_filter_of_two_disabled() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
filter_set_global_state('urltolink', TEXTFILTER_ON);
$this->assertRegExp('~^<p><img class="emoticon" alt="smile" ([^>]+)> http://google.com/</p>$~',
$this->assertRegExp('~^<p><i class="icon fa s/smiley fa-fw emoticon" aria-hidden="true" title=""></i>' .
'<span class="sr-only"></span> http://google.com/</p>$~',
$this->filter_text('<p>:-) http://google.com/</p>', array('glossary', 'urltolink')));
}
}
10 changes: 7 additions & 3 deletions lib/tests/weblib_format_text_test.php
Expand Up @@ -37,7 +37,8 @@ class core_weblib_format_text_testcase extends advanced_testcase {
public function test_format_text_format_html() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertRegExp('~^<p><img class="emoticon" alt="smile" ([^>]+)></p>$~',
$this->assertRegExp('~^<p><i class="icon fa s/smiley fa-fw emoticon" aria-hidden="true" title=""></i>' .
'<span class="sr-only"></span></p>$~',
format_text('<p>:-)</p>', FORMAT_HTML));
}

Expand Down Expand Up @@ -66,7 +67,8 @@ public function test_format_text_format_plain_no_filters() {
public function test_format_text_format_markdown() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertRegExp('~^<p><em><img class="emoticon" alt="smile" ([^>]+)></em></p>\n$~',
$this->assertRegExp('~^<p><em><i class="icon fa s/smiley fa-fw emoticon" aria-hidden="true" title=""></i>' .
'<span class="sr-only"></span></em></p>\n$~',
format_text('*:-)*', FORMAT_MARKDOWN));
}

Expand All @@ -80,7 +82,9 @@ public function test_format_text_format_markdown_nofilter() {
public function test_format_text_format_moodle() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertRegExp('~^<div class="text_to_html"><p><img class="emoticon" alt="smile" ([^>]+)></p></div>$~',
$this->assertRegExp('~^<div class="text_to_html"><p>' .
'<i class="icon fa s/smiley fa-fw emoticon" aria-hidden="true" title=""></i>' .
'<span class="sr-only"></span></p></div>$~',
format_text('<p>:-)</p>', FORMAT_MOODLE));
}

Expand Down
4 changes: 2 additions & 2 deletions mod/resource/tests/lib_test.php
Expand Up @@ -143,12 +143,12 @@ public function test_get_coursemodule_info() {
$info = resource_get_coursemodule_info(
$DB->get_record('course_modules', array('id' => $resource2->cmid)));
$this->assertEquals('R2', $info->name);
$this->assertEquals('f/text-24', $info->icon);
$this->assertEquals('f/text', $info->icon);

// For third one, it should use the highest sortorder icon.
$info = resource_get_coursemodule_info(
$DB->get_record('course_modules', array('id' => $resource3->cmid)));
$this->assertEquals('R3', $info->name);
$this->assertEquals('f/document-24', $info->icon);
$this->assertEquals('f/document', $info->icon);
}
}

0 comments on commit 0b77281

Please sign in to comment.