当前位置: 首页>>代码示例>>PHP>>正文


PHP Data::expects方法代码示例

本文整理汇总了PHP中Magento\Core\Helper\Data::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::expects方法的具体用法?PHP Data::expects怎么用?PHP Data::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Core\Helper\Data的用法示例。


在下文中一共展示了Data::expects方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testJsonEncode

 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);
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: testIsDevAllowed

 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));
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例3: testRender

 /**
  * 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);
 }
开发者ID:,项目名称:,代码行数:10,代码来源:

示例4: testGetConfigurationCountryCodeFromDefault

 /**
  * @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);
 }
开发者ID:,项目名称:,代码行数:13,代码来源:

示例5: testGetRegionJson

 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);
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:16,代码来源:DataTest.php

示例6: testDeserializeInvalidEncodedBodyExceptionDeveloperModeOn

 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');
     }
 }
开发者ID:,项目名称:,代码行数:16,代码来源:

示例7: testGetBmlDisplay

 /**
  * @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));
 }
开发者ID:,项目名称:,代码行数:11,代码来源:

示例8: testRenderDefaultFormat

 /**
  * 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');
 }
开发者ID:,项目名称:,代码行数:11,代码来源:

示例9: testAddAdditionalFieldsToResponseFrontend

 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);
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:23,代码来源:ObserverTest.php

示例10: testLoginFailure

 public function testLoginFailure()
 {
     $jsonRequest = '{"username":"invalid@example.com", "password":"invalid"}';
     $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' => 'invalid@example.com', 'password' => 'invalid']);
     $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerAccountManagementMock->expects($this->any())->method('authenticate')->with('invalid@example.com', '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();
 }
开发者ID:,项目名称:,代码行数:17,代码来源:

示例11: testGetOptions

 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));
 }
开发者ID:,项目名称:,代码行数:36,代码来源:


注:本文中的Magento\Core\Helper\Data::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。