Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\Component\Bridge;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Bridge\ZfExtensionManagerSfContainer;
|
Chris@0
|
6 use PHPUnit\Framework\TestCase;
|
Chris@0
|
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
|
Chris@17
|
8 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
Chris@17
|
9 use Zend\Feed\Reader\Extension\Atom\Entry;
|
Chris@17
|
10 use Zend\Feed\Reader\StandaloneExtensionManager;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * @coversDefaultClass \Drupal\Component\Bridge\ZfExtensionManagerSfContainer
|
Chris@0
|
14 * @group Bridge
|
Chris@0
|
15 */
|
Chris@0
|
16 class ZfExtensionManagerSfContainerTest extends TestCase {
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * @covers ::setContainer
|
Chris@17
|
20 * @covers ::setStandalone
|
Chris@0
|
21 * @covers ::get
|
Chris@0
|
22 */
|
Chris@0
|
23 public function testGet() {
|
Chris@0
|
24 $service = new \stdClass();
|
Chris@0
|
25 $service->value = 'myvalue';
|
Chris@0
|
26 $container = new ContainerBuilder();
|
Chris@0
|
27 $container->set('foo', $service);
|
Chris@0
|
28 $bridge = new ZfExtensionManagerSfContainer();
|
Chris@0
|
29 $bridge->setContainer($container);
|
Chris@0
|
30 $this->assertEquals($service, $bridge->get('foo'));
|
Chris@17
|
31 $bridge->setStandalone(StandaloneExtensionManager::class);
|
Chris@17
|
32 $this->assertInstanceOf(Entry::class, $bridge->get('Atom\Entry'));
|
Chris@17
|
33 // Ensure that the container is checked first.
|
Chris@17
|
34 $container->set('atomentry', $service);
|
Chris@17
|
35 $this->assertEquals($service, $bridge->get('Atom\Entry'));
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 /**
|
Chris@0
|
39 * @covers ::setContainer
|
Chris@17
|
40 * @covers ::setStandalone
|
Chris@0
|
41 * @covers ::has
|
Chris@0
|
42 */
|
Chris@0
|
43 public function testHas() {
|
Chris@0
|
44 $service = new \stdClass();
|
Chris@0
|
45 $service->value = 'myvalue';
|
Chris@0
|
46 $container = new ContainerBuilder();
|
Chris@0
|
47 $container->set('foo', $service);
|
Chris@0
|
48 $bridge = new ZfExtensionManagerSfContainer();
|
Chris@0
|
49 $bridge->setContainer($container);
|
Chris@0
|
50 $this->assertTrue($bridge->has('foo'));
|
Chris@0
|
51 $this->assertFalse($bridge->has('bar'));
|
Chris@17
|
52 $this->assertFalse($bridge->has('Atom\Entry'));
|
Chris@17
|
53 $bridge->setStandalone(StandaloneExtensionManager::class);
|
Chris@17
|
54 $this->assertTrue($bridge->has('Atom\Entry'));
|
Chris@17
|
55 }
|
Chris@17
|
56
|
Chris@17
|
57 /**
|
Chris@17
|
58 * @covers ::setStandalone
|
Chris@17
|
59 */
|
Chris@17
|
60 public function testSetStandaloneException() {
|
Chris@17
|
61 if (method_exists($this, 'expectException')) {
|
Chris@17
|
62 $this->expectException(\RuntimeException::class);
|
Chris@17
|
63 $this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface');
|
Chris@17
|
64 }
|
Chris@17
|
65 else {
|
Chris@17
|
66 $this->setExpectedException(\RuntimeException::class, 'Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface');
|
Chris@17
|
67 }
|
Chris@17
|
68 $bridge = new ZfExtensionManagerSfContainer();
|
Chris@17
|
69 $bridge->setStandalone(static::class);
|
Chris@17
|
70 }
|
Chris@17
|
71
|
Chris@17
|
72 /**
|
Chris@17
|
73 * @covers ::get
|
Chris@17
|
74 */
|
Chris@17
|
75 public function testGetContainerException() {
|
Chris@17
|
76 if (method_exists($this, 'expectException')) {
|
Chris@17
|
77 $this->expectException(ServiceNotFoundException::class);
|
Chris@17
|
78 $this->expectExceptionMessage('You have requested a non-existent service "test.foo".');
|
Chris@17
|
79 }
|
Chris@17
|
80 else {
|
Chris@17
|
81 $this->setExpectedException(ServiceNotFoundException::class, 'You have requested a non-existent service "test.foo".');
|
Chris@17
|
82 }
|
Chris@17
|
83 $container = new ContainerBuilder();
|
Chris@17
|
84 $bridge = new ZfExtensionManagerSfContainer('test.');
|
Chris@17
|
85 $bridge->setContainer($container);
|
Chris@17
|
86 $bridge->setStandalone(StandaloneExtensionManager::class);
|
Chris@17
|
87 $bridge->get('foo');
|
Chris@0
|
88 }
|
Chris@0
|
89
|
Chris@0
|
90 /**
|
Chris@0
|
91 * @covers ::__construct
|
Chris@0
|
92 * @covers ::has
|
Chris@0
|
93 * @covers ::get
|
Chris@0
|
94 */
|
Chris@0
|
95 public function testPrefix() {
|
Chris@0
|
96 $service = new \stdClass();
|
Chris@0
|
97 $service->value = 'myvalue';
|
Chris@0
|
98 $container = new ContainerBuilder();
|
Chris@0
|
99 $container->set('foo.bar', $service);
|
Chris@0
|
100 $bridge = new ZfExtensionManagerSfContainer('foo.');
|
Chris@0
|
101 $bridge->setContainer($container);
|
Chris@0
|
102 $this->assertTrue($bridge->has('bar'));
|
Chris@0
|
103 $this->assertFalse($bridge->has('baz'));
|
Chris@0
|
104 $this->assertEquals($service, $bridge->get('bar'));
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 /**
|
Chris@0
|
108 * @covers ::canonicalizeName
|
Chris@0
|
109 * @dataProvider canonicalizeNameProvider
|
Chris@0
|
110 */
|
Chris@0
|
111 public function testCanonicalizeName($name, $canonical_name) {
|
Chris@0
|
112 $service = new \stdClass();
|
Chris@0
|
113 $service->value = 'myvalue';
|
Chris@0
|
114 $container = new ContainerBuilder();
|
Chris@0
|
115 $container->set($canonical_name, $service);
|
Chris@0
|
116 $bridge = new ZfExtensionManagerSfContainer();
|
Chris@0
|
117 $bridge->setContainer($container);
|
Chris@0
|
118 $this->assertTrue($bridge->has($name));
|
Chris@0
|
119 $this->assertEquals($service, $bridge->get($name));
|
Chris@0
|
120 }
|
Chris@0
|
121
|
Chris@0
|
122 /**
|
Chris@0
|
123 * Data provider for testReverseProxyEnabled.
|
Chris@0
|
124 *
|
Chris@0
|
125 * Replacements:
|
Chris@0
|
126 * array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
|
Chris@0
|
127 */
|
Chris@0
|
128 public function canonicalizeNameProvider() {
|
Chris@0
|
129 return [
|
Chris@0
|
130 [
|
Chris@0
|
131 'foobar',
|
Chris@0
|
132 'foobar',
|
Chris@0
|
133 ],
|
Chris@0
|
134 [
|
Chris@0
|
135 'foo-bar',
|
Chris@0
|
136 'foobar',
|
Chris@0
|
137 ],
|
Chris@0
|
138 [
|
Chris@0
|
139 'foo_bar',
|
Chris@0
|
140 'foobar',
|
Chris@0
|
141 ],
|
Chris@0
|
142 [
|
Chris@0
|
143 'foo bar',
|
Chris@0
|
144 'foobar',
|
Chris@0
|
145 ],
|
Chris@0
|
146 [
|
Chris@0
|
147 'foo\\bar',
|
Chris@0
|
148 'foobar',
|
Chris@0
|
149 ],
|
Chris@0
|
150 [
|
Chris@0
|
151 'foo/bar',
|
Chris@0
|
152 'foobar',
|
Chris@0
|
153 ],
|
Chris@0
|
154 // There is also a strtolower in canonicalizeName.
|
Chris@0
|
155 [
|
Chris@0
|
156 'Foo/bAr',
|
Chris@0
|
157 'foobar',
|
Chris@0
|
158 ],
|
Chris@0
|
159 [
|
Chris@0
|
160 'foo/-_\\ bar',
|
Chris@0
|
161 'foobar',
|
Chris@0
|
162 ],
|
Chris@0
|
163 ];
|
Chris@0
|
164 }
|
Chris@0
|
165
|
Chris@0
|
166 }
|