Example #1
0
 /**
  * testElementCache method
  *
  * @access public
  * @return void
  */
 function testElementCache()
 {
     $View = new TestView($this->PostsController);
     $element = 'test_element';
     $expected = 'this is the test element';
     $result = $View->element($element);
     $this->assertEqual($result, $expected);
     $cached = false;
     $result = $View->element($element, array('cache' => '+1 second'));
     if (file_exists(CACHE . 'views' . DS . 'element_cache_' . $element)) {
         $cached = true;
         unlink(CACHE . 'views' . DS . 'element_cache_' . $element);
     }
     $this->assertTrue($cached);
     $cached = false;
     $result = $View->element($element, array('cache' => '+1 second', 'other_param' => true, 'anotherParam' => true));
     if (file_exists(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_' . $element)) {
         $cached = true;
         unlink(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_' . $element);
     }
     $this->assertTrue($cached);
     $cached = false;
     $result = $View->element($element, array('cache' => array('time' => '+1 second', 'key' => '/whatever/here')));
     if (file_exists(CACHE . 'views' . DS . 'element_' . Inflector::slug('/whatever/here') . '_' . $element)) {
         $cached = true;
         unlink(CACHE . 'views' . DS . 'element_' . Inflector::slug('/whatever/here') . '_' . $element);
     }
     $this->assertTrue($cached);
     $cached = false;
     $result = $View->element($element, array('cache' => array('time' => '+1 second', 'key' => 'whatever_here')));
     if (file_exists(CACHE . 'views' . DS . 'element_whatever_here_' . $element)) {
         $cached = true;
         unlink(CACHE . 'views' . DS . 'element_whatever_here_' . $element);
     }
     $this->assertTrue($cached);
     $this->assertEqual($result, $expected);
 }
Example #2
0
 /**
  * Test that ctp is used as a fallback file extension for elements
  *
  * @return void
  */
 public function testElementCtpFallback()
 {
     $View = new TestView($this->PostsController);
     $View->ext = '.missing';
     $element = 'test_element';
     $expected = 'this is the test element';
     $result = $View->element($element);
     $this->assertEquals($expected, $result);
 }
 /**
  * testElementCache method
  *
  * @access public
  * @return void
  */
 function testElementCache()
 {
     Cache::drop('test_view');
     Cache::config('test_view', array('engine' => 'File', 'duration' => '+1 day', 'path' => CACHE . 'views' . DS, 'prefix' => ''));
     Cache::clear('test_view');
     $View = new TestView($this->PostsController);
     $View->elementCache = 'test_view';
     $result = $View->element('test_element', array('cache' => true));
     $expected = 'this is the test element';
     $this->assertEquals($expected, $result);
     $result = Cache::read('element__test_element_cache', 'test_view');
     $this->assertEquals($expected, $result);
     $result = $View->element('test_element', array('cache' => true, 'param' => 'one', 'foo' => 'two'));
     $this->assertEquals($expected, $result);
     $result = Cache::read('element__test_element_cache_param_foo', 'test_view');
     $this->assertEquals($expected, $result);
     $result = $View->element('test_element', array('cache' => array('key' => 'custom_key'), 'param' => 'one', 'foo' => 'two'));
     $result = Cache::read('element_custom_key', 'test_view');
     $this->assertEquals($expected, $result);
     $View->elementCache = 'default';
     $result = $View->element('test_element', array('cache' => array('config' => 'test_view'), 'param' => 'one', 'foo' => 'two'));
     $result = Cache::read('element__test_element_cache_param_foo', 'test_view');
     $this->assertEquals($expected, $result);
     Cache::drop('test_view');
 }