コード例 #1
0
 /**
  * testTranslateWithAssociations method
  *
  * @return void
  */
 public function testTranslateWithAssociations()
 {
     $this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User', 'Comment', 'ArticlesTag', 'Tag');
     $TestModel = new TranslatedArticle();
     $TestModel->locale = 'eng';
     $recursive = $TestModel->recursive;
     $result = $TestModel->read(null, 1);
     $expected = array('TranslatedArticle' => array('id' => 1, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'locale' => 'eng', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1'), 'User' => array('id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('all', array('recursive' => -1));
     $expected = array(array('TranslatedArticle' => array('id' => 1, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'locale' => 'eng', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1')), array('TranslatedArticle' => array('id' => 2, 'user_id' => 3, 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'locale' => 'eng', 'title' => 'Title (eng) #2', 'body' => 'Body (eng) #2')), array('TranslatedArticle' => array('id' => 3, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'locale' => 'eng', 'title' => 'Title (eng) #3', 'body' => 'Body (eng) #3')));
     $this->assertEquals($expected, $result);
     $this->assertEquals($TestModel->recursive, $recursive);
     $TestModel->recursive = -1;
     $result = $TestModel->read(null, 1);
     $expected = array('TranslatedArticle' => array('id' => 1, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'locale' => 'eng', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1'));
     $this->assertEquals($expected, $result);
 }
コード例 #2
0
 /**
  * Test that saveAll() works with hasMany associations that contain
  * translations.
  *
  * @return void
  */
 public function testSaveAllTranslatedAssociations()
 {
     $this->loadFixtures('Translate', 'TranslateArticle', 'TranslatedItem', 'TranslatedArticle', 'User');
     $Model = new TranslatedArticle();
     $Model->locale = 'eng';
     $data = array('TranslatedArticle' => array('user_id' => 1, 'published' => 'Y', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1'), 'TranslatedItem' => array(array('title' => 'Nuevo leyenda #1', 'content' => 'Upraveny obsah #1'), array('title' => 'New Title #2', 'content' => 'New Content #2')));
     $result = $Model->saveAll($data);
     $this->assertTrue($result);
     $result = $Model->TranslatedItem->find('all', array('conditions' => array('translated_article_id' => $Model->id)));
     $this->assertEqual(2, count($result));
     $this->assertEqual($data['TranslatedItem'][0]['title'], $result[0]['TranslatedItem']['title']);
     $this->assertEqual($data['TranslatedItem'][1]['title'], $result[1]['TranslatedItem']['title']);
 }