Merge pull request #95 from robbieaverill/pulls/2.0/ss4-compat-fixes

FIX SS4 compatibility updates, PSR-4 in tests, table_name in stubs
This commit is contained in:
Daniel Hensby 2017-06-26 16:38:28 +01:00 committed by GitHub
commit 663264ac83
12 changed files with 166 additions and 156 deletions

View File

@ -1,4 +1,4 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
sudo: false
@ -6,23 +6,20 @@ language: php
matrix:
include:
- php: 5.5
env: DB=MYSQL CORE_RELEASE=4
- php: 5.6
env: DB=MYSQL CORE_RELEASE=4
- php: 5.6
env: DB=PGSQL CORE_RELEASE=4
- php: 7.0
env: DB=MYSQL CORE_RELEASE=4
- php: 7.0
- php: 7.1
env: DB=PGSQL CORE_RELEASE=4
before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- composer install
script:
- vendor/bin/phpunit tagfield/tests

View File

@ -19,11 +19,13 @@
"issues": "http://github.com/silverstripe-labs/silverstripe-tagfield/issues"
},
"require": {
"silverstripe/framework": "^4.0"
"silverstripe/framework": "^4@dev",
"silverstripe/versioned": "^1@dev"
},
"autoload": {
"psr-4": {
"SilverStripe\\TagField\\": "src/"
"SilverStripe\\TagField\\": "src/",
"SilverStripe\\TagField\\Tests\\": "tests/"
}
},
"extra": {

View File

@ -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);
}
}

View File

@ -1,6 +1,6 @@
StringTagFieldTestBlogPost:
SilverStripe\TagField\Tests\Stub\StringTagFieldTestBlogPost:
BlogPost1:
Title: BlogPost1
BlogPost2:
Title: BlogPost2
Tags: Tag1,Tag2
Tags: Tag1,Tag2

View 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',
];
}

View 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);
}
}

View 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
];
}

View 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
];
}

View 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);
}
}

View File

@ -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);
}
}

View File

@ -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