function it_dispatches_an_event_when_removing_a_tree($eventDispatcher, $objectManager, CategoryInterface $tree)
 {
     $tree->isRoot()->willReturn(true);
     $tree->getProducts()->willReturn([]);
     $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_TREE, Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled();
     $objectManager->remove($tree)->shouldBeCalled();
     $this->remove($tree, ['flush' => false]);
 }
 function it_dispatches_an_event_when_removing_a_tree($eventDispatcher, $objectManager, CategoryInterface $tree)
 {
     $tree->getId()->willReturn(12);
     $tree->isRoot()->willReturn(true);
     $tree->getProducts()->willReturn([]);
     $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_TREE, Argument::type('Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent'))->shouldBeCalled();
     $objectManager->remove($tree)->shouldBeCalled();
     $eventDispatcher->dispatch(CategoryEvents::POST_REMOVE_TREE, Argument::type('Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent'))->shouldBeCalled();
     $this->remove($tree, ['flush' => true]);
 }
 /**
  * Define the state of a category
  *
  * @param CategoryInterface $category
  * @param bool              $hasChild
  * @param array             $selectedIds
  *
  * @return string
  */
 protected function defineCategoryState(CategoryInterface $category, $hasChild = false, array $selectedIds = [])
 {
     $state = $category->hasChildren() ? 'closed' : 'leaf';
     if ($hasChild === true) {
         $state = 'open';
     }
     if (in_array($category->getId(), $selectedIds)) {
         $state .= ' toselect jstree-checked';
     }
     if ($category->isRoot()) {
         $state .= ' jstree-root';
     }
     return $state;
 }
 /**
  * Remove a category
  *
  * @param CategoryInterface $category
  */
 public function remove(CategoryInterface $category)
 {
     $eventName = $category->isRoot() ? CategoryEvents::PRE_REMOVE_TREE : CategoryEvents::PRE_REMOVE_CATEGORY;
     $this->eventDispatcher->dispatch($eventName, new GenericEvent($category));
     foreach ($category->getProducts() as $product) {
         $product->removeCategory($category);
     }
     $this->getObjectManager()->remove($category);
 }