public function testExecute() { $this->_getTreeBlock(); $testCategoryId = 1; $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue($testCategoryId)); $categoryMock = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $categoryMock->expects($this->once())->method('load')->will($this->returnValue($categoryMock)); $categoryMock->expects($this->once())->method('getId')->will($this->returnValue($testCategoryId)); $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Catalog\\Model\\Category'))->will($this->returnValue($categoryMock)); $this->chooserBlockMock->expects($this->once())->method('setSelectedCategories')->will($this->returnValue($this->chooserBlockMock)); $testHtml = '<div>Some test html</div>'; $this->chooserBlockMock->expects($this->once())->method('getTreeJson')->will($this->returnValue($testHtml)); $this->resultJson->expects($this->once())->method('setJsonData')->with($testHtml)->willReturnSelf(); $this->controller->execute(); }
/** * @dataProvider getCurrentUrlDataProvider * * @param boolean $secure * @param string $url * @param string $expected */ public function testGetCurrentUrl($secure, $url, $expected) { $defaultStore = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId', 'isCurrentlySecure', '__wakeup'], [], '', false); $defaultStore->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(5)); $defaultStore->expects($this->atLeastOnce())->method('isCurrentlySecure')->will($this->returnValue($secure)); $sidResolver = $this->getMockForAbstractClass('\\Magento\\Framework\\Session\\SidResolverInterface'); $sidResolver->expects($this->any())->method('getSessionIdQueryParam')->will($this->returnValue('SID')); $config = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\Config\\ReinitableConfigInterface'); $this->requestMock->expects($this->atLeastOnce())->method('getRequestString')->will($this->returnValue('')); $this->requestMock->expects($this->atLeastOnce())->method('getQuery')->will($this->returnValue(['SID' => 'sid'])); $urlMock = $this->getMockForAbstractClass('\\Magento\\Framework\\UrlInterface'); $urlMock->expects($this->atLeastOnce())->method('setScope')->will($this->returnSelf()); $urlMock->expects($this->any())->method('getUrl')->will($this->returnValue($url)); $storeManager = $this->getMockForAbstractClass('\\Magento\\Framework\\StoreManagerInterface'); $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($defaultStore)); /** @var \Magento\Store\Model\Store $model */ $model = $this->objectManagerHelper->getObject('Magento\\Store\\Model\\Store', ['storeManager' => $storeManager, 'url' => $urlMock, 'request' => $this->requestMock, 'config' => $config]); $model->setStoreId(2); $model->setCode('scope_code'); $this->assertEquals($expected, $model->getCurrentUrl(false)); }