-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd59cb1
commit a806fe3
Showing
4 changed files
with
81 additions
and
870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
; | ||
} | ||
} |
Oops, something went wrong.