Skip to content

Commit

Permalink
Merge pull request #35 from creative-commoners/issue/32
Browse files Browse the repository at this point in the history
FIX continue browsing button not working correctly
  • Loading branch information
sachajudd committed Jun 6, 2017
2 parents 87a4b0c + 52ba634 commit 824833f
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 81 deletions.
41 changes: 41 additions & 0 deletions code/controllers/DMSCartAbstractController.php
@@ -0,0 +1,41 @@
<?php

class DMSCartAbstractController extends ContentController
{
/**
* Ensure that links for this controller use the customised route.
* Searches through the rules set up for the class and returns the first route.
*
* @param string $action
* @return string
*/
public function Link($action = null)
{
if ($url = array_search(get_called_class(), (array)Config::inst()->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();
}
}
23 changes: 1 addition & 22 deletions code/controllers/DMSCheckoutController.php
@@ -1,6 +1,6 @@
<?php

class DMSCheckoutController extends ContentController
class DMSCheckoutController extends DMSCartAbstractController
{
private static $allowed_actions = array(
'DMSDocumentRequestForm',
Expand Down Expand Up @@ -186,16 +186,6 @@ public function complete()
return $this->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.
*
Expand All @@ -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
*
Expand Down
25 changes: 1 addition & 24 deletions code/controllers/DMSDocumentCartController.php
@@ -1,6 +1,6 @@
<?php

class DMSDocumentCartController extends ContentController
class DMSDocumentCartController extends DMSCartAbstractController
{
private static $url_handlers = array(
'$Action//$ID' => 'handleAction',
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion templates/includes/DMSCartNavigation.ss
@@ -1,5 +1,5 @@
<div>
<a id='continueBrowsing' class='button alt' href='$Controller.getCart.BackUrl()'>
<a id='continueBrowsing' class='button alt' href='$Controller.ContinueBrowsingLink()'>
<%t DMSDocumentCart.CONTINUE_BROWSING "Continue browsing" %></a>
<h4><%t DMSDocumentCart.REQUEST_FORM_HEADING "Your request in summary" %></h4>
</div>
47 changes: 47 additions & 0 deletions tests/controllers/DMSCartAbstractControllerTest.php
@@ -0,0 +1,47 @@
<?php

/**
* Class DMSDocumentCartControllerTest contains all the tests for {@link DMSDocumentCartController}
*/
class DMSCartAbstractControllerTest extends FunctionalTest
{
protected static $fixture_file = 'dms-cart/tests/DMSDocumentCartTest.yml';

/**
* @var DMSCartAbstractController
*/
protected $controller;

public function setUp()
{
parent::setUp();
$this->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());
}
}
26 changes: 9 additions & 17 deletions tests/controllers/DMSCheckoutControllerTest.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -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'));
}
}
26 changes: 9 additions & 17 deletions tests/controllers/DMSDocumentCartControllerTest.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit 824833f

Please sign in to comment.