Skip to content

Commit 307e016

Browse files
djarranbrendanheywood
authored andcommitted
Convert test data providers to static, add coverage, fix comment
1 parent 2f7553e commit 307e016

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
$robot = $DB->get_record('user', ['username' => $config->botusername]);
7474
$botrowdata = [get_string('botuser', 'tool_crawler')];
7575

76-
// Do not display links to bot user if it doesn't exist
76+
// Do not display links to bot user if it doesn't exist.
7777
if ($robot) {
7878
$botrowdata[] = implode(' | ', [
7979
$robot->username,

tests/phpunit/robot_cleanup_test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ protected function setUp(): void {
139139
* Read plugin config params.
140140
* Execute robot_cleanup scheduled task.
141141
* Check if only 1 record (out of 3 configured above) is left in table {tool_crawler_url}.
142+
*
143+
* @covers \tool_crawler\task\robot_cleanup::execute
142144
*/
143145
public function test_robot_cleanup(): void {
144146
global $DB;

tests/phpunit/robot_crawler_test.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp(): void {
6262
*
6363
* @return array of test cases
6464
*/
65-
public function absolute_urls_provider(): array {
65+
public static function absolute_urls_provider(): array {
6666
return [
6767
[
6868
'base' => 'http://test.com/sub/',
@@ -119,6 +119,8 @@ public function absolute_urls_provider(): array {
119119
*
120120
* @param string $base Base part of URL
121121
* @param array $links Combinations of relative paths of URL and expected result
122+
*
123+
* @covers \tool_crawler\task\robot_cleanup::execute
122124
*/
123125
public function test_absolute_urls($base, $links): void {
124126
foreach ($links as $key => $value) {
@@ -131,7 +133,7 @@ public function test_absolute_urls($base, $links): void {
131133
*
132134
* @return array of test cases
133135
*/
134-
public function should_auth_provider(): array {
136+
public static function should_auth_provider(): array {
135137
return [
136138
[false, 'http://my_moodle.com', 'http://evil.com/blah/http://my_moodle.com'],
137139
[false, 'http://my_moodle.com', 'http://my_moodle.com.actually.im.evil.com'],
@@ -152,6 +154,8 @@ public function should_auth_provider(): array {
152154
* @param bool $expected
153155
* @param string $myurl URL of current Moodle installation
154156
* @param string $testurl URL where we should authenticate
157+
*
158+
* @covers \tool_crawler\robot\crawler::should_be_authenticated
155159
*/
156160
public function test_should_be_authenticated($expected, $myurl, $testurl): void {
157161
global $CFG;
@@ -162,6 +166,8 @@ public function test_should_be_authenticated($expected, $myurl, $testurl): void
162166

163167
/**
164168
* Tests existence of new plugin parameter 'retentionperiod'
169+
*
170+
* @covers \tool_crawler\robot\crawler
165171
*/
166172
public function test_param_retention_exists(): void {
167173
$param = get_config('tool_crawler', 'retentionperiod');
@@ -170,6 +176,8 @@ public function test_param_retention_exists(): void {
170176

171177
/**
172178
* Regression test for Issue #17
179+
*
180+
* @covers \tool_crawler\local\url::reset_for_recrawl
173181
*/
174182
public function test_reset_queries(): void {
175183
global $DB;
@@ -219,6 +227,8 @@ public function test_reset_queries(): void {
219227
/**
220228
* Regression test for Issue #48: database must store URI without HTML-escaping, but URI must still be escaped when it is output
221229
* to an HTML document.
230+
*
231+
* @covers \tool_crawler\robot\crawler::mark_for_crawl
222232
*/
223233
public function test_uri_escaping(): void {
224234
$baseurl = 'http://crawler.test/';
@@ -244,6 +254,8 @@ public function test_uri_escaping(): void {
244254

245255
/**
246256
* Regression test for an issue similar to Issue #48: redirection URI must be escaped when it is output to an HTML document.
257+
*
258+
* @covers \tool_crawler\robot\crawler::parse_html
247259
*/
248260
public function test_redirection_uri_escaping(): void {
249261
global $DB;
@@ -291,6 +303,8 @@ public function test_redirection_uri_escaping(): void {
291303

292304
/**
293305
* Test for Issue #92: specified dom elements in the config should be excluded.
306+
*
307+
* @covers \tool_crawler\robot\crawler::parse_html
294308
*/
295309
public function test_should_be_excluded(): void {
296310
global $DB;
@@ -355,7 +369,7 @@ public function test_should_be_excluded(): void {
355369
*
356370
* @return array of potential crawler priority codes.
357371
*/
358-
public function priority_provider(): array {
372+
public static function priority_provider(): array {
359373
return [
360374
['high' => TOOL_CRAWLER_PRIORITY_HIGH],
361375
['normal' => TOOL_CRAWLER_PRIORITY_NORMAL],
@@ -369,6 +383,8 @@ public function priority_provider(): array {
369383
* @dataProvider priority_provider
370384
*
371385
* @param int $parentpriority the priority of the parent queue item
386+
*
387+
* @covers \tool_crawler\robot\crawler::parse_html
372388
*/
373389
public function test_parse_html_priority_inheritance($parentpriority): void {
374390
global $CFG, $DB;
@@ -433,7 +449,7 @@ public function test_parse_html_priority_inheritance($parentpriority): void {
433449
/**
434450
* Test for Issue #120:Specified external urls should be excluded.
435451
*/
436-
public function should_be_crawled_provider(): array {
452+
public static function should_be_crawled_provider(): array {
437453
return [
438454
['http://moodle.org/', false],
439455
['http://validator.w3.org/', false],
@@ -450,6 +466,8 @@ public function should_be_crawled_provider(): array {
450466
* @dataProvider should_be_crawled_provider
451467
* @param string $url
452468
* @param bool $expected
469+
*
470+
* @covers \tool_crawler\robot\crawler::mark_for_crawl
453471
*/
454472
public function test_should_be_crawled($url, $expected): void {
455473
global $CFG;
@@ -471,6 +489,7 @@ public function test_should_be_crawled($url, $expected): void {
471489
/**
472490
* We must insert the hash of the url whenever we update the tool_crawler_url table.
473491
*
492+
* @covers \tool_crawler\local\url::hash_url
474493
*/
475494
public function test_url_creates_hash(): void {
476495
global $DB;
@@ -515,6 +534,7 @@ public function test_url_creates_hash(): void {
515534
self::assertTrue(url::hash_url($newurl) === $newurlrecord->urlhash);
516535
self::assertTrue(url::hash_url($newurl) === $persistent->get('urlhash'));
517536
}
537+
518538
/**
519539
* Data provider for string matches
520540
* This data is taken from the moodle (>3.7) core profiling_string_matches_provider function
@@ -523,7 +543,7 @@ public function test_url_creates_hash(): void {
523543
*
524544
* @return array
525545
*/
526-
public function crawler_url_string_matches_provider(): array {
546+
public static function crawler_url_string_matches_provider(): array {
527547
return [
528548
['/index.php', '/index.php', true],
529549
['/some/dir/index.php', '/index.php', true], // Different from core function.
@@ -557,6 +577,8 @@ public function crawler_url_string_matches_provider(): array {
557577
* @param string $string
558578
* @param string $patterns
559579
* @param bool $expected
580+
*
581+
* @covers \tool_crawler\robot\crawler::crawler_url_string_matches
560582
*/
561583
public function test_crawler_url_string_matches($string, $patterns, $expected): void {
562584
$result = $this->robot->crawler_url_string_matches($string, $patterns);
@@ -568,7 +590,7 @@ public function test_crawler_url_string_matches($string, $patterns, $expected):
568590
*
569591
* @return array
570592
*/
571-
public function url_validity_check_provider(): array {
593+
public static function url_validity_check_provider(): array {
572594
return [
573595
['/index.php', true],
574596
['/some/dir/index.php', true],
@@ -585,6 +607,8 @@ public function url_validity_check_provider(): array {
585607
*
586608
* @param string $url the url to test
587609
* @param bool $expected the expected result
610+
*
611+
* @covers \tool_crawler\robot\crawler::mark_for_crawl
588612
*/
589613
public function test_invalid_url($url, $expected): void {
590614
$baseurl = 'https://www.example.com/moodle';
@@ -601,7 +625,7 @@ public function test_invalid_url($url, $expected): void {
601625
*
602626
* @return array
603627
*/
604-
public function page_title_validity_check_provider(): array {
628+
public static function page_title_validity_check_provider(): array {
605629
return [
606630
[['contents' => '<title>Invalid <i>title</i><title><body></body>'], 'Invalid title'],
607631
[['contents' => '<title>Valid title<title><body></body>'], 'Valid title'],
@@ -615,6 +639,8 @@ public function page_title_validity_check_provider(): array {
615639
*
616640
* @param array $node The node to test.
617641
* @param string $expected
642+
*
643+
* @covers \tool_crawler\robot\crawler::parse_html
618644
*/
619645
public function test_check_page_title_validity($node, $expected): void {
620646
$this->resetAfterTest(true);

0 commit comments

Comments
 (0)