コード例 #1
0
ファイル: StandardTest.php プロジェクト: mvnp/aimeos-core
 public function testSaveDeleteItem()
 {
     $manager = \Aimeos\MShop\Media\Manager\Factory::createManager(\TestHelperExtjs::getContext());
     $typeManager = $manager->getSubManager('type');
     $criteria = $typeManager->createSearch();
     $criteria->setSlice(0, 1);
     $result = $typeManager->searchItems($criteria);
     if (($type = reset($result)) === false) {
         throw new \Exception('No type item found');
     }
     copy(__DIR__ . '/testfiles/test.png', dirname(dirname(dirname(__DIR__))) . '/tmp/test.png');
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('media.label' => 'controller test media', 'media.domain' => 'attribute', 'media.typeid' => $type->getId(), 'media.languageid' => 'de', 'media.url' => 'test.jpg', 'media.mimetype' => 'image/jpeg', 'media.status' => 0));
     $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('media.label' => 'controller test media')))));
     $saved = $this->object->saveItems($saveParams);
     $searched = $this->object->searchItems($searchParams);
     $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'media.id'});
     $this->object->deleteItems($deleteParams);
     $result = $this->object->searchItems($searchParams);
     $this->assertInternalType('object', $saved['items']);
     $this->assertNotNull($saved['items']->{'media.id'});
     $this->assertEquals($saved['items']->{'media.id'}, $searched['items'][0]->{'media.id'});
     $this->assertEquals($saved['items']->{'media.typeid'}, $searched['items'][0]->{'media.typeid'});
     $this->assertEquals($saved['items']->{'media.domain'}, $searched['items'][0]->{'media.domain'});
     $this->assertEquals($saved['items']->{'media.languageid'}, $searched['items'][0]->{'media.languageid'});
     $this->assertEquals($saved['items']->{'media.label'}, $searched['items'][0]->{'media.label'});
     $this->assertEquals($saved['items']->{'media.url'}, $searched['items'][0]->{'media.url'});
     $this->assertEquals($saved['items']->{'media.mimetype'}, $searched['items'][0]->{'media.mimetype'});
     $this->assertEquals($saved['items']->{'media.status'}, $searched['items'][0]->{'media.status'});
     $this->assertEquals(1, count($searched['items']));
     $this->assertEquals(0, count($result['items']));
 }
コード例 #2
0
ファイル: StandardTest.php プロジェクト: nos3/aimeos-core
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->editor = \TestHelperMShop::getContext()->getEditor();
     $manager = \Aimeos\MShop\Media\Manager\Factory::createManager(\TestHelperMShop::getContext());
     $listManager = $manager->getSubManager('lists');
     $this->object = $listManager->getSubManager('type');
 }
コード例 #3
0
 /**
  * Gets required media item ids.
  *
  * @param array $keys List with referenced Ids
  * @throws \Aimeos\MW\Setup\Exception If no type ID is found
  */
 private function getMediaData(array $keys)
 {
     $mediaManager = \Aimeos\MShop\Media\Manager\Factory::createManager($this->additional, 'Standard');
     $urls = array();
     foreach ($keys as $dataset) {
         if (($pos = strpos($dataset, '/')) === false || ($str = substr($dataset, $pos + 1)) === false) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('Some keys for ref media are set wrong "%1$s"', $dataset));
         }
         $urls[] = $str;
     }
     $search = $mediaManager->createSearch();
     $search->setConditions($search->compare('==', 'media.url', $urls));
     $refIds = array();
     foreach ($mediaManager->searchItems($search) as $item) {
         $refIds['media/' . $item->getUrl()] = $item->getId();
     }
     return $refIds;
 }
