-
-
Save jubianchi/4336789 to your computer and use it in GitHub Desktop.
This is an example usage of the AtoumBundle RFC with an improved syntax matching atoum's standards. https://github.com/atoum/AtoumBundle/pull/8
https://github.com/atoum/AtoumBundle/issues/15
This file contains hidden or 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
<?php | |
namespace Acme\DemoBundle\Tests\Controller; | |
require_once __DIR__ . '/../../../../vendor/autoload.php'; | |
require_once __DIR__ . '/../../../../vendor/atoum/atoum/scripts/runner.php'; | |
use atoum\AtoumBundle\Test\Controller; | |
class DemoController extends Controller\ControllerTest | |
{ | |
public function testIndexAction() | |
{ | |
$this | |
->request(array('debug' => true)) | |
->GET('/demo') | |
->hasStatus(301) | |
->GET('/demo/') | |
->hasStatus(200) | |
->hasCharset('UTF-8') | |
->hasVersion('1.1') | |
; | |
} | |
public function testContactActionWithActualSyntax() | |
{ | |
$this | |
->request(array('debug' => true)) | |
->GET('/demo/contact' . uniqid()) | |
->hasStatus(404) | |
->hasCharset('UTF-8') | |
->hasVersion('1.1') | |
->POST('/demo/contact') | |
->hasStatus(200) | |
->hasHeader('Content-Type', 'text/html; charset=UTF-8') | |
->crawler | |
->hasElement('#contact_form')->exactly(1) | |
->hasChild('input')->exactly(3)->end() | |
->hasChild('input') | |
->withAttribute('type', 'email') | |
->withAttribute('name', 'contact[email]') | |
->end() | |
->hasChild('input[type=submit]') | |
->withAttribute('value', 'Send') | |
->end() | |
->hasChild('textarea')->end() | |
->end() | |
->hasElement('li') | |
->withContent('The CSRF token is invalid. Please try to resubmit the form.') | |
->exactly(1) | |
->end() | |
; | |
} | |
public function testContactActionWithProposedSyntax() | |
{ | |
$this | |
->request(array('debug' => true)) | |
->GET('/demo/contact' . uniqid()) | |
->hasStatus(404) | |
->hasCharset('UTF-8') | |
->hasVersion('1.1') | |
->POST('/demo/contact') | |
->hasStatus(200) | |
->hasHeader('Content-Type', 'text/html; charset=UTF-8') | |
->crawler | |
->hasElement('#contact_form') | |
->hasChild('input')->exactly(3) | |
->hasChild('textarea')->isEmpty() // Automatically fallback to ->atLeast(1) | |
->hasChild('input[type=submit]')->exactly(1) | |
->hasChild('input[type=email][name="email"contact[email]"]')->exactly(1) | |
->hasChild('input[type=submit]')->exactly(1) | |
->crawler // As we request the Crawler, ->atLeast(1) is implicitly called | |
->hasElement('h1')->withContent('Contact') | |
->crawler | |
->hasElement('small')->withContent('Send us a message') | |
->parent() // Close the crawler, setting the scope back to #contact_form children | |
->parent() // Close the crawler, setting the scope back to #contact_form element | |
->exactly(1) // Refers to #contact_form | |
->hasElement('li')->exactly(1) | |
->withContent('The CSRF token is invalid. Please try to resubmit the form.') | |
->exactly(1) | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This PR was merged (atoum/AtoumBundle#8).
This gist is now related to the discussion under issue #15 (atoum/AtoumBundle#15)