Skip to content

Commit

Permalink
adding blog comment test
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyph3r committed Sep 13, 2011
1 parent 4b80426 commit 36d3765
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Blogger/BlogBundle/Tests/Controller/BlogControllerTest.php
@@ -0,0 +1,46 @@
<?php

namespace Blogger\BlogBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class BlogControllerTest extends WebTestCase
{
public function testAddBlogComment()
{
$client = static::createClient();

$crawler = $client->request('GET', '/1/a-day-with-symfony');

$this->assertEquals(1, $crawler->filter('h2:contains("A day with Symfony2")')->count());

// Select based on button value, or id or name for buttons
$form = $crawler->selectButton('Submit')->form();

$crawler = $client->submit($form, array(
'blogger_blogbundle_commenttype[user]' => 'name',
'blogger_blogbundle_commenttype[comment]' => 'comment',
));

// Need to follow redirect
$crawler = $client->followRedirect();

// Check comment is now displaying on page, as the last entry. This ensure comments
// are posted in order of oldest to newest
$articleCrawler = $crawler->filter('section .previous-comments article')->last();

$this->assertEquals('name', $articleCrawler->filter('header span.highlight')->text());
$this->assertEquals('comment', $articleCrawler->filter('p')->last()->text());

// Check the sidebar to ensure latest comments are display and there is 10 of them

$this->assertEquals(10, $crawler->filter('aside.sidebar section')->last()
->filter('article')->count()
);

$this->assertEquals('name', $crawler->filter('aside.sidebar section')->last()
->filter('article')->first()
->filter('header span.highlight')->text()
);
}
}

0 comments on commit 36d3765

Please sign in to comment.