You are here

public function PollFieldTest::testPollFields in Poll 8

Test poll entity fields.

File

tests/src/Functional/PollFieldTest.php, line 49

Class

PollFieldTest
Tests the poll fields.

Namespace

Drupal\Tests\poll\Functional

Code

public function testPollFields() {
  $poll = $this->poll;
  $this
    ->drupalLogin($this->admin_user);

  // Add some fields.
  $this
    ->fieldUIAddNewField('admin/config/content/poll', 'number', 'Number field', 'integer');
  $this
    ->fieldUIAddNewField('admin/config/content/poll', 'text', 'Text field', 'string');

  // Test field form display.
  $this
    ->drupalGet('admin/config/content/poll/form-display');
  $this
    ->assertText('Number field');
  $this
    ->assertText('Text field');

  // Test edit poll form.
  $this
    ->drupalGet('poll/' . $poll
    ->id() . '/edit');
  $this
    ->assertText('Number field');
  $this
    ->assertText('Text field');
  $edit = array(
    'field_number[0][value]' => random_int(10, 1000),
    'field_text[0][value]' => $this
      ->randomString(),
  );
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Test view poll form.
  $this
    ->drupalGet('poll/' . $poll
    ->id());
  $this
    ->assertText('Number field');
  $this
    ->assertText('Text field');
}