Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * sfTesterViewCache implements tests for the symfony view cache manager.
13
 *
14
 * @package    symfony
15
 * @subpackage test
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfTesterViewCache.class.php 24615 2009-11-30 22:30:46Z Kris.Wallsmith $
18
 */
19
class sfTesterViewCache extends sfTester
20
{
21
  protected
22
    $viewCacheManager = null,
23
    $response         = null,
24
    $routing          = null;
25
 
26
  /**
27
   * Prepares the tester.
28
   */
29
  public function prepare()
30
  {
31
  }
32
 
33
  /**
34
   * Initializes the tester.
35
   */
36
  public function initialize()
37
  {
38
    $this->viewCacheManager = $this->browser->getContext()->getViewCacheManager();
39
    $this->routing = $this->browser->getContext()->getRouting();
40
    $this->response = $this->browser->getResponse();
41
  }
42
 
43
  /**
44
   * Tests if the given uri is cached.
45
   *
46
   * @param  boolean $boolean      Flag for checking the cache
47
   * @param  boolean $with_layout  If have or not layout
48
   *
49
   * @return sfTestFunctionalBase|sfTester
50
   */
51
  public function isCached($boolean, $with_layout = false)
52
  {
53
    return $this->isUriCached($this->viewCacheManager->getCurrentCacheKey(), $boolean, $with_layout);
54
  }
55
 
56
  /**
57
   * Tests if the given uri is cached.
58
   *
59
   * @param  string  $uri          Uniform resource identifier
60
   * @param  boolean $boolean      Flag for checking the cache
61
   * @param  boolean $with_layout  If have or not layout
62
   *
63
   * @return sfTestFunctionalBase|sfTester
64
   */
65
  public function isUriCached($uri, $boolean, $with_layout = false)
66
  {
67
    $cacheManager = $this->viewCacheManager;
68
 
69
    // check that cache is enabled
70
    if (!$cacheManager)
71
    {
72
      $this->tester->ok(!$boolean, 'cache is disabled');
73
 
74
      return $this->getObjectToReturn();
75
    }
76
 
77
    if ($uri == $this->viewCacheManager->getCurrentCacheKey())
78
    {
79
      $main = true;
80
      $type = $with_layout ? 'page' : 'action';
81
    }
82
    else
83
    {
84
      $main = false;
85
      $type = $uri;
86
    }
87
 
88
    // check layout configuration
89
    if ($cacheManager->withLayout($uri) && !$with_layout)
90
    {
91
      $this->tester->fail('cache without layout');
92
      $this->tester->skip('cache is not configured properly', 2);
93
    }
94
    else if (!$cacheManager->withLayout($uri) && $with_layout)
95
    {
96
      $this->tester->fail('cache with layout');
97
      $this->tester->skip('cache is not configured properly', 2);
98
    }
99
    else
100
    {
101
      $this->tester->pass('cache is configured properly');
102
 
103
      // check page is cached
104
      $ret = $this->tester->is($cacheManager->has($uri), $boolean, sprintf('"%s" %s in cache', $type, $boolean ? 'is' : 'is not'));
105
 
106
      // check that the content is ok in cache
107
      if ($boolean)
108
      {
109
        if (!$ret)
110
        {
111
          $this->tester->fail('content in cache is ok');
112
        }
113
        else if ($with_layout)
114
        {
115
          $response = unserialize($cacheManager->get($uri));
116
          $content = $response->getContent();
117
          $this->tester->ok($content == $this->response->getContent(), 'content in cache is ok');
118
        }
119
        else
120
        {
121
          $ret = unserialize($cacheManager->get($uri));
122
          $content = $ret['content'];
123
          $this->tester->ok(false !== strpos($this->response->getContent(), $content), 'content in cache is ok');
124
        }
125
      }
126
    }
127
 
128
    return $this->getObjectToReturn();
129
  }
130
}