Skip to content

Commit

Permalink
initial bdd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed Jan 13, 2011
1 parent 00d54ca commit a4fe93f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -31,3 +31,6 @@
[submodule "modules/vendo-admin"]
path = modules/vendo-admin
url = git://github.com/vendo/admin.git
[submodule "test/features/default"]
path = test/features/default
url = git://github.com/zombor/Goutte-for-Behat.git
6 changes: 6 additions & 0 deletions test/behat.yml
@@ -0,0 +1,6 @@
parameters:
behat.features.path: test/features/vendo

behat.steps.path:
- %behat.configuration.path%/features/vendo/steps
- %behat.configuration.path%/features/default/steps
1 change: 1 addition & 0 deletions test/features/default
Submodule default added at 04de68
Binary file added test/features/goutte.phar
Binary file not shown.
8 changes: 8 additions & 0 deletions test/features/vendo/cart.feature
@@ -0,0 +1,8 @@
Feature: Shopping cart management
Users can add, modify and delete things in their shopping cart

Scenario: Add item to cart
Given I am on /product/view/195
When I click the "Add to cart" link
Then I should see the "Shopping Cart" page
And there should be 1 item in my shopping cart
10 changes: 10 additions & 0 deletions test/features/vendo/checkout.feature
@@ -0,0 +1,10 @@
Feature: Shopping cart checkout
In order for users to get stuff, they have to pay for it

Scenario: Checkout fails with no data
Given there are items in my cart
When I go to /cart/index
And I click the "Checkout" link
Then I should see the "Checkout goes here" page
When I submit the form
Then I should see the "Checkout goes here" page
5 changes: 5 additions & 0 deletions test/features/vendo/steps/cartSteps.php
@@ -0,0 +1,5 @@
<?php

$steps->And('/^there should be (\d+) item in my shopping cart$/', function($world, $num) {
assertTrue(current($world->response->filter('.total_items')->extract(array('_text'))) == $num);
});
11 changes: 11 additions & 0 deletions test/features/vendo/steps/checkoutSteps.php
@@ -0,0 +1,11 @@
<?php

$steps->Given('/^there are items in my cart$/', function($world) {
$world->visit('cart/add?id=105');
assertTrue($world->response->filter('.total_items')->extract(array('_text')) > 0);
});

$steps->Then('/^I should see the "(.+)" page$/', function($world, $title) {
$text = $world->response->filter('div#content > h2')->extract(array('_text'));
assertSame(current($text), $title);
});
11 changes: 11 additions & 0 deletions test/features/vendo/steps/common.php
@@ -0,0 +1,11 @@
<?php

/*$steps->When('/^I click the (.+) link$/', function($world, $anchor_text) {
$link = $world->response->selectLink($anchor_text)->link();
$world->response = $world->client->click($link);
});*/

$steps->When('/^I submit the form$/', function($world) {
$form = $world->response->selectButton('Submit')->form();
$world->client->submit($form);
});
25 changes: 25 additions & 0 deletions test/features/vendo/support/env.php
@@ -0,0 +1,25 @@
<?php

// Init kohana
defined('APPPATH') ?: define('APPPATH', 'application/');
defined('MODPATH') ?: define('MODPATH', 'modules/');
defined('SYSPATH') ?: define('SYSPATH', 'system/');
defined('EXT') ?: define('EXT', '.php');

require_once APPPATH.'bootstrap.php';

require_once 'Zend/Registry.php';
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
require_once 'test/features/goutte.phar';

// Create WebClient behavior
$world->client = new \Goutte\Client;
$world->client->setServerParameters(array('HTTP_HOST' => 'vendo'));
$world->response = null;
$world->form = array();

// Helpful closures
$world->visit = function($link) use($world) {
$world->response = $world->client->request('GET', $link);
};

0 comments on commit a4fe93f

Please sign in to comment.