PostControllerTest added. LoadPostData now loads one long and one short post for different tests.
This commit is contained in:
parent
4e0bbadd7f
commit
84be9d5df4
|
@ -15,7 +15,7 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
|
||||||
/** @var User $testUser */
|
/** @var User $testUser */
|
||||||
$testUser = $this->getReference('test_user_99999');
|
$testUser = $this->getReference('test_user_99999');
|
||||||
|
|
||||||
$post = (new Post('longpost'))
|
$longPost = (new Post('longpost'))
|
||||||
->setAuthor($testUser)
|
->setAuthor($testUser)
|
||||||
->setCreatedAt(new \DateTime())
|
->setCreatedAt(new \DateTime())
|
||||||
->setText('Test post with many comments')
|
->setText('Test post with many comments')
|
||||||
|
@ -24,10 +24,20 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
|
||||||
->setDeleted(false)
|
->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();
|
$om->flush();
|
||||||
|
|
||||||
$this->addReference('test_post_longpost', $post);
|
$this->addReference('test_post_longpost', $longPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder()
|
public function getOrder()
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Skobkin\Bundle\PointToolsBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
class PostControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
public function testNonExistingPostPage()
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
$client->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');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue