Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Use shorthand {class}::get() syntax instead of DataList::create()

in core code.
  • Loading branch information...
commit c3eabffcb97927f57d5b5dba7c282d8967eb4437 1 parent 71256ea
@halkyon halkyon authored
View
6 admin/code/SecurityAdmin.php
@@ -70,7 +70,7 @@ public function getEditForm($id = null, $fields = null) {
$memberList = GridField::create(
'Members',
false,
- DataList::create('Member'),
+ Member::get(),
$memberListConfig = GridFieldConfig_RecordEditor::create()
->addComponent(new GridFieldExportButton())
)->addExtraClass("members_grid");
@@ -79,7 +79,7 @@ public function getEditForm($id = null, $fields = null) {
$groupList = GridField::create(
'Groups',
false,
- DataList::create('Group'),
+ Group::get(),
GridFieldConfig_RecordEditor::create()
);
$columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns');
@@ -131,7 +131,7 @@ public function getEditForm($id = null, $fields = null) {
if(Permission::check('APPLY_ROLES')) {
$rolesField = GridField::create('Roles',
false,
- DataList::create('PermissionRole'),
+ PermissionRole::get(),
GridFieldConfig_RecordEditor::create()
);
View
11 core/Object.php
@@ -87,23 +87,22 @@ public function config() {
* or calling on Object and passing the class name as the first parameter. The following
* are equivalent:
* $list = DataList::create('SiteTree');
- * $list = DataList::create('SiteTree');
+ * $list = SiteTree::get();
*
* @param string $class the class name
* @param mixed $arguments,... arguments to pass to the constructor
* @return Object
*/
public static function create() {
- $args = func_get_args();
+ $args = func_get_args();
// Class to create should be the calling class if not Object,
// otherwise the first parameter
$class = get_called_class();
- if($class == 'Object')
- $class = array_shift($args);
-
+ if($class == 'Object') $class = array_shift($args);
+
$class = self::getCustomClass($class);
-
+
return Injector::inst()->createWithArgs($class, $args);
}
View
2  forms/DropdownField.php
@@ -13,7 +13,7 @@
*
* public function 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)');
* $fields->addFieldToTab('Root.Content', $field, 'Content');
* </code>
View
4 forms/HtmlEditorField.php
@@ -498,7 +498,7 @@ public function viewfile($request) {
} else {
$url = Director::makeRelative($request->getVar('FileURL'));
$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(
'Title' => basename($url),
'Filename' => $url
@@ -720,7 +720,7 @@ protected function getFiles($parentID = null) {
$wheres = array();
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)
if($parentID) $files->filter('ParentID', $parentID);
View
2  forms/UploadField.php
@@ -528,7 +528,7 @@ public function attach($request) {
$return = array();
- $files = DataList::create('File')->byIDs($request->postVar('ids'));
+ $files = File::get()->byIDs($request->postVar('ids'));
foreach($files as $file) {
$this->attachFile($file);
$file = $this->customiseFile($file);
View
87 model/Versioned.php
@@ -60,7 +60,7 @@ class Versioned extends DataExtension {
"Version" => "Int",
"WasPublished" => "Boolean",
"AuthorID" => "Int",
- "PublisherID" => "Int"
+ "PublisherID" => "Int"
);
/**
@@ -138,8 +138,8 @@ function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
switch($dataQuery->getQueryParam('Versioned.mode')) {
// Noop
case '':
- break;
-
+ break;
+
// Reading a specific data from the archive
case 'archive':
$date = $dataQuery->getQueryParam('Versioned.date');
@@ -186,31 +186,30 @@ function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
// Return all version instances
case 'all_versions':
case 'latest_versions':
- foreach($query->getFrom() as $alias => $join) {
- if($alias != $baseTable) {
- $query->setJoinFilter($alias, "\"$alias\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$alias\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
- }
- $query->renameTable($alias, $alias . '_versions');
- }
+ foreach($query->getFrom() as $alias => $join) {
+ if($alias != $baseTable) {
+ $query->setJoinFilter($alias, "\"$alias\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$alias\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
+ }
+ $query->renameTable($alias, $alias . '_versions');
+ }
- // Add all <basetable>_versions columns
- 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, 'RecordID'), "ID");
-
- // latest_version has one more step
- // Return latest version instances, regardless of whether they are on a particular stage
- // This provides "show all, including deleted" functonality
- if($dataQuery->getQueryParam('Versioned.mode') == 'latest_versions') {
- $archiveTable = self::requireArchiveTempTable($baseTable);
- $query->addInnerJoin($archiveTable, "\"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
- }
+ // Add all <basetable>_versions columns
+ 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, 'RecordID'), "ID");
+
+ // latest_version has one more step
+ // Return latest version instances, regardless of whether they are on a particular stage
+ // This provides "show all, including deleted" functonality
+ if($dataQuery->getQueryParam('Versioned.mode') == 'latest_versions') {
+ $archiveTable = self::requireArchiveTempTable($baseTable);
+ $query->addInnerJoin($archiveTable, "\"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
+ }
- break;
-
- default:
- throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: " . $dataQuery->getQueryParam('Versioned.mode'));
+ break;
+ default:
+ throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: " . $dataQuery->getQueryParam('Versioned.mode'));
}
}
@@ -686,7 +685,7 @@ function stagesDiffer($stage1, $stage2) {
if(!is_numeric($this->owner->ID)) {
return true;
}
-
+
// We test for equality - if one of the versions doesn't exist, this will be false
//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();
@@ -875,10 +874,10 @@ static function reading_archived_date($date) {
* @return DataObject
*/
static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '') {
- // TODO: No identity cache operating
- $items = self::get_by_stage($class, $stage, $filter, $sort, null, 1);
- return $items->First();
- }
+ // TODO: No identity cache operating
+ $items = self::get_by_stage($class, $stage, $filter, $sort, null, 1);
+ return $items->First();
+ }
/**
* Gets the current version number of a specific record.
@@ -992,9 +991,9 @@ function doRollbackTo($version) {
*/
static function get_latest_version($class, $id) {
$baseClass = ClassInfo::baseDataClass($class);
- $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
- $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
- return $list->First();
+ $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
+ $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
+ return $list->First();
}
/**
@@ -1020,9 +1019,9 @@ function isLatestVersion() {
* In particular, this will query deleted records as well as active ones.
*/
static function get_including_deleted($class, $filter = "", $sort = "") {
- $list = DataList::create($class)->where($filter)->sort($sort);
- $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
- return $list;
+ $list = DataList::create($class)->where($filter)->sort($sort);
+ $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
+ return $list;
}
/**
@@ -1031,9 +1030,9 @@ static function get_including_deleted($class, $filter = "", $sort = "") {
*/
static function get_version($class, $id, $version) {
$baseClass = ClassInfo::baseDataClass($class);
- $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version);
- $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
- return $list->First();
+ $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version);
+ $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
+ return $list->First();
}
/**
@@ -1041,10 +1040,10 @@ static function get_version($class, $id, $version) {
* @return DataList
*/
static function get_all_versions($class, $id) {
- $baseClass = ClassInfo::baseDataClass($class);
- $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
- $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
- return $list;
+ $baseClass = ClassInfo::baseDataClass($class);
+ $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
+ $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
+ return $list;
}
function contentcontrollerInit($controller) {
View
8 security/Group.php
@@ -68,7 +68,7 @@ public function getCMSFields() {
new TextField("Title", $this->fieldLabel('Title')),
$parentidfield = DropdownField::create( 'ParentID',
$this->fieldLabel('Parent'),
- DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
+ Group::get()->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
)->setEmptyString(' ')
),
@@ -240,7 +240,7 @@ public function Members($filter = "", $sort = "", $join = "", $limit = "") {
// Filters are conjunctive in DataQuery by default, so this filter would otherwise overrule any less specific ones.
$result->dataQuery()->removeFilterOn('Group_Members');
// 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);
if($join) $result = $result->join($join);
@@ -257,7 +257,7 @@ public function DirectMembers() {
public static function map($filter = "", $sort = "", $blank="") {
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();
if($blank) $map->unshift(0, $blank);
@@ -284,7 +284,7 @@ public function collateFamilyIDs() {
// Get the children of *all* the groups identified in the previous chunk.
// 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;
View
6 security/Member.php
@@ -963,7 +963,7 @@ public function DirectGroups() {
public static function map($filter = "", $sort = "", $blank="") {
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();
if($blank) $map->unshift(0, $blank);
@@ -1062,7 +1062,7 @@ public static function mapInCMSGroups($groups = null) {
? "\"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", "\"Group\".\"ID\"=\"GroupID\"")
->map();
@@ -1148,7 +1148,7 @@ public function getCMSFields() {
$fields->removeByName('Groups');
if(Permission::check('EDIT_PERMISSIONS')) {
- $groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
+ $groupsMap = Group::get()->map('ID', 'Breadcrumbs')->toArray();
asort($groupsMap);
$fields->addFieldToTab('Root.Main',
ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())
View
8 tests/forms/GridFieldTest.php
@@ -69,7 +69,7 @@ public function testGridFieldSetCustomConfig() {
* @covers GridField::setModelClass
*/
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');
$obj->setModelClass('DataModel');
$this->assertEquals('DataModel', $obj->getModelClass(), 'Should return Member');
@@ -89,7 +89,7 @@ public function testGridFieldModelClassThrowsException() {
* @covers GridField::getList
*/
public function testSetAndGetList() {
- $list = DataList::create('Member');
+ $list = Member::get();
$arrayList = ArrayList::create(array(1,2,3));
$obj = new GridField('testfield', 'testfield', $list);
$this->assertEquals($list, $obj->getList());
@@ -110,7 +110,7 @@ public function testGetState() {
* @covers GridField::getColumns
*/
public function testGetColumns(){
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$expected = array (
0 => 'FirstName',
1 => 'Surname',
@@ -123,7 +123,7 @@ public function testGetColumns(){
* @covers GridField::getColumnCount
*/
public function testGetColumnCount() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$this->assertEquals(3, $obj->getColumnCount());
}
View
6 tests/forms/gridfield/GridFieldDataColumnsTest.php
@@ -5,7 +5,7 @@ class GridFieldDataColumnsTest extends SapphireTest {
* @covers GridFieldDataColumns::getDisplayFields
*/
public function testGridFieldGetDefaultDisplayFields() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$expected = singleton('Member')->summaryFields();
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
$this->assertEquals($expected, $columns->getDisplayFields($obj));
@@ -16,7 +16,7 @@ public function testGridFieldGetDefaultDisplayFields() {
* @covers GridFieldDataColumns::getDisplayFields
*/
public function testGridFieldCustomDisplayFields() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$expected = array('Email' => 'Email');
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields($expected);
@@ -29,7 +29,7 @@ public function testGridFieldCustomDisplayFields() {
*/
public function testGridFieldDisplayFieldsWithBadArguments() {
$this->setExpectedException('InvalidArgumentException');
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(new stdClass());
}
View
14 tests/forms/gridfield/GridFieldDetailFormTest.php
@@ -11,7 +11,7 @@ class GridFieldDetailFormTest extends FunctionalTest {
function testAddForm() {
$this->logInWithPermission('ADMIN');
- $group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
+ $group = GridFieldDetailFormTest_PeopleGroup::get()
->filter('Name', 'My Group')
->sort('Name')
->First();
@@ -40,7 +40,7 @@ function testAddForm() {
);
$this->assertFalse($response->isError());
- $group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
+ $group = GridFieldDetailFormTest_PeopleGroup::get()
->filter('Name', 'My Group')
->sort('Name')
->First();
@@ -69,7 +69,7 @@ public function testViewForm() {
function testEditForm() {
$this->logInWithPermission('ADMIN');
- $group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
+ $group = GridFieldDetailFormTest_PeopleGroup::get()
->filter('Name', 'My Group')
->sort('Name')
->First();
@@ -99,7 +99,7 @@ function testEditForm() {
);
$this->assertFalse($response->isError());
- $group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
+ $group = GridFieldDetailFormTest_PeopleGroup::get()
->filter('Name', 'My Group')
->sort('Name')
->First();
@@ -249,7 +249,7 @@ class GridFieldDetailFormTest_Controller extends Controller implements TestOnly
protected $template = 'BlankPage';
function Form() {
- $group = DataList::create('GridFieldDetailFormTest_PeopleGroup')
+ $group = GridFieldDetailFormTest_PeopleGroup::get()
->filter('Name', 'My Group')
->sort('Name')
->First();
@@ -269,7 +269,7 @@ class GridFieldDetailFormTest_GroupController extends Controller implements Test
protected $template = 'BlankPage';
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(new GridFieldToolbarHeader());
$field->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
@@ -279,4 +279,4 @@ function Form() {
}
class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly {
-}
+}
View
112 tests/model/DataListTest.php
@@ -18,22 +18,22 @@ class DataListTest extends SapphireTest {
);
public function testSubtract(){
- $subtractList = DataList::create("DataObjectTest_TeamComment")->filter('ID',1);
- $fullList = DataList::create("DataObjectTest_TeamComment");
+ $subtractList = DataObjectTest_TeamComment::get()->filter('ID', 1);
+ $fullList = DataObjectTest_TeamComment::get();
$newList = $fullList->subtract($subtractList);
$this->assertEquals(2, $newList->Count(), 'List should only contain two objects after subtraction');
}
public function testSubtractBadDataclassThrowsException(){
$this->setExpectedException('InvalidArgumentException');
- $teamsComments = DataList::create("DataObjectTest_TeamComment");
- $teams = DataList::create("DataObjectTest_Team");
+ $teamsComments = DataObjectTest_TeamComment::get();
+ $teams = DataObjectTest_Team::get();
$teamsComments->subtract($teams);
}
function testListCreationSortAndLimit() {
// 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
$names = array();
@@ -54,37 +54,37 @@ function testListCreationSortAndLimit() {
}
function testDataClass() {
- $list = DataList::create('DataObjectTest_TeamComment');
+ $list = DataObjectTest_TeamComment::get();
$this->assertEquals('DataObjectTest_TeamComment',$list->dataClass());
}
function testClone() {
- $list = DataList::create('DataObjectTest_TeamComment');
+ $list = DataObjectTest_TeamComment::get();
$this->assertEquals($list, clone($list));
}
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"';
$this->assertEquals($expected, $list->sql());
}
function testInnerJoin() {
- $list = DataList::create('DataObjectTest_TeamComment');
+ $list = DataObjectTest_TeamComment::get();
$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"';
$this->assertEquals($expected, $list->sql());
}
function testLeftJoin() {
- $list = DataList::create('DataObjectTest_TeamComment');
+ $list = DataObjectTest_TeamComment::get();
$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"';
$this->assertEquals($expected, $list->sql());
}
function testToNestedArray() {
- $list = DataList::create('DataObjectTest_TeamComment')->sort('ID');
+ $list = DataObjectTest_TeamComment::get()->sort('ID');
$nestedArray = $list->toNestedArray();
$expected = array(
0=>
@@ -116,7 +116,7 @@ function testToNestedArray() {
}
function testMap() {
- $map = DataList::create('DataObjectTest_TeamComment')->map()->toArray();
+ $map = DataObjectTest_TeamComment::get()->map()->toArray();
$expected = array(
$this->idFromFixture('DataObjectTest_TeamComment', 'comment1') => 'Joe',
$this->idFromFixture('DataObjectTest_TeamComment', 'comment2') => 'Bob',
@@ -124,7 +124,7 @@ function testMap() {
);
$this->assertEquals($expected, $map);
- $otherMap = DataList::create('DataObjectTest_TeamComment')->map('Name', 'TeamID')->toArray();
+ $otherMap = DataObjectTest_TeamComment::get()->map('Name', 'TeamID')->toArray();
$otherExpected = array(
'Joe' => $this->objFromFixture('DataObjectTest_TeamComment', 'comment1')->TeamID,
'Bob' => $this->objFromFixture('DataObjectTest_TeamComment', 'comment2')->TeamID,
@@ -141,7 +141,7 @@ function testFilter() {
function testWhere() {
// We can use raw SQL queries with where. This is only recommended for advanced uses;
// 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.
$list2 = $list->where('"Name" = \'Joe\'');
@@ -158,7 +158,7 @@ function testWhere() {
function testByID() {
// We can get a single item by ID.
$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
$this->assertInstanceOf('DataObjectTest_Team', $team);
@@ -169,7 +169,7 @@ function testByID() {
* Test DataList->removeByID()
*/
function testRemoveByID() {
- $list = DataList::create("DataObjectTest_Team");
+ $list = DataObjectTest_TeamComment::get();
$id = $this->idFromFixture('DataObjectTest_Team','team2');
$this->assertNotNull($list->byID($id));
@@ -182,18 +182,18 @@ function testRemoveByID() {
*/
function testCanSortBy() {
// Basic check
- $team = DataList::create("DataObjectTest_Team");
+ $team = DataObjectTest_Team::get();
$this->assertTrue($team->canSortBy("Title"));
$this->assertFalse($team->canSortBy("SomethingElse"));
// Subclasses
- $subteam = DataList::create("DataObjectTest_SubTeam");
+ $subteam = DataObjectTest_SubTeam::get();
$this->assertTrue($subteam->canSortBy("Title"));
$this->assertTrue($subteam->canSortBy("SubclassDatabaseField"));
}
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
$this->assertEquals("Subteam 1", $list[0]->Title);
@@ -202,13 +202,13 @@ function testDataListArrayAccess() {
}
function testFind() {
- $list = DataList::create("DataObjectTest_Team");
+ $list = DataObjectTest_Team::get();
$record = $list->find('Title', 'Team 1');
$this->assertEquals($this->idFromFixture('DataObjectTest_Team', 'team1'), $record->ID);
}
function testFindById() {
- $list = DataList::create("DataObjectTest_Team");
+ $list = DataObjectTest_Team::get();
$record = $list->find('ID', $this->idFromFixture('DataObjectTest_Team', 'team1'));
$this->assertEquals('Team 1', $record->Title);
// Test that you can call it twice on the same list
@@ -217,63 +217,63 @@ function testFindById() {
}
public function testSimpleSort() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name');
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
}
public function testSimpleSortOneArgumentASC() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name ASC');
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
}
public function testSimpleSortOneArgumentDESC() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name DESC');
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
}
public function testSortOneArgumentMultipleColumns() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('TeamID ASC, Name DESC');
$this->assertEquals('Joe', $list->first()->Name, 'First comment should be from Bob');
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
}
public function testSimpleSortASC() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name', 'asc');
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
}
public function testSimpleSortDESC() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name', 'desc');
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
}
public function testSortWithArraySyntaxSortASC() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort(array('Name'=>'asc'));
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
}
public function testSortWithArraySyntaxSortDESC() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort(array('Name'=>'desc'));
$this->assertEquals('Phil', $list->first()->Name, 'Last comment should be from Phil');
$this->assertEquals('Bob', $list->last()->Name, 'First comment should be from Bob');
}
public function testSortWithMultipleArraySyntaxSort() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort(array('TeamID'=>'asc','Name'=>'desc'));
$this->assertEquals('Joe', $list->first()->Name, 'First comment should be from Bob');
$this->assertEquals('Phil', $list->last()->Name, 'Last comment should be from Phil');
@@ -283,7 +283,7 @@ public function testSortWithMultipleArraySyntaxSort() {
* $list->filter('Name', 'bob'); // only bob in the list
*/
public function testSimpleFilter() {
- $list = DataList::create("DataObjectTest_Team");
+ $list = DataObjectTest_Team::get();
$list->filter('Title','Team 2');
$this->assertEquals(1, $list->count());
$this->assertEquals('Team 2', $list->first()->Title, 'List should only contain Team 2');
@@ -291,28 +291,28 @@ public function testSimpleFilter() {
}
public function testSimpleFilterEndsWith() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('Name:EndsWith', 'b');
$this->assertEquals(1, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
}
public function testSimpleFilterExactMatchFilter() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('Name:ExactMatch', 'Bob');
$this->assertEquals(1, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
}
public function testSimpleFilterGreaterThanFilter() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('TeamID:GreaterThan', $this->idFromFixture('DataObjectTest_Team', 'team1'));
$this->assertEquals(1, $list->count());
$this->assertEquals('Phil', $list->first()->Name, 'First comment should be from Bob');
}
// public function testSimpleFilterLessThanFilter() {
- // $list = DataList::create("DataObjectTest_TeamComment");
+ // $list = DataObjectTest_TeamComment::get();
// $list = $list->filter('TeamID:LessThan', $this->idFromFixture('DataObjectTest_TeamComment', 'comment2'))->sort('Name');
// $this->assertEquals(2, $list->count());
// $this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
@@ -320,14 +320,14 @@ public function testSimpleFilterGreaterThanFilter() {
// }
public function testSimpleNegationFilter() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('TeamID:Negation', $this->idFromFixture('DataObjectTest_Team', 'team1'));
$this->assertEquals(1, $list->count());
$this->assertEquals('Phil', $list->first()->Name, 'First comment should be from Bob');
}
public function testSimplePartialMatchFilter() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('Name:PartialMatch', 'o')->sort('Name');
$this->assertEquals(2, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
@@ -335,7 +335,7 @@ public function testSimplePartialMatchFilter() {
}
public function testSimpleFilterStartsWith() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('Name:StartsWith', 'B');
$this->assertEquals(1, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
@@ -343,7 +343,7 @@ public function testSimpleFilterStartsWith() {
public function testSimpleFilterWithNonExistingComparisator() {
$this->setExpectedException('InvalidArgumentException');
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('Comment:Bogus', 'team comment');
}
@@ -351,7 +351,7 @@ public function testSimpleFilterWithNonExistingComparisator() {
* $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
*/
public function testSimpleFilterWithMultiple() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter('Name', array('Bob','Phil'));
$this->assertEquals(2, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
@@ -359,7 +359,7 @@ public function testSimpleFilterWithMultiple() {
}
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'));
$this->assertEquals(0, $list->count());
}
@@ -368,20 +368,20 @@ public function testMultipleFilterWithNoMatch() {
* $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
*/
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'));
$this->assertEquals(1, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'Only comment should be from Bob');
}
public function testFilterMultipleWithTwoMatches() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter(array('TeamID'=>$this->idFromFixture('DataObjectTest_Team', 'team1')));
$this->assertEquals(2, $list->count());
}
public function testFilterMultipleWithArrayFilter() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->filter(array('Name'=>array('Bob','Phil')));
$this->assertEquals(2, $list->count(), 'There should be two comments');
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
@@ -392,7 +392,7 @@ public function testFilterMultipleWithArrayFilter() {
* $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
*/
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'))));
$this->assertEquals(1, $list->count(), 'There should be one comments');
$this->assertEquals('Bob', $list->first()->Name, 'Only comment should be from Bob');
@@ -402,7 +402,7 @@ public function testFilterArrayInArray() {
* $list->exclude('Name', 'bob'); // exclude bob from list
*/
public function testSimpleExclude() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->exclude('Name', 'Bob');
$list->sort('Name');
$this->assertEquals(2, $list->count());
@@ -414,7 +414,7 @@ public function testSimpleExclude() {
* $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
*/
public function testSimpleExcludeWithMultiple() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->exclude('Name', array('Joe','Phil'));
$this->assertEquals(1, $list->count());
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
@@ -424,7 +424,7 @@ public function testSimpleExcludeWithMultiple() {
* $list->exclude(array('Name'=>'bob, 'Age'=>21)); // negative version
*/
public function testMultipleExcludeWithMiss() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->exclude(array('Name'=>'Bob', 'Comment'=>'Does not match any comments'));
$this->assertEquals(3, $list->count());
}
@@ -433,7 +433,7 @@ public function testMultipleExcludeWithMiss() {
* $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
*/
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'));
$this->assertEquals(2, $list->count());
}
@@ -442,7 +442,7 @@ public function testMultipleExclude() {
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
*/
public function testMultipleExcludeWithMultipleThatCheersEitherTeam() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->exclude(array('Name'=>'Bob', 'TeamID'=>array(
$this->idFromFixture('DataObjectTest_Team', 'team1'),
$this->idFromFixture('DataObjectTest_Team', 'team2')
@@ -457,7 +457,7 @@ public function testMultipleExcludeWithMultipleThatCheersEitherTeam() {
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // negative version
*/
public function testMultipleExcludeWithMultipleThatCheersOnNonExistingTeam() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->exclude(array('Name'=>'Bob', 'TeamID'=>array(3)));
$this->assertEquals(3, $list->count());
}
@@ -466,7 +466,7 @@ public function testMultipleExcludeWithMultipleThatCheersOnNonExistingTeam() {
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); //negative version
*/
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'));
$this->assertEquals(3, $list->count());
}
@@ -475,7 +475,7 @@ public function testMultipleExcludeWithNoExclusion() {
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
*/
public function testMultipleExcludeWithTwoArray() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->exclude(array('Name' => array('Bob','Joe'), 'TeamID' => array(
$this->idFromFixture('DataObjectTest_Team', 'team1'),
$this->idFromFixture('DataObjectTest_Team', 'team2')
@@ -488,7 +488,7 @@ public function testMultipleExcludeWithTwoArray() {
* $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
*/
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->sort('Name');
$this->assertEquals(2, $list->count());
@@ -500,7 +500,7 @@ public function testMultipleExcludeWithTwoArrayOneTeam() {
*
*/
public function testSortByRelation() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list = $list->sort(array('Team.Title' => 'DESC'));
$this->assertEquals(3, $list->count());
$this->assertEquals($this->idFromFixture('DataObjectTest_Team', 'team2'), $list->first()->TeamID, 'First comment should be for Team 2');
@@ -508,7 +508,7 @@ public function testSortByRelation() {
}
public function testReverse() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name');
$list->reverse();
View
2  tests/model/ManyManyListTest.php
@@ -85,7 +85,7 @@ public function testAddingWithMultipleForeignKeys() {
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
$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);
$this->assertEquals(
array($team1->ID, $team2->ID),
View
18 tests/model/MapTest.php
@@ -17,14 +17,14 @@ class SS_MapTest extends SapphireTest {
);
function testArrayAccess() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$map = new SS_Map($list, 'Name', 'Comment');
$this->assertEquals('This is a team comment by Joe', $map['Joe']);
$this->assertNull($map['DoesntExist']);
}
function testIteration() {
- $list = DataList::create("DataObjectTest_TeamComment")->sort('ID');
+ $list = DataObjectTest_TeamComment::get()->sort('ID');
$map = new SS_Map($list, 'Name', 'Comment');
$text = "";
foreach($map as $k => $v) {
@@ -36,13 +36,13 @@ function testIteration() {
}
function testDefaultConfigIsIDAndTitle() {
- $list = DataList::create("DataObjectTest_Team");
+ $list = DataObjectTest_Team::get();
$map = new SS_Map($list);
$this->assertEquals('Team 1', $map[$this->idFromFixture('DataObjectTest_Team', 'team1')]);
}
function testSetKeyFieldAndValueField() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$map = new SS_Map($list);
$map->setKeyField('Name');
$map->setValueField('Comment');
@@ -50,7 +50,7 @@ function testSetKeyFieldAndValueField() {
}
function testToArray() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$map = new SS_Map($list, 'Name', 'Comment');
$this->assertEquals(array("Joe" => "This is a team comment by Joe",
"Bob" => "This is a team comment by Bob",
@@ -58,7 +58,7 @@ function testToArray() {
}
function testKeys() {
- $list = DataList::create('DataObjectTest_TeamComment');
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name');
$map = new SS_Map($list, 'Name', 'Comment');
$this->assertEquals(array(
@@ -69,7 +69,7 @@ function testKeys() {
}
function testMethodAsValueField() {
- $list = DataList::create('DataObjectTest_Team');
+ $list = DataObjectTest_Team::get();
$list->sort('Title');
$map = new SS_Map($list, 'ID', 'MyTitle');
$this->assertEquals(array(
@@ -83,7 +83,7 @@ function testMethodAsValueField() {
}
function testValues() {
- $list = DataList::create('DataObjectTest_TeamComment');
+ $list = DataObjectTest_TeamComment::get();
$list->sort('Name');
$map = new SS_Map($list, 'Name', 'Comment');
$this->assertEquals(array(
@@ -94,7 +94,7 @@ function testValues() {
}
function testUnshift() {
- $list = DataList::create("DataObjectTest_TeamComment");
+ $list = DataObjectTest_TeamComment::get();
$map = new SS_Map($list, 'Name', 'Comment');
$map->unshift(-1, '(All)');
Please sign in to comment.
Something went wrong with that request. Please try again.