From 20ac85fd7cf661c4a96d37cda1676d06bca5c38d Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 19 Oct 2015 14:03:06 -0400 Subject: [PATCH] Added email/save tests. --- .../src/VuFindTest/Mink/CartTest.php | 114 ++++++++++++++++-- 1 file changed, 105 insertions(+), 9 deletions(-) diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php index e0312a9d963..b33c1ed39fc 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php @@ -160,6 +160,53 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase $this->assertEquals('Your Book Bag is empty.', $info->getText()); } + /** + * Assert that the "no items were selected" message is visible in the cart + * lightbox. + * + * @param Element $page + * + * @return void + */ + protected function checkForNonSelectedMessage(Element $page) + { + $warning = $page->find('css', '.modal-body .alert .message'); + $this->assertTrue(is_object($warning)); + $this->assertEquals( + 'No items were selected. ' + . 'Please click on a checkbox next to an item and try again.', + $warning->getText() + ); + } + + /** + * Assert that the "login required" message is visible in the cart lightbox. + * + * @param Element $page + * + * @return void + */ + protected function checkForLoginMessage(Element $page) + { + $warning = $page->find('css', '.modal-body .alert-danger'); + $this->assertTrue(is_object($warning)); + $this->assertEquals( + 'You must be logged in first', + $warning->getText() + ); + } + + /** + * Select all of the items currently in the cart lightbox. + * + * @param Element $page Page element + */ + protected function selectAllItemsInCart(Element $page) + { + $cartSelectAll = $page->find('css', '.modal-dialog .checkbox-select-all'); + $cartSelectAll->check(); + } + /** * Test that we can put items in the cart and then remove them with the * delete control. @@ -175,17 +222,10 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase // First try deleting without selecting anything: $delete->click(); - $warning = $page->find('css', '.modal-body .alert .message'); - $this->assertTrue(is_object($warning)); - $this->assertEquals( - 'No items were selected. ' - . 'Please click on a checkbox next to an item and try again.', - $warning->getText() - ); + $this->checkForNonSelectedMessage($page); // Now actually select the records to delete: - $cartSelectAll = $page->find('css', '.modal-dialog .checkbox-select-all'); - $cartSelectAll->check(); + $this->selectAllItemsInCart($page); $delete->click(); $deleteConfirm = $page->find('css', '#cart-confirm-delete'); $this->assertTrue(is_object($deleteConfirm)); @@ -231,4 +271,60 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase $session->stop(); } + + /** + * Test that the email control works. + * + * @return void + */ + public function testCartEmail() + { + $session = $this->getMinkSession(); + $session->start(); + $page = $this->setUpGenericCartTest($session); + $button = $page->find('css', '.cart-controls button[name=email]'); + + // First try clicking without selecting anything: + $button->click(); + $this->checkForNonSelectedMessage($page); + + // Now do it for real -- we should get a login prompt. + $this->selectAllItemsInCart($page); + $button->click(); + $title = $page->find('css', '#modalTitle'); + $this->assertEquals($title->getText(), 'Email Selected Book Bag Items'); + $this->checkForLoginMessage($page); + + // TODO: test actually logging in, etc. + + $session->stop(); + } + + /** + * Test that the save control works. + * + * @return void + */ + public function testCartSave() + { + $session = $this->getMinkSession(); + $session->start(); + $page = $this->setUpGenericCartTest($session); + $button = $page->find('css', '.cart-controls button[name=saveCart]'); + + // First try clicking without selecting anything: + $button->click(); + $this->checkForNonSelectedMessage($page); + + // Now do it for real -- we should get a login prompt. + $this->selectAllItemsInCart($page); + $button->click(); + $title = $page->find('css', '#modalTitle'); + $this->assertEquals($title->getText(), 'Save Selected Book Bag Items'); + $this->checkForLoginMessage($page); + + // TODO: test actually logging in, etc. + + $session->stop(); + } } -- GitLab