function it_returns_null_if_category_is_not_found(Category $category, $entityRepository, $mappingCollection)
 {
     $entityRepository->findOneBy(['category' => $category, 'magentoUrl' => ''])->willReturn(null);
     $mappingCollection->getTarget('colors')->willReturn('colors');
     $category->getCode()->willReturn('colors');
     $this->getIdFromCategory($category, '', $mappingCollection)->shouldReturn(null);
 }
 function it_normalizes_categories(Category $category, Category $parentCategory, $webservice, $categoryNormalizer)
 {
     $webservice->getCategoriesStatus()->willReturn([1 => ['category_id' => 1]]);
     $webservice->getStoreViewsList()->willReturn([['store_id' => 10, 'code' => 'fr_fr']]);
     $category->getParent()->willReturn($parentCategory);
     $categoryNormalizer->normalize($category, AbstractNormalizer::MAGENTO_FORMAT, Argument::any())->willReturn(['create' => [], 'update' => [], 'move' => [], 'variation' => []]);
     $this->process($category)->shouldReturn(['create' => [], 'update' => [], 'move' => [], 'variation' => []]);
 }
Ejemplo n.º 3
0
 /**
  * @param Category $category
  *
  * @throws \Exception
  */
 public function clickCategoryFilterLink($category)
 {
     $elt = $this->getElement('Categories tree')->find('css', sprintf('#node_%s a', $category->getId()));
     if (!$elt) {
         throw new \Exception(sprintf('Could not find category filter "%s".', $category->getId()));
     }
     $elt->click();
 }
 /**
  * Test related methods
  */
 public function testGuessUpdates()
 {
     $category = new Category();
     $productOne = new Product();
     $productTwo = new Product();
     $category->addProduct($productOne);
     $category->addProduct($productTwo);
     $guesser = new ContainsProductsUpdateGuesser();
     $em = $this->getEntityManagerMock();
     $updates = $guesser->guessUpdates($em, $category, UpdateGuesserInterface::ACTION_UPDATE_ENTITY);
     $this->assertEquals(2, count($updates));
     $this->assertEquals($productOne, $updates[0]);
     $this->assertEquals($productTwo, $updates[1]);
 }
 function it_returns_only_products_in_the_given_channel(ProductInterface $product1, ProductInterface $product2, Channel $channel, ArrayCollection $productCategories1, ArrayCollection $productCategories2, ArrayCollection $completenesses, Category $rootCategory, Category $category1, Category $category2, AbstractCompleteness $completeness1, AbstractCompleteness $completeness2)
 {
     $channel->getCategory()->willReturn($rootCategory);
     $channel->getId()->willReturn(2);
     $rootCategory->getId()->willReturn(1);
     $product1->getCategories()->willReturn($productCategories1);
     $product2->getCategories()->willReturn($productCategories2);
     $product1->getCompletenesses()->willReturn($completenesses);
     $product2->getCompletenesses()->willReturn($completenesses);
     $completenesses->toArray()->willReturn([$completeness1, $completeness2]);
     $completeness1->getChannel()->willReturn($channel);
     $completeness2->getChannel()->willReturn($channel);
     $completeness1->getRatio()->willReturn(100);
     $completeness2->getRatio()->willReturn(100);
     $productCategories1->toArray()->willReturn([$category1]);
     $productCategories2->toArray()->willReturn([$category2]);
     $category1->getRoot()->willReturn(1);
     $category2->getRoot()->willReturn(5);
     $this->apply($channel, [$product1, $product2])->shouldReturn([$product1]);
 }
 function it_normalizes_category_variations(Category $category, Category $parentCategory, CategoryTranslation $translation, $categoryMapping, $storeViewMapping, $categoryMappingManager)
 {
     $this->globalContext = array_merge($this->globalContext, ['magentoStoreViews' => [['code' => 'fr_fr']], 'magentoStoreView' => 'default']);
     $category->getParent()->willReturn($parentCategory);
     $category->getLabel()->willReturn('category_label');
     $category->setLocale('default_locale')->shouldBeCalled();
     $category->getTranslations()->willReturn([$translation]);
     $category->getCode()->willReturn('category_code');
     $translation->getLocale()->willReturn('fr_FR');
     $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr');
     $category->setLocale('fr_FR')->shouldBeCalled();
     $category->getLabel()->willReturn('Libélé de la catégorie');
     $categoryMappingManager->getIdFromCategory($category, 'soap_url')->willReturn(null);
     $categoryMappingManager->getIdFromCategory($parentCategory, 'soap_url', $categoryMapping)->willReturn(3);
     $categoryMapping->getTarget('category_code')->willReturn('category_code');
     $this->normalize($category, 'MagentoArray', $this->globalContext)->shouldReturn(['create' => [['magentoCategory' => ['3', ['name' => 'Libélé de la catégorie', 'is_active' => 1, 'include_in_menu' => 1, 'available_sort_by' => 1, 'default_sort_by' => 1], 'default'], 'pimCategory' => $category]], 'update' => [], 'move' => [], 'variation' => [['magentoCategory' => [null, ['name' => 'Libélé de la catégorie', 'available_sort_by' => 1, 'default_sort_by' => 1], 'fr_fr'], 'pimCategory' => $category]]]);
 }
 /**
  * {@inheritdoc}
  *
  * @return Category
  */
 protected function createEntity(array $data)
 {
     $category = new Category();
     $category->setCode($data['code']);
     foreach ($this->getLabels($data) as $locale => $label) {
         $translation = $category->getTranslation($locale);
         $translation->setLabel($label);
         $category->addTranslation($translation);
     }
     if ($data['parent']) {
         $parent = new Category();
         $parent->setCode($data['parent']);
         $category->setParent($parent);
     }
     return $category;
 }
 /**
  * {@inheritDoc}
  */
 public function isRoot()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'isRoot', array());
     return parent::isRoot();
 }
 /**
  * @param Category $category
  *
  * @Given /^I should be on the (category "([^"]*)") node creation page$/
  */
 public function iShouldBeOnTheCategoryNodeCreationPage(Category $category)
 {
     $expectedAddress = $this->getPage('Category node creation')->getUrl(['id' => $category->getId()]);
     $this->spin(function () use($expectedAddress) {
         $this->assertAddress($expectedAddress);
         return true;
     }, sprintf('Expected to be on the %s category node creation page. But was not', $category->getCode()));
 }
 /**
  * @param Category $category
  *
  * @Given /^I should be on the (category "([^"]*)") node creation page$/
  */
 public function iShouldBeOnTheCategoryNodeCreationPage(Category $category)
 {
     $expectedAddress = $this->getPage('Category node creation')->getUrl(array('id' => $category->getId()));
     $this->assertAddress($expectedAddress);
 }
 function it_lists_and_format_categories($manager, Category $category0, Category $category1, Category $category2)
 {
     $manager->getProductsCountInCategory(Argument::any(), false)->willReturn(5);
     $category1->getId()->willReturn(2);
     $category1->getLabel()->willReturn('Some category 1');
     $category1->hasChildren()->willReturn(false);
     $category1->isRoot()->willReturn(false);
     $category1Array = ['item' => $category1, '__children' => []];
     $category2->getId()->willReturn(3);
     $category2->getLabel()->willReturn('Some category 2');
     $category2->hasChildren()->willReturn(false);
     $category2->isRoot()->willReturn(false);
     $category2Array = ['item' => $category2, '__children' => []];
     $category0->getId()->willReturn(1);
     $category0->getLabel()->willReturn('Parent category');
     $category0->hasChildren()->willReturn(true);
     $category0->isRoot()->willReturn(false);
     $category0Array = ['item' => $category0, '__children' => [$category1Array, $category2Array]];
     $expected = [['attr' => ['id' => 'node_1'], 'data' => 'Parent category', 'state' => 'open', 'children' => [['attr' => ['id' => 'node_2'], 'data' => 'Some category 1', 'state' => 'leaf', 'children' => [], 'selectedChildrenCount' => 0], ['attr' => ['id' => 'node_3'], 'data' => 'Some category 2', 'state' => 'leaf', 'children' => [], 'selectedChildrenCount' => 0]], 'selectedChildrenCount' => 0]];
     $this->listCategoriesResponse([$category0Array], new ArrayCollection())->shouldEqualUsingJSON($expected);
 }
Ejemplo n.º 12
0
 /**
  * Create a category for testing
  *
  * @param string $code
  *
  * @return \Pim\Bundle\CatalogBundle\Entity\Category
  */
 protected function createCategory($code)
 {
     $category = new Category();
     $category->setCode($code);
     return $category;
 }
Ejemplo n.º 13
0
 /**
  * Test related method
  * Only test if getCreated return a value or null. Setter is not accessible.
  */
 public function testGetCreated()
 {
     $this->assertNull($this->category->getCreated());
 }