|
1
|
|
|
<?php |
|
2
|
|
|
namespace tests; |
|
3
|
|
|
|
|
4
|
|
|
use Yii; |
|
5
|
|
|
use tests\models\PostAbridge as Post; |
|
6
|
|
|
use omgdef\multilingual\MultilingualBehavior; |
|
7
|
|
|
|
|
8
|
|
|
class DuplicationTest extends DatabaseTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
protected static $migrationFileName = 'sqlite_with_dublication.sql'; |
|
11
|
|
|
|
|
12
|
|
|
public function testFindAndSave() |
|
13
|
|
|
{ |
|
14
|
|
|
$post = Post::findOne(4); |
|
15
|
|
|
$this->assertNotNull($post->title); |
|
16
|
|
|
|
|
17
|
|
|
$post = Post::findOne(1); |
|
18
|
|
|
$this->assertNotNull($post->title); |
|
19
|
|
|
|
|
20
|
|
|
$post = Post::find()->multilingual()->where(['id' => 1])->one(); |
|
21
|
|
|
$this->assertNotNull($post->title); |
|
22
|
|
|
|
|
23
|
|
|
$testString = 'TestString'; |
|
24
|
|
|
$post->title = $testString; |
|
25
|
|
|
$this->assertTrue($post->save()); |
|
26
|
|
|
|
|
27
|
|
|
$post = Post::find()->localized('ru')->where(['id' => $post->id])->one(); |
|
28
|
|
|
$this->assertEquals($testString, $post->title); |
|
29
|
|
|
|
|
30
|
|
|
$dataSet = $this->getConnection()->createDataSet(['post', 'postLang']); |
|
31
|
|
|
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/data/test-update-populated-post-dublication.xml'); |
|
32
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testCreate() |
|
36
|
|
|
{ |
|
37
|
|
|
$post = new Post([ |
|
38
|
|
|
'title' => 'New post title', |
|
39
|
|
|
'body' => 'New post body', |
|
40
|
|
|
'title_en' => 'New post title en', |
|
41
|
|
|
'body_en' => 'New post body en', |
|
42
|
|
|
'title_ru' => 'New post title ru', //this value should be overwritten by default language value |
|
43
|
|
|
'body_ru' => 'New post body ru', |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertTrue($post->save()); |
|
47
|
|
|
$dataSet = $this->getConnection()->createDataSet(['post', 'postLang']); |
|
48
|
|
|
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/data/test-create-post-set-translations-dublication.xml'); |
|
49
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
|
50
|
|
|
|
|
51
|
|
|
$post = new Post([ |
|
52
|
|
|
'title' => 'New post title', |
|
53
|
|
|
'body' => 'New post body', |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertTrue($post->save()); |
|
57
|
|
|
$post = Post::findOne($post->id); |
|
58
|
|
|
$this->assertNotNull($post->title); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritdoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getDataSet() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->createFlatXMLDataSet(__DIR__ . '/data/test-dublication.xml'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|