Fix various ORM test issues

This commit is contained in:
Damian Mooyman 2016-11-13 20:35:43 +13:00
parent 00c9c2c775
commit 22cb3d0d74
105 changed files with 668 additions and 732 deletions

View File

@ -514,21 +514,21 @@ mappings:
SilverStripe\View\Parsers\SS_Transliterator: SilverStripe\View\Parsers\Transliterator
URLSegmentFilter: SilverStripe\View\Parsers\URLSegmentFilter
CampaignAdminTest: SilverStripe\Admin\Tests\CampaignAdminTest
CampaignAdminTest_InvalidChangeSet: SilverStripe\Admin\Tests\CampaignAdminTest_InvalidChangeSet
CampaignAdminTest_InvalidChangeSet: SilverStripe\Admin\Tests\CampaignAdminTest\CampaignAdminTest_InvalidChangeSet
CMSMenuItemTest: SilverStripe\Admin\Tests\CMSMenuItemTest
CMSMenuTest: SilverStripe\Admin\Tests\CMSMenuTest
CMSMenuTest_LeftAndMainController: SilverStripe\Admin\Tests\CMSMenuTest_LeftAndMainController
CMSMenuTest_CustomTitle: SilverStripe\Admin\Tests\CMSMenuTest_CustomTitle
CMSMenuTest_LeftAndMainController: SilverStripe\Admin\Tests\CMSMenuTest\CMSMenuTest_LeftAndMainController
CMSMenuTest_CustomTitle: SilverStripe\Admin\Tests\CMSMenuTest\CMSMenuTest_CustomTitle
CMSProfileControllerTest: SilverStripe\Admin\Tests\CMSProfileControllerTest
CMSProfileControllerTestExtension: SilverStripe\Admin\Tests\CMSProfileControllerTestExtension
CMSProfileControllerTestExtension: SilverStripe\Admin\Tests\CMSProfileControllerTest\CMSProfileControllerTestExtension
LeftAndMainTest: SilverStripe\Admin\Tests\LeftAndMainTest
LeftAndMainTest_Controller: SilverStripe\Admin\Tests\LeftAndMainTest_Controller
LeftAndMainTest_Object: SilverStripe\Admin\Tests\LeftAndMainTest_Object
LeftAndMainTest_Controller: SilverStripe\Admin\Tests\LeftAndMainTest\LeftAndMainTest_Controller
LeftAndMainTest_Object: SilverStripe\Admin\Tests\LeftAndMainTest\LeftAndMainTest_Object
ModelAdminTest: SilverStripe\Admin\Tests\ModelAdminTest
ModelAdminTest_Admin: SilverStripe\Admin\Tests\ModelAdminTest_Admin
ModelAdminTest_PlayerAdmin: SilverStripe\Admin\Tests\ModelAdminTest_PlayerAdmin
ModelAdminTest_Contact: SilverStripe\Admin\Tests\ModelAdminTest_Contact
ModelAdminTest_Player: SilverStripe\Admin\Tests\ModelAdminTest_Player
ModelAdminTest_Admin: SilverStripe\Admin\Tests\ModelAdminTest\ModelAdminTest_Admin
ModelAdminTest_PlayerAdmin: SilverStripe\Admin\Tests\ModelAdminTest\ModelAdminTest_PlayerAdmin
ModelAdminTest_Contact: SilverStripe\Admin\Tests\ModelAdminTest\ModelAdminTest_Contact
ModelAdminTest_Player: SilverStripe\Admin\Tests\ModelAdminTest\ModelAdminTest_Player
SecurityAdminTest: SilverStripe\Admin\Tests\SecurityAdminTest
AssetControlExtensionTest: SilverStripe\Assets\Tests\AssetControlExtensionTest
AssetControlExtensionTest_VersionedObject: SilverStripe\Assets\Tests\AssetControlExtensionTest_VersionedObject
@ -989,7 +989,7 @@ mappings:
ViewableDataTest_Cached: SilverStripe\View\Tests\ViewableDataTest\ViewableDataTest_Cached
ViewableDataTest_NotCached: SilverStripe\View\Tests\ViewableDataTest\ViewableDataTest_NotCached
ViewableDataTest_Failover: SilverStripe\View\Tests\ViewableDataTest\ViewableDataTest_Failover
AssetStoreTest_SpyStore: SilverStripe\Assets\Tests\Store\AssetStoreTest\TestAssetStore
AssetStoreTest_SpyStore: SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore
GridField_URLHandlerTest: SilverStripe\Forms\Tests\GridField\GridField_URLHandlerTest
GridField_URLHandlerTest_Controller: SilverStripe\Forms\Tests\GridField\GridField_URLHandlerTest\GridField_URLHandlerTest_Controller
GridField_URLHandlerTest_Component: SilverStripe\Forms\Tests\GridField\GridField_URLHandlerTest\GridField_URLHandlerTest_Component
@ -1050,6 +1050,11 @@ mappings:
SearchFilterApplyRelationTest_ManyManyParent: SilverStripe\ORM\Tests\Filters\SearchFilterApplyRelationTest\SearchFilterApplyRelationTest_ManyManyParent
SearchFilterApplyRelationTest_ManyManyChild: SilverStripe\ORM\Tests\Filters\SearchFilterApplyRelationTest\SearchFilterApplyRelationTest_ManyManyChild
SearchFilterApplyRelationTest_ManyManyGrantChild: SilverStripe\ORM\Tests\Filters\SearchFilterApplyRelationTest\SearchFilterApplyRelationTest_ManyManyGrantChild
RSSFeedTest: SilverStripe\Control\Tests\RSS\RSSFeedTest
RSSFeedTest_ItemA: SilverStripe\Control\Tests\RSS\RSSFeedTest\ItemA
RSSFeedTest_ItemB: SilverStripe\Control\Tests\RSS\RSSFeedTest\ItemB
RSSFeedTest_ItemC: SilverStripe\Control\Tests\RSS\RSSFeedTest\ItemC
RSSFeedTest_ItemD: SilverStripe\Control\Tests\RSS\RSSFeedTest\ItemD
skipConfigs:
- db
- casting

View File

