Skip to content

Commit

Permalink
Merge branch 'MDL-65884-37' of https://github.com/paulholden/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_37_STABLE
  • Loading branch information
stronk7 committed Jan 20, 2020
2 parents 7a8b370 + ad7d0f0 commit 68e4a7d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions filter/activitynames/tests/filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
class filter_activitynames_filter_testcase extends advanced_testcase {

public function test_links() {
global $CFG;
$this->resetAfterTest(true);

// Create a test course.
Expand All @@ -59,8 +58,8 @@ public function test_links() {
preg_match_all('~<a class="autolink" title="([^"]*)" href="[^"]*/mod/page/view.php\?id=([0-9]+)">([^<]*)</a>~',
$filtered, $matches);

// There should be 3 links links.
$this->assertEquals(2, count($matches[1]));
// There should be 2 links links.
$this->assertCount(2, $matches[1]);

// Check text of title attribute.
$this->assertEquals($page1->name, $matches[1][0]);
Expand All @@ -74,4 +73,33 @@ public function test_links() {
$this->assertEquals($page1->name, $matches[3][0]);
$this->assertEquals($page2->name, $matches[3][1]);
}

public function test_links_activity_named_hyphen() {
$this->resetAfterTest(true);

// Create a test course.
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);

// Work around an issue with the activity names filter which maintains a static cache
// of activities for current course ID. We can re-build the cache by switching user.
$this->setUser($this->getDataGenerator()->create_user());

// Create a page activity named '-' (single hyphen).
$page = $this->getDataGenerator()->create_module('page', ['course' => $course->id, 'name' => '-']);

$html = '<p>Please read the - page.</p>';
$filtered = format_text($html, FORMAT_HTML, array('context' => $context));

// Find the page link in the filtered html.
preg_match_all('~<a class="autolink" title="([^"]*)" href="[^"]*/mod/page/view.php\?id=([0-9]+)">([^<]*)</a>~',
$filtered, $matches);

// We should have exactly one match.
$this->assertCount(1, $matches[1]);

$this->assertEquals($page->name, $matches[1][0]);
$this->assertEquals($page->cmid, $matches[2][0]);
$this->assertEquals($page->name, $matches[3][0]);
}
}
2 changes: 1 addition & 1 deletion lib/filterlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* keys. It must be something rare enough to avoid having matches with
* filterobjects. MDL-18165
*/
define('TEXTFILTER_EXCL_SEPARATOR', '-%-');
define('TEXTFILTER_EXCL_SEPARATOR', chr(0x1F) . '%' . chr(0x1F));


/**
Expand Down

0 comments on commit 68e4a7d

Please sign in to comment.