diff --git a/features/book_new_cargo.feature b/features/book_new_cargo.feature new file mode 100644 index 0000000..380b23b --- /dev/null +++ b/features/book_new_cargo.feature @@ -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" \ No newline at end of file diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 40f281b..cc350d1 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -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[^"]+)"$/ + */ + 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!'); + } + } } diff --git a/module/Application/src/Application/Service/BookingService.php b/module/Application/src/Application/Service/BookingService.php index 645c264..fe7fedd 100644 --- a/module/Application/src/Application/Service/BookingService.php +++ b/module/Application/src/Application/Service/BookingService.php @@ -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() ) diff --git a/module/Application/view/application/cargo/index.phtml b/module/Application/view/application/cargo/index.phtml index 7cb0e55..5d453e8 100644 --- a/module/Application/view/application/cargo/index.phtml +++ b/module/Application/view/application/cargo/index.phtml @@ -16,7 +16,7 @@ cargos)): ?>

translate('The list is empty. You have to add a cargo first!'); ?>

-