TYPO3 CMS  TYPO3_7-6
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 
18 
23 {
28  {
29  $extractorClass = 'a9f4d5e4ebb4b03547a2a6094e1170ac';
30  $extractorObject = $this->getMock(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class, [], [], $extractorClass);
31 
32  $extractorRegistry = $this->getMockExtractorRegistry([[$extractorClass, $extractorObject]]);
33 
34  $extractorRegistry->registerExtractionService($extractorClass);
35  $this->assertContains($extractorObject, $extractorRegistry->getExtractors(), '', false, false);
36  }
37 
44  {
45  $className = 'e1f9aa4e1cd3aa7ff05dcdccb117156a';
47  $extractorRegistry->registerExtractionService($className);
48  }
49 
56  {
57  $className = __CLASS__;
59  $extractorRegistry->registerExtractionService($className);
60  }
61 
66  {
67  $extractorClass1 = 'db76010e5c24658c35ea1605cce2391d';
68  $extractorObject1 = $this->getMock(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class, [], [], $extractorClass1);
69  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
70 
71  $extractorClass2 = 'ad9195e2487eea33c8a2abd5cf33cba4';
72  $extractorObject2 = $this->getMock(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class, [], [], $extractorClass2);
73  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(10));
74 
75  $extractorClass3 = 'cef9aa4e1cd3aa7ff05dcdccb117156a';
76  $extractorObject3 = $this->getMock(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class, [], [], $extractorClass3);
77  $extractorObject3->expects($this->any())->method('getPriority')->will($this->returnValue(2));
78 
79  $createdExtractorInstances = [
80  [$extractorClass1, $extractorObject1],
81  [$extractorClass2, $extractorObject2],
82  [$extractorClass3, $extractorObject3],
83  ];
84 
85  $extractorRegistry = $this->getMockExtractorRegistry($createdExtractorInstances);
86  $extractorRegistry->registerExtractionService($extractorClass1);
87  $extractorRegistry->registerExtractionService($extractorClass2);
88  $extractorRegistry->registerExtractionService($extractorClass3);
89 
90  $extractorInstances = $extractorRegistry->getExtractors();
91 
92  $this->assertTrue($extractorInstances[0] instanceof $extractorClass2);
93  $this->assertTrue($extractorInstances[1] instanceof $extractorClass3);
94  $this->assertTrue($extractorInstances[2] instanceof $extractorClass1);
95  }
96 
101  {
102  $extractorClass1 = 'b70551b2b2db62b6b15a9bbfcbd50614';
103  $extractorObject1 = $this->getMock(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class, [], [], $extractorClass1);
104  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
105 
106  $extractorClass2 = 'ac318f1659d278b79b38262f23a78d5d';
107  $extractorObject2 = $this->getMock(\TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class, [], [], $extractorClass2);
108  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(1));
109 
110  $createdExtractorInstances = [
111  [$extractorClass1, $extractorObject1],
112  [$extractorClass2, $extractorObject2],
113  ];
114 
115  $extractorRegistry = $this->getMockExtractorRegistry($createdExtractorInstances);
116  $extractorRegistry->registerExtractionService($extractorClass1);
117  $extractorRegistry->registerExtractionService($extractorClass2);
118 
119  $extractorInstances = $extractorRegistry->getExtractors();
120  $this->assertContains($extractorObject1, $extractorInstances);
121  $this->assertContains($extractorObject2, $extractorInstances);
122  }
123 
130  protected function getMockExtractorRegistry(array $createsExtractorInstances = [])
131  {
132  $extractorRegistry = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::class)
133  ->setMethods(['createExtractorInstance'])
134  ->getMock();
135 
136  if (!empty($createsExtractorInstances)) {
137  $extractorRegistry->expects($this->any())
138  ->method('createExtractorInstance')
139  ->will($this->returnValueMap($createsExtractorInstances));
140  }
141 
142  return $extractorRegistry;
143  }
144 }
$extractorRegistry