TYPO3 CMS  TYPO3_6-2
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  $extractorClass = 'a9f4d5e4ebb4b03547a2a6094e1170ac';
29  $extractorObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', array(), array(), $extractorClass);
30 
31  $extractorRegistry = $this->getMockExtractorRegistry(array(array($extractorClass, $extractorObject)));
32 
33  $extractorRegistry->registerExtractionService($extractorClass);
34  $this->assertContains($extractorObject, $extractorRegistry->getExtractors(), '', FALSE, FALSE);
35  }
36 
43  $className = 'e1f9aa4e1cd3aa7ff05dcdccb117156a';
44  $extractorRegistry = $this->getMockExtractorRegistry();
45  $extractorRegistry->registerExtractionService($className);
46  }
47 
54  $className = __CLASS__;
55  $extractorRegistry = $this->getMockExtractorRegistry();
56  $extractorRegistry->registerExtractionService($className);
57  }
58 
63 
64  $extractorClass1 = 'db76010e5c24658c35ea1605cce2391d';
65  $extractorObject1 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', array(), array(), $extractorClass1);
66  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
67 
68  $extractorClass2 = 'ad9195e2487eea33c8a2abd5cf33cba4';
69  $extractorObject2 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', array(), array(), $extractorClass2);
70  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(10));
71 
72  $extractorClass3 = 'cef9aa4e1cd3aa7ff05dcdccb117156a';
73  $extractorObject3 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', array(), array(), $extractorClass3);
74  $extractorObject3->expects($this->any())->method('getPriority')->will($this->returnValue(2));
75 
76  $createdExtractorInstances = array(
77  array($extractorClass1, $extractorObject1),
78  array($extractorClass2, $extractorObject2),
79  array($extractorClass3, $extractorObject3),
80  );
81 
82  $extractorRegistry = $this->getMockExtractorRegistry($createdExtractorInstances);
83  $extractorRegistry->registerExtractionService($extractorClass1);
84  $extractorRegistry->registerExtractionService($extractorClass2);
85  $extractorRegistry->registerExtractionService($extractorClass3);
86 
87  $extractorInstances = $extractorRegistry->getExtractors();
88 
89  $this->assertTrue($extractorInstances[0] instanceof $extractorClass2);
90  $this->assertTrue($extractorInstances[1] instanceof $extractorClass3);
91  $this->assertTrue($extractorInstances[2] instanceof $extractorClass1);
92  }
93 
98 
99  $extractorClass1 = 'b70551b2b2db62b6b15a9bbfcbd50614';
100  $extractorObject1 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', array(), array(), $extractorClass1);
101  $extractorObject1->expects($this->any())->method('getPriority')->will($this->returnValue(1));
102 
103  $extractorClass2 = 'ac318f1659d278b79b38262f23a78d5d';
104  $extractorObject2 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', array(), array(), $extractorClass2);
105  $extractorObject2->expects($this->any())->method('getPriority')->will($this->returnValue(1));
106 
107  $createdExtractorInstances = array(
108  array($extractorClass1, $extractorObject1),
109  array($extractorClass2, $extractorObject2),
110  );
111 
112  $extractorRegistry = $this->getMockExtractorRegistry($createdExtractorInstances);
113  $extractorRegistry->registerExtractionService($extractorClass1);
114  $extractorRegistry->registerExtractionService($extractorClass2);
115 
116  $extractorInstances = $extractorRegistry->getExtractors();
117  $this->assertTrue($extractorInstances[0] instanceof $extractorClass1);
118  $this->assertTrue($extractorInstances[1] instanceof $extractorClass2);
119  }
120 
127  protected function getMockExtractorRegistry(array $createsExtractorInstances = array()) {
128  $extractorRegistry = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorRegistry')
129  ->setMethods(array('createExtractorInstance'))
130  ->getMock();
131 
132  if (count($createsExtractorInstances) > 0) {
133  $extractorRegistry->expects($this->any())
134  ->method('createExtractorInstance')
135  ->will($this->returnValueMap($createsExtractorInstances));
136  }
137 
138  return $extractorRegistry;
139  }
140 
141 }
getMockExtractorRegistry(array $createsExtractorInstances=array())