Completed
Pull Request — 3.4 (#6961)
by Daniel
09:45
created

VersionableExtensionsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpOnce() 0 19 1
A tearDownOnce() 0 6 1
A testTablesAreCreated() 0 16 2
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){
0 ignored issues
show
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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){
0 ignored issues
show
Unused Code introduced by
The parameter $suffix is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
		$fields = array();
95
		//$fields['db'] = DataObject::database_fields($this->owner->class);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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