Example #1
0
 public function testChildCategoryAccessors()
 {
     $category = new Category();
     $this->assertEmpty($category->getChildCategories()->toArray());
     $firstCategory = new Category();
     $firstCategory->setLevel(1);
     $secondCategory = new Category();
     $secondCategory->setLevel(2);
     $category->addChildCategory($firstCategory)->addChildCategory($secondCategory)->addChildCategory($secondCategory);
     $this->assertEquals([$firstCategory, $secondCategory], array_values($category->getChildCategories()->toArray()));
     $category->removeChildCategory($firstCategory)->removeChildCategory($firstCategory);
     $this->assertEquals([$secondCategory], array_values($category->getChildCategories()->toArray()));
 }
 /**
  * @param Category $root
  * @param array $categories
  */
 protected function addCategories(Category $root, array $categories)
 {
     if (!$categories) {
         return;
     }
     foreach ($categories as $title => $nestedCategories) {
         $categoryTitle = new LocalizedFallbackValue();
         $categoryTitle->setString($title);
         $category = new Category();
         $category->addTitle($categoryTitle);
         $root->addChildCategory($category);
         $this->addCategories($category, $nestedCategories);
     }
 }