From 586ae77bc28858d3f57bca1ce46c0dde1f22c04c Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Mon, 6 Jul 2020 17:33:57 +0800 Subject: [PATCH] MDL-69206 course: Tidy up unit test to avoid potential failures --- course/tests/services_content_item_service_test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/course/tests/services_content_item_service_test.php b/course/tests/services_content_item_service_test.php index 51d2183ff66..f1924fbf8ad 100644 --- a/course/tests/services_content_item_service_test.php +++ b/course/tests/services_content_item_service_test.php @@ -153,9 +153,12 @@ class services_content_item_service_testcase extends \advanced_testcase { $matchingcontentitems1 = $cis->get_content_items_by_name_pattern($user, $pattern1); $matchingcontentitems2 = $cis->get_content_items_by_name_pattern($user, $pattern2); - // The pattern "assign" should return 1 content item ("Assignment"). - $this->assertCount(1, $matchingcontentitems1); - $this->assertEquals("Assignment", $matchingcontentitems1[0]->title); + // The pattern "assign" should return at least 1 content item (ex. "Assignment"). + $this->assertGreaterThanOrEqual(1, count($matchingcontentitems1)); + // Verify the pattern "assign" can be found in the title of each returned content item. + foreach ($matchingcontentitems1 as $contentitem) { + $this->assertEquals(1, preg_match("/$pattern1/i", $contentitem->title)); + } // The pattern "random string" should not return any content items. $this->assertEmpty($matchingcontentitems2); }