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,
@ -193,13 +194,14 @@ class TreeBehaviorScopedTest extends CakeTestCase {
// 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,
@ -215,44 +217,58 @@ class TreeBehaviorScopedTest extends CakeTestCase {
$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(
$expected = array(
array(
'FlagTree' => array(
'id' => 1,
'name' => 'namen #1',
'title' => 'namen #1',
'name' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'flag' => 0,
'locale' => 'deu',
)));
)
)
);
$this->assertEquals($expected, $result);
// 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);