/**
  * Test version
  *
  * @param string[]|string $directories
  * @param string $type
  * @param string $from
  * @param string $to
  *
  * @return void
  * @dataProvider dataProvider
  */
 public function testGetVersionScriptsDiff($directories, $type, $from, $to)
 {
     $virtualPath = $this->getVirtualPath($directories);
     $versions = EcomDev_Utils_Reflection::invokeRestrictedMethod($this->constraint, 'parseVersions', array($virtualPath));
     $result = EcomDev_Utils_Reflection::invokeRestrictedMethod($this->constraint, 'getVersionScriptsDiff', array($versions[$type], $from, $to, $type === 'data' ? 'data-' : ''));
     $this->assertEquals($this->expected('auto')->getDiff(), $result);
 }
 public function testReturnsCorrectImageProcessorClass()
 {
     /** @var $image Varien_Image */
     $image = $this->_model->getImageProcessor();
     $adapterClass = EcomDev_Utils_Reflection::invokeRestrictedMethod($image, '_getAdapter');
     $this->assertInstanceOf('Varien_Image_Adapter_Abstract', $adapterClass);
 }
 /**
  * verify
  * - the localized and default values are returned
  * - if the option does not exist, null is returned
  *   for both default and localized values
  *
  * @param  string $method
  * @param  string $localizedValue
  * @param  string $defaultValue
  * @dataProvider provideForSizeColorInfo
  */
 public function testGetItemColorAndSizeInfo($method, $localizedValue, $defaultValue)
 {
     $this->replaceByMock('resource_model', 'eav/entity_attribute_option_collection', $this->optionValueCollectionStub);
     $this->optionValueCollectionStub->addItem(Mage::getModel('eav/entity_attribute_option', ['attribute_code' => 'color', 'option_id' => 15, 'value' => 'Black', 'default_value' => '2']));
     $handler = Mage::getModel('ebayenterprise_order/create_orderitem');
     $this->assertSame([$localizedValue, $defaultValue], EcomDev_Utils_Reflection::invokeRestrictedMethod($handler, $method, [$this->itemStub]));
 }
 /**
  * will log a warning when the result code is
  * for an error or is unknown
  * @dataProvider provideFailureResultCodes
  */
 public function testLogResultCodeWithError($code)
 {
     $response = $this->getModelMockBuilder('ebayenterprise_address/validation_response')->setConstructorArgs([['api' => $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi'), 'logger' => $this->logger, 'context' => $this->context]])->setMethods(['extractResponseData'])->getMock();
     $response->setResultCode($code);
     $this->logger->expects($this->once())->method('warning');
     EcomDev_Utils_Reflection::invokeRestrictedMethod($response, 'logResultCode');
 }
 /**
  * GIVEN An <sdkApi> that will thrown an <exception> of <exceptionType> when making a request.
  * WHEN A request is made.
  * THEN The <exception> will be caught.
  * AND An exception of <expectedExceptionType> will be thrown.
  *
  * @param string
  * @param string
  * @dataProvider provideSdkExceptions
  */
 public function testSdkExceptionHandling($exceptionType, $expectedExceptionType)
 {
     $exception = new $exceptionType(__METHOD__ . ': Test Exception');
     $this->api->method('send')->will($this->throwException($exception));
     $this->setExpectedException($expectedExceptionType);
     EcomDev_Utils_Reflection::invokeRestrictedMethod($this->allocator, 'makeRequest', [$this->api]);
 }
 /**
  * Test _getGiftCardType method for the following expectations
  * Expectation 1: when this test invoked the method EbayEnterprise_Catalog_Helper_Map_Giftcard::_getGiftCardType
  *                with string of each giftcard constant type it will return the gift card constant value
  */
 public function testGetGiftCardType()
 {
     $testData = array(array('expect' => Enterprise_GiftCard_Model_Giftcard::TYPE_VIRTUAL, 'type' => EbayEnterprise_Catalog_Helper_Map_Giftcard::GIFTCARD_VIRTUAL), array('expect' => Enterprise_GiftCard_Model_Giftcard::TYPE_PHYSICAL, 'type' => EbayEnterprise_Catalog_Helper_Map_Giftcard::GIFTCARD_PHYSICAL), array('expect' => Enterprise_GiftCard_Model_Giftcard::TYPE_COMBINED, 'type' => EbayEnterprise_Catalog_Helper_Map_Giftcard::GIFTCARD_COMBINED));
     $giftcard = Mage::helper('ebayenterprise_catalog/map_giftcard');
     foreach ($testData as $data) {
         $this->assertSame($data['expect'], EcomDev_Utils_Reflection::invokeRestrictedMethod($giftcard, '_getGiftCardType', array($data['type'])));
     }
 }
 /**
  * Before an item is saved, if the item has an associated order address
  * with a valid id, the id of the order address should be set on the item.
  */
 public function testBeforeSave()
 {
     $addressId = 8;
     $address = Mage::getModel('sales/order_address', ['entity_id' => $addressId]);
     $this->_item->setOrderAddress($address);
     EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_item, '_beforeSave');
     $this->assertSame($addressId, $this->_item->getOrderAddressId());
 }
 /**
  * Test getting the fields to include in the feed. Should be pulling the
  * comma-separated list of fields from config.xml and splitting it to produce
  * an array of fields.
  * @return array
  */
 public function testFeedFields()
 {
     $config = $this->getHelperMock('eems_affiliate/config', array('getItemizedOrderFeedFields'));
     $config->expects($this->any())->method('getItemizedOrderFeedFields')->will($this->returnValue('one,two,three'));
     $this->replaceByMock('helper', 'eems_affiliate/config', $config);
     $feed = Mage::getModel('eems_affiliate/feed_order_itemized');
     $this->assertSame(array('one', 'two', 'three'), EcomDev_Utils_Reflection::invokeRestrictedMethod($feed, '_getFeedFields'));
 }
 public function testConfigurationSavedIfModuleNotInstalled()
 {
     $imagemagickMock = $this->getMock('Varien_Image_Adapter_Imagemagic', array('checkDependencies'));
     $imagemagickMock->expects($this->any())->method('checkDependencies')->will($this->returnValue(true));
     $this->_model->setImageAdapter($imagemagickMock);
     $this->_model->setValue(Varien_Image_Adapter::ADAPTER_GD2);
     EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_model, '_beforeSave');
     $this->assertEquals(Varien_Image_Adapter::ADAPTER_GD2, $this->_model->getValue());
 }
 public function testGetTenderTypeLookupApi()
 {
     $service = 'payments';
     $operation = 'tendertype/lookup';
     $tenderTypeHelper = $this->getHelperMockBuilder('ebayenterprise_giftcard/tendertype')->setMethods(null)->setConstructorArgs([$this->constructorArgs])->getMock();
     $this->api = $this->getMockBuilder('\\eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi')->getMockForAbstractClass();
     $this->coreHelper->expects($this->once())->method('getSdkApi')->with($this->identicalTo($service), $this->identicalTo($operation), $this->identicalTo([]), $this->identicalTo($this->apiLogger))->will($this->returnValue($this->api));
     $this->assertSame($this->api, EcomDev_Utils_Reflection::invokeRestrictedMethod($tenderTypeHelper, 'getTenderTypeLookupApi'));
 }
 /**
  * Create the item's identifier by using the sku, client id and catalog id
  * of the item to create an ID.
  */
 public function testGetItemId()
 {
     $item = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product')->disableOriginalConstructor()->setMethods(array('getSku', 'getClientId', 'getCatalogId'))->getMock();
     $collection = $this->getModelMock('ebayenterprise_catalog/pim_product_collection', array('_formatId'));
     $item->expects($this->once())->method('getSku')->will($this->returnValue('45-12345'));
     $item->expects($this->once())->method('getClientId')->will($this->returnValue('clientId'));
     $item->expects($this->once())->method('getCatalogId')->will($this->returnValue('catalogId'));
     $collection->expects($this->once())->method('_formatId')->with($this->identicalTo('45-12345'), $this->identicalTo('clientId'), $this->identicalTo('catalogId'))->will($this->returnValue('45-12345-clientId-catalogId'));
     $this->assertSame('45-12345-clientId-catalogId', EcomDev_Utils_Reflection::invokeRestrictedMethod($collection, '_getItemId', array($item)));
 }
 /**
  * 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 that the method ebayenterprise_order/search_process_response_collection::_sortOrdersMostRecentFirst()
  * is invoked, and it will be passed in an object of type Varien_Object as parameter 1 and 2. When the
  * Varien_Object instance of parameter one has an order date greater and the Varien_Object instance of
  * parameter two, then the method ebayenterprise_order/search_process_response_collection::_sortOrdersMostRecentFirst()
  * will return boolean false, otherwise it will return true.
  *
  * @param string
  * @param string
  * @param bool
  * @dataProvider providerSortOrdersMostRecentFirst
  */
 public function testSortOrdersMostRecentFirst($orderDateA, $orderDateB, $result)
 {
     /** @var EbayEnterprise_Order_Model_Search_Process_Response_ICollection */
     $collection = Mage::getModel('ebayenterprise_order/search_process_response_collection');
     /** @var Varien_Object */
     $varienObjectA = new Varien_Object(['order_date' => $orderDateA]);
     /** @var Varien_Object */
     $varienObjectB = new Varien_Object(['order_date' => $orderDateB]);
     $this->assertSame($result, EcomDev_Utils_Reflection::invokeRestrictedMethod($collection, '_sortOrdersMostRecentFirst', [$varienObjectA, $varienObjectB]));
 }
 /**
  * verify an exception is thrown when missing arguments
  */
 public function testConstructInvalidArguments()
 {
     $expectedException = sprintf(EbayEnterprise_Catalog_Model_Pim_Product::ERROR_INVALID_ARGS, 'EbayEnterprise_Catalog_Model_Pim_Product::_construct', 'client_id, catalog_id, sku');
     $initParams = array();
     $this->setExpectedException('Exception', $expectedException);
     $helper = $this->getHelperMockBuilder('eb2ccore/data')->disableOriginalConstructor()->setMethods(array('triggerError'))->getMock();
     $helper->expects($this->once())->method('triggerError')->with($this->identicalTo($expectedException))->will($this->throwException(new Exception($expectedException)));
     $this->replaceByMock('helper', 'eb2ccore', $helper);
     $product = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product')->disableOriginalConstructor()->setMethods(null)->getMock();
     EcomDev_Utils_Reflection::invokeRestrictedMethod($product, '_construct', array($initParams));
 }
 /**
  * Test getting the last saved test message timestamp to be displayed in the
  * admin.
  * @param string|null $timestamp
  * @param string $value
  * @dataProvider provideLastTimestamp
  */
 public function testAfterLoad($lastTimestamp, $value)
 {
     // suppression the real session from starting
     $session = $this->getModelMockBuilder('core/session')->disableOriginalConstructor()->setMethods(null)->getMock();
     $this->replaceByMock('singleton', 'core/session', $session);
     $helper = $this->getHelperMock('ebayenterprise_amqp/data');
     $helper->expects($this->any())->method('__')->will($this->returnArgument(0));
     $lasttestmessage = Mage::getModel('ebayenterprise_amqp/adminhtml_system_config_backend_lasttestmessage', array('value' => $lastTimestamp, 'helper' => $helper));
     EcomDev_Utils_Reflection::invokeRestrictedMethod($lasttestmessage, '_afterLoad');
     $this->assertSame($value, $lasttestmessage->getValue());
 }
 /**
  * When a language code is found to be invalid, an exception should be thrown.
  */
 public function testInvalidLanguageCodeException()
 {
     $mockLangHelper = $this->getHelperMock('eb2ccore/languages', ['validateLanguageCode']);
     $mockLangHelper->expects($this->any())->method('validateLanguageCode')->will($this->returnValue(false));
     $mockCoreHelper = $this->getHelperMock('eb2ccore/data', ['__']);
     $mockCoreHelper->expects($this->any())->method('__')->will($this->returnArgument(0));
     $backendMock = $this->getModelMockBuilder('eb2ccore/system_config_backend_language_code')->setMethods(array('isValueChanged'))->setConstructorArgs([['language_helper' => $mockLangHelper, 'core_helper' => $mockCoreHelper]])->getMock();
     $backendMock->expects($this->once())->method('isValueChanged')->will($this->returnValue(true));
     $this->setExpectedException('EbayEnterprise_Eb2cCore_Exception');
     EcomDev_Utils_Reflection::invokeRestrictedMethod($backendMock->setValue("invalidlangcode"), '_beforeSave');
 }
 /**
  * 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 that the method ebayenterprise_order/detail_build_request::_buildPayload()
  * is invoked, and it will call the method IOrderDetailRequest::setOrderType() and passed in
  * the class constant EbayEnterprise_Order_Model_Detail_Build_IRequest::DEFAULT_ORDER_DETAIL_SEARCH_TYPE.
  * Then, the method IOrderDetailRequest::setCustomerOrderId() will be invoked and passed in
  * the order id. Finally, the method ebayenterprise_order/detail_build_request::_buildPayload() will
  * return itself.
  */
 public function testBuildPayloadForOrderDetailRequest()
 {
     /** @var string */
     $orderId = '1000049499939393881';
     /** @var Mock_IOrderDetailRequest */
     $payload = $this->getMockBuilder(static::PAYLOAD_CLASS)->disableOriginalConstructor()->setMethods(['setOrderType', 'setCustomerOrderId'])->getMock();
     $payload->expects($this->once())->method('setOrderType')->with($this->identicalTo(EbayEnterprise_Order_Model_Detail_Build_IRequest::DEFAULT_ORDER_DETAIL_SEARCH_TYPE))->will($this->returnSelf());
     $payload->expects($this->once())->method('setCustomerOrderId')->with($this->identicalTo($orderId))->will($this->returnSelf());
     $this->_api->expects($this->any())->method('getRequestBody')->will($this->returnValue($payload));
     /** @var Mock_EbayEnterprise_Order_Model_Detail_Build_Request */
     $buildRequest = $this->getModelMock('ebayenterprise_order/detail_build_request', ['foo'], false, [['order_id' => $orderId, 'api' => $this->_api]]);
     $this->assertSame($buildRequest, EcomDev_Utils_Reflection::invokeRestrictedMethod($buildRequest, '_buildPayload', []));
 }
 public function testStringifyValue()
 {
     $attrModel = $this->getModelMockBuilder('ebayenterprise_catalog/pim_attribute')->disableOriginalConstructor()->setMethods(null)->getMock();
     $dom = Mage::helper('eb2ccore')->getNewDomDocument();
     $n = $dom->createDocumentFragment();
     $n->appendChild($dom->createElement('Foo', 'Value'));
     $n->appendChild($dom->createElement('Bar', 'Thing'));
     $attrModel->value = $n;
     $this->assertSame('<Foo>Value</Foo><Bar>Thing</Bar>', EcomDev_Utils_Reflection::invokeRestrictedMethod($attrModel, '_stringifyValue'));
     $n = $dom->createCDATASection('Some String Value');
     $attrModel->value = $n;
     $this->assertSame('Some String Value', EcomDev_Utils_Reflection::invokeRestrictedMethod($attrModel, '_stringifyValue'));
     $n = $dom->createElement('Foo', 'Bar');
     $attrModel->value = $n;
     $this->assertSame('<Foo>Bar</Foo>', EcomDev_Utils_Reflection::invokeRestrictedMethod($attrModel, '_stringifyValue'));
 }
 /**
  * Test that the method ebayenterprise_inventory/allocation_service::isAllItemBackorderableAndOutOfStock()
  * when invoked, will return true, if the method ebayenterprise_inventory/allocation_service::isAllocatable()
  * return false otherwise it will return true.
  *
  * @param bool
  * @param bool
  * @dataProvider providerIsAllItemBackorderableAndOutOfStock
  */
 public function testIsAllItemBackorderableAndOutOfStock($isAllocatable, $result)
 {
     /** @var EbayEnterprise_Inventory_Model_Quantity_Service $quantityService */
     $quantityService = $this->getModelMock('ebayenterprise_inventory/quantity_service', ['canSendInventoryAllocation']);
     $quantityService->expects($this->once())->method('canSendInventoryAllocation')->will($this->returnValue($isAllocatable));
     /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
     $stockItem = Mage::getModel('cataloginventory/stock_item');
     /** @var Mage_Catalog_Model_Product $product */
     $product = Mage::getModel('catalog/product', ['stock_item' => $stockItem]);
     /** @var Mage_Sales_Model_Quote_Item $item */
     $item = Mage::getModel('sales/quote_item', ['product' => $product]);
     /** @var Mage_Sales_Model_Quote $quote */
     $quote = Mage::getModel('sales/quote')->addItem($item);
     /** Mock_EbayEnterprise_Inventory_Model_Allocation_Service $allocationService */
     $allocationService = Mage::getModel('ebayenterprise_inventory/allocation_service', ['quantity_service' => $quantityService]);
     $this->assertSame($result, EcomDev_Utils_Reflection::invokeRestrictedMethod($allocationService, 'isAllItemBackorderableAndOutOfStock', [$quote]));
 }
 /**
  * Test that the method ebayenterprise_order/search_process_response_map::_extractData()
  * is invoked, and it will loop through the magic config registry eb2ccore/config_registry::$mapSearchResponse.
  * For each key that has an array with key 'type' that is not equal to disabled, then
  * Add a key 'parameters' mapped to an array with element of type IOrderSummary and the value
  * from the key 'getter'. Then, invoked the method eb2ccore/data::invokeCallback() passing
  * in an array with key/value pairs. When loop has ended the method
  * ebayenterprise_order/search_process_response_map::_extractData() will simply return
  * an array with with key/value pairs.
  */
 public function testSearchProcessResponseCollectionSort()
 {
     /** @var array */
     $mapSearchResponse = ['rom_id' => ['class' => 'ebayenterprise_order/search_map', 'type' => 'helper', 'method' => 'getStringValue', 'getter' => 'getId']];
     /** @var string */
     $callbackReturnValue = 'order-73772877776671622716767';
     /** @var array */
     $summaryData = ['rom_id' => $callbackReturnValue];
     /** @var Mock_IOrderSummary */
     $orderSummary = $this->getMockBuilder(static::SUMMARY_CLASS)->disableOriginalConstructor()->getMock();
     /** @var Mock_EbayEnterprise_Eb2cCore_Helper_Data */
     $coreHelper = $this->getHelperMock('eb2ccore/data', ['invokeCallback']);
     $coreHelper->expects($this->once())->method('invokeCallback')->with($this->isType('array'))->will($this->returnValue($callbackReturnValue));
     $config = $this->buildCoreConfigRegistry(['mapSearchResponse' => $mapSearchResponse]);
     /** @var EbayEnterprise_Order_Model_Search_Process_Response_Map */
     $map = Mage::getModel('ebayenterprise_order/search_process_response_map', ['config' => $config, 'core_helper' => $coreHelper]);
     $this->assertSame($summaryData, EcomDev_Utils_Reflection::invokeRestrictedMethod($map, '_extractData', [$orderSummary]));
 }
 /**
  * Test getting the current user in session's start page url, running it
  * through the adminhtml/url method is necessary to account for url secret
  * key validation
  * @param  bool $useSecretKey
  * @dataProvider provideTrueFalse
  */
 public function testGetStartpageUri($useSecretKey)
 {
     $adminUrl = 'admin/some/where';
     $adminWithKey = 'admin/some/where/key/123';
     $expectedUrl = $useSecretKey ? $adminWithKey : $adminUrl;
     $session = $this->getModelMockBuilder('admin/session')->disableOriginalConstructor()->setMethods(array('getUser'))->getMock();
     $user = $this->getModelMockBuilder('admin/user')->disableOriginalConstructor()->setMethods(array('getStartupPageUrl'))->getMock();
     $url = $this->getModelMockBuilder('adminhtml/url')->disableOriginalConstructor()->setMethods(array('useSecretKey', 'getUrl'))->getMock();
     $this->replaceByMock('model', 'adminhtml/url', $url);
     $session->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $user->expects($this->once())->method('getStartupPageUrl')->will($this->returnValue($adminUrl));
     $url->expects($this->once())->method('useSecretKey')->will($this->returnValue($useSecretKey));
     if ($useSecretKey) {
         $url->expects($this->once())->method('getUrl')->with($this->identicalTo($adminUrl))->will($this->returnValue($adminWithKey));
     } else {
         $url->expects($this->never())->method('getUrl');
     }
     $this->assertSame($expectedUrl, EcomDev_Utils_Reflection::invokeRestrictedMethod($session, '_getStartpageUri'));
 }
 /**
  * Test generating the file name using the
  */
 public function testGetFileName()
 {
     $format = '%s_corrected_orders_%s.csv';
     $programId = 'PROGRAM_ID';
     $time = 1397829577;
     $formattedTime = date('YmdHis', $time);
     $fileName = "{$programId}_corrected_orders_{$formattedTime}.csv";
     // get the default store to be used as context for config getting
     $store = Mage::app()->getStore();
     // get the order feed instance with the expected store and start time injected
     $feed = $this->getModelMock('eems_affiliate/feed_order_itemized', array('_getFileNameFormat'), true, array(array('store' => $store, 'start_time' => $time)));
     $feed->expects($this->any())->method('_getFileNameFormat')->will($this->returnValue($format));
     $config = $this->getHelperMock('eems_affiliate/config', array('getProgramId'));
     // Will have different program ids per feed so store context definitely
     // matters when getting this value.
     $config->expects($this->any())->method('getProgramId')->with($this->identicalTo($store))->will($this->returnValue($programId));
     $this->replaceByMock('helper', 'eems_affiliate/config', $config);
     $generated = EcomDev_Utils_Reflection::invokeRestrictedMethod($feed, '_getFileName');
     $this->assertSame($fileName, $generated);
 }
 /**
  * When adding a gift card to the order, the card should be retrieved from
  * the container by card number, have the PIN set on the card and finally
  * be added to the order.
  *
  * @param bool
  * @dataProvider provideTrueFalse
  */
 public function testAddGiftCard($success)
 {
     $cardNumber = '1111111111111111';
     $pin = '1234';
     $this->container->method('getGiftCard')->with($cardNumber)->willReturn($this->giftCard);
     // Pin must be set on the gift card to be added.
     $this->giftCard->expects($this->once())->method('setPin')->with($this->identicalTo($pin))->willReturnSelf();
     // Helper should be used to add the gift card to the order. When gift
     // card is successfully added, it should return self. Otherwise, it will
     // thrown an exception.
     $addGiftCardInvoker = $this->helper->expects($this->once())->method('addGiftCardToOrder')->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container));
     if ($success) {
         $addGiftCardInvoker->willReturnSelf();
     } else {
         $addGiftCardInvoker->willThrowException(new EbayEnterprise_GiftCard_Exception('TEST EXCEPTION: ' . __METHOD__));
     }
     $this->assertSame($this->observer, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->observer, 'addGiftCard', [$cardNumber, $pin]));
     // When gift card added successfully, expect a success message to have
     // been added to the session. When unsuccessful, should add an error
     // message to the session.
     $expectMessageType = $success ? Mage_Core_Model_Message::SUCCESS : Mage_Core_Model_Message::ERROR;
     $this->assertCount(1, $this->session->getMessages()->getItemsByType($expectMessageType));
 }
 /**
  * verify exceptions from the sdk are handled
  *
  * @param string
  * @dataProvider provideExceptions
  */
 public function testTryOperationExceptions($exception)
 {
     $quote = Mage::getModel('sales/quote');
     $result = $this->getModelMock('ebayenterprise_inventory/details_result');
     $detail = $this->getModelMockBuilder('ebayenterprise_inventory/details')->setConstructorArgs([['logger' => $this->logger, 'logger_context' => $this->logContext]])->setMethods(['prepareApi', 'prepareRequest', 'prepareResult'])->getMock();
     $detail->expects($this->once())->method('prepareApi')->will($this->returnValue($this->httpApi));
     $detail->expects($this->once())->method('prepareRequest')->will($this->returnValue($this->request));
     $this->request->expects($this->once())->method('getItems')->will($this->returnValue(['notempty']));
     $this->httpApi->expects($this->once())->method('send')->will($this->throwException(new $exception()));
     // dont really care much about the prepare results call
     $detail->expects($this->any())->method('prepareResult')->will($this->returnValue($result));
     $this->setExpectedException('EbayEnterprise_Inventory_Exception_Details_Operation_Exception');
     EcomDev_Utils_Reflection::invokeRestrictedMethod($detail, 'tryOperation', [$quote]);
 }
 /**
  * When creating order items from quote items, each item should be converted
  * to an order item; the address the item was created for should be set on
  * the created item and the product type of the original item should be
  * copied over to the item (will not happen automatically for quote address
  * items).
  */
 public function testCreateOrderItems()
 {
     $aProductType = 'simple';
     $bProductType = 'configurable';
     $quoteItemA = $this->_stubQuoteItem($aProductType, null);
     $parentQuoteItem = $this->_stubQuoteItem($bProductType, null);
     $quoteItemB = $this->_stubQuoteItem(null, $parentQuoteItem);
     $orderItemA = $this->getModelMock('sales/order_item', ['setOrderAddress', 'setProductType']);
     $orderItemB = $this->getModelMock('sales/order_item', ['setOrderAddress', 'setProductType']);
     $quoteItems = [$quoteItemA, $quoteItemB];
     // The order address the items are being created for.
     $orderAddress = Mage::getModel('sales/order_address');
     // Mock the quote convertor to expect to be converting the two quote
     // items to two order items.
     $this->_quoteConvertor->expects($this->exactly(2))->method('itemToOrderItem')->withConsecutive([$quoteItemA], [$quoteItemB])->will($this->onConsecutiveCalls($orderItemA, $orderItemB));
     // Ensure that both order items have the order address they were created
     // for linked to the item.
     $orderItemA->expects($this->once())->method('setOrderAddress')->with($this->identicalTo($orderAddress))->will($this->returnSelf());
     $orderItemB->expects($this->once())->method('setOrderAddress')->with($this->identicalTo($orderAddress))->will($this->returnSelf());
     // Ensure that both order items have the appropriate product type set.
     // When converting from address items, the item will not have a product
     // type - only available through the associated quote item.
     $orderItemA->expects($this->once())->method('setProductType')->with($this->identicalTo($aProductType))->will($this->returnSelf());
     $orderItemB->expects($this->once())->method('setProductType')->with($this->identicalTo($bProductType))->will($this->returnSelf());
     // Ensure that both order items are added to the order they were
     // created for.
     $this->_order->expects($this->exactly(2))->method('addItem')->withConsecutive([$orderItemA], [$orderItemB])->will($this->returnSelf());
     $this->assertSame($this->_serviceQuote, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_serviceQuote, '_createOrderItems', [$quoteItems, $orderAddress, $this->_order]));
 }
 /**
  * Scenario: Get is in stock data
  * Given a backorder integer value
  * When getting is in stock data
  * Then, return an array with key is in stock map to true if
  * the passed in backorder integer value is greater than the no backorder
  * Then, return an empty array when the passed in backorder integer value is not greater than the no backorder
  *
  * @param int
  * @param array
  * @dataProvider providerGetIsInStockData
  */
 public function testGetIsInStockData($backorder, array $expected)
 {
     $stock = Mage::helper('ebayenterprise_catalog/map_stock');
     $this->assertSame($expected, EcomDev_Utils_Reflection::invokeRestrictedMethod($stock, 'getIsInStockData', [$backorder]));
 }
 /**
  * Test that the block method ebayenterprise_inventoryoverride/cart_item_renderer::removeKnownKeys()
  * when invoked, will be given an array with key value pairs and we expect it to return an array
  * without the key 'edd'.
  *
  * @param array
  * @param array
  * @dataProvider providerRemoveKnownKeys
  */
 public function testRemoveKnownKeys(array $args, array $result)
 {
     /** @var EbayEnterprise_Inventory_Override_Block_Cart_Item_Renderer */
     $renderer = $this->getBlockMock('ebayenterprise_inventoryoverride/cart_item_renderer');
     $this->assertSame($result, EcomDev_Utils_Reflection::invokeRestrictedMethod($renderer, 'removeKnownKeys', [$args]));
 }
 /**
  * Test _isValidProductType method for the following expectations
  * Expectation 1: when this test invoked the method EbayEnterprise_Catalog_Helper_Map::_isValidProductType
  *                with a given value it will check if the value in the six possible Magento product type
  *                it will return true if value match otherwise false
  */
 public function testIsValidProductType()
 {
     $testData = array(array('expect' => true, 'value' => 'simple'), array('expect' => false, 'value' => 'wrong'));
     $map = Mage::helper('ebayenterprise_catalog/map');
     foreach ($testData as $data) {
         $this->assertSame($data['expect'], EcomDev_Utils_Reflection::invokeRestrictedMethod($map, '_isValidProductType', array($data['value'])));
     }
 }
 /**
  * GIVEN An <api> that will thrown an <exception> of <exceptionType> when making a request.
  * WHEN A request is made.
  * THEN The <exception> will be caught.
  * AND An exception of <expectedExceptionType> will be thrown.
  *
  * @param string
  * @param string
  * @dataProvider provideSdkExceptions
  */
 public function testSdkExceptionHandling($exceptionType, $expectedExceptionType)
 {
     $exception = new $exceptionType(__METHOD__ . ': Test Exception');
     $api = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi');
     $api->method('send')->will($this->throwException($exception));
     $this->setExpectedException($expectedExceptionType);
     EcomDev_Utils_Reflection::invokeRestrictedMethod($this->helper, '_sendApiRequest', [$api]);
 }