Esempio n. 1
0
 public function testTransform()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager(TestHelper::getContext());
     $node = $catalogManager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_ONE);
     $output = $this->_object->transform($node, array());
     $this->assertContains('Root', $output);
 }
 /**
  * Rebuilds the catalog index.
  */
 protected function _process()
 {
     $this->_msg('Rebuilding catalog index for performance data', 0);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_getContext());
     $catalogManager->getSubManager('index')->rebuildIndex();
     $this->_status('done');
 }
Esempio n. 3
0
 /**
  * Initializes the catalog list type controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Catalog_List_Type');
     $manager = MShop_Catalog_Manager_Factory::createManager($context);
     $listManager = $manager->getSubManager('list');
     $this->_manager = $listManager->getSubManager('type');
 }
Esempio n. 4
0
 public function testSaveDeleteItem()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager(TestHelper::getContext());
     $node = $catalogManager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_ONE);
     $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('catalog.list.type.domain' => 'product')))), 'start' => 0, 'limit' => 1);
     $catalogListTypeManager = Controller_ExtJS_Catalog_List_Type_Factory::createController(TestHelper::getContext());
     $resultType = $catalogListTypeManager->searchItems($params);
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('catalog.list.parentid' => $node->getId(), 'catalog.list.typeid' => $resultType['items'][0]->{'catalog.list.type.id'}, 'catalog.list.domain' => 'product', 'catalog.list.refid' => -1, 'catalog.list.datestart' => '2000-01-01 00:00:00', 'catalog.list.dateend' => '2000-01-01 00:00:00', 'catalog.list.config' => array('test' => 'unit'), 'catalog.list.position' => 1, 'catalog.list.status' => 1));
     $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('catalog.list.refid' => -1)))));
     $saved = $this->_object->saveItems($saveParams);
     $searched = $this->_object->searchItems($searchParams);
     $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'catalog.list.id'});
     $this->_object->deleteItems($deleteParams);
     $result = $this->_object->searchItems($searchParams);
     $this->assertInternalType('object', $saved['items']);
     $this->assertNotNull($saved['items']->{'catalog.list.id'});
     $this->assertEquals($saved['items']->{'catalog.list.id'}, $searched['items'][0]->{'catalog.list.id'});
     $this->assertEquals($saved['items']->{'catalog.list.parentid'}, $searched['items'][0]->{'catalog.list.parentid'});
     $this->assertEquals($saved['items']->{'catalog.list.typeid'}, $searched['items'][0]->{'catalog.list.typeid'});
     $this->assertEquals($saved['items']->{'catalog.list.domain'}, $searched['items'][0]->{'catalog.list.domain'});
     $this->assertEquals($saved['items']->{'catalog.list.refid'}, $searched['items'][0]->{'catalog.list.refid'});
     $this->assertEquals($saved['items']->{'catalog.list.datestart'}, $searched['items'][0]->{'catalog.list.datestart'});
     $this->assertEquals($saved['items']->{'catalog.list.dateend'}, $searched['items'][0]->{'catalog.list.dateend'});
     $this->assertEquals($saved['items']->{'catalog.list.config'}, $searched['items'][0]->{'catalog.list.config'});
     $this->assertEquals($saved['items']->{'catalog.list.position'}, $searched['items'][0]->{'catalog.list.position'});
     $this->assertEquals($saved['items']->{'catalog.list.status'}, $searched['items'][0]->{'catalog.list.status'});
     $this->assertEquals(1, count($searched['items']));
     $this->assertEquals(0, count($result['items']));
 }
Esempio n. 5
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_editor = TestHelper::getContext()->getEditor();
     $attributeManager = MShop_Catalog_Manager_Factory::createManager(TestHelper::getContext());
     $attributeListManager = $attributeManager->getSubManager('list');
     $this->_object = $attributeListManager->getSubManager('type');
 }
Esempio n. 6
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $paths = TestHelper::getHtmlTemplatePaths();
     $this->_object = new Client_Html_Catalog_List_Items_Default($context, $paths);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $catItems = $catalogManager->searchItems($search);
     if (($catItem = reset($catItems)) === false) {
         throw new Exception('No catalog item found');
     }
     $productManager = MShop_Product_Manager_Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', array('CNC', 'CNE')));
     $total = 0;
     $view = TestHelper::getView();
     $view->listProductItems = $productManager->searchItems($search, array('media', 'price', 'text'), $total);
     $view->listProductTotal = $total;
     $view->listPageSize = 100;
     $view->listPageCurr = 1;
     $view->listParams = array();
     $view->listCatPath = array($catalogManager->createItem(), $catItem);
     $this->_object->setView($view);
 }
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 protected function _process()
 {
     $this->_msg('Adding catalog performance data', 0);
     $context = $this->_getContext();
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $catalogRootItem = $catalogManager->createItem();
     $catalogRootItem->setCode('home');
     $catalogRootItem->setLabel('Home');
     $catalogRootItem->setStatus(1);
     $catalogManager->insertItem($catalogRootItem);
     for ($i = 1; $i <= 5; $i++) {
         $catalogOneItem = $catalogManager->createItem();
         $catalogOneItem->setCode('cat-' . $i);
         $catalogOneItem->setLabel('cat-' . $i);
         $catalogOneItem->setStatus(1);
         $catalogManager->insertItem($catalogOneItem, $catalogRootItem->getId());
         for ($j = 1; $j <= 10; $j++) {
             $catalogTwoItem = $catalogManager->createItem();
             $catalogTwoItem->setCode('cat-' . $i . ':' . $j);
             $catalogTwoItem->setLabel('cat-' . $i . ':' . $j);
             $catalogTwoItem->setStatus(1);
             $catalogManager->insertItem($catalogTwoItem, $catalogOneItem->getId());
             for ($k = 1; $k <= 10; $k++) {
                 $catalogThreeItem = $catalogManager->createItem();
                 $catalogThreeItem->setCode('cat-' . $i . ':' . $j . ':' . $k);
                 $catalogThreeItem->setLabel('cat-' . $i . ':' . $j . ':' . $k);
                 $catalogThreeItem->setStatus(1);
                 $catalogManager->insertItem($catalogThreeItem, $catalogTwoItem->getId());
             }
         }
     }
     $this->_status('done');
 }
Esempio n. 8
0
 public function testTreeWithId()
 {
     $start = microtime(true);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $catalogManager->getTree($this->_root->getId(), array('text', 'media'));
     $stop = microtime(true);
     echo "\n    catalog tree with ID: " . ($stop - $start) * 1000 . " msec\n";
 }
Esempio n. 9
0
 /**
  * Executes the job.
  *
  * @throws Controller_Jobs_Exception If an error occurs
  */
 public function run()
 {
     $timestamp = date('Y-m-d H:i:s');
     $context = clone $this->_getContext();
     $context->getLocale()->setLanguageId(null);
     $context->getLocale()->setCurrencyId(null);
     $manager = MShop_Catalog_Manager_Factory::createManager($context)->getSubManager('index');
     $manager->rebuildIndex();
     $manager->cleanupIndex($timestamp);
 }
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 protected function _process()
 {
     $this->_msg('Adding catalog text performance data', 0);
     $context = $this->_getContext();
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $catalogListManager = $catalogManager->getSubManager('list');
     $catalogListTypeManager = $catalogListManager->getSubManager('type');
     $search = $catalogListTypeManager->createSearch();
     $expr = array($search->compare('==', 'catalog.list.type.domain', 'text'), $search->compare('==', 'catalog.list.type.code', 'default'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $catalogListTypeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new Exception('Catalog list type item not found');
     }
     $textManager = MShop_Text_Manager_Factory::createManager($context);
     $textTypeManager = $textManager->getSubManager('type');
     $search = $textTypeManager->createSearch();
     $expr = array($search->compare('==', 'text.type.domain', 'catalog'), $search->compare('==', 'text.type.code', 'name'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $textTypeManager->searchItems($search);
     if (($textTypeItem = reset($types)) === false) {
         throw new Exception('Text type item not found');
     }
     $textItem = $textManager->createItem();
     $textItem->setTypeId($textTypeItem->getId());
     $textItem->setLanguageId('en');
     $textItem->setDomain('catalog');
     $textItem->setStatus(1);
     $listItem = $catalogListManager->createItem();
     $listItem->setTypeId($typeItem->getId());
     $listItem->setDomain('text');
     $this->_txBegin();
     $start = $pos = 0;
     $search = $catalogManager->createSearch();
     $search->setSortations(array($search->sort('+', 'catalog.id')));
     do {
         $result = $catalogManager->searchItems($search);
         foreach ($result as $id => $item) {
             $textItem->setId(null);
             $textItem->setLabel($item->getLabel());
             $textItem->setContent(str_replace('-', ' ', $item->getLabel()));
             $textManager->saveItem($textItem);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId($textItem->getId());
             $listItem->setPosition($pos++);
             $catalogListManager->saveItem($listItem, false);
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
     $this->_txCommit();
     $this->_status('done');
 }
 /**
  * Rebuilds the catalog index.
  */
 protected function _process()
 {
     $iface = 'MShop_Context_Item_Interface';
     if (!$this->_additional instanceof $iface) {
         throw new MW_Setup_Exception(sprintf('Additionally provided object is not of type "%1$s"', $iface));
     }
     $this->_msg('Rebuilding catalog index for test data', 0);
     $catalogIndexManager = MShop_Catalog_Manager_Factory::createManager($this->_additional)->getSubManager('index');
     $catalogIndexManager->rebuildIndex();
     $catalogIndexManager->optimize();
     $this->_status('done');
 }
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 protected function _process()
 {
     $this->_msg('Adding product categories performance data', 0);
     $context = $this->_getContext();
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $catalogListManager = $catalogManager->getSubManager('list');
     $catalogListTypeManager = $catalogListManager->getSubManager('type');
     $search = $catalogListTypeManager->createSearch();
     $expr = array($search->compare('==', 'catalog.list.type.domain', 'product'), $search->compare('==', 'catalog.list.type.code', 'default'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $catalogListTypeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new Exception('Catalog list type item not found');
     }
     $search = $catalogManager->createSearch();
     $search->setSortations(array($search->sort('+', 'catalog.level'), $search->sort('+', 'catalog.left')));
     $search->setSlice(0, 0x7fffffff);
     $catIds = array_keys($catalogManager->searchItems($search));
     $listItem = $catalogListManager->createItem();
     $listItem->setTypeId($typeItem->getId());
     $listItem->setDomain('product');
     $this->_txBegin();
     $productManager = MShop_Product_Manager_Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setSortations(array($search->sort('+', 'product.id')));
     $start = $pos = 0;
     do {
         $catId = current($catIds);
         if (($catId2 = next($catIds)) === false) {
             $catId2 = reset($catIds);
         }
         $result = $productManager->searchItems($search);
         foreach ($result as $id => $item) {
             $listItem->setId(null);
             $listItem->setParentId($catId);
             $listItem->setRefId($id);
             $listItem->setPosition($pos++);
             $catalogListManager->saveItem($listItem, false);
             $listItem->setId(null);
             $listItem->setParentId($catId2);
             $listItem->setRefId($id);
             $listItem->setPosition($pos++);
             $catalogListManager->saveItem($listItem, false);
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
     $this->_txCommit();
     $this->_status('done');
 }
Esempio n. 13
0
 public function testRun()
 {
     $context = TestHelper::getContext();
     $arcavias = TestHelper::getArcavias();
     $name = 'ControllerJobsCatalogIndexOptimizeDefaultRun';
     $context->getConfig()->set('classes/catalog/manager/name', $name);
     $catalogManagerStub = $this->getMockBuilder('MShop_Catalog_Manager_Default')->setMethods(array('getSubManager'))->setConstructorArgs(array($context))->getMock();
     $catalogIndexManagerStub = $this->getMockBuilder('MShop_Catalog_Manager_Index_Default')->setMethods(array('optimize'))->setConstructorArgs(array($context))->getMock();
     MShop_Catalog_Manager_Factory::injectManager('MShop_Catalog_Manager_' . $name, $catalogManagerStub);
     $catalogManagerStub->expects($this->once())->method('getSubManager')->will($this->returnValue($catalogIndexManagerStub));
     $catalogIndexManagerStub->expects($this->once())->method('optimize');
     $object = new Controller_Jobs_Catalog_Index_Optimize_Default($context, $arcavias);
     $object->run();
 }
 /**
  * Adds the catalog test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws MW_Setup_Exception If a required ID is not available
  */
 private function _addCatalogData(array $testdata)
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_additional, 'Default');
     $parentIds = array('init' => null);
     $catalog = $catalogManager->createItem();
     foreach ($testdata['catalog'] as $key => $dataset) {
         $catalog->setId(null);
         $catalog->setCode($dataset['code']);
         $catalog->setLabel($dataset['label']);
         $catalog->setConfig($dataset['config']);
         $catalog->setStatus($dataset['status']);
         $catalogManager->insertItem($catalog, $parentIds[$dataset['parent']]);
         $parentIds[$key] = $catalog->getId();
     }
 }
Esempio n. 15
0
 /**
  * Executes tasks after processing the items.
  *
  * @param stdClass $params Associative list of parameters
  * @return array Associative list with success value
  */
 public function finish(stdClass $params)
 {
     $this->_checkParams($params, array('site', 'items'));
     $this->_setLocale($params->site);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $indexManager = $catalogManager->getSubManager('index');
     $search = $this->_manager->createSearch();
     $search->setConditions($search->compare('==', 'product.id', $params->items));
     $search->setSlice(0, count($params->items));
     foreach ($this->_manager->searchItems($search) as $item) {
         $indexManager->saveItem($item);
     }
     $this->_clearCache((array) $params->items);
     return array('success' => true);
 }
Esempio n. 16
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $paths = TestHelper::getHtmlTemplatePaths();
     $this->_object = new Client_Html_Catalog_Stage_Image_Default($context, $paths);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $catItems = $catalogManager->searchItems($search, array('media'));
     if (($catItem = reset($catItems)) === false) {
         throw new Exception('No catalog item found');
     }
     $view = TestHelper::getView();
     $view->stageCatPath = array($catItem);
     $this->_object->setView($view);
 }
Esempio n. 17
0
 public function testGetBodyLevelsOnly()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager(TestHelper::getContext());
     $node = $catalogManager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_TREE);
     $view = $this->_object->getView();
     $conf = new MW_Config_Array(array('client' => array('html' => array('catalog' => array('filter' => array('tree' => array('levels-only' => 1)))))));
     $helper = new MW_View_Helper_Config_Default($view, $conf);
     $view->addHelper('config', $helper);
     $helper = new MW_View_Helper_Parameter_Default($view, array('f_catid' => $node->getChild(0)->getId()));
     $view->addHelper('param', $helper);
     $tags = array();
     $expire = null;
     $output = $this->_object->getBody(1, $tags, $expire);
     $this->assertNotContains('level-2', $output);
     $this->assertEquals('2022-01-01 00:00:00', $expire);
     $this->assertEquals(3, count($tags));
 }
Esempio n. 18
0
 public function testExportXLSFile()
 {
     $this->_object = new Controller_ExtJS_Catalog_Export_Text_Default($this->_context);
     $manager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $node = $manager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_ONE);
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.label', array('Root', 'Tee')));
     $ids = array();
     foreach ($manager->searchItems($search) as $item) {
         $ids[$item->getLabel()] = $item->getId();
     }
     $params = new stdClass();
     $params->lang = array('de', 'fr');
     $params->items = array($node->getId());
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $result = $this->_object->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $file = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($file));
     $inputFileType = PHPExcel_IOFactory::identify($file);
     $objReader = PHPExcel_IOFactory::createReader($inputFileType);
     $objPHPExcel = $objReader->load($file);
     $objPHPExcel->setActiveSheetIndex(0);
     if (unlink($file) === false) {
         throw new Exception('Unable to remove export file');
     }
     $sheet = $objPHPExcel->getActiveSheet();
     $this->assertEquals('Language ID', $sheet->getCell('A1')->getValue());
     $this->assertEquals('Text', $sheet->getCell('G1')->getValue());
     $this->assertEquals('de', $sheet->getCell('A4')->getValue());
     $this->assertEquals('Root', $sheet->getCell('B4')->getValue());
     $this->assertEquals($ids['Root'], $sheet->getCell('C4')->getValue());
     $this->assertEquals('default', $sheet->getCell('D4')->getValue());
     $this->assertEquals('name', $sheet->getCell('E4')->getValue());
     $this->assertEquals('', $sheet->getCell('G4')->getValue());
     $this->assertEquals('de', $sheet->getCell('A21')->getValue());
     $this->assertEquals('Tee', $sheet->getCell('B21')->getValue());
     $this->assertEquals($ids['Tee'], $sheet->getCell('C21')->getValue());
     $this->assertEquals('unittype8', $sheet->getCell('D21')->getValue());
     $this->assertEquals('long', $sheet->getCell('E21')->getValue());
     $this->assertEquals('Dies würde die lange Beschreibung der Teekategorie sein. Auch hier machen Bilder einen Sinn.', $sheet->getCell('G21')->getValue());
 }
Esempio n. 19
0
 /**
  * Returns the list of categories with their ID.
  *
  * @param array $config Associative array of existing configurations
  * @param \TYPO3\CMS\Backend\Form\FormEngine|\TYPO3\CMS\Backend\Form\DataPreprocessor $tceForms TCE forms object
  * @param string $sitecode Unique code of the site to retrieve the categories for
  * @return array Associative array with existing and new entries
  */
 public function getCategories(array $config, $tceForms = null, $sitecode = 'default')
 {
     if (isset($config['row']) && isset($config['row']['pid'])) {
         $pageTSConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($config['row']['pid'], 'tx_aimeos');
         if (isset($pageTSConfig['properties']['mshop.']['locale.']['site'])) {
             $sitecode = $pageTSConfig['properties']['mshop.']['locale.']['site'];
         }
     }
     try {
         $context = Base::getContext(Base::getConfig());
         $context->setEditor('flexform');
         $localeManager = \MShop_Locale_Manager_Factory::createManager($context);
         $context->setLocale($localeManager->bootstrap($sitecode, '', '', false));
         $manager = \MShop_Catalog_Manager_Factory::createManager($context);
         $item = $manager->getTree(null, array(), \MW_Tree_Manager_Abstract::LEVEL_TREE);
         $config['items'] = array_merge($config['items'], $this->getCategoryList($item, 0));
     } catch (Exception $e) {
         error_log($e->getMessage() . PHP_EOL . $e->getTraceAsString());
     }
     return $config;
 }
Esempio n. 20
0
 protected function setUp()
 {
     $this->_paths = TestHelper::getHtmlTemplatePaths();
     $this->_context = TestHelper::getContext('unitperf');
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'home'));
     $items = $catalogManager->searchItems($search);
     if (($catalogItem = reset($items)) === false) {
         throw new Exception('No catalog item with code "home" found');
     }
     $productManager = MShop_Product_Manager_Factory::createManager($this->_context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', 'perf-00000'));
     $items = $productManager->searchItems($search);
     if (($productItem = reset($items)) === false) {
         throw new Exception('No product item with code "perf-00000" found');
     }
     $this->_view = TestHelper::getView('unitperf');
     $param = array('f_catid' => $catalogItem->getId(), 'd_prodid' => $productItem->getId());
     $helper = new MW_View_Helper_Parameter_Default($this->_view, $param);
     $this->_view->addHelper('param', $helper);
 }
