Exemple #1
0
 /**
  * @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);
 }
Exemple #2
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #4
0
 /**
  * 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;
 }
Exemple #5
0
 /**
  * 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;
 }
Exemple #6
0
 /**
  * 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;
 }
Exemple #7
0
 /**
  * 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;
 }
 /**
  * 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);
 }
Exemple #9
0
 /**
  * @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);
 }
Exemple #10
0
 /**
  * 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;
 }
Exemple #11
0
 /**
  * @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));
 }
Exemple #12
0
 /**
  * @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());
 }
Exemple #13
0
 /**
  * Create and set default translator to Magento_Validator_ValidatorAbstract.
  */
 protected function _initializeDefaultTranslator()
 {
     $translateAdapter = $this->_translator;
     $objectManager = $this->_objectManager;
     // Pass translations to Mage_Core_Model_Translate from validators
     $translatorCallback = function () use($translateAdapter, $objectManager) {
         /** @var Mage_Core_Model_Translate $translateAdapter */
         $args = func_get_args();
         $expr = $objectManager->create('Mage_Core_Model_Translate_Expr');
         $expr->setText($args[0]);
         array_unshift($args, $expr);
         return $translateAdapter->translate($args);
     };
     /** @var Magento_Translate_Adapter $translator */
     $translator = $this->_objectManager->create('Magento_Translate_Adapter');
     $translator->setOptions(array('translator' => $translatorCallback));
     Magento_Validator_ValidatorAbstract::setDefaultTranslator($translator);
 }
Exemple #14
0
 /**
  * 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();
     }
 }
Exemple #15
0
 /**
  * @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;
 }
Exemple #16
0
 /**
  * @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);
         }
     }
 }
Exemple #17
0
 /**
  * @param array $arguments
  * @param string $className
  * @return Mage_Core_Model_Layout
  */
 public function createLayout(array $arguments = array(), $className = self::CLASS_NAME)
 {
     // because layout singleton was used everywhere in magento code, in observers, models, blocks, etc.
     // the only way how we can replace default layout object with custom one is to save instance of custom layout
     // to instance manager storage using default layout class name as alias
     $createLayout = true;
     if (isset($arguments['area'])) {
         if ($this->_objectManager->hasSharedInstance(self::CLASS_NAME)) {
             /** @var $layout Mage_Core_Model_Layout */
             $layout = $this->_objectManager->get(self::CLASS_NAME);
             if ($arguments['area'] != $layout->getArea()) {
                 $this->_objectManager->removeSharedInstance(self::CLASS_NAME);
             } else {
                 $createLayout = false;
             }
         }
     }
     if ($createLayout) {
         $layout = $this->_objectManager->create($className, $arguments, false);
         $this->_objectManager->addSharedInstance($layout, self::CLASS_NAME);
     }
     return $this->_objectManager->get(self::CLASS_NAME);
 }
Exemple #18
0
 /**
  * Declare headers and content file in response for file download
  *
  * @param string $fileName
  * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
  *                              that case
  * @param string $contentType
  * @param int $contentLength    explicit content length, if strlen($content) isn't applicable
  * @return Mage_Core_Controller_Varien_Action
  */
 protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
 {
     /** @var Magento_Filesystem $filesystem */
     $filesystem = $this->_objectManager->create('Magento_Filesystem');
     $isFile = false;
     $file = null;
     if (is_array($content)) {
         if (!isset($content['type']) || !isset($content['value'])) {
             return $this;
         }
         if ($content['type'] == 'filename') {
             $isFile = true;
             $file = $content['value'];
             $contentLength = $filesystem->getFileSize($file);
         }
     }
     $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
     if (!is_null($content)) {
         if ($isFile) {
             $this->getResponse()->clearBody();
             $this->getResponse()->sendHeaders();
             if (!$filesystem->isFile($file)) {
                 Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('File not found'));
             }
             $stream = $filesystem->createAndOpenStream($file, 'r');
             while ($buffer = $stream->read(1024)) {
                 print $buffer;
             }
             $stream->close();
             if (!empty($content['rm'])) {
                 $filesystem->delete($file);
             }
             exit(0);
         } else {
             $this->getResponse()->setBody($content);
         }
     }
     return $this;
 }
Exemple #19
0
 /**
  * Return new ACL resource model
  *
  * @param array $arguments
  * @return Magento_Acl_Resource
  */
 public function createResource(array $arguments = array())
 {
     return $this->_objectManager->create(self::RESOURCE_CLASS_NAME, $arguments, false);
 }
Exemple #20
0
 /**
  * Create element flyweight flyweight
  *
  * @param string $type
  * @return Mage_Backend_Model_Config_Structure_ElementInterface
  */
 public function create($type)
 {
     return $this->_objectManager->create($this->_flyweightMap[$type]);
 }
Exemple #21
0
 /**
  * Create empty DOM document instance.
  *
  * @return DOMDocument
  */
 public function createDomDocument()
 {
     return $this->_objectManager->create('DOMDocument', array(), false);
 }
Exemple #22
0
 /**
  * Create config data object
  *
  * @param array $arguments
  * @return Mage_Core_Model_Config_Data
  */
 public function create(array $arguments = array())
 {
     return $this->_objectManager->create('Mage_Core_Model_Config_Data', $arguments);
 }
Exemple #23
0
 /**
  * Create new config object
  *
  * @param array $data
  * @return Mage_Backend_Model_Config
  */
 public function create(array $data = array())
 {
     return $this->_objectManager->create('Mage_Backend_Model_Config', $data);
 }
Exemple #24
0
 /**
  * Create new instance
  *
  * @param array $data
  * @return Mage_Core_Model_Theme
  */
 public function create(array $data = array())
 {
     return $this->_objectManager->create('Mage_Core_Model_Theme', $data);
 }
Exemple #25
0
 /**
  * Create token model.
  *
  * @param array $arguments
  * @return Mage_Oauth_Model_Token
  */
 public function create($arguments = array())
 {
     return $this->_objectManager->create('Mage_Oauth_Model_Token', $arguments);
 }
Exemple #26
0
 /**
  * Create new clone model
  *
  * @param string $cloneModel
  * @return Mage_Core_Model_Config_Data
  */
 public function create($cloneModel)
 {
     return $this->_objectManager->create($cloneModel);
 }
Exemple #27
0
 /**
  * Create username token.
  *
  * @param array $arguments
  * @return Mage_Webapi_Model_Soap_Security_usernameToken
  */
 public function createFromArray($arguments = array())
 {
     return $this->_objectManager->create('Mage_Webapi_Model_Soap_Security_UsernameToken', $arguments);
 }
Exemple #28
0
 /**
  * @param array $arguments
  * @return Mage_Index_Model_Process_File
  */
 public function createFromArray(array $arguments = array())
 {
     return $this->_objectManager->create(self::CLASS_NAME, $arguments, false);
 }
Exemple #29
0
 /**
  * create new Eav attribute instance
  *
  * @param string $className
  * @param array $arguments
  * @return mixed
  */
 public function createAttribute($className, $arguments = array())
 {
     return $this->_objectManager->create($className, array('data' => $arguments));
 }
 /**
  * Create new country model
  *
  * @param array $arguments
  * @return Mage_Directory_Model_Country
  */
 public function create(array $arguments = array())
 {
     return $this->_objectManager->create('Mage_Directory_Model_Country', $arguments, false);
 }