silverstripe-framework/tests/model/DataObjectSetTest.php

436 lines
14 KiB
PHP
Raw Normal View History

<?php
/**
* Test the {@link DataObjectSet} class.
*
* @package sapphire
* @subpackage tests
*/
class DataObjectSetTest extends SapphireTest {
static $fixture_file = 'DataObjectSetTest.yml';
protected $extraDataObjects = array(
'DataObjectTest_Team',
'DataObjectTest_SubTeam',
'DataObjectTest_Player',
'DataObjectSetTest_TeamComment',
'DataObjectSetTest_Base',
'DataObjectSetTest_ChildClass',
);
function testArrayAccessExists() {
$set = new DataObjectSet(array(
$one = new DataObject(array('Title' => 'one')),
$two = new DataObject(array('Title' => 'two')),
$three = new DataObject(array('Title' => 'three'))
));
$this->assertEquals(count($set), 3);
$this->assertTrue(isset($set[0]), 'First item in the set is set');
$this->assertEquals($one, $set[0], 'First item in the set is accessible by array notation');
}
function testArrayAccessUnset() {
$set = new DataObjectSet(array(
$one = new DataObject(array('Title' => 'one')),
$two = new DataObject(array('Title' => 'two')),
$three = new DataObject(array('Title' => 'three'))
));
unset($set[0]);
$this->assertEquals(count($set), 2);
}
function testArrayAccessSet() {
$set = new DataObjectSet();
$this->assertEquals(0, count($set));
$set['testing!'] = $test = new DataObject(array('Title' => 'I\'m testing!'));
$this->assertEquals($test, $set['testing!'], 'Set item is accessible by the key we set it as');
}
function testIterator() {
$set = new DataObjectSet(array(
$one = new DataObject(array('Title'=>'one')),
$two = new DataObject(array('Title'=>'two')),
$three = new DataObject(array('Title'=>'three')),
$four = new DataObject(array('Title'=>'four'))
));
// test Pos() with foreach()
$i = 0;
foreach($set as $item) {
$i++;
$this->assertEquals($i, $item->Pos(), "Iterator position is set correctly on ViewableData when iterated with foreach()");
}
// test Pos() manually
$this->assertEquals(1, $one->Pos());
$this->assertEquals(2, $two->Pos());
$this->assertEquals(3, $three->Pos());
$this->assertEquals(4, $four->Pos());
// test DataObjectSet->Count()
$this->assertEquals(4, $set->Count());
// test DataObjectSet->First()
$this->assertSame($one, $set->First());
// test DataObjectSet->Last()
$this->assertSame($four, $set->Last());
// test ViewableData->First()
$this->assertTrue($one->First());
$this->assertFalse($two->First());
$this->assertFalse($three->First());
$this->assertFalse($four->First());
// test ViewableData->Last()
$this->assertFalse($one->Last());
$this->assertFalse($two->Last());
$this->assertFalse($three->Last());
$this->assertTrue($four->Last());
// test ViewableData->Middle()
$this->assertFalse($one->Middle());
$this->assertTrue($two->Middle());
$this->assertTrue($three->Middle());
$this->assertFalse($four->Middle());
// test ViewableData->Even()
$this->assertFalse($one->Even());
$this->assertTrue($two->Even());
$this->assertFalse($three->Even());
$this->assertTrue($four->Even());
// test ViewableData->Odd()
$this->assertTrue($one->Odd());
$this->assertFalse($two->Odd());
$this->assertTrue($three->Odd());
$this->assertFalse($four->Odd());
}
public function testMultipleOf() {
$comments = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
$commArr = $comments->toArray();
$multiplesOf3 = 0;
foreach($comments as $comment) {
if($comment->MultipleOf(3)) {
$comment->IsMultipleOf3 = true;
$multiplesOf3++;
} else {
$comment->IsMultipleOf3 = false;
}
}
$this->assertEquals(1, $multiplesOf3);
$this->assertFalse($commArr[0]->IsMultipleOf3);
$this->assertFalse($commArr[1]->IsMultipleOf3);
$this->assertTrue($commArr[2]->IsMultipleOf3);
foreach($comments as $comment) {
if($comment->MultipleOf(3, 1)) {
$comment->IsMultipleOf3 = true;
} else {
$comment->IsMultipleOf3 = false;
}
}
$this->assertFalse($commArr[0]->IsMultipleOf3);
$this->assertFalse($commArr[1]->IsMultipleOf3);
$this->assertTrue($commArr[2]->IsMultipleOf3);
}
/**
* Test {@link DataObjectSet->Count()}
*/
function testCount() {
$comments = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
/* There are a total of 8 items in the set */
Merge branch '2.4' Conflicts: cache/Cache.php cli/CliController.php core/Convert.php core/Core.php core/ManifestBuilder.php core/Object.php core/SSViewer.php core/control/ContentController.php core/control/ContentNegotiator.php core/control/FormResponse.php core/control/RequestHandler.php core/control/SilverStripeNavigatorItem.php core/i18n.php core/i18nTextCollector.php core/model/DataObjectSet.php core/model/Hierarchy.php core/model/Image.php core/model/MySQLDatabase.php core/model/SiteConfig.php core/model/SiteTree.php core/model/Translatable.php core/model/VirtualPage.php dev/Debug.php dev/SapphireTest.php dev/TestRunner.php dev/YamlFixture.php dev/install/MySQLDatabaseConfigurationHelper.php docs/en/installation/from-source.md docs/en/topics/themes.md docs/en/tutorials/4-site-search.md email/Mailer.php filesystem/File.php filesystem/Folder.php forms/ComplexTableField.php forms/CurrencyField.php forms/DateField.php forms/FieldSet.php forms/FileField.php forms/FileIFrameField.php forms/HtmlEditorConfig.php forms/HtmlEditorField.php forms/SelectionGroup.php forms/SimpleImageField.php forms/TabSet.php forms/TableField.php forms/TableListField.php forms/TreeDropdownField.php forms/TreeMultiselectField.php integration/Geoip.php javascript/SelectionGroup.js javascript/TreeSelectorField.js javascript/UpdateURL.js javascript/core/jquery.ondemand.js javascript/tiny_mce_improvements.js javascript/tree/tree.js lang/en_US.php search/ContentControllerSearchExtension.php security/Group.php security/Member.php security/PermissionCheckboxSetField.php security/PermissionRole.php security/Security.php static-main.php templates/RelationComplexTableField.ss templates/TableListField.ss tests/ConvertTest.php tests/DataObjectSetTest.php tests/DataObjectTest.php tests/DataObjectTest.yml tests/RequestHandlingTest.php tests/SSViewerTest.php tests/SiteTreePermissionsTest.php tests/SiteTreeTest.php tests/TransactionTest.php tests/api/RestfulServiceTest.php tests/control/DirectorTest.php tests/control/ModelAsControllerTest.php tests/fieldtypes/WidgetAreaEditorTest.php tests/forms/CurrencyFieldTest.php tests/forms/FormTest.php tests/model/DatabaseTest.php tests/model/ImageTest.php tests/search/ContentControllerSearchExtensionTest.php tests/security/MemberAuthenticatorTest.php thirdparty/.gitignore thirdparty/behaviour/behaviour.js thirdparty/firebug-lite/firebug.js thirdparty/firebug-lite/firebugx.js thirdparty/jquery-form/jquery.form.js thirdparty/jquery-livequery/jquery.livequery.js thirdparty/jquery-livequery/test/jquery.js thirdparty/jquery-livequery/test/test.html thirdparty/jquery-livequery/test/test2.html thirdparty/jquery-metadata/META.json thirdparty/jquery-metadata/README thirdparty/jquery-metadata/jquery.metadata.js thirdparty/jquery-metadata/test/index.html thirdparty/jquery-metadata/test/jquery.js thirdparty/jquery-metadata/test/test.js thirdparty/jquery-metadata/test/testrunner.js thirdparty/jquery-metadata/test/testsuite.css thirdparty/jquery-ui-themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png thirdparty/jquery-ui-themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png thirdparty/jquery-ui-themes/smoothness/images/ui-icons_222222_256x240.png thirdparty/jquery-ui-themes/smoothness/images/ui-icons_2e83ff_256x240.png thirdparty/jquery-ui-themes/smoothness/images/ui-icons_454545_256x240.png thirdparty/jquery-ui-themes/smoothness/images/ui-icons_888888_256x240.png thirdparty/jquery-ui-themes/smoothness/images/ui-icons_cd0a0a_256x240.png thirdparty/jquery-ui/i18n/jquery-ui-i18n.js thirdparty/jquery-ui/i18n/ui.datepicker-ar.js thirdparty/jquery-ui/i18n/ui.datepicker-bg.js thirdparty/jquery-ui/i18n/ui.datepicker-ca.js thirdparty/jquery-ui/i18n/ui.datepicker-cs.js thirdparty/jquery-ui/i18n/ui.datepicker-da.js thirdparty/jquery-ui/i18n/ui.datepicker-de.js thirdparty/jquery-ui/i18n/ui.datepicker-el.js thirdparty/jquery-ui/i18n/ui.datepicker-eo.js thirdparty/jquery-ui/i18n/ui.datepicker-es.js thirdparty/jquery-ui/i18n/ui.datepicker-fa.js thirdparty/jquery-ui/i18n/ui.datepicker-fi.js thirdparty/jquery-ui/i18n/ui.datepicker-fr.js thirdparty/jquery-ui/i18n/ui.datepicker-he.js thirdparty/jquery-ui/i18n/ui.datepicker-hr.js thirdparty/jquery-ui/i18n/ui.datepicker-hu.js thirdparty/jquery-ui/i18n/ui.datepicker-hy.js thirdparty/jquery-ui/i18n/ui.datepicker-id.js thirdparty/jquery-ui/i18n/ui.datepicker-is.js thirdparty/jquery-ui/i18n/ui.datepicker-it.js thirdparty/jquery-ui/i18n/ui.datepicker-ja.js thirdparty/jquery-ui/i18n/ui.datepicker-ko.js thirdparty/jquery-ui/i18n/ui.datepicker-lt.js thirdparty/jquery-ui/i18n/ui.datepicker-lv.js thirdparty/jquery-ui/i18n/ui.datepicker-ms.js thirdparty/jquery-ui/i18n/ui.datepicker-nl.js thirdparty/jquery-ui/i18n/ui.datepicker-no.js thirdparty/jquery-ui/i18n/ui.datepicker-pl.js thirdparty/jquery-ui/i18n/ui.datepicker-pt-BR.js thirdparty/jquery-ui/i18n/ui.datepicker-ro.js thirdparty/jquery-ui/i18n/ui.datepicker-ru.js thirdparty/jquery-ui/i18n/ui.datepicker-sk.js thirdparty/jquery-ui/i18n/ui.datepicker-sl.js thirdparty/jquery-ui/i18n/ui.datepicker-sq.js thirdparty/jquery-ui/i18n/ui.datepicker-sr-SR.js thirdparty/jquery-ui/i18n/ui.datepicker-sr.js thirdparty/jquery-ui/i18n/ui.datepicker-sv.js thirdparty/jquery-ui/i18n/ui.datepicker-th.js thirdparty/jquery-ui/i18n/ui.datepicker-tr.js thirdparty/jquery-ui/i18n/ui.datepicker-uk.js thirdparty/jquery-ui/i18n/ui.datepicker-zh-CN.js thirdparty/jquery-ui/i18n/ui.datepicker-zh-TW.js thirdparty/jquery/jquery.js thirdparty/jsmin/.piston.yml thirdparty/jsmin/jsmin.php thirdparty/prototype/prototype.js thirdparty/scriptaculous/dragdrop.js thirdparty/simplepie/.piston.yml thirdparty/spyc/.piston.yml thirdparty/spyc/README thirdparty/spyc/php4/spyc.php4 thirdparty/spyc/php4/test.php4 thirdparty/spyc/spyc.php thirdparty/spyc/spyc.yaml thirdparty/tinymce-advcode/dialog.html thirdparty/tinymce-advcode/editor_plugin_src.js thirdparty/tinymce-advcode/js/dialog.js thirdparty/tinymce/langs/en.js thirdparty/tinymce/plugins/advhr/langs/en_dlg.js thirdparty/tinymce/plugins/advhr/rule.htm thirdparty/tinymce/plugins/advimage/image.htm thirdparty/tinymce/plugins/advimage/langs/en_dlg.js thirdparty/tinymce/plugins/advlink/langs/en_dlg.js thirdparty/tinymce/plugins/advlink/link.htm thirdparty/tinymce/plugins/emotions/emotions.htm thirdparty/tinymce/plugins/emotions/langs/en_dlg.js thirdparty/tinymce/plugins/example/dialog.htm thirdparty/tinymce/plugins/fullpage/fullpage.htm thirdparty/tinymce/plugins/fullpage/langs/en_dlg.js thirdparty/tinymce/plugins/fullscreen/fullscreen.htm thirdparty/tinymce/plugins/inlinepopups/template.htm thirdparty/tinymce/plugins/media/langs/en_dlg.js thirdparty/tinymce/plugins/media/media.htm thirdparty/tinymce/plugins/paste/js/pasteword.js thirdparty/tinymce/plugins/paste/langs/en_dlg.js thirdparty/tinymce/plugins/paste/pastetext.htm thirdparty/tinymce/plugins/paste/pasteword.htm thirdparty/tinymce/plugins/searchreplace/langs/en_dlg.js thirdparty/tinymce/plugins/searchreplace/searchreplace.htm thirdparty/tinymce/plugins/spellchecker/editor_plugin.js thirdparty/tinymce/plugins/spellchecker/editor_plugin_src.js thirdparty/tinymce/plugins/style/langs/en_dlg.js thirdparty/tinymce/plugins/style/props.htm thirdparty/tinymce/plugins/table/cell.htm thirdparty/tinymce/plugins/table/langs/en_dlg.js thirdparty/tinymce/plugins/table/merge_cells.htm thirdparty/tinymce/plugins/table/row.htm thirdparty/tinymce/plugins/table/table.htm thirdparty/tinymce/plugins/template/langs/en_dlg.js thirdparty/tinymce/plugins/template/template.htm thirdparty/tinymce/plugins/xhtmlxtras/abbr.htm thirdparty/tinymce/plugins/xhtmlxtras/acronym.htm thirdparty/tinymce/plugins/xhtmlxtras/attributes.htm thirdparty/tinymce/plugins/xhtmlxtras/cite.htm thirdparty/tinymce/plugins/xhtmlxtras/del.htm thirdparty/tinymce/plugins/xhtmlxtras/ins.htm thirdparty/tinymce/plugins/xhtmlxtras/langs/en_dlg.js thirdparty/tinymce/themes/advanced/about.htm thirdparty/tinymce/themes/advanced/anchor.htm thirdparty/tinymce/themes/advanced/charmap.htm thirdparty/tinymce/themes/advanced/color_picker.htm thirdparty/tinymce/themes/advanced/image.htm thirdparty/tinymce/themes/advanced/langs/en.js thirdparty/tinymce/themes/advanced/langs/en_dlg.js thirdparty/tinymce/themes/advanced/link.htm thirdparty/tinymce/themes/advanced/source_editor.htm thirdparty/tinymce/themes/simple/langs/en.js thirdparty/tinymce/tiny_mce.js thirdparty/tinymce/tiny_mce_src.js widgets/Widget.php
2011-02-14 06:47:53 +01:00
$this->assertEquals($comments->Count(), 3, 'There are a total of 3 items in the set');
}
/**
* Test {@link DataObjectSet->First()}
*/
function testFirst() {
$comments = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
/* The first object is Joe's comment */
$this->assertEquals($comments->First()->Name, 'Joe', 'The first object has a Name field value of "Joe"');
}
/**
* Test {@link DataObjectSet->Last()}
*/
function testLast() {
$comments = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
/* The last object is Dean's comment */
$this->assertEquals($comments->Last()->Name, 'Phil', 'The last object has a Name field value of "Phil"');
}
/**
* Test {@link DataObjectSet->map()}
*/
function testMap() {
$comments = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
/* Now we get a map of all the PageComment records */
$map = $comments->map('ID', 'Title', '(Select one)');
$expectedMap = array(
'' => '(Select one)',
1 => 'Joe',
2 => 'Bob',
3 => 'Phil'
);
/* There are 9 items in the map. 3 are records. 1 is the empty value */
$this->assertEquals(count($map), 4, 'There are 4 items in the map. 3 are records. 1 is the empty value');
/* We have the same map as our expected map, asserted above */
/* toDropDownMap() is an alias of map() - let's make a map from that */
$map2 = $comments->toDropDownMap('ID', 'Title', '(Select one)');
/* There are 4 items in the map. 3 are records. 1 is the empty value */
$this->assertEquals(count($map), 4, 'There are 4 items in the map. 3 are records. 1 is the empty value.');
}
function testRemoveDuplicates() {
// Note that PageComment and DataObjectSetTest_TeamComment are both descendants of DataObject, and don't
// share an inheritance relationship below that.
$pageComments = DataObject::get('DataObjectSetTest_TeamComment');
$teamComments = DataObject::get('DataObjectSetTest_TeamComment');
/* Test default functionality (remove by ID). We'd expect to loose all our
* team comments as they have the same IDs as the first three page comments */
$allComments = new DataObjectSet();
$allComments->merge($pageComments);
$allComments->merge($teamComments);
$this->assertEquals($allComments->Count(), 6);
$allComments->removeDuplicates();
$this->assertEquals($allComments->Count(), 3, 'Standard functionality is to remove duplicate base class/IDs');
/* Now test removing duplicates based on a common field. In this case we shall
* use 'Name', so we can get all the unique commentators */
$comment = new DataObjectSetTest_TeamComment();
$comment->Name = "Bob";
$allComments->push($comment);
$this->assertEquals($allComments->Count(), 4);
$allComments->removeDuplicates('Name');
$this->assertEquals($allComments->Count(), 3, 'There are 3 uniquely named commentators');
// Ensure that duplicates are removed where the base data class is the same.
$mixedSet = new DataObjectSet();
$mixedSet->push(new DataObjectSetTest_Base(array('ID' => 1)));
$mixedSet->push(new DataObjectSetTest_ChildClass(array('ID' => 1))); // dup: same base class and ID
$mixedSet->push(new DataObjectSetTest_ChildClass(array('ID' => 1))); // dup: more than one dup of the same object
$mixedSet->push(new DataObjectSetTest_ChildClass(array('ID' => 2))); // not dup: same type again, but different
$mixedSet->push(new DataObjectSetTest_Base(array('ID' => 1))); // dup: another dup, not consequetive.
$mixedSet->removeDuplicates('ID');
$this->assertEquals($mixedSet->Count(), 2, 'There are 3 unique data objects in a very mixed set');
}
/**
* Test {@link DataObjectSet->parseQueryLimit()}
*/
function testParseQueryLimit() {
// Create empty objects, because they don't need to have contents
$sql = new SQLQuery('*', '"Member"');
$max = $sql->unlimitedRowCount();
$set = new DataObjectSet();
// Test handling an array
$set->parseQueryLimit($sql->limit(array('limit'=>5, 'start'=>2)));
$expected = array(
'pageStart' => 2,
'pageLength' => 5,
'totalSize' => $max,
);
$this->assertEquals($expected, $set->getPageLimits(), 'The page limits match expected values.');
// Test handling OFFSET string
// uppercase
$set->parseQueryLimit($sql->limit('3 OFFSET 1'));
$expected = array(
'pageStart' => 1,
'pageLength' => 3,
'totalSize' => $max,
);
$this->assertEquals($expected, $set->getPageLimits(), 'The page limits match expected values.');
// and lowercase
$set->parseQueryLimit($sql->limit('32 offset 3'));
$expected = array(
'pageStart' => 3,
'pageLength' => 32,
'totalSize' => $max,
);
$this->assertEquals($expected, $set->getPageLimits(), 'The page limits match expected values.');
// Finally check MySQL LIMIT syntax
$set->parseQueryLimit($sql->limit('7, 7'));
$expected = array(
'pageStart' => 7,
'pageLength' => 7,
'totalSize' => $max,
);
$this->assertEquals($expected, $set->getPageLimits(), 'The page limits match expected values.');
}
/**
* Test {@link DataObjectSet->insertFirst()}
*/
function testInsertFirst() {
// Get one comment
$comment = DataObject::get_one('DataObjectSetTest_TeamComment', "\"Name\" = 'Joe'");
// Get all other comments
$set = DataObject::get('DataObjectSetTest_TeamComment', '"Name" != \'Joe\'');
// Duplicate so we can use it later without another lookup
$otherSet = clone $set;
// insert without a key
$otherSet->insertFirst($comment);
$this->assertEquals($comment, $otherSet->First(), 'Comment should be first');
// Give us another copy
$otherSet = clone $set;
// insert with a numeric key
$otherSet->insertFirst($comment, 2);
$this->assertEquals($comment, $otherSet->First(), 'Comment should be first');
// insert with a non-numeric key
$set->insertFirst($comment, 'SomeRandomKey');
$this->assertEquals($comment, $set->First(), 'Comment should be first');
}
/**
* Test {@link DataObjectSet->getRange()}
*/
function testGetRange() {
$comments = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
// Make sure we got all 8 comments
$this->assertEquals($comments->Count(), 3, 'Three comments in the database.');
// Grab a range
$range = $comments->getRange(1, 2);
$this->assertEquals($range->Count(), 2, 'Two comment in the range.');
// And now grab a range that shouldn't be full. Remember counting starts at 0.
$range = $comments->getRange(2, 1);
$this->assertEquals($range->Count(), 1, 'One comment in the range.');
// Make sure it's the last one
$this->assertEquals($range->First(), $comments->Last(), 'The only item in the range should be the last one.');
}
/**
* Test {@link DataObjectSet->exists()}
*/
function testExists() {
// Test an empty set
$set = new DataObjectSet();
$this->assertFalse($set->exists(), 'Empty set doesn\'t exist.');
// Test a non-empty set
$set = DataObject::get('DataObjectSetTest_TeamComment', '', "\"ID\" ASC");
$this->assertTrue($set->exists(), 'Non-empty set does exist.');
}
/**
* Test {@link DataObjectSet->shift()}
*/
function testShift() {
$set = new DataObjectSet();
$set->push(new ArrayData(array('Name' => 'Joe')));
$set->push(new ArrayData(array('Name' => 'Bob')));
$set->push(new ArrayData(array('Name' => 'Ted')));
$this->assertEquals('Joe', $set->shift()->Name);
}
/**
* Test {@link DataObjectSet->unshift()}
*/
function testUnshift() {
$set = new DataObjectSet();
$set->push(new ArrayData(array('Name' => 'Joe')));
$set->push(new ArrayData(array('Name' => 'Bob')));
$set->push(new ArrayData(array('Name' => 'Ted')));
$set->unshift(new ArrayData(array('Name' => 'Steve')));
$this->assertEquals('Steve', $set->First()->Name);
}
/**
* Test {@link DataObjectSet->pop()}
*/
function testPop() {
$set = new DataObjectSet();
$set->push(new ArrayData(array('Name' => 'Joe')));
$set->push(new ArrayData(array('Name' => 'Bob')));
$set->push(new ArrayData(array('Name' => 'Ted')));
$this->assertEquals('Ted', $set->pop()->Name);
}
/**
* Test {@link DataObjectSet->sort()}
*/
function testSort() {
$set = new DataObjectSet(array(
array('Name'=>'Object1', 'F1'=>1, 'F2'=>2, 'F3'=>3),
array('Name'=>'Object2', 'F1'=>2, 'F2'=>1, 'F3'=>4),
array('Name'=>'Object3', 'F1'=>5, 'F2'=>2, 'F3'=>2),
));
// test a single sort ASC
$set->sort('F3', 'ASC');
$this->assertEquals($set->First()->Name, 'Object3', 'Object3 should be first in the set');
// test a single sort DESC
$set->sort('F3', 'DESC');
$this->assertEquals($set->First()->Name, 'Object2', 'Object2 should be first in the set');
// test a multi sort
$set->sort(array('F2'=>'ASC', 'F1'=>'ASC'));
$this->assertEquals($set->Last()->Name, 'Object3', 'Object3 should be last in the set');
// test a multi sort
$set->sort(array('F2'=>'ASC', 'F1'=>'DESC'));
$this->assertEquals($set->Last()->Name, 'Object1', 'Object1 should be last in the set');
}
}
/**
* @package sapphire
* @subpackage tests
*/
class DataObjectSetTest_TeamComment extends DataObject implements TestOnly {
static $db = array(
'Name' => 'Varchar',
'Comment' => 'Text',
);
static $has_one = array(
'Team' => 'DataObjectTest_Team',
);
}
class DataObjectSetTest_Base extends DataObject implements TestOnly {
static $db = array(
'Name' => 'Varchar'
);
}
class DataObjectSetTest_ChildClass extends DataObjectSetTest_Base implements TestOnly {
}