mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
more PaginatorComponent unit tests
This commit is contained in:
parent
1d1a762a37
commit
31fd4217b1
1 changed files with 95 additions and 1 deletions
|
@ -23,6 +23,8 @@ App::uses('PaginatorComponent', 'Controller/Component');
|
||||||
App::uses('CakeRequest', 'Network');
|
App::uses('CakeRequest', 'Network');
|
||||||
App::uses('CakeResponse', 'Network');
|
App::uses('CakeResponse', 'Network');
|
||||||
|
|
||||||
|
require_once dirname(dirname(dirname(__FILE__))) . DS . 'Model' . DS . 'models.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PaginatorTestController class
|
* PaginatorTestController class
|
||||||
*
|
*
|
||||||
|
@ -288,7 +290,8 @@ class PaginatorComponentTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $fixtures = array('core.post', 'core.comment', 'core.author');
|
public $fixtures = array('core.post', 'core.comment', 'core.author',
|
||||||
|
'core.translated_article', 'core.translate_article', 'core.user');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setup
|
* setup
|
||||||
|
@ -402,6 +405,97 @@ class PaginatorComponentTest extends CakeTestCase {
|
||||||
$this->assertSame(2, $Controller->params['paging']['PaginatorControllerPost']['count']);
|
$this->assertSame(2, $Controller->params['paging']['PaginatorControllerPost']['count']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPaginateNotCondition() {
|
||||||
|
$Controller = new PaginatorTestController($this->request);
|
||||||
|
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
|
||||||
|
$Controller->request->params['pass'] = array('1');
|
||||||
|
$Controller->request->query = array();
|
||||||
|
$Controller->constructClasses();
|
||||||
|
$Controller->Paginator->settings = array(
|
||||||
|
'conditions' => array(
|
||||||
|
'NOT' => array('PaginatorAuthor.user' => 'mariano'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||||
|
$this->assertEquals('larry', $result[0]['PaginatorAuthor']['user']);
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaginateI18nConditionUser() {
|
||||||
|
$Request = new CakeRequest('articles/index');
|
||||||
|
$Controller = new PaginatorTestController($Request);
|
||||||
|
$Controller->uses = array('TranslatedArticle');
|
||||||
|
$Controller->constructClasses();
|
||||||
|
$Controller->TranslatedArticle->locale = 'eng';
|
||||||
|
$Controller->Paginator->settings = array(
|
||||||
|
'recursive' => 0,
|
||||||
|
'conditions' => array(
|
||||||
|
'User.user' => 'mariano',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = $Controller->Paginator->paginate('TranslatedArticle');
|
||||||
|
$this->assertEquals('Title (eng) #1', $result[0]['TranslatedArticle']['title']);
|
||||||
|
$this->assertEquals('mariano', $result[0]['User']['user']);
|
||||||
|
$this->assertEquals('Title (eng) #3', $result[1]['TranslatedArticle']['title']);
|
||||||
|
$this->assertEquals('mariano', $result[1]['User']['user']);
|
||||||
|
$this->assertCount(2, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaginateI18nConditionTitle() {
|
||||||
|
$Request = new CakeRequest('articles/index');
|
||||||
|
$Controller = new PaginatorTestController($Request);
|
||||||
|
$Controller->uses = array('TranslatedArticle');
|
||||||
|
$Controller->constructClasses();
|
||||||
|
$Controller->TranslatedArticle->locale = 'eng';
|
||||||
|
$Controller->Paginator->settings = array(
|
||||||
|
'recursive' => 0,
|
||||||
|
'conditions' => array(
|
||||||
|
'I18n__title.content' => 'Title (eng) #3',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = $Controller->Paginator->paginate('TranslatedArticle');
|
||||||
|
$this->assertEquals('Title (eng) #3', $result[0]['TranslatedArticle']['title']);
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaginateI18nConditionNotTitle() {
|
||||||
|
$Request = new CakeRequest('articles/index');
|
||||||
|
$Controller = new PaginatorTestController($Request);
|
||||||
|
$Controller->uses = array('TranslatedArticle');
|
||||||
|
$Controller->constructClasses();
|
||||||
|
$Controller->TranslatedArticle->locale = 'eng';
|
||||||
|
$Controller->Paginator->settings = array(
|
||||||
|
'recursive' => 0,
|
||||||
|
'conditions' => array(
|
||||||
|
'I18n__title.content !=' => '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = $Controller->Paginator->paginate('TranslatedArticle');
|
||||||
|
$this->assertEquals('Title (eng) #1', $result[0]['TranslatedArticle']['title']);
|
||||||
|
$this->assertEquals('Title (eng) #2', $result[1]['TranslatedArticle']['title']);
|
||||||
|
$this->assertEquals('Title (eng) #3', $result[2]['TranslatedArticle']['title']);
|
||||||
|
$this->assertCount(3, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaginateI18nConditionNotTitleArraySyntax() {
|
||||||
|
$Request = new CakeRequest('articles/index');
|
||||||
|
$Controller = new PaginatorTestController($Request);
|
||||||
|
$Controller->uses = array('TranslatedArticle');
|
||||||
|
$Controller->constructClasses();
|
||||||
|
$Controller->TranslatedArticle->locale = 'eng';
|
||||||
|
$Controller->Paginator->settings = array(
|
||||||
|
'recursive' => 0,
|
||||||
|
'conditions' => array(
|
||||||
|
'NOT' => array('I18n__title.content' => ''),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = $Controller->Paginator->paginate('TranslatedArticle');
|
||||||
|
$this->assertEquals('Title (eng) #1', $result[0]['TranslatedArticle']['title']);
|
||||||
|
$this->assertEquals('Title (eng) #2', $result[1]['TranslatedArticle']['title']);
|
||||||
|
$this->assertEquals('Title (eng) #3', $result[2]['TranslatedArticle']['title']);
|
||||||
|
$this->assertCount(3, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that non-numeric values are rejected for page, and limit
|
* Test that non-numeric values are rejected for page, and limit
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue