Skip to content

Commit

Permalink
BDD Tests: Getting tests working with newest behat
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed Jul 5, 2011
1 parent 04db19e commit df54686
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 41 deletions.
28 changes: 22 additions & 6 deletions test/behat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
paths:
features: %behat.paths.base%/vendo
support: %behat.paths.base%/vendo/support
steps:
- %behat.paths.base%/vendo/steps
- %behat.paths.base%/default/steps
#paths:
# features: %behat.paths.base%/vendo
# support: %behat.paths.base%/vendo/support
# steps:
# - %behat.paths.base%/vendo/steps
# - %behat.paths.base%/default/steps

default:
# formatter:
# name: progress
environment:
parameters:
start_url: http://vendo/

paths:
features: '%%BEHAT_BASE_PATH%%/vendo'
support: '%%BEHAT_BASE_PATH%%/vendo/support'
steps:
- '%%BEHAT_BASE_PATH%%/vendo/steps'

imports:
- mink/behat.yml
12 changes: 6 additions & 6 deletions test/features/vendo/cart.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ Feature: Shopping cart management
Given I create a test product

Scenario: Add item to cart
Given I am on the test product page
When I click the "Add to cart" link
Given I visit the test product page
When I follow "Add to cart"
Then I should see the "Shopping Cart" page
And there should be 1 item in my shopping cart

Scenario: Remove item to cart
Given I am on the test product page
When I click the "Add to cart" link
Given I visit the test product page
When I follow "Add to cart"
Then I should see the "Shopping Cart" page
And there should be 1 item in my shopping cart
When I check the delete checkbox for "Test Product"
And I press "Delete Selected / Update Quantities"
Then there should be 0 items in my shopping cart

Scenario: Change quantity of item to cart
Given I am on the test product page
When I click the "Add to cart" link
Given I visit the test product page
When I follow "Add to cart"
Then I should see the "Shopping Cart" page
And there should be 1 item in my shopping cart
When I update the quantity of "Test Product" to "2"
Expand Down
2 changes: 1 addition & 1 deletion test/features/vendo/checkout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Shopping cart checkout
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
And I follow "Checkout"
Then I should see "Checkout goes here"
When I press "Submit Order"
Then I should see "Checkout goes here"
10 changes: 10 additions & 0 deletions test/features/vendo/core.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@code
Feature: Ensure core classes function properly

# Scenario: I can read a product's variants
# Given the following product exists:
# | name | price | description | order |
# | Foo | 9.99 | This is a test | 1 |
# And the following variant exists
# | name | price | description | order |
# | Foo - Var | | | |
12 changes: 7 additions & 5 deletions test/features/vendo/steps/cartSteps.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

$steps->And('/^there should be (\d+) item|items in my shopping cart$/', function($world, $num) {
assertTrue(current($world->response->filter('.total_items')->extract(array('_text'))) == $num);
$node = $world->getSession()->getPage()->find('xpath', '//td[@id="total_items"]');

assertTrue($node->getText() == $num);
});

$steps->Given('/^I create a test product$/', function($world) {
Expand All @@ -24,23 +26,23 @@
)->delete();
});

$steps->Given('/^I am on the test product page$/', function($world) {
$steps->Given('/^I visit the test product page$/', function($world) {
$product = Model::factory('vendo_product')->load(
db::select()->where('name', '=', 'Test Product')
);
$world->visit('/product/view/'.$product->id);
$world->getSession()->visit($world->getPathTo('/product/view/'.$product->id));
});

$steps->When('/^I check the delete checkbox for "([^"]*)"$/', function($world, $product_name) {
$product = Model::factory('vendo_product')->load(
db::select()->where('name', '=', $product_name)
);
$world->inputFields['delete['.$product->id.']'] = true;
$world->getSession()->getDriver()->check('//input[@name="delete['.$product->id.']"]');
});

$steps->When('/^I update the quantity of "([^"]*)" to "(\d+)"$/', function($world, $product_name, $num) {
$product = Model::factory('vendo_product')->load(
db::select()->where('name', '=', $product_name)
);
$world->inputFields['new_quantity['.$product->id.']'] = $num;
$world->getSession()->getDriver()->setValue('//input[@name="new_quantity['.$product->id.']"]', $num);
});
13 changes: 9 additions & 4 deletions test/features/vendo/steps/checkoutSteps.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?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);
$product = Model::factory('vendo_product')->load(
db::select()->where('name', '=', 'Foobar')
);
$world->getSession()->visit('/cart/add?id='.$product->id);
$node = $world->getSession()->getPage()->find('xpath', '//td[@id="total_items"]');

assertTrue($node->getText() > 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);
$node = $world->getSession()->getPage()->find('xpath', '//div[@id="content"]/h2');
assertSame($title, $node->getText());
});
2 changes: 1 addition & 1 deletion test/features/vendo/steps/googleCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}
catch (Payment_Exception $e)
{
throw new \Everzet\Behat\Exception\Pending('No Internet Connection!');
throw new \Behat\Behat\Exception\Pending('No Internet Connection!');
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/features/vendo/steps/userSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

$steps->Given('/^I log in$/', function($world) use($steps) {
$steps->Given('I am logged out', $world);
$steps->When('I click the "Login" link', $world);
$steps->When('I follow "Login"', $world);
$steps->And('I fill in "email" with "[email protected]"', $world);
$steps->And('I fill in "password" with "test"', $world);
$steps->And('I press "Login"', $world);
Expand Down
12 changes: 12 additions & 0 deletions test/features/vendo/support/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

// Init kohana
require_once '../modules/unittest/bootstrap.php';

require_once 'mink/autoload.php';
require_once 'Zend/Registry.php';
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';

// Ignore facebook html errors
libxml_use_internal_errors(true);
17 changes: 2 additions & 15 deletions test/features/vendo/support/env.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
<?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 'features/goutte.phar';
<?php

// Create WebClient behavior
$world->client = new \Goutte\Client;
Expand All @@ -37,7 +24,7 @@
}
catch (Exception $e)
{
var_dump('Couldn\'t delete a model: '.$e->getMessage());
//var_dump('Couldn\'t delete a model: '.$e->getMessage());
}
},
$world);
4 changes: 2 additions & 2 deletions test/features/vendo/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: User management

Scenario: register
Given I am logged out
When I click the "Register" link
When I follow "Register"
And I fill out the registration form
And I press "Submit"
Then I should be logged in
Expand All @@ -16,7 +16,7 @@ Feature: User management
Scenario: logout
Given I log in
Then I should be logged in
When I click the "Logout" link
When I follow "Logout"
Then I should be logged out

Scenario: delete registered user
Expand Down

0 comments on commit df54686

Please sign in to comment.