[TASK] Extend WorkspaceServiceTests for fetchPagesWithVersionsInTable 45/54445/4
authorSusanne Moog <susanne.moog@typo3.com>
Thu, 19 Oct 2017 12:49:50 +0000 (14:49 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 19 Oct 2017 21:27:46 +0000 (23:27 +0200)
Add new tests for fetchPagesWithVersionsInTable and correct comments.

Change-Id: I2fe08656ecddf3f7391e6012bb969dd85c2cfb24
Resolves: #82811
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/54445
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/workspaces/Classes/Service/WorkspaceService.php
typo3/sysext/workspaces/Tests/Functional/Service/WorkspaceServiceTest.php

index 3428030..414e0ac 100644 (file)
@@ -960,20 +960,22 @@ class WorkspaceService implements SingletonInterface
      *
      * Result:
      * [
+     *   'sys_template' => [],
      *   'tt_content' => [
-     *     1 => 1,
-     *     11 => 11,
-     *     13 => 13,
-     *     15 => 15
+     *     1 => true,
+     *     11 => true,
+     *     13 => true,
+     *     15 => true
      *   ],
      *   'tx_something => [
-     *     15 => 15,
-     *     11 => 11,
-     *     21 => 21
+     *     15 => true,
+     *     11 => true,
+     *     21 => true
      *   ],
      * ]
      *
      * @param int $workspaceId
+     *
      * @return array
      */
     public function getPagesWithVersionsInTable($workspaceId)
@@ -994,10 +996,10 @@ class WorkspaceService implements SingletonInterface
      *
      * Result:
      * [
-     *   1 => 1,
-     *   11 => 11,
-     *   13 => 13,
-     *   15 => 15
+     *   1 => true,
+     *   11 => true,
+     *   13 => true,
+     *   15 => true
      * ],
      *
      * @param int $workspaceId
index f3346db..88a6884 100644 (file)
@@ -14,10 +14,14 @@ namespace TYPO3\CMS\Workspaces\Tests\Functional\Service;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Bootstrap;
+use TYPO3\CMS\Workspaces\Service\WorkspaceService;
+use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
+
 /**
  * Workspace service test
  */
