コード例 #1
0
    public function testCustomInflectorUsesViewRendererTargetWhenPassedInWithReferenceFlag()
    {
        $this->request->setModuleName('bar')
                      ->setControllerName('index')
                      ->setActionName('test');
        $controller = new Bar_IndexController($this->request, $this->response, array());

        $this->helper->view->addBasePath($this->basePath . '/_files/modules/bar/views');

        require_once 'Zend/Filter/PregReplace.php';
        require_once 'Zend/Filter/Word/UnderscoreToSeparator.php';
        
        $inflector = new Zend_Filter_Inflector('test.phtml');
        $inflector->addRules(array(
            ':module'     => array('Word_CamelCaseToDash', 'stringToLower'),
            ':controller' => array('Word_CamelCaseToDash', new Zend_Filter_Word_UnderscoreToSeparator(DIRECTORY_SEPARATOR), 'StringToLower'),
            ':action'     => array(
                'Word_CamelCaseToDash', 
                new Zend_Filter_PregReplace('/[^a-z0-9]+/i', '-'),
                'StringToLower'
            ),
        ));
        $this->helper->setInflector($inflector, true);

        $this->helper->render();
        $body = $this->response->getBody();
        $this->assertContains('Rendered index/test.phtml in bar module', $body);
    }
コード例 #2
0
ファイル: AuthTest.php プロジェクト: rexmac/zyndax
 public function testPreDispatchNonWhitelistedActionViaAjaxRequest()
 {
     $this->request->setHeader('X_REQUESTED_WITH', 'XMLHttpRequest')->setModuleName('default')->setControllerName('foo')->setActionName('home');
     $this->plugin->preDispatch($this->request);
     $this->assertEquals(500, $this->response->getHttpResponseCode());
     $this->assertEquals(json_encode(array('redirect' => '/user/login')), $this->response->getBody());
 }
コード例 #3
0
 public function testCorrectViewHelperPathShouldBePropagatedWhenSubControllerInvokedInDefaultModule()
 {
     require_once $this->basePath . '/_files/modules/default/controllers/Admin/HelperController.php';
     $this->request->setControllerName('admin_helper')->setActionName('render');
     $controller = new Admin_HelperController($this->request, $this->response, array());
     $this->helper->render();
     $body = $this->response->getBody();
     $this->assertContains('SampleZfHelper invoked', $body, 'Received ' . $body);
 }
コード例 #4
0
 public function testPostDispatchDoesNotRenderViewWhenNoViewRendererSet()
 {
     $this->request->setModuleName('bar')->setControllerName('index')->setActionName('index');
     $this->front->setParam('noViewRenderer', true);
     $controller = new Bar_IndexController($this->request, $this->response, array());
     $this->helper->postDispatch();
     $body = $this->response->getBody();
     $this->assertTrue(empty($body));
 }
コード例 #5
0
 /**
  * Asserts that the response contains JSON data.
  *
  * Also checks if the content type header is compatible
  * to JSON data.
  */
 public function containsJson()
 {
     $content = $this->response->getBody();
     try {
         Zend_Json::decode($content);
     } catch (Zend_Json_Exception $e) {
         PHPUnit_Framework_Assert::fail('Invalid JSON data found: ' . $e->getMessage());
     }
     $this->headerEquals('Content-Type', 'application/json');
 }
コード例 #6
0
ファイル: Default.php プロジェクト: jpbender/mage_virtual
 /**
  * Prepare response body before caching
  *
  * @param Zend_Controller_Response_Http $response
  * @return string
  */
 public function prepareContent(Zend_Controller_Response_Http $response)
 {
     $content = $response->getBody();
     $placeholders = array();
     preg_match_all(Enterprise_PageCache_Model_Container_Placeholder::HTML_NAME_PATTERN, $content, $placeholders, PREG_PATTERN_ORDER);
     $placeholders = array_unique($placeholders[1]);
     try {
         foreach ($placeholders as $definition) {
             $this->_placeholder = Mage::getModel('enterprise_pagecache/container_placeholder', $definition);
             $content = preg_replace_callback($this->_placeholder->getPattern(), array($this, '_getPlaceholderReplacer'), $content);
         }
         $this->_placeholder = null;
     } catch (Exception $e) {
         $this->_placeholder = null;
         throw $e;
     }
     return $content;
 }
コード例 #7
0
 /**
  * Handles logic for caching pages.  Currently checks the root block for the
  * "CachePageFlag".  Pages are only cached if the user is not logged in and does
  * not have items in their cart.
  *
  * @param $observer
  * @return void
  */
 public function cachePage(Zend_Controller_Response_Http $response)
 {
     // Check if cache flag is set
     $rootBlock = Mage::app()->getLayout()->getBlock('root');
     if ($rootBlock && $rootBlock->getCachePageFlag()) {
         if ($this->passesConditions($rootBlock->getCachePageConditions())) {
             $cache = Mage::app()->getCache();
             $id = $this->generateFPCId();
             if ($rootBlock->getCachePageExpires() > 0) {
                 $expires = $rootBlock->getCachePageExpires();
             } else {
                 //default expires
                 $expires = Mage::getStoreConfig(Brim_PageCache_Model_Config::XML_PATH_EXPIRES);
             }
             $storageObject = Mage::getModel('brim_pagecache/storage');
             if (Mage::getStoreConfig(Brim_PageCache_Model_Config::XML_PATH_ENABLE_MINIFY_HTML)) {
                 // Minify the response body.  Helps save on cache storage space
                 // Basic grouped product page 34k in size was about 28K minified,
                 $minifyBody = Brim_PageCache_Model_Minify_HTML::minify($response->getBody());
                 $response->setBody($minifyBody);
             }
             $storageObject->setResponse($response);
             /**
              * Block update data contains partial layouts for each block.  Allows us to regenerate each one
              * with out loosing customizations.
              */
             $storageObject->setBlockUpdateData($this->getBlockUpdateData());
             // Set the expected expires time for this page
             $date = Mage::app()->getLocale()->date()->addSecond($expires);
             $storageObject->setData(self::RESPONSE_HEADER_EXPIRES_DATE, $date->get(Zend_Date::RFC_1123));
             $storageObject->setData(self::RESPONSE_HEADER_EXPIRES, $expires);
             $storageObject->setData(self::RESPONSE_HEADER_CONDITIONS, $rootBlock->getCachePageConditions());
             $storageObject->setData(self::RESPONSE_HEADER_STORE, Mage::app()->getStore()->getCode());
             $storageObject->setData(self::RESPONSE_HEADER_ORIG_TIME, microtime(true) - self::$_start_time);
             $this->debug('Saving page with cache id : ' . $id);
             if (($product = Mage::registry('product')) != null) {
                 $this->devDebug('Registering Tag: ' . self::FPC_TAG . '_PRODUCT_' . $product->getId());
                 $this->registerPageTags(self::FPC_TAG . '_PRODUCT_' . $product->getId());
             }
             if (($category = Mage::registry('current_category')) != null && $product == null) {
                 $this->devDebug('Registering Tag: ' . self::FPC_TAG . '_CATEGORY_' . $category->getId());
                 $this->registerPageTags(self::FPC_TAG . '_CATEGORY_' . $category->getId());
             }
             $cache->save(serialize($storageObject), $id, $this->getPageTags(), $expires);
         } else {
             // failed conditions
             if ($response->canSendHeaders(false)) {
                 $response->setHeader(self::RESPONSE_HEADER_FAILED, $this->_failed_conditions);
             }
         }
     } else {
         if ($response->canSendHeaders(false)) {
             // page not set to cache
             $response->setHeader(self::RESPONSE_HEADER_FAILED, 'no_cache');
         }
     }
 }
コード例 #8
0
 /**
  * Prepare response body before caching
  *
  * @param Zend_Controller_Response_Http $response
  * @return string
  */
 public function prepareContent(Zend_Controller_Response_Http $response)
 {
     return $this->replaceContentToPlaceholderReplacer($response->getBody());
 }
コード例 #9
0
 protected function _sendResponse($httpCode, $code, $message)
 {
     // TODO Why is sometimes sending response twice??? :S
     if (self::$responseSent) {
         return;
     }
     if (!($response = Zend_Controller_Front::getInstance()->getResponse())) {
         $response = new Zend_Controller_Response_Http();
     }
     $response->setHttpResponseCode($httpCode);
     if (!$response->getBody()) {
         $body = array('code' => $code, 'message' => $message);
         $response->setBody(Zend_Json::encode($body));
     }
     if ($response->canSendHeaders()) {
         $response->clearHeaders();
         $response->setHeader('Content-Type', 'application/json');
         $response->sendResponse();
         self::$responseSent = true;
     }
     exit;
 }
コード例 #10
0
ファイル: Default.php プロジェクト: lmcro/magecache
 /**
  * Process response body by specific request
  *
  * @param Zend_Controller_Response_Http $response response
  * @param Zend_Controller_Request_Http  $request  request
  *
  * @return Smile_MageCache_Model_Engine_Default
  */
 public function processResponse(Zend_Controller_Response_Http $response, Zend_Controller_Request_Http $request)
 {
     /*
      * Check request and response.
      * Note: Deal only with 200 for the moment
      */
     if ($this->canProcessRequest($request) && $response->getHttpResponseCode() == 200) {
         $cacheId = $this->getRequestCacheId();
         $content = $response->getBody();
         if (function_exists('gzcompress')) {
             $content = gzcompress($content);
         }
         $res = $this->_adapter->save($content, $cacheId, $this->getRequestTags());
         $this->setMetadata('response_headers', $response->getHeaders());
         $this->_saveMetadata();
     }
     return $this;
 }