You are here

public function ConfigReverterTest::testRevert in Configuration Update Manager 8

@covers \Drupal\config_update\ConfigReverter::revert @dataProvider revertProvider

File

tests/src/Unit/ConfigReverterTest.php, line 199

Class

ConfigReverterTest
Tests the \Drupal\config_update\ConfigReverter class.

Namespace

Drupal\Tests\config_update\Unit

Code

public function testRevert($type, $name, $config_name, $expected, $config_before, $config_after) {

  // Clear dispatch log and set pre-config.
  $this->dispatchedEvents = [];
  if ($config_name) {
    $this->configStorage[$config_name] = $config_before;
  }
  $save_config = $this->configStorage;

  // Call the reverter and test the Boolean result.
  $result = $this->configReverter
    ->revert($type, $name);
  $this
    ->assertEquals($result, $expected);
  if ($result) {

    // Verify that the config is correct after revert, and logging worked.
    $this
      ->assertEquals($this->configStorage[$config_name], $config_after);
    $this
      ->assertEquals(count($this->dispatchedEvents), 1);
    $this
      ->assertEquals($this->dispatchedEvents[0][0], ConfigRevertInterface::REVERT);
  }
  else {

    // Verify that the config didn't change and no events were logged.
    $this
      ->assertEquals($this->configStorage, $save_config);
    $this
      ->assertEquals(count($this->dispatchedEvents), 0);
  }
}