Development

Changeset 32698

You must first sign up to be able to contribute.

Changeset 32698

Show
Ignore:
Timestamp:
07/01/11 08:55:58 (2 years ago)
Author:
fabien
Message:

[1.4] fixed a unit test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/CHANGELOG

    r32407 r32698  
     107/01/11: Version 1.4.12 
     2------------------------ 
     3 
     4 
    1503/30/11: Version 1.4.11 
    26------------------------ 
  • branches/1.4/lib/view/sfViewCacheManager.class.php

    r30031 r32698  
    130130    } 
    131131 
    132     if (strpos($internalUri, '@') === 0 && strpos($internalUri, '@sf_cache_partial') === false) 
     132    // note the special rules @sf_cache_partial and @sf_cache_fragment 
     133    if (strpos($internalUri, '@') === 0 && strpos($internalUri, '@sf_cache_partial') === false && strpos($internalUri, '@sf_cache_fragment') === false ) 
    133134    { 
    134135      throw new sfException('A cache key cannot be generated for an internal URI using the @rule syntax'); 
     
    166167      { 
    167168        $cacheKey = 'sf_cache_partial/'; 
     169        $cacheKey .= $this->convertParametersToKey($params); 
    168170      } 
    169  
    170       $cacheKey .= $this->convertParametersToKey($params); 
     171      elseif( $route_name == 'sf_cache_fragment' ) 
     172      { 
     173        $cacheKey = 'sf_cache_fragment/'; 
     174        $cacheKey .= $this->convertParametersToFragmentKey($params); 
     175      } 
     176      else 
     177      { 
     178        $cacheKey .= $this->convertParametersToKey($params); 
     179      } 
    171180    } 
    172181 
     
    295304 
    296305  /** 
     306   * Transforms an associative array of parameters from an URI into a unique key 
     307   * This method is only used for fragment 
     308   * 
     309   * @param  array $params  Associative array of parameters from the URI (including, at least, module and action) 
     310   * 
     311   * @return string Unique key 
     312   */ 
     313  protected function convertParametersToFragmentKey($params) 
     314  { 
     315    // module should be __sf_cache_fragment and action should be the 
     316    // fragment name, also used as sf_cache_key parameter 
     317    // these parameters can be removed from the generated kay 
     318    unset($params['module'] , $params['action']); 
     319 
     320    ksort($params); 
     321    foreach ($params as $key => $value) 
     322    { 
     323      $cacheKey .= sprintf('%s/%s/', $key, $value); 
     324    } 
     325 
     326    return rtrim( $cacheKey , '/' ); 
     327  } 
     328 
     329  /** 
    297330   * Adds a cache to the manager. 
    298331   * 
     
    675708  public function start($name, $lifeTime, $clientLifeTime = null, $vary = array()) 
    676709  { 
    677     $internalUri = $this->routing->getCurrentInternalUri(); 
    678  
    679710    if (!$clientLifeTime) 
    680711    { 
    681712      $clientLifeTime = $lifeTime; 
    682713    } 
     714 
     715    // fetch fragment uri 
     716    $internalUri = $this->getFragmentUri( $name ); 
    683717 
    684718    // add cache config to cache manager 
    685719    list($route_name, $params) = $this->controller->convertUrlStringToParameters($internalUri); 
     720    // module should be __sf_cache_fragment and action should be the name of the fragment 
    686721    $this->addCache($params['module'], $params['action'], array('withLayout' => false, 'lifeTime' => $lifeTime, 'clientLifeTime' => $clientLifeTime, 'vary' => $vary)); 
    687722 
    688723    // get data from cache if available 
    689     $data = $this->get($internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name); 
     724    // note that sf_cache_key is automatically add on getFragmentUri() 
     725    $data = $this->get( $internalUri ); 
    690726    if ($data !== null) 
    691727    { 
     
    708744   * @return bool true, if success otherwise false 
    709745   */ 
    710   public function stop($name
     746  public function stop( $name
    711747  { 
    712748    $data = ob_get_clean(); 
    713749 
    714     // save content to cache 
    715     $internalUri = $this->routing->getCurrentInternalUri(); 
    716750    try 
    717751    { 
    718       $this->set($data, $internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name); 
     752      $this->set( $data, $this->getFragmentUri( $name ) ); 
    719753    } 
    720754    catch (Exception $e) 
     
    723757 
    724758    return $data; 
     759  } 
     760 
     761  /** 
     762   * Computes a fragment internal URI. 
     763   * 
     764   * @param  string $name      The fragement name 
     765   * 
     766   * @return string The internal URI 
     767   */ 
     768  public function getFragmentUri( $name ) 
     769  { 
     770    // in fragement case, module is __sf_cache_fragment and action is the fragment name 
     771    // module and action are required to the set() procedure and isCacheable() method 
     772    return sprintf('@sf_cache_fragment?module=%s&action=%s&sf_cache_key=%s', '__sf_cache_fragment' , $name , $name ); 
    725773  } 
    726774 
  • branches/1.4/test/unit/validator/sfValidatorDecoratorTest.php

    r19531 r32698  
    6363$t->is($v->getMessages(), array('required' => 'This string is required.', 'invalid' => 'This string is invalid.', 'max_length' => '"%value%" is too long (%max_length% characters max).', 'min_length' => '"%value%" is too short (%min_length% characters min).'), '->getMessages() returns messages from the embedded validator'); 
    6464$v->setMessages(array('required' => 'Required...')); 
    65 $t->is($v->getMessages(), array('required' => 'Required...'), '->setMessages() sets all messages for the embedded validator'); 
     65$t->is($v->getMessages(), array('required' => 'Required...', 'invalid' => 'Invalid.'), '->setMessages() sets all messages for the embedded validator'); 
    6666 
    6767// ->getOption() ->getOptions() ->hasOption() ->getOptions() ->setOptions() 
     
    7272$t->is($v->hasOption('min_length'), true, '->hasOption() returns true if the embedded validator has a given option'); 
    7373$v->setOptions(array('min_length' => 10)); 
    74 $t->is($v->getOptions(), array('min_length' => 10), '->setOptions() sets all options for the embedded validator'); 
     74$t->is($v->getOptions(), array('required' => true, 'trim' => false, 'empty_value' => null, 'min_length' => 10), '->setOptions() sets all options for the embedded validator'); 
    7575 
    7676$v = new MyValidator();