Commit 61c8ea49 authored by lussoluca's avatar lussoluca

More tests

parent e65c864e
......@@ -30,7 +30,7 @@ class DatabaseStorageTest extends WebprofilerTestBase {
}
/**
* Test the purge on cache clear enabled setting.
* Tests the purge on cache clear enabled setting.
*/
public function testCacheClearEnabledOnDatabaseStorage() {
$this->enableCacheClear();
......@@ -45,7 +45,7 @@ class DatabaseStorageTest extends WebprofilerTestBase {
}
/**
* Test the purge on cache clear disabled setting.
* Tests the purge on cache clear disabled setting.
*/
public function testCacheClearDisabledOnDatabaseStorage() {
$this->disableCacheClear();
......
......@@ -30,7 +30,7 @@ class FileStorageTest extends WebprofilerTestBase {
}
/**
* Test the purge on cache clear enabled setting.
* Tests the purge on cache clear enabled setting.
*/
public function testCacheClearEnabledOnFileStorage() {
$this->enableCacheClear();
......@@ -45,7 +45,7 @@ class FileStorageTest extends WebprofilerTestBase {
}
/**
* Test the purge on cache clear disabled setting.
* Tests the purge on cache clear disabled setting.
*/
public function testCacheClearDisabledOnFileStorage() {
$this->disableCacheClear();
......
......@@ -12,8 +12,11 @@ class ToolbarTest extends WebprofilerTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['webprofiler', 'node', 'views'];
public static $modules = ['webprofiler', 'node'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
......
<?php
namespace Drupal\Tests\webprofiler\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Class DecoratorTest.
*/
class DecoratorTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'views'];
/**
* Tests the Entity Type Manager service decoration.
*
* @param string $service
* The service name.
* @param string $original
* The original class.
* @param string $decorated
* The decorated class.
*
* @dataProvider decorators
*/
public function testEntityTypeDecorator($service, $original, $decorated) {
$entityTypeManagerOriginal = $this->container->get($service);
$this->assertInstanceOf($original, $entityTypeManagerOriginal);
$this->container->get('module_installer')->install(['webprofiler']);
$entityTypeManagerDecorated = $this->container->get($service);
$this->assertInstanceOf($decorated, $entityTypeManagerDecorated);
}
/**
* DataProvider for testEntityTypeDecorator.
*
* @return array
* The array of values to run tests on.
*/
public function decorators() {
return array(
array('entity_type.manager', 'Drupal\Core\Entity\EntityTypeManager', 'Drupal\webprofiler\Entity\EntityManagerWrapper'),
array('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory', 'Drupal\webprofiler\Cache\CacheFactoryWrapper'),
array('asset.css.collection_renderer', 'Drupal\Core\Asset\CssCollectionRenderer', 'Drupal\webprofiler\Asset\CssCollectionRendererWrapper'),
array('asset.js.collection_renderer', 'Drupal\Core\Asset\JsCollectionRenderer', 'Drupal\webprofiler\Asset\JsCollectionRendererWrapper'),
array('state', 'Drupal\Core\State\State', 'Drupal\webprofiler\State\StateWrapper'),
array('views.executable', 'Drupal\views\ViewExecutableFactory', 'Drupal\webprofiler\Views\ViewExecutableFactoryWrapper'),
array('form_builder', 'Drupal\Core\Form\FormBuilder', 'Drupal\webprofiler\Form\FormBuilderWrapper'),
array('access_manager', 'Drupal\Core\Access\AccessManager', 'Drupal\webprofiler\Access\AccessManagerWrapper'),
array('theme.negotiator', 'Drupal\Core\Theme\ThemeNegotiator', 'Drupal\webprofiler\Theme\ThemeNegotiatorWrapper'),
array('config.factory', 'Drupal\Core\Config\ConfigFactory', 'Drupal\webprofiler\Config\ConfigFactoryWrapper'),
array('string_translation', 'Drupal\Core\StringTranslation\TranslationManager', 'Drupal\webprofiler\StringTranslation\TranslationManagerWrapper'),
);
}
}
......@@ -34,6 +34,9 @@ class AssetsDataCollectorTest extends DataCollectorBaseTest {
$this->assetCollectionRendererInterface = $this->getMock('Drupal\Core\Asset\AssetCollectionRendererInterface');
}
/**
* Tests the Assets data collector.
*/
public function testCSS() {
$css = [
'core/assets/vendor/normalize-css/normalize.css' => [
......
<?php
namespace Drupal\Tests\webprofiler\Unit\DataCollector;
use Drupal\webprofiler\DataCollector\BlocksDataCollector;
use Drupal\webprofiler\Entity\Decorators\Config\ConfigEntityStorageDecorator;
use Drupal\webprofiler\Entity\EntityManagerWrapper;
use Drupal\webprofiler\Entity\EntityViewBuilderDecorator;
/**
* @coversDefaultClass \Drupal\webprofiler\DataCollector\BlocksDataCollector
*
* @group webprofiler
*/
class BlocksDataCollectorTest extends DataCollectorBaseTest {
/**
* @var \Drupal\webprofiler\DataCollector\BlocksDataCollector
*/
private $blocksDataCollector;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $entityTypeManager;
/**
* @var
*/
private $block;
/**
* @var
*/
private $entityStorage;
/**
* @var
*/
private $entityManagerWrapper;
/**
* @var
*/
private $configEntityStorageDecorator;
/**
* @var
*/
private $entityViewBuilder;
/**
* @var
*/
private $entityViewBuilderDecorator;
/**
* @var
*/
private $entity;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->entityTypeManager = $this->getMockBuilder('Drupal\Core\Entity\EntityTypeManagerInterface')->getMock();
$this->entityStorage = $this->getMockBuilder('Drupal\Core\Config\Entity\ConfigEntityStorageInterface')->getMock();
$this->entityViewBuilder = $this->getMockBuilder('Drupal\Core\Entity\EntityViewBuilderInterface')->getMock();
$this->entity = $this->getMockBuilder('Drupal\Core\Entity\EntityInterface')->getMock();
$this->block = $this->getMockBuilder('Drupal\block\BlockInterface')->getMock();
$this->entityManagerWrapper = new EntityManagerWrapper($this->entityTypeManager);
$this->blocksDataCollector = new BlocksDataCollector($this->entityManagerWrapper);
$this->configEntityStorageDecorator = new ConfigEntityStorageDecorator($this->entityStorage);
$this->entityViewBuilderDecorator = new EntityViewBuilderDecorator($this->entityViewBuilder);
}
/**
* Tests the Assets data collector.
*/
public function testLoadedBlock() {
$this->block->expects($this->once())
->method('getPluginId')
->will($this->returnValue('block_id'));
$this->entityStorage->expects($this->atMost(2))
->method('load')
->will($this->returnValue($this->block));
$this->entityTypeManager->expects($this->atMost(2))
->method('getHandler')
->will($this->returnValue($this->configEntityStorageDecorator));
/** @var \Drupal\Core\Entity\EntityStorageInterface $handler * */
$handler = $this->entityManagerWrapper->getStorage('block');
$this->assertNotNull($handler);
$block = $handler->load('block_id');
$this->assertEquals('block_id', $block->getPluginId());
$this->blocksDataCollector->collect($this->request, $this->response, $this->exception);
$this->assertCount(1, $this->blocksDataCollector->getLoadedBlocks());
$this->assertEquals(1, $this->blocksDataCollector->getLoadedBlocksCount());
}
/**
* Tests the Assets data collector.
*/
public function testRenderedBlock() {
$this->block->expects($this->once())
->method('getPluginId')
->will($this->returnValue('block_id'));
$this->entityStorage->expects($this->atMost(2))
->method('load')
->will($this->returnValue($this->block));
$this->entityTypeManager->expects($this->atMost(2))
->method('getHandler')
->withConsecutive(
['block', 'view_builder'],
['block', 'storage']
)
->willReturnOnConsecutiveCalls(
$this->returnValue($this->entityViewBuilderDecorator),
$this->returnValue($this->configEntityStorageDecorator)
);
/** @var \Drupal\Core\Entity\EntityStorageInterface $handler * */
$handler = $this->entityManagerWrapper->getViewBuilder('block');
$this->assertNotNull($handler);
$block = $handler->view($this->entity);
// $this->assertEquals('block_id', $block->getPluginId());
$this->blocksDataCollector->collect($this->request, $this->response, $this->exception);
$this->assertCount(1, $this->blocksDataCollector->getRenderedBlocks());
$this->assertEquals(1, $this->blocksDataCollector->getRenderedBlocksCount());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment