Esempio n. 1
0
 public function testJsonEncode()
 {
     $expectedValue = 'string';
     $this->coreHelper->expects($this->once())->method('jsonEncode')->with($this->equalTo($expectedValue))->will($this->returnValue($expectedValue));
     $result = $this->object->jsonEncode($expectedValue);
     $this->assertEquals($expectedValue, $result);
 }
Esempio n. 2
0
 public function testIsDevAllowed()
 {
     $store = 'some store';
     $result = 'result';
     $this->helperMock->expects($this->once())->method('isDevAllowed')->with($store)->will($this->returnValue($result));
     $this->assertEquals($result, $this->model->isDevAllowed($store));
 }
Esempio n. 3
0
 /**
  * Test render method.
  */
 public function testRender()
 {
     $arrayToRender = array('key' => 'value');
     /** Assert that jsonEncode method in mocked helper will run once */
     $this->_helperMock->expects($this->once())->method('jsonEncode');
     $this->_restJsonRenderer->render($arrayToRender);
 }
Esempio n. 4
0
 /**
  * @param string|null $request
  * @param string|null|false $config
  * @param string|null $default
  * @dataProvider getConfigurationCountryCodeFromDefaultDataProvider
  */
 public function testGetConfigurationCountryCodeFromDefault($request, $config, $default)
 {
     $this->_configurationCountryCodePrepareRequest($request);
     $this->_configurationCountryCodePrepareConfig($config);
     $this->_coreHelper->expects($this->once())->method('getDefaultCountry')->will($this->returnValue($default));
     $this->_configurationCountryCodeAssertResult($default);
 }
Esempio n. 5
0
 public function testGetRegionJson()
 {
     $countries = array(new \Magento\Framework\Object(array('country_id' => 'Country1')), new \Magento\Framework\Object(array('country_id' => 'Country2')));
     $countryIterator = new \ArrayIterator($countries);
     $this->_countryCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue($countryIterator));
     $regions = array(new \Magento\Framework\Object(array('country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name')), new \Magento\Framework\Object(array('country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name')), new \Magento\Framework\Object(array('country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name')));
     $regionIterator = new \ArrayIterator($regions);
     $this->_regionCollection->expects($this->once())->method('addCountryFilter')->with(array('Country1', 'Country2'))->will($this->returnSelf());
     $this->_regionCollection->expects($this->once())->method('load');
     $this->_regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue($regionIterator));
     $expectedDataToEncode = array('config' => array('show_all_regions' => false, 'regions_required' => array()), 'Country1' => array('r1' => array('code' => 'r1-code', 'name' => 'r1-name'), 'r2' => array('code' => 'r2-code', 'name' => 'r2-name')), 'Country2' => array('r3' => array('code' => 'r3-code', 'name' => 'r3-name')));
     $this->_coreHelper->expects($this->once())->method('jsonEncode')->with(new \PHPUnit_Framework_Constraint_IsIdentical($expectedDataToEncode))->will($this->returnValue('encoded_json'));
     // Test
     $result = $this->_object->getRegionJson();
     $this->assertEquals('encoded_json', $result);
 }
Esempio n. 6
0
 public function testDeserializeInvalidEncodedBodyExceptionDeveloperModeOn()
 {
     /** Prepare mocks for SUT constructor. */
     $this->_helperMock->expects($this->once())->method('jsonDecode')->will($this->throwException(new \Zend_Json_Exception('Decoding error:' . PHP_EOL . 'Decoding failed: Syntax error')));
     $this->_appStateMock->expects($this->once())->method('getMode')->will($this->returnValue('developer'));
     /** Initialize SUT. */
     $inputInvalidJson = '{"key1":"test1"."key2":"test2"}';
     try {
         $this->_jsonDeserializer->deserialize($inputInvalidJson);
         $this->fail("Exception is expected to be raised");
     } catch (\Magento\Webapi\Exception $e) {
         $this->assertInstanceOf('Magento\\Webapi\\Exception', $e, 'Exception type is invalid');
         $this->assertContains('Decoding error:', $e->getMessage(), 'Exception message is invalid');
         $this->assertEquals(\Magento\Webapi\Exception::HTTP_BAD_REQUEST, $e->getHttpCode(), 'HTTP code is invalid');
     }
 }
Esempio n. 7
0
 /**
  * @dataProvider dataProviderGetBmlDisplay
  */
 public function testGetBmlDisplay($section, $expectedValue, $expectedFlag, $expected)
 {
     $this->_model->setStoreId(1);
     $this->_coreData->expects($this->any())->method('getDefaultCountry')->with(1)->will($this->returnValue('US'));
     $this->_scopeConfig->expects($this->any())->method('isSetFlag')->will($this->returnValue($expectedFlag));
     $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValueMap([['payment/' . Config::METHOD_WPP_BML . '/' . $section . '_display', 'store', 1, $expectedValue], ['payment/' . Config::METHOD_WPP_BML . '/active', 'store', 1, $expectedValue], ['payment/' . Config::METHOD_WPP_PE_BML . '/active', 'store', 1, $expectedValue]]));
     $this->assertEquals($expected, $this->_model->getBmlDisplay($section));
 }
Esempio n. 8
0
 /**
  * Test default render format is JSON.
  */
 public function testRenderDefaultFormat()
 {
     /** Set undefined rendering format. */
     $_SERVER['HTTP_ACCEPT'] = 'undefined';
     /** Assert that jsonEncode method will be executed at least once. */
     $this->_helperMock->expects($this->atLeastOnce())->method('jsonEncode');
     $this->_errorProcessor->render('Message');
 }
 public function testAddAdditionalFieldsToResponseFrontend()
 {
     $directpostRequest = $this->getMock('Magento\\Authorizenet\\Model\\Directpost\\Request', array());
     $order = $this->getMock('Magento\\Sales\\Model\\Order', array(), array(), '', false);
     $methodInstance = $this->getMock('Magento\\Authorizenet\\Model\\Directpost', array(), array(), '', false);
     $methodInstance->expects($this->once())->method('generateRequestFromOrder')->with($this->identicalTo($order))->will($this->returnValue($directpostRequest));
     $payment = $this->getMock('Magento\\Sales\\Model\\Order\\Payment', array('getMethodInstance', '__wakeup'), array(), '', false);
     $payment->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodInstance));
     $payment->setMethod('authorizenet_directpost');
     $order->expects($this->once())->method('getId')->will($this->returnValue(1));
     $order->expects($this->atLeastOnce())->method('getPayment')->will($this->returnValue($payment));
     $this->coreRegistry->expects($this->once())->method('registry')->with('directpost_order')->will($this->returnValue($order));
     $request = new \Magento\Framework\Object();
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', array(), array(), '', false);
     $controller = $this->getMock('Magento\\Checkout\\Controller\\Action', array('getRequest', 'getResponse'), array(), '', false);
     $controller->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     $controller->expects($this->once())->method('getResponse')->will($this->returnValue($response));
     $observer = new \Magento\Framework\Event\Observer(array('event' => new \Magento\Framework\Object(array('controller_action' => $controller))));
     $this->coreData->expects($this->once())->method('jsonEncode')->with(self::logicalNot(self::isEmpty()))->will($this->returnValue('encoded response'));
     $response->expects($this->once())->method('clearHeader')->with('Location');
     $response->expects($this->once())->method('representJson')->with('encoded response');
     $this->model->addAdditionalFieldsToResponseFrontend($observer);
 }
Esempio n. 10
0
 public function testLoginFailure()
 {
     $jsonRequest = '{"username":"******", "password":"******"}';
     $loginFailureResponse = '{"message":"Invalid login or password."}';
     $this->request->expects($this->any())->method('getRawBody')->willReturn($jsonRequest);
     $this->request->expects($this->any())->method('getMethod')->willReturn('POST');
     $this->request->expects($this->any())->method('isXmlHttpRequest')->willReturn(true);
     $this->resultJsonFactory->expects($this->never())->method('create')->willReturn($this->resultJson);
     $this->dataHelper->expects($this->any())->method('jsonDecode')->with($jsonRequest)->willReturn(['username' => '*****@*****.**', 'password' => 'invalid']);
     $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerAccountManagementMock->expects($this->any())->method('authenticate')->with('*****@*****.**', 'invalid')->willThrowException(new InvalidEmailOrPasswordException('Invalid login or password.', []));
     $this->customerSession->expects($this->never())->method('setCustomerDataAsLoggedIn')->with($customerMock);
     $this->customerSession->expects($this->never())->method('regenerateId');
     $this->resultJson->expects($this->never())->method('setData')->with(['message' => 'Invalid login or password.'])->willReturn($loginFailureResponse);
     $this->resultRaw->expects($this->once())->method('setHttpResponseCode')->with(401);
     $this->object->execute();
 }