Esempio n. 21
0
 public function testImportFromCSVFile()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'root'));
     $items = $catalogManager->searchItems($search);
     if (($root = reset($items)) === false) {
         throw new Controller_ExtJS_Exception('No item found for catalog code "root"');
     }
     $id = $root->getId();
     $data = array();
     $data[] = '"Language ID","Catalog code","Catalog ID","List type","Text type","Text ID","Text"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: long"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: meta desc"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: meta keywords"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: meta title"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: name"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: short"' . "\n";
     $data[] = ' ';
     $ds = DIRECTORY_SEPARATOR;
     $csv = 'en-catalog-test.csv';
     $filename = PATH_TESTS . $ds . 'tmp' . $ds . 'catalog-import.zip';
     if (file_put_contents(PATH_TESTS . $ds . 'tmp' . $ds . $csv, implode('', $data)) === false) {
         throw new Exception(sprintf('Unable to write test file "%1$s"', $csv));
     }
     $zip = new ZipArchive();
     $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     $zip->addFile(PATH_TESTS . $ds . 'tmp' . $ds . $csv, $csv);
     $zip->close();
     if (unlink(PATH_TESTS . $ds . 'tmp' . $ds . $csv) === false) {
         throw new Exception('Unable to remove export file');
     }
     $params = new stdClass();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $params->items = $filename;
     $this->_object->importFile($params);
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $criteria = $textManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'text.domain', 'catalog');
     $expr[] = $criteria->compare('==', 'text.languageid', 'en');
     $expr[] = $criteria->compare('==', 'text.status', 1);
     $expr[] = $criteria->compare('~=', 'text.content', 'Root:');
     $criteria->setConditions($criteria->combine('&&', $expr));
     $textItems = $textManager->searchItems($criteria);
     $textIds = array();
     foreach ($textItems as $item) {
         $textManager->deleteItem($item->getId());
         $textIds[] = $item->getId();
     }
     $listManager = $catalogManager->getSubManager('list');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'catalog.list.domain', 'text');
     $expr[] = $criteria->compare('==', 'catalog.list.refid', $textIds);
     $criteria->setConditions($criteria->combine('&&', $expr));
     $listItems = $listManager->searchItems($criteria);
     foreach ($listItems as $item) {
         $listManager->deleteItem($item->getId());
     }
     foreach ($textItems as $item) {
         $this->assertEquals('Root:', substr($item->getContent(), 0, 5));
     }
     $this->assertEquals(6, count($textItems));
     $this->assertEquals(6, count($listItems));
     if (file_exists($filename) !== false) {
         throw new Exception('Import file was not removed');
     }
 }
