You are here

public function SettingsFormTest::testEditSettings in Node Option Premium 8

Tests editing existing configuration.

File

tests/src/Functional/Form/SettingsFormTest.php, line 151

Class

SettingsFormTest
Tests configuring the module.

Namespace

Drupal\Tests\nopremium\Functional\Form

Code

public function testEditSettings() {
  $this
    ->drupalLogin($this->adminUser);

  // Create two content types.
  $this
    ->drupalCreateContentType([
    'type' => 'bar',
  ]);
  $this
    ->drupalCreateContentType([
    'type' => 'foo',
  ]);

  // Change some configuration programmatically.
  $this
    ->config('nopremium.settings')
    ->set('default_message', 'The default premium message.')
    ->set('messages', [
    'foo' => 'The foo message',
  ])
    ->set('view_modes', [
    'full' => 'full',
    'rss' => 'rss',
  ])
    ->set('teaser_view_mode', 'rss')
    ->save();

  // Test submitting form without changing anything.
  $this
    ->drupalPostForm('/admin/config/content/nopremium', [], 'Save configuration');

  // Assert that the configuration stayed the same.
  $expected = [
    'default_message' => 'The default premium message.',
    'view_modes' => [
      'full' => 'full',
      'rss' => 'rss',
    ],
    'teaser_view_mode' => 'rss',
    'messages' => [
      'foo' => 'The foo message',
      'bar' => '',
    ],
  ];
  $config = $this
    ->config('nopremium.settings')
    ->getRawData();
  unset($config['_core']);
  $this
    ->assertSame($expected, $config);
}