コード例 #1
0
 public function testFindOneByDefaultTitle()
 {
     $expectedCategory = $this->repository->getMasterCatalogRoot();
     $expectedTitle = $expectedCategory->getDefaultTitle()->getString();
     $actualCategory = $this->repository->findOneByDefaultTitle($expectedTitle);
     $this->assertInstanceOf('OroB2B\\Bundle\\CatalogBundle\\Entity\\Category', $actualCategory);
     $this->assertEquals($expectedCategory, $actualCategory);
     $this->assertEquals($expectedTitle, $actualCategory->getDefaultTitle()->getString());
     $this->assertNull($this->repository->findOneByDefaultTitle('Not existing category'));
 }
コード例 #2
0
 public function testOnPostSubmitExistingProduct()
 {
     $product = $this->createProduct(1);
     $event = $this->createEvent($product);
     $newCategory = $this->createCategory(1);
     $categoryWithProduct = $this->createCategory(2);
     $categoryWithProduct->addProduct($product);
     $this->assertCategoryAdd($event, $newCategory);
     $this->categoryRepository->expects($this->once())->method('findOneByProduct')->will($this->returnValue($categoryWithProduct));
     $this->extension->onPostSubmit($event);
     $this->assertEquals([$product], $newCategory->getProducts()->toArray());
     $this->assertEquals([], $categoryWithProduct->getProducts()->toArray());
 }
コード例 #3
0
 protected function setUp()
 {
     $this->product = new Product();
     $this->sourceProduct = new Product();
     $this->category = new Category();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->categoryRepository = $this->getMockBuilder('OroB2B\\Bundle\\CatalogBundle\\Entity\\Repository\\CategoryRepository')->disableOriginalConstructor()->getMock();
     $this->categoryRepository->expects($this->once())->method('findOneByProduct')->will($this->returnCallback(function () {
         $args = func_get_args();
         $product = $args[0];
         if ($this->category->getProducts()->contains($product)) {
             return $this->category;
         } else {
             return null;
         }
     }));
     $this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with($this->categoryClass)->will($this->returnValue($this->categoryRepository));
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->with($this->categoryClass)->will($this->returnValue($this->objectManager));
     $this->listener = new ProductDuplicateListener();
     $this->listener->setCategoryClass($this->categoryClass);
     $this->listener->setDoctrineHelper($this->doctrineHelper);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function onPostSubmit(FormEvent $event)
 {
     /** @var Product|null $product */
     $product = $event->getData();
     if (!$product) {
         return;
     }
     $form = $event->getForm();
     if (!$form->isValid()) {
         return;
     }
     /** @var Category $category */
     $category = $form->get('category')->getData();
     if (null !== $product->getId()) {
         /** @var Category $productCategory */
         $productCategory = $this->categoryRepository->findOneByProduct($product);
         if ($productCategory instanceof Category && $category !== $productCategory) {
             $productCategory->removeProduct($product);
         }
     }
     if ($category instanceof Category) {
         $category->addProduct($product);
     }
 }