2016-02-23 21:53:52 +01:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\DB;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\ORM\DataExtension;
|
|
|
|
use SilverStripe\ORM\Versioning\VersionableExtension;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
|
|
|
|
|
2016-02-23 21:53:52 +01:00
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
class VersionableExtensionsTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'VersionableExtensionsFixtures.yml';
|
|
|
|
|
|
|
|
protected $requiredExtensions = array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'VersionableExtensionsTest_DataObject' => array('SilverStripe\\ORM\\Versioning\\Versioned'),
|
2016-02-23 21:53:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'VersionableExtensionsTest_DataObject',
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
public function setUpOnce()
|
|
|
|
{
|
|
|
|
Config::nest();
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
VersionableExtensionsTest_DataObject::add_extension('SilverStripe\\ORM\\Versioning\\Versioned');
|
2016-02-23 21:53:52 +01:00
|
|
|
VersionableExtensionsTest_DataObject::add_extension('VersionableExtensionsTest_Extension');
|
|
|
|
|
|
|
|
$cfg = Config::inst();
|
|
|
|
|
|
|
|
$cfg->update('VersionableExtensionsTest_DataObject', 'versionableExtensions', array(
|
|
|
|
'VersionableExtensionsTest_Extension' => array(
|
|
|
|
'test1',
|
|
|
|
'test2',
|
|
|
|
'test3'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
parent::setUpOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
public function testTablesAreCreated()
|
|
|
|
{
|
|
|
|
$tables = DB::table_list();
|
|
|
|
|
|
|
|
$check = array(
|
|
|
|
'versionableextensionstest_dataobject_test1_live', 'versionableextensionstest_dataobject_test2_live', 'versionableextensionstest_dataobject_test3_live',
|
|
|
|
'versionableextensionstest_dataobject_test1_versions', 'versionableextensionstest_dataobject_test2_versions', 'versionableextensionstest_dataobject_test3_versions'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check that the right tables exist
|
|
|
|
foreach ($check as $tableName) {
|
|
|
|
|
|
|
|
$this->assertContains($tableName, array_keys($tables), 'Contains table: '.$tableName);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class VersionableExtensionsTest_DataObject extends DataObject implements TestOnly {
|
|
|
|
|
|
|
|
private static $db = array(
|
|
|
|
'Title' => 'Varchar'
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-25 07:09:29 +02:00
|
|
|
class VersionableExtensionsTest_Extension extends DataExtension implements VersionableExtension, TestOnly {
|
2016-02-23 21:53:52 +01:00
|
|
|
|
|
|
|
|
2016-05-25 07:09:29 +02:00
|
|
|
public function isVersionedTable($table) {
|
2016-02-23 21:53:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-05-25 07:09:29 +02:00
|
|
|
* Update fields and indexes for the versonable suffix table
|
2016-02-23 21:53:52 +01:00
|
|
|
*
|
2016-05-25 07:09:29 +02:00
|
|
|
* @param string $suffix Table suffix being built
|
|
|
|
* @param array $fields List of fields in this model
|
|
|
|
* @param array $indexes List of indexes in this model
|
2016-02-23 21:53:52 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2016-05-25 07:09:29 +02:00
|
|
|
public function updateVersionableFields($suffix, &$fields, &$indexes){
|
|
|
|
$indexes['ExtraField'] = true;
|
|
|
|
$fields['ExtraField'] = 'Varchar()';
|
2016-02-23 21:53:52 +01:00
|
|
|
}
|
|
|
|
}
|