Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Config / Entity / ConfigEntityTypeTest.php
index 914d4f6fe53307b735eff76065aeb1c9bf298a7e..0c1ac1bd8f3c20e16a2fb990861e0eb018763389 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Drupal\Tests\Core\Config\Entity;
 
+use Drupal\Core\Config\TypedConfigManagerInterface;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Config\Entity\ConfigEntityType;
 use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
@@ -12,6 +14,23 @@ use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
  */
 class ConfigEntityTypeTest extends UnitTestCase {
 
+  /**
+   * The mocked typed config manager.
+   *
+   * @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $typedConfigManager;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    $this->typedConfigManager = $this->getMock(TypedConfigManagerInterface::class);
+    $container = new ContainerBuilder();
+    $container->set('config.typed', $this->typedConfigManager);
+    \Drupal::setContainer($container);
+  }
+
   /**
    * Sets up a ConfigEntityType object for a given set of values.
    *
@@ -85,7 +104,7 @@ class ConfigEntityTypeTest extends UnitTestCase {
     $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it');
     new ConfigEntityType([
       'id' => 'example_config_entity_type',
-      'handlers' => ['storage' => '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage']
+      'handlers' => ['storage' => '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'],
     ]);
   }
 
@@ -137,11 +156,6 @@ class ConfigEntityTypeTest extends UnitTestCase {
 
   public function providerGetPropertiesToExport() {
     $data = [];
-    $data[] = [
-      [],
-      NULL,
-    ];
-
     $data[] = [
       [
         'config_export' => [
@@ -177,4 +191,27 @@ class ConfigEntityTypeTest extends UnitTestCase {
     return $data;
   }
 
+  /**
+   * @covers ::getPropertiesToExport
+   */
+  public function testGetPropertiesToExportSchemaFallback() {
+    $this->typedConfigManager->expects($this->once())
+      ->method('getDefinition')
+      ->will($this->returnValue(['mapping' => ['id' => '', 'dependencies' => '']]));
+    $config_entity_type = new ConfigEntityType([
+      'id' => 'example_config_entity_type',
+    ]);
+    $this->assertEquals(['id' => 'id', 'dependencies' => 'dependencies'], $config_entity_type->getPropertiesToExport('test'));
+  }
+
+  /**
+   * @covers ::getPropertiesToExport
+   */
+  public function testGetPropertiesToExportNoFallback() {
+    $config_entity_type = new ConfigEntityType([
+      'id' => 'example_config_entity_type',
+    ]);
+    $this->assertNull($config_entity_type->getPropertiesToExport());
+  }
+
 }