/** * test that mock classes injected into paginatorHelper are called when using link() * * @expectedException CakeException * @return void */ public function testMockAjaxProviderClassInjection() { $mock = $this->getMock('PaginatorHelper', array(), array($this->View), 'PaginatorMockJsHelper'); $Paginator = new PaginatorHelper($this->View, array('ajax' => 'PaginatorMockJs')); $Paginator->request->params['paging'] = array('Article' => array('current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, 'defaults' => array(), 'options' => array(), 'paramType' => 'named')); $Paginator->PaginatorMockJs = $mock; $Paginator->PaginatorMockJs->expects($this->once())->method('link'); $Paginator->link('Page 2', array('page' => 2), array('update' => '#content')); new PaginatorHelper($this->View, array('ajax' => 'Form')); }
/** * Taken from Cake PaginatorHelper, extended to apply active class automatically * * Generates a plain or Ajax link with pagination parameters * * ### Options * * - `update` The Id of the DOM element you wish to update. Creates Ajax enabled links * with the AjaxHelper. * - `escape` Whether you want the contents html entity encoded, defaults to true * - `model` The model to use, defaults to PaginatorHelper::defaultModel() * * @param string $title Title for the link. * @param string|array $url Url for the action. See Router::url() * @param array $options Options for the link. See #options for list of keys. * @return string A link with pagination parameters. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::link */ public function link($title, $url = array(), $options = array()) { $named = $this->params['named']; unset($named['sort'], $named['direction'], $named['page']); if (count($url)) { //add a null value to named array if it does not exists and is null in url foreach ($url as $key => $value) { if (is_null($value) && !isset($named[$key])) { $named[$key] = $url[$key]; } } //check if the url array is contained entirely within the named array $match = count($url) == count(array_intersect_assoc($url, $named)); if ($match) { if (isset($options['class']) && !empty($options['class'])) { $options['class'] .= ' active btn-success'; } else { $options['class'] = 'active btn-success'; } } } return parent::link($title, $url, $options); }