forked from patricknelson/silverstripe-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMigrateTaskTest.php
119 lines (83 loc) · 3.22 KB
/
MigrateTaskTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
class MigrateTaskTest extends SapphireTest {
protected static $fixture_file = 'MigrateTaskTest.yml';
protected $extraDataObjects = [
Migration_TestParent::class,
Migration_TestChild::class,
Migration_TestGrandchild::class,
];
/**
* @var MigrateTask
*/
protected $task;
public function setUp() {
parent::setUp();
// Initialize task instance, ensure it's quiet.
$this->task = new MigrateTask();
$this->task->setSilent(true);
}
public function testEnsureWorking() {
// Just a generic test to make sure unit testing is working.
$task = new MigrateTask();
$this->assertContains("migrations", $task->getMigrationPath());
}
public function testLatestBatch() {
// Ensure that there are 2 migrations in the latest batch and 1 before that and that they both will run in the correct order.
$this->assertEquals(2, MigrateTask::getLatestBatch());
$this->task->down();
$this->assertEquals(1, MigrateTask::getLatestBatch());
}
public function testTransactionRollback() {
// TODO: Ensure changes are rolled back in case there is an exception.
}
public function testChangePageType() {
// TODO: Ensure that page type can be changed properly and is set in both draft/published versions.
// TODO: Ensure that only "Page" instances are allowed as PageType's.
}
public function testPublish() {
// TODO: Ensure that changes performed on published pages are retained.
// TODO: Ensure that changes performed on unpublished pages (with NO published version) are still at least retained in draft.
// TODO: Ensure that changes performed on unpublished pages (WITH published version) are still retained in draft with published version unchanged.
}
public function testTransitionField() {
// TODO: Make sure values are retained from old -> new.
// TODO: Make sure values are properly transformed from old -> new
}
public function testGetTableForField() {
$this->assertEquals(Migration_TestParent::class, Migration::getTableForField(Migration_TestGrandchild::class, 'ParentField'));
$this->assertEquals(Migration_TestChild::class, Migration::getTableForField(Migration_TestGrandchild::class, 'ChildField'));
$this->assertEquals(Migration_TestGrandchild::class, Migration::getTableForField(Migration_TestGrandchild::class, 'Grandchild'));
}
}
class Migration_UnitTestOnly extends Migration implements TestOnly, MigrationInterface {
public static $throwException = false;
public function up() {
// TODO: Do stuff here.
static::exceptionator();
}
public function down() {
// TODO: Reverse stuff here.
static::exceptionator();
}
public function isObsolete() {
return false;
}
protected static function exceptionator() {
if (static::$throwException) throw new Exception("Test exception.");
}
}
class Migration_TestParent extends DataObject implements TestOnly {
private static $db = [
'ParentField' => 'Varchar(255)',
];
}
class Migration_TestChild extends Migration_TestParent implements TestOnly {
private static $db = [
'ChildField' => 'Varchar(255)',
];
}
class Migration_TestGrandchild extends Migration_TestChild implements TestOnly {
private static $db = [
'Grandchild' => 'Varchar(255)',
];
}