protected function TourUITest::editTest in Tour UI 8
Tests the editing of a tour.
1 call to TourUITest::editTest()
- TourUITest::testUi in tests/
src/ Functional/ TourUITest.php - Tests the listing and editing of a tour.
File
- tests/
src/ Functional/ TourUITest.php, line 88
Class
- TourUITest
- Tests the Tour UI.
Namespace
Drupal\Tests\tour_ui\FunctionalCode
protected function editTest() {
// Create a new tour. Ensure that it comes before the test tours.
$edit = [
'label' => 'a' . $this
->randomString(),
'id' => strtolower($this
->randomMachineName()),
'module' => strtolower($this
->randomMachineName()),
];
$this
->drupalPostForm('admin/config/user-interface/tour/add', $edit, t('Save'));
$this
->assertRaw(t('The %tour tour has been created.', [
'%tour' => $edit['label'],
]));
$elements = $this
->xpath('//table/tbody/tr');
$this
->assertEquals(1, count($elements));
// Edit and re-save an existing tour.
$this
->assertTitle(t('Edit tour | @site-name', [
'@site-name' => \Drupal::config('system.site')
->get('name'),
]));
$this
->drupalPostForm(NULL, [], t('Save'));
$this
->assertRaw(t('Updated the %tour tour', [
'%tour' => $edit['label'],
]));
// Reorder the tour tips.
$this
->drupalGet('admin/config/user-interface/tour/manage/tour-test');
$weights = [
'tips[tour-test-1][weight]' => '2',
'tips[tour-test-3][weight]' => '1',
];
$this
->drupalPostForm(NULL, $weights, t('Save'));
$this
->drupalGet('admin/config/user-interface/tour/manage/tour-test');
$elements = $this
->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
':class' => 'draggable odd',
':text' => 'The awesome image',
]);
$this
->assertEquals(1, count($elements), 'Found odd tip "The awesome image".');
$elements = $this
->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
':class' => 'draggable even',
':text' => 'The first tip',
]);
$this
->assertEquals(1, count($elements), 'Found even tip "The first tip".');
$weights = [
'tips[tour-test-1][weight]' => '1',
'tips[tour-test-3][weight]' => '2',
];
$this
->drupalPostForm(NULL, $weights, t('Save'));
$this
->drupalGet('admin/config/user-interface/tour/manage/tour-test');
$elements = $this
->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
':class' => 'draggable odd',
':text' => 'The first tip',
]);
$this
->assertEquals(1, count($elements), 'Found odd tip "The first tip".');
$elements = $this
->xpath('//tr[@class=:class and ./td[contains(., :text)]]', [
':class' => 'draggable even',
':text' => 'The awesome image',
]);
$this
->assertEquals(1, count($elements), 'Found even tip "The awesome image".');
// Attempt to create a duplicate tour.
$this
->drupalPostForm('admin/config/user-interface/tour/add', $edit, t('Save'));
$this
->assertRaw(t('The machine-readable name is already in use. It must be unique.'));
// Delete a tour.
$this
->drupalGet('admin/config/user-interface/tour/manage/' . $edit['id']);
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$this
->assertRaw(t('Are you sure you want to delete the %tour tour?', [
'%tour' => $edit['label'],
]));
$this
->clickLink(t('Cancel'));
$this
->clickLink(t('Delete'));
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$elements = $this
->xpath('//table/tbody/tr');
$this
->assertEquals(2, count($elements));
$this
->assertRaw(t('Deleted the %tour tour.', [
'%tour' => $edit['label'],
]));
}