[TASK] Clean up tests from Context API refactoring 57/57757/3
authorBenni Mack <benni@typo3.org>
Wed, 1 Aug 2018 15:23:34 +0000 (17:23 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 1 Aug 2018 19:18:50 +0000 (21:18 +0200)
Due to the Context API a lot less mocking needs to be done, and tests can be cleaned up.

On top, cObject receives a TSFE object as first parameter as DI, which can be used in
the code instead of global variables.

Resolves: #85708
Releases: master
Change-Id: I9d662b6735983d71e0b046548b747ac9b7f529db
Reviewed-on: https://review.typo3.org/57757
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbQueryParserTest.php
typo3/sysext/frontend/Tests/Unit/ContentObject/CaseContentObjectTest.php
typo3/sysext/frontend/Tests/Unit/ContentObject/FilesContentObjectTest.php
typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php

index 5a00003..a00d4d7 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Storage;
  */
 
 use Prophecy\Argument;
-use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
@@ -32,7 +31,6 @@ use TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser;
 use TYPO3\CMS\Extbase\Persistence\QueryInterface;
-use TYPO3\CMS\Frontend\Page\PageRepository;
 
 class Typo3DbQueryParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
 {
@@ -633,8 +631,6 @@ class Typo3DbQueryParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
             ],
             'delete' => 'deleted_column'
         ];
-        $GLOBALS['TSFE'] = new \stdClass();
-        $GLOBALS['TSFE']->sys_page = new PageRepository(new Context());
         $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
 
         $connectionProphet = $this->prophesize(Connection::class);
@@ -700,8 +696,6 @@ class Typo3DbQueryParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
             ],
             'delete' => 'deleted_column'
         ];
-        $GLOBALS['TSFE'] = new \stdClass();
-        $GLOBALS['TSFE']->sys_page = new PageRepository(new Context());
         $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
 
         $connectionProphet = $this->prophesize(Connection::class);
index e7c4232..3468fd6 100644 (file)
@@ -16,12 +16,10 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Frontend\ContentObject\CaseContentObject;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\ContentObject\TextContentObject;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
-use TYPO3\CMS\Frontend\Page\PageRepository;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
@@ -49,18 +47,8 @@ class CaseContentObjectTest extends UnitTestCase
             ->setMethods(['dummy'])
             ->disableOriginalConstructor()
             ->getMock();
-        $tsfe->tmpl = $this->getMockBuilder(TemplateService::class)
-            ->setMethods(['dummy'])
-            ->disableOriginalConstructor()
-            ->getMock();
-        $tsfe->config = [];
-        $tsfe->page = [];
-        $tsfe->sys_page = $this->getMockBuilder(PageRepository::class)
-            ->setMethods(['getRawRecord'])
-            ->getMock();
-        $GLOBALS['TSFE'] = $tsfe;
 
-        $contentObjectRenderer = new ContentObjectRenderer();
+        $contentObjectRenderer = new ContentObjectRenderer($tsfe);
         $contentObjectRenderer->setContentObjectClassMap([
             'CASE' => CaseContentObject::class,
             'TEXT' => TextContentObject::class,
index 9745f19..b2bbcdc 100644 (file)
@@ -25,7 +25,6 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\ContentObject\FilesContentObject;
 use TYPO3\CMS\Frontend\ContentObject\TextContentObject;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
-use TYPO3\CMS\Frontend\Page\PageRepository;
 use TYPO3\CMS\Frontend\Resource\FileCollector;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -50,11 +49,6 @@ class FilesContentObjectTest extends UnitTestCase
     protected $subject;
 
     /**
-     * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
-     */
-    protected $tsfe;
-
-    /**
      * Set up
      */
     protected function setUp()
@@ -62,20 +56,13 @@ class FilesContentObjectTest extends UnitTestCase
         $templateService = $this->getMockBuilder(TemplateService::class)
             ->setMethods(['getFileName', 'linkData'])
             ->getMock();
-        $this->tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)
+        $tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)
             ->setMethods(['dummy'])
             ->disableOriginalConstructor()
             ->getMock();
-        $this->tsfe->tmpl = $templateService;
-        $this->tsfe->config = [];
-        $this->tsfe->page = [];
-        $sysPageMock = $this->getMockBuilder(PageRepository::class)
-            ->setMethods(['getRawRecord'])
-            ->getMock();
-        $this->tsfe->sys_page = $sysPageMock;
-        $GLOBALS['TSFE'] = $this->tsfe;
+        $tsfe->tmpl = $templateService;
 
-        $contentObjectRenderer = new ContentObjectRenderer();
+        $contentObjectRenderer = new ContentObjectRenderer($tsfe);
         $contentObjectRenderer->setContentObjectClassMap([
             'FILES' => FilesContentObject::class,
             'TEXT' => TextContentObject::class,
index 4bcde2b..eb1e0f2 100644 (file)
@@ -16,11 +16,9 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Typolink;
 
 use Psr\Log\LoggerInterface;
 use TYPO3\CMS\Core\Log\LogManager;
-use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
-use TYPO3\CMS\Frontend\Page\PageRepository;
 use TYPO3\CMS\Frontend\Typolink\AbstractTypolinkBuilder;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -45,11 +43,6 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
     protected $frontendControllerMock;
 
     /**
-     * @var \PHPUnit_Framework_MockObject_MockObject|TemplateService
-     */
-    protected $templateServiceMock;
-
-    /**
      * Set up
      */
     protected function setUp()
@@ -58,23 +51,13 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
 
         $this->createMockedLoggerAndLogManager();
 
-        $this->templateServiceMock =
-            $this->getMockBuilder(TemplateService::class)
-            ->setMethods(['getFileName', 'linkData'])->getMock();
-        $pageRepositoryMock =
-            $this->getAccessibleMock(PageRepository::class, ['getRawRecord', 'getMountPointInfo']);
-        $this->frontendControllerMock =
-            $this->getAccessibleMock(
-                TypoScriptFrontendController::class,
+        $this->frontendControllerMock = $this->getAccessibleMock(
+            TypoScriptFrontendController::class,
             ['dummy'],
-                [],
-                '',
-                false
-            );
-        $this->frontendControllerMock->tmpl = $this->templateServiceMock;
-        $this->frontendControllerMock->config = [];
-        $this->frontendControllerMock->page =  [];
-        $this->frontendControllerMock->sys_page = $pageRepositoryMock;
+            [],
+            '',
+            false
+        );
         $GLOBALS['TSFE'] = $this->frontendControllerMock;
     }
 
@@ -83,14 +66,6 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
     //////////////////////
 
     /**
-     * @return TypoScriptFrontendController
-     */
-    protected function getFrontendController()
-    {
-        return $GLOBALS['TSFE'];
-    }
-
-    /**
      * Avoid logging to the file system (file writer is currently the only configured writer)
      */
     protected function createMockedLoggerAndLogManager()