Commit 7ab2a389 authored by lussoluca's avatar lussoluca

Merge branch 'testing' of bitbucket.org:wellnet-team/devel into testing

parents 8d52f52e 61c8ea49
<?php
namespace Drupal\Tests\webprofiler\Functional;
use Drupal\Tests\webprofiler\FunctionalJavascript\WebprofilerTestBase;
/**
* Tests the database storage backend option.
*
* @group webprofiler
*/
class DatabaseStorageTest extends WebprofilerTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['devel', 'webprofiler'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->config('webprofiler.config')
->set('storage', 'profiler.database_storage')
->save(TRUE);
$this->drupalLogin($this->drupalCreateUser(['access webprofiler']));
}
/**
* Tests the purge on cache clear enabled setting.
*/
public function testCacheClearEnabledOnDatabaseStorage() {
$this->enableCacheClear();
$profiles = $this->getProfiles();
$this->assertCount(4, $profiles);
drupal_flush_all_caches();
$profiles = $this->getProfiles();
$this->assertCount(0, $profiles);
}
/**
* Tests the purge on cache clear disabled setting.
*/
public function testCacheClearDisabledOnDatabaseStorage() {
$this->disableCacheClear();
$profiles = $this->getProfiles();
$this->assertCount(4, $profiles);
drupal_flush_all_caches();
$profiles = $this->getProfiles();
$this->assertCount(4, $profiles);
}
/**
* Enables the "purge on cache clear" settings.
*/
private function enableCacheClear() {
$this->config('webprofiler.config')
->set('purge_on_cache_clear', TRUE)
->save(TRUE);
}
/**
* Disables the "purge on cache clear" settings.
*/
private function disableCacheClear() {
$this->config('webprofiler.config')
->set('purge_on_cache_clear', FALSE)
->save(TRUE);
}
/**
* Returns the stored profiles.
*
* @return array
* The stored profiles.
*/
private function getProfiles() {
/** @var \Drupal\webprofiler\Profiler\Profiler $profiler */
$profiler = $this->container->get('profiler');
$profiles = $profiler->find(NULL, NULL, 100, NULL, '', '');
return $profiles;
}
}
<?php
namespace Drupal\Tests\webprofiler\Functional;
use Drupal\Tests\webprofiler\FunctionalJavascript\WebprofilerTestBase;
/**
* Tests the file storage backend option.
*
* @group webprofiler
*/
class FileStorageTest extends WebprofilerTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['devel', 'webprofiler'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->config('webprofiler.config')
->set('storage', 'profiler.file_storage')
->save(TRUE);
$this->drupalLogin($this->drupalCreateUser(['access webprofiler']));
}
/**
* Tests the purge on cache clear enabled setting.
*/
public function testCacheClearEnabledOnFileStorage() {
$this->enableCacheClear();
$profiles = $this->getProfiles();
$this->assertCount(4, $profiles);
drupal_flush_all_caches();
$profiles = $this->getProfiles();
$this->assertCount(0, $profiles);
}
/**
* Tests the purge on cache clear disabled setting.
*/
public function testCacheClearDisabledOnFileStorage() {
$this->disableCacheClear();
$profiles = $this->getProfiles();
$this->assertCount(4, $profiles);
drupal_flush_all_caches();
$profiles = $this->getProfiles();
$this->assertCount(4, $profiles);
}
/**
* Enables the "purge on cache clear" settings.
*/
private function enableCacheClear() {
$this->config('webprofiler.config')
->set('purge_on_cache_clear', TRUE)
->save(TRUE);
}
/**
* Disables the "purge on cache clear" settings.
*/
private function disableCacheClear() {
$this->config('webprofiler.config')
->set('purge_on_cache_clear', FALSE)
->save(TRUE);
}
/**
* Returns the stored profiles.
*
* @return array
* The stored profiles.
*/
private function getProfiles() {
/** @var \Drupal\webprofiler\Profiler\Profiler $profiler */
$profiler = $this->container->get('profiler');
$profiles = $profiler->find(NULL, NULL, 100, NULL, '', '');
return $profiles;
}
}
......@@ -5,15 +5,18 @@ namespace Drupal\Tests\webprofiler\FunctionalJavascript;
/**
* Tests the JavaScript functionality of webprofiler.
*
* @group toolbar
* @group webprofiler
*/
class ToolbarTest extends WebprofilerTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['webprofiler', 'node', 'views'];
public static $modules = ['webprofiler', 'node'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
......@@ -54,4 +57,23 @@ class ToolbarTest extends WebprofilerTestBase {
$assert->pageTextContains($token);
}
/**
* Tests the toolbar not appears on excluded path.
*/
public function testToolbarNotAppearsOnExcludedPath() {
$this->loginForDashboard();
$this->drupalGet('admin/config/development/devel');
$token = $this->waitForToolbar();
$assert = $this->assertSession();
$assert->pageTextContains($token);
$assert->pageTextContains('Configure Webprofiler');
$this->config('webprofiler.config')
->set('exclude', '/admin/config/development/devel')
->save();
$this->drupalGet('admin/config/development/devel');
$this->assertSession()->pageTextNotContains('sf-toolbar');
}
}
......@@ -7,6 +7,8 @@ use PHPUnit_Framework_AssertionFailedError;
/**
* Class WebprofilerTestBase.
*
* @group webprofiler
*/
abstract class WebprofilerTestBase extends JavascriptTestBase {
......
<?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());
}
}
......@@ -6,6 +6,8 @@ use Drupal\Tests\UnitTestCase;
/**
* Class DataCollectorBaseTest.
*
* @group webprofiler
*/
abstract class DataCollectorBaseTest extends UnitTestCase {
......
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