From 84be9d5df46a6fb37f346f4033ef661d50464eeb Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 12 Dec 2016 19:58:29 +0300 Subject: [PATCH] PostControllerTest added. LoadPostData now loads one long and one short post for different tests. --- .../DataFixtures/ORM/LoadPostData.php | 16 ++++- .../Tests/Controller/PostControllerTest.php | 61 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/PostControllerTest.php diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php index 3e86d1f..a624211 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php @@ -15,7 +15,7 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface /** @var User $testUser */ $testUser = $this->getReference('test_user_99999'); - $post = (new Post('longpost')) + $longPost = (new Post('longpost')) ->setAuthor($testUser) ->setCreatedAt(new \DateTime()) ->setText('Test post with many comments') @@ -24,10 +24,20 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface ->setDeleted(false) ; - $om->persist($post); + $shortPost = (new Post('shortpost')) + ->setAuthor($testUser) + ->setCreatedAt(new \DateTime()) + ->setText('Test short post') + ->setPrivate(false) + ->setType(Post::TYPE_POST) + ->setDeleted(false) + ; + + $om->persist($longPost); + $om->persist($shortPost); $om->flush(); - $this->addReference('test_post_longpost', $post); + $this->addReference('test_post_longpost', $longPost); } public function getOrder() diff --git a/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/PostControllerTest.php b/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/PostControllerTest.php new file mode 100644 index 0000000..38ba547 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/PostControllerTest.php @@ -0,0 +1,61 @@ +request('GET', '/nonexistingpost'); + + $this->assertTrue($client->getResponse()->isNotFound(), '404 response code for non-existing post'); + } + + /** + * @return Crawler + */ + public function testShortPostPageIsOk() + { + $client = static::createClient(); + $crawler = $client->request('GET', '/shortpost'); + + $this->assertTrue($client->getResponse()->isOk(), '200 response code for existing post'); + + return $crawler; + } + + /** + * @depends testShortPostPageIsOk + * + * @param Crawler $crawler + * + * @return Crawler + */ + public function testShortPostPageHasPostBlock(Crawler $crawler) + { + $postBlock = $crawler->filter('div.post-block'); + + $this->assertEquals(1, $postBlock->count(), 'Post page has zero or more than one div.post-block'); + + return $postBlock->first(); + } + + /** + * @depends testShortPostPageHasPostBlock + * + * @param Crawler $postBlock + */ + public function testShortPostPostBlockHasCorrectPostText(Crawler $postBlock) + { + $postText = $postBlock->filter('div.post-text > div')->first(); + + $this->assertEquals(1, $postText->count(), 'Postblock has no .post-text block'); + $p = $postText->filter('p'); + $this->assertEquals(1, $p->count(), '.post-text has zero or more than one paragraphs'); + $this->assertEquals('Test short post', $p->text(), '.post-text has no correct post text'); + } +}