Example #1
0
 /**
  * @param ProductModel $product
  * @depends testAddContent
  */
 public function testRemoveContent(ProductModel $product)
 {
     $product->clearProductAssociatedContents();
     $contents = $product->getProductAssociatedContents();
     $this->assertEquals(1, count($contents));
     $content = $contents->getFirst();
     $event = new ProductDeleteContentEvent($product, $content->getContentId());
     $event->setDispatcher($this->getDispatcher());
     $action = new Product();
     $action->removeContent($event);
     $product->clearProductAssociatedContents();
     $deletedContent = $product->getProductAssociatedContents();
     $this->assertEquals(0, count($deletedContent));
     return $product;
 }
Example #2
0
 public function removeContent(ProductDeleteContentEvent $event)
 {
     $content = ProductAssociatedContentQuery::create()->filterByContentId($event->getContentId())->filterByProduct($event->getProduct())->findOne();
     if ($content !== null) {
         $content->setDispatcher($event->getDispatcher())->delete();
     }
 }