added FragmentCache test for issue #8273

This commit is contained in:
Carsten Brandt
2015-05-05 23:10:18 +02:00
parent fc9b678ca4
commit 94d6843f8b
2 changed files with 92 additions and 0 deletions

View File

@ -14,6 +14,7 @@ use yii\caching\Dependency;
use yii\di\Instance;
/**
* FragmentCache is used by [[yii\base\View]] to provide caching of page fragments.
*
* @property string|boolean $cachedContent The cached content. False is returned if valid content is not found
* in the cache. This property is read-only.

View File

@ -0,0 +1,91 @@
<?php
namespace yiiunit\framework\widgets;
use Yii;
use yii\caching\ArrayCache;
use yii\base\View;
use yii\widgets\Breadcrumbs;
/**
* @group widgets
* @group caching
*/
class FragmentCacheTest extends \yiiunit\TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockWebApplication();
Yii::$app->set('cache', [
'class' => ArrayCache::className(),
]);
}
public function testCacheEnabled()
{
$expectedLevel = ob_get_level();
ob_start();
ob_implicit_flush(false);
$view = new View();
$this->assertTrue($view->beginCache('test'));
echo "cached fragment";
$view->endCache();
ob_start();
ob_implicit_flush(false);
$this->assertFalse($view->beginCache('test'));
$this->assertEquals("cached fragment", ob_get_clean());
ob_end_clean();
$this->assertEquals($expectedLevel, ob_get_level(), 'Output buffer not closed correctly.');
}
public function testCacheDisabled1()
{
$expectedLevel = ob_get_level();
ob_start();
ob_implicit_flush(false);
$view = new View();
$this->assertTrue($view->beginCache('test', ['enabled' => false]));
echo "cached fragment";
$view->endCache();
ob_start();
ob_implicit_flush(false);
$this->assertTrue($view->beginCache('test', ['enabled' => false]));
echo "cached fragment";
$view->endCache();
$this->assertEquals("cached fragment", ob_get_clean());
ob_end_clean();
$this->assertEquals($expectedLevel, ob_get_level(), 'Output buffer not closed correctly.');
}
public function testCacheDisabled2()
{
$expectedLevel = ob_get_level();
ob_start();
ob_implicit_flush(false);
$view = new View();
$this->assertTrue($view->beginCache('test'));
echo "cached fragment";
$view->endCache();
ob_start();
ob_implicit_flush(false);
$this->assertTrue($view->beginCache('test', ['enabled' => false]));
echo "cached fragment other";
$view->endCache();
$this->assertEquals("cached fragment other", ob_get_clean());
ob_end_clean();
$this->assertEquals($expectedLevel, ob_get_level(), 'Output buffer not closed correctly.');
}
// TODO test dynamic replacements
}