/** * Add category by path * * @param mixed $path Path * * @return \XLite\Model\Category */ protected function addCategoryByPath($path) { if (!is_array($path)) { $path = array_map('trim', explode('>>>', $path)); } $category = $this->getCategoryByPath($path); if (!$category) { $category = new \XLite\Model\Category(); $this->categoriesCache[implode('/', $path)] = $category; $category->setName(array_pop($path)); $category->setParent($this->addCategoryByPath($path)); \XLite\Core\Database::getRepo('XLite\\Model\\Category')->insert($category); } return $category; }
public function testGetSiblings() { $p = \XLite\Core\Database::getRepo('XLite\\Model\\Category')->find(1); $c1 = new \XLite\Model\Category(); $c1->map($this->categoryData); $p->addChildren($c1); $c2 = new \XLite\Model\Category(); $c2->map($this->categoryData); $p->addChildren($c2); $em = \XLite\Core\Database::getEM(); $em->flush(); $found = false; foreach ($c1->getSiblings() as $s) { if ($s->getCategoryId() == $c2->getCategoryId()) { $found = true; } } $this->assertTrue($found, 'sibling category is not found'); $em->remove($c1); $em->remove($c2); $em->flush(); }