You are here

public function ConfigActionsServiceTest::testAutoExecute in Config Actions 8

@covers ::autoExecute

File

tests/src/Kernel/ConfigActionsServiceTest.php, line 92

Class

ConfigActionsServiceTest
test the ConfigActions service

Namespace

Drupal\Tests\config_actions\Kernel

Code

public function testAutoExecute() {

  // Test default value returned.
  self::assertFalse($this->configActions
    ->autoExecute());
  $source = 'core.date_format.long';
  $value = 'My new label';
  $action = [
    'plugin' => 'change',
    'auto' => FALSE,
    'source' => $source,
    'path' => [
      'label',
    ],
    'value' => $value,
  ];
  $orig_config = $this
    ->getConfig($source);
  $orig_config['label'] = $value;

  // First test with autoExecute disabled.
  $this->configActions
    ->autoExecute(FALSE);
  self::assertFalse($this->configActions
    ->autoExecute());
  $new_config = $this->configActions
    ->processAction($action);
  self::assertEquals($orig_config, $new_config);

  // Next, test with autoExecute enabled.
  // Action should get skipped.
  $this->configActions
    ->autoExecute(TRUE);
  self::assertTrue($this->configActions
    ->autoExecute());
  $new_config = $this->configActions
    ->processAction($action);
  self::assertNull($new_config);
}