Skip to content

Commit c4c8cdd

Browse files
committed
test: added missing test for RobotsController
1 parent 6ab743b commit c4c8cdd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace phpMyFAQ\Controller;
4+
5+
use phpMyFAQ\Strings;
6+
use phpMyFAQ\Translation;
7+
use PHPUnit\Framework\MockObject\Exception;
8+
use PHPUnit\Framework\TestCase;
9+
use Symfony\Component\HttpFoundation\Response;
10+
use Twig\Environment;
11+
12+
class RobotsControllerTest extends TestCase
13+
{
14+
private Environment $twig;
15+
private RobotsController $controller;
16+
17+
/**
18+
* @throws Exception
19+
* @throws \phpMyFAQ\Core\Exception
20+
*/
21+
protected function setUp(): void
22+
{
23+
parent::setUp();
24+
25+
Strings::init();
26+
27+
Translation::create()
28+
->setLanguagesDir(PMF_TRANSLATION_DIR)
29+
->setDefaultLanguage('en')
30+
->setCurrentLanguage('en')
31+
->setMultiByteLanguage();
32+
33+
$this->twig = $this->createMock(Environment::class);
34+
$this->controller = new RobotsController();
35+
}
36+
37+
/**
38+
* @throws \Exception
39+
*/
40+
public function testIndex(): void
41+
{
42+
$response = $this->controller->index();
43+
44+
$this->assertInstanceOf(Response::class, $response);
45+
$this->assertEquals('text/plain', $response->headers->get('Content-Type'));
46+
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
47+
$this->assertEquals('User-agent: *\nDisallow: /admin/\nSitemap: /sitemap.xml', $response->getContent());
48+
}
49+
}

0 commit comments

Comments
 (0)