/** * @magentoDataFixture Mage/Core/_files/layout_update.php */ public function testFetchUpdatesByHandle() { /** @var $resourceLayoutUpdate Mage_Core_Model_Resource_Layout_Update */ $resourceLayoutUpdate = $this->_objectManager->create('Mage_Core_Model_Resource_Layout_Update'); $result = $resourceLayoutUpdate->fetchUpdatesByHandle('test_handle'); $this->assertEquals('not_temporary', $result); }
/** * Retrieve subject * * @return Mage_Backend_Model_Config_Structure_SearchInterface */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = $this->_objectManager->get('Mage_Backend_Model_Config_Structure'); } return $this->_subject; }
/** * Retrieve subject * * @return Mage_Backend_Model_Config_Structure_Element_Group */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = $this->_objectManager->create('Mage_Backend_Model_Config_Structure_Element_Group'); } return $this->_subject; }
/** * Get renderer for Mime-Type specified in Accept header of request. * * @return Mage_Webapi_Controller_Response_Rest_RendererInterface * @throws Mage_Webapi_Exception * @throws LogicException */ public function get() { $acceptTypes = $this->_request->getAcceptTypes(); $availableRenderers = (array) $this->_applicationConfig->getNode(self::XML_PATH_WEBAPI_RESPONSE_RENDERS); if (!is_array($acceptTypes)) { $acceptTypes = array($acceptTypes); } foreach ($acceptTypes as $acceptType) { foreach ($availableRenderers as $rendererConfig) { $rendererType = (string) $rendererConfig->type; if ($acceptType == $rendererType || $acceptType == current(explode('/', $rendererType)) . '/*' || $acceptType == '*/*') { $rendererClass = (string) $rendererConfig->model; break 2; } } } if (!isset($rendererClass)) { /** If server does not have renderer for any of the accepted types it SHOULD send 406 (not acceptable). */ throw new Mage_Webapi_Exception($this->_helper->__('Server cannot understand Accept HTTP header media type.'), Mage_Webapi_Exception::HTTP_NOT_ACCEPTABLE); } $renderer = $this->_objectManager->get($rendererClass); if (!$renderer instanceof Mage_Webapi_Controller_Response_Rest_RendererInterface) { throw new LogicException('The renderer must implement "Mage_Webapi_Controller_Response_Rest_RendererInterface".'); } return $renderer; }
/** * @param Mage_Core_Model_Event_Manager $eventDispatcher * @param Mage_Core_Model_Cache $cacheManager * @param Mage_Core_Model_Resource_Abstract $resource * @param Varien_Data_Collection_Db $resourceCollection * @param Varien_Io_File $ioFile * @param Magento_ObjectManager $objectManager * @param array $data */ public function __construct(Mage_Core_Model_Event_Manager $eventDispatcher, Mage_Core_Model_Cache $cacheManager, Varien_Io_File $ioFile, Magento_ObjectManager $objectManager, Mage_Core_Model_Resource_Abstract $resource = null, Varien_Data_Collection_Db $resourceCollection = null, array $data = array()) { parent::__construct($eventDispatcher, $cacheManager, $resource, $resourceCollection, $data); $this->_ioFile = $ioFile; $this->_objectManager = $objectManager; $this->_design = $this->_objectManager->get('Mage_Core_Model_Design_Package'); }
/** * Create front controller instance. * * Use current API type to define proper request class. * * @param string $apiType * @return Mage_Webapi_Controller_DispatcherInterface * @throws LogicException If there is no corresponding dispatcher class for current API type. */ public function get($apiType) { if (!isset($this->_apiDispatcherMap[$apiType])) { throw new LogicException(sprintf('There is no corresponding dispatcher class for the "%s" API type.', $apiType)); } $dispatcherClass = $this->_apiDispatcherMap[$apiType]; return $this->_objectManager->get($dispatcherClass); }
/** * Create new url generator instance * * @param string $generatorClassName * @param array $arguments * @return Mage_Backend_Model_Widget_Grid_Row_UrlGenerator * @throws InvalidArgumentException */ public function createUrlGenerator($generatorClassName, array $arguments = array()) { $rowUrlGenerator = $this->_objectManager->create($generatorClassName, $arguments, false); if (false === $rowUrlGenerator instanceof Mage_Backend_Model_Widget_Grid_Row_UrlGenerator) { throw new InvalidArgumentException('Passed wrong parameters'); } return $rowUrlGenerator; }
/** * Create new config object * * @param string $type * @return Mage_Backend_Model_Config_CommentInterface * @throws InvalidArgumentException */ public function create($type) { $commentModel = $this->_objectManager->create($type); if (!$commentModel instanceof Mage_Backend_Model_Config_CommentInterface) { throw new InvalidArgumentException('Incorrect comment model provided'); } return $commentModel; }
/** * Create backend model by name * * @param string $modelName * @return Mage_Core_Model_Config_Data * @throws InvalidArgumentException */ public function create($modelName) { $model = $this->_objectManager->create($modelName); if (!$model instanceof Mage_Core_Model_Config_Data) { throw new InvalidArgumentException('Invalid config field backend model: ' . $modelName); } return $model; }
/** * Create front controller instance. * * @param string $className * @param Mage_Webapi_Controller_Request $request * @return Mage_Webapi_Controller_ActionAbstract * @throws InvalidArgumentException */ public function createActionController($className, $request) { $actionController = $this->_objectManager->create($className, array('request' => $request)); if (!$actionController instanceof Mage_Webapi_Controller_ActionAbstract) { throw new InvalidArgumentException('The specified class is not a valid API action controller.'); } return $actionController; }
/** * Create route instance. * * @param $routeClass * @param string $route Map used to match with later submitted URL path * @param array $defaults Defaults for map variables with keys as variable names * @param array $reqs Regular expression requirements for variables (keys as variable names) * @param mixed $locale * @return Zend_Controller_Router_Route_Interface * @throws LogicException If specified route class does not implement proper interface. */ public function createRoute($routeClass, $route, $defaults = array(), $reqs = array(), $locale = null) { $route = $this->_objectManager->create($routeClass, array('route' => $route, 'defaults' => $defaults, 'regs' => $reqs, 'locale' => $locale), false); if (!$route instanceof Zend_Controller_Router_Route_Interface) { throw new LogicException('Route must implement "Zend_Controller_Router_Route_Interface".'); } return $route; }
/** * Test get method. */ public function testGet() { /** Mock front controller mock to return Soap api type. */ $this->_apiFrontController->expects($this->once())->method('determineApiType')->will($this->returnValue(Mage_Webapi_Controller_Front::API_TYPE_SOAP)); /** Assert object manager get method will be executed once with Mage_Webapi_Controller_Response parameter. */ $this->_objectManager->expects($this->once())->method('get')->with('Mage_Webapi_Controller_Response'); $this->_factory->get(); }
/** * Create response object. * * Use current API type to define proper response class. * * @return Mage_Webapi_Controller_Response * @throws LogicException If there is no corresponding response class for current API type. */ public function get() { $apiType = $this->_apiFrontController->determineApiType(); if (!isset($this->_apiResponseMap[$apiType])) { throw new LogicException(sprintf('There is no corresponding response class for the "%s" API type.', $apiType)); } $requestClass = $this->_apiResponseMap[$apiType]; return $this->_objectManager->get($requestClass); }
/** * Get mapper instance * * @param string $type * @param array $arguments * @return Mage_Backend_Model_Config_Structure_MapperInterface * @throws Exception */ public function create($type, $arguments = array()) { $className = $this->_getMapperClassNameByType($type); /** @var Mage_Backend_Model_Config_Structure_MapperInterface $mapperInstance */ $mapperInstance = $this->_objectManager->get($className, $arguments); if (false == $mapperInstance instanceof Mage_Backend_Model_Config_Structure_MapperInterface) { throw new Exception('Mapper object is not instance on Mage_Backend_Model_Config_Structure_MapperInterface'); } return $mapperInstance; }
/** * Get argument handler factory by given type * @param string $type * @return Mage_Core_Model_Layout_Argument_HandlerInterface * @throws InvalidArgumentException */ public function getArgumentHandlerByType($type) { if (false == is_string($type)) { throw new InvalidArgumentException('Passed invalid argument handler type'); } if (!isset($this->_handlerFactories[$type])) { throw new InvalidArgumentException('Argument handler ' . $type . ' is not exists'); } return $this->_objectManager->create($this->_handlerFactories[$type], array(), false); }
/** * Test action controller method with exception. */ public function testCreateActionControllerWithException() { /** Create object of class which is not instance of Mage_Webapi_Controller_ActionAbstract. */ $wrongController = new Varien_Object(); /** Create request object. */ $request = new Mage_Webapi_Controller_Request('SOAP'); /** Mock object manager create method to return wrong controller */ $this->_objectManagerMock->expects($this->any())->method('create')->will($this->returnValue($wrongController)); $this->setExpectedException('InvalidArgumentException', 'The specified class is not a valid API action controller.'); $this->_factory->createActionController('ClassName', $request); }
/** * @param string $className * @param array $routerInfo * @return Mage_Core_Controller_Varien_Router_Abstract */ public function createRouter($className, array $routerInfo = array()) { $arguments = array('areaCode' => null, 'baseController' => null); if (isset($routerInfo['area'])) { $arguments['areaCode'] = $routerInfo['area']; } if (isset($routerInfo['base_controller'])) { $arguments['baseController'] = $routerInfo['base_controller']; } return $this->_objectManager->get($className, $arguments); }
/** * @param array $eventData * @param bool $needLock * * @dataProvider safeProcessEventDataProvider */ public function testSafeProcessEvent(array $eventData, $needLock = false) { if ($needLock) { $this->_processFile->processLock(); } $event = $this->_objectManager->create('Mage_Index_Model_Event', array('data' => $eventData)); $this->assertEquals($this->_model, $this->_model->safeProcessEvent($event)); if ($needLock) { $this->_processFile->processUnlock(); } $this->assertFalse($this->_processFile->isProcessLocked(true)); }
/** * Apply all updater to value * * @param mixed $value * @param array $updaters * @throws InvalidArgumentException * @return mixed */ public function applyUpdaters($value, array $updaters = array()) { foreach ($updaters as $updater) { /** @var Mage_Core_Model_Layout_Argument_UpdaterInterface $updaterInstance */ $updaterInstance = $this->_objectManager->create($updater, array(), false); if (false === $updaterInstance instanceof Mage_Core_Model_Layout_Argument_UpdaterInterface) { throw new InvalidArgumentException($updater . ' should implement Mage_Core_Model_Layout_Argument_UpdaterInterface'); } $value = $updaterInstance->update($value); } return $value; }
/** * @magentoDataFixture Mage/Core/_files/layout_update.php */ public function testMakeTemporaryLayoutUpdatesPermanent() { /** @var $coreLayoutUpdate Mage_Core_Model_Resource_Layout_Update */ $coreLayoutUpdate = $this->_objectManager->create('Mage_Core_Model_Resource_Layout_Update'); $resultBefore = $coreLayoutUpdate->fetchUpdatesByHandle('test_handle'); $this->assertEquals('not_temporary', $resultBefore); /** @var $vdeLayoutUpdate Mage_DesignEditor_Model_Resource_Layout_Update */ $vdeLayoutUpdate = $this->_objectManager->create('Mage_DesignEditor_Model_Resource_Layout_Update'); $vdeLayoutUpdate->makeTemporaryLayoutUpdatesPermanent($this->_design->getDesignTheme()->getThemeId(), array(Mage_Core_Model_App::ADMIN_STORE_ID)); $resultAfter = $coreLayoutUpdate->fetchUpdatesByHandle('test_handle'); $this->assertEquals('not_temporarytemporary', $resultAfter); }
/** * Test getValidatorConfig created correct validator config. Check that validator translator was initialized. */ public function testGetValidatorConfig() { $this->_objectManager->expects($this->at(2))->method('create')->with('Mage_Core_Model_Translate_Expr')->will($this->returnValue(new Mage_Core_Model_Translate_Expr())); $factory = new Mage_Core_Model_Validator_Factory($this->_objectManager, $this->_config, $this->_translateAdapter); $actualConfig = $factory->getValidatorConfig(); $this->assertInstanceOf('Magento_Validator_Config', $actualConfig, 'Object of incorrect type was created'); // Check that validator translator was correctly instantiated $validatorTranslator = Magento_Validator_ValidatorAbstract::getDefaultTranslator(); $this->assertInstanceOf('Magento_Translate_Adapter', $validatorTranslator, 'Default validator translate adapter was not set correctly'); // Dive into callback /** @var Mage_Core_Model_Translate $translateAdapter */ $this->assertEquals('Test message', $validatorTranslator->translate('Test message'), 'Translator callback function was not initialized'); }
/** * Create a form element with necessary controls * * @return Mage_Theme_Block_Adminhtml_System_Design_Theme_Edit_Tab_Css */ protected function _prepareForm() { $form = new Varien_Data_Form(); $this->setForm($form); $this->_addThemeCssFieldset(); $this->_addCustomCssFieldset(); $formData['custom_css_content'] = $this->_getCurrentTheme()->getCustomCssFile()->getContent(); /** @var $session Mage_Backend_Model_Session */ $session = $this->_objectManager->get('Mage_Backend_Model_Session'); $cssFileContent = $session->getThemeCustomCssData(); if ($cssFileContent) { $formData['custom_css_content'] = $cssFileContent; $session->unsThemeCustomCssData(); } $form->addValues($formData); return $this; }
/** * @param string $sourcePath * @param string $resultPath * * @dataProvider applyRewritesDataProvider * @magentoConfigFixture global/rewrite/test_url/from /test\/(\w*)/ * @magentoConfigFixture global/rewrite/test_url/to new_test/$1/subdirectory * @magentoDataFixture Mage/Core/_files/url_rewrite.php * @magentoDbIsolation enabled */ public function testApplyRewrites($sourcePath, $resultPath) { /** @var $request Mage_Core_Controller_Request_Http */ $request = $this->_objectManager->create('Mage_Core_Controller_Request_Http'); $request->setPathInfo($sourcePath); $this->_model->applyRewrites($request); $this->assertEquals($resultPath, $request->getPathInfo()); }
/** * Clear temporary layout updates and layout links */ public function clearLayoutUpdates() { $daysToExpire = $this->_helper->getDaysToExpire(); // remove expired links /** @var $linkCollection Mage_Core_Model_Resource_Layout_Link_Collection */ $linkCollection = $this->_objectManager->create('Mage_Core_Model_Resource_Layout_Link_Collection'); $linkCollection->addTemporaryFilter(true)->addUpdatedDaysBeforeFilter($daysToExpire); /** @var $layoutLink Mage_Core_Model_Layout_Link */ foreach ($linkCollection as $layoutLink) { $layoutLink->delete(); } // remove expired updates without links /** @var $layoutCollection Mage_Core_Model_Resource_Layout_Update_Collection */ $layoutCollection = $this->_objectManager->create('Mage_Core_Model_Resource_Layout_Update_Collection'); $layoutCollection->addNoLinksFilter()->addUpdatedDaysBeforeFilter($daysToExpire); /** @var $layoutUpdate Mage_Core_Model_Layout_Update */ foreach ($layoutCollection as $layoutUpdate) { $layoutUpdate->delete(); } }
/** * @return DOMDocument */ protected function _getDom() { $mergedConfigXml = $this->_loadCache(); if ($mergedConfigXml) { $mergedConfig = new DOMDocument(); $mergedConfig->loadXML($mergedConfigXml); } else { $fileList = $this->getMenuConfigurationFiles(); $mergedConfig = $this->_factory->create('Mage_Backend_Model_Menu_Config_Menu', array('configFiles' => $fileList))->getMergedConfig(); $this->_saveCache($mergedConfig->saveXML()); } return $mergedConfig; }
public function testCreateLayoutGetSharedInstance() { $this->_arguments = array('area' => 'TestArea'); $this->_objectManager->expects($this->once())->method('hasSharedInstance')->with(self::CLASS_NAME)->will($this->returnValue(true)); $modelLayout = $this->getMock(self::CLASS_NAME, array('getArea'), array(), '', false); $this->_objectManager->expects($this->at(1))->method('get')->with(self::CLASS_NAME)->will($this->returnValue($modelLayout)); $modelLayout->expects($this->any())->method('getArea')->will($this->returnValue('TestArea')); $this->_objectManager->expects($this->never())->method('removeSharedInstance'); $this->_objectManager->expects($this->never())->method('create'); $this->_objectManager->expects($this->never())->method('addSharedInstance'); $this->_objectManager->expects($this->at(2))->method('get')->with(self::CLASS_NAME)->will($this->returnValue($modelLayout)); $this->assertEquals($modelLayout, $this->_model->createLayout($this->_arguments)); }
/** * Retrieve proper interpreter for the specified content type. * * @param string $contentType * @return Mage_Webapi_Controller_Request_Rest_InterpreterInterface * @throws LogicException|Mage_Webapi_Exception */ public function get($contentType) { $interpretersMetadata = (array) $this->_applicationConfig->getNode(self::XML_PATH_WEBAPI_REQUEST_INTERPRETERS); if (empty($interpretersMetadata) || !is_array($interpretersMetadata)) { throw new LogicException('Request interpreter adapter is not set.'); } foreach ($interpretersMetadata as $interpreterMetadata) { $interpreterType = (string) $interpreterMetadata->type; if ($interpreterType == $contentType) { $interpreterClass = (string) $interpreterMetadata->model; break; } } if (!isset($interpreterClass) || empty($interpreterClass)) { throw new Mage_Webapi_Exception($this->_helper->__('Server cannot understand Content-Type HTTP header media type "%s"', $contentType), Mage_Webapi_Exception::HTTP_BAD_REQUEST); } $interpreter = $this->_objectManager->get($interpreterClass); if (!$interpreter instanceof Mage_Webapi_Controller_Request_Rest_InterpreterInterface) { throw new LogicException('The interpreter must implement "Mage_Webapi_Controller_Request_Rest_InterpreterInterface".'); } return $interpreter; }
/** * @param string $actualClassName * @param array $properties * @param string|null $expectedClassName * * @dataProvider newInstanceDataProvider */ public function testNewInstance($actualClassName, array $properties = array(), $expectedClassName = null) { if (!$expectedClassName) { $expectedClassName = $actualClassName; } $testObject = self::$_objectManager->create($actualClassName); $this->assertInstanceOf($expectedClassName, $testObject); if ($properties) { foreach ($properties as $propertyName => $propertyClass) { $this->assertAttributeInstanceOf($propertyClass, $propertyName, $testObject); } } }
/** * 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(); }
/** * Match provided request and if matched - return corresponding controller * * @param Mage_Core_Controller_Request_Http $request * @return Mage_Core_Controller_Front_Action|null */ public function match(Mage_Core_Controller_Request_Http $request) { //checking before even try to find out that current module //should use this router if (!$this->_beforeModuleMatch()) { return null; } $params = $this->_parseRequest($request); if (false == $this->_canProcess($params)) { return null; } $this->_app->loadDiConfiguration($this->_areaCode); return $this->_matchController($request, $params); }