Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
codeliner committed Nov 26, 2013
2 parents 93def45 + 20661a8 commit 0654cd8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
49 changes: 49 additions & 0 deletions features/book_new_cargo.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Feature: Book new Cargo
In order to manage a transport of a Cargo
As a booking manager
I need to be able to book the Cargo on a Voyage with enough free capacity

@javascript
Scenario: Add a Cargo
Given I am on "application/cargo/add"
When I fill in "size" with "40"
And I click the submit button
Then the url should match "application/cargo/index"

@javascript
Scenario: Add a Voyage with low capacity
Given I am on "application/voyage/add"
When I fill in "voyage_number" with "LOW123"
And I fill in "name" with "Low Voyage"
And I fill in "capacity" with "30"
And I click the submit button
Then the url should match "application/voyage/index"

@javascript
Scenario: Add a Voyage with high capacity
Given I am on "application/voyage/add"
When I fill in "voyage_number" with "HIGH123"
And I fill in "name" with "High Voyage"
And I fill in "capacity" with "100"
And I click the submit button
Then the url should match "application/voyage/index"

@javascript
Scenario: Try to book Cargo on Voyage with not enough capacity
Given I am on "application/cargo/index"
When I click on first item in the list "cargo-list"
And I wait until I am on page "application/cargo/show"
And I select "LOW123" from "voyage_number"
And I click the submit button
Then the url should match "application/booking/booking"
And the response should contain "Voyage [LOW123] has not enough capacity"

@javascript
Scenario: Book Cargo on Voyage with enough capacity
Given I am on "application/cargo/index"
When I click on first item in the list "cargo-list"
And I wait until I am on page "application/cargo/show"
And I select "HIGH123" from "voyage_number"
And I click the submit button
Then the url should match "application/booking/booking"
And the response should contain "Cargo was successfully booked"
35 changes: 35 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,40 @@ public function iClickTheSubmitButton()
throw new \RuntimeException("Can not find the submit btn");
}
}

/**
* @When /^I click on first item in the list "([^"]*)"$/
*/
public function iClickOnFirstItemInTheList($arg1)
{
$session = $this->getSession();
$page = $session->getPage();

$ul = $page->find('css', '#cargo-list');

$li = $ul->find('css', 'li');

$li->find('css', 'a')->click();
}

/**
* @Given /^I wait until I am on page "(?P<page>[^"]+)"$/
*/
public function iWaitUntilIAmOnPage($page)
{
$matchingFound = false;

for($i=1;$i++;$i<=5) {
if (strpos($this->getSession()->getCurrentUrl(), $this->locatePath($page)) !== false) {
$matchingFound = true;
break;
}
sleep(1);
}

if (!$matchingFound) {
throw new \Exception('Stoped waiting, timelimit reached!');
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function bookNewCargo(Cargo\Cargo $cargo, Voyage\Voyage $voyage)
if (!$this->overbookingPolicy->isAllowed($cargo, $voyage)) {
throw new Exception\RuntimeException(
sprintf(
'Cargo <%s> can not be booked. Voyage <%s> has not enough capacity.',
'Cargo [%s] can not be booked. Voyage [%s] has not enough capacity.',
$cargo->getTrackingId()->toString(),
$voyage->getVoyageNumber()->toString()
)
Expand Down
2 changes: 1 addition & 1 deletion module/Application/view/application/cargo/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?php if (empty($this->cargos)): ?>
<p class="alert-danger"><?php echo $this->translate('The list is empty. You have to add a cargo first!'); ?></p>
<?php else: ?>
<ul>
<ul id="cargo-list">
<?php foreach ($this->cargos as $cargo): ?>
<li><a href="<?php echo $this->url('application/default/trackingid', array('controller' => 'cargo', 'action' => 'show', 'trackingid' => $cargo->getTrackingId()->toString())) ?>"><?php echo $cargo->getTrackingId() ?></a></li>
<?php endforeach; ?>
Expand Down

0 comments on commit 0654cd8

Please sign in to comment.