|
1
|
|
|
<?php |
|
2
|
|
|
namespace SumoCoders\FrameworkErrorBundle\Tests\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
5
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Client; |
|
7
|
|
|
|
|
8
|
|
|
class ExceptionControllerTest extends WebTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function test404Page() |
|
11
|
|
|
{ |
|
12
|
|
|
$client = static::createClient(); |
|
13
|
|
|
$crawler = $client->request('GET', '/non-existing-path'); |
|
14
|
|
|
|
|
15
|
|
|
$this->assertErrorPage($client, $crawler, 404, 'Page not found.'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testStandardException() |
|
19
|
|
|
{ |
|
20
|
|
|
$client = static::createClient(); |
|
21
|
|
|
$crawler = $client->request('GET', '/exception/standard'); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertErrorPage($client, $crawler, 500); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Check if a page is a real error page |
|
28
|
|
|
* |
|
29
|
|
|
* @param Client $client |
|
30
|
|
|
* @param Crawler $crawler |
|
31
|
|
|
* @param string $code |
|
32
|
|
|
* @param string $message |
|
33
|
|
|
*/ |
|
34
|
|
|
private function assertErrorPage( |
|
35
|
|
|
Client $client, |
|
36
|
|
|
Crawler $crawler, |
|
37
|
|
|
$code, |
|
38
|
|
|
$message = 'Something went wrong.' |
|
39
|
|
|
) { |
|
40
|
|
|
// check if the code is set correctly |
|
41
|
|
|
$this->assertEquals($code, $client->getResponse()->getStatusCode()); |
|
42
|
|
|
|
|
43
|
|
|
// check if the title is ok |
|
44
|
|
|
$this->assertEquals( |
|
45
|
|
|
sprintf('%1$s: %2$s', $code, $message), |
|
46
|
|
|
$crawler->filter('title')->html() |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
// check if no-index is set |
|
50
|
|
|
$this->assertEquals( |
|
51
|
|
|
'noindex, nofollow', |
|
52
|
|
|
$crawler->filter('meta[name=robots]')->attr('content') |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
// check if the message is ok |
|
56
|
|
|
$this->assertEquals( |
|
57
|
|
|
sprintf('%1$s: %2$s', $code, $message), |
|
58
|
|
|
$crawler->filter('#content h1')->html() |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|