Skip to content
Permalink
Browse files

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.
  • Loading branch information...
markstory committed Nov 1, 2012
1 parent 8035b37 commit 414e0a34848b2f9d90f7135dfc63ca2b6050e316
@@ -169,20 +169,21 @@ public function testMoveDownWithScope() {
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,
));
$this->Tree->save($data);
$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 @@ public function testTranslatingTree() {
)));
$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 @@ public function testTranslatingTree() {
)));
$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);
@@ -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)
);
}

0 comments on commit 414e0a3

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.