/** * @covers \Magento\Eav\Model\Attribute\Data\File::outputValue * * @param string $format * @param mixed $value * @param mixed $expectedResult * @param int $callTimes * @dataProvider outputValueDataProvider */ public function testOutputValue($format, $value, $callTimes, $expectedResult) { $entityMock = $this->getMock('\\Magento\\Framework\\Model\\AbstractModel', [], [], '', false); $entityMock->expects($this->once())->method('getData')->will($this->returnValue($value)); $attributeMock = $this->getMock('\\Magento\\Eav\\Model\\Attribute', [], [], '', false); $this->urlEncoder->expects($this->exactly($callTimes))->method('encode')->will($this->returnValue('url_key')); $this->model->setEntity($entityMock); $this->model->setAttribute($attributeMock); $this->assertEquals($expectedResult, $this->model->outputValue($format)); }
public function testGetPreviewFile() { $value = 'image.jpg'; $url = 'http://example.com/backend/customer/index/viewfile/' . $value; $formMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->disableOriginalConstructor()->getMock(); $this->image->setForm($formMock); $this->image->setValue($value); $this->urlEncoder->expects($this->once())->method('encode')->with($value)->will($this->returnArgument(0)); $this->backendHelperMock->expects($this->once())->method('getUrl')->with('customer/index/viewfile', ['image' => $value])->will($this->returnValue($url)); $this->assertContains($url, $this->image->getElementHtml()); }
/** * @param string $baseUrl * @param string $fileName * @param bool $isUsingStaticUrls * @param string $expectedHtml * @dataProvider providerGetImageHtmlDeclaration */ public function testGetImageHtmlDeclaration($baseUrl, $fileName, $isUsingStaticUrls, $expectedHtml) { $directive = '{{media url="/' . $fileName . '"}}'; $this->generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStaticUrls); $this->urlEncoderMock->expects($this->any())->method('encode')->with($directive)->willReturn($directive); $this->backendDataMock->expects($this->any())->method('getUrl')->with('cms/wysiwyg/directive', ['___directive' => $directive])->willReturn($directive); $this->assertEquals($expectedHtml, $this->imagesHelper->getImageHtmlDeclaration($fileName)); }
protected function setUp() { $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); /** @var \Magento\Framework\App\Helper\Context $context */ $context = $objectManagerHelper->getObject('Magento\\Framework\\App\\Helper\\Context', ['httpRequest' => $this->requestMock]); $className = 'Magento\\Checkout\\Helper\\Cart'; $arguments = $objectManagerHelper->getConstructArguments($className, ['context' => $context]); $this->urlBuilderMock = $context->getUrlBuilder(); $this->urlEncoder = $context->getUrlEncoder(); $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) { return strtr(base64_encode($url), '+/=', '-_,'); }); $this->scopeConfigMock = $context->getScopeConfig(); $this->cartMock = $arguments['checkoutCart']; $this->checkoutSessionMock = $arguments['checkoutSession']; $this->helper = $objectManagerHelper->getObject($className, $arguments); }
protected function setUp() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['getId', 'getSharingCode'], [], '', false); $wishlist->expects($this->any())->method('getId')->will($this->returnValue(5)); $wishlist->expects($this->any())->method('getSharingCode')->will($this->returnValue('somesharingcode')); $customer = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $customer->expects($this->any())->method('getId')->will($this->returnValue(8)); $customer->expects($this->any())->method('getEmail')->will($this->returnValue('*****@*****.**')); $this->wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['getWishlist', 'getCustomer', 'urlEncode'], [], '', false); $this->urlEncoder = $this->getMock('Magento\\Framework\\Url\\EncoderInterface', ['encode'], [], '', false); $this->wishlistHelper->expects($this->any())->method('getWishlist')->will($this->returnValue($wishlist)); $this->wishlistHelper->expects($this->any())->method('getCustomer')->will($this->returnValue($customer)); $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) { return strtr(base64_encode($url), '+/=', '-_,'); }); $this->urlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface'); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->link = $this->objectManagerHelper->getObject('Magento\\Wishlist\\Block\\Rss\\EmailLink', ['wishlistHelper' => $this->wishlistHelper, 'rssUrlBuilder' => $this->urlBuilder, 'urlEncoder' => $this->urlEncoder]); }
protected function setUp() { $this->urlBuilderMock = $this->getMock('Magento\\Framework\\UrlInterface'); $this->urlEncoder = $this->getMockBuilder('Magento\\Framework\\Url\\EncoderInterface')->getMock(); $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) { return strtr(base64_encode($url), '+/=', '-_,'); }); $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\RequestInterface', ['getRouteName', 'getControllerName', 'getParam', 'setActionName', 'getActionName', 'setModuleName', 'getModuleName', 'getCookie']); $contextMock = $this->getMock('\\Magento\\Framework\\App\\Helper\\Context', [], [], '', false); $contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($this->urlBuilderMock)); $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $contextMock->expects($this->any())->method('getUrlEncoder')->will($this->returnValue($this->urlEncoder)); $this->storeManagerMock = $this->getMock('\\Magento\\Framework\\Store\\StoreManagerInterface'); $this->coreHelperMock = $this->getMock('\\Magento\\Core\\Helper\\Data', [], [], '', false); $this->scopeConfigMock = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->cartMock = $this->getMock('\\Magento\\Checkout\\Model\\Cart', [], [], '', false); $this->checkoutSessionMock = $this->getMock('\\Magento\\Checkout\\Model\\Session', [], [], '', false); $this->helper = new Cart($contextMock, $this->storeManagerMock, $this->scopeConfigMock, $this->cartMock, $this->checkoutSessionMock); }
/** * @covers \Magento\Theme\Helper\Storage::convertPathToId * @covers \Magento\Theme\Helper\Storage::convertIdToPath */ public function testConvertPathToIdAndIdToPath() { $path = '/image/path/to'; $this->urlEncoder->expects($this->once())->method('encode')->with('/path/to')->willReturnCallback(function ($path) { return base64_encode($path); }); $this->urlDecoder->expects($this->once())->method('decode')->with(base64_encode('/path/to'))->willReturnCallback(function ($path) { return base64_decode($path); }); $value = $this->helper->convertPathToId($path); $this->assertEquals(base64_encode('/path/to'), $value); $this->assertEquals($path, $this->helper->convertIdToPath($value)); }
public function testGetRemoveParamsWithReferer() { $url = 'result url'; $wishlistItemId = 1; $referer = 'referer'; $refererEncoded = 'referer_encoded'; $this->wishlistItem->expects($this->once())->method('getWishlistItemId')->willReturn($wishlistItemId); $this->requestMock->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer); $this->urlEncoderMock->expects($this->once())->method('encode')->with($referer)->willReturn($refererEncoded); $this->urlBuilder->expects($this->once())->method('getUrl')->with('wishlist/index/remove', [])->willReturn($url); $this->postDataHelper->expects($this->once())->method('getPostData')->with($url, ['item' => $wishlistItemId, ActionInterface::PARAM_NAME_URL_ENCODED => $refererEncoded])->willReturn($url); $this->assertEquals($url, $this->model->getRemoveParams($this->wishlistItem, true)); }