Пример #1
0
 public function testMultiSortArrayItems()
 {
     $this->assertCount(0, ObjectUtils::multiSort($this->_provideCollection(0, '_provideArray'), 'id'));
     $collection = $this->_provideCollection(125, '_provideArray');
     $collectionNamed = ObjectUtils::keyExplode($collection, 'name');
     $this->assertCount(count($collection), ObjectUtils::multiSort($collection, 'id'));
     $this->assertTrue(ArrayUtils::isCollection(ObjectUtils::multiSort($collectionNamed, 'id')));
     // make sure the same order
     $this->assertEquals($collection->toArray(), ObjectUtils::multiSort($collection, 'id'));
     // make sure proper order
     $collection = $this->_provideCollection(5, '_provideArray');
     $sortedCollection = ObjectUtils::multiSort($collection, 'categoryId');
     $this->assertEquals(array(5, 1, 2, 3, 4), ObjectUtils::keyFilter($sortedCollection, 'id'));
     $sortedCollection = ObjectUtils::multiSort($collection, 'categoryId', true);
     $this->assertEquals(array(4, 3, 2, 1, 5), ObjectUtils::keyFilter($sortedCollection, 'id'));
     $sortedCollection = ObjectUtils::multiSort($collection, 'date');
     $this->assertEquals(array(1, 2, 3, 4, 5), ObjectUtils::keyFilter($sortedCollection, 'id'));
     $sortedCollection = ObjectUtils::multiSort($collection, 'date', true);
     $this->assertEquals(array(5, 4, 3, 2, 1), ObjectUtils::keyFilter($sortedCollection, 'id'));
 }