Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelrandy committed Oct 7, 2015
1 parent bd59cb1 commit a806fe3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 870 deletions.
2 changes: 1 addition & 1 deletion src/Aperophp/Provider/Controller/Participate.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function connect(Application $app)
$app['session']->getFlashBag()->add('success', 'Participation ajoutée.');

if ($participation['percentage'] > 0) {
$app['mailer']->send($app['mail_factory']->createParticipation($user, $drink));
$app['mailer']->send($app['mail_factory']->createParticipation($user, $drink));
}

return $returnValue;
Expand Down
80 changes: 80 additions & 0 deletions tests/units/Aperophp/Provider/Controller/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace tests\units\Aperophp\Provider\Controller;

require_once __DIR__.'/../../../../../vendor/autoload.php';

use Aperophp\Test\Test;

class Comment extends Test
{
protected function getDefaultDatas($data_overload=array())
{
return array_merge(
array(
'drink_comment[captcha]' => '',
'drink_comment[user][firstname]' => 'Foo',
'drink_comment[user][lastname]' => 'Bar',
'drink_comment[user][email]' => '[email protected]',
'drink_comment[content]' => 'Super apéro.',
),
$data_overload
);
}

public function testCommentDrinkWithUnanonymousUser()
{
$this->assert
->if($client = $this->createClient())
->and($crawler = $client->request('GET', '/1/view.html'))
->then()
->boolean($client->getResponse()->isOk())->isTrue()
->integer($crawler->filter('blockquote')->count()-1)->isEqualTo(2)
->if($form = $crawler->selectButton('comment')->form())
->and($crawler = $client->submit($form, $this->getDefaultDatas()))
->then()
->dump($client->getResponse()->getContent())
->boolean($client->getResponse()->isRedirect('/1/view.html'))->isTrue()
->if($crawler = $client->followRedirect())
->then()
->boolean($client->getResponse()->isOk())->isTrue()
->integer($crawler->filter('div.alert-success')->count())->isEqualTo(1)
->integer($crawler->filter('blockquote')->count()-1)->isEqualTo(3)
;
}

public function testNewCommentDrink_withNoCaptcha_isNotCreated()
{
$this->assert
->if($client = $this->createClient())
->and($crawler = $client->request('GET', '/1/view.html'))
->then()
->boolean($client->getResponse()->isOk())->isTrue()
->integer($crawler->filter('blockquote')->count()-1)->isEqualTo(2)
->if($form = $crawler->selectButton('comment')->form())
->and($crawler = $client->submit($form, $this->getDefaultDatas(array('drink_comment[user][firstname]' => 'DO NOT FEED'))))
->then()
->boolean($client->getResponse()->isRedirect('/drink/1/view.html'))->isFalse()
;
}

public function testCommentDrinkWithNoData()
{
$this->assert
->if($client = $this->createClient())
->and($crawler = $client->request('GET', '/1/view.html'))
->then()
->boolean($client->getResponse()->isOk())->isTrue()
->integer($crawler->filter('blockquote')->count()-1)->isEqualTo(2)
->if($form = $crawler->selectButton('comment')->form())
->and($crawler = $client->submit($form, $this->getDefaultDatas(array(
'drink_comment[user][firstname]' => '',
'drink_comment[user][lastname]' => '',
'drink_comment[user][email]' => '',
'drink_comment[content]' => '',
))))
->then()
->boolean($client->getResponse()->isRedirect('/drink/1/view.html'))->isFalse()
;
}
}
Loading

0 comments on commit a806fe3

Please sign in to comment.