From d9f21174364ce6946f7863480acde2c8adc1d1b0 Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Fri, 7 Jul 2017 00:41:04 +0200 Subject: [PATCH] more unit tests --- .../Model/Behavior/TranslateBehaviorTest.php | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 80a9c5a45..37c42465b 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -1443,4 +1443,165 @@ class TranslateBehaviorTest extends CakeTestCase { $this->assertEquals('name', $results[0]['TranslateTestModel']['field']); } + public function testBeforeFindAllI18nConditions() { + $this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User'); + $TestModel = new TranslatedArticle(); + $TestModel->cacheQueries = false; + $TestModel->locale = 'eng'; + $expected = array( + 'conditions' => array( + 'NOT' => array('I18n__title.content' => ''), + ), + 'fields' => null, + 'joins' => array( + array( + 'type' => 'INNER', + 'alias' => 'I18n__title', + 'table' => (object)array( + 'tablePrefix' => '', + 'table' => 'article_i18n', + 'schemaName' => 'test', + ), + 'conditions' => array( + 'TranslatedArticle.id' => (object)array( + 'type' => 'identifier', + 'value' => 'I18n__title.foreign_key', + ), + 'I18n__title.model' => 'TranslatedArticle', + 'I18n__title.field' => 'title', + 'I18n__title.locale' => 'eng', + ), + ), + array( + 'type' => 'INNER', + 'alias' => 'I18n__body', + 'table' => (object)array( + 'tablePrefix' => '', + 'table' => 'article_i18n', + 'schemaName' => 'test', + ), + 'conditions' => array( + 'TranslatedArticle.id' => (object)array( + 'type' => 'identifier', + 'value' => 'I18n__body.foreign_key', + ), + 'I18n__body.model' => 'TranslatedArticle', + 'I18n__body.field' => 'body', + 'I18n__body.locale' => 'eng', + ), + ), + ), + 'limit' => 2, + 'offset' => null, + 'order' => array( + 'TranslatedArticle.id' => 'ASC', + ), + 'page' => 1, + 'group' => null, + 'callbacks' => true, + 'recursive' => 0, + ); + $query = array( + 'conditions' => array( + 'NOT' => array( + 'I18n__title.content' => '', + ), + ), + 'fields' => null, + 'joins' => array(), + 'limit' => 2, + 'offset' => null, + 'order' => array( + 'TranslatedArticle.id' => 'ASC', + ), + 'page' => 1, + 'group' => null, + 'callbacks' => true, + 'recursive' => 0, + ); + $TranslateBehavior = ClassRegistry::getObject('TranslateBehavior'); + $result = $TranslateBehavior->beforeFind($TestModel, $query); + $this->assertEquals($expected, $result); + } + + public function testBeforeFindCountI18nConditions() { + $this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User'); + $TestModel = new TranslatedArticle(); + $TestModel->cacheQueries = false; + $TestModel->locale = 'eng'; + $expected = array( + 'conditions' => array( + 'NOT' => array('I18n__title.content' => ''), + ), + 'fields' => 'COUNT(DISTINCT(`TranslatedArticle`.`id`)) AS count', + 'joins' => array( + array( + 'type' => 'INNER', + 'alias' => 'I18n__title', + 'table' => (object)array( + 'tablePrefix' => '', + 'table' => 'article_i18n', + 'schemaName' => 'test', + ), + 'conditions' => array( + 'TranslatedArticle.id' => (object)array( + 'type' => 'identifier', + 'value' => 'I18n__title.foreign_key', + ), + 'I18n__title.model' => 'TranslatedArticle', + 'I18n__title.field' => 'title', + 'I18n__title.locale' => 'eng', + ), + ), + array( + 'type' => 'INNER', + 'alias' => 'I18n__body', + 'table' => (object)array( + 'tablePrefix' => '', + 'table' => 'article_i18n', + 'schemaName' => 'test', + ), + 'conditions' => array( + 'TranslatedArticle.id' => (object)array( + 'type' => 'identifier', + 'value' => 'I18n__body.foreign_key', + ), + 'I18n__body.model' => 'TranslatedArticle', + 'I18n__body.field' => 'body', + 'I18n__body.locale' => 'eng', + ), + ), + ), + 'limit' => 2, + 'offset' => null, + 'order' => array( + 0 => false, + ), + 'page' => 1, + 'group' => null, + 'callbacks' => true, + 'recursive' => 0, + ); + $query= array( + 'conditions' => array( + 'NOT' => array( + 'I18n__title.content' => '', + ) + ), + 'fields' => 'COUNT(*) AS `count`', + 'joins' => array(), + 'limit' => 2, + 'offset' => null, + 'order' => array( + 0 => false + ), + 'page' => 1, + 'group' => null, + 'callbacks' => true, + 'recursive' => 0, + ); + $TranslateBehavior = ClassRegistry::getObject('TranslateBehavior'); + $result = $TranslateBehavior->beforeFind($TestModel, $query); + $this->assertEquals($expected, $result); + } }