Skip to content
Permalink
Browse files

Fixing failing tests in PaginatorHelper and moving tests related to J…

…sHelper interaction into a separate test method.
  • Loading branch information...
markstory committed Apr 24, 2010
1 parent 999eb4b commit bf566e1aada11a8c823bb5b2afc06560dee1736f
Showing with 27 additions and 18 deletions.
  1. +4 −2 cake/libs/view/helpers/paginator.php
  2. +23 −16 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -94,8 +94,10 @@ function __construct($config = array()) {
App::import('Helper', $ajaxProvider);
$classname = $ajaxProvider . 'Helper';
if (!is_callable(array($classname, 'link'))) {
trigger_error(sprintf(__('%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname), E_USER_WARNING);
if (!method_exists($classname, 'link')) {
throw new Exception(sprintf(
__('%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname
));
}
}
@@ -17,7 +17,7 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Helper', array('Html', 'Paginator', 'Form', 'Ajax', 'Javascript', 'Js'));
App::import('Helper', array('Html', 'Paginator', 'Form', 'Js'));
Mock::generate('JsHelper', 'PaginatorMockJsHelper');
@@ -36,7 +36,7 @@ class PaginatorHelperTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->Paginator = new PaginatorHelper(array('ajax' => 'Ajax'));
$this->Paginator = new PaginatorHelper();
$this->Paginator->params['paging'] = array(
'Article' => array(
'current' => 9,
@@ -57,11 +57,8 @@ function setUp() {
)
)
);
$this->Paginator->Html =& new HtmlHelper();
$this->Paginator->Ajax =& new AjaxHelper();
$this->Paginator->Ajax->Html =& new HtmlHelper();
$this->Paginator->Ajax->Javascript =& new JavascriptHelper();
$this->Paginator->Ajax->Form =& new FormHelper();
$this->Paginator->Html = new HtmlHelper();
$this->Paginator->Js = new PaginatorMockJsHelper();
Configure::write('Routing.prefixes', array());
Router::reload();
@@ -134,7 +131,7 @@ function testSortLinks() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
));
$this->Paginator->options(array('url' => array('param')));
@@ -154,10 +151,6 @@ function testSortLinks() {
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('modulus'=> '2', 'url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list'));
$this->assertPattern('/\/projects\/sort\/page:2/', $result);
$this->assertPattern('/<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*Event.observe/', $result);
$result = $this->Paginator->sort('TestTitle', 'title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
@@ -1832,13 +1825,27 @@ function testNextLinkUsingDotNotation() {
$this->assertTags($result, $expected);
}
/**
* Ensure that the internal link class object is called when the update key is present
*
* @return void
*/
function testAjaxLinkGeneration() {
$this->Paginator->Js->expectCallCount('link', 2);
$result = $this->Paginator->numbers(array(
'modulus'=> '2',
'url'=> array('controller' => 'projects', 'action' => 'sort'),
'update' => 'list'
));
}
/**
* test that mock classes injected into paginatorHelper are called when using link()
*
* @return void
*/
function testMockAjaxProviderClassInjection() {
$Paginator =& new PaginatorHelper(array('ajax' => 'PaginatorMockJs'));
$Paginator = new PaginatorHelper(array('ajax' => 'PaginatorMockJs'));
$Paginator->params['paging'] = array(
'Article' => array(
'current' => 9,
@@ -1850,12 +1857,12 @@ function testMockAjaxProviderClassInjection() {
'options' => array()
)
);
$Paginator->PaginatorMockJs =& new PaginatorMockJsHelper();
$Paginator->PaginatorMockJs = new PaginatorMockJsHelper();
$Paginator->PaginatorMockJs->expectOnce('link');
$result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content'));
$this->expectError();
$Paginator =& new PaginatorHelper(array('ajax' => 'Form'));
$this->expectException();
$Paginator = new PaginatorHelper(array('ajax' => 'Form'));
}
}
?>

0 comments on commit bf566e1

Please sign in to comment.
You can’t perform that action at this time.