[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Tests / Functional / ActionHandler / ActionHandlerTest.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Tests\Functional\ActionHandler;
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\CMS\Backend\Utility\BackendUtility;
18
19 /**
20 * Action handler test
21 */
22 class ActionHandlerTest extends \TYPO3\CMS\Components\TestingFramework\Core\FunctionalTestCase
23 {
24 protected $coreExtensionsToLoad = ['version', 'workspaces'];
25
26 /**
27 * Set up
28 *
29 * @return void
30 */
31 protected function setUp()
32 {
33 parent::setUp();
34 $this->setUpBackendUserFromFixture(1);
35 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
36 }
37
38 /**
39 * @test
40 */
41 public function sendToSpecificStageExecuteIgnoresDoublePublishes()
42 {
43 $actionHandler = new \TYPO3\CMS\Workspaces\Controller\Remote\ActionHandler();
44
45 $this->importDataSet(__DIR__ . '/Fixtures/pages.xml');
46 $this->importDataSet(__DIR__ . '/Fixtures/sys_workspace.xml');
47 $this->importDataSet(__DIR__ . '/Fixtures/tt_content.xml');
48
49 // Prepare parameter
50 $parameter = new \stdClass();
51 $parameter->additional = '';
52 $parameter->recipients = [];
53 $parameter->comments = '';
54
55 // Send to LIVE
56 $parameter->affects = new \stdClass();
57 $parameter->affects->nextStage = -20;
58 $parameter->affects->elements = [];
59
60 // First and only affected element
61 $elementOne = new \stdClass();
62 $elementOne->table = 'tt_content';
63 $elementOne->uid = 2;
64 $elementOne->t3ver_oid = 1;
65 $parameter->affects->elements[] = $elementOne;
66
67 $recordBeforePublish = BackendUtility::getRecord('tt_content', 2);
68 $this->assertEquals($recordBeforePublish['header'], 'Workspace version of original content');
69
70 // First publish
71 $result = $actionHandler->sendToSpecificStageExecute($parameter);
72 $this->assertTrue($result['success']);
73 $recordAfterFirstPublish = BackendUtility::getRecord('tt_content', 2);
74
75 $this->assertEquals($recordAfterFirstPublish['t3ver_wsid'], 0);
76 $this->assertEquals($recordAfterFirstPublish['header'], 'Original content');
77
78 // Second publish
79 $result = $actionHandler->sendToSpecificStageExecute($parameter);
80 $this->assertTrue($result['success']);
81 $recordAfterSecondPublish = BackendUtility::getRecord('tt_content', 2);
82
83 // In case of an error, this will again be "Workspace version of original content"
84 $this->assertEquals($recordAfterSecondPublish['t3ver_wsid'], 0);
85 $this->assertEquals($recordAfterSecondPublish['header'], 'Original content');
86 }
87 }