-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebProfiler debugging integration #175
base: 8.x-3.x
Are you sure you want to change the base?
Changes from 5 commits
ebe7e92
2398860
41c021e
657cfef
0b6dca7
a0e0a6f
46ccda6
dcab46a
e0518ad
ed002ff
1d3dbab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\WebProfiler\WebProfilerServiceProvider. | ||
*/ | ||
|
||
namespace Drupal\rules; | ||
|
||
use Drupal\Core\Config\BootstrapConfigStorageFactory; | ||
use Drupal\Core\DependencyInjection\ContainerBuilder; | ||
use Drupal\Core\DependencyInjection\ServiceProviderBase; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Defines a service profiler for the web profiler module. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. |
||
*/ | ||
class RulesServiceProvider extends ServiceProviderBase { | ||
|
||
const CONFIG_PREFIX = 'webprofiler.config'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this const? Docblock plx. |
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function register(ContainerBuilder $container) { | ||
if (FALSE !== $container->hasDefinition('logger.channel.rules') && $this->isRulesDebuggingEnabled()) { | ||
$container->register('webprofiler.rules', 'Drupal\rules\WebProfiler\DataCollector\RulesDataCollector') | ||
->addArgument(new Reference('logger.channel.rules')) | ||
->addTag('data_collector', array( | ||
'template' => '@rules/Collector/rules.html.twig', | ||
'id' => 'rules', | ||
'title' => 'Rules', | ||
'priority' => 200, | ||
)); | ||
// Replace the regular logger.channel.rules service with a traceable one. | ||
$definition = $container->findDefinition('logger.channel.rules'); | ||
$definition->setClass('Drupal\rules\WebProfiler\RulesChannelLoggerWrapper'); | ||
} | ||
} | ||
|
||
/** | ||
* Checks whether the site is multilingual. | ||
* | ||
* @return bool | ||
* TRUE if the site is multilingual, FALSE otherwise. | ||
*/ | ||
protected function isRulesDebuggingEnabled() { | ||
$config_storage = BootstrapConfigStorageFactory::get(); | ||
$config = $config_storage->read(static::CONFIG_PREFIX); | ||
return !empty($config['active_toolbar_items']['rules']); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\Tests\RulesDrupalWebTestBase | ||
*/ | ||
|
||
namespace Drupal\rules\Tests; | ||
|
||
use Drupal\simpletest\WebTestBase; | ||
|
||
/** | ||
* Tests that the webprofile shows rules debug log and respects rules settings. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WebProfiler and Rules |
||
* | ||
* @group block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... No :P |
||
*/ | ||
class RulesDrupalWebTestBase extends WebTestBase { | ||
|
||
/** | ||
* Modules to install. | ||
* | ||
* @var array | ||
*/ | ||
public static $modules = ['rules', 'rules_ui']; | ||
|
||
/** | ||
* Authenticated user. | ||
* | ||
* @var \Drupal\user\Entity\User | ||
*/ | ||
protected $user; | ||
|
||
/** | ||
* User with administer rules permissions. | ||
* | ||
* @var \Drupal\user\Entity\User | ||
*/ | ||
protected $adminUser; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$permissions = array('create page content', 'administer rules'); | ||
$this->user = $this->drupalCreateUser(); | ||
$this->adminUser = $this->drupalCreateUser($permissions); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\Tests\RulesWebProfilerTest | ||
*/ | ||
|
||
namespace Drupal\rules\Tests; | ||
|
||
/** | ||
* Class RulesWebProfilerTest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a proper description. |
||
* @group Rules | ||
*/ | ||
class RulesWebProfilerTest extends RulesDrupalWebTestBase { | ||
|
||
/** | ||
* Authenticated user with access to web profiler. | ||
* | ||
* @var \Drupal\user\Entity\User | ||
*/ | ||
protected $webProfilerUser; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() { | ||
parent::setup(); | ||
|
||
$this->webProfilerUser = $this->drupalCreateUser(array( | ||
'access webprofiler', | ||
'view webprofiler toolbar', | ||
)); | ||
|
||
// Enables rules web debugging with web profiler. | ||
$this->config('webprofiler.config')->set('active_toolbar_items.rules', 'rules'); | ||
$this->drupalLogin($this->webProfilerUser); | ||
} | ||
|
||
/** | ||
* Tests does necessary information exist in WebProfiler toolbar. | ||
*/ | ||
public function testWebProfilerToolbar() { | ||
$this->drupalGet('<front>', array( | ||
'log' => '1', | ||
'log-level' => 'info', | ||
'log-message' => 'info message', | ||
'log-amount' => 5, | ||
)); | ||
|
||
$this->assertText('Rules logs', 'Rules logs are visible in the toolbar.'); | ||
$this->assertText('Info log entries 5', 'Additional rules logs info is visible in the toolbar.'); | ||
|
||
$this->drupalGet('<front>', array( | ||
'log' => '1', | ||
'log-level' => 'critical', | ||
'log-message' => 'critical message', | ||
'log-amount' => 3, | ||
)); | ||
|
||
$this->assertText('Rules logs', 'Rules logs are visible in the toolbar.'); | ||
$this->assertText('Error log entries 3', 'Additional rules logs info is visible in the toolbar.'); | ||
|
||
$this->drupalGet('<front>', array( | ||
'log' => '0', | ||
'log-level' => 'debug', | ||
'log-message' => 'debug message', | ||
'log-amount' => 3, | ||
)); | ||
|
||
$this->assertText('Rules logs', 'Rules logs are visible in the toolbar.'); | ||
$this->assertText('Debug log entries 0', 'Additional rules logs info is visible in the toolbar.'); | ||
|
||
$this->config('webprofiler.config')->set('active_toolbar_items.rules', ''); | ||
|
||
$this->drupalGet('<front>', array( | ||
'log' => '1', | ||
'log-level' => 'debug', | ||
'log-message' => 'debug message', | ||
'log-amount' => 3, | ||
)); | ||
|
||
$this->assertNoText('Rules logs', 'Rules logs are no visible in the toolbar.'); | ||
$this->assertNoText('Debug log entries 3', 'Additional rules logs info is not visible in the toolbar.'); | ||
} | ||
|
||
/** | ||
* Goes to WebProfiler page using link from toolbar and check entries there. | ||
*/ | ||
public function testWebProfilerPage() { | ||
$this->drupalGet('<front>', array( | ||
'log' => '1', | ||
'log-level' => 'info', | ||
'log-message' => 'info message', | ||
'log-amount' => 5, | ||
)); | ||
|
||
$links = $this->xpath('//div[@class="sf-toolbar-icon"]/a[@title="Rules"]'); | ||
|
||
$url = $this->getAbsoluteUrl($links[0]['href']); | ||
$this->drupalGet($url); | ||
$this->assertText('Rules logs', 'Rules logs table exists'); | ||
$this->assertText('info message', 'Rules log entry exists'); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.