|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * Contains \Drupal\rules\Tests\RulesWebProfilerTest |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Drupal\rules\Tests; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class RulesWebProfilerTest |
| 12 | + * @group Rules |
| 13 | + */ |
| 14 | +class RulesWebProfilerTest extends RulesDrupalWebTestBase { |
| 15 | + |
| 16 | + /** |
| 17 | + * Authenticated user with access to web profiler. |
| 18 | + * |
| 19 | + * @var \Drupal\user\Entity\User |
| 20 | + */ |
| 21 | + protected $webProfilerUser; |
| 22 | + |
| 23 | + /** |
| 24 | + * {@inheritdoc} |
| 25 | + */ |
| 26 | + public function setUp() { |
| 27 | + parent::setup(); |
| 28 | + |
| 29 | + $this->webProfilerUser = $this->drupalCreateUser(array( |
| 30 | + 'access webprofiler', |
| 31 | + 'view webprofiler toolbar', |
| 32 | + )); |
| 33 | + |
| 34 | + // Enables rules web debugging with web profiler. |
| 35 | + $this->config('webprofiler.config')->set('active_toolbar_items.rules', 'rules'); |
| 36 | + $this->drupalLogin($this->webProfilerUser); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Tests does necessary information exist in WebProfiler toolbar. |
| 41 | + */ |
| 42 | + public function testWebProfilerToolbar() { |
| 43 | + $this->drupalGet('<front>', array( |
| 44 | + 'log' => '1', |
| 45 | + 'log-level' => 'info', |
| 46 | + 'log-message' => 'info message', |
| 47 | + 'log-amount' => 5, |
| 48 | + )); |
| 49 | + |
| 50 | + $this->assertText('Rules logs', 'Rules logs are visible in the toolbar.'); |
| 51 | + $this->assertText('Info log entries 5', 'Additional rules logs info is visible in the toolbar.'); |
| 52 | + |
| 53 | + $this->drupalGet('<front>', array( |
| 54 | + 'log' => '1', |
| 55 | + 'log-level' => 'critical', |
| 56 | + 'log-message' => 'critical message', |
| 57 | + 'log-amount' => 3, |
| 58 | + )); |
| 59 | + |
| 60 | + $this->assertText('Rules logs', 'Rules logs are visible in the toolbar.'); |
| 61 | + $this->assertText('Error log entries 3', 'Additional rules logs info is visible in the toolbar.'); |
| 62 | + |
| 63 | + $this->drupalGet('<front>', array( |
| 64 | + 'log' => '0', |
| 65 | + 'log-level' => 'debug', |
| 66 | + 'log-message' => 'debug message', |
| 67 | + 'log-amount' => 3, |
| 68 | + )); |
| 69 | + |
| 70 | + $this->assertText('Rules logs', 'Rules logs are visible in the toolbar.'); |
| 71 | + $this->assertText('Debug log entries 0', 'Additional rules logs info is visible in the toolbar.'); |
| 72 | + |
| 73 | + $this->config('webprofiler.config')->set('active_toolbar_items.rules', ''); |
| 74 | + |
| 75 | + $this->drupalGet('<front>', array( |
| 76 | + 'log' => '1', |
| 77 | + 'log-level' => 'debug', |
| 78 | + 'log-message' => 'debug message', |
| 79 | + 'log-amount' => 3, |
| 80 | + )); |
| 81 | + |
| 82 | + $this->assertNoText('Rules logs', 'Rules logs are no visible in the toolbar.'); |
| 83 | + $this->assertNoText('Debug log entries 3', 'Additional rules logs info is not visible in the toolbar.'); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Goes to WebProfiler page using link from toolbar and check entries there. |
| 88 | + */ |
| 89 | + public function testWebProfilerPage() { |
| 90 | + $this->drupalGet('<front>', array( |
| 91 | + 'log' => '1', |
| 92 | + 'log-level' => 'info', |
| 93 | + 'log-message' => 'info message', |
| 94 | + 'log-amount' => 5, |
| 95 | + )); |
| 96 | + |
| 97 | + $links = $this->xpath('//div[@class="sf-toolbar-icon"]/a[@title="Rules"]'); |
| 98 | + |
| 99 | + $url = $this->getAbsoluteUrl($links[0]['href']); |
| 100 | + $this->drupalGet($url); |
| 101 | + $this->assertText('Rules logs', 'Rules logs table exists'); |
| 102 | + $this->assertText('info message', 'Rules log entry exists'); |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments