public function setUp() { $this->_helper = $this->getHelperMock('ebayenterprise_giftcard/data'); $this->_helper->expects($this->any())->method('__')->with($this->isType('string'))->will($this->returnArgument(0)); // disable constructor to prevent having to mock dependencies $this->_checkoutSession = $this->getModelMockBuilder('checkout/session')->disableOriginalConstructor()->setMethods(array('addError'))->getMock(); // disable constructor to prevent having to mock dependencies $this->_giftCardSession = $this->getModelMockBuilder('ebayenterprise_giftcard/session')->disableOriginalConstructor()->setMethods(array('setEbayEnterpriseCurrentGiftCard'))->getMock(); // disable constructor to avoid mocking dependencies $this->_request = $this->getMockBuilder('Mage_Core_Controller_Request_Http')->disableOriginalConstructor()->getMock(); $this->_request->expects($this->any())->method('getParam')->will($this->returnValueMap(array(array(self::CARDNUMBER_FIELD, '', $this->_giftCardNumber), array(self::PIN_FIELD, '', $this->_giftCardPin)))); $this->_giftCard = $this->getMock('EbayEnterprise_GiftCard_Model_IGiftcard'); $this->_giftCard->expects($this->any())->method('setPin')->with($this->isType('string'))->will($this->returnSelf()); // disable constructor to avoid mocking dependencies $this->_container = $this->getMockBuilder('EbayEnterprise_GiftCard_Model_IContainer')->disableOriginalConstructor()->getMock(); // use value map so that if anything other than the giftcard number and pin are passed in, // the function will return null. so tests should fail if a change breaks assumptions about // getGiftCard's arguments. $this->_container->expects($this->any())->method('getGiftCard')->will($this->returnValueMap(array(array($this->_giftCardNumber, $this->_giftCard)))); // disable constructor to avoid mocking dependencies $this->_controller = $this->getMockBuilder('EbayEnterprise_GiftCard_Controller_Abstract')->disableOriginalConstructor()->setMethods(array('_redirect', 'loadLayout', 'renderLayout', 'setFlag'))->getMock(); // inject mocked dependencies EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->_controller, '_container', $this->_container); EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->_controller, '_helper', $this->_helper); EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->_controller, '_request', $this->_request); }
protected function tearDown() { // Restore the original inventory helper instance to the payload helper // to prevent the mock form potentially polluting other tests with // unexpected mock behavior. EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->payloadHelper, 'inventoryHelper', $this->origInventoryHelper); }
/** * * * @param string $type * @param array $requiredKeys * @dataProvider dataProvider * @loadFixture config */ public function testGetDefaultData($type, $requiredKeys) { EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->processor, 'requiredKeys', $requiredKeys); EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->processor, 'type', $type); $dataSet = $this->readAttribute($this, 'dataName'); $this->assertEquals($this->expected($dataSet)->getData(), $this->processor->getDefaultData()); }
/** * Constructor adds test groups defined on global level * and adds additional logic for test names retrieval * * @see PHPUnit_Framework_TestSuite::__construct() */ public function __construct($theClass = '', $groups = array()) { if (!$theClass instanceof ReflectionClass) { $theClass = EcomDev_Utils_Reflection::getReflection($theClass); } // Check annotations for test case name $annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($theClass->getName()); if (isset($annotations['name'])) { $this->suiteName = $annotations['name']; } // Creates all test instances parent::__construct($theClass); // Just sort-out them by our internal groups foreach ($groups as $group) { $this->groups[$group] = $this->tests(); } foreach ($this->tests() as $test) { if ($test instanceof PHPUnit_Framework_TestSuite) { /* @todo * Post an issue into PHPUnit bugtracker for * impossibility for specifying group by parent test case * Because it is a very dirty hack :( **/ $testGroups = array(); foreach ($groups as $group) { $testGroups[$group] = $test->tests(); } EcomDev_Utils_Reflection::setRestrictedPropertyValue($test, 'groups', $testGroups); } } // Remove un grouped tests group, if it exists if (isset($this->groups[self::NO_GROUP_KEYWORD])) { unset($this->groups[self::NO_GROUP_KEYWORD]); } }
public function testRemoveMethod() { EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->mockProxy, 'methods', array('methodName', 'methodName2', 'methodName3')); $this->mockProxy->removeMethod('methodName2'); $this->assertAttributeEquals(array('methodName', 'methodName3'), 'methods', $this->mockProxy); $this->mockProxy->removeMethod('methodName'); $this->assertAttributeEquals(array('methodName3'), 'methods', $this->mockProxy); }
/** * Removes method name from a mock builder * * @param string $methodName * @return $this */ public function removeMethod($methodName) { $methods = ReflectionUtil::getRestrictedPropertyValue($this, 'methods'); $methodIndex = array_search($methodName, $methods); if ($methodIndex !== false) { array_splice($methods, $methodIndex, 1); } ReflectionUtil::setRestrictedPropertyValue($this, 'methods', $methods); return $this; }
/** * Test EbayEnterprise_Catalog_Helper_Map_Stock::_getStockMap method with the following expectations * Expectation 1: when this test invoked this method EbayEnterprise_Catalog_Helper_Map_Stock::_getStockMap * will set the class property EbayEnterprise_Catalog_Helper_Map_Stock::_StockMap with an * array of ROM SalesClass values mapped to valid (we hope) Magento_CatalogInventory_Model_Stock::BACKORDER_xxx value */ public function testGetStockMap() { $mapData = array('advanceOrderOpen' => 1, 'advanceOrderLimited' => 2); $configRegistryMock = $this->getModelMock('eb2ccore/config_registry', array('getConfigData')); $configRegistryMock->expects($this->once())->method('getConfigData')->with($this->identicalTo(EbayEnterprise_Catalog_Helper_Map_Stock::STOCK_CONFIG_PATH))->will($this->returnValue($mapData)); $this->replaceByMock('model', 'eb2ccore/config_registry', $configRegistryMock); $stock = Mage::helper('ebayenterprise_catalog/map_stock'); EcomDev_Utils_Reflection::setRestrictedPropertyValue($stock, '_stockMap', array()); $this->assertSame($mapData, EcomDev_Utils_Reflection::invokeRestrictedMethod($stock, '_getStockMap', array())); }
/** * Test _getGiftCardMap method with the following expectations * Expectation 1: when this test invoked this method EbayEnterprise_Catalog_Helper_Map_Giftcard::_getGiftCardMap * will set the class property EbayEnterprise_Catalog_Helper_Map_Giftcard::_giftcardMap with an * array of eb2c giftcard tender type key map to Magento giftcard type */ public function testGetGiftCardMap() { $mapData = array('SD' => 'virtual', 'SP' => 'physical', 'ST' => 'combined', 'SV' => 'virtual', 'SX' => 'combined'); $configRegistryMock = $this->getModelMock('eb2ccore/config_registry', array('getConfigData')); $configRegistryMock->expects($this->once())->method('getConfigData')->with($this->identicalTo(EbayEnterprise_Catalog_Helper_Feed::GIFTCARD_TENDER_CONFIG_PATH))->will($this->returnValue($mapData)); $this->replaceByMock('model', 'eb2ccore/config_registry', $configRegistryMock); $giftcard = Mage::helper('ebayenterprise_catalog/map_giftcard'); EcomDev_Utils_Reflection::setRestrictedPropertyValue($giftcard, '_giftcardMap', array()); $this->assertSame($mapData, EcomDev_Utils_Reflection::invokeRestrictedMethod($giftcard, '_getGiftCardMap', array())); }
public function tearDown() { $collection = $this->getProductSyncCronScheduleCollection(); foreach ($collection as $item) { $item->delete(); } $resource = Mage::getModel("core/resource"); $resource->getConnection("core_write")->delete($resource->getTableName("klevu_search/order_sync")); EcomDev_Utils_Reflection::setRestrictedPropertyValue(Mage::getConfig(), "_classNameCache", array()); parent::tearDown(); }
/** * Resets translator data * * @return EcomDev_PHPUnit_Model_App_Area */ public function resetTranslate() { $translator = $this->_application->getTranslator(); EcomDev_Utils_Reflection::setRestrictedPropertyValue($translator, '_config', null); EcomDev_Utils_Reflection::setRestrictedPropertyValue($translator, '_locale', null); EcomDev_Utils_Reflection::setRestrictedPropertyValue($translator, '_cacheId', null); EcomDev_Utils_Reflection::setRestrictedPropertyValue($translator, '_translateInline', null); EcomDev_Utils_Reflection::setRestrictedPropertyValue($translator, '_dataScope', null); EcomDev_Utils_Reflection::setRestrictedPropertyValue($translator, '_data', array()); return $this; }
/** * @singleton core/layout */ public function testItReplacesRegularLayoutWithCompilerOne() { $originalValue = Mage::app()->getLayout(); $manager = $this->mockModel('ecomdev_layoutcompiler/manager')->replaceByMock('singleton'); $manager->expects($this->once())->method('isEnabled')->willReturn(true); $layout = $this->getMockForAbstractClass('EcomDev_LayoutCompiler_Contract_LayoutInterface'); $manager->expects($this->once())->method('getLayout')->willReturn($layout); $this->observer->replaceLayout(); $this->assertSame($layout, Mage::registry('_singleton/core/layout')); $this->assertSame($layout, Mage::app()->getLayout()); EcomDev_Utils_Reflection::setRestrictedPropertyValue(Mage::app(), '_layout', $originalValue); }
/** * Test _getAttributeCollection method with the following assumptions * Expectation 1: the class property EbayEnterprise_Catalog_Helper_Attribute::_attributeCollection * will be set to a known value of null, so that when this test invoked the method * EbayEnterprise_Catalog_Helper_Attribute::_getAttributeCollection the mocked * methods Mage_Eav_Model_Resource_Entity_Attribute_Collection::addFieldToFilter and * addExpressionFieldToSelect will be invoked with the specific arguments specified in this test. */ public function testGetAttributeCollection() { $entityTypeId = 4; $collectionMock = $this->getResourceModelMockBuilder('eav/entity_attribute_collection')->disableOriginalConstructor()->setMethods(array('addFieldToFilter', 'addExpressionFieldToSelect'))->getMock(); $collectionMock->expects($this->once())->method('addFieldToFilter')->with($this->identicalTo('entity_type_id'), $this->identicalTo($entityTypeId))->will($this->returnSelf()); $collectionMock->expects($this->once())->method('addExpressionFieldToSelect')->with($this->identicalTo('lcase_attr_code'), $this->identicalTo('LCASE({{attrcode}})'), $this->identicalTo(array('attrcode' => 'attribute_code')))->will($this->returnSelf()); $this->replaceByMock('resource_model', 'eav/entity_attribute_collection', $collectionMock); $attributeHelperMock = $this->getHelperMockBuilder('ebayenterprise_catalog/map_attribute')->disableOriginalConstructor()->setMethods(array('_getEntityTypeId'))->getMock(); $attributeHelperMock->expects($this->once())->method('_getEntityTypeId')->will($this->returnValue($entityTypeId)); EcomDev_Utils_Reflection::setRestrictedPropertyValue($attributeHelperMock, '_attributeCollection', null); $this->assertSame($collectionMock, EcomDev_Utils_Reflection::invokeRestrictedMethod($attributeHelperMock, '_getAttributeCollection', array())); }
/** * Scenario: Get CSR Administrative user startup page URL * When getting CSR Administrative user startup page URL * Then get the user's configured startup URL path * And get the full URL using the startup URL path */ public function testGetStartpageUri() { $adminUrl = 'admin/some/where'; $expectedUrl = "https://example-test.com/index.php/{$adminUrl}"; $url = $this->getModelMockBuilder('adminhtml/url')->disableOriginalConstructor()->setMethods(['getUrl'])->getMock(); $url->expects($this->once())->method('getUrl')->with($this->identicalTo($adminUrl))->will($this->returnValue($expectedUrl)); $user = $this->getModelMockBuilder('admin/user')->disableOriginalConstructor()->setMethods(['getStartupPageUrl'])->getMock(); $user->expects($this->once())->method('getStartupPageUrl')->will($this->returnValue($adminUrl)); $session = $this->getModelMockBuilder('admin/session')->disableOriginalConstructor()->setMethods(['getUser'])->getMock(); $session->expects($this->once())->method('getUser')->will($this->returnValue($user)); EcomDev_Utils_Reflection::setRestrictedPropertyValue($session, 'url', $url); $this->assertSame($expectedUrl, EcomDev_Utils_Reflection::invokeRestrictedMethod($session, '_getStartpageUri')); }
/** * Test validation of the feed config. Provider will give a set of feed config * and if the config is expected to be invalid, the exception message that * should be caught. * @param array $feedConfig * @param string $exceptionMessage * @dataProvider provideFeedConfigForValidation */ public function testValidateFeedConfig($feedConfig, $exceptionMessage) { $feedModelMock = $this->getModelMockBuilder('ebayenterprise_catalog/feed_core')->disableOriginalConstructor()->setMethods(null)->getMock(); $feedModelMock->setFeedConfig($feedConfig); // ensure the list of required config fields are set to an expected set of fields EcomDev_Utils_Reflection::setRestrictedPropertyValue($feedModelMock, '_requiredConfigFields', array('local_directory', 'event_type')); if ($exceptionMessage) { $this->setExpectedException('EbayEnterprise_Catalog_Exception_Feed_File', $exceptionMessage); EcomDev_Utils_Reflection::invokeRestrictedMethod($feedModelMock, '_validateFeedConfig'); } else { $this->assertSame($feedModelMock, EcomDev_Utils_Reflection::invokeRestrictedMethod($feedModelMock, '_validateFeedConfig')); } }
/** * Test that the method ebayenterprise_order/search_process_response_collection::sort() * is invoked, and call the PHP usort() function and pass it the class property * ebayenterprise_order/search_process_response_collection::$_items as first parameter * and an array with one element as the ebayenterprise_order/search_process_response_collection * object and another element as the string literal for the method _sortOrdersMostRecentFirst. * Then, the method ebayenterprise_order/search_process_response_collection::_sortOrdersMostRecentFirst() * will be invoked and passed in the Varien_Object parameters in the class property * ebayenterprise_order/search_process_response_collection::$_items. Finally, the method * ebayenterprise_order/search_process_response_collection::sort() will return itself. */ public function testSearchProcessResponseCollectionSort() { /** @var Varien_Object */ $varienObjectA = new Varien_Object(); /** @var Varien_Object */ $varienObjectB = new Varien_Object(); /** @var EbayEnterprise_Order_Model_Search_Process_Response_ICollection */ $collection = $this->getModelMock('ebayenterprise_order/search_process_response_collection', ['_sortOrdersMostRecentFirst']); $collection->expects($this->once())->method('_sortOrdersMostRecentFirst')->with($this->identicalTo($varienObjectB), $this->identicalTo($varienObjectA))->will($this->returnValue(true)); // Set the class property ebayenterprise_order/search_process_response_collection::$_items // to an array of Varien_Object. EcomDev_Utils_Reflection::setRestrictedPropertyValue($collection, '_items', [$varienObjectA, $varienObjectB]); $this->assertSame($collection, $collection->sort()); }
/** * verify: * - given an array with a 'token' key; the token will be stored as additionalinformation in the payment info model. * - the method will work with a varien object as well. * * @dataProvider provideTrueFalse */ public function testAssignData($isDataObject) { $data = array('token' => 'thetokenstring', 'ignored_field' => 'ignored_value', 'shipping_address' => ['status' => 'right one'], 'billing_address' => ['status' => 'wrong one']); if ($isDataObject) { $data = new Varien_Object($data); } $express = Mage::getModel('ebayenterprise_paypal/method_express'); $info = Mage::getModel('payment/info'); EcomDev_Utils_Reflection::setRestrictedPropertyValue($express, '_selectorKeys', array('token')); $express->setData('info_instance', $info); $express->assignData($data); $this->assertSame('thetokenstring', $info->getAdditionalInformation('token')); $this->assertSame('right one', $info->getAdditionalInformation(EbayEnterprise_PayPal_Model_Express_Checkout::PAYMENT_INFO_ADDRESS_STATUS)); }
public function setUp() { $this->helper = $this->getHelperMock('ebayenterprise_giftcard/data'); $this->helper->expects($this->any())->method('__')->with($this->isType('string'))->will($this->returnArgument(0)); // disable constructor to prevent having to mock dependencies $this->checkoutSession = $this->getModelMockBuilder('checkout/session')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->giftCard = $this->getMock('EbayEnterprise_GiftCard_Model_IGiftcard'); $this->giftCard->expects($this->any())->method('setPin')->with($this->isType('string'))->will($this->returnSelf()); // disable constructor to avoid mocking dependencies $this->container = $this->getMockBuilder('EbayEnterprise_GiftCard_Model_IContainer')->disableOriginalConstructor()->getMock(); $this->container->expects($this->any())->method('getGiftCard')->will($this->returnValue($this->giftCard)); // disable constructor to avoid mocking dependencies $this->controller = $this->getMockBuilder('EbayEnterprise_GiftCard_CartController')->disableOriginalConstructor()->setMethods(['_redirect', '_rewrite', 'setFlag', '_getCardInfoFromRequest'])->getMock(); $this->controller->expects($this->once())->method('_getCardInfoFromRequest')->will($this->returnValue([$this->giftCardNumber, $this->giftCardPin])); // inject mocked dependencies EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->controller, '_container', $this->container); EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->controller, '_helper', $this->helper); }
/** * Test that the method ebayenterprise_order/detail_process_response::process() * is invoked, and it will call the method ebayenterprise_order/detail_process_response::_processResponse(). * Finally, the method ebayenterprise_order/detail_process_response::process() will return an instance of type * EbayEnterprise_Order_Model_Detail_Process_IResponse. * * @param IOrderDetailResponse | null * @dataProvider providerProcessOrderDetailResponsePayload */ public function testProcessOrderDetailResponsePayload($response) { /** @var bool */ $invalidResponse = is_null($response); /** @var Mock_EbayEnterprise_Order_Model_Detail_Process_Response */ $detailProcessResponse = $this->getModelMockBuilder('ebayenterprise_order/detail_process_response')->disableOriginalConstructor()->setMethods(['_populateOrder', '_populateOrderAddress', '_determineBillingAddress', '_determineShippingAddress', '_populateOrderItem', '_populateOrderPayment', '_populateOrderShipment', '_populateOrderShipGroup'])->getMock(); // Set the class property ebayenterprise_order/detail_process_response::$_response to a known state EcomDev_Utils_Reflection::setRestrictedPropertyValue($detailProcessResponse, '_response', $response); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_populateOrder')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_populateOrderAddress')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_determineBillingAddress')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_determineShippingAddress')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_populateOrderItem')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_populateOrderPayment')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_populateOrderShipment')->will($this->returnSelf()); $detailProcessResponse->expects($invalidResponse ? $this->never() : $this->once())->method('_populateOrderShipGroup')->will($this->returnSelf()); $this->assertSame($detailProcessResponse, $detailProcessResponse->process()); }
/** * Applies fixture configuration values into Mage_Core_Model_Config * * @param array $configuration * @return $this * @throws InvalidArgumentException */ protected function _applyConfig($configuration) { if (!is_array($configuration)) { throw new InvalidArgumentException('Configuration part should be an associative list'); } Mage::getConfig()->loadScopeSnapshot(); foreach ($configuration as $path => $value) { $this->_setConfigNodeValue($path, $value); } Mage::getConfig()->loadDb(); // Flush website and store configuration caches foreach (Mage::app()->getWebsites(true) as $website) { EcomDev_Utils_Reflection::setRestrictedPropertyValue($website, '_configCache', array()); } foreach (Mage::app()->getStores(true) as $store) { EcomDev_Utils_Reflection::setRestrictedPropertyValue($store, '_configCache', array()); } return $this; }
/** * Scenario: When setting the region code provided by paypal * we may receive the full region name. If this is a US region * the desired result would be to use the 2-character region code. */ public function testSetQuoteAddressRegion() { /** @var Mage_Sales_Model_Quote_Address $quoteAddress */ $quoteAddress = Mage::getModel('sales/quote_address'); // testing US regions only $quoteAddress->setCountryId(self::COUNTRY_CODE); /** @var EbayEnterprise_PayPal_Helper_Region $regionHelper */ $regionHelper = Mage::helper('ebayenterprise_paypal/region'); // mock region resource to stub the load method $regionResource = $this->getResourceModelMock('directory/region', ['loadByName']); EcomDev_Utils_Reflection::setRestrictedPropertyValue($regionHelper, 'regionResource', $regionResource); // rewrite model with mocked region directory $regionDirectory = $this->getModelMock('directory/region'); $regionDirectory->method('getId')->will($this->returnValue(self::REGION_ID)); $regionDirectory->method('getCode')->will($this->returnValue(self::REGION_CODE)); $this->replaceByMock('model', 'directory/region', $regionDirectory); // mutate the quote address $regionHelper->setQuoteAddressRegion($quoteAddress, self::REGION_NAME); // test for mutation $this->assertSame(self::REGION_CODE, $quoteAddress->getRegionCode()); }
protected function tearDown() { // Restore the original log context instance. EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->helper, 'logContext', $this->origLogContext); }
/** * verify a fragment is returned containing the nodes for the category links */ public function testPassCategoryLinks() { $doc = $this->_newDocument('<root/>'); $pimHelper = $this->getHelperMock('ebayenterprise_catalog/pim', array('none')); $product = $this->getModelMock('catalog/product', array('getCategoryCollection')); $collection = $this->getResourceModelMockBuilder('catalog/category_collection')->disableOriginalConstructor()->setMethods(array('getItemById', 'load', 'addAttributeToSelect'))->getMock(); $category = $this->getModelMock('catalog/category', array('getPath', 'getName', 'getId')); $category2 = $this->getModelMock('catalog/category', array('getPath', 'getName', 'getId')); $product->expects($this->any())->method('getCategoryCollection')->will($this->returnValue($collection)); $category->expects($this->any())->method('getId')->will($this->returnValue(1)); $category->expects($this->any())->method('getPath')->will($this->returnValue('1')); $category->expects($this->any())->method('getName')->will($this->returnValue('parent')); $category2->expects($this->any())->method('getId')->will($this->returnValue(18)); $category2->expects($this->any())->method('getPath')->will($this->returnValue('1/18')); $category2->expects($this->any())->method('getName')->will($this->returnValue('child')); $collection->expects($this->any())->method('getItemById')->will($this->returnValueMap(array(array(1, $category), array(18, $category2)))); $collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); $collection->expects($this->any())->method('load')->will($this->returnSelf()); EcomDev_Utils_Reflection::setRestrictedPropertyValue($collection, '_items', array($category, $category2)); $this->replaceByMock('resource_model', 'catalog/category_collection', $collection); $result = $pimHelper->passCategoryLinks('dontcare', 'dontcare', $product, $doc); $this->assertNotNull($result); $doc->documentElement->appendChild($result); $expected = $this->_newDocument(' <root> <CategoryLink import_mode="Replace"> <Name><![CDATA[parent]]></Name> </CategoryLink> <CategoryLink import_mode="Replace"> <Name><![CDATA[parent-child]]></Name> </CategoryLink> </root>'); $this->assertSame($expected->saveXML(), $doc->saveXML()); }
/** * Get files to process should return an array of file details for all files * that should be processed by the product feed model. A list of files for * each type of feed (item, content, etc.) should be retrieved using each * of the core feed models loaded during construction. The maps of file * details should all be created using the _unifiedAllFiles method to create * the maps and merge them with any previously created file details. * The list of file details should finally be sorted, using the * _compareFeedFiles method. * @mock EbayEnterprise_Catalog_Model_Feed::_unifiedAllFiles * @mock EbayEnterprise_Catalog_Model_Feed::_compareFeedFiles * @mock EbayEnterprise_Catalog_Helper_Data::buildErrorFeedFilename * @mock EbayEnterprise_Catalog_Model_Error_Confirmations::loadFile * @mock EbayEnterprise_Catalog_Model_Error_Confirmations::initFeed */ public function testGetFilesToProcess() { $coreFeed = $this->getModelMockBuilder('ebayenterprise_catalog/feed_core')->disableOriginalConstructor()->setMethods(array('lsLocalDirectory', 'getEventType'))->getMock(); $prodHelper = $this->getHelperMock('ebayenterprise_catalog/data', array('buildErrorFeedFilename')); $errorConfirmations = $this->getModelMockBuilder('ebayenterprise_catalog/error_confirmations')->setMethods(array('loadFile', 'initFeed'))->getMock(); $prodFeed = $this->getModelMockBuilder('ebayenterprise_catalog/feed')->setMethods(array('_unifiedAllFiles', '_compareFeedFiles'))->getMock(); $this->replaceByMock('model', 'ebayenterprise_catalog/error_confirmations', $errorConfirmations); $this->replaceByMock('helper', 'ebayenterprise_catalog', $prodHelper); $localFile = '/Mage/var/local/file.xml'; $eventType = 'SomeEvent'; $errorFile = 'error_file.xml'; $fileDetails = array('local_file' => $localFile, 'timestamp' => '2014-03-02 11:11:11', 'core_feed' => $coreFeed, 'error_file' => $errorFile); $coreFeed->expects($this->once())->method('lsLocalDirectory')->will($this->returnValue(array($localFile))); $coreFeed->expects($this->once())->method('getEventType')->will($this->returnValue($eventType)); $prodHelper->expects($this->once())->method('buildErrorFeedFilename')->with($this->identicalTo($eventType))->will($this->returnValue($errorFile)); $errorConfirmations->expects($this->once())->method('loadFile')->with($this->identicalTo($errorFile))->will($this->returnSelf()); $errorConfirmations->expects($this->once())->method('initFeed')->with($this->identicalTo($eventType))->will($this->returnSelf()); $prodFeed->expects($this->once())->method('_unifiedAllFiles')->with($this->identicalTo(array()), $this->identicalTo(array($localFile)), $this->identicalTo($coreFeed), $this->identicalTo($errorFile))->will($this->returnValue(array($fileDetails))); $prodFeed->expects($this->any())->method('_compareFeedFiles')->will($this->returnValue(0)); // set the core feed models to a single known core feed EcomDev_Utils_Reflection::setRestrictedPropertyValue($prodFeed, '_coreFeedTypes', array($coreFeed)); $this->assertSame(array($fileDetails), EcomDev_Utils_Reflection::invokeRestrictedMethod($prodFeed, '_getFilesToProcess')); }
/** * Test _getDefaultParentCategoryId method */ public function testGetDefaultParentCategoryId() { $catogyCollectionModelMock = $this->getResourceModelMockBuilder('catalog/category_collection')->disableOriginalConstructor()->setMethods(array('addAttributeToSelect', 'addAttributeToFilter', 'getFirstItem'))->getMock(); $catogyCollectionModelMock->expects($this->once())->method('addAttributeToSelect')->with($this->equalTo('entity_id'))->will($this->returnSelf()); $catogyCollectionModelMock->expects($this->once())->method('addAttributeToFilter')->with($this->equalTo('parent_id'), $this->equalTo(array('eq' => 0)))->will($this->returnSelf()); $catogyCollectionModelMock->expects($this->once())->method('getFirstItem')->will($this->returnValue(Mage::getModel('catalog/category')->addData(array('entity_id' => 1)))); $this->replaceByMock('resource_model', 'catalog/category_collection', $catogyCollectionModelMock); $helper = Mage::helper('ebayenterprise_catalog'); EcomDev_Utils_Reflection::setRestrictedPropertyValue($helper, '_defaultParentCategoryId', null); $this->assertSame(1, $helper->getDefaultParentCategoryId()); }
/** * @see self::testGetFeedAttributes; however, this test is testing * when the passed in store id is not equal to the default store view store id * it expects only translatable attributes to be returned. */ public function testGetFeedAttributesTranslatableAttributes() { $storeId = 2; $pimModelMock = $this->getModelMockBuilder('ebayenterprise_catalog/pim')->setMethods(array())->getMock(); EcomDev_Utils_Reflection::setRestrictedPropertyValue($pimModelMock, '_batch', $this->_batch); // use array_values because we dont care about the indices of the elements. $this->assertSame($this->_translatableAttributes, array_values(EcomDev_Utils_Reflection::invokeRestrictedMethod($pimModelMock, '_getFeedAttributes', array($storeId)))); }
/** * Get around Magento's aggressive caching strategy and actually clear the configuration cache. */ protected function clearConfigCache() { // Flush website and store configuration caches foreach (Mage::app()->getWebsites(true) as $website) { EcomDev_Utils_Reflection::setRestrictedPropertyValue($website, '_configCache', array()); } foreach (Mage::app()->getStores(true) as $store) { EcomDev_Utils_Reflection::setRestrictedPropertyValue($store, '_configCache', array()); } }
/** * Will return the last item if there are items in the collection. */ public function testGetLastItem() { $pimProduct = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product')->disableOriginalConstructor()->getMock(); $collection = Mage::getModel('ebayenterprise_catalog/pim_product_collection'); EcomDev_Utils_Reflection::setRestrictedPropertyValue($collection, '_items', array($pimProduct)); $this->assertSame($pimProduct, $collection->getLastItem()); }
/** * */ protected function tearDown() { EcomDev_Utils_Reflection::setRestrictedPropertyValue('Hackathon_FixtureGenerator_Model_Generator_Container', 'generators', $this->originalGenerators); }
/** * Run all of the indexers. * * @return $this */ protected function reindexAll() { $indexer = Mage::getSingleton('index/indexer'); // Delete all index events $index_events = Mage::getResourceModel("index/event_collection"); foreach ($index_events as $event) { /** @var Mage_Index_Model_Event $event */ $event->delete(); } // Remove the stores cache from the category product index if ($process = $indexer->getProcessByCode("catalog_category_product")) { EcomDev_Utils_Reflection::setRestrictedPropertyValue($process->getIndexer()->getResource(), "_storesInfo", null); } $processes = $indexer->getProcessesCollection(); // Reset all the indexers foreach ($processes as $process) { /** @var Mage_Index_Model_Process $process */ if ($process->hasData('runed_reindexall')) { $process->setData('runed_reindexall', false); } } // Run all indexers foreach ($processes as $process) { /** @var Mage_Index_Model_Process $process */ $process->reindexEverything(); } return $this; }
/** * For each item given, a new order item payload should be created, * dispatched in an event with the Magento order item, and added to an * item reference payload in the order item reference container. */ public function testAddOrderItemReferences() { // stub the event observer so the orderitem handler doesn't interfere with the test $this->replaceByMock('model', 'ebayenterprise_order/observer', $this->_observerStub); $itemRefContainer = $this->_request->getShipGroups()->getEmptyShipGroup(); $items = [Mage::getModel('sales/order_item'), Mage::getModel('sales/order_item')]; $orderItems = $this->_request->getOrderItems(); $constructorArgs = ['api' => $this->_httpApi, 'config' => $this->_config, 'order' => $this->_order, 'payload' => $this->_requestStub]; $handler = $this->getModelMockBuilder('ebayenterprise_order/create_orderitem')->disableOriginalConstructor()->getMock(); $create = Mage::getModel('ebayenterprise_order/create', $constructorArgs); EcomDev_Utils_Reflection::setRestrictedPropertyValue($create, '_defaultItemHandler', $handler); $references = EcomDev_Utils_Reflection::invokeRestrictedMethod($create, '_addOrderItemReferences', [$itemRefContainer, $items, $orderItems, $this->_shipAddress, $this->_order]); // Should be one item reference and one event dispatched for each item. $expectedCount = count($items); $this->assertCount($expectedCount, $references->getItemReferences()); $this->assertEventDispatchedExactly('ebayenterprise_order_create_item', $expectedCount); }