mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Conditionally adding tag field tests
This commit is contained in:
parent
7f6c958914
commit
4c062448b8
@ -1,23 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
class TestTag extends DataObject {
|
if(class_exists('TagField')) {
|
||||||
|
class TestTag extends DataObject {
|
||||||
private static $db = array(
|
|
||||||
'Title' => 'Text'
|
private static $db = array(
|
||||||
);
|
'Title' => 'Text'
|
||||||
|
);
|
||||||
private static $belongs_many_many = array(
|
|
||||||
'Pages' => 'TestTagFieldPage'
|
private static $belongs_many_many = array(
|
||||||
);
|
'Pages' => 'TestTagFieldPage'
|
||||||
|
);
|
||||||
function requireDefaultRecords(){
|
|
||||||
$class = $this->class;
|
function requireDefaultRecords(){
|
||||||
if(!DataObject::get_one($class)) {
|
$class = $this->class;
|
||||||
foreach(array('one', 'two', 'three', 'four') as $title) {
|
if(!DataObject::get_one($class)) {
|
||||||
$tag = new $class();
|
foreach(array('one', 'two', 'three', 'four') as $title) {
|
||||||
$tag->Title = $title;
|
$tag = new $class();
|
||||||
$tag->write();
|
$tag->Title = $title;
|
||||||
|
$tag->write();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,38 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
class TestTagFieldPage extends Page {
|
if(class_exists('TagField')) {
|
||||||
|
class TestTagFieldPage extends Page {
|
||||||
private static $db = array(
|
|
||||||
'TestTagString' => 'Text',
|
|
||||||
'FixedTags' => 'Text'
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $many_many = array(
|
|
||||||
'TestTags' => 'TestTag',
|
|
||||||
);
|
|
||||||
|
|
||||||
function getCMSFields() {
|
|
||||||
$fields = parent::getCMSFields();
|
|
||||||
|
|
||||||
$tf1 = new TagField('TestTagString', "Single column tags (try 'one', 'two', 'three', 'four')", 'TestTag');
|
private static $db = array(
|
||||||
$fields->addFieldToTab('Root.Content.Main', $tf1);
|
'TestTagString' => 'Text',
|
||||||
|
'FixedTags' => 'Text'
|
||||||
|
);
|
||||||
|
|
||||||
$tf2 = new TagField('TestTags', "Relation tags (try 'one', 'two', 'three', 'four')", null, 'TestTag');
|
private static $many_many = array(
|
||||||
$fields->addFieldToTab('Root.Content.Main', $tf2);
|
'TestTags' => 'TestTag',
|
||||||
|
);
|
||||||
|
|
||||||
$tf3 = new TagField('FixedTags', "Fixed tags (try 'PHP', 'Ruby', 'Python')", null, 'TestTag');
|
function getCMSFields() {
|
||||||
$tf3->setCustomTags(array('PHP', 'Ruby', 'Python'));
|
$fields = parent::getCMSFields();
|
||||||
$fields->addFieldToTab('Root.Content.Main', $tf3);
|
|
||||||
|
$tf1 = new TagField('TestTagString', "Single column tags (try 'one', 'two', 'three', 'four')", 'TestTag');
|
||||||
return $fields;
|
$fields->addFieldToTab('Root.Content.Main', $tf1);
|
||||||
}
|
|
||||||
|
$tf2 = new TagField('TestTags', "Relation tags (try 'one', 'two', 'three', 'four')", null, 'TestTag');
|
||||||
function requireDefaultRecords(){
|
$fields->addFieldToTab('Root.Content.Main', $tf2);
|
||||||
$class = $this->class;
|
|
||||||
if(!DataObject::get_one($class)) {
|
$tf3 = new TagField('FixedTags', "Fixed tags (try 'PHP', 'Ruby', 'Python')", null, 'TestTag');
|
||||||
$page = new $class();
|
$tf3->setCustomTags(array('PHP', 'Ruby', 'Python'));
|
||||||
$page->Title = "Test TagField";
|
$fields->addFieldToTab('Root.Content.Main', $tf3);
|
||||||
$page->write();
|
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requireDefaultRecords(){
|
||||||
|
$class = $this->class;
|
||||||
|
if(!DataObject::get_one($class)) {
|
||||||
|
$page = new $class();
|
||||||
|
$page->Title = "Test TagField";
|
||||||
|
$page->write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user