You are here

protected function TourUITest::tipTest in Tour UI 8

Tests the add/edit/delete of a tour tip.

1 call to TourUITest::tipTest()
TourUITest::testUi in tests/src/Functional/TourUITest.php
Tests the listing and editing of a tour.

File

tests/src/Functional/TourUITest.php, line 159

Class

TourUITest
Tests the Tour UI.

Namespace

Drupal\Tests\tour_ui\Functional

Code

protected function tipTest() {

  // Create a new tour for tips to be added to.
  $edit = [
    'label' => 'a' . $this
      ->randomString(),
    'id' => strtolower($this
      ->randomMachineName()),
    'module' => $this
      ->randomString(),
    'paths' => '',
  ];
  $this
    ->drupalPostForm('admin/config/user-interface/tour/add', $edit, t('Save'));
  $this
    ->assertRaw(t('The %tour tour has been created.', [
    '%tour' => $edit['label'],
  ]));

  // Add a new tip.
  $tip = [
    'new' => 'image',
  ];
  $this
    ->drupalPostForm('admin/config/user-interface/tour/manage/' . $edit['id'], $tip, t('Add'));
  $tip = [
    'label' => 'a' . $this
      ->randomString(),
    'id' => 'tour-ui-test-image-tip',
    'url' => 'http://testimage.png',
    'alt' => 'Testing a new image tip through Tour UI.',
  ];
  $this
    ->drupalPostForm(NULL, $tip, t('Save'));
  $elements = $this
    ->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
    ':class' => 'draggable odd',
    ':text' => $tip['label'],
  ]);
  $this
    ->assertEquals(1, count($elements), 'Found tip "' . $tip['label'] . '".');

  // Edit the tip.
  $tip_id = $tip['id'];
  unset($tip['id']);
  $tip['label'] = 'a' . $this
    ->randomString();
  $this
    ->drupalPostForm('admin/config/user-interface/tour/manage/' . $edit['id'] . '/tip/edit/' . $tip_id, $tip, t('Save'));
  $elements = $this
    ->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
    ':class' => 'draggable odd',
    ':text' => $tip['label'],
  ]);
  $this
    ->assertEquals(1, count($elements), 'Found tip "' . $tip['label'] . '".');

  // Delete the tip.
  $this
    ->drupalPostForm('admin/config/user-interface/tour/manage/' . $edit['id'] . '/tip/delete/' . $tip_id, [], t('Delete'));
  $elements = $this
    ->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
    ':class' => 'draggable odd',
    ':text' => $tip['label'],
  ]);
  $this
    ->assertNotEqual(count($elements), 1, 'Did not find tip "' . $tip['label'] . '".');
}