public function testDeletePost() { $post = Post::findOne(2); $this->assertEquals(1, $post->delete()); $dataSet = $this->getConnection()->createDataSet(['post', 'postLang']); $expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/data/test-delete-post-na.xml'); $this->assertDataSetsEqual($expectedDataSet, $dataSet); }
public function testPostHasTranslation() { $post = new Post(); $this->assertFalse($post->hasTranslation()); $this->assertFalse($post->hasTranslation('en-US')); $post = Post::findOne(2); $this->assertTrue($post->hasTranslation()); $this->assertTrue($post->hasTranslation('en-US')); $this->assertTrue($post->hasTranslation('de-DE')); $this->assertTrue($post->hasTranslation('ru-RU')); }
public function testSetStringValue() { /** @var Post $post */ $post = Post::findOne(2); $post->attachBehavior('target-tags', ['class' => Target::className(), 'targetAttribute' => 'tagNames', 'delimiter' => false]); $this->assertEquals(['tag 2', 'tag 3', 'tag 4'], $post->tagNames); $post->tagNames = 'test'; $this->assertEquals(['test'], $post->tagNames); $post->tagNames = 'test, test2, test3'; $this->assertEquals(['test, test2, test3'], $post->tagNames); }
public function testValidatePost() { /** @var Post $post */ $post = Post::findOne(2); $post->attachBehavior('target-tags', ['class' => Target::className(), 'targetAttribute' => 'tagNames', 'beforeLink' => function ($tag) { /** @var Tag $tag */ $tag->frequency = 'aaa'; }]); $post->tagNames = ['tag 3', 'tag 6', 'mega long tag name']; $this->assertEquals(false, $post->save()); $this->assertEquals(['tagNames' => ['[tag 6] Frequency must be an integer.', '[mega long tag name] Name should contain at most 6 characters.', '[mega long tag name] Frequency must be an integer.']], $post->getErrors()); }
public function testCurrentTranslateRelations() { Yii::$app->language = 'ru-RU'; /** @var Post $model */ $model = Post::findOne(1); $this->assertTrue(count($model->currentTranslate) == 2); $data = array_keys($model->currentTranslate); $expectedData = ['en', 'ru']; $this->assertEquals($data, $expectedData); $this->assertTrue($model->hasTranslate()); Yii::$app->language = 'fr-FR'; /** @var Post $model */ $model = Post::findOne(1); $this->assertTrue(count($model->currentTranslate) == 1); $data = array_keys($model->currentTranslate); $expectedData = ['en']; $this->assertEquals($data, $expectedData); $this->assertFalse($model->hasTranslate()); }
public function testAttributeChanged() { /** @var Post $model */ $model = Post::findOne(1); $this->assertFalse($model->isAttributeChanged('titleLang')); $this->assertFalse($model->isAttributeChanged('status_id')); $model->titleLang = 'test'; $this->assertTrue($model->isAttributeChanged('titleLang')); $model->status_id = 2; $this->assertTrue($model->isAttributeChanged('status_id')); }
public function testCheckIsSet() { $model = new Post(); $this->assertFalse(isset($model->id)); $this->assertFalse(isset($model->titleLang)); $this->assertFalse(isset($model->description)); $this->assertFalse(isset($model->lang_id)); $this->assertTrue(isset($model->language)); $this->assertTrue(isset($model->translation)); $this->assertTrue(isset($model->currentTranslate)); $this->assertTrue(isset($model->hasTranslate)); $this->assertTrue(isset($model->modelTestProperty)); /** @var Post $model */ $model = Post::findOne(1); $this->assertTrue(isset($model->id)); $this->assertTrue(isset($model->titleLang)); $this->assertTrue(isset($model->description)); $this->assertFalse(isset($model->title)); $this->assertFalse(isset($model->modelData)); $model->modelData = 'OK'; $this->assertTrue(isset($model->modelData)); $this->assertFalse(isset($model->data)); $model->data = 'OK'; $this->assertTrue(isset($model->data)); }