This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use DJStarCOM\RobotsManager\RobotsManager; |
||
4 | use PHPUnit\Framework\TestCase; |
||
5 | |||
6 | /** |
||
7 | * Class RobotsManagerTest |
||
8 | */ |
||
9 | class RobotsManagerTest extends TestCase |
||
10 | { |
||
11 | |||
12 | public function testNewInstanceEmpty(): void |
||
13 | { |
||
14 | $robots = new RobotsManager; |
||
15 | $this->assertEquals('', $robots->generate()); |
||
16 | } |
||
17 | |||
18 | View Code Duplication | public function testAddSitemap(): void |
|
0 ignored issues
–
show
|
|||
19 | { |
||
20 | $robots = new RobotsManager; |
||
21 | $sitemap = 'sitemap.xml'; |
||
22 | |||
23 | $this->assertStringNotContainsString($sitemap, $robots->generate()); |
||
24 | $robots->addSitemap($sitemap); |
||
25 | $this->assertStringContainsString('Sitemap: '.$sitemap, $robots->generate()); |
||
26 | } |
||
27 | |||
28 | View Code Duplication | public function testAddUserAgent(): void |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
29 | { |
||
30 | $robots = new RobotsManager; |
||
31 | $userAgent = 'Google'; |
||
32 | |||
33 | $this->assertStringNotContainsString('User-agent: '.$userAgent, $robots->generate()); |
||
34 | $robots->addUserAgent($userAgent); |
||
35 | $this->assertStringContainsString('User-agent: '.$userAgent, $robots->generate()); |
||
36 | } |
||
37 | |||
38 | View Code Duplication | public function testaddHost(): void |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
39 | { |
||
40 | $robots = new RobotsManager; |
||
41 | $host = 'www.google.com'; |
||
42 | |||
43 | $this->assertStringNotContainsString('Host: '.$host, $robots->generate()); |
||
44 | $robots->addHost($host); |
||
45 | $this->assertStringContainsString('Host: '.$host, $robots->generate()); |
||
46 | } |
||
47 | |||
48 | View Code Duplication | public function testaddDisallow(): void |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
49 | { |
||
50 | $robots = new RobotsManager; |
||
51 | $path = '/dir/'; |
||
52 | $paths = ['/dir-1/', '/dir-2/', '/dir-3/']; |
||
53 | |||
54 | // Test a single path. |
||
55 | $this->assertStringNotContainsString('Disallow: '.$path, $robots->generate()); |
||
56 | $robots->addDisallow($path); |
||
57 | $this->assertStringContainsString('Disallow: '.$path, $robots->generate()); |
||
58 | |||
59 | // Test array of paths. |
||
60 | foreach ($paths as $path_test) { |
||
61 | $this->assertStringNotContainsString('Disallow: '.$path_test, $robots->generate()); |
||
62 | } |
||
63 | |||
64 | // Add the array of paths |
||
65 | $robots->addDisallow($paths); |
||
66 | |||
67 | // Check the old path is still there |
||
68 | $this->assertStringContainsString('Disallow: '.$path, $robots->generate()); |
||
69 | foreach ($paths as $path_test) { |
||
70 | $this->assertStringContainsString('Disallow: '.$path_test, $robots->generate()); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | View Code Duplication | public function testaddAllow(): void |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
75 | { |
||
76 | $robots = new RobotsManager; |
||
77 | $path = '/dir/'; |
||
78 | $paths = ['/dir-1/', '/dir-2/', '/dir-3/']; |
||
79 | |||
80 | // Test a single path. |
||
81 | $this->assertStringNotContainsString('Allow: '.$path, $robots->generate()); |
||
82 | $robots->addAllow($path); |
||
83 | $this->assertStringContainsString('Allow: '.$path, $robots->generate()); |
||
84 | |||
85 | // Test array of paths. |
||
86 | foreach ($paths as $path_test) { |
||
87 | $this->assertStringNotContainsString('Allow: '.$path_test, $robots->generate()); |
||
88 | } |
||
89 | |||
90 | // Add the array of paths |
||
91 | $robots->addAllow($paths); |
||
92 | |||
93 | // Check the old path is still there |
||
94 | $this->assertStringContainsString('Allow: '.$path, $robots->generate()); |
||
95 | |||
96 | foreach ($paths as $path_test) { |
||
97 | $this->assertStringContainsString('Allow: '.$path_test, $robots->generate()); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | public function testaddComment(): void |
||
102 | { |
||
103 | $robots = new RobotsManager; |
||
104 | $comment_1 = 'Test comment'; |
||
105 | $comment_2 = 'Another comment'; |
||
106 | $comment_3 = 'Final test comment'; |
||
107 | |||
108 | $this->assertStringNotContainsString('# '.$comment_1, $robots->generate()); |
||
109 | $this->assertStringNotContainsString('# '.$comment_2, $robots->generate()); |
||
110 | $this->assertStringNotContainsString('# '.$comment_3, $robots->generate()); |
||
111 | |||
112 | $robots->addComment($comment_1); |
||
113 | $this->assertStringContainsString('# '.$comment_1, $robots->generate()); |
||
114 | |||
115 | $robots->addComment($comment_2); |
||
116 | $this->assertStringContainsString('# '.$comment_1, $robots->generate()); |
||
117 | $this->assertStringContainsString('# '.$comment_2, $robots->generate()); |
||
118 | |||
119 | $robots->addComment($comment_3); |
||
120 | $this->assertStringContainsString('# '.$comment_1, $robots->generate()); |
||
121 | $this->assertStringContainsString('# '.$comment_2, $robots->generate()); |
||
122 | $this->assertStringContainsString('# '.$comment_3, $robots->generate()); |
||
123 | } |
||
124 | |||
125 | public function testaddSpacer(): void |
||
126 | { |
||
127 | $robots = new RobotsManager; |
||
128 | |||
129 | $lines = count(preg_split('/'.PHP_EOL.'/', $robots->generate())); |
||
130 | $this->assertEquals(1, $lines); // Starts off with at least one line. |
||
131 | |||
132 | $robots->addSpacer(); |
||
133 | $robots->addSpacer(); |
||
134 | $lines = count(preg_split('/'.PHP_EOL.'/', $robots->generate())); |
||
135 | |||
136 | $this->assertEquals(2, $lines); |
||
137 | } |
||
138 | |||
139 | public function testReset(): void |
||
140 | { |
||
141 | $robots = new RobotsManager; |
||
142 | |||
143 | $this->assertEquals('', $robots->generate()); |
||
144 | |||
145 | $robots->addComment('First Comment'); |
||
146 | $robots->addHost('www.google.com'); |
||
147 | $robots->addSitemap('sitemap.xml'); |
||
148 | $this->assertNotEquals('', $robots->generate()); |
||
149 | |||
150 | $robots->reset(); |
||
151 | $this->assertEquals('', $robots->generate()); |
||
152 | } |
||
153 | } |
||
154 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.