Fix totally incorrect test.

TranslateBehavior should never be overlapped with real fields.
It should only be used to add fields that don't exist on the parent
table.
This commit is contained in:
mark_story 2012-10-31 22:51:37 -04:00
parent 8035b37df2
commit 414e0a3484
2 changed files with 45 additions and 29 deletions

View file

@ -169,12 +169,12 @@ class TreeBehaviorScopedTest extends CakeTestCase {
public function testTranslatingTree() {
$this->Tree = new FlagTree();
$this->Tree->cacheQueries = false;
$this->Tree->Behaviors->attach('Translate', array('name'));
$this->Tree->Behaviors->attach('Translate', array('title'));
//Save
$this->Tree->locale = 'eng';
$data = array('FlagTree' => array(
'name' => 'name #1',
'title' => 'name #1',
'locale' => 'eng',
'parent_id' => null,
));
@ -182,7 +182,8 @@ class TreeBehaviorScopedTest extends CakeTestCase {
$result = $this->Tree->find('all');
$expected = array(array('FlagTree' => array(
'id' => 1,
'name' => 'name #1',
'title' => 'name #1',
'name' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
@ -191,15 +192,16 @@ class TreeBehaviorScopedTest extends CakeTestCase {
)));
$this->assertEquals($expected, $result);
//update existing record, same locale
// update existing record, same locale
$this->Tree->create();
$data['FlagTree']['name'] = 'Named 2';
$data['FlagTree']['title'] = 'Named 2';
$this->Tree->id = 1;
$this->Tree->save($data);
$result = $this->Tree->find('all');
$expected = array(array('FlagTree' => array(
'id' => 1,
'name' => 'Named 2',
'title' => 'Named 2',
'name' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
@ -208,51 +210,65 @@ class TreeBehaviorScopedTest extends CakeTestCase {
)));
$this->assertEquals($expected, $result);
//update different locale, same record
// update different locale, same record
$this->Tree->create();
$this->Tree->locale = 'deu';
$this->Tree->id = 1;
$data = array('FlagTree' => array(
'id' => 1,
'parent_id' => null,
'name' => 'namen #1',
'title' => 'namen #1',
'locale' => 'deu',
));
$this->Tree->save($data);
$this->Tree->locale = 'deu';
$result = $this->Tree->find('all');
$expected = array(array('FlagTree' => array(
'id' => 1,
'name' => 'namen #1',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'flag' => 0,
'locale' => 'deu',
)));
$expected = array(
array(
'FlagTree' => array(
'id' => 1,
'title' => 'namen #1',
'name' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'flag' => 0,
'locale' => 'deu',
)
)
);
$this->assertEquals($expected, $result);
//Save with bindTranslation
// Save with bindTranslation
$this->Tree->locale = 'eng';
$data = array(
'name' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
'parent_id' => null
);
$this->Tree->create($data);
$this->Tree->save();
$this->Tree->unbindTranslation();
$translations = array('name' => 'Name');
$translations = array('title' => 'Title');
$this->Tree->bindTranslation($translations, false);
$this->Tree->locale = array('eng', 'spa');
$result = $this->Tree->read();
$expected = array(
'FlagTree' => array('id' => 2, 'parent_id' => null, 'locale' => 'eng', 'name' => 'New title', 'flag' => 0, 'lft' => 3, 'rght' => 4),
'Name' => array(
array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'New title'),
array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'Nuevo leyenda')
'FlagTree' => array(
'id' => 2,
'parent_id' => null,
'locale' => 'eng',
'name' => '',
'title' => 'New title',
'flag' => 0,
'lft' => 3,
'rght' => 4
),
'Title' => array(
array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'title', 'content' => 'New title'),
array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Nuevo leyenda')
),
);
$this->assertEquals($expected, $result);

View file

@ -41,11 +41,11 @@ class FlagTreeFixture extends CakeTestFixture {
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer','key' => 'primary'),
'name' => array('type' => 'string','null' => false),
'id' => array('type' => 'integer','key' => 'primary'),
'name' => array('type' => 'string','null' => false),
'parent_id' => 'integer',
'lft' => array('type' => 'integer','null' => false),
'rght' => array('type' => 'integer','null' => false),
'flag' => array('type' => 'integer','null' => false, 'length' => 1, 'default' => 0)
'lft' => array('type' => 'integer','null' => false),
'rght' => array('type' => 'integer','null' => false),
'flag' => array('type' => 'integer','null' => false, 'length' => 1, 'default' => 0)
);
}