TYPO3 CMS  TYPO3_8-7
ExtractorRegistryTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 class ExtractorRegistryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
26  {
27  $extractorClass = 'a9f4d5e4ebb4b03547a2a6094e1170ac';
28  $extractorObject = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
29  ->setMockClassName($extractorClass)
30  ->getMock();
31 
32  $extractorRegistry = $this->getMockExtractorRegistry([[$extractorClass, $extractorObject]]);
33 
34  $extractorRegistry->registerExtractionService($extractorClass);
35  $this->assertContains($extractorObject, $extractorRegistry->getExtractors(), '', false, false);
36  }
37 
42  {
43  $this->expectException(\InvalidArgumentException::class);
44  $this->expectExceptionCode(1422705270);
45 
46  $className = 'e1f9aa4e1cd3aa7ff05dcdccb117156a';
48  $extractorRegistry->registerExtractionService($className);
49  }
50 
55  {
56  $this->expectException(\InvalidArgumentException::class);
57  $this->expectExceptionCode(1422705271);
58 
59  $className = __CLASS__;
61  $extractorRegistry->registerExtractionService($className);
62  }
63 
68  {
69  $extractorClass1 = 'db76010e5c24658c35ea1605cce2391d';
70  $extractorObject1 = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
71  ->setMockClassName($extractorClass1)
72  ->getMock();
73  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
74 
75  $extractorClass2 = 'ad9195e2487eea33c8a2abd5cf33cba4';
76  $extractorObject2 = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
77  ->setMockClassName($extractorClass2)
78  ->getMock();
79  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(10));
80 
81  $extractorClass3 = 'cef9aa4e1cd3aa7ff05dcdccb117156a';
82  $extractorObject3 = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
83  ->setMockClassName($extractorClass3)
84  ->getMock();
85  $extractorObject3->expects($this->any())->method('getPriority')->will($this->returnValue(2));
86 
87  $createdExtractorInstances = [
88  [$extractorClass1, $extractorObject1],
89  [$extractorClass2, $extractorObject2],
90  [$extractorClass3, $extractorObject3],
91  ];
92 
93  $extractorRegistry = $this->getMockExtractorRegistry($createdExtractorInstances);
94  $extractorRegistry->registerExtractionService($extractorClass1);
95  $extractorRegistry->registerExtractionService($extractorClass2);
96  $extractorRegistry->registerExtractionService($extractorClass3);
97 
98  $extractorInstances = $extractorRegistry->getExtractors();
99 
100  $this->assertTrue($extractorInstances[0] instanceof $extractorClass2);
101  $this->assertTrue($extractorInstances[1] instanceof $extractorClass3);
102  $this->assertTrue($extractorInstances[2] instanceof $extractorClass1);
103  }
104 
109  {
110  $extractorClass1 = 'b70551b2b2db62b6b15a9bbfcbd50614';
111  $extractorObject1 = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
112  ->setMockClassName($extractorClass1)
113  ->getMock();
114  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
115 
116  $extractorClass2 = 'ac318f1659d278b79b38262f23a78d5d';
117  $extractorObject2 = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
118  ->setMockClassName($extractorClass2)
119  ->getMock();
120  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(1));
121 
122  $createdExtractorInstances = [
123  [$extractorClass1, $extractorObject1],
124  [$extractorClass2, $extractorObject2],
125  ];
126 
127  $extractorRegistry = $this->getMockExtractorRegistry($createdExtractorInstances);
128  $extractorRegistry->registerExtractionService($extractorClass1);
129  $extractorRegistry->registerExtractionService($extractorClass2);
130 
131  $extractorInstances = $extractorRegistry->getExtractors();
132  $this->assertContains($extractorObject1, $extractorInstances);
133  $this->assertContains($extractorObject2, $extractorInstances);
134  }
135 
142  protected function getMockExtractorRegistry(array $createsExtractorInstances = [])
143  {
144  $extractorRegistry = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::class)
145  ->setMethods(['createExtractorInstance'])
146  ->getMock();
147 
148  if (!empty($createsExtractorInstances)) {
149  $extractorRegistry->expects($this->any())
150  ->method('createExtractorInstance')
151  ->will($this->returnValueMap($createsExtractorInstances));
152  }
153 
154  return $extractorRegistry;
155  }
156 }
$extractorRegistry