Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / DependencyInjection / ContainerBuilderTest.php
index 026154da70876348c01189553c12dfc9fffdd0ab..e8de5ecf59ac382af67424c33847bbbb2b0a33ef 100644 (file)
@@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\DependencyInjection;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Tests\Core\DependencyInjection\Fixture\BarClass;
+use Symfony\Component\DependencyInjection\Definition;
 
 /**
  * @coversDefaultClass \Drupal\Core\DependencyInjection\ContainerBuilder
@@ -61,6 +62,53 @@ class ContainerBuilderTest extends UnitTestCase {
     $container->register('Bar');
   }
 
+  /**
+   * @covers ::register
+   */
+  public function testRegister() {
+    $container = new ContainerBuilder();
+    $service = $container->register('bar');
+    $this->assertTrue($service->isPublic());
+  }
+
+  /**
+   * @covers ::setDefinition
+   */
+  public function testSetDefinition() {
+    // Test a service with defaults.
+    $container = new ContainerBuilder();
+    $definition = new Definition();
+    $service = $container->setDefinition('foo', $definition);
+    $this->assertTrue($service->isPublic());
+    $this->assertFalse($service->isPrivate());
+
+    // Test a service with public set to false.
+    $definition = new Definition();
+    $definition->setPublic(FALSE);
+    $service = $container->setDefinition('foo', $definition);
+    $this->assertFalse($service->isPublic());
+    $this->assertFalse($service->isPrivate());
+
+    // Test a service with private set to true. Drupal does not support this.
+    // We only support using setPublic() to make things not available outside
+    // the container.
+    $definition = new Definition();
+    $definition->setPrivate(TRUE);
+    $service = $container->setDefinition('foo', $definition);
+    $this->assertTrue($service->isPublic());
+    $this->assertFalse($service->isPrivate());
+  }
+
+  /**
+   * @covers ::setAlias
+   */
+  public function testSetAlias() {
+    $container = new ContainerBuilder();
+    $container->register('bar');
+    $alias = $container->setAlias('foo', 'bar');
+    $this->assertTrue($alias->isPublic());
+  }
+
   /**
    * Tests serialization.
    */
@@ -70,4 +118,27 @@ class ContainerBuilderTest extends UnitTestCase {
     serialize($container);
   }
 
+  /**
+   * Tests constructor and resource tracking disabling.
+   *
+   * This test runs in a separate process to ensure the aliased class does not
+   * affect any other tests.
+   *
+   * @runInSeparateProcess
+   * @preserveGlobalState disabled
+   */
+  public function testConstructor() {
+    class_alias(testInterface::class, 'Symfony\Component\Config\Resource\ResourceInterface');
+    $container = new ContainerBuilder();
+    $this->assertFalse($container->isTrackingResources());
+  }
+
+}
+
+/**
+ * A test interface for testing ContainerBuilder::__construct().
+ *
+ * @see \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest::testConstructor()
+ */
+interface testInterface {
 }