Skip to content

Commit

Permalink
updating cart bdd tests to be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed Jan 21, 2011
1 parent 3c30b74 commit 926e0b8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/features/vendo/cart.feature
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
Feature: Shopping cart management
Users can add, modify and delete things in their shopping cart

Scenario: Create Test item
Given I create a test product

Scenario: Add item to cart
Given I am on /product/view/195
Given I am on the test product page
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

Scenario: Remove item to cart
Given I am on /product/view/195
Given I am on the test product page
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
When I check "delete[195]"
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 /product/view/195
Given I am on the test product page
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
When I fill in "new_quantity[195]" with "2"
When I update the quantity of "Test Product" to "2"
And I press "Delete Selected / Update Quantities"
Then there should be 2 items in my shopping cart
Then there should be 2 items in my shopping cart

Scenario: Delete Test item
Given I delete the test product
40 changes: 40 additions & 0 deletions test/features/vendo/steps/cartSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,44 @@

$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);
});

$steps->Given('/^I create a test product$/', function($world) {
$product = new Model_Vendo_Product;
$product->set_fields(
array(
'name' => 'Test Product',
'price' => 9.99,
'description' => 'BDD Test',
'order' => 1
)
);
$product->save();
});

$steps->Given('/^I delete the test product$/', function($world) {
$product = Model::factory('vendo_product')->load(
db::select()->where('name', '=', 'Test Product')
)->delete();
});

$steps->Given('/^I am on the test product page$/', function($world) {
$product = Model::factory('vendo_product')->load(
db::select()->where('name', '=', 'Test Product')
);
$world->visit('/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;
});

$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;
});

0 comments on commit 926e0b8

Please sign in to comment.