/**
  * 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 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));
    }
 /**
  * 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;
 }