mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
FIX SS4 compatibility updates, PSR-4 in tests, table_name in stubs
This commit is contained in:
parent
f741c0d2b0
commit
cde9dc917a
@ -23,7 +23,8 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SilverStripe\\TagField\\": "src/"
|
||||
"SilverStripe\\TagField\\": "src/",
|
||||
"SilverStripe\\TagField\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
|
@ -1,14 +1,11 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
namespace SilverStripe\TagField\Tests;
|
||||
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\TagField\StringTagField;
|
||||
use SilverStripe\TagField\Tests\Stub\StringTagFieldTestBlogPost;
|
||||
|
||||
/**
|
||||
* @mixin PHPUnit_Framework_TestCase
|
||||
@ -18,13 +15,13 @@ class StringTagFieldTest extends SapphireTest
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public static $fixture_file = 'tagfield/tests/StringTagFieldTest.yml';
|
||||
protected static $fixture_file = 'StringTagFieldTest.yml';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $extraDataObjects = array(
|
||||
'StringTagFieldTestBlogPost',
|
||||
protected static $extra_dataobjects = array(
|
||||
StringTagFieldTestBlogPost::class,
|
||||
);
|
||||
|
||||
public function testItSavesTagsOnNewRecords()
|
||||
@ -48,7 +45,7 @@ class StringTagFieldTest extends SapphireTest
|
||||
protected function getNewStringTagFieldTestBlogPost($name)
|
||||
{
|
||||
return $this->objFromFixture(
|
||||
'StringTagFieldTestBlogPost',
|
||||
StringTagFieldTestBlogPost::class,
|
||||
$name
|
||||
);
|
||||
}
|
||||
@ -124,46 +121,3 @@ class StringTagFieldTest extends SapphireTest
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @property string $Tags
|
||||
*/
|
||||
class StringTagFieldTestBlogPost extends DataObject implements TestOnly
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Title' => 'Text',
|
||||
'Content' => 'Text',
|
||||
'Tags' => 'Text',
|
||||
);
|
||||
}
|
||||
|
||||
class StringTagFieldTestController extends Controller implements TestOnly
|
||||
{
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function StringTagFieldTestForm()
|
||||
{
|
||||
$fields = new FieldList(
|
||||
$tagField = new StringTagField('Tags')
|
||||
);
|
||||
|
||||
$actions = new FieldList(
|
||||
new FormAction('StringTagFieldTestFormSubmit')
|
||||
);
|
||||
|
||||
return new Form($this, 'StringTagFieldTestForm', $fields, $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject $dataObject
|
||||
* @param Form $form
|
||||
*/
|
||||
public function StringTagFieldTestFormSubmit(DataObject $dataObject, Form $form)
|
||||
{
|
||||
$form->saveInto($dataObject);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
StringTagFieldTestBlogPost:
|
||||
SilverStripe\TagField\Tests\Stub\StringTagFieldTestBlogPost:
|
||||
BlogPost1:
|
||||
Title: BlogPost1
|
||||
BlogPost2:
|
||||
Title: BlogPost2
|
||||
Tags: Tag1,Tag2
|
||||
Tags: Tag1,Tag2
|
||||
|
17
tests/Stub/StringTagFieldTestBlogPost.php
Normal file
17
tests/Stub/StringTagFieldTestBlogPost.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\TagField\Tests\Stub;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
class StringTagFieldTestBlogPost extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'StringTagFieldTestBlogPost';
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Text',
|
||||
'Content' => 'Text',
|
||||
'Tags' => 'Text',
|
||||
];
|
||||
}
|
32
tests/Stub/StringTagFieldTestController.php
Normal file
32
tests/Stub/StringTagFieldTestController.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\TagField\Tests\Stub;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\TagField\StringTagField;
|
||||
|
||||
class StringTagFieldTestController extends Controller implements TestOnly
|
||||
{
|
||||
public function StringTagFieldTestForm()
|
||||
{
|
||||
$fields = new FieldList(
|
||||
$tagField = new StringTagField('Tags')
|
||||
);
|
||||
|
||||
$actions = new FieldList(
|
||||
new FormAction('StringTagFieldTestFormSubmit')
|
||||
);
|
||||
|
||||
return new Form($this, 'StringTagFieldTestForm', $fields, $actions);
|
||||
}
|
||||
|
||||
public function StringTagFieldTestFormSubmit(DataObject $dataObject, Form $form)
|
||||
{
|
||||
$form->saveInto($dataObject);
|
||||
}
|
||||
}
|
21
tests/Stub/TagFieldTestBlogPost.php
Normal file
21
tests/Stub/TagFieldTestBlogPost.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\TagField\Tests\Stub;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\TagField\Tests\Stub\TagFieldTestBlogTag;
|
||||
|
||||
class TagFieldTestBlogPost extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'TagFieldTestBlogPost';
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Text',
|
||||
'Content' => 'Text'
|
||||
];
|
||||
|
||||
private static $many_many = [
|
||||
'Tags' => TagFieldTestBlogTag::class
|
||||
];
|
||||
}
|
22
tests/Stub/TagFieldTestBlogTag.php
Normal file
22
tests/Stub/TagFieldTestBlogTag.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\TagField\Tests\Stub;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\TagField\Tests\Stub\TagFieldTestBlogPost;
|
||||
|
||||
class TagFieldTestBlogTag extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'TagFieldTestBlogTag';
|
||||
|
||||
private static $default_sort = '"TagFieldTestBlogTag"."ID" ASC';
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Varchar(200)'
|
||||
];
|
||||
|
||||
private static $belongs_many_many = [
|
||||
'BlogPosts' => TagFieldTestBlogPost::class
|
||||
];
|
||||
}
|
33
tests/Stub/TagFieldTestController.php
Normal file
33
tests/Stub/TagFieldTestController.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\TagField\Tests\Stub;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\TagField\StringTagField;
|
||||
|
||||
class TagFieldTestController extends Controller implements TestOnly
|
||||
{
|
||||
public function TagFieldTestForm()
|
||||
{
|
||||
$fields = new FieldList(
|
||||
$tagField = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'))
|
||||
);
|
||||
|
||||
$actions = new FieldList(
|
||||
new FormAction('TagFieldTestFormSubmit')
|
||||
);
|
||||
|
||||
return new Form($this, 'TagFieldTestForm', $fields, $actions);
|
||||
}
|
||||
|
||||
public function TagFieldTestFormSubmit(DataObject $dataObject, Form $form)
|
||||
{
|
||||
$form->saveInto($dataObject);
|
||||
}
|
||||
}
|
@ -1,15 +1,18 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
namespace SilverStripe\TagField\Tests;
|
||||
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\TagField\TagField;
|
||||
use SilverStripe\TagField\Tests\Stub\TagFieldTestBlogPost;
|
||||
use SilverStripe\TagField\Tests\Stub\TagFieldTestBlogTag;
|
||||
use SilverStripe\TagField\Tests\Stub\TagFieldTestController;
|
||||
|
||||
/**
|
||||
* @mixin PHPUnit_Framework_TestCase
|
||||
@ -19,20 +22,20 @@ class TagFieldTest extends SapphireTest
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public static $fixture_file = 'tagfield/tests/TagFieldTest.yml';
|
||||
protected static $fixture_file = 'TagFieldTest.yml';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $extraDataObjects = array(
|
||||
'TagFieldTestBlogTag',
|
||||
'TagFieldTestBlogPost',
|
||||
);
|
||||
protected static $extra_dataobjects = [
|
||||
TagFieldTestBlogTag::class,
|
||||
TagFieldTestBlogPost::class,
|
||||
];
|
||||
|
||||
public function testItSavesLinksToNewTagsOnNewRecords()
|
||||
{
|
||||
$record = $this->getNewTagFieldTestBlogPost('BlogPost1');
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
$field->setValue(array('Tag3', 'Tag4'));
|
||||
$field->saveInto($record);
|
||||
$record->write();
|
||||
@ -50,7 +53,7 @@ class TagFieldTest extends SapphireTest
|
||||
protected function getNewTagFieldTestBlogPost($name)
|
||||
{
|
||||
return $this->objFromFixture(
|
||||
'TagFieldTestBlogPost',
|
||||
TagFieldTestBlogPost::class,
|
||||
$name
|
||||
);
|
||||
}
|
||||
@ -87,7 +90,7 @@ class TagFieldTest extends SapphireTest
|
||||
$record = $this->getNewTagFieldTestBlogPost('BlogPost1');
|
||||
$record->write();
|
||||
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
$field->setValue(array('Tag3', 'Tag4'));
|
||||
$field->saveInto($record);
|
||||
|
||||
@ -101,7 +104,7 @@ class TagFieldTest extends SapphireTest
|
||||
{
|
||||
$record = $this->getNewTagFieldTestBlogPost('BlogPost1');
|
||||
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
$field->setValue(array('Tag1', 'Tag2'));
|
||||
$field->saveInto($record);
|
||||
|
||||
@ -118,7 +121,7 @@ class TagFieldTest extends SapphireTest
|
||||
$record = $this->getNewTagFieldTestBlogPost('BlogPost1');
|
||||
$record->write();
|
||||
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
$field->setValue(array('Tag1', 'Tag2'));
|
||||
$field->saveInto($record);
|
||||
|
||||
@ -135,7 +138,7 @@ class TagFieldTest extends SapphireTest
|
||||
{
|
||||
$record = $this->getNewTagFieldTestBlogPost('BlogPost2');
|
||||
$record->write();
|
||||
$tag2ID = $this->idFromFixture('TagFieldTestBlogTag', 'Tag2');
|
||||
$tag2ID = $this->idFromFixture(TagFieldTestBlogTag::class, 'Tag2');
|
||||
|
||||
// Check tags before write
|
||||
$this->compareExpectedAndActualTags(
|
||||
@ -149,7 +152,7 @@ class TagFieldTest extends SapphireTest
|
||||
$this->assertContains($tag2ID, TagFieldTestBlogTag::get()->column('ID'));
|
||||
|
||||
// Write new tags
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
$field->setValue(array('222', 'Tag3'));
|
||||
$field->saveInto($record);
|
||||
|
||||
@ -169,7 +172,7 @@ class TagFieldTest extends SapphireTest
|
||||
|
||||
public function testItSuggestsTags()
|
||||
{
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
|
||||
/**
|
||||
* Partial tag title match.
|
||||
@ -274,13 +277,13 @@ class TagFieldTest extends SapphireTest
|
||||
new TagFieldTestController($record),
|
||||
'Form',
|
||||
new FieldList(
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'))
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class))
|
||||
),
|
||||
new FieldList()
|
||||
);
|
||||
|
||||
$form->loadDataFrom(
|
||||
$this->objFromFixture('TagFieldTestBlogPost', 'BlogPost2')
|
||||
$this->objFromFixture(TagFieldTestBlogPost::class, 'BlogPost2')
|
||||
);
|
||||
|
||||
$ids = TagFieldTestBlogTag::get()->column('Title');
|
||||
@ -299,14 +302,14 @@ class TagFieldTest extends SapphireTest
|
||||
|
||||
$tag = TagFieldTestBlogTag::get()->filter('Title', 'Tag1')->first();
|
||||
|
||||
$field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'), array($tag->Title, 'Tag3'));
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class), array($tag->Title, 'Tag3'));
|
||||
$field->setCanCreate(false);
|
||||
$field->saveInto($record);
|
||||
|
||||
/**
|
||||
* @var TagFieldTestBlogPost $record
|
||||
*/
|
||||
$record = DataObject::get_by_id('TagFieldTestBlogPost', $record->ID);
|
||||
$record = DataObject::get_by_id(TagFieldTestBlogPost::class, $record->ID);
|
||||
|
||||
$this->compareExpectedAndActualTags(
|
||||
array('Tag1'),
|
||||
@ -340,74 +343,3 @@ class TagFieldTest extends SapphireTest
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TagFieldTestBlogTag extends DataObject implements TestOnly
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $default_sort = '"TagFieldTestBlogTag"."ID" ASC';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar(200)'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $belongs_many_many = array(
|
||||
'BlogPosts' => 'TagFieldTestBlogPost'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method ManyManyList Tags()
|
||||
*/
|
||||
class TagFieldTestBlogPost extends DataObject implements TestOnly
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Title' => 'Text',
|
||||
'Content' => 'Text'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $many_many = array(
|
||||
'Tags' => 'TagFieldTestBlogTag'
|
||||
);
|
||||
}
|
||||
|
||||
class TagFieldTestController extends Controller implements TestOnly
|
||||
{
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function TagFieldTestForm()
|
||||
{
|
||||
$fields = new FieldList(
|
||||
$tagField = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'))
|
||||
);
|
||||
|
||||
$actions = new FieldList(
|
||||
new FormAction('TagFieldTestFormSubmit')
|
||||
);
|
||||
|
||||
return new Form($this, 'TagFieldTestForm', $fields, $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject $dataObject
|
||||
* @param Form $form
|
||||
*/
|
||||
public function TagFieldTestFormSubmit(DataObject $dataObject, Form $form)
|
||||
{
|
||||
$form->saveInto($dataObject);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
TagFieldTestBlogTag:
|
||||
SilverStripe\TagField\Tests\Stub\TagFieldTestBlogTag:
|
||||
Tag1:
|
||||
Title: Tag1
|
||||
Tag2:
|
||||
Title: 222
|
||||
TagFieldTestBlogPost:
|
||||
SilverStripe\TagField\Tests\Stub\TagFieldTestBlogPost:
|
||||
BlogPost1:
|
||||
Title: BlogPost1
|
||||
BlogPost2:
|
||||
Title: BlogPost2
|
||||
Tags: =>TagFieldTestBlogTag.Tag1,=>TagFieldTestBlogTag.Tag2
|
||||
Tags: =>SilverStripe\TagField\Tests\Stub\TagFieldTestBlogTag.Tag1,=>SilverStripe\TagField\Tests\Stub\TagFieldTestBlogTag.Tag2
|
||||
|
Loading…
Reference in New Issue
Block a user