From 52ba63484548323ec4b28bbf9475f38f57727b5b Mon Sep 17 00:00:00 2001 From: Franco Springveldt Date: Fri, 2 Jun 2017 09:46:55 +1200 Subject: [PATCH] FIX continue browsing button not working correctly --- .../controllers/DMSCartAbstractController.php | 41 ++++++++++++++++ code/controllers/DMSCheckoutController.php | 23 +-------- .../controllers/DMSDocumentCartController.php | 25 +--------- templates/includes/DMSCartNavigation.ss | 2 +- .../DMSCartAbstractControllerTest.php | 47 +++++++++++++++++++ .../controllers/DMSCheckoutControllerTest.php | 26 ++++------ .../DMSDocumentCartControllerTest.php | 26 ++++------ 7 files changed, 109 insertions(+), 81 deletions(-) create mode 100644 code/controllers/DMSCartAbstractController.php create mode 100644 tests/controllers/DMSCartAbstractControllerTest.php diff --git a/code/controllers/DMSCartAbstractController.php b/code/controllers/DMSCartAbstractController.php new file mode 100644 index 0000000..99760f8 --- /dev/null +++ b/code/controllers/DMSCartAbstractController.php @@ -0,0 +1,41 @@ +get('Director', 'rules'))) { + // Check for slashes and drop them + if ($indexOf = stripos($url, '/')) { + $url = substr($url, 0, $indexOf); + } + return $this->join_links($url, $action); + } + } + + /** + * Retrieves a {@link DMSDocumentCart} instance + * + * @return DMSDocumentCart + */ + public function getCart() + { + return DMSDocumentCart::singleton(); + } + + /** + * Controls the `Continue browsing` link found in DMSCartNavigation.ss. Defaults all requests back to home. + * @return string + */ + public function getContinueBrowsingLink() + { + return Director::absoluteBaseURL(); + } +} diff --git a/code/controllers/DMSCheckoutController.php b/code/controllers/DMSCheckoutController.php index bb0e93f..fdfea7c 100644 --- a/code/controllers/DMSCheckoutController.php +++ b/code/controllers/DMSCheckoutController.php @@ -1,6 +1,6 @@ customise($data)->renderWith('Page'); } - /** - * Retrieves a {@link DMSDocumentCart} instance - * - * @return DMSDocumentCart - */ - public function getCart() - { - return singleton('DMSDocumentCart'); - } - /** * Updates the cart receiver info just before the request is sent. * @@ -207,17 +197,6 @@ public function updateCartReceiverInfo($data) $this->getCart()->setReceiverInfo($info); } - /** - * Ensure that links for this controller use the customised route - * - * @param string $action - * @return string - */ - public function Link($action = null) - { - return $this->join_links('checkout', $action); - } - /** * If BCC email addresses are configured, return the addresses to send to in comma delimited format * diff --git a/code/controllers/DMSDocumentCartController.php b/code/controllers/DMSDocumentCartController.php index 1258e6e..dad92b9 100644 --- a/code/controllers/DMSDocumentCartController.php +++ b/code/controllers/DMSDocumentCartController.php @@ -1,6 +1,6 @@ 'handleAction', @@ -161,16 +161,6 @@ public function remove(SS_HTTPRequest $request) return $this->redirectBack(); } - /** - * Retrieves a {@link DMSDocumentCart} instance - * - * @return DMSDocumentCart - */ - public function getCart() - { - return singleton('DMSDocumentCart'); - } - /** * Validates a request to add a document to the cart * @@ -287,17 +277,4 @@ public function DMSCartEditForm() $this->extend('updateDMSCartEditForm', $form); return $form; } - - /** - * Ensure that links for this controller use the customised route - * - * @param string $action - * @return string - */ - public function Link($action = null) - { - if ($url = array_search(__CLASS__, (array)Config::inst()->get('Director', 'rules'))) { - return $this->join_links($url, $action); - } - } } diff --git a/templates/includes/DMSCartNavigation.ss b/templates/includes/DMSCartNavigation.ss index 0c33ec8..d3a125c 100644 --- a/templates/includes/DMSCartNavigation.ss +++ b/templates/includes/DMSCartNavigation.ss @@ -1,5 +1,5 @@
- + <%t DMSDocumentCart.CONTINUE_BROWSING "Continue browsing" %>

<%t DMSDocumentCart.REQUEST_FORM_HEADING "Your request in summary" %>

diff --git a/tests/controllers/DMSCartAbstractControllerTest.php b/tests/controllers/DMSCartAbstractControllerTest.php new file mode 100644 index 0000000..2aaf3c0 --- /dev/null +++ b/tests/controllers/DMSCartAbstractControllerTest.php @@ -0,0 +1,47 @@ +controller = DMSCartAbstractController::create(); + } + + /** + * Ensure the link is "friendly", not a class name + */ + public function testLink() + { + $this->assertNull($this->controller->Link()); + } + + /** + * Tests if a Cart is received + */ + public function testGetCart() + { + // Callable from base class + $this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart()); + } + + /** + * Controls the `Continue browsing` link found in DMSCartNavigation.ss. Defaults all requests back to home. + * @return string + */ + public function testGetContinueBrowsingLink() + { + // Base instance returns something + $this->assertSame(Director::absoluteBaseURL(), $this->controller->getContinueBrowsingLink()); + } +} diff --git a/tests/controllers/DMSCheckoutControllerTest.php b/tests/controllers/DMSCheckoutControllerTest.php index bc84e34..8350a05 100644 --- a/tests/controllers/DMSCheckoutControllerTest.php +++ b/tests/controllers/DMSCheckoutControllerTest.php @@ -47,14 +47,6 @@ public function testDMSDocumentRequestFormIsExtensible() ); } - /** - * Tests if a Cart is received - */ - public function testGetCart() - { - $this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart()); - } - /** * Tests whether the recipient details are updated from the controller */ @@ -144,15 +136,6 @@ public function testCompletePage() $this->assertContains('You will receive a confirmation email', $result); } - /** - * Ensure the link is "friendly", not a class name - */ - public function testLink() - { - $this->assertSame('checkout', $this->controller->Link()); - $this->assertSame('checkout/complete', $this->controller->Link('complete')); - } - /** * Test that the items in my cart are listed on the checkout page, and that some form fields exist */ @@ -172,4 +155,13 @@ public function testIndexCheckoutForm() $this->assertContains('Doc3', $body); $this->assertContains('Receiver Name', $body); } + + /** + * Ensure the link is "friendly", not a class name + */ + public function testLink() + { + $this->assertSame('checkout', $this->controller->Link()); + $this->assertSame('checkout/complete', $this->controller->Link('complete')); + } } diff --git a/tests/controllers/DMSDocumentCartControllerTest.php b/tests/controllers/DMSDocumentCartControllerTest.php index 37a412b..dadcd44 100644 --- a/tests/controllers/DMSDocumentCartControllerTest.php +++ b/tests/controllers/DMSDocumentCartControllerTest.php @@ -153,13 +153,6 @@ public function testRemove() $this->assertJson($response, 'Confirmed that an ajax call to remove() method responded with JSON'); } - public function testCart() - { - $this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart()); - //For good measure assert it's empty - $this->assertTrue($this->controller->getIsCartEmpty()); - } - /** * Ensure that a validation error is shown when requesting to add more of a document that is allowed */ @@ -223,16 +216,6 @@ public function testUpdateCartItems() $this->assertEquals(5, $this->cart->getItem($item->getItemId())->getQuantity()); } - /** - * Ensure the link is "friendly", not a class name - */ - public function testLink() - { - $this->assertSame('documentcart', $this->controller->Link()); - $this->assertSame('documentcart/view', $this->controller->Link('view')); - } - - /** * Tests DMSCartEditForm form has a FieldList */ @@ -264,4 +247,13 @@ public function testView() $this->assertInstanceOf('SS_HTTPResponse', $result); $this->assertContains('Updating cart items', $result->getBody()); } + + /** + * Ensure the link is "friendly", not a class name + */ + public function testLink() + { + $this->assertSame('documentcart', $this->controller->Link()); + $this->assertSame('documentcart/view', $this->controller->Link('view')); + } }