class ConfigTest in Drupal 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest
- 8 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\ConfigTest
- 8 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php \Drupal\Tests\Composer\Plugin\ProjectMessage\ConfigTest
- 8 core/modules/system/tests/src/Functional/File/ConfigTest.php \Drupal\Tests\system\Functional\File\ConfigTest
- 8 core/modules/config/tests/config_test/src/Entity/ConfigTest.php \Drupal\config_test\Entity\ConfigTest
- 8 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php \Drupal\Tests\migrate\Unit\destination\ConfigTest
- 8 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8\ConfigTest
Same name and namespace in other branches
- 9 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php \Drupal\Tests\migrate\Unit\destination\ConfigTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\Config @group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Tests\migrate\Unit\destination\ConfigTest
 
Expanded class hierarchy of ConfigTest
File
- core/modules/ migrate/ tests/ src/ Unit/ destination/ ConfigTest.php, line 13 
Namespace
Drupal\Tests\migrate\Unit\destinationView source
class ConfigTest extends UnitTestCase {
  /**
   * Test the import method.
   */
  public function testImport() {
    $source = [
      'test' => 'x',
    ];
    $migration = $this
      ->getMockBuilder('Drupal\\migrate\\Plugin\\Migration')
      ->disableOriginalConstructor()
      ->getMock();
    $config = $this
      ->getMockBuilder('Drupal\\Core\\Config\\Config')
      ->disableOriginalConstructor()
      ->getMock();
    foreach ($source as $key => $val) {
      $config
        ->expects($this
        ->once())
        ->method('set')
        ->with($this
        ->equalTo($key), $this
        ->equalTo($val))
        ->will($this
        ->returnValue($config));
    }
    $config
      ->expects($this
      ->once())
      ->method('save');
    $config
      ->expects($this
      ->once())
      ->method('getName')
      ->willReturn('d8_config');
    $config_factory = $this
      ->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
    $config_factory
      ->expects($this
      ->once())
      ->method('getEditable')
      ->with('d8_config')
      ->will($this
      ->returnValue($config));
    $row = $this
      ->getMockBuilder('Drupal\\migrate\\Row')
      ->disableOriginalConstructor()
      ->getMock();
    $row
      ->expects($this
      ->any())
      ->method('getRawDestination')
      ->will($this
      ->returnValue($source));
    $language_manager = $this
      ->getMockBuilder('Drupal\\language\\ConfigurableLanguageManagerInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $language_manager
      ->expects($this
      ->never())
      ->method('getLanguageConfigOverride')
      ->with('fr', 'd8_config')
      ->will($this
      ->returnValue($config));
    $destination = new Config([
      'config_name' => 'd8_config',
    ], 'd8_config', [
      'pluginId' => 'd8_config',
    ], $migration, $config_factory, $language_manager);
    $destination_id = $destination
      ->import($row);
    $this
      ->assertEquals($destination_id, [
      'd8_config',
    ]);
  }
  /**
   * Test the import method.
   */
  public function testLanguageImport() {
    $source = [
      'langcode' => 'mi',
    ];
    $migration = $this
      ->getMockBuilder(MigrationInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $config = $this
      ->getMockBuilder('Drupal\\Core\\Config\\Config')
      ->disableOriginalConstructor()
      ->getMock();
    foreach ($source as $key => $val) {
      $config
        ->expects($this
        ->once())
        ->method('set')
        ->with($this
        ->equalTo($key), $this
        ->equalTo($val))
        ->will($this
        ->returnValue($config));
    }
    $config
      ->expects($this
      ->once())
      ->method('save');
    $config
      ->expects($this
      ->any())
      ->method('getName')
      ->willReturn('d8_config');
    $config_factory = $this
      ->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
    $config_factory
      ->expects($this
      ->once())
      ->method('getEditable')
      ->with('d8_config')
      ->will($this
      ->returnValue($config));
    $row = $this
      ->getMockBuilder('Drupal\\migrate\\Row')
      ->disableOriginalConstructor()
      ->getMock();
    $row
      ->expects($this
      ->any())
      ->method('getRawDestination')
      ->will($this
      ->returnValue($source));
    $row
      ->expects($this
      ->any())
      ->method('getDestinationProperty')
      ->will($this
      ->returnValue($source['langcode']));
    $language_manager = $this
      ->getMockBuilder('Drupal\\language\\ConfigurableLanguageManagerInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $language_manager
      ->expects($this
      ->any())
      ->method('getLanguageConfigOverride')
      ->with('mi', 'd8_config')
      ->will($this
      ->returnValue($config));
    $destination = new Config([
      'config_name' => 'd8_config',
      'translations' => 'true',
    ], 'd8_config', [
      'pluginId' => 'd8_config',
    ], $migration, $config_factory, $language_manager);
    $destination_id = $destination
      ->import($row);
    $this
      ->assertEquals($destination_id, [
      'd8_config',
      'mi',
    ]);
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| ConfigTest:: | public | function | Test the import method. | |
| ConfigTest:: | public | function | Test the import method. | |
| PhpunitCompatibilityTrait:: | public | function | Returns a mock object for the specified class using the available method. | |
| PhpunitCompatibilityTrait:: | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| UnitTestCase:: | protected | property | The random generator. | |
| UnitTestCase:: | protected | property | The app root. | 1 | 
| UnitTestCase:: | protected | function | Asserts if two arrays are equal by sorting them first. | |
| UnitTestCase:: | protected | function | Mocks a block with a block plugin. | 1 | 
| UnitTestCase:: | protected | function | Returns a stub class resolver. | |
| UnitTestCase:: | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase:: | public | function | Returns a stub config storage that returns the supplied configuration. | |
| UnitTestCase:: | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase:: | protected | function | Gets the random generator for the utility methods. | |
| UnitTestCase:: | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase:: | public | function | Generates a unique random string containing letters and numbers. | |
| UnitTestCase:: | protected | function | 340 | 
