You are here

public function CustomFormattersGeneralTest::testCustomFormattersUi in Custom Formatters 8.3

Test General UI related functionality.

File

src/Tests/CustomFormattersGeneralTest.php, line 15

Class

CustomFormattersGeneralTest
Test general functionality.

Namespace

Drupal\custom_formatters\Tests

Code

public function testCustomFormattersUi() {

  // Ensure the Formatters administration is linked in the structure section.
  $this
    ->drupalGet('admin/structure');
  $this
    ->assertLinkByHref('admin/structure/formatters');
  $this
    ->assertText('Administer Formatters.');
  $this
    ->drupalGet('admin/structure/formatters');

  // Ensure the Formatters overview page is present.
  $expected_title = t(':title | :sitename', [
    ':title' => 'Formatters',
    ':sitename' => \Drupal::config('system.site')
      ->get('name'),
  ]);
  $this
    ->assertTitle($expected_title);

  // Ensure the Settings link is present and correct.
  $this
    ->assertLink(t('Settings'));
  $this
    ->assertLinkByHref('admin/structure/formatters/settings');

  // Ensure our pre-prepared test formatter is present.
  $this
    ->assertText('Test Formatter');
  $this
    ->assertLinkByHref('admin/structure/formatters/manage/test_formatter');
  $this
    ->assertCustomFormatterExists('test_formatter');

  // Ensure our pre-prepared test formatter is present on the Manage display
  // page.
  $this
    ->drupalGet('admin/structure/types/manage/article/display');
  $this
    ->assertRaw('custom_formatters:test_formatter');
  $this
    ->assertRaw('Custom: Test Formatter');

  // Change the Label prefix.
  $edit = [
    'label_prefix_value' => $this
      ->randomMachineName(),
  ];
  $this
    ->drupalPostForm('admin/structure/formatters/settings', $edit, t('Save configuration'));
  $this
    ->assertText(t('Custom Formatters settings have been updated.'));

  // Ensure our pre-prepared test formatter is present on the Manage display
  // page with the altered label prefix.
  $this
    ->drupalGet('admin/structure/types/manage/article/display');
  $this
    ->assertRaw(t('@prefix: Test Formatter', [
    '@prefix' => $edit['label_prefix_value'],
  ]));

  // Remove the Label prefix.
  $edit = [
    'label_prefix' => FALSE,
  ];
  $this
    ->drupalPostForm('admin/structure/formatters/settings', $edit, t('Save configuration'));
  $this
    ->assertText(t('Custom Formatters settings have been updated.'));

  // Ensure our pre-prepared test formatter is present on the Manage display
  // page without a label prefix.
  $this
    ->drupalGet('admin/structure/types/manage/article/display');
  $this
    ->assertRaw('Test Formatter');
}