/** * @param DOMDocument * @param string * @return DOMXPath */ protected function getXPath(DOMDocument $doc, $prefix) { /** @var DOMXPath */ $xpath = $this->coreHelper->getNewDomXPath($doc); /** @var DOMElement */ $element = $doc->documentElement; $xpath->registerNamespace($prefix, $element->namespaceURI); return $xpath; }
/** * Mask the StoredValue request XML message of any sensitive data - PAN, PIN. * * @param string * @return string */ public function maskXmlNodes($xml) { /** @var DOMDocument */ $doc = $this->coreHelper->getNewDomDocument(); $doc->loadXML($xml); /** @var DOMElement */ $element = $doc->documentElement; /** @var DOMXPath */ $xpath = $this->coreHelper->getNewDomXPath($doc); $xpath->registerNamespace('x', $element->namespaceURI); $this->maskPin($doc, $xpath)->maskPan($doc, $xpath); return $doc->saveXML(); }
/** * Test that the helper callback method ebayenterprise_catalog/map::extractCustomAttributes() * when invoked will be given as its first parameter an object of type DOMNodeList, and as its second parameter * an object of type catalog/product. Then, we expect the proper custom attribute to be extracted * and added to the passed-in product object. * * @param string * @param Mage_Catalog_Model_Product * @dataProvider providerExtractCustomAttributes */ public function testExtractCustomAttributes($feedFile, Mage_Catalog_Model_Product $product) { $this->_doc->loadXML(file_get_contents($feedFile)); /** @var DOMXPath $xpath */ $xpath = $this->_coreHelper->getNewDomXPath($this->_doc); /** @var DOMNodeList $nodes */ $nodes = $xpath->query('//CustomAttributes/Attribute'); /** @var EbayEnterprise_Catalog_Helper_Map $map */ $map = Mage::helper('ebayenterprise_catalog/map'); // Proving that product object has no value $this->assertEmpty($product->getData()); // Proving that when the method ebayenterprise_catalog/map::extractCustomAttributes() // invoked it will always return null $this->assertNull($map->extractCustomAttributes($nodes, $product)); // Proving that after calling the method ebayenterprise_catalog/map::extractCustomAttributes() // the empty passed in product object will now contains data $this->assertNotEmpty($product->getData()); }
/** * Scenario: Extract size option * Given an XML NodeList object containing size data. * When the callback extracts the size option. * Then The size option id is returned. */ public function testExtractSizeValue() { /** @var int $optionId */ $optionId = 89; /** @var DOMDocument $doc */ $doc = $this->coreHelper->getNewDomDocument(); $doc->loadXML('<root> <Size> <Code>77</Code> <Description xml:lang="en-us">Small</Description> </Size> </root>'); /** @var DOMXPath $xpath */ $xpath = $this->coreHelper->getNewDomXPath($doc); /** @var DOMNodeList $nodeList */ $nodeList = $xpath->query('Size', $doc->documentElement); /** @var Mock_EbayEnterprise_Catalog_Helper_Map_Attribute $mapAttribute */ $mapAttribute = $this->getHelperMock('ebayenterprise_catalog/map_attribute', ['_setOptionValues']); $mapAttribute->expects($this->once())->method('_setOptionValues')->with($this->identicalTo('size'), $this->identicalTo('77'), $this->identicalTo(['en-us' => 'Small']))->will($this->returnValue($optionId)); $this->assertSame($optionId, $mapAttribute->extractSizeValue($nodeList)); }
/** * load a product collection base on a given set of product data and apply * the product data to the collection and then save * product data is expected to have known SKU in order to load the collection * @param DOMDocument $itemDataDoc * @param int $storeId * @param array $cfgData * @param EbayEnterprise_Catalog_Interface_Import_Items $items * @return self */ protected function _importExtractedData(DOMDocument $itemDataDoc, $storeId, array $cfgData, EbayEnterprise_Catalog_Interface_Import_Items $items) { $feedXPath = $this->_coreHelper->getNewDomXPath($itemDataDoc); $skusToUpdate = $this->_getSkusToUpdate($feedXPath, $cfgData); if (count($skusToUpdate)) { $collection = $items->buildCollection($skusToUpdate); if ($cfgData['feed_type'] === 'product') { $collection->setStore($storeId); } foreach ($feedXPath->query($cfgData['base_item_xpath']) as $itemNode) { $this->_updateItem($feedXPath, $itemNode, $collection, $storeId, $cfgData, $items); } $logData = ['total_products' => $collection->getSize(), 'feed_type' => $cfgData['feed_type']]; $logMessage = 'saving collection of {total_products} {feed_type}'; $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); // keep track of skus we've processed for the website $this->_importedSkus = array_unique(array_merge($this->_importedSkus, $skusToUpdate)); $this->_helper->saveCollectionStubIndexer($collection); } return $this; }