/**
  * Create DOMDocumentFragment with the <Item> node.
  * For each pim attribute model given, append DOM to represent the value.
  */
 public function testBuildItemNode()
 {
     $pimAttribute = $this->getModelMockBuilder('ebayenterprise_catalog/pim_attribute')->disableOriginalConstructor()->getMock();
     $pimAttributes = array($pimAttribute);
     $pimProduct = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product')->disableOriginalConstructor()->setMethods(array('getPimAttributes'))->getMock();
     $pimProduct->expects($this->once())->method('getPimAttributes')->will($this->returnValue($pimAttributes));
     $pim = $this->getModelMockBuilder('ebayenterprise_catalog/pim')->setMethods(array('_appendAttributeValue'))->getMock();
     $pim->expects($this->once())->method('_appendAttributeValue')->with($this->isInstanceOf('EbayEnterprise_Dom_Element'), $this->identicalTo($pimAttribute))->will($this->returnSelf());
     $childNode = 'Item';
     $this->_doc->loadXML('<root/>');
     EcomDev_Utils_Reflection::setRestrictedPropertyValue($pim, '_doc', $this->_doc);
     $itemFragment = EcomDev_Utils_Reflection::invokeRestrictedMethod($pim, '_buildItemNode', array($pimProduct, $childNode));
     $this->assertTrue($itemFragment->hasChildNodes(), 'Item fragment is empty');
     $this->_doc->documentElement->appendChild($itemFragment);
     $this->assertSame(1, count($this->_doc->childNodes), 'Item node was not added');
 }
 /**
  * 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());
 }
 /**
  * Test getting the operation type for a product based on when the product
  * was created. If the product was created after the last run of the export,
  * found via a config value, the operation type should be "Add". Otherwise,
  * the operation type should be "Change".
  */
 public function testPassOperationType()
 {
     // As this is a pseudo-product attribute, the value will be empty and the
     // attribute code should will begin with an '_'
     $attributeValue = '';
     $attributeCode = '_operation_type';
     // These time formats match the formats actually being used.
     $addProduct = Mage::getModel('catalog/product', array('created_at' => '2014-02-02 00:00:00'));
     $changeProduct = Mage::getModel('catalog/product', array('created_at' => '2014-01-01 00:00:00'));
     // Any products created after this time should get "Add" operation type,
     // any created before should get "Change" operation type
     $lastRunTime = '2014-01-15T00:00:00+00:00';
     $doc = new EbayEnterprise_Dom_Document();
     $addAttr = $doc->createAttribute('operation_type');
     $addAttr->value = 'Add';
     $changeAttr = $doc->createAttribute('operation_type');
     $changeAttr->value = 'Change';
     // Stub out the config registry and helper that delivers it so a known
     // last run time can be reliably returned.
     $cfg = $this->buildCoreConfigRegistry(array('pimExportFeedCutoffDate' => $lastRunTime));
     $prodHelper = $this->getHelperMock('ebayenterprise_catalog/data', array('getConfigModel'));
     $prodHelper->expects($this->any())->method('getConfigModel')->will($this->returnValue($cfg));
     $this->replaceByMock('helper', 'ebayenterprise_catalog', $prodHelper);
     $changeResult = Mage::helper('ebayenterprise_catalog/pim')->passOperationType($attributeValue, $attributeCode, $changeProduct, $doc);
     $this->assertSame('Change', $changeResult->value);
     $this->assertSame('operation_type', $changeResult->name);
     $addResult = Mage::helper('ebayenterprise_catalog/pim')->passOperationType($attributeValue, $attributeCode, $addProduct, $doc);
     $this->assertSame('Add', $addResult->value);
     $this->assertSame('operation_type', $addResult->name);
 }
    /**
     * Test extractConfigurableAttributesData method for the following expectations
     * Expectation 1: the size attribute will not be present in the result since it will not be in the
     *                attribute set.
     */
    public function testExtractConfigurableAttributesDataNotInSet()
    {
        $catalogId = 54;
        $sku = '54-HTSC883399';
        $styleId = 'HTSC883399';
        $confAttr = 'color,size';
        $data = explode(',', $confAttr);
        $result = array(array('id' => null, 'label' => 'color', 'position' => 0, 'values' => array(), 'attribute_id' => 922, 'attribute_code' => 'color', 'frontend_label' => 'color'), array('id' => null, 'label' => 'size', 'position' => 0, 'values' => array(), 'attribute_id' => 923, 'attribute_code' => 'size', 'frontend_label' => 'size'));
        $doc = new EbayEnterprise_Dom_Document('1.0', 'UTF-8');
        $doc->loadXML('<root>
				<CustomAttributes>
					<Attribute name="ConfigurableAttributes">
						<Value>color</Value>
					</Attribute>
				</CustomAttributes>
			</root>');
        $xpath = new DOMXPath($doc);
        $nodeList = $xpath->query('CustomAttributes/Attribute[@name="ConfigurableAttributes"]/Value', $doc->documentElement);
        $simpleTypeMock = $this->getModelMockBuilder('catalog/product_type_simple')->disableOriginalConstructor()->setMethods(null)->getMock();
        $product = $this->getModelMockBuilder('catalog/product')->disableOriginalConstructor()->setMethods(array('getTypeInstance', 'setTypeId', 'setTypeInstance', 'getSku', 'getStyleId'))->getMock();
        $product->expects($this->at(2))->method('getTypeInstance')->with($this->identicalTo(true))->will($this->returnValue($simpleTypeMock));
        $product->expects($this->once())->method('setTypeId')->with($this->identicalTo(Mage_catalog_Model_Product_Type::TYPE_CONFIGURABLE))->will($this->returnSelf());
        $product->expects($this->once())->method('setTypeInstance')->with($this->isInstanceOf('Mage_Catalog_Model_Product_Type_Abstract'), $this->identicalTo(true))->will($this->returnSelf());
        $product->expects($this->once())->method('getSku')->will($this->returnValue($sku));
        $product->expects($this->once())->method('getStyleId')->will($this->returnValue($styleId));
        $existedConfAttrData = array();
        $configurableTypeMock = $this->getModelMockBuilder('catalog/product_type_configurable')->disableOriginalConstructor()->setMethods(array('getConfigurableAttributesAsArray'))->getMock();
        $configurableTypeMock->expects($this->once())->method('getConfigurableAttributesAsArray')->with($this->identicalTo($product))->will($this->returnValue($existedConfAttrData));
        $product->expects($this->at(5))->method('getTypeInstance')->with($this->identicalTo(true))->will($this->returnValue($configurableTypeMock));
        $coreHelper = $this->getHelperMockBuilder('eb2ccore/data')->disableOriginalConstructor()->setMethods(array('extractNodeVal', 'getConfigModel'))->getMock();
        $coreHelper->expects($this->once())->method('extractNodeVal')->with($this->identicalTo($nodeList))->will($this->returnValue($confAttr));
        $coreHelper->expects($this->any())->method('getConfigModel')->will($this->returnValue($this->buildCoreConfigRegistry(array('catalogId' => $catalogId))));
        $this->replaceByMock('helper', 'eb2ccore', $coreHelper);
        $attributeHelperMock = $this->getHelperMockBuilder('ebayenterprise_catalog/map_attribute')->disableOriginalConstructor()->setMethods(array('_getConfiguredAttributeData', '_isSuperAttributeExists', '_isAttributeInSet', '_turnOffManageStock'))->getMock();
        $attributeHelperMock->expects($this->exactly(1))->method('_getConfiguredAttributeData')->with($this->identicalTo($data[0]))->will($this->returnValue($result[0]));
        $attributeHelperMock->expects($this->any())->method('_isAttributeInSet')->will($this->returnValueMap(array(array('color', $product, true), array('size', $product, false))));
        $attributeHelperMock->expects($this->exactly(2))->method('_isSuperAttributeExists')->will($this->returnValueMap(array(array($existedConfAttrData, $data[0], false), array($existedConfAttrData, $data[1], false))));
        $attributeHelperMock->expects($this->once())->method('_turnOffManageStock')->with($this->identicalTo($product))->will($this->returnSelf());
        $this->assertSame(array($result[0]), $attributeHelperMock->extractConfigurableAttributesData($nodeList, $product));
    }
 /**
  * Create a file from the dom, and return its full path.
  * 'protected' so we can test around it.
  * @param EbayEnterprise_Dom_Document $dom
  * @param int $storeId
  * @return self
  */
 protected function _createFileFromDom(EbayEnterprise_Dom_Document $dom, $storeId)
 {
     $dom->save($this->_generateFilePath($storeId));
     return $this;
 }
 /**
  * setup the document with the root node and the message header.
  * @return self
  */
 protected function _startDocument()
 {
     $config = $this->_getFeedConfig();
     $this->_doc->loadXML(sprintf(self::XML_TEMPLATE, $config[self::KEY_ROOT_NODE], self::XMLNS, $config[self::KEY_SCHEMA_LOCATION], Mage::helper('ebayenterprise_catalog')->generateMessageHeader($config[self::KEY_EVENT_TYPE]), Mage::helper('eb2ccore')->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)));
     return $this;
 }