Exemplo n.º 1
0
 /**
  * @depends testToggleVisibility
  */
 public function testAddContent(ProductModel $product)
 {
     $contents = $product->getProductAssociatedContents();
     $this->assertEquals(0, count($contents));
     $content = ContentQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     $event = new ProductAddContentEvent($product, $content->getId());
     $event->setDispatcher($this->getDispatcher());
     $action = new Product();
     $action->addContent($event);
     $product->clearProductAssociatedContents();
     $newContents = $product->getProductAssociatedContents();
     $this->assertEquals(1, count($newContents));
     return $product;
 }
Exemplo n.º 2
0
 public function addContent(ProductAddContentEvent $event)
 {
     if (ProductAssociatedContentQuery::create()->filterByContentId($event->getContentId())->filterByProduct($event->getProduct())->count() <= 0) {
         $content = new ProductAssociatedContent();
         $content->setDispatcher($event->getDispatcher())->setProduct($event->getProduct())->setContentId($event->getContentId())->save();
     }
 }