class LibraryDiscoveryCollectorTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryCollector @group Asset
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest
Expanded class hierarchy of LibraryDiscoveryCollectorTest
File
- core/
tests/ Drupal/ Tests/ Core/ Asset/ LibraryDiscoveryCollectorTest.php, line 18 - Contains \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest.
Namespace
Drupal\Tests\Core\AssetView source
class LibraryDiscoveryCollectorTest extends UnitTestCase {
/**
* The mock cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cache;
/**
* The mock lock backend.
*
* @var \Drupal\Core\Lock\LockBackendInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $lock;
/**
* The mock library discovery parser.
*
* @var \Drupal\Core\Asset\LibraryDiscoveryParser|\PHPUnit_Framework_MockObject_MockObject
*/
protected $libraryDiscoveryParser;
/**
* The library discovery collector under test.
*
* @var \Drupal\Core\Asset\LibraryDiscoveryCollector
*/
protected $libraryDiscoveryCollector;
/**
* The mocked theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $themeManager;
/**
* Test library data.
*
* @var array
*/
protected $libraryData = array(
'test_1' => array(
'js' => array(),
'css' => array(),
),
'test_2' => array(
'js' => array(),
'css' => array(),
),
);
protected $activeTheme;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->cache = $this
->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$this->lock = $this
->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
$this->themeManager = $this
->getMockBuilder('Drupal\\Core\\Theme\\ThemeManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->libraryDiscoveryParser = $this
->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscoveryParser')
->disableOriginalConstructor()
->getMock();
}
/**
* Tests the resolve cache miss function.
*
* @covers ::resolveCacheMiss
*/
public function testResolveCacheMiss() {
$this->activeTheme = $this
->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')
->disableOriginalConstructor()
->getMock();
$this->themeManager
->expects($this
->exactly(3))
->method('getActiveTheme')
->willReturn($this->activeTheme);
$this->activeTheme
->expects($this
->once())
->method('getName')
->willReturn('kitten_theme');
$this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager);
$this->libraryDiscoveryParser
->expects($this
->once())
->method('buildByExtension')
->with('test')
->willReturn($this->libraryData);
$this
->assertSame($this->libraryData, $this->libraryDiscoveryCollector
->get('test'));
$this
->assertSame($this->libraryData, $this->libraryDiscoveryCollector
->get('test'));
}
/**
* Tests the destruct method.
*
* @covers ::destruct
*/
public function testDestruct() {
$this->activeTheme = $this
->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')
->disableOriginalConstructor()
->getMock();
$this->themeManager
->expects($this
->exactly(3))
->method('getActiveTheme')
->willReturn($this->activeTheme);
$this->activeTheme
->expects($this
->once())
->method('getName')
->willReturn('kitten_theme');
$this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager);
$this->libraryDiscoveryParser
->expects($this
->once())
->method('buildByExtension')
->with('test')
->willReturn($this->libraryData);
$lock_key = 'library_info:kitten_theme:Drupal\\Core\\Cache\\CacheCollector';
$this->lock
->expects($this
->once())
->method('acquire')
->with($lock_key)
->will($this
->returnValue(TRUE));
$this->cache
->expects($this
->exactly(2))
->method('get')
->with('library_info:kitten_theme')
->willReturn(FALSE);
$this->cache
->expects($this
->once())
->method('set')
->with('library_info:kitten_theme', array(
'test' => $this->libraryData,
), Cache::PERMANENT, [
'library_info',
]);
$this->lock
->expects($this
->once())
->method('release')
->with($lock_key);
// This should get data and persist the key.
$this->libraryDiscoveryCollector
->get('test');
$this->libraryDiscoveryCollector
->destruct();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LibraryDiscoveryCollectorTest:: |
protected | property | ||
LibraryDiscoveryCollectorTest:: |
protected | property | The mock cache backend. | |
LibraryDiscoveryCollectorTest:: |
protected | property | Test library data. | |
LibraryDiscoveryCollectorTest:: |
protected | property | The library discovery collector under test. | |
LibraryDiscoveryCollectorTest:: |
protected | property | The mock library discovery parser. | |
LibraryDiscoveryCollectorTest:: |
protected | property | The mock lock backend. | |
LibraryDiscoveryCollectorTest:: |
protected | property | The mocked theme manager. | |
LibraryDiscoveryCollectorTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LibraryDiscoveryCollectorTest:: |
public | function | Tests the destruct method. | |
LibraryDiscoveryCollectorTest:: |
public | function | Tests the resolve cache miss function. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |