/** * Scenario: Mask StoredValue* Payload XML sensitive data * Given an XML Payload containing sensitive data. * When the mask XML nodes is applied. * Then all sensitive data are masked in XML Payload. * * @param string * @param string * @param array * @param string * @dataProvider providerMaskXmlNodes */ public function testMaskXmlNodes($xml, $mask, array $expressionList, $prefix) { /** @var DOMDocument */ $doc = $this->coreHelper->getNewDomDocument(); $doc->loadXML($xml); /** @var DOMXPath */ $xpath = $this->getXPath($doc, $prefix); foreach ($expressionList as $expression) { // Proving that the value of the nodes are not masked prior to calling // the method ebayenterprise_giftcard/giftcard::maskXmlNodes() on the // XML Payload. $this->assertNotSame($mask, $xpath->evaluate($expression)); } /** @var DOMDocument */ $maskDoc = $this->coreHelper->getNewDomDocument(); // Masking the node values in the XML Payload $maskDoc->loadXML($this->mask->maskXmlNodes($xml)); /** @var DOMXPath */ $maskXPath = $this->getXPath($maskDoc, $prefix); foreach ($expressionList as $expression) { // Proving that the value of the nodes are now masked after calling // the method ebayenterprise_giftcard/giftcard::maskXmlNodes() on the // XML Payload. $this->assertSame($mask, $maskXPath->evaluate($expression)); } }
public function setUp() { parent::setUp(); $this->_coreHelper = Mage::helper('eb2ccore'); $this->_doc = $this->_coreHelper->getNewDomDocument(); // suppressing the real session from starting $session = $this->getModelMockBuilder('core/session')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->replaceByMock('singleton', 'core/session', $session); }
/** * 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(); }
/** * given an acknowledgment feed file, load into a DOMDocument object * attach it into a DOMXPath object and then query it using a constant * that hold XPath for extracting the related exported file * and then return an array of key acknowledgment map to the given acknowledgment file * and a 'related' key mapped to the extracted exported file in the acknowledgment file * @param string $ackFile the full path to the acknowledgment to extract the exported file related to it * @param string $exportedDir the directory to where exported sent file exists * @return array */ protected function _extractAckExportedFile($ackFile, $exportedDir) { $doc = $this->_coreHelper->getNewDomDocument(); $doc->load($ackFile); $xpath = $this->_coreHelper->getNewDOMXPath($doc); return [self::ACK_KEY => $ackFile, self::RELATED_KEY => $exportedDir . DS . $this->_coreHelper->extractNodeVal($xpath->query(self::XPATH_ACK_EXPORTED_FILE, $this->_coreHelper->getDomElement($doc)))]; }
/** * Build an DOMDocument that can be schema validated to check for the * language code to be a valid xml:lang. * * @param string * @return DOMDocument */ protected function _buildLanguageCheckDocument($languageCode) { // Construct a DOMDocument conforming to the language code schema xsd. // Requires a "root" node with an xml:lang attribute. $doc = $this->_coreHelper->getNewDomDocument(); $doc->loadXML("<root xml:lang='{$languageCode}'/>"); return $doc; }
/** * Load the XML file into a new DOMDocument. * * @param string * @return DOMDocument * @throws EbayEnterprise_Eb2cCore_Exception_InvalidXml If file files to be loaded into a DOMDocument. */ protected function loadDoc($fileName) { $doc = $this->coreHelper->getNewDomDocument(); if ($doc->load($fileName)) { return $doc; } // If file could not be loaded into a DOMDocument, treat the XML as invalid. throw Mage::exception('EbayEnterprise_Eb2cCore_Exception_InvalidXml', "Could not load {$fileName} in DOMDocument."); }
public function setUp() { $this->_realCoreHelper = Mage::helper('eb2ccore'); $this->_doc = $this->_realCoreHelper->getNewDomDocument(); $this->_coreHelper = $this->getHelperMock('eb2ccore/data', array('getConfigModel', 'triggerError', 'parseBool', 'getNewDomDocument')); $this->_docMock = $this->getMockBuilder('EbayEnterprise_Dom_Document')->disableOriginalConstructor()->setMethods(array('save', 'loadXML', 'importNode'))->getMock(); $this->_pimProductCollection = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product_collection')->disableOriginalConstructor()->setMethods(array('count', 'getItems'))->getMock(); $this->_feedTypeConfig = $this->_stubFeedConfig(); $this->_productIdCollection = new Varien_Data_Collection(); $this->_productIdCollection->addItem(new Varien_Object(array('id' => 1, 'entity_id' => 1))); $this->_emptyBatch = Mage::getModel('ebayenterprise_catalog/pim_batch'); $batchClass = 'EbayEnterprise_Catalog_Model_Pim_Batch'; $this->_defaultStore = $this->getModelMockBuilder('core/store')->disableOriginalConstructor()->setMethods(array('getId'))->getMock(); $this->_defaultStore->expects($this->any())->method('getId')->will($this->returnValue(0)); $this->_store = $this->getModelMockBuilder('core/store')->disableOriginalConstructor()->setMethods(array('getId'))->getMock(); $this->_store->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->_storesArray = array(0 => $this->_defaultStore, 1 => $this->_store); $this->_batch = Mage::getModel('ebayenterprise_catalog/pim_batch', array($batchClass::COLLECTION_KEY => $this->_productIdCollection, $batchClass::STORES_KEY => array(1 => $this->_store), $batchClass::FT_CONFIG_KEY => $this->_feedTypeConfig, $batchClass::DEFAULT_STORE_KEY => $this->_defaultStore)); $this->_coreFeed = $this->getModelMockBuilder('ebayenterprise_catalog/feed_core')->disableOriginalConstructor()->setMethods(array('getLocalDirectory'))->getMock(); $this->_prodHelper = $this->getHelperMockBuilder('ebayenterprise_catalog/data')->disableOriginalConstructor()->setMethods(array('generateFileName'))->getMock(); // suppressing the real session from starting $session = $this->getModelMockBuilder('core/session')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->replaceByMock('singleton', 'core/session', $session); }
/** * @see self::testExtractAttributeSetValue but this time we are testing that * when a known attribute set is found it will return the knowned attribute set * id in magento. */ public function testExtractAttributeSetValueKnowAttributeSet() { $attributeSetId = 4; $knownAttributeSetId = 5; $attributeSetName = 'Luma'; $helper = $this->getHelperMock('ebayenterprise_catalog/data', ['getAttributeSetIdByName']); $helper->expects($this->once())->method('getAttributeSetIdByName')->with($this->identicalTo($attributeSetName))->will($this->returnValue($knownAttributeSetId)); $this->replaceByMock('helper', 'ebayenterprise_catalog', $helper); $product = Mage::getModel('catalog/product', ['attribute_set_id' => $attributeSetId]); $doc = $this->coreHelper->getNewDomDocument(); $doc->loadXML("<root>\n <Item>\n <CustomAttributes>\n <Attribute name='AttributeSet'>\n <Value>{$attributeSetName}</Value>\n </Attribute>\n </CustomAttributes>\n </Item>\n </root>"); $xpath = $this->coreHelper->getNewDomXPath($doc); $nodes = $xpath->query('Item/CustomAttributes/Attribute[@name="AttributeSet"]/Value', $doc->documentElement); $this->assertSame($knownAttributeSetId, $this->mapHelper->extractAttributeSetValue($nodes, $product)); }
/** * 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 the preliminary data into EbayEnterprise_Dom_Document object and then return * a EbayEnterprise_Dom_Document object * @param int $storeId * @return EbayEnterprise_Dom_Document */ protected function _loadDom($storeId) { $doc = $this->_coreHelper->getNewDomDocument(); $doc->loadXml(sprintf(self::XML_TEMPLATE, self::ROOT_NODE, $this->_getCurrentHostName($storeId), $this->_coreHelper->getConfigModel()->clientId, Mage::getModel('core/date')->date('c'), $this->_catalogHelper->generateMessageHeader($this->_config->imageFeedEventType), $this->_coreHelper->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA))); return $doc; }