Esempio n. 22
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $this->_object = MShop_Catalog_Manager_Factory::createManager($context);
 }
Esempio n. 23
0
 /**
  * Adds data for the given language.
  *
  * @param string $langid Language id
  * @param array $ids List of of item ids whose texts should be added
  * @param MW_Container_Content_Interface $contentItem Content item
  */
 protected function _addLanguage(MW_Container_Content_Interface $contentItem, $langid, array $ids)
 {
     $manager = MShop_Catalog_Manager_Factory::createManager($this->_getContext());
     foreach ($ids as $id) {
         foreach ($this->_getNodeList($manager->getTree($id, array('text'))) as $item) {
             $this->_addItem($contentItem, $item, $langid);
         }
     }
 }
Esempio n. 24
0
 public function testImportFromXLSFile()
 {
     $this->_object = new Controller_ExtJS_Catalog_Import_Text_Default($this->_context);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $node = $catalogManager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_ONE);
     $params = new stdClass();
     $params->lang = array('en');
     $params->items = $node->getId();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $exporter = new Controller_ExtJS_Catalog_Export_Text_Default($this->_context);
     $result = $exporter->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $filename = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($filename));
     $filename2 = 'catalog-import.xls';
     $phpExcel = PHPExcel_IOFactory::load($filename);
     if (unlink($filename) !== true) {
         throw new Exception(sprintf('Deleting file "%1$s" failed', $filename));
     }
     $sheet = $phpExcel->getSheet(0);
     $sheet->setCellValueByColumnAndRow(6, 2, 'Root: delivery info');
     $sheet->setCellValueByColumnAndRow(6, 3, 'Root: long');
     $sheet->setCellValueByColumnAndRow(6, 4, 'Root: name');
     $sheet->setCellValueByColumnAndRow(6, 5, 'Root: payment info');
     $sheet->setCellValueByColumnAndRow(6, 6, 'Root: short');
     $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel5');
     $objWriter->save($filename2);
     $params = new stdClass();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $params->items = $filename2;
     $this->_object->importFile($params);
     if (file_exists($filename2) !== false) {
         throw new Exception('Import file was not removed');
     }
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $criteria = $textManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'text.domain', 'catalog');
     $expr[] = $criteria->compare('==', 'text.languageid', 'en');
     $expr[] = $criteria->compare('==', 'text.status', 1);
     $expr[] = $criteria->compare('~=', 'text.content', 'Root:');
     $criteria->setConditions($criteria->combine('&&', $expr));
     $textItems = $textManager->searchItems($criteria);
     $textIds = array();
     foreach ($textItems as $item) {
         $textManager->deleteItem($item->getId());
         $textIds[] = $item->getId();
     }
     $listManager = $catalogManager->getSubManager('list');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'catalog.list.domain', 'text');
     $expr[] = $criteria->compare('==', 'catalog.list.refid', $textIds);
     $criteria->setConditions($criteria->combine('&&', $expr));
     $listItems = $listManager->searchItems($criteria);
     foreach ($listItems as $item) {
         $listManager->deleteItem($item->getId());
     }
     $this->assertEquals(5, count($textItems));
     $this->assertEquals(5, count($listItems));
     foreach ($textItems as $item) {
         $this->assertEquals('Root:', substr($item->getContent(), 0, 5));
     }
 }
