Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Magento\Wishlist\Test\Unit\Controller\Index; use Magento\Catalog\Helper\..

Decoded Output download

<?php
  namespace Magento\Wishlist\Test\Unit\Controller\Index; use Magento\Catalog\Helper\Product as ProductHelper; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Exception as ProductException; use Magento\Checkout\Helper\Cart as CartHelper; use Magento\Checkout\Model\Cart as CheckoutCart; use Magento\Framework\App\Action\Context; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Data\Form\FormKey\Validator; use Magento\Framework\DataObject; use Magento\Framework\Escaper; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata; use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Framework\UrlInterface; use Magento\Quote\Model\Quote; use Magento\Wishlist\Controller\Index\Cart; use Magento\Wishlist\Controller\WishlistProviderInterface; use Magento\Wishlist\Helper\Data; use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\Item\Option; use Magento\Wishlist\Model\Item\OptionFactory; use Magento\Wishlist\Model\ItemFactory; use Magento\Wishlist\Model\LocaleQuantityProcessor; use Magento\Wishlist\Model\ResourceModel\Item\Option\Collection; use Magento\Wishlist\Model\Wishlist; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class CartTest extends TestCase { protected $model; protected $contextMock; protected $wishlistProviderMock; protected $quantityProcessorMock; protected $itemFactoryMock; protected $checkoutCartMock; protected $optionFactoryMock; protected $productHelperMock; protected $escaperMock; protected $helperMock; protected $requestMock; protected $redirectMock; protected $objectManagerMock; protected $messageManagerMock; protected $urlMock; protected $cartHelperMock; protected $resultFactoryMock; protected $resultRedirectMock; protected $resultJsonMock; protected $formKeyValidator; private $cookieManagerMock; private $cookieMetadataFactoryMock; protected function setUp() : void { $this->wishlistProviderMock = $this->getMockBuilder(WishlistProviderInterface::class)->disableOriginalConstructor()->onlyMethods(array("getWishlist"))->getMockForAbstractClass(); $this->quantityProcessorMock = $this->getMockBuilder(LocaleQuantityProcessor::class)->disableOriginalConstructor()->getMock(); $this->itemFactoryMock = $this->getMockBuilder(ItemFactory::class)->disableOriginalConstructor()->onlyMethods(array("create"))->getMock(); $this->checkoutCartMock = $this->getMockBuilder(CheckoutCart::class)->disableOriginalConstructor()->onlyMethods(array("save", "getQuote"))->addMethods(array("getShouldRedirectToCart", "getCartUrl"))->getMock(); $this->optionFactoryMock = $this->getMockBuilder(OptionFactory::class)->disableOriginalConstructor()->onlyMethods(array("create"))->getMock(); $this->productHelperMock = $this->getMockBuilder(ProductHelper::class)->disableOriginalConstructor()->getMock(); $this->escaperMock = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock(); $this->helperMock = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->onlyMethods(array("getParams", "getParam"))->addMethods(array("isAjax", "getPostValue"))->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder(RedirectInterface::class)->disableOriginalConstructor()->getMockForAbstractClass(); $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMockForAbstractClass(); $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->onlyMethods(array("addSuccessMessage"))->getMockForAbstractClass(); $this->urlMock = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->onlyMethods(array("getUrl"))->getMockForAbstractClass(); $this->cartHelperMock = $this->getMockBuilder(CartHelper::class)->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock(); $this->resultJsonMock = $this->getMockBuilder(Json::class)->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->requestMock); $this->contextMock->expects($this->any())->method("getRedirect")->willReturn($this->redirectMock); $this->contextMock->expects($this->any())->method("getObjectManager")->willReturn($this->objectManagerMock); $this->contextMock->expects($this->any())->method("getMessageManager")->willReturn($this->messageManagerMock); $this->contextMock->expects($this->any())->method("getUrl")->willReturn($this->urlMock); $this->contextMock->expects($this->any())->method("getResultFactory")->willReturn($this->resultFactoryMock); $this->resultFactoryMock->expects($this->any())->method("create")->willReturnMap(array(array(ResultFactory::TYPE_REDIRECT, array(), $this->resultRedirectMock), array(ResultFactory::TYPE_JSON, array(), $this->resultJsonMock))); $this->formKeyValidator = $this->getMockBuilder(Validator::class)->disableOriginalConstructor()->getMock(); $this->cookieManagerMock = $this->getMockForAbstractClass(CookieManagerInterface::class); $cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)->disableOriginalConstructor()->getMock(); $this->cookieMetadataFactoryMock = $this->getMockBuilder(CookieMetadataFactory::class)->disableOriginalConstructor()->onlyMethods(array("createPublicCookieMetadata"))->getMock(); $this->cookieMetadataFactoryMock->expects($this->any())->method("createPublicCookieMetadata")->willReturn($cookieMetadataMock); $cookieMetadataMock->expects($this->any())->method("setDuration")->willReturnSelf(); $cookieMetadataMock->expects($this->any())->method("setPath")->willReturnSelf(); $cookieMetadataMock->expects($this->any())->method("setSameSite")->willReturnSelf(); $cookieMetadataMock->expects($this->any())->method("setHttpOnly")->willReturnSelf(); $this->model = new Cart($this->contextMock, $this->wishlistProviderMock, $this->quantityProcessorMock, $this->itemFactoryMock, $this->checkoutCartMock, $this->optionFactoryMock, $this->productHelperMock, $this->escaperMock, $this->helperMock, $this->cartHelperMock, $this->formKeyValidator, $this->cookieManagerMock, $this->cookieMetadataFactoryMock); } public function testExecuteWithInvalidFormKey() : void { $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(false); $this->resultRedirectMock->expects($this->once())->method("setPath")->with("*/*/")->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithNoItem() : void { $itemId = false; $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->once())->method("getParam")->with("item", null)->willReturn($itemId); $this->itemFactoryMock->expects($this->once())->method("create")->willReturn($itemMock); $itemMock->expects($this->once())->method("load")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->once())->method("getId")->willReturn(null); $this->resultRedirectMock->expects($this->once())->method("setPath")->with("*/*", array())->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithNoWishlist() : void { $itemId = 2; $wishlistId = 1; $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("load", "getId"))->addMethods(array("getWishlistId"))->getMock(); $this->requestMock->expects($this->once())->method("getParam")->with("item", null)->willReturn($itemId); $this->itemFactoryMock->expects($this->once())->method("create")->willReturn($itemMock); $itemMock->expects($this->once())->method("load")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->once())->method("getId")->willReturn($itemId); $itemMock->expects($this->once())->method("getWishlistId")->willReturn($wishlistId); $this->wishlistProviderMock->expects($this->once())->method("getWishlist")->with($wishlistId)->willReturn(null); $this->resultRedirectMock->expects($this->once())->method("setPath")->with("*/*", array())->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithQuantityArray() : void { $refererUrl = $this->prepareExecuteWithQuantityArray(); $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $this->resultRedirectMock->expects($this->once())->method("setUrl")->with($refererUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithQuantityArrayAjax() : void { $refererUrl = $this->prepareExecuteWithQuantityArray(true); $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $this->resultJsonMock->expects($this->once())->method("setData")->with(array("backUrl" => $refererUrl))->willReturnSelf(); $this->assertSame($this->resultJsonMock, $this->model->execute()); } protected function prepareExecuteWithQuantityArray($isAjax = false) : string { $itemId = 2; $wishlistId = 1; $qty = array($itemId => 3); $productId = 4; $productName = "product_name"; $indexUrl = "index_url"; $configureUrl = "configure_url"; $options = array(5 => "option"); $params = array("item" => $itemId, "qty" => $qty); $refererUrl = "referer_url"; $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("load", "getId", "setQty", "setOptions", "getBuyRequest", "mergeBuyRequest", "addToCart", "getProduct"))->addMethods(array("getWishlistId", "getProductId"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("create")->willReturn($itemMock); $itemMock->expects($this->once())->method("load")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("getId")->willReturn($itemId); $itemMock->expects($this->once())->method("getWishlistId")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("getWishlist")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("getParam")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "item") { return $itemId; } elseif ($arg1 == "qty") { return $qty; } }); $this->quantityProcessorMock->expects($this->once())->method("process")->with($qty[$itemId])->willReturnArgument(0); $itemMock->expects($this->once())->method("setQty")->with($qty[$itemId])->willReturnSelf(); $itemMock->expects($this->once())->method("getProductId")->willReturn($productId); $this->urlMock->method("getUrl")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "*/*" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "*/*/configure/" && $arg2["id"] == $itemId && $arg2["product_id"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("create")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("getCollection")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("addItemFilter")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("getOptionsByItem")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("setOptions")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("getParams")->willReturn($params); $this->requestMock->expects($this->once())->method("isAjax")->willReturn($isAjax); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("getBuyRequest")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("addParamsToBuyRequest")->with($params, array("current_config" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("mergeBuyRequest")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("addToCart")->with($this->checkoutCartMock, true)->willReturn(true); $this->checkoutCartMock->expects($this->once())->method("save")->willReturnSelf(); $quoteMock = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->onlyMethods(array("collectTotals"))->addMethods(array("getHasError"))->getMock(); $this->checkoutCartMock->expects($this->exactly(2))->method("getQuote")->willReturn($quoteMock); $quoteMock->expects($this->once())->method("collectTotals")->willReturnSelf(); $wishlistMock->expects($this->once())->method("save")->willReturnSelf(); $quoteMock->expects($this->once())->method("getHasError")->willReturn(false); $productMock = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->atLeastOnce())->method("getProduct")->willReturn($productMock); $productMock->expects($this->atLeastOnce())->method("getName")->willReturn($productName); $this->messageManagerMock->expects($this->once())->method("addComplexSuccessMessage")->willReturnSelf(); $this->cartHelperMock->expects($this->once())->method("getShouldRedirectToCart")->willReturn(false); $this->redirectMock->expects($this->once())->method("getRefererUrl")->willReturn($refererUrl); $this->helperMock->expects($this->once())->method("calculate")->willReturnSelf(); return $refererUrl; } public function testExecuteWithoutQuantityArrayAndOutOfStock() : void { $itemId = 2; $wishlistId = 1; $qty = array(); $productId = 4; $indexUrl = "index_url"; $configureUrl = "configure_url"; $options = array(5 => "option"); $params = array("item" => $itemId, "qty" => $qty); $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("load", "getId", "setQty", "setOptions", "getBuyRequest", "mergeBuyRequest", "addToCart", "getProduct"))->addMethods(array("getWishlistId", "getProductId"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("create")->willReturn($itemMock); $itemMock->expects($this->once())->method("load")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("getId")->willReturn($itemId); $itemMock->expects($this->once())->method("getWishlistId")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("getWishlist")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("getParam")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "item") { return $itemId; } elseif ($arg1 == "qty") { return $qty; } }); $this->quantityProcessorMock->expects($this->once())->method("process")->with(1)->willReturnArgument(0); $itemMock->expects($this->once())->method("setQty")->with(1)->willReturnSelf(); $itemMock->expects($this->once())->method("getProductId")->willReturn($productId); $this->urlMock->method("getUrl")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "*/*" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "*/*/configure/" && $arg2["id"] == $itemId && $arg2["product_id"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("create")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("getCollection")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("addItemFilter")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("getOptionsByItem")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("setOptions")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("getParams")->willReturn($params); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("getBuyRequest")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("addParamsToBuyRequest")->with($params, array("current_config" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("mergeBuyRequest")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("addToCart")->with($this->checkoutCartMock, true)->willThrowException(new ProductException(__("Test Phrase"))); $this->messageManagerMock->expects($this->once())->method("addErrorMessage")->with("This product(s) is out of stock.", null)->willReturnSelf(); $this->helperMock->expects($this->once())->method("calculate")->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method("setUrl")->with($indexUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithoutQuantityArrayAndConfigurable() : void { $itemId = 2; $wishlistId = 1; $qty = array(); $productId = 4; $indexUrl = "index_url"; $configureUrl = "configure_url"; $options = array(5 => "option"); $params = array("item" => $itemId, "qty" => $qty); $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("load", "getId", "setQty", "setOptions", "getBuyRequest", "mergeBuyRequest", "addToCart", "getProduct"))->addMethods(array("getWishlistId", "getProductId"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("create")->willReturn($itemMock); $itemMock->expects($this->once())->method("load")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("getId")->willReturn($itemId); $itemMock->expects($this->once())->method("getWishlistId")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("getWishlist")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("getParam")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "item") { return $itemId; } elseif ($arg1 == "qty") { return $qty; } }); $this->quantityProcessorMock->expects($this->once())->method("process")->with(1)->willReturnArgument(0); $itemMock->expects($this->once())->method("setQty")->with(1)->willReturnSelf(); $itemMock->expects($this->once())->method("getProductId")->willReturn($productId); $this->urlMock->method("getUrl")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "*/*" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "*/*/configure/" && $arg2["id"] == $itemId && $arg2["product_id"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("create")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("getCollection")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("addItemFilter")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("getOptionsByItem")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("setOptions")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("getParams")->willReturn($params); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("getBuyRequest")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("addParamsToBuyRequest")->with($params, array("current_config" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("mergeBuyRequest")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("addToCart")->with($this->checkoutCartMock, true)->willThrowException(new LocalizedException(__("message"))); $this->messageManagerMock->expects($this->once())->method("addNoticeMessage")->with("message", null)->willReturnSelf(); $this->helperMock->expects($this->once())->method("calculate")->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method("setUrl")->with($configureUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithEditQuantity() : void { $itemId = 2; $wishlistId = 1; $qty = 1; $postQty = 2; $productId = 4; $indexUrl = "index_url"; $configureUrl = "configure_url"; $options = array(5 => "option"); $params = array("item" => $itemId, "qty" => $qty); $this->formKeyValidator->expects($this->once())->method("validate")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("load", "getId", "setQty", "setOptions", "getBuyRequest", "mergeBuyRequest", "addToCart", "getProduct"))->addMethods(array("getWishlistId", "getProductId"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("create")->willReturn($itemMock); $itemMock->expects($this->once())->method("load")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("getId")->willReturn($itemId); $itemMock->expects($this->once())->method("getWishlistId")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("getWishlist")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("getParam")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "item") { return $itemId; } elseif ($arg1 == "qty") { return $qty; } }); $this->requestMock->expects($this->once())->method("getPostValue")->with("qty")->willReturn($postQty); $this->quantityProcessorMock->expects($this->once())->method("process")->with($postQty)->willReturnArgument(0); $itemMock->expects($this->once())->method("setQty")->with($postQty)->willReturnSelf(); $itemMock->expects($this->once())->method("getProductId")->willReturn($productId); $this->urlMock->method("getUrl")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "*/*" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "*/*/configure/" && $arg2["id"] == $itemId && $arg2["product_id"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("create")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("getCollection")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("addItemFilter")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("getOptionsByItem")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("setOptions")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("getParams")->willReturn($params); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("getBuyRequest")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("addParamsToBuyRequest")->with($params, array("current_config" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("mergeBuyRequest")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("addToCart")->with($this->checkoutCartMock, true)->willThrowException(new LocalizedException(__("message"))); $this->messageManagerMock->expects($this->once())->method("addNoticeMessage")->with("message", null)->willReturnSelf(); $this->helperMock->expects($this->once())->method("calculate")->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method("setUrl")->with($configureUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } } ?>

Did this file decode correctly?

Original Code

<?php
  namespace Magento\Wishlist\Test\Unit\Controller\Index; use Magento\Catalog\Helper\Product as ProductHelper; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Exception as ProductException; use Magento\Checkout\Helper\Cart as CartHelper; use Magento\Checkout\Model\Cart as CheckoutCart; use Magento\Framework\App\Action\Context; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Data\Form\FormKey\Validator; use Magento\Framework\DataObject; use Magento\Framework\Escaper; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata; use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Framework\UrlInterface; use Magento\Quote\Model\Quote; use Magento\Wishlist\Controller\Index\Cart; use Magento\Wishlist\Controller\WishlistProviderInterface; use Magento\Wishlist\Helper\Data; use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\Item\Option; use Magento\Wishlist\Model\Item\OptionFactory; use Magento\Wishlist\Model\ItemFactory; use Magento\Wishlist\Model\LocaleQuantityProcessor; use Magento\Wishlist\Model\ResourceModel\Item\Option\Collection; use Magento\Wishlist\Model\Wishlist; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class CartTest extends TestCase { protected $model; protected $contextMock; protected $wishlistProviderMock; protected $quantityProcessorMock; protected $itemFactoryMock; protected $checkoutCartMock; protected $optionFactoryMock; protected $productHelperMock; protected $escaperMock; protected $helperMock; protected $requestMock; protected $redirectMock; protected $objectManagerMock; protected $messageManagerMock; protected $urlMock; protected $cartHelperMock; protected $resultFactoryMock; protected $resultRedirectMock; protected $resultJsonMock; protected $formKeyValidator; private $cookieManagerMock; private $cookieMetadataFactoryMock; protected function setUp() : void { $this->wishlistProviderMock = $this->getMockBuilder(WishlistProviderInterface::class)->disableOriginalConstructor()->onlyMethods(array("\x67\145\x74\127\x69\x73\x68\154\151\163\x74"))->getMockForAbstractClass(); $this->quantityProcessorMock = $this->getMockBuilder(LocaleQuantityProcessor::class)->disableOriginalConstructor()->getMock(); $this->itemFactoryMock = $this->getMockBuilder(ItemFactory::class)->disableOriginalConstructor()->onlyMethods(array("\x63\162\145\x61\x74\x65"))->getMock(); $this->checkoutCartMock = $this->getMockBuilder(CheckoutCart::class)->disableOriginalConstructor()->onlyMethods(array("\x73\x61\x76\x65", "\x67\x65\164\121\165\x6f\x74\x65"))->addMethods(array("\147\x65\x74\x53\x68\157\x75\154\144\x52\145\144\x69\162\x65\x63\164\124\157\103\x61\x72\x74", "\147\145\x74\103\141\x72\x74\125\x72\154"))->getMock(); $this->optionFactoryMock = $this->getMockBuilder(OptionFactory::class)->disableOriginalConstructor()->onlyMethods(array("\143\162\145\x61\x74\x65"))->getMock(); $this->productHelperMock = $this->getMockBuilder(ProductHelper::class)->disableOriginalConstructor()->getMock(); $this->escaperMock = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock(); $this->helperMock = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->onlyMethods(array("\x67\x65\164\x50\x61\162\x61\x6d\x73", "\147\x65\x74\x50\141\x72\141\x6d"))->addMethods(array("\x69\x73\x41\x6a\x61\x78", "\147\145\x74\x50\157\163\164\x56\141\x6c\x75\x65"))->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder(RedirectInterface::class)->disableOriginalConstructor()->getMockForAbstractClass(); $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMockForAbstractClass(); $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->onlyMethods(array("\x61\144\144\x53\x75\x63\143\x65\163\x73\115\x65\x73\163\141\x67\x65"))->getMockForAbstractClass(); $this->urlMock = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->onlyMethods(array("\x67\x65\164\125\x72\x6c"))->getMockForAbstractClass(); $this->cartHelperMock = $this->getMockBuilder(CartHelper::class)->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock(); $this->resultJsonMock = $this->getMockBuilder(Json::class)->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method("\147\x65\x74\x52\145\161\x75\x65\x73\x74")->willReturn($this->requestMock); $this->contextMock->expects($this->any())->method("\x67\145\164\x52\145\144\151\x72\x65\x63\164")->willReturn($this->redirectMock); $this->contextMock->expects($this->any())->method("\147\x65\x74\x4f\x62\x6a\x65\143\164\115\x61\x6e\x61\x67\145\162")->willReturn($this->objectManagerMock); $this->contextMock->expects($this->any())->method("\x67\x65\164\x4d\x65\x73\x73\x61\147\x65\115\141\156\x61\x67\145\162")->willReturn($this->messageManagerMock); $this->contextMock->expects($this->any())->method("\x67\145\164\125\162\154")->willReturn($this->urlMock); $this->contextMock->expects($this->any())->method("\147\x65\x74\122\x65\163\165\x6c\x74\106\x61\x63\x74\157\162\171")->willReturn($this->resultFactoryMock); $this->resultFactoryMock->expects($this->any())->method("\143\162\x65\141\x74\145")->willReturnMap(array(array(ResultFactory::TYPE_REDIRECT, array(), $this->resultRedirectMock), array(ResultFactory::TYPE_JSON, array(), $this->resultJsonMock))); $this->formKeyValidator = $this->getMockBuilder(Validator::class)->disableOriginalConstructor()->getMock(); $this->cookieManagerMock = $this->getMockForAbstractClass(CookieManagerInterface::class); $cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)->disableOriginalConstructor()->getMock(); $this->cookieMetadataFactoryMock = $this->getMockBuilder(CookieMetadataFactory::class)->disableOriginalConstructor()->onlyMethods(array("\143\x72\x65\x61\164\x65\x50\x75\x62\154\151\143\x43\157\157\153\x69\x65\115\145\x74\141\x64\x61\x74\x61"))->getMock(); $this->cookieMetadataFactoryMock->expects($this->any())->method("\x63\162\145\x61\164\x65\x50\165\x62\154\x69\143\x43\157\157\x6b\151\145\115\145\164\x61\144\141\164\x61")->willReturn($cookieMetadataMock); $cookieMetadataMock->expects($this->any())->method("\163\145\x74\x44\165\162\x61\164\151\157\156")->willReturnSelf(); $cookieMetadataMock->expects($this->any())->method("\163\145\164\120\x61\x74\150")->willReturnSelf(); $cookieMetadataMock->expects($this->any())->method("\x73\145\x74\123\141\155\145\123\151\164\145")->willReturnSelf(); $cookieMetadataMock->expects($this->any())->method("\x73\x65\x74\x48\164\x74\160\117\156\154\x79")->willReturnSelf(); $this->model = new Cart($this->contextMock, $this->wishlistProviderMock, $this->quantityProcessorMock, $this->itemFactoryMock, $this->checkoutCartMock, $this->optionFactoryMock, $this->productHelperMock, $this->escaperMock, $this->helperMock, $this->cartHelperMock, $this->formKeyValidator, $this->cookieManagerMock, $this->cookieMetadataFactoryMock); } public function testExecuteWithInvalidFormKey() : void { $this->formKeyValidator->expects($this->once())->method("\x76\x61\154\151\x64\x61\164\145")->with($this->requestMock)->willReturn(false); $this->resultRedirectMock->expects($this->once())->method("\163\145\164\x50\141\x74\150")->with("\52\57\52\x2f")->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithNoItem() : void { $itemId = false; $this->formKeyValidator->expects($this->once())->method("\x76\141\154\x69\144\141\164\x65")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->once())->method("\x67\x65\x74\120\141\x72\141\155")->with("\x69\164\145\155", null)->willReturn($itemId); $this->itemFactoryMock->expects($this->once())->method("\x63\x72\x65\141\x74\145")->willReturn($itemMock); $itemMock->expects($this->once())->method("\x6c\157\x61\x64")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->once())->method("\x67\x65\x74\x49\x64")->willReturn(null); $this->resultRedirectMock->expects($this->once())->method("\163\x65\x74\120\x61\164\x68")->with("\x2a\57\x2a", array())->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithNoWishlist() : void { $itemId = 2; $wishlistId = 1; $this->formKeyValidator->expects($this->once())->method("\166\x61\x6c\151\144\x61\164\145")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("\154\x6f\141\144", "\147\x65\x74\x49\x64"))->addMethods(array("\x67\x65\164\x57\151\x73\150\154\151\163\x74\x49\144"))->getMock(); $this->requestMock->expects($this->once())->method("\147\x65\x74\x50\x61\x72\141\155")->with("\151\x74\145\155", null)->willReturn($itemId); $this->itemFactoryMock->expects($this->once())->method("\x63\162\145\x61\164\x65")->willReturn($itemMock); $itemMock->expects($this->once())->method("\154\157\x61\x64")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->once())->method("\x67\145\164\x49\x64")->willReturn($itemId); $itemMock->expects($this->once())->method("\x67\145\164\127\151\163\150\154\151\x73\x74\x49\144")->willReturn($wishlistId); $this->wishlistProviderMock->expects($this->once())->method("\x67\x65\164\x57\x69\x73\150\x6c\151\163\x74")->with($wishlistId)->willReturn(null); $this->resultRedirectMock->expects($this->once())->method("\x73\x65\164\x50\x61\164\150")->with("\52\57\x2a", array())->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithQuantityArray() : void { $refererUrl = $this->prepareExecuteWithQuantityArray(); $this->formKeyValidator->expects($this->once())->method("\x76\x61\154\x69\x64\x61\x74\x65")->with($this->requestMock)->willReturn(true); $this->resultRedirectMock->expects($this->once())->method("\163\x65\x74\x55\x72\x6c")->with($refererUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithQuantityArrayAjax() : void { $refererUrl = $this->prepareExecuteWithQuantityArray(true); $this->formKeyValidator->expects($this->once())->method("\166\141\x6c\151\x64\x61\x74\145")->with($this->requestMock)->willReturn(true); $this->resultJsonMock->expects($this->once())->method("\163\145\164\104\141\x74\x61")->with(array("\142\141\x63\153\125\162\154" => $refererUrl))->willReturnSelf(); $this->assertSame($this->resultJsonMock, $this->model->execute()); } protected function prepareExecuteWithQuantityArray($isAjax = false) : string { $itemId = 2; $wishlistId = 1; $qty = array($itemId => 3); $productId = 4; $productName = "\160\x72\x6f\x64\165\143\x74\137\x6e\x61\x6d\145"; $indexUrl = "\x69\156\144\145\170\x5f\165\162\x6c"; $configureUrl = "\x63\157\x6e\x66\151\x67\x75\162\145\x5f\165\x72\x6c"; $options = array(5 => "\157\160\164\x69\x6f\156"); $params = array("\151\x74\x65\x6d" => $itemId, "\x71\x74\x79" => $qty); $refererUrl = "\x72\x65\x66\x65\162\145\x72\137\165\x72\154"; $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("\x6c\157\141\144", "\x67\145\x74\x49\x64", "\163\145\x74\x51\x74\x79", "\x73\145\164\x4f\x70\164\x69\x6f\x6e\x73", "\x67\145\x74\x42\x75\171\122\145\161\x75\x65\163\x74", "\x6d\145\162\147\x65\102\165\171\122\x65\x71\165\145\x73\x74", "\141\144\144\124\157\x43\141\x72\x74", "\x67\145\x74\120\162\157\144\x75\x63\x74"))->addMethods(array("\x67\145\164\127\x69\x73\x68\x6c\x69\163\164\111\144", "\147\145\x74\120\162\157\x64\165\x63\164\x49\x64"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("\143\162\x65\141\164\x65")->willReturn($itemMock); $itemMock->expects($this->once())->method("\154\157\x61\x64")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("\x67\x65\164\x49\x64")->willReturn($itemId); $itemMock->expects($this->once())->method("\147\145\x74\127\151\x73\150\154\x69\163\164\111\x64")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("\147\x65\164\127\151\x73\x68\154\151\x73\x74")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("\x67\145\164\x50\141\x72\141\155")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "\151\x74\145\155") { return $itemId; } elseif ($arg1 == "\161\164\x79") { return $qty; } }); $this->quantityProcessorMock->expects($this->once())->method("\160\162\x6f\143\145\x73\x73")->with($qty[$itemId])->willReturnArgument(0); $itemMock->expects($this->once())->method("\x73\145\164\x51\x74\x79")->with($qty[$itemId])->willReturnSelf(); $itemMock->expects($this->once())->method("\x67\145\164\120\x72\x6f\x64\165\143\x74\111\x64")->willReturn($productId); $this->urlMock->method("\x67\145\164\x55\162\154")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "\52\x2f\52" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "\52\x2f\52\x2f\143\157\156\x66\x69\147\x75\162\145\57" && $arg2["\151\144"] == $itemId && $arg2["\160\x72\x6f\x64\165\143\x74\137\151\144"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("\143\x72\x65\141\164\145")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("\x67\x65\164\x43\x6f\x6c\x6c\145\x63\x74\x69\157\156")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("\141\x64\144\x49\164\145\x6d\x46\x69\x6c\x74\x65\x72")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("\147\145\164\117\x70\x74\151\x6f\156\x73\102\171\x49\164\145\155")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("\163\x65\164\x4f\x70\x74\x69\x6f\156\x73")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("\147\145\x74\120\141\162\141\155\163")->willReturn($params); $this->requestMock->expects($this->once())->method("\151\x73\101\152\141\x78")->willReturn($isAjax); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("\x67\x65\x74\102\x75\171\122\x65\161\165\145\x73\164")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("\141\x64\x64\120\141\162\x61\155\163\124\157\102\x75\171\x52\145\161\x75\x65\163\x74")->with($params, array("\x63\x75\162\162\145\156\x74\x5f\x63\157\156\146\151\147" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("\155\x65\162\147\x65\102\x75\x79\x52\x65\161\x75\145\x73\x74")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("\x61\144\x64\124\x6f\103\141\162\164")->with($this->checkoutCartMock, true)->willReturn(true); $this->checkoutCartMock->expects($this->once())->method("\163\141\x76\x65")->willReturnSelf(); $quoteMock = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->onlyMethods(array("\x63\157\154\x6c\145\x63\164\124\157\x74\x61\x6c\163"))->addMethods(array("\x67\145\164\x48\x61\163\105\x72\162\x6f\x72"))->getMock(); $this->checkoutCartMock->expects($this->exactly(2))->method("\147\x65\164\x51\165\157\x74\x65")->willReturn($quoteMock); $quoteMock->expects($this->once())->method("\143\157\154\x6c\x65\143\164\124\157\x74\x61\x6c\x73")->willReturnSelf(); $wishlistMock->expects($this->once())->method("\163\x61\x76\145")->willReturnSelf(); $quoteMock->expects($this->once())->method("\147\145\164\x48\x61\163\x45\162\162\157\162")->willReturn(false); $productMock = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->atLeastOnce())->method("\x67\x65\164\x50\162\x6f\144\165\x63\x74")->willReturn($productMock); $productMock->expects($this->atLeastOnce())->method("\147\x65\164\116\141\x6d\x65")->willReturn($productName); $this->messageManagerMock->expects($this->once())->method("\141\144\x64\103\157\155\x70\x6c\x65\x78\123\165\x63\143\145\x73\163\x4d\x65\163\163\141\x67\x65")->willReturnSelf(); $this->cartHelperMock->expects($this->once())->method("\x67\x65\x74\x53\x68\x6f\x75\154\144\122\x65\144\x69\162\x65\143\x74\x54\x6f\x43\141\x72\x74")->willReturn(false); $this->redirectMock->expects($this->once())->method("\x67\x65\164\122\x65\x66\145\x72\145\x72\x55\x72\x6c")->willReturn($refererUrl); $this->helperMock->expects($this->once())->method("\x63\141\154\x63\165\x6c\x61\164\x65")->willReturnSelf(); return $refererUrl; } public function testExecuteWithoutQuantityArrayAndOutOfStock() : void { $itemId = 2; $wishlistId = 1; $qty = array(); $productId = 4; $indexUrl = "\151\x6e\x64\145\x78\x5f\x75\162\154"; $configureUrl = "\143\x6f\156\x66\x69\x67\165\162\x65\137\165\x72\x6c"; $options = array(5 => "\157\160\164\151\x6f\x6e"); $params = array("\x69\x74\x65\x6d" => $itemId, "\x71\x74\171" => $qty); $this->formKeyValidator->expects($this->once())->method("\166\141\x6c\x69\144\141\164\145")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("\154\157\x61\x64", "\147\145\x74\x49\x64", "\x73\145\x74\121\x74\171", "\163\x65\x74\x4f\x70\x74\x69\x6f\x6e\x73", "\147\x65\x74\x42\165\x79\122\x65\161\x75\145\163\164", "\x6d\x65\162\147\x65\102\x75\171\x52\145\161\x75\x65\163\x74", "\141\x64\144\124\157\103\x61\162\164", "\x67\145\164\x50\162\x6f\x64\x75\x63\x74"))->addMethods(array("\147\x65\164\127\151\x73\x68\x6c\151\x73\164\x49\144", "\x67\145\x74\120\x72\157\x64\165\143\164\111\144"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("\143\162\x65\x61\x74\x65")->willReturn($itemMock); $itemMock->expects($this->once())->method("\154\157\x61\144")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("\147\145\x74\111\144")->willReturn($itemId); $itemMock->expects($this->once())->method("\147\x65\x74\x57\151\163\x68\154\x69\x73\164\x49\x64")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("\x67\145\x74\127\151\163\150\x6c\151\163\x74")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("\x67\145\x74\120\141\x72\x61\x6d")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "\151\x74\145\155") { return $itemId; } elseif ($arg1 == "\161\x74\x79") { return $qty; } }); $this->quantityProcessorMock->expects($this->once())->method("\160\162\x6f\x63\x65\x73\163")->with(1)->willReturnArgument(0); $itemMock->expects($this->once())->method("\x73\145\164\x51\164\171")->with(1)->willReturnSelf(); $itemMock->expects($this->once())->method("\x67\145\x74\120\x72\x6f\144\165\x63\164\111\x64")->willReturn($productId); $this->urlMock->method("\x67\x65\164\125\x72\154")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "\52\x2f\x2a" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "\52\57\x2a\57\x63\x6f\x6e\x66\x69\x67\x75\162\145\57" && $arg2["\151\x64"] == $itemId && $arg2["\x70\x72\x6f\144\x75\x63\164\137\x69\144"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("\x63\162\145\x61\164\x65")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("\147\145\164\103\157\154\x6c\145\x63\164\151\x6f\x6e")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("\x61\x64\x64\x49\164\145\155\x46\x69\x6c\x74\145\162")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("\147\x65\164\x4f\160\164\x69\157\x6e\x73\x42\x79\111\x74\145\x6d")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("\163\x65\164\x4f\x70\164\x69\x6f\x6e\163")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("\x67\x65\x74\120\x61\x72\x61\155\x73")->willReturn($params); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("\x67\145\164\x42\165\x79\122\x65\x71\x75\x65\163\164")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("\x61\144\x64\x50\141\162\x61\155\163\124\x6f\x42\165\x79\x52\145\x71\165\145\x73\x74")->with($params, array("\143\165\x72\x72\x65\156\x74\137\x63\157\156\146\151\x67" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("\x6d\x65\x72\147\x65\102\x75\x79\x52\x65\161\x75\x65\163\x74")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("\141\144\144\x54\157\103\x61\162\x74")->with($this->checkoutCartMock, true)->willThrowException(new ProductException(__("\124\145\163\x74\x20\x50\x68\162\141\163\145"))); $this->messageManagerMock->expects($this->once())->method("\141\x64\x64\x45\162\162\157\x72\115\x65\x73\163\x61\147\145")->with("\124\150\x69\163\40\160\x72\157\x64\x75\x63\x74\x28\163\x29\40\151\163\40\157\x75\x74\x20\157\x66\x20\163\164\157\x63\x6b\x2e", null)->willReturnSelf(); $this->helperMock->expects($this->once())->method("\143\x61\x6c\x63\165\154\x61\164\x65")->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method("\x73\x65\164\125\162\154")->with($indexUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithoutQuantityArrayAndConfigurable() : void { $itemId = 2; $wishlistId = 1; $qty = array(); $productId = 4; $indexUrl = "\151\156\144\x65\x78\x5f\165\162\154"; $configureUrl = "\x63\x6f\x6e\146\x69\x67\165\x72\145\x5f\165\x72\x6c"; $options = array(5 => "\x6f\x70\164\151\x6f\x6e"); $params = array("\151\x74\145\x6d" => $itemId, "\161\x74\171" => $qty); $this->formKeyValidator->expects($this->once())->method("\x76\x61\154\x69\144\x61\x74\145")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("\154\157\141\x64", "\147\x65\164\x49\144", "\x73\x65\164\121\x74\171", "\163\x65\164\x4f\x70\164\x69\x6f\x6e\x73", "\x67\x65\x74\x42\165\x79\x52\145\161\165\x65\163\x74", "\155\145\162\147\145\x42\x75\171\x52\145\161\165\x65\x73\x74", "\x61\144\144\x54\157\103\x61\x72\164", "\x67\145\x74\x50\x72\157\x64\165\x63\164"))->addMethods(array("\x67\x65\x74\x57\151\x73\150\154\x69\163\x74\x49\x64", "\147\145\164\120\162\157\144\165\143\164\111\144"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("\x63\x72\145\x61\x74\x65")->willReturn($itemMock); $itemMock->expects($this->once())->method("\154\x6f\x61\144")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("\x67\145\x74\x49\x64")->willReturn($itemId); $itemMock->expects($this->once())->method("\147\145\x74\x57\151\163\x68\x6c\151\x73\x74\x49\144")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("\x67\145\x74\x57\151\163\150\154\151\x73\164")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("\147\145\164\120\x61\x72\x61\155")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "\151\164\145\x6d") { return $itemId; } elseif ($arg1 == "\161\164\x79") { return $qty; } }); $this->quantityProcessorMock->expects($this->once())->method("\160\x72\x6f\x63\x65\163\x73")->with(1)->willReturnArgument(0); $itemMock->expects($this->once())->method("\163\145\x74\x51\164\x79")->with(1)->willReturnSelf(); $itemMock->expects($this->once())->method("\147\145\x74\120\x72\157\144\x75\x63\164\111\144")->willReturn($productId); $this->urlMock->method("\x67\x65\x74\125\162\x6c")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "\52\57\x2a" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "\52\57\x2a\x2f\143\157\x6e\x66\151\147\x75\162\145\57" && $arg2["\x69\144"] == $itemId && $arg2["\160\162\x6f\144\x75\x63\x74\x5f\151\x64"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("\x63\x72\x65\141\164\x65")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("\x67\145\x74\x43\x6f\x6c\154\x65\143\x74\x69\157\x6e")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("\141\144\x64\111\164\x65\x6d\x46\151\x6c\x74\x65\162")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("\x67\x65\164\x4f\x70\x74\x69\157\x6e\x73\x42\171\x49\164\145\x6d")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("\x73\x65\164\x4f\160\164\x69\157\x6e\163")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("\147\x65\x74\120\x61\162\141\x6d\163")->willReturn($params); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("\147\145\x74\102\165\x79\x52\145\161\165\x65\x73\164")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("\141\x64\x64\120\x61\x72\x61\x6d\x73\124\157\102\x75\171\x52\x65\x71\165\145\163\164")->with($params, array("\x63\165\x72\x72\145\156\164\137\x63\157\x6e\146\151\147" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("\155\x65\x72\x67\x65\x42\x75\x79\122\145\x71\x75\145\x73\164")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("\141\144\144\x54\157\103\141\x72\x74")->with($this->checkoutCartMock, true)->willThrowException(new LocalizedException(__("\x6d\x65\163\x73\x61\x67\x65"))); $this->messageManagerMock->expects($this->once())->method("\141\x64\144\x4e\157\164\151\x63\x65\115\145\163\x73\141\147\145")->with("\x6d\145\163\x73\141\147\x65", null)->willReturnSelf(); $this->helperMock->expects($this->once())->method("\x63\141\154\143\x75\x6c\x61\164\145")->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method("\x73\145\164\x55\x72\x6c")->with($configureUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } public function testExecuteWithEditQuantity() : void { $itemId = 2; $wishlistId = 1; $qty = 1; $postQty = 2; $productId = 4; $indexUrl = "\151\156\x64\145\170\137\x75\162\x6c"; $configureUrl = "\x63\157\156\x66\x69\x67\x75\162\x65\137\165\162\x6c"; $options = array(5 => "\157\x70\164\x69\x6f\156"); $params = array("\151\164\x65\155" => $itemId, "\x71\x74\171" => $qty); $this->formKeyValidator->expects($this->once())->method("\x76\141\x6c\x69\x64\x61\x74\x65")->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->onlyMethods(array("\154\157\x61\144", "\147\x65\164\x49\144", "\163\x65\x74\x51\164\x79", "\163\145\x74\x4f\160\164\151\x6f\x6e\163", "\147\145\x74\x42\x75\171\x52\x65\x71\x75\x65\163\x74", "\x6d\x65\x72\x67\145\102\x75\171\x52\x65\161\x75\x65\163\x74", "\141\x64\x64\124\x6f\x43\141\x72\x74", "\147\x65\164\x50\x72\x6f\144\165\x63\164"))->addMethods(array("\147\145\164\127\x69\163\150\x6c\x69\163\164\111\x64", "\147\145\164\120\x72\x6f\x64\165\x63\x74\x49\144"))->getMock(); $this->itemFactoryMock->expects($this->once())->method("\143\x72\145\141\x74\145")->willReturn($itemMock); $itemMock->expects($this->once())->method("\154\x6f\x61\144")->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method("\147\x65\164\x49\144")->willReturn($itemId); $itemMock->expects($this->once())->method("\147\145\164\x57\x69\x73\150\154\x69\163\164\x49\x64")->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder(Wishlist::class)->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method("\x67\145\164\x57\x69\x73\x68\x6c\151\163\164")->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->method("\x67\145\x74\120\x61\x72\141\155")->willReturnCallback(function ($arg1, $arg2) use($itemId, $qty) { if ($arg1 == "\x69\164\x65\155") { return $itemId; } elseif ($arg1 == "\161\x74\x79") { return $qty; } }); $this->requestMock->expects($this->once())->method("\147\145\x74\x50\157\163\164\126\141\x6c\165\x65")->with("\161\164\x79")->willReturn($postQty); $this->quantityProcessorMock->expects($this->once())->method("\160\162\x6f\x63\145\163\x73")->with($postQty)->willReturnArgument(0); $itemMock->expects($this->once())->method("\163\x65\x74\121\164\171")->with($postQty)->willReturnSelf(); $itemMock->expects($this->once())->method("\147\145\164\x50\x72\x6f\144\165\x63\164\x49\144")->willReturn($productId); $this->urlMock->method("\x67\x65\164\125\162\x6c")->willReturnCallback(function ($arg1, $arg2) use($indexUrl, $configureUrl, $itemId, $productId) { if ($arg1 == "\52\57\52" && is_null($arg2)) { return $indexUrl; } elseif ($arg1 == "\x2a\x2f\52\x2f\143\157\x6e\x66\151\147\165\x72\x65\x2f" && $arg2["\151\x64"] == $itemId && $arg2["\160\162\x6f\144\x75\143\164\x5f\x69\x64"] == $productId) { return $configureUrl; } }); $optionMock = $this->getMockBuilder(Option::class)->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method("\x63\162\x65\x61\164\145")->willReturn($optionMock); $optionsMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method("\147\145\164\x43\x6f\154\x6c\x65\143\164\x69\x6f\156")->willReturn($optionsMock); $optionsMock->expects($this->once())->method("\x61\144\x64\x49\164\145\155\x46\151\154\164\145\x72")->with(array($itemId))->willReturnSelf(); $optionsMock->expects($this->once())->method("\147\x65\164\x4f\x70\164\x69\x6f\x6e\x73\102\171\x49\164\145\155")->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method("\163\x65\x74\x4f\160\x74\x69\157\156\x73")->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method("\x67\145\x74\x50\x61\x72\141\155\x73")->willReturn($params); $buyRequestMock = $this->getMockBuilder(DataObject::class)->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method("\147\x65\164\x42\165\x79\122\145\161\x75\145\x73\164")->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method("\x61\x64\144\120\x61\162\141\155\x73\x54\x6f\x42\x75\x79\x52\x65\x71\165\x65\x73\x74")->with($params, array("\x63\165\x72\x72\145\156\164\137\143\157\156\x66\x69\147" => $buyRequestMock))->willReturn($buyRequestMock); $itemMock->expects($this->once())->method("\155\x65\x72\147\x65\102\165\x79\x52\x65\161\165\x65\163\x74")->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method("\x61\x64\x64\x54\x6f\x43\141\x72\164")->with($this->checkoutCartMock, true)->willThrowException(new LocalizedException(__("\x6d\145\x73\x73\x61\147\x65"))); $this->messageManagerMock->expects($this->once())->method("\x61\x64\144\x4e\157\x74\x69\143\x65\115\x65\163\163\141\147\145")->with("\x6d\145\163\x73\x61\x67\145", null)->willReturnSelf(); $this->helperMock->expects($this->once())->method("\143\x61\154\x63\165\154\x61\x74\145")->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method("\x73\145\164\x55\x72\154")->with($configureUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); } }

Function Calls

None

Variables

None

Stats

MD5 a37b1ca5ca57d699dbee1e571130a2b3
Eval Count 0
Decode Time 121 ms