Skip to content

Commit

Permalink
MNT New tests classes to test version tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Jan 7, 2024
1 parent 5f70444 commit 9053227
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 0 deletions.
13 changes: 13 additions & 0 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ SilverStripe\FrameworkTest\Model\Employee:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension

SilverStripe\FrameworkTest\Versioned\Model\NonVersionedParentObject:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
SilverStripe\FrameworkTest\Versioned\Model\NonVersionedChildObject:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
SilverStripe\FrameworkTest\Versioned\Model\VersionedChildObject:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
SilverStripe\FrameworkTest\Versioned\Model\VersionedParentObject:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension

SilverStripe\ORM\DatabaseAdmin:
extensions:
- SilverStripe\FrameworkTest\GridFieldArbitraryData\DatabaseBuildExtension
Expand Down
18 changes: 18 additions & 0 deletions code/versioned/NonVersionedChildObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SilverStripe\FrameworkTest\Versioned\Model;

use SilverStripe\ORM\DataObject;

class NonVersionedChildObject extends DataObject
{
private static $table_name = 'NonVersionedChildObject';

private static $db = [
'Name'=>'Varchar(255)',
];

private static $has_one = [
'VersionedParentObject' => VersionedParentObject::class,
];
}
40 changes: 40 additions & 0 deletions code/versioned/NonVersionedParentObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace SilverStripe\FrameworkTest\Versioned\Model;

use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataObject;

class NonVersionedParentObject extends DataObject
{
private static $table_name = 'NonVersionedParentObject';

private static $db = [
'Name'=>'Varchar(255)',
];

private static $has_one = [
'TestPageVersionedObject' => TestPageVersionedObject::class,
];

private static $has_many = [
'VersionedChildObjects' => VersionedChildObject::class,
];

private static $owns = ['VersionedChildObjects'];

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.VersionedChildObjects', GridField::create(
'VersionedChildObjects',
'VersionedChildObjects',
$this->VersionedChildObjects(),
GridFieldConfig_RecordEditor::create()
));

return $fields;
}
}
46 changes: 46 additions & 0 deletions code/versioned/TestPageVersionedObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace SilverStripe\FrameworkTest\Versioned\Model;

use Page;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;

/**
* Parent class of all test pages
*/
class TestPageVersionedObject extends Page implements \TestPageInterface
{
private static $table_name = 'FrameworkTestPage_VersionedObject';

private static $has_many = [
'VersionedParentObjects' => VersionedParentObject::class,
'NonVersionedParentObjects' => NonVersionedParentObject::class,
];

private static $owns = [
'VersionedParentObjects',
'NonVersionedParentObjects',
];

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.VersionedParentObjects', GridField::create(
'VersionedParentObjects',
'VersionedParentObjects',
$this->VersionedParentObjects(),
GridFieldConfig_RecordEditor::create()
));

$fields->addFieldToTab('Root.NonVersionedParentObjects', GridField::create(
'NonVersionedParentObjects',
'NonVersionedParentObjects',
$this->NonVersionedParentObjects(),
GridFieldConfig_RecordEditor::create()
));

return $fields;
}
}
16 changes: 16 additions & 0 deletions code/versioned/TestVersionedObjectModelAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace SilverStripe\FrameworkTest\Versioned\Admin;

use SilverStripe\Admin\ModelAdmin;

class TestVersionedObjectModelAdmin extends ModelAdmin
{
private static $url_segment = 'versioned-test';
private static $menu_title = 'Test Versioned Object';

private static $managed_models = [
"SilverStripe\\FrameworkTest\\Versioned\\Model\\VersionedParentObject",
"SilverStripe\\FrameworkTest\\Versioned\\Model\\NonVersionedParentObject",
];
}
23 changes: 23 additions & 0 deletions code/versioned/VersionedChildObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace SilverStripe\FrameworkTest\Versioned\Model;

use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;

class VersionedChildObject extends DataObject
{
private static $table_name = 'VersionedChildObject';

private static $extensions = [
Versioned::class,
];

private static $db = [
'Name'=>'Varchar(255)',
];

private static $has_one = [
'NonVersionedParentObject' => NonVersionedParentObject::class,
];
}
46 changes: 46 additions & 0 deletions code/versioned/VersionedParentObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace SilverStripe\FrameworkTest\Versioned\Model;

use Page;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;

class VersionedParentObject extends DataObject
{
private static $table_name = 'VersionedParentObject';

private static $extensions = [
Versioned::class
];

private static $db = [
'Name'=>'Varchar(255)',
];

private static $has_one = [
'TestPageVersionedObject' => TestPageVersionedObject::class,
];

private static $has_many = [
'NonVersionedChildObjects' => NonVersionedChildObject::class,
];

private static $owns = ['NonVersionedChildObjects'];

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.NonVersionedChildObjects', GridField::create(
'NonVersionedChildObjects',
'NonVersionedChildObjects',
$this->NonVersionedChildObjects(),
GridFieldConfig_RecordEditor::create()
));

return $fields;
}
}

0 comments on commit 9053227

Please sign in to comment.