-class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
+class WorkspaceServiceTest extends FunctionalTestCase
 {
     /**
      * @var array
@@ -31,7 +35,7 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         parent::setUp();
         $this->setUpBackendUserFromFixture(1);
-        \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
+        Bootstrap::getInstance()->initializeLanguageObject();
         $this->importDataSet(__DIR__ . '/../Fixtures/sys_workspace.xml');
     }
 
@@ -41,9 +45,9 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     public function emptyWorkspaceReturnsEmptyArray()
     {
         $this->markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         $result = $service->selectVersionsInWorkspace(90);
-        $this->assertTrue(empty($result), 'The workspace 90 contains no changes and the result was supposed to be empty');
+        $this->assertEmpty($result, 'The workspace 90 contains no changes and the result was supposed to be empty');
         $this->assertTrue(is_array($result), 'Even the empty result from workspace 90 is supposed to be an array');
     }
 
@@ -54,10 +58,14 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
         $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         $result = $service->selectVersionsInWorkspace(91, 0, -99, 2);
         $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
-        $this->assertEquals(1, count($result['pages']), 'The result is supposed to contain one version for this page in workspace 91');
+        $this->assertCount(
+            1,
+            $result['pages'],
+            'The result is supposed to contain one version for this page in workspace 91'
+        );
         $this->assertEquals(102, $result['pages'][0]['uid'], 'Wrong workspace overlay record picked');
         $this->assertEquals(1, $result['pages'][0]['livepid'], 'Real pid wasn\'t resolved correctly');
     }
@@ -69,10 +77,14 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
         $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
-        $result = $service->selectVersionsInWorkspace(\TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES, 0, -99, 2);
+        $service = new WorkspaceService();
+        $result = $service->selectVersionsInWorkspace(WorkspaceService::SELECT_ALL_WORKSPACES, 0, -99, 2);
         $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
-        $this->assertEquals(2, count($result['pages']), 'The result is supposed to contain one version for this page in workspace 91');
+        $this->assertCount(
+            2,
+            $result['pages'],
+            'The result is supposed to contain one version for this page in workspace 91'
+        );
     }
 
     /**
@@ -82,10 +94,14 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
         $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
         $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
-        $this->assertEquals(4, count($result['pages']), 'The result is supposed to contain four versions for this page in workspace 91');
+        $this->assertCount(
+            4,
+            $result['pages'],
+            'The result is supposed to contain four versions for this page in workspace 91'
+        );
     }
 
     /**
@@ -95,17 +111,25 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
         $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         // testing stage 1
         $result = $service->selectVersionsInWorkspace(91, 0, 1, 1, 99);
         $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
-        $this->assertEquals(2, count($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
+        $this->assertCount(
+            2,
+            $result['pages'],
+            'The result is supposed to contain two versions for this page in workspace 91'
+        );
         $this->assertEquals(102, $result['pages'][0]['uid'], 'First records is supposed to have the uid 102');
         $this->assertEquals(105, $result['pages'][1]['uid'], 'First records is supposed to have the uid 105');
         // testing stage 2
         $result = $service->selectVersionsInWorkspace(91, 0, 2, 1, 99);
         $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
-        $this->assertEquals(2, count($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
+        $this->assertCount(
+            2,
+            $result['pages'],
+            'The result is supposed to contain two versions for this page in workspace 91'
+        );
         $this->assertEquals(104, $result['pages'][0]['uid'], 'First records is supposed to have the uid 106');
         $this->assertEquals(106, $result['pages'][1]['uid'], 'First records is supposed to have the uid 106');
     }
@@ -117,17 +141,29 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
         $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         // testing all "draft" records
         $result = $service->selectVersionsInWorkspace(91, 1, -99, 1, 99);
         $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
-        $this->assertEquals(2, count($result['pages']), 'The result is supposed to contain three versions for this page in workspace 91');
+        $this->assertCount(
+            2,
+            $result['pages'],
+            'The result is supposed to contain three versions for this page in workspace 91'
+        );
         // testing all "archive" records
         $result = $service->selectVersionsInWorkspace(91, 2, -99, 1, 99);
-        $this->assertEquals(2, count($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
+        $this->assertCount(
+            2,
+            $result['pages'],
+            'The result is supposed to contain two versions for this page in workspace 91'
+        );
         // testing both types records
         $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
-        $this->assertEquals(4, count($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
+        $this->assertCount(
+            4,
+            $result['pages'],
+            'The result is supposed to contain two versions for this page in workspace 91'
+        );
     }
 
     /**
@@ -141,10 +177,18 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
         $this->markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
         $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
         // Test if the placeholder can be found when we ask using recursion (same result)
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         $result = $service->selectVersionsInWorkspace(91, 0, -99, 2, 99);
-        $this->assertEquals(0, count($result['pages']), 'Changes should not show up in this branch of the tree within workspace 91');
-        $this->assertEquals(0, count($result['tt_content']), 'Changes should not show up in this branch of the tree within workspace 91');
+        $this->assertCount(
+            0,
+            $result['pages'],
+            'Changes should not show up in this branch of the tree within workspace 91'
+        );
+        $this->assertCount(
+            0,
+            $result['tt_content'],
+            'Changes should not show up in this branch of the tree within workspace 91'
+        );
     }
 
     /**
@@ -154,13 +198,13 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
         // Test if the placeholder can be found when we ask using recursion (same result)
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         $result = $service->selectVersionsInWorkspace(91, 0, -99, 5, 99);
-        $this->assertEquals(1, count($result['pages']), 'Wrong amount of page versions found within workspace 91');
+        $this->assertCount(1, $result['pages'], 'Wrong amount of page versions found within workspace 91');
         $this->assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
         $this->assertEquals(5, $result['pages'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
         $this->assertEquals(2, $result['pages'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
-        $this->assertEquals(1, count($result['tt_content']), 'Wrong amount of tt_content versions found within workspace 91');
+        $this->assertCount(1, $result['tt_content'], 'Wrong amount of tt_content versions found within workspace 91');
         $this->assertEquals(106, $result['tt_content'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
         $this->assertEquals(7, $result['tt_content'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
         $this->assertEquals(2, $result['tt_content'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
@@ -173,10 +217,57 @@ class WorkspaceServiceTest extends \TYPO3\TestingFramework\Core\Functional\Funct
     {
         $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
         // Test if the placeholder can be found when we ask using recursion (same result)
-        $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
+        $service = new WorkspaceService();
         $result = $service->selectVersionsInWorkspace(91, 0, -99, 3, 99);
-        $this->assertEquals(1, count($result), 'Wrong amount of versions found within workspace 91');
-        $this->assertEquals(1, count($result['pages']), 'Wrong amount of page versions found within workspace 91');
+        $this->assertCount(1, $result, 'Wrong amount of versions found within workspace 91');
+        $this->assertCount(1, $result['pages'], 'Wrong amount of page versions found within workspace 91');
         $this->assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
     }
+
+    /**
+     * @test
+     */
+    public function getPagesWithVersionsInTableReturnsPagesWithVersionsInTable()
+    {
+        $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
+        $workspaceService = new WorkspaceService();
+        $result = $workspaceService->getPagesWithVersionsInTable(91);
+        $expected = [
+            'sys_category' => [],
+            'sys_collection' => [],
+            'sys_file_collection' => [],
+            'sys_file_metadata' => [],
+            'sys_file_reference' => [],
+            'backend_layout' => [],
+            'pages_language_overlay' => [],
+            'sys_template' => [],
+            'tt_content' => [
+                1 => true,
+                7 => true,
+            ]
+        ];
+        self::assertSame($expected, $result);
+    }
+
+    /**
+     * @test
+     */
+    public function hasPageRecordVersionsReturnsTrueForPageWithVersions()
+    {
+        $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
+        $workspaceService = new WorkspaceService();
+        $result = $workspaceService->hasPageRecordVersions(91, 7);
+        self::assertTrue($result);
+    }
+
+    /**
+     * @test
+     */
+    public function hasPageRecordVersionsReturnsFalseForPageWithoutVersions()
+    {
+        $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
+        $workspaceService = new WorkspaceService();
+        $result = $workspaceService->hasPageRecordVersions(91, 3);
+        self::assertFalse($result);
+    }
 }