Esempio n. 11
0
 public function testGetOptions()
 {
     $optionIds = 'a:1:{i:0;i:1;}';
     $selectionIds = 'a:1:{i:0;s:1:"2";}';
     $selectionId = '2';
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getTypeInstance', '__wakeup', 'getCustomOption', 'getSelectionId', 'getName', 'getPriceModel'], [], '', false);
     $typeInstance = $this->getMock('Magento\\Bundle\\Model\\Product\\Type', ['getOptionsByIds', 'getSelectionsByIds'], [], '', false);
     $priceModel = $this->getMock('Magento\\Bundle\\Model\\Product\\Price', ['getSelectionFinalTotalPrice'], [], '', false);
     $selectionQty = $this->getMock('Magento\\Quote\\Model\\Quote\\Item\\Option', ['getValue', '__wakeup'], [], '', false);
     $bundleOption = $this->getMock('Magento\\Bundle\\Model\\Option', ['getSelections', 'getTitle', '__wakeup'], [], '', false);
     $selectionOption = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface', ['getValue']);
     $collection = $this->getMock('Magento\\Bundle\\Model\\Resource\\Option\\Collection', ['appendSelections'], [], '', false);
     $itemOption = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface', ['getValue']);
     $collection2 = $this->getMock('Magento\\Bundle\\Model\\Resource\\Selection\\Collection', [], [], '', false);
     $this->escaper->expects($this->once())->method('escapeHtml')->with('name')->will($this->returnValue('name'));
     $this->coreData->expects($this->once())->method('currency')->with(15)->will($this->returnValue('<span class="price">$15.00</span>'));
     $priceModel->expects($this->once())->method('getSelectionFinalTotalPrice')->will($this->returnValue(15));
     $selectionQty->expects($this->any())->method('getValue')->will($this->returnValue(1));
     $bundleOption->expects($this->any())->method('getSelections')->will($this->returnValue([$product]));
     $bundleOption->expects($this->once())->method('getTitle')->will($this->returnValue('title'));
     $selectionOption->expects($this->once())->method('getValue')->will($this->returnValue($selectionIds));
     $collection->expects($this->once())->method('appendSelections')->with($collection2, true)->will($this->returnValue([$bundleOption]));
     $itemOption->expects($this->once())->method('getValue')->will($this->returnValue($optionIds));
     $typeInstance->expects($this->once())->method('getOptionsByIds')->with(unserialize($optionIds), $product)->will($this->returnValue($collection));
     $typeInstance->expects($this->once())->method('getSelectionsByIds')->with(unserialize($selectionIds), $product)->will($this->returnValue($collection2));
     $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance));
     $product->expects($this->any())->method('getCustomOption')->with('selection_qty_' . $selectionId)->will($this->returnValue($selectionQty));
     $product->expects($this->any())->method('getSelectionId')->will($this->returnValue($selectionId));
     $product->expects($this->once())->method('getName')->will($this->returnValue('name'));
     $product->expects($this->once())->method('getPriceModel')->will($this->returnValue($priceModel));
     $this->item->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $this->item->expects($this->at(1))->method('getOptionByCode')->with('bundle_option_ids')->will($this->returnValue($itemOption));
     $this->item->expects($this->at(2))->method('getOptionByCode')->with('bundle_selection_ids')->will($this->returnValue($selectionOption));
     $this->productConfiguration->expects($this->once())->method('getCustomOptions')->with($this->item)->will($this->returnValue([0 => ['label' => 'title', 'value' => 'value']]));
     $this->assertEquals([0 => ['label' => 'title', 'value' => [0 => '1 x name <span class="price">$15.00</span>']], 1 => ['label' => 'title', 'value' => 'value']], $this->helper->getOptions($this->item));
 }