/** * Test render method */ public function testRender() { $arrayToRender = array('key' => 'value'); /** Assert jsonEncode method in mocked helper will run once */ $this->_helperMock->expects($this->once())->method('jsonEncode'); $this->_restJsonRenderer->render($arrayToRender); }
public function testDuplicateProductTypeFile() { $currentProduct = $this->getMock('Mage_Catalog_Model_Product', array('getTypeId', 'getTypeInstance'), array(), '', false); $currentProduct->expects($this->once())->method('getTypeId')->will($this->returnValue(Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)); $newProduct = $this->getMock('Mage_Catalog_Model_Product', array('getTypeId', 'getTypeInstance'), array(), '', false); $links = $this->_getLinks(); $samples = $this->_getSamples(); $getLinks = new Varien_Object($links); $getSamples = new Varien_Object($samples); $typeInstance = $this->getMock('Mage_Downloadable_Model_Product_Type', array('getLinks', 'getSamples'), array(), '', false); $typeInstance->expects($this->atLeastOnce())->method('getLinks')->will($this->returnValue(array($getLinks))); $typeInstance->expects($this->atLeastOnce())->method('getSamples')->will($this->returnValue(array($getSamples))); $currentProduct->expects($this->atLeastOnce())->method('getTypeInstance')->will($this->returnValue($typeInstance)); $this->_setObserverExpectedMethods($currentProduct, $newProduct); $callbackJsonEncode = function ($arg) { return json_encode($arg); }; $this->_helperJsonEncode->expects($this->atLeastOnce())->method('jsonEncode')->will($this->returnCallback($callbackJsonEncode)); $this->assertNull($newProduct->getDownloadableData($newProduct)); $this->_model->duplicateProduct($this->_observer); $newDownloadableData = $newProduct->getDownloadableData(); $fileData = json_decode($newDownloadableData['link'][0]['file'], true); $this->assertEquals($links['price'], $newDownloadableData['link'][0]['price']); $this->assertEquals($links['link_file'][0], $fileData[0]['file'][0]); $this->assertEquals($samples['title'], $newDownloadableData['sample'][0]['title']); $this->assertEquals(false, $newDownloadableData['link'][0]['is_delete']); $this->assertEquals($links['number_of_downloads'], $newDownloadableData['link'][0]['number_of_downloads']); }
/** * Test to get valid html code for 'image' with placeholder */ public function testImagePlaceholder() { $urlPath = 'http://example.com/pub/images/image-placeholder.png'; $this->_block->setValue(null); $this->_coreHelper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $html = $this->_createHtmlCode('', $urlPath); $this->assertXmlStringEqualsXmlString(str_replace('×', '&times;', "<test>{$html}</test>"), str_replace('×', '&times;', "<test>{$this->_block->getElementHtml()}</test>"), 'Another BaseImage html code is expected'); }
/** * Test to get valid html code for 'image' with placeholder */ public function testImagePlaceholder() { $urlPath = 'http://example.com/pub/images/image-placeholder.png'; $this->_model->setValue(null); $this->_design->expects($this->once())->method('getViewFileUrl')->will($this->returnValue($urlPath)); $this->_helperData->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $html = $this->_createHtmlCode('', $urlPath); $this->assertXmlStringEqualsXmlString("<test>{$html}</test>", "<test>{$this->_model->getElementHtml()}</test>", 'Another BaseImage html code is expected'); }
public function setUp() { $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false); $this->_coreSessionMock = $this->getMock('Mage_Core_Model_Session', array('getFormKey'), array(), '', false); $this->_coreSessionMock->expects($this->any())->method('getFormKey')->will($this->returnValue('salt')); $this->_coreHelperMock = $this->getMock('Mage_Core_Helper_Data', array('getHash'), array(), '', false); $this->_coreHelperMock->expects($this->any())->method('getHash')->will($this->returnArgument(0)); $mockItem = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false); $mockItem->expects($this->any())->method('isDisabled')->will($this->returnValue(false)); $mockItem->expects($this->any())->method('isAllowed')->will($this->returnValue(true)); $mockItem->expects($this->any())->method('getId')->will($this->returnValue('Mage_Adminhtml::system_acl_roles')); $mockItem->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/user_role')); $this->_menuMock->expects($this->any())->method('get')->with($this->equalTo('Mage_Adminhtml::system_acl_roles'))->will($this->returnValue($mockItem)); $helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false); $helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue($this->_areaFrontName)); $this->_routes = array('admin' => 'adminhtml', 'adminhtml' => ''); $this->_model = new Mage_Backend_Model_Url(array('startupMenuItemId' => 'Mage_Adminhtml::system_acl_roles', 'menu' => $this->_menuMock, 'backendHelper' => $helperMock, 'coreSession' => $this->_coreSessionMock, 'coreHelper' => $this->_coreHelperMock, 'routes' => $this->_routes)); $this->_requestMock = $this->getMock('Mage_Core_Controller_Request_Http', array(), array(), '', false); $this->_model->setRequest($this->_requestMock); }
public function setUp() { $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false); $this->_menuConfigMock = $this->getMock('Mage_Backend_Model_Menu_Config', array(), array(), '', false); $this->_menuConfigMock->expects($this->any())->method('getMenu')->will($this->returnValue($this->_menuMock)); $this->_coreSessionMock = $this->getMock('Mage_Core_Model_Session', array('getFormKey'), array(), '', false); $this->_coreSessionMock->expects($this->any())->method('getFormKey')->will($this->returnValue('salt')); $this->_coreHelperMock = $this->getMock('Mage_Core_Helper_Data', array('getHash'), array(), '', false); $this->_coreHelperMock->expects($this->any())->method('getHash')->will($this->returnArgument(0)); $mockItem = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false); $mockItem->expects($this->any())->method('isDisabled')->will($this->returnValue(false)); $mockItem->expects($this->any())->method('isAllowed')->will($this->returnValue(true)); $mockItem->expects($this->any())->method('getId')->will($this->returnValue('Mage_Adminhtml::system_acl_roles')); $mockItem->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/user_role')); $this->_menuMock->expects($this->any())->method('get')->with($this->equalTo('Mage_Adminhtml::system_acl_roles'))->will($this->returnValue($mockItem)); $helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false); $helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue($this->_areaFrontName)); $this->_storeConfigMock = $this->getMock('Mage_Core_Model_Store_Config', array(), array(), '', false); $this->_storeConfigMock->expects($this->any())->method('getConfig')->with(Mage_Backend_Model_Url::XML_PATH_STARTUP_MENU_ITEM)->will($this->returnValue('Mage_Adminhtml::system_acl_roles')); $this->_model = new Mage_Backend_Model_Url($helperMock, $this->_coreHelperMock, $this->_coreSessionMock, $this->_storeConfigMock, $this->_menuConfigMock); $this->_requestMock = $this->getMock('Mage_Core_Controller_Request_Http', array(), array(), '', false); $this->_model->setRequest($this->_requestMock); }