/** * generates a folder and its contents to be used in Position tests * * @return Folder the parent folder */ protected function getFolderForPositionTest() { if (null === self::$folderForPositionTest) { $folder = new Folder(); $folder->setParent(0); $folder->setVisible(1); $folder->setPosition(1); $this->setI18n($folder); $folder->save(); for ($i = 0; $i < 4; $i++) { $content = new \Thelia\Model\Content(); $content->addFolder($folder); $content->setVisible(1); $content->setPosition($i + 1); $this->setI18n($content); $contentFolders = $content->getContentFolders(); $collection = new Collection(); $collection->prepend($contentFolders[0]->setDefaultFolder(1)); $content->setContentFolders($collection); $content->save(); } self::$folderForPositionTest = $folder; } return self::$folderForPositionTest; }
public function testPrepend() { $col = new Collection(); $this->assertEquals(1, $col->prepend('a'), 'prepend() returns 1 on an empty collection'); $data = array('bar1', 'bar2', 'bar3'); $col = new Collection($data); $this->assertEquals(4, $col->prepend('bar4'), 'prepend() returns the new number of elements in the collection when adding a variable'); $this->assertEquals(array('bar4', 'bar1', 'bar2', 'bar3'), $col->getData(), 'prepend() adds new element to the beginning of the collection'); }