You are here

public function CounterTest::testCounterCodePagesSettings in Yandex.Metrics 8.3

Test Yandex.Metrics page specific settings.

File

tests/src/Functional/CounterTest.php, line 139
Contains \Drupal\yandex_metrics\Tests\CounterTest.

Class

CounterTest
Tests of functionality and settings of Yandex.Metrics Counter module.

Namespace

Drupal\Tests\yandex_metrics\Functional

Code

public function testCounterCodePagesSettings() {

  // Login as administrator.
  $this
    ->drupalLogin($this->admin_user);
  $edit = array();
  $edit["counter_code"] = $this->yandex_metrics_code;
  $this
    ->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));

  // Create test node.
  $node = $this
    ->drupalCreateNode();

  // Check if counter exists.
  $this
    ->drupalGet('node');
  $this
    ->checkCounter();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->checkCounter();

  // Disable counter on node overview and node full pages.
  $edit = array();
  $edit["pages"] = \Drupal::config('yandex_metrics.settings')
    ->get('visibility.path.pages') . "\r\n" . 'node' . "\r\n" . 'node/*';
  $this
    ->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));

  // Check if counter doesn't exist.
  $this
    ->drupalGet('node');
  $this
    ->checkNoCounter();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->checkNoCounter();

  // Enable counter only on node pages.
  $edit = array();
  $edit['visibility'] = 1;
  $edit['pages'] = 'node/*';
  $this
    ->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));

  // Check if counter exists.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->checkCounter();

  // Check if counter doesn't exist.
  $this
    ->drupalGet('node');
  $this
    ->checkNoCounter();
  $this
    ->drupalGet('user');
  $this
    ->checkNoCounter();
}