mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Use shorthand {class}::get() syntax instead of DataList::create()
in core code.
This commit is contained in:
parent
71256ea7f8
commit
c3eabffcb9
@ -70,7 +70,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
$memberList = GridField::create(
|
$memberList = GridField::create(
|
||||||
'Members',
|
'Members',
|
||||||
false,
|
false,
|
||||||
DataList::create('Member'),
|
Member::get(),
|
||||||
$memberListConfig = GridFieldConfig_RecordEditor::create()
|
$memberListConfig = GridFieldConfig_RecordEditor::create()
|
||||||
->addComponent(new GridFieldExportButton())
|
->addComponent(new GridFieldExportButton())
|
||||||
)->addExtraClass("members_grid");
|
)->addExtraClass("members_grid");
|
||||||
@ -79,7 +79,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
$groupList = GridField::create(
|
$groupList = GridField::create(
|
||||||
'Groups',
|
'Groups',
|
||||||
false,
|
false,
|
||||||
DataList::create('Group'),
|
Group::get(),
|
||||||
GridFieldConfig_RecordEditor::create()
|
GridFieldConfig_RecordEditor::create()
|
||||||
);
|
);
|
||||||
$columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns');
|
$columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||||
@ -131,7 +131,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
if(Permission::check('APPLY_ROLES')) {
|
if(Permission::check('APPLY_ROLES')) {
|
||||||
$rolesField = GridField::create('Roles',
|
$rolesField = GridField::create('Roles',
|
||||||
false,
|
false,
|
||||||
DataList::create('PermissionRole'),
|
PermissionRole::get(),
|
||||||
GridFieldConfig_RecordEditor::create()
|
GridFieldConfig_RecordEditor::create()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -87,23 +87,22 @@ abstract class Object {
|
|||||||
* or calling on Object and passing the class name as the first parameter. The following
|
* or calling on Object and passing the class name as the first parameter. The following
|
||||||
* are equivalent:
|
* are equivalent:
|
||||||
* $list = DataList::create('SiteTree');
|
* $list = DataList::create('SiteTree');
|
||||||
* $list = DataList::create('SiteTree');
|
* $list = SiteTree::get();
|
||||||
*
|
*
|
||||||
* @param string $class the class name
|
* @param string $class the class name
|
||||||
* @param mixed $arguments,... arguments to pass to the constructor
|
* @param mixed $arguments,... arguments to pass to the constructor
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
public static function create() {
|
public static function create() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
// Class to create should be the calling class if not Object,
|
// Class to create should be the calling class if not Object,
|
||||||
// otherwise the first parameter
|
// otherwise the first parameter
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
if($class == 'Object')
|
if($class == 'Object') $class = array_shift($args);
|
||||||
$class = array_shift($args);
|
|
||||||
|
|
||||||
$class = self::getCustomClass($class);
|
$class = self::getCustomClass($class);
|
||||||
|
|
||||||
return Injector::inst()->createWithArgs($class, $args);
|
return Injector::inst()->createWithArgs($class, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* public function getCMSFields() {
|
* public function getCMSFields() {
|
||||||
* $fields = parent::getCMSFields();
|
* $fields = parent::getCMSFields();
|
||||||
* $field = new DropdownField('GalleryID', 'Gallery', DataList::create('Gallery')->map('ID', 'Title'));
|
* $field = new DropdownField('GalleryID', 'Gallery', Gallery::get()->map('ID', 'Title'));
|
||||||
* $field->setEmptyString('(Select one)');
|
* $field->setEmptyString('(Select one)');
|
||||||
* $fields->addFieldToTab('Root.Content', $field, 'Content');
|
* $fields->addFieldToTab('Root.Content', $field, 'Content');
|
||||||
* </code>
|
* </code>
|
||||||
|
@ -498,7 +498,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
} else {
|
} else {
|
||||||
$url = Director::makeRelative($request->getVar('FileURL'));
|
$url = Director::makeRelative($request->getVar('FileURL'));
|
||||||
$url = preg_replace('/_resampled\/[^-]+-/', '', $url);
|
$url = preg_replace('/_resampled\/[^-]+-/', '', $url);
|
||||||
$file = DataList::create('File')->filter('Filename', $url)->first();
|
$file = File::get()->filter('Filename', $url)->first();
|
||||||
if(!$file) $file = new File(array(
|
if(!$file) $file = new File(array(
|
||||||
'Title' => basename($url),
|
'Title' => basename($url),
|
||||||
'Filename' => $url
|
'Filename' => $url
|
||||||
@ -720,7 +720,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
$wheres = array();
|
$wheres = array();
|
||||||
foreach($exts as $ext) $wheres[] = '"Filename" LIKE \'%.' . $ext . '\'';
|
foreach($exts as $ext) $wheres[] = '"Filename" LIKE \'%.' . $ext . '\'';
|
||||||
|
|
||||||
$files = DataList::create('File')->where(implode(' OR ', $wheres));
|
$files = File::get()->where(implode(' OR ', $wheres));
|
||||||
|
|
||||||
// Limit by folder (if required)
|
// Limit by folder (if required)
|
||||||
if($parentID) $files->filter('ParentID', $parentID);
|
if($parentID) $files->filter('ParentID', $parentID);
|
||||||
|
@ -528,7 +528,7 @@ class UploadField extends FileField {
|
|||||||
|
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
$files = DataList::create('File')->byIDs($request->postVar('ids'));
|
$files = File::get()->byIDs($request->postVar('ids'));
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
$this->attachFile($file);
|
$this->attachFile($file);
|
||||||
$file = $this->customiseFile($file);
|
$file = $this->customiseFile($file);
|
||||||
|
@ -60,7 +60,7 @@ class Versioned extends DataExtension {
|
|||||||
"Version" => "Int",
|
"Version" => "Int",
|
||||||
"WasPublished" => "Boolean",
|
"WasPublished" => "Boolean",
|
||||||
"AuthorID" => "Int",
|
"AuthorID" => "Int",
|
||||||
"PublisherID" => "Int"
|
"PublisherID" => "Int"
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,8 +138,8 @@ class Versioned extends DataExtension {
|
|||||||
switch($dataQuery->getQueryParam('Versioned.mode')) {
|
switch($dataQuery->getQueryParam('Versioned.mode')) {
|
||||||
// Noop
|
// Noop
|
||||||
case '':
|
case '':
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Reading a specific data from the archive
|
// Reading a specific data from the archive
|
||||||
case 'archive':
|
case 'archive':
|
||||||
$date = $dataQuery->getQueryParam('Versioned.date');
|
$date = $dataQuery->getQueryParam('Versioned.date');
|
||||||
@ -186,31 +186,30 @@ class Versioned extends DataExtension {
|
|||||||
// Return all version instances
|
// Return all version instances
|
||||||
case 'all_versions':
|
case 'all_versions':
|
||||||
case 'latest_versions':
|
case 'latest_versions':
|
||||||
foreach($query->getFrom() as $alias => $join) {
|
foreach($query->getFrom() as $alias => $join) {
|
||||||
if($alias != $baseTable) {
|
if($alias != $baseTable) {
|
||||||
$query->setJoinFilter($alias, "\"$alias\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$alias\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
|
$query->setJoinFilter($alias, "\"$alias\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$alias\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
|
||||||
}
|
}
|
||||||
$query->renameTable($alias, $alias . '_versions');
|
$query->renameTable($alias, $alias . '_versions');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all <basetable>_versions columns
|
// Add all <basetable>_versions columns
|
||||||
foreach(self::$db_for_versions_table as $name => $type) {
|
foreach(self::$db_for_versions_table as $name => $type) {
|
||||||
$query->selectField(sprintf('"%s_versions"."%s"', $baseTable, $name), $name);
|
$query->selectField(sprintf('"%s_versions"."%s"', $baseTable, $name), $name);
|
||||||
}
|
}
|
||||||
$query->selectField(sprintf('"%s_versions"."%s"', $baseTable, 'RecordID'), "ID");
|
$query->selectField(sprintf('"%s_versions"."%s"', $baseTable, 'RecordID'), "ID");
|
||||||
|
|
||||||
// latest_version has one more step
|
// latest_version has one more step
|
||||||
// Return latest version instances, regardless of whether they are on a particular stage
|
// Return latest version instances, regardless of whether they are on a particular stage
|
||||||
// This provides "show all, including deleted" functonality
|
// This provides "show all, including deleted" functonality
|
||||||
if($dataQuery->getQueryParam('Versioned.mode') == 'latest_versions') {
|
if($dataQuery->getQueryParam('Versioned.mode') == 'latest_versions') {
|
||||||
$archiveTable = self::requireArchiveTempTable($baseTable);
|
$archiveTable = self::requireArchiveTempTable($baseTable);
|
||||||
$query->addInnerJoin($archiveTable, "\"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
|
$query->addInnerJoin($archiveTable, "\"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
default:
|
throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: " . $dataQuery->getQueryParam('Versioned.mode'));
|
||||||
throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: " . $dataQuery->getQueryParam('Versioned.mode'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,7 +685,7 @@ class Versioned extends DataExtension {
|
|||||||
if(!is_numeric($this->owner->ID)) {
|
if(!is_numeric($this->owner->ID)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We test for equality - if one of the versions doesn't exist, this will be false
|
// We test for equality - if one of the versions doesn't exist, this will be false
|
||||||
//TODO: DB Abstraction: if statement here:
|
//TODO: DB Abstraction: if statement here:
|
||||||
$stagesAreEqual = DB::query("SELECT CASE WHEN \"$table1\".\"Version\"=\"$table2\".\"Version\" THEN 1 ELSE 0 END FROM \"$table1\" INNER JOIN \"$table2\" ON \"$table1\".\"ID\" = \"$table2\".\"ID\" AND \"$table1\".\"ID\" = {$this->owner->ID}")->value();
|
$stagesAreEqual = DB::query("SELECT CASE WHEN \"$table1\".\"Version\"=\"$table2\".\"Version\" THEN 1 ELSE 0 END FROM \"$table1\" INNER JOIN \"$table2\" ON \"$table1\".\"ID\" = \"$table2\".\"ID\" AND \"$table1\".\"ID\" = {$this->owner->ID}")->value();
|
||||||
@ -875,10 +874,10 @@ class Versioned extends DataExtension {
|
|||||||
* @return DataObject
|
* @return DataObject
|
||||||
*/
|
*/
|
||||||
static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '') {
|
static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '') {
|
||||||
// TODO: No identity cache operating
|
// TODO: No identity cache operating
|
||||||
$items = self::get_by_stage($class, $stage, $filter, $sort, null, 1);
|
$items = self::get_by_stage($class, $stage, $filter, $sort, null, 1);
|
||||||
return $items->First();
|
return $items->First();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current version number of a specific record.
|
* Gets the current version number of a specific record.
|
||||||
@ -992,9 +991,9 @@ class Versioned extends DataExtension {
|
|||||||
*/
|
*/
|
||||||
static function get_latest_version($class, $id) {
|
static function get_latest_version($class, $id) {
|
||||||
$baseClass = ClassInfo::baseDataClass($class);
|
$baseClass = ClassInfo::baseDataClass($class);
|
||||||
$list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
|
$list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
|
||||||
$list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
|
$list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
|
||||||
return $list->First();
|
return $list->First();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1020,9 +1019,9 @@ class Versioned extends DataExtension {
|
|||||||
* In particular, this will query deleted records as well as active ones.
|
* In particular, this will query deleted records as well as active ones.
|
||||||
*/
|
*/
|
||||||
static function get_including_deleted($class, $filter = "", $sort = "") {
|
static function get_including_deleted($class, $filter = "", $sort = "") {
|
||||||
$list = DataList::create($class)->where($filter)->sort($sort);
|
$list = DataList::create($class)->where($filter)->sort($sort);
|
||||||
$list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
|
$list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1031,9 +1030,9 @@ class Versioned extends DataExtension {
|
|||||||
*/
|
*/
|
||||||
static function get_version($class, $id, $version) {
|
static function get_version($class, $id, $version) {
|
||||||
$baseClass = ClassInfo::baseDataClass($class);
|
$baseClass = ClassInfo::baseDataClass($class);
|
||||||
$list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version);
|
$list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version);
|
||||||
$list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
|
$list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
|
||||||
return $list->First();
|
return $list->First();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1041,10 +1040,10 @@ class Versioned extends DataExtension {
|
|||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
static function get_all_versions($class, $id) {
|
static function get_all_versions($class, $id) {
|
||||||
$baseClass = ClassInfo::baseDataClass($class);
|
$baseClass = ClassInfo::baseDataClass($class);
|
||||||
$list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
|
$list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
|
||||||
$list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
|
$list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
function contentcontrollerInit($controller) {
|
function contentcontrollerInit($controller) {
|
||||||
|
@ -68,7 +68,7 @@ class Group extends DataObject {
|
|||||||
new TextField("Title", $this->fieldLabel('Title')),
|
new TextField("Title", $this->fieldLabel('Title')),
|
||||||
$parentidfield = DropdownField::create( 'ParentID',
|
$parentidfield = DropdownField::create( 'ParentID',
|
||||||
$this->fieldLabel('Parent'),
|
$this->fieldLabel('Parent'),
|
||||||
DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
|
Group::get()->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
|
||||||
)->setEmptyString(' ')
|
)->setEmptyString(' ')
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ class Group extends DataObject {
|
|||||||
// Filters are conjunctive in DataQuery by default, so this filter would otherwise overrule any less specific ones.
|
// Filters are conjunctive in DataQuery by default, so this filter would otherwise overrule any less specific ones.
|
||||||
$result->dataQuery()->removeFilterOn('Group_Members');
|
$result->dataQuery()->removeFilterOn('Group_Members');
|
||||||
// Now set all children groups as a new foreign key
|
// Now set all children groups as a new foreign key
|
||||||
$groups = DataList::create("Group")->byIDs($this->collateFamilyIDs());
|
$groups = Group::get()->byIDs($this->collateFamilyIDs());
|
||||||
$result = $result->forForeignID($groups->column('ID'))->where($filter)->sort($sort)->limit($limit);
|
$result = $result->forForeignID($groups->column('ID'))->where($filter)->sort($sort)->limit($limit);
|
||||||
if($join) $result = $result->join($join);
|
if($join) $result = $result->join($join);
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ class Group extends DataObject {
|
|||||||
public static function map($filter = "", $sort = "", $blank="") {
|
public static function map($filter = "", $sort = "", $blank="") {
|
||||||
Deprecation::notice('3.0', 'Use DataList::("Group")->map()');
|
Deprecation::notice('3.0', 'Use DataList::("Group")->map()');
|
||||||
|
|
||||||
$list = DataList::create("Group")->where($filter)->sort($sort);
|
$list = Group::get()->where($filter)->sort($sort);
|
||||||
$map = $list->map();
|
$map = $list->map();
|
||||||
|
|
||||||
if($blank) $map->unshift(0, $blank);
|
if($blank) $map->unshift(0, $blank);
|
||||||
@ -284,7 +284,7 @@ class Group extends DataObject {
|
|||||||
|
|
||||||
// Get the children of *all* the groups identified in the previous chunk.
|
// Get the children of *all* the groups identified in the previous chunk.
|
||||||
// This minimises the number of SQL queries necessary
|
// This minimises the number of SQL queries necessary
|
||||||
$chunkToAdd = DataList::create('Group')->where("\"ParentID\" IN ($idList)")->column('ID');
|
$chunkToAdd = Group::get()->where("\"ParentID\" IN ($idList)")->column('ID');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $familyIDs;
|
return $familyIDs;
|
||||||
|
@ -963,7 +963,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
public static function map($filter = "", $sort = "", $blank="") {
|
public static function map($filter = "", $sort = "", $blank="") {
|
||||||
Deprecation::notice('3.0', 'Use DataList::("Member")->map()');
|
Deprecation::notice('3.0', 'Use DataList::("Member")->map()');
|
||||||
|
|
||||||
$list = DataList::create("Member")->where($filter)->sort($sort);
|
$list = Member::get()->where($filter)->sort($sort);
|
||||||
$map = $list->map();
|
$map = $list->map();
|
||||||
|
|
||||||
if($blank) $map->unshift(0, $blank);
|
if($blank) $map->unshift(0, $blank);
|
||||||
@ -1062,7 +1062,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
? "\"GroupID\" IN (" . implode( ',', $groupIDList ) . ")"
|
? "\"GroupID\" IN (" . implode( ',', $groupIDList ) . ")"
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
return DataList::create("Member")->where($filterClause)->sort("\"Surname\", \"FirstName\"")
|
return Member::get()->where($filterClause)->sort("\"Surname\", \"FirstName\"")
|
||||||
->innerJoin("Group_Members", "\"MemberID\"=\"Member\".\"ID\"")
|
->innerJoin("Group_Members", "\"MemberID\"=\"Member\".\"ID\"")
|
||||||
->innerJoin("Group", "\"Group\".\"ID\"=\"GroupID\"")
|
->innerJoin("Group", "\"Group\".\"ID\"=\"GroupID\"")
|
||||||
->map();
|
->map();
|
||||||
@ -1148,7 +1148,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
$fields->removeByName('Groups');
|
$fields->removeByName('Groups');
|
||||||
|
|
||||||
if(Permission::check('EDIT_PERMISSIONS')) {
|
if(Permission::check('EDIT_PERMISSIONS')) {
|
||||||
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
|
$groupsMap = Group::get()->map('ID', 'Breadcrumbs')->toArray();
|
||||||
asort($groupsMap);
|
asort($groupsMap);
|
||||||
$fields->addFieldToTab('Root.Main',
|
$fields->addFieldToTab('Root.Main',
|
||||||
ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())
|
ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())
|
||||||
|
@ -69,7 +69,7 @@ class GridFieldTest extends SapphireTest {
|
|||||||
* @covers GridField::setModelClass
|
* @covers GridField::setModelClass
|
||||||
*/
|
*/
|
||||||
public function testGridFieldModelClass() {
|
public function testGridFieldModelClass() {
|
||||||
$obj = new GridField('testfield', 'testfield', DataList::create('Member'));
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
||||||
$this->assertEquals('Member', $obj->getModelClass(), 'Should return Member');
|
$this->assertEquals('Member', $obj->getModelClass(), 'Should return Member');
|
||||||
$obj->setModelClass('DataModel');
|
$obj->setModelClass('DataModel');
|
||||||
$this->assertEquals('DataModel', $obj->getModelClass(), 'Should return Member');
|
$this->assertEquals('DataModel', $obj->getModelClass(), 'Should return Member');
|
||||||
@ -89,7 +89,7 @@ class GridFieldTest extends SapphireTest {
|
|||||||
* @covers GridField::getList
|
* @covers GridField::getList
|
||||||
*/
|
*/
|
||||||
public function testSetAndGetList() {
|
public function testSetAndGetList() {
|
||||||
$list = DataList::create('Member');
|
$list = Member::get();
|
||||||
$arrayList = ArrayList::create(array(1,2,3));
|
$arrayList = ArrayList::create(array(1,2,3));
|
||||||
$obj = new GridField('testfield', 'testfield', $list);
|
$obj = new GridField('testfield', 'testfield', $list);
|
||||||
$this->assertEquals($list, $obj->getList());
|
$this->assertEquals($list, $obj->getList());
|
||||||
@ -110,7 +110,7 @@ class GridFieldTest extends SapphireTest {
|
|||||||
* @covers GridField::getColumns
|
* @covers GridField::getColumns
|
||||||
*/
|
*/
|
||||||
public function testGetColumns(){
|
public function testGetColumns(){
|
||||||
$obj = new GridField('testfield', 'testfield', DataList::create('Member'));
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
||||||
$expected = array (
|
$expected = array (
|
||||||
0 => 'FirstName',
|
0 => 'FirstName',
|
||||||
1 => 'Surname',
|
1 => 'Surname',
|
||||||
@ -123,7 +123,7 @@ class GridFieldTest extends SapphireTest {
|
|||||||
* @covers GridField::getColumnCount
|
* @covers GridField::getColumnCount
|
||||||
*/
|
*/
|
||||||
public function testGetColumnCount() {
|
public function testGetColumnCount() {
|
||||||
$obj = new GridField('testfield', 'testfield', DataList::create('Member'));
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
||||||
$this->assertEquals(3, $obj->getColumnCount());
|
$this->assertEquals(3, $obj->getColumnCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ class GridFieldDataColumnsTest extends SapphireTest {
|
|||||||
* @covers GridFieldDataColumns::getDisplayFields
|
* @covers GridFieldDataColumns::getDisplayFields
|
||||||
*/
|
*/
|
||||||
public function testGridFieldGetDefaultDisplayFields() {
|
public function testGridFieldGetDefaultDisplayFields() {
|
||||||
$obj = new GridField('testfield', 'testfield', DataList::create('Member'));
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
||||||
$expected = singleton('Member')->summaryFields();
|
$expected = singleton('Member')->summaryFields();
|
||||||
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||||
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
||||||
@ -16,7 +16,7 @@ class GridFieldDataColumnsTest extends SapphireTest {
|
|||||||
* @covers GridFieldDataColumns::getDisplayFields
|
* @covers GridFieldDataColumns::getDisplayFields
|
||||||
*/
|
*/
|
||||||
public function testGridFieldCustomDisplayFields() {
|
public function testGridFieldCustomDisplayFields() {
|
||||||
$obj = new GridField('testfield', 'testfield', DataList::create('Member'));
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
||||||
$expected = array('Email' => 'Email');
|
$expected = array('Email' => 'Email');
|
||||||
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||||
$columns->setDisplayFields($expected);
|
$columns->setDisplayFields($expected);
|
||||||
@ -29,7 +29,7 @@ class GridFieldDataColumnsTest extends SapphireTest {
|
|||||||
*/
|
*/
|
||||||
public function testGridFieldDisplayFieldsWithBadArguments() {
|
public function testGridFieldDisplayFieldsWithBadArguments() {
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
$obj = new GridField('testfield', 'testfield', DataList::create('Member'));
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
||||||
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||||
$columns->setDisplayFields(new stdClass());
|
$columns->setDisplayFields(new stdClass());
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
|||||||
|
|
||||||
function testAddForm() {
|
function testAddForm() {
|
||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
$group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
|
$group = GridFieldDetailFormTest_PeopleGroup::get()
|
||||||
->filter('Name', 'My Group')
|
->filter('Name', 'My Group')
|
||||||
->sort('Name')
|
->sort('Name')
|
||||||
->First();
|
->First();
|
||||||
@ -40,7 +40,7 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
|||||||
);
|
);
|
||||||
$this->assertFalse($response->isError());
|
$this->assertFalse($response->isError());
|
||||||
|
|
||||||
$group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
|
$group = GridFieldDetailFormTest_PeopleGroup::get()
|
||||||
->filter('Name', 'My Group')
|
->filter('Name', 'My Group')
|
||||||
->sort('Name')
|
->sort('Name')
|
||||||
->First();
|
->First();
|
||||||
@ -69,7 +69,7 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
|||||||
|
|
||||||
function testEditForm() {
|
function testEditForm() {
|
||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
$group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
|
$group = GridFieldDetailFormTest_PeopleGroup::get()
|
||||||
->filter('Name', 'My Group')
|
->filter('Name', 'My Group')
|
||||||
->sort('Name')
|
->sort('Name')
|
||||||
->First();
|
->First();
|
||||||
@ -99,7 +99,7 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
|||||||
);
|
);
|
||||||
$this->assertFalse($response->isError());
|
$this->assertFalse($response->isError());
|
||||||
|
|
||||||
$group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
|
$group = GridFieldDetailFormTest_PeopleGroup::get()
|
||||||
->filter('Name', 'My Group')
|
->filter('Name', 'My Group')
|
||||||
->sort('Name')
|
->sort('Name')
|
||||||
->First();
|
->First();
|
||||||
@ -249,7 +249,7 @@ class GridFieldDetailFormTest_Controller extends Controller implements TestOnly
|
|||||||
protected $template = 'BlankPage';
|
protected $template = 'BlankPage';
|
||||||
|
|
||||||
function Form() {
|
function Form() {
|
||||||
$group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
|
$group = GridFieldDetailFormTest_PeopleGroup::get()
|
||||||
->filter('Name', 'My Group')
|
->filter('Name', 'My Group')
|
||||||
->sort('Name')
|
->sort('Name')
|
||||||
->First();
|
->First();
|
||||||
@ -269,7 +269,7 @@ class GridFieldDetailFormTest_GroupController extends Controller implements Test
|
|||||||
protected $template = 'BlankPage';
|
protected $template = 'BlankPage';
|
||||||
|
|
||||||
function Form() {
|
function Form() {
|
||||||
$field = new GridField('testfield', 'testfield', DataList::create('GridFieldDetailFormTest_PeopleGroup')->sort('Name'));
|
$field = new GridField('testfield', 'testfield', GridFieldDetailFormTest_PeopleGroup::get()->sort('Name'));
|
||||||
$field->getConfig()->addComponent($gridFieldForm = new GridFieldDetailForm($this, 'Form'));
|
$field->getConfig()->addComponent($gridFieldForm = new GridFieldDetailForm($this, 'Form'));
|
||||||
$field->getConfig()->addComponent(new GridFieldToolbarHeader());
|
$field->getConfig()->addComponent(new GridFieldToolbarHeader());
|
||||||
$field->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
|
$field->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
|
||||||
@ -279,4 +279,4 @@ class GridFieldDetailFormTest_GroupController extends Controller implements Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly {
|
class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly {
|
||||||
}
|
}
|
||||||
|
@ -18,22 +18,22 @@ class DataListTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public function testSubtract(){
|
public function testSubtract(){
|
||||||
$subtractList = DataList::create("DataObjectTest_TeamComment")->filter('ID',1);
|
$subtractList = DataObjectTest_TeamComment::get()->filter('ID', 1);
|
||||||
$fullList = DataList::create("DataObjectTest_TeamComment");
|
$fullList = DataObjectTest_TeamComment::get();
|
||||||
$newList = $fullList->subtract($subtractList);
|
$newList = $fullList->subtract($subtractList);
|
||||||
$this->assertEquals(2, $newList->Count(), 'List should only contain two objects after subtraction');
|
$this->assertEquals(2, $newList->Count(), 'List should only contain two objects after subtraction');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubtractBadDataclassThrowsException(){
|
public function testSubtractBadDataclassThrowsException(){
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
$teamsComments = DataList::create("DataObjectTest_TeamComment");
|
$teamsComments = DataObjectTest_TeamComment::get();
|
||||||
$teams = DataList::create("DataObjectTest_Team");
|
$teams = DataObjectTest_Team::get();
|
||||||
$teamsComments->subtract($teams);
|
$teamsComments->subtract($teams);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testListCreationSortAndLimit() {
|
function testListCreationSortAndLimit() {
|
||||||
// By default, a DataList will contain all items of that class
|
// By default, a DataList will contain all items of that class
|
||||||
$list = DataList::create('DataObjectTest_TeamComment')->sort('ID');
|
$list = DataObjectTest_TeamComment::get()->sort('ID');
|
||||||
|
|
||||||
// We can iterate on the DataList
|
// We can iterate on the DataList
|
||||||
$names = array();
|
$names = array();
|
||||||
@ -54,37 +54,37 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testDataClass() {
|
function testDataClass() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$this->assertEquals('DataObjectTest_TeamComment',$list->dataClass());
|
$this->assertEquals('DataObjectTest_TeamComment',$list->dataClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testClone() {
|
function testClone() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$this->assertEquals($list, clone($list));
|
$this->assertEquals($list, clone($list));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSql() {
|
function testSql() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment"';
|
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment"';
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertEquals($expected, $list->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInnerJoin() {
|
function testInnerJoin() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->innerJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
$list->innerJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" INNER JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" INNER JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertEquals($expected, $list->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLeftJoin() {
|
function testLeftJoin() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->leftJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
$list->leftJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" LEFT JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" LEFT JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertEquals($expected, $list->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testToNestedArray() {
|
function testToNestedArray() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment')->sort('ID');
|
$list = DataObjectTest_TeamComment::get()->sort('ID');
|
||||||
$nestedArray = $list->toNestedArray();
|
$nestedArray = $list->toNestedArray();
|
||||||
$expected = array(
|
$expected = array(
|
||||||
0=>
|
0=>
|
||||||
@ -116,7 +116,7 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testMap() {
|
function testMap() {
|
||||||
$map = DataList::create('DataObjectTest_TeamComment')->map()->toArray();
|
$map = DataObjectTest_TeamComment::get()->map()->toArray();
|
||||||
$expected = array(
|
$expected = array(
|
||||||
$this->idFromFixture('DataObjectTest_TeamComment', 'comment1') => 'Joe',
|
$this->idFromFixture('DataObjectTest_TeamComment', 'comment1') => 'Joe',
|
||||||
$this->idFromFixture('DataObjectTest_TeamComment', 'comment2') => 'Bob',
|
$this->idFromFixture('DataObjectTest_TeamComment', 'comment2') => 'Bob',
|
||||||
@ -124,7 +124,7 @@ class DataListTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected, $map);
|
$this->assertEquals($expected, $map);
|
||||||
$otherMap = DataList::create('DataObjectTest_TeamComment')->map('Name', 'TeamID')->toArray();
|
$otherMap = DataObjectTest_TeamComment::get()->map('Name', 'TeamID')->toArray();
|
||||||
$otherExpected = array(
|
$otherExpected = array(
|
||||||
'Joe' => $this->objFromFixture('DataObjectTest_TeamComment', 'comment1')->TeamID,
|
'Joe' => $this->objFromFixture('DataObjectTest_TeamComment', 'comment1')->TeamID,
|
||||||
'Bob' => $this->objFromFixture('DataObjectTest_TeamComment', 'comment2')->TeamID,
|
'Bob' => $this->objFromFixture('DataObjectTest_TeamComment', 'comment2')->TeamID,
|
||||||
@ -141,7 +141,7 @@ class DataListTest extends SapphireTest {
|
|||||||
function testWhere() {
|
function testWhere() {
|
||||||
// We can use raw SQL queries with where. This is only recommended for advanced uses;
|
// We can use raw SQL queries with where. This is only recommended for advanced uses;
|
||||||
// if you can, you should use filter().
|
// if you can, you should use filter().
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
|
|
||||||
// where() returns a new DataList, like all the other modifiers, so it can be chained.
|
// where() returns a new DataList, like all the other modifiers, so it can be chained.
|
||||||
$list2 = $list->where('"Name" = \'Joe\'');
|
$list2 = $list->where('"Name" = \'Joe\'');
|
||||||
@ -158,7 +158,7 @@ class DataListTest extends SapphireTest {
|
|||||||
function testByID() {
|
function testByID() {
|
||||||
// We can get a single item by ID.
|
// We can get a single item by ID.
|
||||||
$id = $this->idFromFixture('DataObjectTest_Team','team2');
|
$id = $this->idFromFixture('DataObjectTest_Team','team2');
|
||||||
$team = DataList::create("DataObjectTest_Team")->byID($id);
|
$team = DataObjectTest_Team::get()->byID($id);
|
||||||
|
|
||||||
// byID() returns a DataObject, rather than a DataList
|
// byID() returns a DataObject, rather than a DataList
|
||||||
$this->assertInstanceOf('DataObjectTest_Team', $team);
|
$this->assertInstanceOf('DataObjectTest_Team', $team);
|
||||||
@ -169,7 +169,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* Test DataList->removeByID()
|
* Test DataList->removeByID()
|
||||||
*/
|
*/
|
||||||
function testRemoveByID() {
|
function testRemoveByID() {
|
||||||
$list = DataList::create("DataObjectTest_Team");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$id = $this->idFromFixture('DataObjectTest_Team','team2');
|
$id = $this->idFromFixture('DataObjectTest_Team','team2');
|
||||||
|
|
||||||
$this->assertNotNull($list->byID($id));
|
$this->assertNotNull($list->byID($id));
|
||||||
@ -182,18 +182,18 @@ class DataListTest extends SapphireTest {
|
|||||||
*/
|
*/
|
||||||
function testCanSortBy() {
|
function testCanSortBy() {
|
||||||
// Basic check
|
// Basic check
|
||||||
$team = DataList::create("DataObjectTest_Team");
|
$team = DataObjectTest_Team::get();
|
||||||
$this->assertTrue($team->canSortBy("Title"));
|
$this->assertTrue($team->canSortBy("Title"));
|
||||||
$this->assertFalse($team->canSortBy("SomethingElse"));
|
$this->assertFalse($team->canSortBy("SomethingElse"));
|
||||||
|
|
||||||
// Subclasses
|
// Subclasses
|
||||||
$subteam = DataList::create("DataObjectTest_SubTeam");
|
$subteam = DataObjectTest_SubTeam::get();
|
||||||
$this->assertTrue($subteam->canSortBy("Title"));
|
$this->assertTrue($subteam->canSortBy("Title"));
|
||||||
$this->assertTrue($subteam->canSortBy("SubclassDatabaseField"));
|
$this->assertTrue($subteam->canSortBy("SubclassDatabaseField"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDataListArrayAccess() {
|
function testDataListArrayAccess() {
|
||||||
$list = DataList::create("DataObjectTest_Team")->sort("Title");
|
$list = DataObjectTest_Team::get()->sort('Title');
|
||||||
|
|
||||||
// We can use array access to refer to single items in the DataList, as if it were an array
|
// We can use array access to refer to single items in the DataList, as if it were an array
|
||||||
$this->assertEquals("Subteam 1", $list[0]->Title);
|
$this->assertEquals("Subteam 1", $list[0]->Title);
|
||||||
@ -202,13 +202,13 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testFind() {
|
function testFind() {
|
||||||
$list = DataList::create("DataObjectTest_Team");
|
$list = DataObjectTest_Team::get();
|
||||||
$record = $list->find('Title', 'Team 1');
|
$record = $list->find('Title', 'Team 1');
|
||||||
$this->assertEquals($this->idFromFixture('DataObjectTest_Team', 'team1'), $record->ID);
|
$this->assertEquals($this->idFromFixture('DataObjectTest_Team', 'team1'), $record->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testFindById() {
|
function testFindById() {
|
||||||
$list = DataList::create("DataObjectTest_Team");
|
$list = DataObjectTest_Team::get();
|
||||||
$record = $list->find('ID', $this->idFromFixture('DataObjectTest_Team', 'team1'));
|
$record = $list->find('ID', $this->idFromFixture('DataObjectTest_Team', 'team1'));
|
||||||
$this->assertEquals('Team 1', $record->Title);
|
$this->assertEquals('Team 1', $record->Title);
|
||||||
// Test that you can call it twice on the same list
|
// Test that you can call it twice on the same list
|
||||||
@ -217,63 +217,63 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleSort() {
|
public function testSimpleSort() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name');
|
$list->sort('Name');
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleSortOneArgumentASC() {
|
public function testSimpleSortOneArgumentASC() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name ASC');
|
$list->sort('Name ASC');
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleSortOneArgumentDESC() {
|
public function testSimpleSortOneArgumentDESC() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name DESC');
|
$list->sort('Name DESC');
|
||||||
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
|
||||||
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSortOneArgumentMultipleColumns() {
|
public function testSortOneArgumentMultipleColumns() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('TeamID ASC, Name DESC');
|
$list->sort('TeamID ASC, Name DESC');
|
||||||
$this->assertEquals('Joe', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Joe', $list->first()->Name, 'First comment should be from Bob');
|
||||||
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleSortASC() {
|
public function testSimpleSortASC() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name', 'asc');
|
$list->sort('Name', 'asc');
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleSortDESC() {
|
public function testSimpleSortDESC() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name', 'desc');
|
$list->sort('Name', 'desc');
|
||||||
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
|
||||||
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSortWithArraySyntaxSortASC() {
|
public function testSortWithArraySyntaxSortASC() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort(array('Name'=>'asc'));
|
$list->sort(array('Name'=>'asc'));
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSortWithArraySyntaxSortDESC() {
|
public function testSortWithArraySyntaxSortDESC() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort(array('Name'=>'desc'));
|
$list->sort(array('Name'=>'desc'));
|
||||||
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
|
||||||
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSortWithMultipleArraySyntaxSort() {
|
public function testSortWithMultipleArraySyntaxSort() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort(array('TeamID'=>'asc','Name'=>'desc'));
|
$list->sort(array('TeamID'=>'asc','Name'=>'desc'));
|
||||||
$this->assertEquals('Joe', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Joe', $list->first()->Name, 'First comment should be from Bob');
|
||||||
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
|
||||||
@ -283,7 +283,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->filter('Name', 'bob'); // only bob in the list
|
* $list->filter('Name', 'bob'); // only bob in the list
|
||||||
*/
|
*/
|
||||||
public function testSimpleFilter() {
|
public function testSimpleFilter() {
|
||||||
$list = DataList::create("DataObjectTest_Team");
|
$list = DataObjectTest_Team::get();
|
||||||
$list->filter('Title','Team 2');
|
$list->filter('Title','Team 2');
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Team 2', $list->first()->Title, 'List should only contain Team 2');
|
$this->assertEquals('Team 2', $list->first()->Title, 'List should only contain Team 2');
|
||||||
@ -291,28 +291,28 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleFilterEndsWith() {
|
public function testSimpleFilterEndsWith() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('Name:EndsWith', 'b');
|
$list->filter('Name:EndsWith', 'b');
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleFilterExactMatchFilter() {
|
public function testSimpleFilterExactMatchFilter() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('Name:ExactMatch', 'Bob');
|
$list->filter('Name:ExactMatch', 'Bob');
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleFilterGreaterThanFilter() {
|
public function testSimpleFilterGreaterThanFilter() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('TeamID:GreaterThan', $this->idFromFixture('DataObjectTest_Team', 'team1'));
|
$list->filter('TeamID:GreaterThan', $this->idFromFixture('DataObjectTest_Team', 'team1'));
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Phil', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Phil', $list->first()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function testSimpleFilterLessThanFilter() {
|
// public function testSimpleFilterLessThanFilter() {
|
||||||
// $list = DataList::create("DataObjectTest_TeamComment");
|
// $list = DataObjectTest_TeamComment::get();
|
||||||
// $list = $list->filter('TeamID:LessThan', $this->idFromFixture('DataObjectTest_TeamComment', 'comment2'))->sort('Name');
|
// $list = $list->filter('TeamID:LessThan', $this->idFromFixture('DataObjectTest_TeamComment', 'comment2'))->sort('Name');
|
||||||
// $this->assertEquals(2, $list->count());
|
// $this->assertEquals(2, $list->count());
|
||||||
// $this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
// $this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
@ -320,14 +320,14 @@ class DataListTest extends SapphireTest {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
public function testSimpleNegationFilter() {
|
public function testSimpleNegationFilter() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('TeamID:Negation', $this->idFromFixture('DataObjectTest_Team', 'team1'));
|
$list->filter('TeamID:Negation', $this->idFromFixture('DataObjectTest_Team', 'team1'));
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Phil', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Phil', $list->first()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimplePartialMatchFilter() {
|
public function testSimplePartialMatchFilter() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('Name:PartialMatch', 'o')->sort('Name');
|
$list->filter('Name:PartialMatch', 'o')->sort('Name');
|
||||||
$this->assertEquals(2, $list->count());
|
$this->assertEquals(2, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
@ -335,7 +335,7 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleFilterStartsWith() {
|
public function testSimpleFilterStartsWith() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('Name:StartsWith', 'B');
|
$list->filter('Name:StartsWith', 'B');
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
@ -343,7 +343,7 @@ class DataListTest extends SapphireTest {
|
|||||||
|
|
||||||
public function testSimpleFilterWithNonExistingComparisator() {
|
public function testSimpleFilterWithNonExistingComparisator() {
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('Comment:Bogus', 'team comment');
|
$list->filter('Comment:Bogus', 'team comment');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
* $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
||||||
*/
|
*/
|
||||||
public function testSimpleFilterWithMultiple() {
|
public function testSimpleFilterWithMultiple() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter('Name', array('Bob','Phil'));
|
$list->filter('Name', array('Bob','Phil'));
|
||||||
$this->assertEquals(2, $list->count());
|
$this->assertEquals(2, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
@ -359,7 +359,7 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testMultipleFilterWithNoMatch() {
|
public function testMultipleFilterWithNoMatch() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter(array('Name'=>'Bob', 'Comment'=>'Phil is a unique guy, and comments on team2'));
|
$list->filter(array('Name'=>'Bob', 'Comment'=>'Phil is a unique guy, and comments on team2'));
|
||||||
$this->assertEquals(0, $list->count());
|
$this->assertEquals(0, $list->count());
|
||||||
}
|
}
|
||||||
@ -368,20 +368,20 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
|
* $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
|
||||||
*/
|
*/
|
||||||
public function testFilterMultipleArray() {
|
public function testFilterMultipleArray() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob'));
|
$list->filter(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob'));
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'Only comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'Only comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilterMultipleWithTwoMatches() {
|
public function testFilterMultipleWithTwoMatches() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter(array('TeamID'=>$this->idFromFixture('DataObjectTest_Team', 'team1')));
|
$list->filter(array('TeamID'=>$this->idFromFixture('DataObjectTest_Team', 'team1')));
|
||||||
$this->assertEquals(2, $list->count());
|
$this->assertEquals(2, $list->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilterMultipleWithArrayFilter() {
|
public function testFilterMultipleWithArrayFilter() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter(array('Name'=>array('Bob','Phil')));
|
$list->filter(array('Name'=>array('Bob','Phil')));
|
||||||
$this->assertEquals(2, $list->count(), 'There should be two comments');
|
$this->assertEquals(2, $list->count(), 'There should be two comments');
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
@ -392,7 +392,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
|
* $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
|
||||||
*/
|
*/
|
||||||
public function testFilterArrayInArray() {
|
public function testFilterArrayInArray() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->filter(array('Name'=>array('Bob','Phil'), 'TeamID'=>array($this->idFromFixture('DataObjectTest_Team', 'team1'))));
|
$list->filter(array('Name'=>array('Bob','Phil'), 'TeamID'=>array($this->idFromFixture('DataObjectTest_Team', 'team1'))));
|
||||||
$this->assertEquals(1, $list->count(), 'There should be one comments');
|
$this->assertEquals(1, $list->count(), 'There should be one comments');
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'Only comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'Only comment should be from Bob');
|
||||||
@ -402,7 +402,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude('Name', 'bob'); // exclude bob from list
|
* $list->exclude('Name', 'bob'); // exclude bob from list
|
||||||
*/
|
*/
|
||||||
public function testSimpleExclude() {
|
public function testSimpleExclude() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude('Name', 'Bob');
|
$list->exclude('Name', 'Bob');
|
||||||
$list->sort('Name');
|
$list->sort('Name');
|
||||||
$this->assertEquals(2, $list->count());
|
$this->assertEquals(2, $list->count());
|
||||||
@ -414,7 +414,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
|
* $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
|
||||||
*/
|
*/
|
||||||
public function testSimpleExcludeWithMultiple() {
|
public function testSimpleExcludeWithMultiple() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude('Name', array('Joe','Phil'));
|
$list->exclude('Name', array('Joe','Phil'));
|
||||||
$this->assertEquals(1, $list->count());
|
$this->assertEquals(1, $list->count());
|
||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
@ -424,7 +424,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>'bob, 'Age'=>21)); // negative version
|
* $list->exclude(array('Name'=>'bob, 'Age'=>21)); // negative version
|
||||||
*/
|
*/
|
||||||
public function testMultipleExcludeWithMiss() {
|
public function testMultipleExcludeWithMiss() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name'=>'Bob', 'Comment'=>'Does not match any comments'));
|
$list->exclude(array('Name'=>'Bob', 'Comment'=>'Does not match any comments'));
|
||||||
$this->assertEquals(3, $list->count());
|
$this->assertEquals(3, $list->count());
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
|
* $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
|
||||||
*/
|
*/
|
||||||
public function testMultipleExclude() {
|
public function testMultipleExclude() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob'));
|
$list->exclude(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob'));
|
||||||
$this->assertEquals(2, $list->count());
|
$this->assertEquals(2, $list->count());
|
||||||
}
|
}
|
||||||
@ -442,7 +442,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
|
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
|
||||||
*/
|
*/
|
||||||
public function testMultipleExcludeWithMultipleThatCheersEitherTeam() {
|
public function testMultipleExcludeWithMultipleThatCheersEitherTeam() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name'=>'Bob', 'TeamID'=>array(
|
$list->exclude(array('Name'=>'Bob', 'TeamID'=>array(
|
||||||
$this->idFromFixture('DataObjectTest_Team', 'team1'),
|
$this->idFromFixture('DataObjectTest_Team', 'team1'),
|
||||||
$this->idFromFixture('DataObjectTest_Team', 'team2')
|
$this->idFromFixture('DataObjectTest_Team', 'team2')
|
||||||
@ -457,7 +457,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // negative version
|
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // negative version
|
||||||
*/
|
*/
|
||||||
public function testMultipleExcludeWithMultipleThatCheersOnNonExistingTeam() {
|
public function testMultipleExcludeWithMultipleThatCheersOnNonExistingTeam() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name'=>'Bob', 'TeamID'=>array(3)));
|
$list->exclude(array('Name'=>'Bob', 'TeamID'=>array(3)));
|
||||||
$this->assertEquals(3, $list->count());
|
$this->assertEquals(3, $list->count());
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); //negative version
|
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); //negative version
|
||||||
*/
|
*/
|
||||||
public function testMultipleExcludeWithNoExclusion() {
|
public function testMultipleExcludeWithNoExclusion() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name'=>array('Bob','Joe'), 'Comment' => 'Phil is a unique guy, and comments on team2'));
|
$list->exclude(array('Name'=>array('Bob','Joe'), 'Comment' => 'Phil is a unique guy, and comments on team2'));
|
||||||
$this->assertEquals(3, $list->count());
|
$this->assertEquals(3, $list->count());
|
||||||
}
|
}
|
||||||
@ -475,7 +475,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
||||||
*/
|
*/
|
||||||
public function testMultipleExcludeWithTwoArray() {
|
public function testMultipleExcludeWithTwoArray() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name' => array('Bob','Joe'), 'TeamID' => array(
|
$list->exclude(array('Name' => array('Bob','Joe'), 'TeamID' => array(
|
||||||
$this->idFromFixture('DataObjectTest_Team', 'team1'),
|
$this->idFromFixture('DataObjectTest_Team', 'team1'),
|
||||||
$this->idFromFixture('DataObjectTest_Team', 'team2')
|
$this->idFromFixture('DataObjectTest_Team', 'team2')
|
||||||
@ -488,7 +488,7 @@ class DataListTest extends SapphireTest {
|
|||||||
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
||||||
*/
|
*/
|
||||||
public function testMultipleExcludeWithTwoArrayOneTeam() {
|
public function testMultipleExcludeWithTwoArrayOneTeam() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->exclude(array('Name' => array('Bob', 'Phil'), 'TeamID' => array($this->idFromFixture('DataObjectTest_Team', 'team1'))));
|
$list->exclude(array('Name' => array('Bob', 'Phil'), 'TeamID' => array($this->idFromFixture('DataObjectTest_Team', 'team1'))));
|
||||||
$list->sort('Name');
|
$list->sort('Name');
|
||||||
$this->assertEquals(2, $list->count());
|
$this->assertEquals(2, $list->count());
|
||||||
@ -500,7 +500,7 @@ class DataListTest extends SapphireTest {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testSortByRelation() {
|
public function testSortByRelation() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list = $list->sort(array('Team.Title' => 'DESC'));
|
$list = $list->sort(array('Team.Title' => 'DESC'));
|
||||||
$this->assertEquals(3, $list->count());
|
$this->assertEquals(3, $list->count());
|
||||||
$this->assertEquals($this->idFromFixture('DataObjectTest_Team', 'team2'), $list->first()->TeamID, 'First comment should be for Team 2');
|
$this->assertEquals($this->idFromFixture('DataObjectTest_Team', 'team2'), $list->first()->TeamID, 'First comment should be for Team 2');
|
||||||
@ -508,7 +508,7 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testReverse() {
|
public function testReverse() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name');
|
$list->sort('Name');
|
||||||
$list->reverse();
|
$list->reverse();
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class ManyManyListTest extends SapphireTest {
|
|||||||
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
|
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
|
||||||
$team2 = $this->objFromFixture('DataObjectTest_Team', 'team2');
|
$team2 = $this->objFromFixture('DataObjectTest_Team', 'team2');
|
||||||
|
|
||||||
$playersTeam1Team2 = DataList::create('DataObjectTest_Team')->relation('Players')->setForeignID(array($team1->ID, $team2->ID));
|
$playersTeam1Team2 = DataObjectTest_Team::get()->relation('Players')->setForeignID(array($team1->ID, $team2->ID));
|
||||||
$playersTeam1Team2->add($newPlayer);
|
$playersTeam1Team2->add($newPlayer);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array($team1->ID, $team2->ID),
|
array($team1->ID, $team2->ID),
|
||||||
|
@ -17,14 +17,14 @@ class SS_MapTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function testArrayAccess() {
|
function testArrayAccess() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
$this->assertEquals('This is a team comment by Joe', $map['Joe']);
|
$this->assertEquals('This is a team comment by Joe', $map['Joe']);
|
||||||
$this->assertNull($map['DoesntExist']);
|
$this->assertNull($map['DoesntExist']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testIteration() {
|
function testIteration() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment")->sort('ID');
|
$list = DataObjectTest_TeamComment::get()->sort('ID');
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
$text = "";
|
$text = "";
|
||||||
foreach($map as $k => $v) {
|
foreach($map as $k => $v) {
|
||||||
@ -36,13 +36,13 @@ class SS_MapTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testDefaultConfigIsIDAndTitle() {
|
function testDefaultConfigIsIDAndTitle() {
|
||||||
$list = DataList::create("DataObjectTest_Team");
|
$list = DataObjectTest_Team::get();
|
||||||
$map = new SS_Map($list);
|
$map = new SS_Map($list);
|
||||||
$this->assertEquals('Team 1', $map[$this->idFromFixture('DataObjectTest_Team', 'team1')]);
|
$this->assertEquals('Team 1', $map[$this->idFromFixture('DataObjectTest_Team', 'team1')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSetKeyFieldAndValueField() {
|
function testSetKeyFieldAndValueField() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$map = new SS_Map($list);
|
$map = new SS_Map($list);
|
||||||
$map->setKeyField('Name');
|
$map->setKeyField('Name');
|
||||||
$map->setValueField('Comment');
|
$map->setValueField('Comment');
|
||||||
@ -50,7 +50,7 @@ class SS_MapTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testToArray() {
|
function testToArray() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
$this->assertEquals(array("Joe" => "This is a team comment by Joe",
|
$this->assertEquals(array("Joe" => "This is a team comment by Joe",
|
||||||
"Bob" => "This is a team comment by Bob",
|
"Bob" => "This is a team comment by Bob",
|
||||||
@ -58,7 +58,7 @@ class SS_MapTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testKeys() {
|
function testKeys() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name');
|
$list->sort('Name');
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
@ -69,7 +69,7 @@ class SS_MapTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testMethodAsValueField() {
|
function testMethodAsValueField() {
|
||||||
$list = DataList::create('DataObjectTest_Team');
|
$list = DataObjectTest_Team::get();
|
||||||
$list->sort('Title');
|
$list->sort('Title');
|
||||||
$map = new SS_Map($list, 'ID', 'MyTitle');
|
$map = new SS_Map($list, 'ID', 'MyTitle');
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
@ -83,7 +83,7 @@ class SS_MapTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testValues() {
|
function testValues() {
|
||||||
$list = DataList::create('DataObjectTest_TeamComment');
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->sort('Name');
|
$list->sort('Name');
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
@ -94,7 +94,7 @@ class SS_MapTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testUnshift() {
|
function testUnshift() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
|
|
||||||
$map->unshift(-1, '(All)');
|
$map->unshift(-1, '(All)');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user