You are here

class ZfExtensionManagerSfContainerTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php \Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest

@coversDefaultClass \Drupal\Component\Bridge\ZfExtensionManagerSfContainer @group Bridge

Hierarchy

Expanded class hierarchy of ZfExtensionManagerSfContainerTest

File

core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php, line 18
Contains \Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest.

Namespace

Drupal\Tests\Component\Bridge
View source
class ZfExtensionManagerSfContainerTest extends UnitTestCase {

  /**
   * @covers ::setContainer
   * @covers ::get
   */
  public function testGet() {
    $service = new \stdClass();
    $service->value = 'myvalue';
    $container = new ContainerBuilder();
    $container
      ->set('foo', $service);
    $bridge = new ZfExtensionManagerSfContainer();
    $bridge
      ->setContainer($container);
    $this
      ->assertEquals($service, $bridge
      ->get('foo'));
  }

  /**
   * @covers ::setContainer
   * @covers ::has
   */
  public function testHas() {
    $service = new \stdClass();
    $service->value = 'myvalue';
    $container = new ContainerBuilder();
    $container
      ->set('foo', $service);
    $bridge = new ZfExtensionManagerSfContainer();
    $bridge
      ->setContainer($container);
    $this
      ->assertTrue($bridge
      ->has('foo'));
    $this
      ->assertFalse($bridge
      ->has('bar'));
  }

  /**
   * @covers ::__construct
   * @covers ::has
   * @covers ::get
   */
  public function testPrefix() {
    $service = new \stdClass();
    $service->value = 'myvalue';
    $container = new ContainerBuilder();
    $container
      ->set('foo.bar', $service);
    $bridge = new ZfExtensionManagerSfContainer('foo.');
    $bridge
      ->setContainer($container);
    $this
      ->assertTrue($bridge
      ->has('bar'));
    $this
      ->assertFalse($bridge
      ->has('baz'));
    $this
      ->assertEquals($service, $bridge
      ->get('bar'));
  }

  /**
   * @covers ::canonicalizeName
   * @dataProvider canonicalizeNameProvider
   */
  public function testCanonicalizeName($name, $canonical_name) {
    $service = new \stdClass();
    $service->value = 'myvalue';
    $container = new ContainerBuilder();
    $container
      ->set($canonical_name, $service);
    $bridge = new ZfExtensionManagerSfContainer();
    $bridge
      ->setContainer($container);
    $this
      ->assertTrue($bridge
      ->has($name));
    $this
      ->assertEquals($service, $bridge
      ->get($name));
  }

  /**
   * Data provider for testReverseProxyEnabled.
   *
   * Replacements:
   *   array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
   */
  public function canonicalizeNameProvider() {
    return array(
      array(
        'foobar',
        'foobar',
      ),
      array(
        'foo-bar',
        'foobar',
      ),
      array(
        'foo_bar',
        'foobar',
      ),
      array(
        'foo bar',
        'foobar',
      ),
      array(
        'foo\\bar',
        'foobar',
      ),
      array(
        'foo/bar',
        'foobar',
      ),
      // There is also a strtolower in canonicalizeName.
      array(
        'Foo/bAr',
        'foobar',
      ),
      array(
        'foo/-_\\ bar',
        'foobar',
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 259
ZfExtensionManagerSfContainerTest::canonicalizeNameProvider public function Data provider for testReverseProxyEnabled.
ZfExtensionManagerSfContainerTest::testCanonicalizeName public function @covers ::canonicalizeName @dataProvider canonicalizeNameProvider
ZfExtensionManagerSfContainerTest::testGet public function @covers ::setContainer @covers ::get
ZfExtensionManagerSfContainerTest::testHas public function @covers ::setContainer @covers ::has
ZfExtensionManagerSfContainerTest::testPrefix public function @covers ::__construct @covers ::has @covers ::get