@ -70,7 +70,8 @@ class CMSMenu extends Object implements IteratorAggregate, i18nEntityProvider {
*/
public static function add_controller($controllerClass) {
if($menuItem = self::menuitem_for_controller($controllerClass)) {
self::add_menu_item_obj($controllerClass, $menuItem);
$code = static::get_menu_code($controllerClass);
self::add_menu_item_obj($code, $menuItem);
}
}

View File

@ -2,16 +2,9 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\Admin\CMSMenuItem;
use SilverStripe\Dev\SapphireTest;
/**
* @package framework
* @subpackage tests
*/
class CMSMenuItemTest extends SapphireTest {
public function testAttributes() {

View File

@ -2,55 +2,48 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\Admin\CMSMenu;
use SilverStripe\Admin\CMSMenuItem;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Admin\SecurityAdmin;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
/**
* @package framework
* @subpackage tests
*/
class CMSMenuTest extends SapphireTest implements TestOnly {
public function testBasicMenuHandling() {
// Clear existing menu
CMSMenu::clear_menu();
$menuItems = CMSMenu::get_menu_items();
$this->assertTrue((empty($menuItems)), 'Menu can be cleared');
// Add a controller to the menu and check it is as expected
CMSMenu::add_controller('CMSMenuTest_LeftAndMainController');
CMSMenu::add_controller(CMSMenuTest\LeftAndMainController::class);
$menuItems = CMSMenu::get_menu_items();
$menuItem = $menuItems['CMSMenuTest_LeftAndMainController'];
$this->assertInstanceOf('SilverStripe\\Admin\\CMSMenuItem', $menuItem, 'Controller menu item is of class CMSMenuItem');
$this->assertContains($menuItem->url, singleton('CMSMenuTest_LeftAndMainController')->Link(),
$menuItem = $menuItems['SilverStripe-Admin-Tests-CMSMenuTest-LeftAndMainController'];
$this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'Controller menu item is of class CMSMenuItem');
$this->assertContains($menuItem->url, CMSMenuTest\LeftAndMainController::singleton()->Link(),
'Controller menu item has the correct link');
$this->assertEquals($menuItem->controller, 'CMSMenuTest_LeftAndMainController',
$this->assertEquals($menuItem->controller, CMSMenuTest\LeftAndMainController::class,
'Controller menu item has the correct controller class');
$this->assertEquals($menuItem->priority, singleton('CMSMenuTest_LeftAndMainController')->stat('menu_priority'),
$this->assertEquals($menuItem->priority, CMSMenuTest\LeftAndMainController::singleton()->stat('menu_priority'),
'Controller menu item has the correct priority');
CMSMenu::clear_menu();
// Add another controller
CMSMenu::add_controller('CMSMenuTest_CustomTitle');
CMSMenu::add_controller(CMSMenuTest\CustomTitle::class);
$menuItems = CMSMenu::get_menu_items();
$menuItem = $menuItems['CMSMenuTest_CustomTitle'];
$this->assertInstanceOf('SilverStripe\\Admin\\CMSMenuItem', $menuItem, 'Controller menu item is of class CMSMenuItem');
$this->assertEquals('CMSMenuTest_CustomTitle (localised)', $menuItem->title);
$menuItem = $menuItems['SilverStripe-Admin-Tests-CMSMenuTest-CustomTitle'];
$this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'Controller menu item is of class CMSMenuItem');
$this->assertEquals(CMSMenuTest\CustomTitle::class . ' (localised)', $menuItem->title);
CMSMenu::clear_menu();
// Add a link to the menu
CMSMenu::add_link('LinkCode', 'link title', 'http://www.example.com');
$menuItems = CMSMenu::get_menu_items();
$menuItem = $menuItems['LinkCode'];
$this->assertInstanceOf('SilverStripe\\Admin\\CMSMenuItem', $menuItem, 'Link menu item is of class CMSMenuItem');
$this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'Link menu item is of class CMSMenuItem');
$this->assertEquals($menuItem->title, 'link title', 'Link menu item has the correct title');
$this->assertEquals($menuItem->url,'http://www.example.com', 'Link menu item has the correct link');
$this->assertNull($menuItem->controller, 'Link menu item has no controller class');
@ -61,10 +54,10 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
public function testRemove() {
CMSMenu::clear_menu();
CMSMenu::add_menu_item('custom', 'Custom Title', 'custom');
CMSMenu::add_menu_item('other', 'Other Section', 'other', 'CMSMenuTest_LeftAndMainController');
CMSMenu::add_menu_item('other', 'Other Section', 'other', CMSMenuTest\LeftAndMainController::class);
$this->assertNotEmpty(CMSMenu::get_menu_items());
CMSMenu::remove_menu_class('CMSMenuTest_LeftAndMainController');
CMSMenu::remove_menu_class(CMSMenuTest\LeftAndMainController::class);
CMSMenu::remove_menu_item('custom');
$this->assertEmpty(CMSMenu::get_menu_items());
@ -92,10 +85,9 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
// 1.) SecurityAdmin is included
// 2.) LeftAndMain & ModelAdmin are excluded
$cmsClasses = CMSMenu::get_cms_classes();
$this->assertContains('SilverStripe\\Admin\\SecurityAdmin', $cmsClasses, 'SecurityAdmin included in valid CMS Classes');
$this->assertNotContains('SilverStripe\\Admin\\LeftAndMain', $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
$this->assertNotContains('SilverStripe\\Admin\\ModelAdmin', $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
$this->assertContains(SecurityAdmin::class, $cmsClasses, 'SecurityAdmin included in valid CMS Classes');
$this->assertNotContains(LeftAndMain::class, $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
$this->assertNotContains(ModelAdmin::class, $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
}
public function testAdvancedMenuHandling() {
@ -104,12 +96,16 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
CMSMenu::clear_menu();
CMSMenu::populate_menu();
$menuItem = CMSMenu::get_menu_item('SilverStripe-Admin-SecurityAdmin');
$this->assertInstanceOf('SilverStripe\\Admin\\CMSMenuItem', $menuItem, 'SecurityAdmin menu item exists');
$this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'SecurityAdmin menu item exists');
$this->assertContains($menuItem->url, SecurityAdmin::singleton()->Link(), 'Menu item has the correct link');
$this->assertEquals($menuItem->controller, 'SilverStripe\\Admin\\SecurityAdmin', 'Menu item has the correct controller class');
$this->assertEquals(
$menuItem->priority,
SecurityAdmin::class,
$menuItem->controller,
'Menu item has the correct controller class'
);
$this->assertEquals(
SecurityAdmin::singleton()->stat('menu_priority'),
$menuItem->priority,
'Menu item has the correct priority'
);
@ -128,31 +124,3 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
}
}
/**
* @package framework
* @subpackage tests
*/
class CMSMenuTest_LeftAndMainController extends LeftAndMain implements TestOnly {
private static $url_segment = 'CMSMenuTest_LeftAndMainController';
private static $menu_title = 'CMSMenuTest_LeftAndMainController';
private static $menu_priority = 50;
}
class CMSMenuTest_CustomTitle extends LeftAndMain implements TestOnly {
private static $url_segment = 'CMSMenuTest_CustomTitle';
private static $menu_priority = 50;
public static function menu_title($class = null, $localised = false) {
if($localised) {
return __CLASS__ . ' (localised)';
} else {
return __CLASS__ . ' (unlocalised)';
}
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace SilverStripe\Admin\Tests\CMSMenuTest;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Dev\TestOnly;
class CustomTitle extends LeftAndMain implements TestOnly
{
private static $url_segment = 'CMSMenuTest_CustomTitle';
private static $menu_priority = 50;
public static function menu_title($class = null, $localised = false)
{
if ($localised) {
return __CLASS__ . ' (localised)';
} else {
return __CLASS__ . ' (unlocalised)';
}
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace SilverStripe\Admin\Tests\CMSMenuTest;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Dev\TestOnly;
class LeftAndMainController extends LeftAndMain implements TestOnly
{
private static $url_segment = 'CMSMenuTest_LeftAndMainController';
private static $menu_title = 'CMSMenuTest_LeftAndMainController';
private static $menu_priority = 50;
}

View File

@ -2,19 +2,9 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Security\Member;
/**
* @package framework
* @subpackage tests
*/
class CMSProfileControllerTest extends FunctionalTest {
protected static $fixture_file = 'CMSProfileControllerTest.yml';
@ -22,8 +12,8 @@ class CMSProfileControllerTest extends FunctionalTest {
public $autoFollowRedirection = false;
public function testMemberCantEditAnother() {
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user1');
$anotherMember = $this->objFromFixture('SilverStripe\\Security\\Member', 'user2');
$member = $this->objFromFixture(Member::class, 'user1');
$anotherMember = $this->objFromFixture(Member::class, 'user2');
$this->session()->inst_set('loggedInAs', $member->ID);
$response = $this->post('admin/myprofile/EditForm', array(
@ -37,13 +27,13 @@ class CMSProfileControllerTest extends FunctionalTest {
'Password[_ConfirmPassword]' => 'password',
));
$anotherMember = $this->objFromFixture('SilverStripe\\Security\\Member', 'user2');
$anotherMember = $this->objFromFixture(Member::class, 'user2');
$this->assertNotEquals($anotherMember->FirstName, 'JoeEdited', 'FirstName field stays the same');
}
public function testMemberEditsOwnProfile() {
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user3');
$member = $this->objFromFixture(Member::class, 'user3');
$this->session()->inst_set('loggedInAs', $member->ID);
$response = $this->post('admin/myprofile/EditForm', array(
@ -57,16 +47,18 @@ class CMSProfileControllerTest extends FunctionalTest {
'Password[_ConfirmPassword]' => 'password',
));
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user3');
$member = $this->objFromFixture(Member::class, 'user3');
$this->assertEquals('JoeEdited', $member->FirstName, 'FirstName field was changed');
}
public function testExtendedPermissionsStopEditingOwnProfile() {
$existingExtensions = Member::config()->get('extensions');
Member::config()->update('extensions', array('CMSProfileControllerTestExtension'));
Member::config()->update('extensions', [
CMSProfileControllerTest\TestExtension::class
]);
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user1');
$member = $this->objFromFixture(Member::class, 'user1');
$this->session()->inst_set('loggedInAs', $member->ID);
$response = $this->post('admin/myprofile/EditForm', array(
@ -80,7 +72,7 @@ class CMSProfileControllerTest extends FunctionalTest {
'Password[_ConfirmPassword]' => 'password',
));
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user1');
$member = $this->objFromFixture(Member::class, 'user1');
$this->assertNotEquals($member->FirstName, 'JoeEdited',
'FirstName field was NOT changed because we modified canEdit');
@ -91,15 +83,3 @@ class CMSProfileControllerTest extends FunctionalTest {
}
}
/**
* @package framework
* @subpackage tests
*/
class CMSProfileControllerTestExtension extends DataExtension {
public function canEdit($member = null) {
return false;
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Admin\Tests\CMSProfileControllerTest;
use SilverStripe\ORM\DataExtension;
class TestExtension extends DataExtension
{
public function canEdit($member = null)
{
return false;
}
}

View File

@ -2,16 +2,15 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Admin\CampaignAdmin;
use SilverStripe\ORM\Versioning\ChangeSet;
use SilverStripe\ORM\UnexpectedDataException;
use ReflectionClass;
class CampaignAdminTest extends SapphireTest
{
protected $extraDataObjects = [
CampaignAdminTest\InvalidChangeSet::class,
];
/**
* Call a protected method on an object via reflection
@ -19,27 +18,20 @@ class CampaignAdminTest extends SapphireTest
* @param object $object The object to call the method on
* @param string $method The name of the method
* @param array $args The arguments to pass to the method
* @return mixed
*/
function callProtectedMethod($object, $method, $args = []) {
protected function callProtectedMethod($object, $method, $args = []) {
$class = new ReflectionClass(get_class($object));
$methodObj = $class->getMethod($method);
$methodObj->setAccessible(true);
return $methodObj->invokeArgs($object, $args);
}
function testInvalidDataHandling() {
$changeset = new CampaignAdminTest_InvalidChangeSet();
public function testInvalidDataHandling() {
$changeset = new CampaignAdminTest\InvalidChangeSet();
$admin = new CampaignAdmin();
$result = $this->callProtectedMethod($admin, 'getChangeSetResource', [$changeset] );
$this->assertEquals('Corrupt database! bad data' , $result['Description']);
}
}
class CampaignAdminTest_InvalidChangeSet extends ChangeSet
{
function sync()
{
throw new UnexpectedDataException("bad data");
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Admin\Tests\CampaignAdminTest;
use SilverStripe\ORM\UnexpectedDataException;
use SilverStripe\ORM\Versioning\ChangeSet;
class InvalidChangeSet extends ChangeSet
{
public function sync()
{
throw new UnexpectedDataException("bad data");
}
}

View File

@ -2,30 +2,29 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\ORM\DataObject;
use SilverStripe\Admin\CMSMenu;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Security\Member;
use SilverStripe\View\Requirements;
/**
* @package framework
* @subpackage tests
*/
class LeftAndMainTest extends FunctionalTest {
protected static $fixture_file = 'LeftAndMainTest.yml';
protected $extraDataObjects = array('LeftAndMainTest_Object');
protected $extraDataObjects = [
LeftAndMainTest\TestObject::class
];
protected $extraControllers = [
LeftAndMainTest\TestController::class,
];
protected $backupCombined;
public function setUp() {
public function setUp()
{
parent::setUp();
// @todo fix controller stack problems and re-activate
@ -35,10 +34,10 @@ class LeftAndMainTest extends FunctionalTest {
LeftAndMain::config()
->update('extra_requirements_css', array(
FRAMEWORK_DIR . '/tests/assets/LeftAndMainTest.css'
FRAMEWORK_ADMIN_DIR . '/tests/assets/LeftAndMainTest.css'
))
->update('extra_requirements_javascript', array(
FRAMEWORK_DIR . '/tests/assets/LeftAndMainTest.js'
FRAMEWORK_ADMIN_DIR . '/tests/assets/LeftAndMainTest.js'
));
Requirements::set_combined_files_enabled(false);
@ -66,9 +65,8 @@ class LeftAndMainTest extends FunctionalTest {
Requirements::set_combined_files_enabled($this->backupCombined);
}
public function testExtraCssAndJavascript() {
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
$admin = $this->objFromFixture(Member::class, 'admin');
$this->session()->inst_set('loggedInAs', $admin->ID);
$response = $this->get('LeftAndMainTest_Controller');
@ -86,7 +84,7 @@ class LeftAndMainTest extends FunctionalTest {
$this->logInWithPermission('ADMIN');
// forcing sorting for non-MySQL
$rootPages = LeftAndMainTest_Object::get()
$rootPages = LeftAndMainTest\TestObject::get()
->filter("ParentID", 0)
->sort('"ID"');
$siblingIDs = $rootPages->column('ID');
@ -105,9 +103,9 @@ class LeftAndMainTest extends FunctionalTest {
$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
$this->assertEquals(200, $response->getStatusCode());
$page1 = DataObject::get_by_id('LeftAndMainTest_Object', $page1->ID, false);
$page2 = DataObject::get_by_id('LeftAndMainTest_Object', $page2->ID, false);
$page3 = DataObject::get_by_id('LeftAndMainTest_Object', $page3->ID, false);
$page1 = DataObject::get_by_id(LeftAndMainTest\TestObject::class, $page1->ID, false);
$page2 = DataObject::get_by_id(LeftAndMainTest\TestObject::class, $page2->ID, false);
$page3 = DataObject::get_by_id(LeftAndMainTest\TestObject::class, $page3->ID, false);
$this->assertEquals(2, $page1->Sort, 'Page1 is sorted after Page2');
$this->assertEquals(1, $page2->Sort, 'Page2 is sorted before Page1');
@ -117,10 +115,10 @@ class LeftAndMainTest extends FunctionalTest {
public function testSaveTreeNodeParentID() {
$this->logInWithPermission('ADMIN');
$page2 = $this->objFromFixture('LeftAndMainTest_Object', 'page2');
$page3 = $this->objFromFixture('LeftAndMainTest_Object', 'page3');
$page31 = $this->objFromFixture('LeftAndMainTest_Object', 'page31');
$page32 = $this->objFromFixture('LeftAndMainTest_Object', 'page32');
$page2 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page2');
$page3 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page3');
$page31 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page31');
$page32 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page32');
// Move page2 into page3, between page3.1 and page 3.2
$siblingIDs = array(
@ -135,9 +133,9 @@ class LeftAndMainTest extends FunctionalTest {
);
$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
$this->assertEquals(200, $response->getStatusCode());
$page2 = DataObject::get_by_id('LeftAndMainTest_Object', $page2->ID, false);
$page31 = DataObject::get_by_id('LeftAndMainTest_Object', $page31->ID, false);
$page32 = DataObject::get_by_id('LeftAndMainTest_Object', $page32->ID, false);
$page2 = DataObject::get_by_id(LeftAndMainTest\TestObject::class, $page2->ID, false);
$page31 = DataObject::get_by_id(LeftAndMainTest\TestObject::class, $page31->ID, false);
$page32 = DataObject::get_by_id(LeftAndMainTest\TestObject::class, $page32->ID, false);
$this->assertEquals($page3->ID, $page2->ParentID, 'Moved page gets new parent');
$this->assertEquals(1, $page31->Sort, 'Children pages before insertaion are unaffected');
@ -149,7 +147,7 @@ class LeftAndMainTest extends FunctionalTest {
* Check that all subclasses of leftandmain can be accessed
*/
public function testLeftAndMainSubclasses() {
$adminuser = $this->objFromFixture('SilverStripe\\Security\\Member','admin');
$adminuser = $this->objFromFixture(Member::class,'admin');
$this->session()->inst_set('loggedInAs', $adminuser->ID);
$this->resetMenu();
@ -175,9 +173,9 @@ class LeftAndMainTest extends FunctionalTest {
}
public function testCanView() {
$adminuser = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
$securityonlyuser = $this->objFromFixture('SilverStripe\\Security\\Member', 'securityonlyuser');
$allcmssectionsuser = $this->objFromFixture('SilverStripe\\Security\\Member', 'allcmssectionsuser');
$adminuser = $this->objFromFixture(Member::class, 'admin');
$securityonlyuser = $this->objFromFixture(Member::class, 'securityonlyuser');
$allcmssectionsuser = $this->objFromFixture(Member::class, 'allcmssectionsuser');
// anonymous user
$this->session()->inst_set('loggedInAs', null);
@ -243,11 +241,11 @@ class LeftAndMainTest extends FunctionalTest {
* Test {@see LeftAndMain::updatetreenodes}
*/
public function testUpdateTreeNodes() {
$page1 = $this->objFromFixture('LeftAndMainTest_Object', 'page1');
$page2 = $this->objFromFixture('LeftAndMainTest_Object', 'page2');
$page3 = $this->objFromFixture('LeftAndMainTest_Object', 'page3');
$page31 = $this->objFromFixture('LeftAndMainTest_Object', 'page31');
$page32 = $this->objFromFixture('LeftAndMainTest_Object', 'page32');
$page1 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page1');
$page2 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page2');
$page3 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page3');
$page31 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page31');
$page32 = $this->objFromFixture(LeftAndMainTest\TestObject::class, 'page32');
$this->logInWithPermission('ADMIN');
// Check page
@ -285,35 +283,3 @@ class LeftAndMainTest extends FunctionalTest {
$this->assertEquals(0, count($data));
}
}
/**
* @package framework
* @subpackage tests
*/
class LeftAndMainTest_Controller extends LeftAndMain implements TestOnly {
protected $template = 'BlankPage';
private static $tree_class = 'LeftAndMainTest_Object';
}
/**
* @package framework
* @subpackage tests
*/
class LeftAndMainTest_Object extends DataObject implements TestOnly {
private static $db = array(
'Title' => 'Varchar',
'URLSegment' => 'Varchar',
'Sort' => 'Int',
);
private static $default_sort = '"Sort"';
private static $extensions = array(
'SilverStripe\\ORM\\Hierarchy\\Hierarchy'
);
public function CMSTreeClasses() {}
}

View File

@ -1,4 +1,4 @@
LeftAndMainTest_Object:
SilverStripe\Admin\Tests\LeftAndMainTest\TestObject:
page1:
Title: Page 1
Sort: 1
@ -10,11 +10,11 @@ LeftAndMainTest_Object:
Sort: 3
page31:
Title: Page 3.1
Parent: =>LeftAndMainTest_Object.page3
Parent: =>SilverStripe\Admin\Tests\LeftAndMainTest\TestObject.page3
Sort: 1
page32:
Title: Page 3.2
Parent: =>LeftAndMainTest_Object.page3
Parent: =>SilverStripe\Admin\Tests\LeftAndMainTest\TestObject.page3
Sort: 2
page4:
Title: Page 4

View File

@ -0,0 +1,19 @@
<?php
namespace SilverStripe\Admin\Tests\LeftAndMainTest;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\TestOnly;
class TestController extends LeftAndMain implements TestOnly
{
protected $template = 'BlankPage';
private static $tree_class = TestObject::class;
public function Link($action = null)
{
return Controller::join_links('LeftAndMainTest_Controller', $action, '/');
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace SilverStripe\Admin\Tests\LeftAndMainTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Hierarchy\Hierarchy;
class TestObject extends DataObject implements TestOnly
{
private static $table_name = 'LeftAndMainTest_Object';
private static $db = array(
'Title' => 'Varchar',
'URLSegment' => 'Varchar',
'Sort' => 'Int',
);
private static $default_sort = '"Sort"';
private static $extensions = [
Hierarchy::class
];
public function CMSTreeClasses()
{
}
}

View File

@ -2,42 +2,40 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
class ModelAdminTest extends FunctionalTest {
protected static $fixture_file = 'ModelAdminTest.yml';
protected $extraDataObjects = array(
'ModelAdminTest_Admin',
'ModelAdminTest_Contact',
'ModelAdminTest_Player'
);
protected $extraDataObjects = [
ModelAdminTest\Contact::class,
ModelAdminTest\Player::class
];
protected $extraControllers = [
ModelAdminTest\ContactAdmin::class,
ModelAdminTest\PlayerAdmin::class,
];
public function testModelAdminOpens() {
$this->autoFollowRedirection = false;
$this->logInAs('admin');
$this->assertTrue((bool)Permission::check("ADMIN"));
$this->assertEquals(200, $this->get('ModelAdminTest_Admin')->getStatusCode());
$this->assertEquals(200, $this->get('ContactAdmin')->getStatusCode());
}
public function testExportFieldsDefaultIsSummaryFields() {
$admin = new ModelAdminTest_Admin();
$admin = new ModelAdminTest\ContactAdmin();
$admin->doInit();
$this->assertEquals(
$admin->getExportFields(),
ModelAdminTest_Contact::singleton()->summaryFields()
ModelAdminTest\Contact::singleton()->summaryFields()
);
}
public function testExportFieldsOverloadedMethod() {
$admin = new ModelAdminTest_PlayerAdmin();
$admin = new ModelAdminTest\PlayerAdmin();
$admin->doInit();
$this->assertEquals($admin->getExportFields(), array(
'Name' => 'Name',
@ -46,44 +44,3 @@ class ModelAdminTest extends FunctionalTest {
}
}
class ModelAdminTest_Admin extends ModelAdmin implements TestOnly {
private static $url_segment = 'testadmin';
private static $managed_models = array(
'ModelAdminTest_Contact',
);
}
class ModelAdminTest_PlayerAdmin extends ModelAdmin implements TestOnly {
private static $url_segment = 'testadmin';
private static $managed_models = array(
'ModelAdminTest_Player'
);
public function getExportFields() {
return array(
'Name' => 'Name',
'Position' => 'Position'
);
}
}
class ModelAdminTest_Contact extends DataObject implements TestOnly {
private static $db = array(
'Name' => 'Varchar',
'Phone' => 'Varchar',
);
private static $summary_fields = array(
'Name' => 'Name',
'Phone' => 'Phone'
);
}
class ModelAdminTest_Player extends DataObject implements TestOnly {
private static $db = array(
'Name' => 'Varchar',
'Position' => 'Varchar',
);
private static $has_one = array(
'Contact' => 'ModelAdminTest_Contact'
);
}

View File

@ -1,4 +1,4 @@
ModelAdminTest_Contact:
SilverStripe\Admin\Tests\ModelAdminTest\Contact:
sam:
Name: Sam
Phone: 021 123 456

View File

@ -0,0 +1,19 @@
<?php
namespace SilverStripe\Admin\Tests\ModelAdminTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
class Contact extends DataObject implements TestOnly
{
private static $table_name = 'ModelAdminTest_Contact';
private static $db = array(
'Name' => 'Varchar',
'Phone' => 'Varchar',
);
private static $summary_fields = array(
'Name' => 'Name',
'Phone' => 'Phone'
);
}

View File

@ -0,0 +1,21 @@
<?php
namespace SilverStripe\Admin\Tests\ModelAdminTest;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\TestOnly;
class ContactAdmin extends ModelAdmin implements TestOnly
{
private static $url_segment = 'contactadmin';
private static $managed_models = array(
Contact::class,
);
public function Link($action = null) {
if(!$action) $action = $this->sanitiseClassName($this->modelClass);
return Controller::join_links('ContactAdmin', $action, '/');
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace SilverStripe\Admin\Tests\ModelAdminTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
class Player extends DataObject implements TestOnly
{
private static $table_name = 'ModelAdminTest_Player';
private static $db = array(
'Name' => 'Varchar',
'Position' => 'Varchar',
);
private static $has_one = array(
'Contact' => Contact::class
);
}

View File

@ -0,0 +1,29 @@
<?php
namespace SilverStripe\Admin\Tests\ModelAdminTest;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\TestOnly;
class PlayerAdmin extends ModelAdmin implements TestOnly
{
private static $url_segment = 'playeradmin';
private static $managed_models = array(
Player::class
);
public function getExportFields()
{
return array(
'Name' => 'Name',
'Position' => 'Position'
);
}
public function Link($action = null) {
if(!$action) $action = $this->sanitiseClassName($this->modelClass);
return Controller::join_links('PlayerAdmin', $action, '/');
}
}

View File

@ -2,21 +2,19 @@
namespace SilverStripe\Admin\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Security\Group;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
/**
* @package cms
* @subpackage tests
*/
class SecurityAdminTest extends FunctionalTest {
protected static $fixture_file = 'LeftAndMainTest.yml';
protected $extraDataObjects = array('LeftAndMainTest_Object');
protected $extraDataObjects = [
LeftAndMainTest\TestObject::class,
];
// TODO Fix export feature (moved from MemberTableField to GridFieldExportButton)
// public function testGroupExport() {
@ -55,11 +53,11 @@ class SecurityAdminTest extends FunctionalTest {
// }
public function testPermissionFieldRespectsHiddenPermissions() {
$this->session()->inst_set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
$this->session()->inst_set('loggedInAs', $this->idFromFixture(Member::class, 'admin'));
$group = $this->objFromFixture('SilverStripe\\Security\\Group', 'admin');
$group = $this->objFromFixture(Group::class, 'admin');
Config::inst()->update('SilverStripe\\Security\\Permission', 'hidden_permissions', array('CMS_ACCESS_ReportAdmin'));
Config::inst()->update(Permission::class, 'hidden_permissions', array('CMS_ACCESS_ReportAdmin'));
$response = $this->get(sprintf('admin/security/EditForm/field/Groups/item/%d/edit', $group->ID));
$this->assertContains(

View File

@ -16,7 +16,7 @@
It is safe to remove this file for normal website operation.
-->
<phpunit bootstrap="tests/php/bootstrap.php" colors="true">
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>

View File

@ -98,7 +98,7 @@ class DBClassName extends DBEnum {
return $baseClass;
}
// Fallback to global default
return 'SilverStripe\ORM\DataObject';
return DataObject::class;
}
/**

View File

@ -32,7 +32,7 @@ class AssetControlExtensionTest extends SapphireTest {
// Setup fixture manually
$object1 = new AssetControlExtensionTest\VersionedObject();
$object1->Title = 'My object';
$fish1 = realpath(__DIR__ .'/../ORM/testimages/test-image-high-quality.jpg');
$fish1 = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$object1->Header->setFromLocalFile($fish1, 'Header/MyObjectHeader.jpg');
$object1->Download->setFromString('file content', 'Documents/File.txt');
$object1->write();
@ -151,7 +151,7 @@ class AssetControlExtensionTest extends SapphireTest {
$object3TupleOld = $object3->Header->getValue();
// Replace image and write each to filesystem
$fish1 = realpath(__DIR__ .'/../ORM/testimages/test-image-high-quality.jpg');
$fish1 = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$object1->Header->setFromLocalFile($fish1, 'Header/Replaced_MyObjectHeader.jpg');
$object1->write();
$object2->Image->setFromLocalFile($fish1, 'Images/Replaced_BeautifulFish.jpg');

View File

@ -8,9 +8,6 @@ use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link SS_FileFinder} class.
*
* @package framework
* @subpackage tests
*/
class FileFinderTest extends SapphireTest {

View File

@ -44,7 +44,7 @@ class FileMigrationHelperTest extends SapphireTest {
TestAssetStore::activate('FileMigrationHelperTest/assets');
// Ensure that each file has a local record file in this new assets base
$from = FRAMEWORK_PATH . '/tests/php/ORM/testimages/test-image-low-quality.jpg';
$from = FRAMEWORK_PATH . '/tests/php/ORM/ImageTest/test-image-low-quality.jpg';
foreach(File::get()->exclude('ClassName', Folder::class) as $file) {
$dest = TestAssetStore::base_path() . '/' . $file->generateFilename();
Filesystem::makeFolder(dirname($dest));

View File

@ -7,10 +7,6 @@ use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\Parsers\Transliterator;
/**
* @package framework
* @subpackage tests
*/
class FileNameFilterTest extends SapphireTest {
public function setUp() {

View File

@ -13,9 +13,6 @@ use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
/**
* @author Ingo Schommer (ingo at silverstripe dot com)
*
* @package framework
* @subpackage tests
*/
class FolderTest extends SapphireTest {

View File

@ -8,9 +8,6 @@ use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link GD} class.
*
* @package framework
* @subpackage tests
*/
class GDTest extends SapphireTest {

View File

@ -56,7 +56,7 @@ class AssetStoreTest extends SapphireTest
);
// Test setFromStream (seekable)
$fish1 = realpath(__DIR__ . '/../../ORM/testimages/test-image-high-quality.jpg');
$fish1 = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-high-quality.jpg');
$fish1Stream = fopen($fish1, 'r');
$fish1Tuple = $backend->setFromStream($fish1Stream, 'parent/awesome-fish.jpg');
fclose($fish1Stream);
@ -71,7 +71,7 @@ class AssetStoreTest extends SapphireTest
// Test with non-seekable streams
TestAssetStore::$seekable_override = false;
$fish2 = realpath(__DIR__ . '/../../ORM/testimages/test-image-low-quality.jpg');
$fish2 = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-low-quality.jpg');
$fish2Stream = fopen($fish2, 'r');
$fish2Tuple = $backend->setFromStream($fish2Stream, 'parent/mediocre-fish.jpg');
fclose($fish2Stream);
@ -95,7 +95,7 @@ class AssetStoreTest extends SapphireTest
$backend = $this->getBackend();
// Put a file in
$fish1 = realpath(__DIR__ . '/../../ORM/testimages/test-image-high-quality.jpg');
$fish1 = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish1);
$fish1Tuple = $backend->setFromLocalFile($fish1, 'directory/lovely-fish.jpg');
$this->assertEquals(
@ -112,7 +112,7 @@ class AssetStoreTest extends SapphireTest
);
// Write a different file with same name. Should not detect duplicates since sha are different
$fish2 = realpath(__DIR__ . '/../../ORM/testimages/test-image-low-quality.jpg');
$fish2 = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-low-quality.jpg');
try {
$fish2Tuple = $backend->setFromLocalFile(
$fish2,
@ -301,7 +301,7 @@ class AssetStoreTest extends SapphireTest
$backend = $this->getBackend();
// jpg
$fish = realpath(__DIR__ . '/../../ORM/testimages/test-image-high-quality.jpg');
$fish = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-high-quality.jpg');
$fishTuple = $backend->setFromLocalFile($fish, 'parent/awesome-fish.jpg');
$this->assertEquals(
'image/jpeg',
@ -335,7 +335,7 @@ class AssetStoreTest extends SapphireTest
$backend = $this->getBackend();
// Put a file in
$fish1 = realpath(__DIR__ . '/../../ORM/testimages/test-image-high-quality.jpg');
$fish1 = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish1);
$fish1Tuple = $backend->setFromLocalFile($fish1, 'directory/lovely-fish.jpg');
$this->assertEquals(
@ -353,7 +353,7 @@ class AssetStoreTest extends SapphireTest
// Write a different file with same name.
// Since we are using legacy filenames, this should generate a new filename
$fish2 = realpath(__DIR__ . '/../../ORM/testimages/test-image-low-quality.jpg');
$fish2 = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-low-quality.jpg');
try {
$backend->setFromLocalFile(
$fish2,
@ -456,7 +456,7 @@ class AssetStoreTest extends SapphireTest
public function testProtect()
{
$backend = $this->getBackend();
$fish = realpath(__DIR__ . '/../../ORM/testimages/test-image-high-quality.jpg');
$fish = realpath(__DIR__ . '/../../ORM/ImageTest/test-image-high-quality.jpg');
$fishTuple = $backend->setFromLocalFile($fish, 'parent/lovely-fish.jpg');
$fishVariantTuple = $backend->setFromLocalFile($fish, $fishTuple['Filename'], $fishTuple['Hash'], 'copy');

View File

@ -9,10 +9,6 @@ use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Versioning\Versioned;
/**
* @package framework
* @subpackage tests
*/
class UploadTest extends SapphireTest {
protected $usesDatabase = true;

View File

@ -3,28 +3,13 @@
namespace SilverStripe\Control\Tests;
use SilverStripe\Control\Tests\DirectorTest\TestController;
use SilverStripe\ORM\DataModel;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Control\Director;
use SilverStripe\Control\RequestProcessor;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\RequestFilter;
use SilverStripe\Control\Controller;
/**
* @package framework
* @subpackage tests
*
* @todo test Director::alternateBaseFolder()
*/
class DirectorTest extends SapphireTest {
@ -433,7 +418,7 @@ class DirectorTest extends SapphireTest {
}
/**
* @covers SilverStripe\Control\Director::extract_request_headers()
* @covers \SilverStripe\Control\Director::extract_request_headers()
*/
public function testExtractRequestHeaders() {
$request = array(

View File

@ -5,11 +5,6 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\Email\Mailer;
/**
* @package framework
* @subpackage tests
*/
class EmailTest extends SapphireTest {
public function testAttachFiles() {

View File

@ -5,12 +5,6 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Control\Email\Mailer;
/**
* @package framework
* @subpackage tests
*/
class MailerTest extends SapphireTest {
/**

View File

@ -6,10 +6,6 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
/**
* @package framework
* @subpackage tests
*/
class HTTPResponseTest extends SapphireTest {
public function testStatusDescriptionStripsNewlines() {

View File

@ -11,8 +11,6 @@ use SilverStripe\Control\HTTP;
* Tests the {@link HTTP} class
*
* @skipUpgrade
* @package framework
* @subpackage tests
*/
class HTTPTest extends FunctionalTest {

View File

@ -5,10 +5,6 @@ namespace SilverStripe\Control\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\NullHTTPRequest;
/**
* @package framework
* @subpackage tests
*/
class NullHTTPRequestTest extends SapphireTest {
public function testAllHttpVerbsAreFalse() {

View File

@ -1,28 +1,23 @@
<?php
use SilverStripe\Control\Controller;
namespace SilverStripe\Control\Tests\RSS;
use SilverStripe\Control\Director;
use SilverStripe\Control\RSS\RSSFeed;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ViewableData;
use SilverStripe\View\Parsers\ShortcodeParser;
/**
* @package framework
* @subpackage tests
*/
class RSSFeedTest extends SapphireTest {
protected static $original_host;
public function testRSSFeed() {
$list = new ArrayList();
$list->push(new RSSFeedTest_ItemA());
$list->push(new RSSFeedTest_ItemB());
$list->push(new RSSFeedTest_ItemC());
$list->push(new RSSFeedTest\ItemA());
$list->push(new RSSFeedTest\ItemB());
$list->push(new RSSFeedTest\ItemC());
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->outputToBrowser();
@ -63,7 +58,7 @@ class RSSFeedTest extends SapphireTest {
public function testRSSFeedWithShortcode() {
$list = new ArrayList();
$list->push(new RSSFeedTest_ItemD());
$list->push(new RSSFeedTest\ItemD());
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->outputToBrowser();
@ -92,8 +87,10 @@ class RSSFeedTest extends SapphireTest {
public function setUp() {
parent::setUp();
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/');
if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST'];
Config::inst()->update(Director::class, 'alternate_base_url', '/');
if(!self::$original_host) {
self::$original_host = $_SERVER['HTTP_HOST'];
}
$_SERVER['HTTP_HOST'] = 'www.example.org';
ShortcodeParser::get('default')->register('test_shortcode', function() {
@ -103,91 +100,6 @@ class RSSFeedTest extends SapphireTest {
public function tearDown() {
parent::tearDown();
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', null);
$_SERVER['HTTP_HOST'] = self::$original_host;
}
}
class RSSFeedTest_ItemA extends ViewableData {
// RSS-feed items must have $casting/$db information.
private static $casting = array(
'Title' => 'Varchar',
'Content' => 'Text',
'AltContent' => 'Text',
);
public function getTitle() {
return "ItemA";
}
public function getContent() {
return "ItemA Content";
}
public function getAltContent() {
return "ItemA AltContent";
}
public function Link($action = null) {
return Controller::join_links("item-a/", $action);
}
}
class RSSFeedTest_ItemB extends ViewableData {
// ItemB tests without $casting
public function Title() {
return "ItemB";
}
public function AbsoluteLink() {
return "http://www.example.com/item-b.html";
}
public function Content() {
return "ItemB Content";
}
public function AltContent() {
return "ItemB AltContent";
}
}
class RSSFeedTest_ItemC extends ViewableData {
// ItemC tests fields - Title has casting, Content doesn't.
private static $casting = array(
'Title' => 'Varchar',
'AltContent' => 'Text',
);
public $Title = "ItemC";
public $Content = "ItemC Content";
public $AltContent = "ItemC AltContent";
public function Link() {
return "item-c.html";
}
public function AbsoluteLink() {
return "http://www.example.com/item-c.html";
}
}
class RSSFeedTest_ItemD extends ViewableData {
// ItemD test fields - all fields use casting but Content & AltContent cast as HTMLText
private static $casting = array(
'Title' => 'Varchar',
'Content' => 'HTMLText', // Supports shortcodes
);
public $Title = 'ItemD';
public $Content = '<p>ItemD Content [test_shortcode]</p>';
public function Link() {
return 'item-d.html';
}
public function AbsoluteLink() {
return 'http://www.example.org/item-d.html';
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace SilverStripe\Control\Tests\RSS\RSSFeedTest;
use SilverStripe\Control\Controller;
use SilverStripe\View\ViewableData;
class ItemA extends ViewableData
{
// RSS-feed items must have $casting/$db information.
private static $casting = array(
'Title' => 'Varchar',
'Content' => 'Text',
'AltContent' => 'Text',
);
public function getTitle()
{
return "ItemA";
}
public function getContent()
{
return "ItemA Content";
}
public function getAltContent()
{
return "ItemA AltContent";
}
public function Link($action = null)
{
return Controller::join_links("item-a/", $action);
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace SilverStripe\Control\Tests\RSS\RSSFeedTest;
use SilverStripe\View\ViewableData;
class ItemB extends ViewableData
{
// ItemB tests without $casting
public function Title()
{
return "ItemB";
}
public function AbsoluteLink()
{
return "http://www.example.com/item-b.html";
}
public function Content()
{
return "ItemB Content";
}
public function AltContent()
{
return "ItemB AltContent";
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace SilverStripe\Control\Tests\RSS\RSSFeedTest;
use SilverStripe\View\ViewableData;
class ItemC extends ViewableData
{
// ItemC tests fields - Title has casting, Content doesn't.
private static $casting = array(
'Title' => 'Varchar',
'AltContent' => 'Text',
);
public $Title = "ItemC";
public $Content = "ItemC Content";
public $AltContent = "ItemC AltContent";
public function Link()
{
return "item-c.html";
}
public function AbsoluteLink()
{
return "http://www.example.com/item-c.html";
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace SilverStripe\Control\Tests\RSS\RSSFeedTest;
use SilverStripe\View\ViewableData;
class ItemD extends ViewableData
{
// ItemD test fields - all fields use casting but Content & AltContent cast as HTMLText
private static $casting = array(
'Title' => 'Varchar',
'Content' => 'HTMLText', // Supports shortcodes
);
public $Title = 'ItemD';
public $Content = '<p>ItemD Content [test_shortcode]</p>';
public function Link()
{
return 'item-d.html';
}
public function AbsoluteLink()
{
return 'http://www.example.org/item-d.html';
}
}

View File

@ -2,24 +2,14 @@
namespace SilverStripe\Control\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Session;
/**
* Tests to cover the {@link Session} class
*
* @package framework
* @subpackage tests
*/
class SessionTest extends SapphireTest {
public function testGetSetBasics() {

View File

@ -5,10 +5,6 @@ namespace SilverStripe\Core\Tests\ClassInfoTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
/**
* @package framework
* @subpackage tests
*/
class BaseClass extends DataObject implements TestOnly
{
private static $table_name = 'ClassInfoTest_BaseClass';

View File

@ -5,10 +5,6 @@ namespace SilverStripe\Core\Tests\ClassInfoTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
/**
* @package framework
* @subpackage tests
*/
class BaseDataClass extends DataObject implements TestOnly
{
private static $table_name = 'ClassInfoTest_BaseDataClass';

View File

@ -2,10 +2,6 @@
namespace SilverStripe\Core\Tests\ClassInfoTest;
/**
* @package framework
* @subpackage tests
*/
class HasFields extends NoFields
{
private static $table_name = 'ClassInfoTest_HasFields';

View File

@ -2,10 +2,6 @@
namespace SilverStripe\Core\Tests\ClassInfoTest;
/**
* @package framework
* @subpackage tests
*/
class NoFields extends BaseDataClass
{
private static $table_name = 'ClassInfoTest_NoFields';

View File

@ -2,10 +2,6 @@
namespace SilverStripe\Core\Tests\ClassInfoTest;
/**
* @package framework
* @subpackage tests
*/
class WithRelation extends NoFields
{
private static $table_name = 'ClassInfoTest_WithRelation';

View File

@ -8,9 +8,6 @@ use SilverStripe\Control\Director;
/**
* Tests for the core of SilverStripe, such as how the temporary
* directory is determined throughout the framework.
*
* @package framework
* @subpackage tests
*/
class CoreTest extends SapphireTest {

View File

@ -6,9 +6,6 @@ use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link ClassManifest} class.
*
* @package framework
* @subpackage tests
*/
class ClassLoaderTest extends SapphireTest {

View File

@ -5,9 +5,6 @@ use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link ClassManifest} class.
*
* @package framework
* @subpackage tests
*/
class ClassManifestTest extends SapphireTest {

View File

@ -5,9 +5,6 @@ use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link ManifestFileFinder} class.
*
* @package framework
* @subpackage tests
*/
class ManifestFileFinderTest extends SapphireTest {

View File

@ -8,9 +8,6 @@ use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link ClassManifest} class.
*
* @package framework
* @subpackage tests
*/
class NamespacedClassManifestTest extends SapphireTest {

View File

@ -4,12 +4,8 @@ use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ThemeManifest;
use SilverStripe\Dev\SapphireTest;
/**
* Tests for the {@link TemplateLoader} class.
*
* @package framework
* @subpackage tests
*/
class ThemeResourceLoaderTest extends SapphireTest {

View File

@ -3,10 +3,6 @@
use SilverStripe\Core\Manifest\ClassManifest;
use SilverStripe\Dev\SapphireTest;
/**
* @package framework
* @subpackage tests
*/
class TokenisedRegularExpressionTest extends SapphireTest {
public function getTokens() {
return token_get_all(<<<PHP

View File

@ -6,10 +6,6 @@ use SilverStripe\Dev\BulkLoader_Result;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\Tests\BulkLoaderResultTest\Player;
/**
* @package framework
* @subpackage tests
*/
class BulkLoaderResultTest extends SapphireTest
{
protected $extraDataObjects = array(Player::class);

View File

@ -2,19 +2,14 @@
namespace SilverStripe\Dev\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\DevelopmentAdmin;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use Exception;
use SilverStripe\Dev\Tests\DevAdminControllerTest\Controller1;
/**
* Note: the running of this test is handled by the thing it's testing (DevelopmentAdmin controller).
*
* @package framework
* @package tests
*/
class DevAdminControllerTest extends FunctionalTest {

View File

@ -239,7 +239,7 @@ class CheckboxSetFieldTest extends SapphireTest {
// Invalid value should fail
$validator = new RequiredFields();
$fakeID = CheckboxSetFieldTest_Tag::get()->max('ID') + 1;
$fakeID = CheckboxSetFieldTest\Tag::get()->max('ID') + 1;
$field->setValue(array($fakeID));
$this->assertFalse(
$field->validate($validator),

View File

@ -3,19 +3,10 @@
namespace SilverStripe\Forms\Tests;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Storage\DBFile;
use SilverStripe\Control\Director;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
/**
* Description of DBFileTest
*
* @author dmooyman
*/
class DBFileTest extends SapphireTest {
protected $extraDataObjects = array(
@ -45,7 +36,7 @@ class DBFileTest extends SapphireTest {
$obj = new DBFileTest\TestObject();
// Test image tag
$fish = realpath(__DIR__ .'/../ORM/testimages/test-image-high-quality.jpg');
$fish = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish);
$obj->MyFile->setFromLocalFile($fish, 'awesome-fish.jpg');
$this->assertEquals(
@ -65,7 +56,7 @@ class DBFileTest extends SapphireTest {
$obj = new DBFileTest\ImageOnly();
// Test from image
$fish = realpath(__DIR__ .'/../ORM/testimages/test-image-high-quality.jpg');
$fish = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish);
$obj->MyFile->setFromLocalFile($fish, 'awesome-fish.jpg');
@ -78,7 +69,7 @@ class DBFileTest extends SapphireTest {
$obj = new DBFileTest\TestObject();
// Test from image
$fish = realpath(__DIR__ .'/../ORM/testimages/test-image-high-quality.jpg');
$fish = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish);
$obj->MyFile->setFromLocalFile($fish, 'private/awesome-fish.jpg', null, null, array(
'visibility' => AssetStore::VISIBILITY_PROTECTED

View File

@ -5,10 +5,6 @@ namespace SilverStripe\Forms\Tests\DatetimeFieldTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
/**
* @package framework
* @subpackage tests
*/
class Model extends DataObject implements TestOnly
{
private static $table_name = 'DatetimeFieldTest_Model';

View File

@ -5,10 +5,6 @@ namespace SilverStripe\Forms\Tests\FormFieldTest;
use SilverStripe\Core\Extension;
use SilverStripe\Dev\TestOnly;
/**
* @package framework
* @subpackage tests
*/
class TestExtension extends Extension implements TestOnly
{

View File

@ -8,7 +8,6 @@ use SilverStripe\Forms\Tests\FormTest\ControllerWithStrictPostCheck;
use SilverStripe\Forms\Tests\FormTest\Player;
use SilverStripe\Forms\Tests\FormTest\Team;
use SilverStripe\ORM\DataModel;
use SilverStripe\ORM\Tests\DataObjectTest\Team;
use SilverStripe\Security\SecurityToken;
use SilverStripe\Security\RandomGenerator;
use SilverStripe\Dev\CSSContentParser;

View File

@ -6,10 +6,6 @@ use SilverStripe\Core\Extension;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\Form;
/**
* @package framework
* @subpackage tests
*/
class DummyMediaFormFieldExtension extends Extension implements TestOnly
{
public static $fields = null;

View File

@ -89,8 +89,8 @@ class ChangeSetTest extends SapphireTest {
$cs->addObject($this->objFromFixture(ChangeSetTest\EndObjectChild::class, 'endchild1'));
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_End.end1' => ChangeSetItem::EXPLICITLY,
'ChangeSetTest_EndChild.endchild1' => ChangeSetItem::EXPLICITLY
ChangeSetTest\EndObject::class.'.end1' => ChangeSetItem::EXPLICITLY,
ChangeSetTest\EndObjectChild::class.'.endchild1' => ChangeSetItem::EXPLICITLY
]);
}
@ -105,12 +105,12 @@ class ChangeSetTest extends SapphireTest {
$cs->sync();
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY
]);
$cs->sync();
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY
]);
}
@ -126,7 +126,7 @@ class ChangeSetTest extends SapphireTest {
$cs->sync();
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY
]);
$end = $this->objFromFixture(ChangeSetTest\EndObject::class, 'end1');
@ -136,8 +136,8 @@ class ChangeSetTest extends SapphireTest {
$cs->sync();
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY,
'ChangeSetTest_End.end1' => ChangeSetItem::IMPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY,
ChangeSetTest\EndObject::class.'.end1' => ChangeSetItem::IMPLICITLY
]);
$baseItem = ChangeSetItem::get_for_object($base)->first();
@ -172,7 +172,7 @@ class ChangeSetTest extends SapphireTest {
$cs->sync();
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY
]);
$this->assertTrue($cs->isSynced());
@ -184,8 +184,8 @@ class ChangeSetTest extends SapphireTest {
$cs->sync();
$this->assertChangeSetLooksLike($cs, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY,
'ChangeSetTest_End.end1' => ChangeSetItem::IMPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY,
ChangeSetTest\EndObject::class.'.end1' => ChangeSetItem::IMPLICITLY
]);
$this->assertTrue($cs->isSynced());
}
@ -396,7 +396,7 @@ class ChangeSetTest extends SapphireTest {
// Assert changeset only contains root object
$this->assertChangeSetLooksLike($changeset, [
'ChangeSetTest_Base.base' => ChangeSetItem::EXPLICITLY
ChangeSetTest\BaseObject::class.'.base' => ChangeSetItem::EXPLICITLY
]);
$changeset->publish();

View File

@ -2,24 +2,21 @@
namespace SilverStripe\ORM\Tests;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Tests\ComponentSetTest\Player;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
class ComponentSetTest extends SapphireTest {
protected static $fixture_file = 'ComponentSetTest.yml';
protected $extraDataObjects = array(
Player::class,
ComponentSetTest\Player::class,
ComponentSetTest\Team::class,
);
public function testSetByIDListManyMany() {
$team1 = $this->objFromFixture('ComponentSetTest_Team', 'team1');
$player1_team1 = $this->objFromFixture('ComponentSetTest_Player', 'player1_team1');
$player2 = $this->objFromFixture('ComponentSetTest_Player', 'player2');
$team1 = $this->objFromFixture(ComponentSetTest\Team::class, 'team1');
$player1_team1 = $this->objFromFixture(ComponentSetTest\Player::class, 'player1_team1');
$player2 = $this->objFromFixture(ComponentSetTest\Player::class, 'player2');
$team1->Players()->setByIdList(array(
$player1_team1->ID,

View File

@ -3,7 +3,7 @@ SilverStripe\ORM\Tests\ComponentSetTest\Player:
Email: player1_team1@test.com
player2:
Email: player2@test.com
ComponentSetTest_Team:
SilverStripe\ORM\Tests\ComponentSetTest\Team:
team1:
Title: team1
Players: =>SilverStripe\ORM\Tests\ComponentSetTest\Player.player1_team1

View File

@ -7,7 +7,9 @@ use SilverStripe\ORM\DataObject;
class CustomDefault extends DataObject implements TestOnly
{
private static $default_classname = 'DBClassNameTest_CustomDefaultSubclass';
private static $table_name = 'DBClassNameTest_CustomDefault';
private static $default_classname = CustomDefaultSubclass::class;
private static $db = array(
'Title' => 'Varchar'

View File

@ -18,7 +18,7 @@ use Exception;
*/
class DBMoneyTest extends SapphireTest {
protected static $fixture_file = 'MoneyTest.yml';
protected static $fixture_file = 'DBMoneyTest.yml';
protected $extraDataObjects = array(
DBMoneyTest\TestObject::class,

View File

@ -1,4 +1,4 @@
SilverStripe\ORM\Tests\DBMoneyTest\DataObject:
SilverStripe\ORM\Tests\DBMoneyTest\TestObject:
test1:
MyMoneyCurrency: EUR
MyMoneyAmount: 1.23
@ -8,7 +8,7 @@ SilverStripe\ORM\Tests\DBMoneyTest\DataObject:
test3:
MyMoneyCurrency: NZD
MyMoneyAmount: 7.66
SilverStripe\ORM\Tests\DBMoneyTest\SubClass:
SilverStripe\ORM\Tests\DBMoneyTest\TestObjectSubclass:
test2:
MyOtherMoneyCurrency: GBP
MyOtherMoneyAmount: 2.46

View File

@ -23,7 +23,7 @@ class DBStringTest extends SapphireTest {
public function testDefault() {
/** @var DBString $dbField */
$dbField = Object::create_from_string(
"StringFieldTest_MyStringField(['default' => 'Here is my default text'])",
DBStringTest\MyStringField::class."(['default' => 'Here is my default text'])",
'Myfield'
);
$this->assertEquals(

View File

@ -2,15 +2,13 @@
namespace SilverStripe\ORM\Tests;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\ORM\Versioning\DataDifferencer;
use SilverStripe\ORM\DataObject;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
class DataDifferencerTest extends SapphireTest {
@ -33,7 +31,7 @@ class DataDifferencerTest extends SapphireTest {
// Create a test files for each of the fixture references
$files = File::get()->exclude('ClassName', Folder::class);
foreach($files as $file) {
$fromPath = FRAMEWORK_PATH . '/tests/model/testimages/' . $file->Name;
$fromPath = __DIR__ . '/ImageTest/' . $file->Name;
$destPath = TestAssetStore::getLocalPath($file); // Only correct for test asset store
Filesystem::makeFolder(dirname($destPath));
copy($fromPath, $destPath);
@ -62,7 +60,7 @@ class DataDifferencerTest extends SapphireTest {
}
public function testHasOnes() {
/** @var \SilverStripe\ORM\Tests\DataDifferencerTest\DataDifferencerTest_Object $obj1 */
/** @var DataDifferencerTest\TestObject $obj1 */
$obj1 = $this->objFromFixture(DataDifferencerTest\TestObject::class, 'obj1');
$image1 = $this->objFromFixture(Image::class, 'image1');
$image2 = $this->objFromFixture(Image::class, 'image2');
@ -75,9 +73,9 @@ class DataDifferencerTest extends SapphireTest {
$obj1->write();
$afterVersion = $obj1->Version;
$this->assertNotEquals($beforeVersion, $afterVersion);
/** @var \SilverStripe\ORM\Tests\DataDifferencerTest\DataDifferencerTest_Object $obj1v1 */
/** @var DataDifferencerTest\TestObject $obj1v1 */
$obj1v1 = Versioned::get_version(DataDifferencerTest\TestObject::class, $obj1->ID, $beforeVersion);
/** @var \SilverStripe\ORM\Tests\DataDifferencerTest\DataDifferencerTest_Object $obj1v2 */
/** @var DataDifferencerTest\TestObject $obj1v2 */
$obj1v2 = Versioned::get_version(DataDifferencerTest\TestObject::class, $obj1->ID, $afterVersion);
$differ = new DataDifferencer($obj1v1, $obj1v2);
$obj1Diff = $differ->diffedData();

View File

@ -12,7 +12,7 @@ SilverStripe\ORM\Tests\DataDifferencerTest\HasOneRelationObject:
Title: obj1
relobj2:
Title: obj2
SilverStripe\ORM\Tests\DataDifferencerTest\Object:
SilverStripe\ORM\Tests\DataDifferencerTest\TestObject:
obj1:
Choices: a,b
Image: =>SilverStripe\Assets\Image.image1

View File

@ -15,7 +15,6 @@ use SilverStripe\ORM\Versioning\Versioned;
*/
class TestObject extends DataObject implements TestOnly
{
private static $table_name = 'DataDifferencerTest_Object';
private static $extensions = array(

View File

@ -92,7 +92,9 @@ class DataExtensionTest extends SapphireTest {
*/
public function testAddExtensionLoadsStatics() {
// Object::add_extension() will load DOD statics directly, so let's try adding a extension on the fly
DataExtensionTest\Player::add_extension('DataExtensionTest_PlayerExtension');
DataExtensionTest\Player::add_extension(
DataExtensionTest\PlayerExtension::class
);
// Now that we've just added the extension, we need to rebuild the database
$this->resetDBSchema(true);
@ -177,10 +179,10 @@ class DataExtensionTest extends SapphireTest {
}
public function testExtensionAllMethodNamesHasOwner() {
/** @var \SilverStripe\ORM\Tests\DataExtensionTest\DataExtensionTest_MyObject $do */
/** @var DataExtensionTest\MyObject $do */
$do = DataExtensionTest\MyObject::create();
$this->assertTrue($do->hasMethod('getTestValueWithDataExtensionTest_MyObject'));
$this->assertTrue($do->hasMethod('getTestValueWith_MyObject'));
}
public function testPageFieldGeneration() {

View File

@ -2,6 +2,7 @@
namespace SilverStripe\ORM\Tests\DataExtensionTest;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataExtension;
@ -10,7 +11,7 @@ class AllMethodNames extends DataExtension implements TestOnly
public function allMethodNames()
{
return array(
strtolower('getTestValueWith' . $this->owner->ClassName)
strtolower('getTestValueWith_' . ClassInfo::shortName($this->owner))
);
}
}

View File

@ -21,9 +21,12 @@ class DataListTest extends SapphireTest {
// Borrow the model from DataObjectTest
protected static $fixture_file = 'DataObjectTest.yml';
public function setUpOnce() {
$this->extraDataObjects = DataObjectTest::$extra_data_objects;
parent::setUpOnce();
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects
);
}
public function testFilterDataObjectByCreatedDate() {

View File

@ -81,18 +81,18 @@ class DataObjectDuplicationTest extends SapphireTest {
$one->twos()->add($two);
$one->threes()->add($three);
$one = DataObject::get_by_id("DataObjectDuplicateTestClass1", $one->ID);
$two = DataObject::get_by_id("DataObjectDuplicateTestClass2", $two->ID);
$three = DataObject::get_by_id("DataObjectDuplicateTestClass3", $three->ID);
$one = DataObject::get_by_id(DataObjectDuplicationTest\Class1::class, $one->ID);
$two = DataObject::get_by_id(DataObjectDuplicationTest\Class2::class, $two->ID);
$three = DataObject::get_by_id(DataObjectDuplicationTest\Class3::class, $three->ID);
//test duplication
$oneCopy = $one->duplicate();
$twoCopy = $two->duplicate();
$threeCopy = $three->duplicate();
$oneCopy = DataObject::get_by_id("DataObjectDuplicateTestClass1", $oneCopy->ID);
$twoCopy = DataObject::get_by_id("DataObjectDuplicateTestClass2", $twoCopy->ID);
$threeCopy = DataObject::get_by_id("DataObjectDuplicateTestClass3", $threeCopy->ID);
$oneCopy = DataObject::get_by_id(DataObjectDuplicationTest\Class1::class, $oneCopy->ID);
$twoCopy = DataObject::get_by_id(DataObjectDuplicationTest\Class2::class, $twoCopy->ID);
$threeCopy = DataObject::get_by_id(DataObjectDuplicationTest\Class3::class, $threeCopy->ID);
$this->assertNotNull($oneCopy, "Copy of 1 exists");
$this->assertNotNull($twoCopy, "Copy of 2 exists");

View File

@ -20,9 +20,9 @@ class DataObjectLazyLoadingTest extends SapphireTest {
'VersionedTest.yml'
);
public function setUpOnce()
protected function getExtraDataObjects()
{
$this->extraDataObjects = array_merge(
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects,
VersionedTest::$extra_data_objects,
@ -31,7 +31,6 @@ class DataObjectLazyLoadingTest extends SapphireTest {
VersionedSubObject::class,
]
);
parent::setUpOnce();
}
public function testQueriedColumnsID() {

View File

@ -160,29 +160,29 @@ class DataObjectSchemaTest extends SapphireTest
);
$this->assertEquals(
[
'ID' => 'DataObjectSchemaTest_HasFields.PrimaryKey',
'ClassName' => 'DataObjectSchemaTest_BaseDataClass.DBClassName',
'LastEdited' => 'DataObjectSchemaTest_BaseDataClass.DBDatetime',
'Created' => 'DataObjectSchemaTest_BaseDataClass.DBDatetime',
'Title' => 'DataObjectSchemaTest_BaseDataClass.Varchar',
'Description' => 'DataObjectSchemaTest_HasFields.Varchar',
'MoneyFieldCurrency' => 'DataObjectSchemaTest_HasFields.Varchar(3)',
'MoneyFieldAmount' => 'DataObjectSchemaTest_HasFields.Decimal(19,4)',
'MoneyField' => 'DataObjectSchemaTest_HasFields.Money',
'ID' => DataObjectSchemaTest\HasFields::class.'.PrimaryKey',
'ClassName' => DataObjectSchemaTest\BaseDataClass::class.'.DBClassName',
'LastEdited' => DataObjectSchemaTest\BaseDataClass::class.'.DBDatetime',
'Created' => DataObjectSchemaTest\BaseDataClass::class.'.DBDatetime',
'Title' => DataObjectSchemaTest\BaseDataClass::class.'.Varchar',
'Description' => DataObjectSchemaTest\HasFields::class.'.Varchar',
'MoneyFieldCurrency' => DataObjectSchemaTest\HasFields::class.'.Varchar(3)',
'MoneyFieldAmount' => DataObjectSchemaTest\HasFields::class.'.Decimal(19,4)',
'MoneyField' => DataObjectSchemaTest\HasFields::class.'.Money',
],
$schema->fieldSpecs(HasFields::class, DataObjectSchema::INCLUDE_CLASS)
);
// DB_ONLY excludes composite field MoneyField
$this->assertEquals(
[
'ID' => 'DataObjectSchemaTest_HasFields.PrimaryKey',
'ClassName' => 'DataObjectSchemaTest_BaseDataClass.DBClassName',
'LastEdited' => 'DataObjectSchemaTest_BaseDataClass.DBDatetime',
'Created' => 'DataObjectSchemaTest_BaseDataClass.DBDatetime',
'Title' => 'DataObjectSchemaTest_BaseDataClass.Varchar',
'Description' => 'DataObjectSchemaTest_HasFields.Varchar',
'MoneyFieldCurrency' => 'DataObjectSchemaTest_HasFields.Varchar(3)',
'MoneyFieldAmount' => 'DataObjectSchemaTest_HasFields.Decimal(19,4)'
'ID' => DataObjectSchemaTest\HasFields::class.'.PrimaryKey',
'ClassName' => DataObjectSchemaTest\BaseDataClass::class.'.DBClassName',
'LastEdited' => DataObjectSchemaTest\BaseDataClass::class.'.DBDatetime',
'Created' => DataObjectSchemaTest\BaseDataClass::class.'.DBDatetime',
'Title' => DataObjectSchemaTest\BaseDataClass::class.'.Varchar',
'Description' => DataObjectSchemaTest\HasFields::class.'.Varchar',
'MoneyFieldCurrency' => DataObjectSchemaTest\HasFields::class.'.Varchar(3)',
'MoneyFieldAmount' => DataObjectSchemaTest\HasFields::class.'.Decimal(19,4)'
],
$schema->fieldSpecs(
HasFields::class,
@ -193,10 +193,10 @@ class DataObjectSchemaTest extends SapphireTest
// Use all options at once
$this->assertEquals(
[
'ID' => 'DataObjectSchemaTest_HasFields.PrimaryKey',
'Description' => 'DataObjectSchemaTest_HasFields.Varchar',
'MoneyFieldCurrency' => 'DataObjectSchemaTest_HasFields.Varchar(3)',
'MoneyFieldAmount' => 'DataObjectSchemaTest_HasFields.Decimal(19,4)',
'ID' => DataObjectSchemaTest\HasFields::class.'.PrimaryKey',
'Description' => DataObjectSchemaTest\HasFields::class.'.Varchar',
'MoneyFieldCurrency' => DataObjectSchemaTest\HasFields::class.'.Varchar(3)',
'MoneyFieldAmount' => DataObjectSchemaTest\HasFields::class.'.Decimal(19,4)',
],
$schema->fieldSpecs(
HasFields::class,

View File

@ -53,15 +53,14 @@ class DataObjectTest extends SapphireTest {
DataObjectTest\Ploy::class,
DataObjectTest\Bogey::class,
DataObjectTest\Sortable::class,
// From ManyManyListTest
ExtraFieldsObject::class,
Product::class,
Category::class,
);
public function setUpOnce() {
$this->extraDataObjects = static::$extra_data_objects;
parent::setUpOnce();
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects
);
}
public function testDb() {

View File

@ -8,6 +8,9 @@ use SilverStripe\ORM\DB;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
/**
* @skipUpgrade
*/
class DataQueryTest extends SapphireTest {
protected static $fixture_file = 'DataQueryTest.yml';
@ -20,6 +23,9 @@ class DataQueryTest extends SapphireTest {
DataQueryTest\ObjectE::class,
DataQueryTest\ObjectF::class,
DataQueryTest\ObjectG::class,
SQLSelectTest\TestObject::class,
SQLSelectTest\TestBase::class,
SQLSelectTest\TestChild::class,
);
public function testSortByJoinedFieldRetainsSourceInformation() {
@ -34,7 +40,7 @@ class DataQueryTest extends SapphireTest {
$query = new DataQuery(DataQueryTest\ObjectB::class);
$result = $query->leftJoin(
DataQueryTest\ObjectC::class,
'DataQueryTest_C',
"\"DataQueryTest_B\".\"TestCID\" = \"DataQueryTest_B\".\"ID\""
)->sort('"DataQueryTest_B"."Title"', 'ASC');
@ -61,12 +67,12 @@ class DataQueryTest extends SapphireTest {
// Test applyRelation with two has_ones pointing to the same class
$dq = new DataQuery(DataQueryTest\ObjectB::class);
$dq->applyRelation('TestC');
$this->assertTrue($dq->query()->isJoinedTo(DataQueryTest\ObjectC::class));
$this->assertTrue($dq->query()->isJoinedTo('DataQueryTest_C'));
$this->assertContains('"DataQueryTest_C"."ID" = "DataQueryTest_B"."TestCID"', $dq->sql());
$dq = new DataQuery(DataQueryTest\ObjectB::class);
$dq->applyRelation('TestCTwo');
$this->assertTrue($dq->query()->isJoinedTo(DataQueryTest\ObjectC::class));
$this->assertTrue($dq->query()->isJoinedTo('DataQueryTest_C'));
$this->assertContains('"DataQueryTest_C"."ID" = "DataQueryTest_B"."TestCTwoID"', $dq->sql());
}
@ -75,7 +81,7 @@ class DataQueryTest extends SapphireTest {
$newDQ = new DataQuery(DataQueryTest\ObjectE::class);
//apply a relation to a relation from an ancestor class
$newDQ->applyRelation('TestA');
$this->assertTrue($newDQ->query()->isJoinedTo(DataQueryTest\ObjectC::class));
$this->assertTrue($newDQ->query()->isJoinedTo('DataQueryTest_C'));
$this->assertContains('"DataQueryTest_A"."ID" = "DataQueryTest_C"."TestAID"', $newDQ->sql($params));
//test many_many relation
@ -128,7 +134,7 @@ class DataQueryTest extends SapphireTest {
public function testRelationOrderWithCustomJoin() {
$dataQuery = new DataQuery(DataQueryTest\ObjectB::class);
$dataQuery->innerJoin(DataQueryTest\ObjectD::class, '"DataQueryTest_D"."RelationID" = "DataQueryTest_B"."ID"');
$dataQuery->innerJoin('DataQueryTest_D', '"DataQueryTest_D"."RelationID" = "DataQueryTest_B"."ID"');
$dataQuery->execute();
}
@ -207,7 +213,7 @@ class DataQueryTest extends SapphireTest {
}
public function testOrderByMultiple() {
$dq = new DataQuery('SQLSelectTest_DO');
$dq = new DataQuery(SQLSelectTest\TestObject::class);
$dq = $dq->sort('"Name" ASC, MID("Name", 8, 1) DESC');
$this->assertContains(
'ORDER BY "SQLSelectTest_DO"."Name" ASC, "_SortColumn0" DESC',
@ -296,8 +302,8 @@ class DataQueryTest extends SapphireTest {
));
$result = $query->getFinalisedQuery(array('Title'));
$from = $result->getFrom();
$this->assertContains(DataQueryTest\ObjectC::class, array_keys($from));
$this->assertNotContains(DataQueryTest\ObjectE::class, array_keys($from));
$this->assertContains('DataQueryTest_C', array_keys($from));
$this->assertNotContains('DataQueryTest_E', array_keys($from));
// Including filter on sub-table requires it
$query = new DataQuery(DataQueryTest\ObjectC::class);
@ -311,8 +317,8 @@ class DataQueryTest extends SapphireTest {
$from = $result->getFrom();
// Check that including "SortOrder" prompted inclusion of DataQueryTest_E table
$this->assertContains(DataQueryTest\ObjectC::class, array_keys($from));
$this->assertContains(DataQueryTest\ObjectE::class, array_keys($from));
$this->assertContains('DataQueryTest_C', array_keys($from));
$this->assertContains('DataQueryTest_E', array_keys($from));
$arrayResult = iterator_to_array($result->execute());
$first = array_shift($arrayResult);
$this->assertNotNull($first);

View File

@ -4,7 +4,6 @@ namespace SilverStripe\ORM\Tests\DataQueryTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Tests\DataQueryTest;
class ObjectC extends DataObject implements TestOnly
{
@ -15,18 +14,18 @@ class ObjectC extends DataObject implements TestOnly
);
private static $has_one = array(
'TestA' => DataQueryTest\ObjectA::class,
'TestB' => DataQueryTest\ObjectB::class,
'TestA' => ObjectA::class,
'TestB' => ObjectB::class,
);
private static $has_many = array(
'TestAs' => DataQueryTest\ObjectA::class,
'TestAs' => ObjectA::class,
'TestBs' => 'SilverStripe\\ORM\\Tests\\DataQueryTest\\ObjectB.TestC',
'TestBsTwo' => 'SilverStripe\\ORM\\Tests\\DataQueryTest\\ObjectB.TestCTwo',
);
private static $many_many = array(
'ManyTestAs' => DataQueryTest\ObjectA::class,
'ManyTestBs' => DataQueryTest\ObjectB::class,
'ManyTestAs' => ObjectA::class,
'ManyTestBs' => ObjectB::class,
);
}

View File

@ -4,13 +4,12 @@ namespace SilverStripe\ORM\Tests\DataQueryTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Tests\DataQueryTest;
class ObjectD extends DataObject implements TestOnly
{
private static $table_name = 'DataQueryTest_D';
private static $has_one = array(
'Relation' => DataQueryTest\ObjectB::class,
'Relation' => ObjectB::class,
);
}

View File

@ -3,9 +3,8 @@
namespace SilverStripe\ORM\Tests\DataQueryTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\Tests\DataQueryTest;
class ObjectE extends DataQueryTest\ObjectC implements TestOnly
class ObjectE extends ObjectC implements TestOnly
{
private static $table_name = 'DataQueryTest_E';

View File

@ -3,14 +3,13 @@
namespace SilverStripe\ORM\Tests\DataQueryTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\Tests\DataQueryTest;
class ObjectG extends DataQueryTest\ObjectC implements TestOnly
class ObjectG extends ObjectC implements TestOnly
{
private static $table_name = 'DataQueryTest_G';
private static $belongs_many_many = array(
'ManyTestEs' => DataQueryTest\ObjectE::class,
'ManyTestEs' => ObjectE::class,
);
}

View File

@ -34,7 +34,7 @@ class SearchFilterApplyRelationTest extends SapphireTest {
$all = SearchFilterApplyRelationTest\TestObject::singleton();
$context = $all->getDefaultSearchContext();
$filter = new ExactMatchFilter("SearchFilterApplyRelationTest_HasOneGrantChild.Title");
$filter = new ExactMatchFilter("SearchFilterApplyRelationTest_HasOneGrandChild.Title");
$context->setFilters(null);
$context->addFilter($filter);
$params = array(
@ -51,31 +51,31 @@ class SearchFilterApplyRelationTest extends SapphireTest {
$all = SearchFilterApplyRelationTest\TestObject::singleton();
$context = $all->getDefaultSearchContext();
$filter = new PartialMatchFilter("SearchFilterApplyRelationTest_HasManyGrantChildren.Title");
$filter = new PartialMatchFilter("SearchFilterApplyRelationTest_HasManyGrandChildren.Title");
$context->setFilters(null);
$context->addFilter($filter);
$params = array(
"SearchFilterApplyRelationTest_HasManyGrantChildren__Title" => "I am has_many object1",
"SearchFilterApplyRelationTest_HasManyGrandChildren__Title" => "I am has_many object1",
);
$results = $context->getResults($params);
$this->assertEquals(1, $results->count());
$this->assertEquals(array($do1->ID), $results->column('ID'));
$params = array(
"SearchFilterApplyRelationTest_HasManyGrantChildren__Title" => "I am has_many object3",
"SearchFilterApplyRelationTest_HasManyGrandChildren__Title" => "I am has_many object3",
);
$results = $context->getResults($params);
$this->assertEquals(1, $results->count());
$this->assertEquals(array($do2->ID), $results->column('ID'));
$params = array(
"SearchFilterApplyRelationTest_HasManyGrantChildren__Title" => "I am has_many object",
"SearchFilterApplyRelationTest_HasManyGrandChildren__Title" => "I am has_many object",
);
$results = $context->getResults($params);
$this->assertEquals(2, $results->count());
$params = array(
"SearchFilterApplyRelationTest_HasManyGrantChildren__Title" => "not exist",
"SearchFilterApplyRelationTest_HasManyGrandChildren__Title" => "not exist",
);
$results = $context->getResults($params);
$this->assertEquals(0, $results->count());
@ -85,29 +85,29 @@ class SearchFilterApplyRelationTest extends SapphireTest {
$all = SearchFilterApplyRelationTest\TestObject::singleton();
$context = $all->getDefaultSearchContext();
$filter = new PartialMatchFilter("ManyManyGrantChildren.Title");
$filter = new PartialMatchFilter("ManyManyGrandChildren.Title");
$context->setFilters(null);
$context->addFilter($filter);
$params = array(
"ManyManyGrantChildren__Title" => "I am many_many object1",
"ManyManyGrandChildren__Title" => "I am many_many object1",
);
$results = $context->getResults($params);
$this->assertEquals(2, $results->count());
$params = array(
"ManyManyGrantChildren__Title" => "I am many_many object2",
"ManyManyGrandChildren__Title" => "I am many_many object2",
);
$results = $context->getResults($params);
$this->assertEquals(2, $results->count());
$params = array(
"ManyManyGrantChildren__Title" => "I am many_many object",
"ManyManyGrandChildren__Title" => "I am many_many object",
);
$results = $context->getResults($params);
$this->assertEquals(2, $results->count());
$params = array(
"ManyManyGrantChildren__Title" => "not exist",
"ManyManyGrandChildren__Title" => "not exist",
);
$results = $context->getResults($params);
$this->assertEquals(0, $results->count());

View File

@ -10,14 +10,14 @@ class TestObject extends DataObject implements TestOnly
private static $table_name = 'SearchFilterApplyRelationTest_DO';
private static $has_one = array(
'SearchFilterApplyRelationTest_HasOneGrantChild' => HasOneGrandChild::class
'SearchFilterApplyRelationTest_HasOneGrandChild' => HasOneGrandChild::class
);
private static $has_many = array(
'SearchFilterApplyRelationTest_HasManyGrantChildren' => HasManyGrandChild::class
'SearchFilterApplyRelationTest_HasManyGrandChildren' => HasManyGrandChild::class
);
private static $many_many = array(
'ManyManyGrantChildren' => ManyManyGrandChild::class
'ManyManyGrandChildren' => ManyManyGrandChild::class
);
}

View File

@ -2,20 +2,13 @@
namespace SilverStripe\ORM\Tests;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\GroupedList;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\ArrayData;
/**
* Tests for the {@link GroupedList} list decorator.
*
* @package framework
* @subpackage tests
*/
class GroupedListTest extends SapphireTest {

View File

@ -12,9 +12,12 @@ class HasManyListTest extends SapphireTest {
// Borrow the model from DataObjectTest
protected static $fixture_file = 'DataObjectTest.yml';
public function setUpOnce() {
$this->extraDataObjects = DataObjectTest::$extra_data_objects;
parent::setUpOnce();
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects
);
}
public function testRelationshipEmptyOnNewRecords() {
@ -36,14 +39,14 @@ class HasManyListTest extends SapphireTest {
);
// Test that each team has the correct fans
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
$team2 = $this->objFromFixture('DataObjectTest_Team', 'team2');
$team1 = $this->objFromFixture(DataObjectTest\Team::class, 'team1');
$team2 = $this->objFromFixture(DataObjectTest\Team::class, 'team2');
$this->assertEquals(array('Bob', 'Joe'), $team1->Comments()->sort('Name')->column('Name'));
$this->assertEquals(array('Phil'), $team2->Comments()->sort('Name')->column('Name'));
// Test that removing comments from unrelated team has no effect
$team1comment = $this->objFromFixture('DataObjectTest_TeamComment', 'comment1');
$team2comment = $this->objFromFixture('DataObjectTest_TeamComment', 'comment3');
$team1comment = $this->objFromFixture(DataObjectTest\TeamComment::class, 'comment1');
$team2comment = $this->objFromFixture(DataObjectTest\TeamComment::class, 'comment3');
$team1->Comments()->remove($team2comment);
$team2->Comments()->remove($team1comment);
$this->assertEquals(array('Bob', 'Joe'), $team1->Comments()->sort('Name')->column('Name'));
@ -52,8 +55,8 @@ class HasManyListTest extends SapphireTest {
$this->assertEquals($team2->ID, $team2comment->TeamID);
// Test that removing items from the related team resets the has_one relations on the fan
$team1comment = $this->objFromFixture('DataObjectTest_TeamComment', 'comment1');
$team2comment = $this->objFromFixture('DataObjectTest_TeamComment', 'comment3');
$team1comment = $this->objFromFixture(DataObjectTest\TeamComment::class, 'comment1');
$team2comment = $this->objFromFixture(DataObjectTest\TeamComment::class, 'comment3');
$team1->Comments()->remove($team1comment);
$team2->Comments()->remove($team2comment);
$this->assertEquals(array('Bob'), $team1->Comments()->sort('Name')->column('Name'));

View File

@ -22,19 +22,16 @@ class HierarchyTest extends SapphireTest {
* Test the Hierarchy prevents infinite loops.
*/
public function testPreventLoop() {
$this->setExpectedException(
ValidationException::class,
sprintf('Infinite loop found within the "%s" hierarchy', HierarchyTest\TestObject::class)
);
$obj2 = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj2');
$obj2aa = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj2aa');
$obj2->ParentID = $obj2aa->ID;
try {
$obj2->write();
}
catch (ValidationException $e) {
$this->assertContains('Infinite loop found within the "HierarchyTest_Object" hierarchy', $e->getMessage());
return;
}
$this->fail('Failed to prevent infinite loop in hierarchy.');
$obj2->write();
}
/**
@ -63,7 +60,7 @@ class HierarchyTest extends SapphireTest {
// Obj 3 has been deleted; let's bring it back from the grave
$obj3 = Versioned::get_including_deleted("HierarchyTest_Object", "\"Title\" = 'Obj 3'")->First();
$obj3 = Versioned::get_including_deleted(HierarchyTest\TestObject::class, "\"Title\" = 'Obj 3'")->First();
// Check that all obj 3 children are returned
$this->assertEquals(array("Obj 3a", "Obj 3b", "Obj 3c", "Obj 3d"),
@ -86,7 +83,7 @@ class HierarchyTest extends SapphireTest {
$this->objFromFixture(HierarchyTest\TestObject::class, 'obj3')->markUnexpanded();
// Query some objs in a different context and check their m
$objs = DataObject::get("HierarchyTest_Object", '', '"ID" ASC');
$objs = DataObject::get(HierarchyTest\TestObject::class, '', '"ID" ASC');
$marked = $expanded = array();
foreach($objs as $obj) {
if($obj->isMarked()) $marked[] = $obj->Title;
@ -547,7 +544,9 @@ EOT;
}
public function testHideFromHeirarchy() {
HierarchyTest\HideTestObject::config()->hide_from_hierarchy = array('HierarchyHideTest_SubObject');
HierarchyTest\HideTestObject::config()->update('hide_from_hierarchy', [
HierarchyTest\HideTestSubObject::class,
]);
$obj4 = $this->objFromFixture(HierarchyTest\HideTestObject::class, 'obj4');
$obj4->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Tests;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Filesystem as SSFilesystem;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Storage\DBFile;
use SilverStripe\Core\Config\Config;
@ -32,7 +33,7 @@ class ImageTest extends SapphireTest {
$files = File::get()->exclude('ClassName', Folder::class);
foreach($files as $image) {
$filePath = TestAssetStore::getLocalPath($image); // Only correct for test asset store
$sourcePath = FRAMEWORK_PATH . '/tests/model/testimages/' . $image->Name;
$sourcePath = __DIR__ . '/ImageTest/' . $image->Name;
if(!file_exists($filePath)) {
SSFilesystem::makeFolder(dirname($filePath));
if (!copy($sourcePath, $filePath)) {

View File

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -19,12 +19,12 @@ class ManyManyListTest extends SapphireTest {
ManyManyListTest\Product::class,
];
public function setUpOnce() {
$this->extraDataObjects = array_merge(
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
static::$extra_data_objects
ManyManyListTest::$extra_data_objects
);
parent::setUpOnce();
}
public function testAddCompositedExtraFields() {

View File

@ -13,9 +13,12 @@ class MapTest extends SapphireTest {
// Borrow the model from DataObjectTest
protected static $fixture_file = 'DataObjectTest.yml';
public function setUpOnce() {
$this->extraDataObjects = DataObjectTest::$extra_data_objects;
parent::setUpOnce();
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects
);
}
public function testValues() {
@ -76,7 +79,7 @@ class MapTest extends SapphireTest {
public function testDefaultConfigIsIDAndTitle() {
$list = Team::get();
$map = new Map($list);
$this->assertEquals('Team 1', $map[$this->idFromFixture('DataObjectTest_Team', 'team1')]);
$this->assertEquals('Team 1', $map[$this->idFromFixture(DataObjectTest\Team::class, 'team1')]);
}
public function testSetKeyFieldAndValueField() {

View File

@ -2,25 +2,18 @@
namespace SilverStripe\ORM\Tests;
use SilverStripe\ORM\Connect\PDOQuery;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Connect\PDOConnector;
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\Dev\SapphireTest;
/**
* @package framework
* @subpackage testing
*/
class PDODatabaseTest extends SapphireTest {
protected static $fixture_file = 'MySQLDatabaseTest.yml';
protected $extraDataObjects = array(
'MySQLDatabaseTest_Data'
MySQLDatabaseTest\Data::class
);
public function testPreparedStatements() {
@ -38,12 +31,12 @@ class PDODatabaseTest extends SapphireTest {
'SELECT "Sort", "Title" FROM "MySQLDatabaseTest_Data" WHERE "Sort" > ? ORDER BY "Sort"',
array(2)
);
$this->assertInstanceOf('SilverStripe\\ORM\\Connect\\PDOQuery', $result1);
$this->assertInstanceOf('SilverStripe\\ORM\\Connect\\PDOQuery', $result2);
$this->assertInstanceOf(PDOQuery::class, $result1);
$this->assertInstanceOf(PDOQuery::class, $result2);
// Also select non-prepared statement
$result3 = DB::get_connector()->query('SELECT "Sort", "Title" FROM "MySQLDatabaseTest_Data" ORDER BY "Sort"');
$this->assertInstanceOf('SilverStripe\\ORM\\Connect\\PDOQuery', $result3);
$this->assertInstanceOf(PDOQuery::class, $result3);
// Iterating one level should not buffer, but return the right result
$this->assertEquals(
@ -112,13 +105,13 @@ class PDODatabaseTest extends SapphireTest {
// Test update which affects no rows
$query->setWhere(array('Title' => 'Bob'));
$result = $query->execute();
$this->assertInstanceOf('SilverStripe\\ORM\\Connect\\PDOQuery', $result);
$this->assertInstanceOf(PDOQuery::class, $result);
$this->assertEquals(0, DB::affected_rows());
// Test update which affects some rows
$query->setWhere(array('Title' => 'First Item'));
$result = $query->execute();
$this->assertInstanceOf('SilverStripe\\ORM\\Connect\\PDOQuery', $result);
$this->assertInstanceOf(PDOQuery::class, $result);
$this->assertEquals(1, DB::affected_rows());
}
}

View File

@ -16,12 +16,12 @@ class PaginatedListTest extends SapphireTest {
protected static $fixture_file = 'DataObjectTest.yml';
public function setUpOnce() {
$this->extraDataObjects = array_merge(
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects
);
parent::setUpOnce();
}
public function testPageStart() {

View File

@ -2,30 +2,28 @@
namespace SilverStripe\ORM\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Tests\DataObjectTest\Fan;
use SilverStripe\ORM\Tests\DataObjectTest\Team;
/**
* Tests the PolymorphicHasManyList class
*
* @see PolymorphicHasManyList
*
* @todo Complete
*
* @package framework
* @subpackage tests
*/
class PolymorphicHasManyListTest extends SapphireTest {
// Borrow the model from DataObjectTest
protected static $fixture_file = 'DataObjectTest.yml';
public function setUpOnce() {
$this->extraDataObjects = DataObjectTest::$extra_data_objects;
parent::setUpOnce();
protected function getExtraDataObjects()
{
return array_merge(
DataObjectTest::$extra_data_objects,
ManyManyListTest::$extra_data_objects
);
}
public function testRelationshipEmptyOnNewRecords() {
@ -38,7 +36,6 @@ class PolymorphicHasManyListTest extends SapphireTest {
* Test that DataList::relation works with PolymorphicHasManyList
*/
public function testFilterRelation() {
// Check that expected teams exist
$list = Team::get();
$this->assertEquals(
@ -51,8 +48,8 @@ class PolymorphicHasManyListTest extends SapphireTest {
$this->assertEquals(array('Damian', 'Mitch', 'Richard'), $fans->sort('Name')->column('Name'));
// Modify list of fans and retest
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
$subteam1 = $this->objFromFixture('DataObjectTest_SubTeam', 'subteam1');
$team1 = $this->objFromFixture(DataObjectTest\Team::class, 'team1');
$subteam1 = $this->objFromFixture(DataObjectTest\SubTeam::class, 'subteam1');
$newFan1 = Fan::create();
$newFan1->Name = 'Bobby';
$newFan1->write();
@ -80,26 +77,26 @@ class PolymorphicHasManyListTest extends SapphireTest {
);
// Test that each team has the correct fans
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
$subteam1 = $this->objFromFixture('DataObjectTest_SubTeam', 'subteam1');
$team1 = $this->objFromFixture(DataObjectTest\Team::class, 'team1');
$subteam1 = $this->objFromFixture(DataObjectTest\SubTeam::class, 'subteam1');
$this->assertEquals(array('Damian', 'Richard'), $team1->Fans()->sort('Name')->column('Name'));
$this->assertEquals(array('Mitch'), $subteam1->Fans()->sort('Name')->column('Name'));
// Test that removing items from unrelated team has no effect
$team1fan = $this->objFromFixture('DataObjectTest_Fan', 'fan1');
$subteam1fan = $this->objFromFixture('DataObjectTest_Fan', 'fan4');
$team1fan = $this->objFromFixture(DataObjectTest\Fan::class, 'fan1');
$subteam1fan = $this->objFromFixture(DataObjectTest\Fan::class, 'fan4');
$team1->Fans()->remove($subteam1fan);
$subteam1->Fans()->remove($team1fan);
$this->assertEquals(array('Damian', 'Richard'), $team1->Fans()->sort('Name')->column('Name'));
$this->assertEquals(array('Mitch'), $subteam1->Fans()->sort('Name')->column('Name'));
$this->assertEquals($team1->ID, $team1fan->FavouriteID);
$this->assertEquals('DataObjectTest_Team', $team1fan->FavouriteClass);
$this->assertEquals(DataObjectTest\Team::class, $team1fan->FavouriteClass);
$this->assertEquals($subteam1->ID, $subteam1fan->FavouriteID);
$this->assertEquals('DataObjectTest_SubTeam', $subteam1fan->FavouriteClass);
$this->assertEquals(DataObjectTest\SubTeam::class, $subteam1fan->FavouriteClass);
// Test that removing items from the related team resets the has_one relations on the fan
$team1fan = $this->objFromFixture('DataObjectTest_Fan', 'fan1');
$subteam1fan = $this->objFromFixture('DataObjectTest_Fan', 'fan4');
$team1fan = $this->objFromFixture(DataObjectTest\Fan::class, 'fan1');
$subteam1fan = $this->objFromFixture(DataObjectTest\Fan::class, 'fan4');
$team1->Fans()->remove($team1fan);
$subteam1->Fans()->remove($subteam1fan);
$this->assertEquals(array('Richard'), $team1->Fans()->sort('Name')->column('Name'));

View File

@ -14,6 +14,8 @@ use SilverStripe\ORM\ManyManyList;
*/
class TestObject extends DataObject implements TestOnly
{
private static $table_name = 'UnsavedRelationListTest_DataObject';
private static $db = array(
'Name' => 'Varchar',
);

View File

@ -32,10 +32,9 @@ class VersionedTest extends SapphireTest {
VersionedTest\CustomTable::class,
];
public function setUpOnce()
protected function getExtraDataObjects()
{
$this->extraDataObjects = static::$extra_data_objects;
parent::setUpOnce();
return static::$extra_data_objects;
}
public function testUniqueIndexes() {
@ -139,9 +138,10 @@ class VersionedTest extends SapphireTest {
$obj = new VersionedTest\Subclass();
$obj->ExtraField = 'Foo'; // ensure that child version table gets written
$obj->write();
$class = VersionedTest\TestObject::class;
$this->setExpectedException(
'InvalidArgumentException',
"Can't find VersionedTest_DataObject#{$obj->ID} in stage Live"
"Can't find {$class}#{$obj->ID} in stage Live"
);
// Fail publishing from live to stage
@ -198,14 +198,14 @@ class VersionedTest extends SapphireTest {
$targetPage->delete();
// Get all items, ignoring deleted
$remainingPages = DataObject::get("VersionedTest_DataObject", "\"ParentID\" = 0",
$remainingPages = DataObject::get(VersionedTest\TestObject::class, "\"ParentID\" = 0",
"\"VersionedTest_DataObject\".\"ID\" ASC");
// Check that page 3 has gone
$this->assertNotNull($remainingPages);
$this->assertEquals(array("Page 1", "Page 2", "Subclass Page 1"), $remainingPages->column('Title'));
// Get all including deleted
$allPages = Versioned::get_including_deleted("VersionedTest_DataObject", "\"ParentID\" = 0",
$allPages = Versioned::get_including_deleted(VersionedTest\TestObject::class, "\"ParentID\" = 0",
"\"VersionedTest_DataObject\".\"ID\" ASC");
// Check that page 3 is still there
$this->assertEquals(array("Page 1", "Page 2", "Page 3", "Subclass Page 1"), $allPages->column('Title'));
@ -215,7 +215,7 @@ class VersionedTest extends SapphireTest {
// Check that this still works if we switch to reading the other stage
Versioned::set_stage(Versioned::LIVE);
$allPages = Versioned::get_including_deleted("VersionedTest_DataObject", "\"ParentID\" = 0",
$allPages = Versioned::get_including_deleted(VersionedTest\TestObject::class, "\"ParentID\" = 0",
"\"VersionedTest_DataObject\".\"ID\" ASC");
$this->assertEquals(array("Page 1", "Page 2", "Page 3", "Subclass Page 1"), $allPages->column('Title'));
@ -540,22 +540,22 @@ class VersionedTest extends SapphireTest {
$obj->Name = "test";
$obj->write();
$obj->Name = "test2";
$obj->ClassName = "VersionedTest_Subclass";
$obj->ClassName = VersionedTest\Subclass::class;
$obj->write();
$subclassVersion = $obj->Version;
$obj->Name = "test3";
$obj->ClassName = "VersionedTest_DataObject";
$obj->ClassName = VersionedTest\TestObject::class;
$obj->write();
// We should be able to pass the subclass and still get the correct class back
$obj2 = Versioned::get_version("VersionedTest_Subclass", $obj->ID, $subclassVersion);
$this->assertInstanceOf("VersionedTest_Subclass", $obj2);
$obj2 = Versioned::get_version(VersionedTest\Subclass::class, $obj->ID, $subclassVersion);
$this->assertInstanceOf(VersionedTest\Subclass::class, $obj2);
$this->assertEquals("test2", $obj2->Name);
$obj3 = Versioned::get_latest_version("VersionedTest_Subclass", $obj->ID);
$obj3 = Versioned::get_latest_version(VersionedTest\Subclass::class, $obj->ID);
$this->assertEquals("test3", $obj3->Name);
$this->assertInstanceOf("VersionedTest_DataObject", $obj3);
$this->assertInstanceOf(VersionedTest\TestObject::class, $obj3);
}
@ -588,7 +588,7 @@ class VersionedTest extends SapphireTest {
singleton(VersionedTest\Subclass::class)->flushCache(true);
Versioned::set_reading_mode('Archive.2006-01-01 00:00:00');
$testPage2006 = DataObject::get(VersionedTest\Subclass::class)->filter(array('Title' => 'Archived page'))->first();
$this->assertInstanceOf("VersionedTest_Subclass", $testPage2006);
$this->assertInstanceOf(VersionedTest\Subclass::class, $testPage2006);
$this->assertEquals("2005", $testPage2006->ExtraField);
$this->assertEquals("This is the content from 2005", $testPage2006->Content);
@ -596,7 +596,7 @@ class VersionedTest extends SapphireTest {
singleton(VersionedTest\Subclass::class)->flushCache(true);
Versioned::set_reading_mode('Archive.2008-01-01 00:00:00');
$testPage2008 = DataObject::get(VersionedTest\Subclass::class)->filter(array('Title' => 'Archived page'))->first();
$this->assertInstanceOf("VersionedTest_Subclass", $testPage2008);
$this->assertInstanceOf(VersionedTest\Subclass::class, $testPage2008);
$this->assertEquals("2007", $testPage2008->ExtraField);
$this->assertEquals("It's 2007 already!", $testPage2008->Content);
@ -605,7 +605,7 @@ class VersionedTest extends SapphireTest {
Versioned::set_reading_mode('Stage.Stage');
$testPageCurrent = DataObject::get(VersionedTest\Subclass::class)->filter(array('Title' => 'Archived page'))
->first();
$this->assertInstanceOf("VersionedTest_Subclass", $testPageCurrent);
$this->assertInstanceOf(VersionedTest\Subclass::class, $testPageCurrent);
$this->assertEquals("2009", $testPageCurrent->ExtraField);
$this->assertEquals("I'm enjoying 2009", $testPageCurrent->Content);
}
@ -872,7 +872,9 @@ class VersionedTest extends SapphireTest {
* @param int $version
*/
protected function assertRecordHasLatestVersion($record, $version) {
foreach(ClassInfo::ancestry(get_class($record), true) as $table) {
$schema = DataObject::getSchema();
foreach(ClassInfo::ancestry(get_class($record), true) as $class) {
$table = $schema->tableName($class);
$versionForClass = DB::prepared_query(
$sql = "SELECT MAX(\"Version\") FROM \"{$table}_Versions\" WHERE \"RecordID\" = ?",
array($record->ID)
@ -957,7 +959,7 @@ class VersionedTest extends SapphireTest {
$this->assertRecordHasLatestVersion($record, 2);
}
public function testVersionedHandlesRenamedDataObjectFields(){
public function testVersionedHandlesRenamedDataObjectFields() {
Config::inst()->remove(VersionedTest\RelatedWithoutversion::class,'db','Name','Varchar');
Config::inst()->update(VersionedTest\RelatedWithoutversion::class,'db',array(

View File

@ -2,15 +2,10 @@
namespace SilverStripe\Security\Tests;
use SilverStripe\Security\GroupCsvBulkLoader;
use SilverStripe\Security\Group;
use SilverStripe\Dev\SapphireTest;
/**
* @package framework
* @subpackage tests
*/
class GroupCsvBulkLoaderTest extends SapphireTest {
protected static $fixture_file = 'GroupCsvBulkLoaderTest.yml';

View File

@ -4,10 +4,6 @@ namespace SilverStripe\Security\Tests\MemberTest;
use SilverStripe\Security\PasswordValidator;
/**
* @package framework
* @subpackage tests
*/
class TestPasswordValidator extends PasswordValidator
{
public function __construct()

View File

@ -2,12 +2,6 @@
namespace i18nTest;
/**
* Created by PhpStorm.
* User: dmooyman
* Date: 17/06/16
* Time: 12:49 PM
*/
class i18nTestNamespacedClass
{