예제 #1
0
 public function testJoin()
 {
     $this->assertEmpty(ArrayUtils::join(array(), array(), 'categoryId', 'category', 'id'));
     $joinedCollection = array(array('id' => 1, 'name' => 'lorem', 'categoryId' => 5, 'date' => '2013.07.08', 'category' => array('id' => 5, 'name' => 'Empty')), array('id' => 2, 'name' => 'ipsum', 'categoryId' => 3, 'date' => '2013.07.07', 'category' => array('id' => 3, 'name' => 'Dolor sit')), array('id' => 5, 'name' => 'dolor', 'categoryId' => 1, 'date' => '2012.07.08', 'category' => array('id' => 1, 'name' => 'Lorem')), array('id' => 6, 'name' => 'sit', 'categoryId' => 3, 'date' => '2013.12.08', 'category' => array('id' => 3, 'name' => 'Dolor sit')), array('id' => 9, 'name' => 'amet', 'categoryId' => 5, 'date' => '2013.10.14', 'category' => array('id' => 5, 'name' => 'Empty')));
     $this->assertEquals(ArrayUtils::join($this->_getArrayPreset('2D_collection_5'), $this->_getArrayPreset('2D_collection_categories'), 'categoryId', 'category', 'id'), $joinedCollection);
     // make sure that keys stay intact
     $this->assertEquals(array_keys(ArrayUtils::join($this->_getArrayPreset('2D_collection_5_named'), $this->_getArrayPreset('2D_collection_categories'), 'categoryId', 'category', 'id')), array_keys($this->_getArrayPreset('2D_collection_5_named')));
     $categories = $this->_getArrayPreset('2D_collection_categories');
     unset($categories[4]);
     $this->assertCount(3, ArrayUtils::join($this->_getArrayPreset('2D_collection_5'), $categories, 'categoryId', 'category', 'id', ArrayUtils::JOIN_INNER));
 }