当前位置: 首页>>代码示例>>PHP>>正文


PHP DataObjectSet::Last方法代码示例

本文整理汇总了PHP中DataObjectSet::Last方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectSet::Last方法的具体用法?PHP DataObjectSet::Last怎么用?PHP DataObjectSet::Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataObjectSet的用法示例。


在下文中一共展示了DataObjectSet::Last方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testIterator

 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());
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:46,代码来源:DataObjectSetTest.php

示例2: testSort

 /**
  * 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');
 }
开发者ID:hamishcampbell,项目名称:silverstripe-sapphire,代码行数:19,代码来源:DataObjectSetTest.php


注:本文中的DataObjectSet::Last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。