Example #1
0
 public function testImageConfiguration()
 {
     $this->resource->setResultMode(\Shopware\Components\Api\Resource\Resource::HYDRATE_OBJECT);
     $create = $this->getSimpleTestData();
     $images = $this->getEntityOffset('Shopware\\Models\\Media\\Media', 0, 1, array('id as mediaId'));
     $configurator = $this->getSimpleConfiguratorSet(1, 2);
     $variants = $this->createConfiguratorVariants($configurator['groups']);
     $usedOption = $this->getOptionsForImage($configurator, 1, 'name');
     foreach ($images as &$image) {
         $image['options'] = array($usedOption);
     }
     $create['images'] = $images;
     $create['configuratorSet'] = $configurator;
     $create['variants'] = $variants;
     $article = $this->resource->create($create);
     /**@var $image \Shopware\Models\Article\Image */
     foreach ($article->getImages() as $image) {
         $this->assertCount(1, $image->getMappings());
         /**@var $mapping \Shopware\Models\Article\Image\Mapping */
         foreach ($image->getMappings() as $mapping) {
             $this->assertCount(1, $mapping->getRules());
         }
     }
     $this->resource->generateVariantImages($article->getId());
     $article = $this->resource->getOne($article->getId());
     /**@var $variant \Shopware\Models\Article\Detail */
     foreach ($article->getDetails() as $variant) {
         foreach ($variant->getConfiguratorOptions() as $option) {
             if ($option->getName() == $usedOption[0]['name']) {
                 $this->assertCount(1, $variant->getImages());
             }
         }
     }
 }