Passed
Push — master ( 88105a...84be9d )
by Alexey
17:21
created

PostControllerTest::testShortPostPageIsOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Component\DomCrawler\Crawler;
7
8
class PostControllerTest extends WebTestCase
9
{
10
    public function testNonExistingPostPage()
11
    {
12
        $client = static::createClient();
13
        $client->request('GET', '/nonexistingpost');
14
15
        $this->assertTrue($client->getResponse()->isNotFound(), '404 response code for non-existing post');
16
    }
17
18
    /**
19
     * @return Crawler
20
     */
21
    public function testShortPostPageIsOk()
22
    {
23
        $client = static::createClient();
24
        $crawler = $client->request('GET', '/shortpost');
25
26
        $this->assertTrue($client->getResponse()->isOk(), '200 response code for existing post');
27
28
        return $crawler;
29
    }
30
31
    /**
32
     * @depends testShortPostPageIsOk
33
     *
34
     * @param Crawler $crawler
35
     *
36
     * @return Crawler
37
     */
38
    public function testShortPostPageHasPostBlock(Crawler $crawler)
39
    {
40
        $postBlock = $crawler->filter('div.post-block');
41
42
        $this->assertEquals(1, $postBlock->count(), 'Post page has zero or more than one div.post-block');
43
44
        return $postBlock->first();
45
    }
46
47
    /**
48
     * @depends testShortPostPageHasPostBlock
49
     *
50
     * @param Crawler $postBlock
51
     */
52
    public function testShortPostPostBlockHasCorrectPostText(Crawler $postBlock)
53
    {
54
        $postText = $postBlock->filter('div.post-text > div')->first();
55
56
        $this->assertEquals(1, $postText->count(), 'Postblock has no .post-text block');
57
        $p = $postText->filter('p');
58
        $this->assertEquals(1, $p->count(), '.post-text has zero or more than one paragraphs');
59
        $this->assertEquals('Test short post', $p->text(), '.post-text has no correct post text');
60
    }
61
}
62