ConfigTest.php

Same filename in this branch
  1. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  2. 8.9.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  3. 8.9.x core/modules/system/tests/src/Functional/File/ConfigTest.php
  4. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  5. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  6. 8.9.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php
Same filename and directory in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  2. 9 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  3. 9 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  4. 9 core/modules/system/tests/src/Functional/File/ConfigTest.php
  5. 9 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  6. 9 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  7. 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php
  8. 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  9. 10 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  10. 10 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  11. 10 core/modules/system/tests/src/Functional/File/ConfigTest.php
  12. 10 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  13. 10 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  14. 10 core/tests/Drupal/Tests/Core/Config/ConfigTest.php
  15. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  16. 11.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  17. 11.x core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  18. 11.x core/modules/system/tests/src/Functional/File/ConfigTest.php
  19. 11.x core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  20. 11.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  21. 11.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php

Namespace

Drupal\Tests\migrate\Unit\destination

File

core/modules/migrate/tests/src/Unit/destination/ConfigTest.php

View source
<?php

namespace Drupal\Tests\migrate\Unit\destination;

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\Config;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\Config
 * @group migrate
 */
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',
    ]);
  }

}

Classes

Title Deprecated Summary
ConfigTest @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\Config[[api-linebreak]] @group migrate

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.