/** * Initialize reader instance */ protected function setUp() { $path = array(__DIR__, '..', '..', '_files', 'acl.xml'); $path = realpath(implode(DIRECTORY_SEPARATOR, $path)); $this->_configMock = $this->getMock('Mage_Core_Model_Config', array(), array(), '', false); $this->_configMock->expects($this->any())->method('getModuleDir')->with('etc', 'Mage_Webapi')->will($this->returnValue(realpath(__DIR__ . '/../../../../../../../../../app/code/core/Mage/Webapi/etc'))); $this->_reader = new Mage_Webapi_Model_Authorization_Config_Reader($this->_configMock, array($path)); }
/** * Set up before test */ protected function setUp() { $helper = new Magento_Test_Helper_ObjectManager($this); $this->_config = $this->getMockBuilder('Mage_Core_Model_Config')->disableOriginalConstructor()->setMethods(array('getModuleConfigurationFiles'))->getMock(); $this->_readerFactory = $this->getMockBuilder('Mage_Webapi_Model_Authorization_Config_Reader_Factory')->disableOriginalConstructor()->setMethods(array('createReader'))->getMock(); $this->_configReader = $this->getMockBuilder('Magento_Acl_Config_Reader')->disableOriginalConstructor()->setMethods(array('getAclResources'))->getMock(); $this->_model = $helper->getModel('Mage_Webapi_Model_Authorization_Config', array('config' => $this->_config, 'readerFactory' => $this->_readerFactory)); $this->_config->expects($this->any())->method('getModuleConfigurationFiles')->will($this->returnValue(array())); $this->_readerFactory->expects($this->any())->method('createReader')->will($this->returnValue($this->_configReader)); }
/** * Save default translator */ protected function setUp() { $this->_defaultTranslator = Magento_Validator_ValidatorAbstract::getDefaultTranslator(); $this->_objectManager = $this->getMockBuilder('Magento_ObjectManager_Zend')->setMethods(array('create', 'get'))->disableOriginalConstructor()->getMock(); $this->_validatorConfig = $this->getMockBuilder('Magento_Validator_Config')->setMethods(array('createValidatorBuilder', 'createValidator'))->disableOriginalConstructor()->getMock(); $this->_objectManager->expects($this->once())->method('get')->with('Magento_Validator_Config', array('configFiles' => array('/tmp/moduleOne/etc/validation.xml')))->will($this->returnValue($this->_validatorConfig)); $this->_objectManager->expects($this->at(0))->method('create')->with('Magento_Translate_Adapter')->will($this->returnValue(new Magento_Translate_Adapter())); // Config mock $this->_config = $this->getMockBuilder('Mage_Core_Model_Config')->setMethods(array('getModuleConfigurationFiles'))->disableOriginalConstructor()->getMock(); $this->_config->expects($this->once())->method('getModuleConfigurationFiles')->with('validation.xml')->will($this->returnValue(array('/tmp/moduleOne/etc/validation.xml'))); // Translate adapter mock $this->_translateAdapter = $this->getMockBuilder('Mage_Core_Model_Translate')->disableOriginalConstructor()->setMethods(array('_getTranslatedString'))->getMock(); $this->_translateAdapter->expects($this->any())->method('_getTranslatedString')->will($this->returnArgument(0)); }
/** * Test get method with wrong Renderer class. */ public function testGetWithWrongRendererClass() { $acceptTypes = array('application/json'); $availableRenders = $this->_createConfigElementForRenders(); /** Mock application config getNode method to return the list of renders. */ $this->_applicationMock->expects($this->once())->method('getNode')->will($this->returnValue($availableRenders)); /** Mock request getAcceptTypes method to return specified value. */ $this->_requestMock->expects($this->once())->method('getAcceptTypes')->will($this->returnValue($acceptTypes)); /** Mock object to return Varien_Object */ $this->_objectManagerMock->expects($this->once())->method('get')->with('Mage_Webapi_Controller_Response_Rest_Renderer_Json')->will($this->returnValue(new Varien_Object())); $this->setExpectedException('LogicException', 'The renderer must implement "Mage_Webapi_Controller_Response_Rest_RendererInterface".'); $this->_factory->get(); }
/** * @param string $key * @param string $fileOrWrapper * @dataProvider addStreamLogDataProvider */ public function testAddStreamLog($key, $fileOrWrapper) { $this->_config->expects($this->any())->method('getNode')->will($this->returnValue('')); $this->assertFalse($this->_model->hasLog($key)); $this->_model->addStreamLog($key, $fileOrWrapper); $this->assertTrue($this->_model->hasLog($key)); $loggers = $this->_loggersProperty->getValue($this->_model); $this->assertArrayHasKey($key, $loggers); $zendLog = $loggers[$key]; $this->assertInstanceOf('Zend_Log', $zendLog); $writersProperty = new ReflectionProperty($zendLog, '_writers'); $writersProperty->setAccessible(true); $writers = $writersProperty->getValue($zendLog); $this->assertArrayHasKey(0, $writers); $stream = $writers[0]; $this->assertInstanceOf('Zend_Log_Writer_Stream', $writers[0]); $streamProperty = new ReflectionProperty($stream, '_stream'); $streamProperty->setAccessible(true); $fileOrWrapper = $streamProperty->getValue($stream); $this->assertInternalType('resource', $fileOrWrapper); $this->assertEquals('stream', get_resource_type($fileOrWrapper)); }
/** * Create Magento_ObjectManager_Zend instance * * @param bool $mockNewInstance */ protected function _prepareObjectManagerForGetCreateTests($mockNewInstance = false) { $this->_magentoConfig = $this->getMock('Mage_Core_Model_Config', array('loadBase'), array(), '', false); $this->_magentoConfig->expects($this->any())->method('loadBase')->will($this->returnSelf()); $this->_instanceManager = $this->getMock('Zend\\Di\\InstanceManager', array('addSharedInstance'), array(), '', false); $this->_diInstance = $this->getMock('Zend\\Di\\Di', array('instanceManager', 'newInstance', 'get', 'setDefinitionList')); $this->_diInstance->expects($this->any())->method('instanceManager')->will($this->returnValue($this->_instanceManager)); if ($mockNewInstance) { $this->_diInstance->expects($this->once())->method('newInstance')->will($this->returnCallback(array($this, 'verifyCreate'))); } else { $this->_diInstance->expects($this->once())->method('get')->will($this->returnCallback(array($this, 'verifyGet'))); } $this->_objectManager = new Magento_ObjectManager_Zend(null, $this->_diInstance); }
protected function setUp() { $this->_configMock = $this->getMock('Mage_Core_Model_Config', array(), array(), '', false); $this->_configMock->expects($this->any())->method('getModuleDir')->with('etc', 'Mage_Backend')->will($this->returnValue(realpath(__DIR__ . '/../../../../../../../../../app/code/core/Mage/Backend/etc'))); }