CacheContextsTest.php in Render cache 7.2
File
tests/src/Cache/CacheContextsTest.php
View source
<?php
namespace Drupal\render_cache\Tests\Cache;
use Drupal\render_cache\Cache\CacheContexts;
use Mockery;
class CacheContextsTest extends \PHPUnit_Framework_TestCase {
protected $cacheContexts;
public function setUp() {
$foo_cache_context = Mockery::mock('\\Drupal\\Core\\Cache\\CacheContextInterface');
$foo_cache_context
->shouldReceive('getLabel')
->andReturn('Foo');
$foo_cache_context
->shouldReceive('getContext')
->andReturn('bar');
$container = Mockery::mock('alias:Drupal\\service_container\\DependencyInjection\\ContainerInterface');
$container
->shouldReceive('get')
->with('cache_context.foo')
->andReturn($foo_cache_context);
$this->cacheContexts = new CacheContexts($container, array(
'cache_context.foo',
));
}
public function test_getAll() {
$this
->assertEquals(array(
'cache_context.foo',
), $this->cacheContexts
->getAll(), 'Cache Contexts service contains the right services.');
}
public function test_getLabels() {
$this
->assertEquals(array(
'cache_context.foo' => 'Foo',
), $this->cacheContexts
->getLabels(), 'Cache Contexts service retrieves the right labels.');
}
public function test_convertTokensToKeys() {
$tokens = array(
'foo',
'bar',
'cache_context.foo',
);
$altered_tokens = array(
'foo',
'bar',
'bar',
);
$this
->assertEquals($altered_tokens, $this->cacheContexts
->convertTokensToKeys($tokens), 'Cache Contexts can be converted properly.');
}
}