/** * Test that an exception is raised when you try to over-write the name attribute. * * @expectedException CakeException * @return void */ public function testExceptionOnNameTranslation() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel = new TranslatedItem(); $TestModel->bindTranslation(array('name' => 'name')); }
/** * Test infinite loops not occuring with unbindTranslation() * * @return void */ public function testUnbindTranslationInfinteLoop() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel = new TranslatedItem(); $TestModel->Behaviors->detach('Translate'); $TestModel->actsAs = array(); $TestModel->Behaviors->attach('Translate'); $TestModel->bindTranslation(array('title', 'content'), true); $result = $TestModel->unbindTranslation(); $this->assertFalse($result); }
/** * Test that translations can be bound and unbound dynamically. * * @return void */ public function testUnbindTranslation() { $this->loadFixtures('Translate', 'TranslatedItem'); $Model = new TranslatedItem(); $Model->unbindTranslation(); $Model->bindTranslation(array('body', 'slug'), false); $result = $Model->Behaviors->Translate->settings['TranslatedItem']; $this->assertEquals(array('body', 'slug'), $result); $Model->unbindTranslation(array('body')); $result = $Model->Behaviors->Translate->settings['TranslatedItem']; $this->assertNotContains('body', $result); $Model->unbindTranslation('slug'); $result = $Model->Behaviors->Translate->settings['TranslatedItem']; $this->assertNotContains('slug', $result); }
/** * Test that additional records are not inserted for associated translations. * * @return void */ public function testNoExtraRowsForAssociatedTranslations() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel = new TranslatedItem(); $TestModel->locale = 'spa'; $TestModel->unbindTranslation(); $TestModel->bindTranslation(array('name' => 'nameTranslate')); $data = array('TranslatedItem' => array('slug' => 'spanish-name', 'name' => 'Spanish name')); $TestModel->create($data); $TestModel->save(); $Translate = $TestModel->translateModel(); $results = $Translate->find('all', array('conditions' => array('locale' => $TestModel->locale, 'foreign_key' => $TestModel->id))); $this->assertCount(1, $results, 'Only one field should be saved'); $this->assertEquals('name', $results[0]['TranslateTestModel']['field']); }
/** * testAttachDetach method * * @access public * @return void */ function testAttachDetach() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel = new TranslatedItem(); $Behavior = $this->Model->Behaviors->Translate; $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = array_keys($TestModel->hasMany); $expected = array('Title', 'Content'); $this->assertEqual($result, $expected); $TestModel->Behaviors->detach('Translate'); $result = array_keys($TestModel->hasMany); $expected = array(); $this->assertEqual($result, $expected); $result = isset($TestModel->Behaviors->Translate); $this->assertFalse($result); $result = isset($Behavior->settings[$TestModel->alias]); $this->assertFalse($result); $result = isset($Behavior->runtime[$TestModel->alias]); $this->assertFalse($result); $TestModel->Behaviors->attach('Translate', array('title' => 'Title', 'content' => 'Content')); $result = array_keys($TestModel->hasMany); $expected = array('Title', 'Content'); $this->assertEqual($result, $expected); $result = isset($TestModel->Behaviors->Translate); $this->assertTrue($result); $Behavior = $TestModel->Behaviors->Translate; $result = isset($Behavior->settings[$TestModel->alias]); $this->assertTrue($result); $result = isset($Behavior->runtime[$TestModel->alias]); $this->assertTrue($result); }