-
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
Open
M1r1k
wants to merge
11
commits into
fago:8.x-3.x
Choose a base branch
from
M1r1k:webprofiler
base: 8.x-3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+647
−58
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ebe7e92
Init commit for webprofiler integration
2398860
Get rid of Assets entries after copy\paste
41c021e
Finish integration
657cfef
Fix couple of problems and put test data to check patch with
0b6dca7
Remove redundant tests and try to fix travis
a0e0a6f
Tests rule
46ccda6
Fix webprofiler webtest
dcab46a
Try to fix travic build with drush tricks
e0518ad
Try to fix travic build with drush tricks #2
ed002ff
Lets do a trick
1d3dbab
And finish the trick with camelCase directory name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
log_errors: warning | ||
debug_log: false | ||
debug: false | ||
log_level: info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\Logger\RulesStubLogger. | ||
*/ | ||
|
||
namespace Drupal\rules\Logger; | ||
|
||
use Drupal\Core\Logger\RfcLoggerTrait; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Logs events into the memory with ability check it afterwards. | ||
*/ | ||
class RulesStubLogger implements LoggerInterface { | ||
use RfcLoggerTrait; | ||
|
||
/** | ||
* The database connection object. | ||
* | ||
* @var array | ||
*/ | ||
protected $logs; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function log($level, $message, array $context = array()) { | ||
$this->logs[] = [ | ||
'level' => $level, | ||
'message' => $message, | ||
'context' => $context, | ||
]; | ||
} | ||
|
||
/** | ||
* Clears static logs storage. | ||
*/ | ||
public function cleanLogs() { | ||
$this->logs = array(); | ||
} | ||
|
||
/** | ||
* Returns statically saved logs. | ||
* | ||
* @return array | ||
* Array of logs. | ||
*/ | ||
public function getLogs() { | ||
return $this->logs; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\RulesServiceProvider. | ||
*/ | ||
|
||
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 WebProfiler module. | ||
*/ | ||
class RulesServiceProvider extends ServiceProviderBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function register(ContainerBuilder $container) { | ||
if (FALSE !== $container->hasDefinition('logger.channel.rules') && $container->hasDefinition('webprofiler.drupal')) { | ||
$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'); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\Tests\RulesDrupalWebTestBase | ||
*/ | ||
|
||
namespace Drupal\rules\Tests; | ||
|
||
use Drupal\simpletest\WebTestBase; | ||
|
||
/** | ||
* Rules base web test. | ||
* | ||
* @group rules | ||
*/ | ||
abstract class RulesDrupalWebTestBase extends WebTestBase { | ||
|
||
/** | ||
* Modules to install. | ||
* | ||
* @var array | ||
*/ | ||
public static $modules = ['rules']; | ||
|
||
/** | ||
* 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(); | ||
// @todo uncomment it when patch with permission comes. | ||
// $this->adminUser = $this->drupalCreateUser($permissions); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?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. |
||
* | ||
* Tests integration Rules logging with WebProfiler module. | ||
* | ||
* @group rules | ||
*/ | ||
class RulesWebProfilerTest extends RulesDrupalWebTestBase { | ||
|
||
/** | ||
* Authenticated user with access to WebProfiler. | ||
* | ||
* @var \Drupal\user\Entity\User | ||
*/ | ||
protected $webProfilerUser; | ||
|
||
public static $modules = ['rules', 'webprofiler', 'block']; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() { | ||
parent::setup(); | ||
|
||
// Enable rules logging. | ||
$this->container->get('config.factory') | ||
->getEditable('rules.settings') | ||
->set('debug_log', 1) | ||
->set('log_errors', 'debug') | ||
->save(); | ||
|
||
$this->webProfilerUser = $this->drupalCreateUser(array( | ||
'access webprofiler', | ||
'view webprofiler toolbar', | ||
)); | ||
|
||
// Enables rules web debugging with WebProfiler. | ||
$this->container->get('config.factory') | ||
->getEditable('webprofiler.config') | ||
->set('active_toolbar_items.rules', 'rules') | ||
->save(); | ||
|
||
$this->drupalLogin($this->webProfilerUser); | ||
} | ||
|
||
/** | ||
* Goes to WebProfiler page using link from toolbar and check entries there. | ||
*/ | ||
public function testWebProfilerPage() { | ||
$this->drupalGet('404', [ | ||
'query' => [ | ||
'log' => '1', | ||
'log-level' => 'critical', | ||
'log-message' => 'critical message', | ||
'log-amount' => 5, | ||
], | ||
]); | ||
|
||
$this->drupalGet('admin/reports/profiler/list'); | ||
$links = $this->xpath('//main//table[1]//a'); | ||
$url = $this->getAbsoluteUrl($links[0]['href']); | ||
$this->drupalGet($url); | ||
$this->assertText('Rules logs', 'Rules logs table exists'); | ||
$this->assertText('critical message', 'Rules log entry exists'); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We need a stub logger for that (as discussed).