Esempio n. 25
0
 protected function _getCatalogItem()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $items = $catalogManager->searchItems($search);
     if (($item = reset($items)) === false) {
         throw new Exception('No catalog item with code "cafe" found');
     }
     return $item;
 }
Esempio n. 26
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     MShop_Catalog_Manager_Factory::createManager(TestHelper::getContext(), 'notexist');
 }
Esempio n. 27
0
 public function testExportCSVFile()
 {
     $manager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $node = $manager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_ONE);
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.label', array('Root', 'Tee')));
     $ids = array();
     foreach ($manager->searchItems($search) as $item) {
         $ids[$item->getLabel()] = $item->getId();
     }
     $params = new stdClass();
     $params->lang = array('de', 'fr');
     $params->items = array($node->getId());
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $result = $this->_object->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $file = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($file));
     $zip = new ZipArchive();
     $zip->open($file);
     $testdir = 'tmp' . DIRECTORY_SEPARATOR . 'csvexport';
     if (!is_dir($testdir) && mkdir($testdir, 0755, true) === false) {
         throw new Controller_ExtJS_Exception(sprintf('Couldn\'t create directory "csvexport"'));
     }
     $zip->extractTo($testdir);
     $zip->close();
     if (unlink($file) === false) {
         throw new Exception('Unable to remove export file');
     }
     $lines = $langs = array();
     $langs['fr'] = $testdir . DIRECTORY_SEPARATOR . 'fr.csv';
     $langs['de'] = $testdir . DIRECTORY_SEPARATOR . 'de.csv';
     foreach ($langs as $lang => $path) {
         $this->assertTrue(file_exists($path));
         $fh = fopen($path, 'r');
         while (($data = fgetcsv($fh)) != false) {
             $lines[$lang][] = $data;
         }
         fclose($fh);
         if (unlink($path) === false) {
             throw new Exception('Unable to remove export file');
         }
     }
     if (rmdir($testdir) === false) {
         throw new Exception('Unable to remove test export directory');
     }
     $this->assertEquals('Language ID', $lines['de'][0][0]);
     $this->assertEquals('Text', $lines['de'][0][6]);
     $this->assertEquals('de', $lines['de'][3][0]);
     $this->assertEquals('Root', $lines['de'][3][1]);
     $this->assertEquals($ids['Root'], $lines['de'][3][2]);
     $this->assertEquals('default', $lines['de'][3][3]);
     $this->assertEquals('name', $lines['de'][3][4]);
     $this->assertEquals('', $lines['de'][3][6]);
     $this->assertEquals('de', $lines['de'][23][0]);
     $this->assertEquals('Tee', $lines['de'][23][1]);
     $this->assertEquals($ids['Tee'], $lines['de'][23][2]);
     $this->assertEquals('unittype8', $lines['de'][23][3]);
     $this->assertEquals('long', $lines['de'][23][4]);
     $this->assertEquals('Dies würde die lange Beschreibung der Teekategorie sein. Auch hier machen Bilder einen Sinn.', $lines['de'][23][6]);
 }
Esempio n. 28
0
 public function testSearchByCategoriesPriceText()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $search = $catalogManager->createSearch(true);
     $search->setConditions($search->compare('==', 'catalog.label', 'cat-1'));
     $result = $catalogManager->searchItems($search);
     if (($catItem = reset($result)) === false) {
         throw new Exception('No catalog item found');
     }
     $catIds = array((int) $this->_catItem->getId(), (int) $catItem->getId());
     $start = microtime(true);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $indexManager = $catalogManager->getSubManager('index');
     $search = $indexManager->createSearch(true);
     $search->setSlice(0, $this->_slizeSize);
     $expr = array($search->getConditions(), $search->compare('==', 'catalog.index.catalog.id', (int) $this->_catItem->getId()), $search->compare('>=', $search->createFunction('catalog.index.catalogcount', array('default', $catIds)), 2), $search->compare('>', $search->createFunction('catalog.index.text.relevance', array('default', 'en', 'plain')), 0), $search->compare('>=', $search->createFunction('catalog.index.price.value', array('default', 'EUR', 'default')), 0));
     $search->setConditions($search->combine('&&', $expr));
     $sort = array($search->sort('-', $search->createFunction('sort:catalog.index.text.relevance', array('default', 'en', 'plain'))));
     $search->setSortations($sort);
     $total = 0;
     $result = $indexManager->searchItems($search, array('text', 'price', 'media'), $total);
     $stop = microtime(true);
     printf("\n    catalog index search by category count/text/price, sort by relevance (%1\$d/%2\$d): %3\$f msec\n", count($result), $total, ($stop - $start) * 1000);
 }
