You are here

public function PollFieldUITest::testPollFieldUI in Poll 8

Test if 'Manage fields' page is visible in the poll's settings UI.

File

tests/src/Functional/PollFieldUITest.php, line 39

Class

PollFieldUITest
Tests the poll field UI.

Namespace

Drupal\Tests\poll\Functional

Code

public function testPollFieldUI() {
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->drupalGet('admin/config/content/poll');
  $this
    ->assertResponse(200);

  // Check if 'Manage fields' tab appears in the poll's settings page.
  $this
    ->assertUrl('admin/config/content/poll');
  $xpath = '//div/main/aside/div/div/nav/ul/li[2]/a';
  $this
    ->assertFieldByXPath($xpath, 'Manage fields');

  // Ensure that the 'Manage display' page is visible.
  $this
    ->clickLink('Manage display');
  $this
    ->assertTitle('Manage display | Drupal');

  // Ensure vote results in List
  $element = $this
    ->cssSelect('#poll-votes');
  $this
    ->assertNotEqual($element, array(), '"Vote form/Results" field is available.');

  // Ensure that the 'Manage fields' page is visible.
  $this
    ->clickLink('Manage fields');
  $this
    ->assertTitle('Manage fields | Drupal');

  // Add a poll field.
  $this
    ->clickLink('Add field');
  $edit = [
    'new_storage_type' => 'field_ui:entity_reference:user',
    'label' => 'poll',
    'field_name' => 'poll',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save and continue');
  $edit = [
    'settings[target_type]' => 'poll',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save field settings');
  $this
    ->assertText('Updated field poll field settings.');
  $edit = [
    'label' => 'field_poll',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save settings');
  $this
    ->assertText('Saved field_poll configuration.');

  // Ensure that the newly created field is listed.
  $this
    ->assertText($edit['label']);
}