1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package framework |
4
|
|
|
* @subpackage tests |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
class VersionableExtensionsTest extends SapphireTest |
8
|
|
|
{ |
9
|
|
|
protected static $fixture_file = 'VersionableExtensionsFixtures.yml'; |
10
|
|
|
|
11
|
|
|
protected $requiredExtensions = array( |
12
|
|
|
'VersionableExtensionsTest_DataObject' => array('Versioned'), |
13
|
|
|
); |
14
|
|
|
|
15
|
|
|
protected $extraDataObjects = array( |
16
|
|
|
'VersionableExtensionsTest_DataObject', |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
public function setUpOnce() |
21
|
|
|
{ |
22
|
|
|
Config::nest(); |
23
|
|
|
|
24
|
|
|
VersionableExtensionsTest_DataObject::add_extension('Versioned'); |
25
|
|
|
VersionableExtensionsTest_DataObject::add_extension('VersionableExtensionsTest_Extension'); |
26
|
|
|
|
27
|
|
|
$cfg = Config::inst(); |
28
|
|
|
|
29
|
|
|
$cfg->update('VersionableExtensionsTest_DataObject', 'versionableExtensions', array( |
30
|
|
|
'VersionableExtensionsTest_Extension' => array( |
31
|
|
|
'test1', |
32
|
|
|
'test2', |
33
|
|
|
'test3' |
34
|
|
|
) |
35
|
|
|
)); |
36
|
|
|
|
37
|
|
|
parent::setUpOnce(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function tearDownOnce() |
41
|
|
|
{ |
42
|
|
|
parent::tearDownOnce(); |
43
|
|
|
|
44
|
|
|
Config::unnest(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testTablesAreCreated() |
51
|
|
|
{ |
52
|
|
|
$tables = DB::table_list(); |
53
|
|
|
|
54
|
|
|
$check = array( |
55
|
|
|
'versionableextensionstest_dataobject_test1_live', 'versionableextensionstest_dataobject_test2_live', 'versionableextensionstest_dataobject_test3_live', |
56
|
|
|
'versionableextensionstest_dataobject_test1_versions', 'versionableextensionstest_dataobject_test2_versions', 'versionableextensionstest_dataobject_test3_versions' |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
// Check that the right tables exist |
60
|
|
|
foreach ($check as $tableName) { |
61
|
|
|
|
62
|
|
|
$this->assertContains($tableName, array_keys($tables), 'Contains table: '.$tableName); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
class VersionableExtensionsTest_DataObject extends DataObject implements TestOnly { |
70
|
|
|
|
71
|
|
|
private static $db = array( |
72
|
|
|
'Title' => 'Varchar' |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
class VersionableExtensionsTest_Extension extends DataExtension implements TestOnly { |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function isVersionedTable($table){ |
|
|
|
|
82
|
|
|
return true; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* fieldsInExtraTables function. |
88
|
|
|
* |
89
|
|
|
* @access public |
90
|
|
|
* @param mixed $suffix |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function fieldsInExtraTables($suffix){ |
|
|
|
|
94
|
|
|
$fields = array(); |
95
|
|
|
//$fields['db'] = DataObject::database_fields($this->owner->class); |
|
|
|
|
96
|
|
|
$fields['indexes'] = $this->owner->databaseIndexes(); |
97
|
|
|
|
98
|
|
|
$fields['db'] = array_merge( |
99
|
|
|
DataObject::database_fields($this->owner->class) |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
return $fields; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.