Esempio n. 29
0
 /**
  * Executes the job.
  *
  * @throws Controller_Jobs_Exception If an error occurs
  */
 public function run()
 {
     $manager = MShop_Catalog_Manager_Factory::createManager($this->_getContext());
     $manager->getSubManager('index')->optimize();
 }
Esempio n. 30
0
 public function testSearchItemsCatalog()
 {
     $context = $this->_context;
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $catSearch = $catalogManager->createSearch();
     $conditions = array($catSearch->compare('==', 'catalog.label', 'Kaffee'), $catSearch->compare('==', 'catalog.editor', $this->_editor));
     $catSearch->setConditions($catSearch->combine('&&', $conditions));
     $result = $catalogManager->searchItems($catSearch);
     if (($catItem = reset($result)) === false) {
         throw new Exception('No catalog item found');
     }
     $conditions = array($catSearch->compare('==', 'catalog.label', 'Neu'), $catSearch->compare('==', 'catalog.editor', $this->_editor));
     $catSearch->setConditions($catSearch->combine('&&', $conditions));
     $result = $catalogManager->searchItems($catSearch);
     if (($catNewItem = reset($result)) === false) {
         throw new Exception('No catalog item found');
     }
     $search = $this->_object->createSearch();
     $search->setConditions($search->compare('==', 'product.editor', $this->_editor));
     $sortfunc = $search->createFunction('sort:catalog.index.catalog.position', array('promotion', $catItem->getId()));
     $search->setSortations(array($search->sort('+', $sortfunc)));
     $search->setSlice(0, 1);
     $this->assertEquals(1, count($this->_object->searchItems($search)));
     $total = 0;
     $search = $this->_object->createSearch();
     $search->setSlice(0, 1);
     $conditions = array($search->compare('==', 'catalog.index.catalog.id', $catItem->getId()), $search->compare('==', 'product.editor', $this->_editor));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $this->_object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(2, $total);
     $conditions = array($search->compare('!=', 'catalog.index.catalog.id', null), $search->compare('==', 'product.editor', $this->_editor));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $this->_object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(7, $total);
     $func = $search->createFunction('catalog.index.catalog.position', array('promotion', $catItem->getId()));
     $conditions = array($search->compare('>=', $func, 0), $search->compare('==', 'product.editor', $this->_editor));
     $search->setConditions($search->combine('&&', $conditions));
     $sortfunc = $search->createFunction('sort:catalog.index.catalog.position', array('promotion', $catItem->getId()));
     $search->setSortations(array($search->sort('+', $sortfunc)));
     $result = $this->_object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(2, $total);
     $catIds = array((int) $catItem->getId(), (int) $catNewItem->getId());
     $func = $search->createFunction('catalog.index.catalogcount', array('default', $catIds));
     $conditions = array($search->compare('==', $func, 2), $search->compare('==', 'product.editor', $this->_editor));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $this->_object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(1, $total);
 }