Skip to content

Commit

Permalink
Add test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 14, 2018
1 parent 0909c87 commit f256760
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/View/Helper/SearchHelper.php
Expand Up @@ -33,8 +33,8 @@ class SearchHelper extends Helper
/**
* Checks for pagination and if so, blacklist limit and page params.
*
* @param \Cake\View\View $View
* @param array $config
* @param \Cake\View\View $View View
* @param array $config Config
*/
public function __construct(View $View, array $config)
{
Expand Down
29 changes: 25 additions & 4 deletions tests/TestCase/View/Helper/SearchHelperTest.php
Expand Up @@ -2,6 +2,7 @@
namespace Search\Test\View\Helper;

use Cake\Http\ServerRequest;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\View\View;
Expand All @@ -28,11 +29,18 @@ public function setUp()
{
parent::setUp();

Router::reload();

$this->view = new View();
$config = [];
$this->searchHelper = new SearchHelper($this->view, $config);

Router::$initialized = true;
Router::scope('/', function (RouteBuilder $routes) {
$routes->connect(
'/controller/action',
['controller' => 'Controller', 'action' => 'action']
);
$routes->fallbacks();
});
}

/**
Expand Down Expand Up @@ -139,9 +147,22 @@ public function testResetUrlWithPaginatorAndAdditionalBlacklist()
/**
* @return void
*/
public function _testResetLink()
public function testResetLink()
{
$request = new ServerRequest('/controller/action?page=2&limit=5&sort=x&direction=asc&foo=bar');

$this->view = new View($request);
$config = [];
$this->searchHelper = new SearchHelper($this->view, $config);

$params = [
'foo' => 'bar',
];
$this->view->set('_searchParams', $params);

$result = $this->searchHelper->resetLink('Reset search filter', ['class' => 'button']);
dd($result);

$expected = '<a href="/?page=2&amp;limit=5&amp;sort=x&amp;direction=asc" class="button">Reset search filter</a>';
$this->assertSame($expected, $result);
}
}

0 comments on commit f256760

Please sign in to comment.