コード例 #4
0
ファイル: MediaAddTestData.php プロジェクト: mvnp/aimeos-core
 /**
  * Adds the required media test data for attributes.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws \Aimeos\MW\Setup\Exception If no type ID is found
  */
 private function addMediaData(array $testdata)
 {
     $mediaManager = \Aimeos\MShop\Media\Manager\Factory::createManager($this->additional, 'Standard');
     $mediaTypeManager = $mediaManager->getSubManager('type', 'Standard');
     $mtypeIds = array();
     $mtype = $mediaTypeManager->createItem();
     $this->conn->begin();
     foreach ($testdata['media/type'] as $key => $dataset) {
         $mtype->setId(null);
         $mtype->setCode($dataset['code']);
         $mtype->setDomain($dataset['domain']);
         $mtype->setLabel($dataset['label']);
         $mtype->setStatus($dataset['status']);
         $mediaTypeManager->saveItem($mtype);
         $mtypeIds[$key] = $mtype->getId();
     }
     $media = $mediaManager->createItem();
     foreach ($testdata['media'] as $key => $dataset) {
         if (!isset($mtypeIds[$dataset['typeid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No media type ID found for "%1$s"', $dataset['typeid']));
         }
         $media->setId(null);
         $media->setLanguageId($dataset['langid']);
         $media->setTypeId($mtypeIds[$dataset['typeid']]);
         $media->setDomain($dataset['domain']);
         $media->setLabel($dataset['label']);
         $media->setUrl($dataset['link']);
         $media->setStatus($dataset['status']);
         $media->setMimeType($dataset['mimetype']);
         if (isset($dataset['preview'])) {
             $media->setPreview($dataset['preview']);
         }
         $mediaManager->saveItem($media, false);
     }
     $this->conn->commit();
 }
コード例 #5
0
ファイル: StandardTest.php プロジェクト: mvnp/aimeos-core
 /**
  * Sets up the fixture. This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->editor = \TestHelperMShop::getContext()->getEditor();
     $this->object = \Aimeos\MShop\Media\Manager\Factory::createManager(\TestHelperMShop::getContext());
 }
コード例 #6
0
 protected function delete(\Aimeos\MShop\Product\Item\Iface $product)
 {
     $mediaManager = \Aimeos\MShop\Media\Manager\Factory::createManager($this->context);
     $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context);
     $listManager = $manager->getSubManager('lists');
     foreach ($product->getListItems('media') as $listItem) {
         $mediaManager->deleteItem($listItem->getRefItem()->getId());
         $listManager->deleteItem($listItem->getId());
     }
     $manager->deleteItem($product->getId());
 }
コード例 #7
0
 protected function getListItems()
 {
     $manager = \Aimeos\MShop\Media\Manager\Factory::createManager($this->context, 'Standard');
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'media.url', 'prod_266x221/198_prod_266x221.jpg'));
     $search->setSlice(0, 1);
     $results = $manager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new \Exception('No media item found');
     }
     $search = $this->object->createSearch();
     $expr = array($search->compare('==', 'media.lists.parentid', $item->getId()), $search->compare('==', 'media.lists.domain', 'attribute'), $search->compare('==', 'media.lists.editor', $this->editor), $search->compare('==', 'media.lists.type.code', 'option'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'media.lists.position')));
     return $this->object->searchItems($search);
 }
コード例 #8
0
 /**
  * Insert media items and product/media relations.
  */
 protected function process()
 {
     $this->msg('Adding product media performance data', 0);
     $context = $this->getContext();
     $prefix = 'http://demo.aimeos.org/media/';
     $mediaManager = \Aimeos\MShop\Media\Manager\Factory::createManager($context);
     $mediaTypeManager = $mediaManager->getSubManager('type');
     $expr = array();
     $search = $mediaTypeManager->createSearch();
     $expr[] = $search->compare('==', 'media.type.domain', 'product');
     $expr[] = $search->compare('==', 'media.type.code', 'default');
     $search->setConditions($search->combine('&&', $expr));
     $types = $mediaTypeManager->searchItems($search);
     if (($mediaTypeItem = reset($types)) === false) {
         throw new \Exception('Media type item not found');
     }
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context);
     $productListManager = $productManager->getSubManager('lists');
     $productListTypeManager = $productListManager->getSubManager('type');
     $expr = array();
     $search = $productListTypeManager->createSearch();
     $expr[] = $search->compare('==', 'product.lists.type.domain', 'media');
     $expr[] = $search->compare('==', 'product.lists.type.code', 'default');
     $search->setConditions($search->combine('&&', $expr));
     $types = $productListTypeManager->searchItems($search);
     if (($productListTypeItem = reset($types)) === false) {
         throw new \Exception('Product list type item not found');
     }
     $expr = array();
     $search = $productListTypeManager->createSearch();
     $expr[] = $search->compare('==', 'product.lists.type.domain', 'media');
     $expr[] = $search->compare('==', 'product.lists.type.code', 'download');
     $search->setConditions($search->combine('&&', $expr));
     $types = $productListTypeManager->searchItems($search);
     if (($downloadListTypeItem = reset($types)) === false) {
         throw new \Exception('Product list type item not found');
     }
     $mediaItem = $mediaManager->createItem();
     $mediaItem->setTypeId($mediaTypeItem->getId());
     $mediaItem->setLanguageId(null);
     $mediaItem->setDomain('product');
     $mediaItem->setMimeType('image/jpeg');
     $mediaItem->setStatus(1);
     $downloadItem = $mediaManager->createItem();
     $downloadItem->setTypeId($mediaTypeItem->getId());
     $downloadItem->setLanguageId(null);
     $downloadItem->setDomain('product');
     $downloadItem->setMimeType('application/pdf');
     $downloadItem->setLabel('PDF download');
     $downloadItem->setPreview($prefix . 'unitperf/download-preview.jpg');
     $downloadItem->setUrl($prefix . 'unitperf/download.pdf');
     $downloadItem->setStatus(1);
     $mediaManager->saveItem($downloadItem);
     $listItem = $productListManager->createItem();
     $listItem->setTypeId($productListTypeItem->getId());
     $listItem->setDomain('media');
     $downloadListItem = $productListManager->createItem();
     $downloadListItem->setTypeId($downloadListTypeItem->getId());
     $downloadListItem->setRefId($downloadItem->getId());
     $downloadListItem->setDomain('media');
     $downloadListItem->setPosition(0);
     $search = $productManager->createSearch();
     $search->setSortations(array($search->sort('+', 'product.id')));
     $this->txBegin();
     $start = $pos = 0;
     do {
         $result = $productManager->searchItems($search);
         foreach ($result as $id => $item) {
             $mediaItem->setId(null);
             $mediaItem->setLabel('1. picture for ' . $item->getLabel());
             $mediaItem->setPreview($prefix . 'unitperf/' . (($pos + 0) % 4 + 1) . '.jpg');
             $mediaItem->setUrl($prefix . 'unitperf/' . (($pos + 0) % 4 + 1) . '-big.jpg');
             $mediaManager->saveItem($mediaItem);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId($mediaItem->getId());
             $listItem->setPosition(0);
             $productListManager->saveItem($listItem, false);
             $mediaItem->setId(null);
             $mediaItem->setLabel('2. picture for ' . $item->getLabel());
             $mediaItem->setPreview($prefix . 'unitperf/' . (($pos + 1) % 4 + 1) . '.jpg');
             $mediaItem->setUrl($prefix . 'unitperf/' . (($pos + 1) % 4 + 1) . '-big.jpg');
             $mediaManager->saveItem($mediaItem);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId($mediaItem->getId());
             $listItem->setPosition(1);
             $productListManager->saveItem($listItem, false);
             $mediaItem->setId(null);
             $mediaItem->setLabel('3. picture for ' . $item->getLabel());
             $mediaItem->setPreview($prefix . 'unitperf/' . (($pos + 2) % 4 + 1) . '.jpg');
             $mediaItem->setUrl($prefix . 'unitperf/' . (($pos + 2) % 4 + 1) . '-big.jpg');
             $mediaManager->saveItem($mediaItem);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId($mediaItem->getId());
             $listItem->setPosition(2);
             $productListManager->saveItem($listItem, false);
             $mediaItem->setId(null);
             $mediaItem->setLabel('4. picture for ' . $item->getLabel());
             $mediaItem->setPreview($prefix . 'unitperf/' . (($pos + 3) % 4 + 1) . '.jpg');
             $mediaItem->setUrl($prefix . 'unitperf/' . (($pos + 3) % 4 + 1) . '-big.jpg');
             $mediaManager->saveItem($mediaItem);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId($mediaItem->getId());
             $listItem->setPosition(3);
             $productListManager->saveItem($listItem, false);
             $pos++;
             $downloadListItem->setId(null);
             $downloadListItem->setParentId($id);
             $productListManager->saveItem($downloadListItem, false);
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
     $this->txCommit();
     $this->status('done');
 }
コード例 #9
0
 /**
  * Adds the media-list test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param array $refIds Associative list of domains and the keys/IDs of the inserted items
  * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 private function addMediaListData(array $testdata, array $refIds)
 {
     $mediaManager = \Aimeos\MShop\Media\Manager\Factory::createManager($this->additional, 'Standard');
     $mediaListManager = $mediaManager->getSubmanager('lists', 'Standard');
     $mediaListTypeManager = $mediaListManager->getSubManager('type', 'Standard');
     $urls = array();
     foreach ($testdata['media/lists'] as $dataset) {
         if (($pos = strpos($dataset['parentid'], '/')) === false || ($str = substr($dataset['parentid'], $pos + 1)) === false) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid']));
         }
         $urls[] = $str;
     }
     $search = $mediaManager->createSearch();
     $search->setConditions($search->compare('==', 'media.url', $urls));
     $result = $mediaManager->searchItems($search);
     $parentIds = array();
     foreach ($result as $item) {
         $parentIds['media/' . $item->getUrl()] = $item->getId();
     }
     $medListTypes = array();
     $medListType = $mediaListTypeManager->createItem();
     foreach ($testdata['media/lists/type'] as $key => $dataset) {
         $medListType->setId(null);
         $medListType->setCode($dataset['code']);
         $medListType->setDomain($dataset['domain']);
         $medListType->setLabel($dataset['label']);
         $medListType->setStatus($dataset['status']);
         $mediaListTypeManager->saveItem($medListType);
         $medListTypes[$key] = $medListType->getId();
     }
     $this->conn->begin();
     $medList = $mediaListManager->createItem();
     foreach ($testdata['media/lists'] as $dataset) {
         if (!isset($parentIds[$dataset['parentid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No media ID found for "%1$s"', $dataset['parentid']));
         }
         if (!isset($medListTypes[$dataset['typeid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No media list type ID found for "%1$s"', $dataset['typeid']));
         }
         if (!isset($refIds[$dataset['domain']][$dataset['refid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain']));
         }
         $medList->setId(null);
         $medList->setParentId($parentIds[$dataset['parentid']]);
         $medList->setTypeId($medListTypes[$dataset['typeid']]);
         $medList->setRefId($refIds[$dataset['domain']][$dataset['refid']]);
         $medList->setDomain($dataset['domain']);
         $medList->setDateStart($dataset['start']);
         $medList->setDateEnd($dataset['end']);
         $medList->setConfig($dataset['config']);
         $medList->setPosition($dataset['pos']);
         $medList->setStatus($dataset['status']);
         $mediaListManager->saveItem($medList, false);
     }
     $this->conn->commit();
 }
コード例 #10
0
 protected function cleanupMedia()
 {
     $manager = \Aimeos\MShop\Media\Manager\Factory::createManager($this->context);
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'media.domain', 'product'), $search->compare('==', 'media.label', 'import-%'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'media.id')));
     $start = 0;
     do {
         $result = $manager->searchItems($search);
         $manager->deleteItems(array_keys($result));
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
 }
コード例 #11
0
ファイル: FactoryTest.php プロジェクト: mvnp/aimeos-core
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('\\Aimeos\\MShop\\Exception');
     \Aimeos\MShop\Media\Manager\Factory::createManager(\TestHelperMShop::getContext(), 'unknown');
 }