‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪ExtractorRegistryTest extends UnitTestCase
23 {
28  {
29  $extractorClass = 'a9f4d5e4ebb4b03547a2a6094e1170ac';
30  $extractorObject = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
31  ->setMockClassName($extractorClass)
32  ->getMock();
33 
34  ‪$extractorRegistry = $this->‪getMockExtractorRegistry([[$extractorClass, $extractorObject]]);
35 
36  ‪$extractorRegistry->registerExtractionService($extractorClass);
37  $this->assertContains($extractorObject, ‪$extractorRegistry->getExtractors(), '', false, false);
38  }
39 
44  {
45  $this->expectException(\InvalidArgumentException::class);
46  $this->expectExceptionCode(1422705270);
47 
48  $className = 'e1f9aa4e1cd3aa7ff05dcdccb117156a';
50  ‪$extractorRegistry->registerExtractionService($className);
51  }
52 
57  {
58  $this->expectException(\InvalidArgumentException::class);
59  $this->expectExceptionCode(1422705271);
60 
61  $className = __CLASS__;
63  ‪$extractorRegistry->registerExtractionService($className);
64  }
65 
70  {
71  $extractorClass1 = 'db76010e5c24658c35ea1605cce2391d';
72  $extractorObject1 = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
73  ->setMockClassName($extractorClass1)
74  ->getMock();
75  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
76 
77  $extractorClass2 = 'ad9195e2487eea33c8a2abd5cf33cba4';
78  $extractorObject2 = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
79  ->setMockClassName($extractorClass2)
80  ->getMock();
81  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(10));
82 
83  $extractorClass3 = 'cef9aa4e1cd3aa7ff05dcdccb117156a';
84  $extractorObject3 = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
85  ->setMockClassName($extractorClass3)
86  ->getMock();
87  $extractorObject3->expects($this->any())->method('getPriority')->will($this->returnValue(2));
88 
89  $createdExtractorInstances = [
90  [$extractorClass1, $extractorObject1],
91  [$extractorClass2, $extractorObject2],
92  [$extractorClass3, $extractorObject3],
93  ];
94 
95  ‪$extractorRegistry = $this->‪getMockExtractorRegistry($createdExtractorInstances);
96  ‪$extractorRegistry->registerExtractionService($extractorClass1);
97  ‪$extractorRegistry->registerExtractionService($extractorClass2);
98  ‪$extractorRegistry->registerExtractionService($extractorClass3);
99 
100  $extractorInstances = ‪$extractorRegistry->getExtractors();
101 
102  $this->assertTrue($extractorInstances[0] instanceof $extractorClass2);
103  $this->assertTrue($extractorInstances[1] instanceof $extractorClass3);
104  $this->assertTrue($extractorInstances[2] instanceof $extractorClass1);
105  }
106 
111  {
112  $extractorClass1 = 'b70551b2b2db62b6b15a9bbfcbd50614';
113  $extractorObject1 = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
114  ->setMockClassName($extractorClass1)
115  ->getMock();
116  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
117 
118  $extractorClass2 = 'ac318f1659d278b79b38262f23a78d5d';
119  $extractorObject2 = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface::class)
120  ->setMockClassName($extractorClass2)
121  ->getMock();
122  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(1));
123 
124  $createdExtractorInstances = [
125  [$extractorClass1, $extractorObject1],
126  [$extractorClass2, $extractorObject2],
127  ];
128 
129  ‪$extractorRegistry = $this->‪getMockExtractorRegistry($createdExtractorInstances);
130  ‪$extractorRegistry->registerExtractionService($extractorClass1);
131  ‪$extractorRegistry->registerExtractionService($extractorClass2);
132 
133  $extractorInstances = ‪$extractorRegistry->getExtractors();
134  $this->assertContains($extractorObject1, $extractorInstances);
135  $this->assertContains($extractorObject2, $extractorInstances);
136  }
137 
144  protected function ‪getMockExtractorRegistry(array $createsExtractorInstances = [])
145  {
146  ‪$extractorRegistry = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::class)
147  ->setMethods(['createExtractorInstance'])
148  ->getMock();
149 
150  if (!empty($createsExtractorInstances)) {
151  ‪$extractorRegistry->expects($this->any())
152  ->method('createExtractorInstance')
153  ->will($this->returnValueMap($createsExtractorInstances));
154  }
155 
156  return ‪$extractorRegistry;
157  }
158 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registeredExtractorClassCanBeRetrieved
‪registeredExtractorClassCanBeRetrieved()
Definition: ExtractorRegistryTest.php:27
‪$extractorRegistry
‪$extractorRegistry
Definition: ext_localconf.php:131
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registerExtractorClassThrowsExceptionIfClassDoesNotImplementRightInterface
‪registerExtractorClassThrowsExceptionIfClassDoesNotImplementRightInterface()
Definition: ExtractorRegistryTest.php:56
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest
Definition: ExtractorRegistryTest.php:23
‪TYPO3
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry
Definition: ExtractorRegistry.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registeredExtractorClassWithSamePriorityAreAllReturned
‪registeredExtractorClassWithSamePriorityAreAllReturned()
Definition: ExtractorRegistryTest.php:110
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index
Definition: ExtractorRegistryTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\getMockExtractorRegistry
‪PHPUnit_Framework_MockObject_MockObject TYPO3 CMS Core Resource Index ExtractorRegistry getMockExtractorRegistry(array $createsExtractorInstances=[])
Definition: ExtractorRegistryTest.php:144
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registerExtractorClassThrowsExceptionIfClassDoesNotExist
‪registerExtractorClassThrowsExceptionIfClassDoesNotExist()
Definition: ExtractorRegistryTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registerExtractorClassWithHighestPriorityIsFirstInResult
‪registerExtractorClassWithHighestPriorityIsFirstInResult()
Definition: ExtractorRegistryTest.php:69