[FEATURE] Automatically determine page type for URIs with format
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Web / Routing / UriBuilderTest.php
index 7bed74e..3cafd26 100644 (file)
@@ -475,14 +475,68 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
-       public function buildTypolinkConfigurationConsidersPageType() {
+       public function buildTypolinkConfigurationResolvesPageTypeFromFormat() {
                $this->uriBuilder->setTargetPageUid(123);
-               $this->uriBuilder->setTargetPageType(2);
+               $this->uriBuilder->setFormat('txt');
+
+               $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')
+                       ->will($this->returnValue(array('view' => array('formatToPageTypeMapping' => array('txt' => 2)))));
+               $this->uriBuilder->injectConfigurationManager($mockConfigurationManager);
+
+               $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
+                       ->with(NULL, 'txt')
+                       ->will($this->returnValue(2));
+
                $expectedConfiguration = array('parameter' => '123,2', 'useCacheHash' => 1);
                $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
                $this->assertEquals($expectedConfiguration, $actualConfiguration);
        }
 
+       /**
+        * @test
+        */
+       public function buildTypolinkConfigurationResolvesDefaultPageTypeFromFormatIfNoMappingIsConfigured() {
+               $this->uriBuilder->setTargetPageUid(123);
+               $this->uriBuilder->setFormat('txt');
+
+               $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue(array()));
+               $this->uriBuilder->injectConfigurationManager($mockConfigurationManager);
+
+               $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
+                       ->with(NULL, 'txt')
+                       ->will($this->returnValue(0));
+
+               $expectedConfiguration = array('parameter' => '123,0', 'useCacheHash' => 1);
+               $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
+
+               $this->assertEquals($expectedConfiguration, $actualConfiguration);
+       }
+
+       /**
+        * @test
+        */
+       public function buildTypolinkConfigurationResolvesDefaultPageTypeFromFormatIfFormatIsNotMapped() {
+               $this->uriBuilder->setTargetPageUid(123);
+               $this->uriBuilder->setFormat('txt');
+
+               $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')
+                       ->will($this->returnValue(array(array('view' => array('formatToPageTypeMapping' => array('pdf' => 2))))));
+               $this->uriBuilder->injectConfigurationManager($mockConfigurationManager);
+
+               $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
+                       ->with(NULL, 'txt')
+                       ->will($this->returnValue(0));
+
+               $expectedConfiguration = array('parameter' => '123,0', 'useCacheHash' => 1);
+               $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
+
+               $this->assertEquals($expectedConfiguration, $actualConfiguration);
+       }
+
+
        /**
         * @test
         */