Skip to content

Instantly share code, notes, and snippets.

@andreaswolf
Created July 1, 2014 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreaswolf/524ccdf5febae59fc147 to your computer and use it in GitHub Desktop.
Save andreaswolf/524ccdf5febae59fc147 to your computer and use it in GitHub Desktop.
Flux functional tests
<?php
namespace FluidTYPO3\Flux\Tests\Functional\Service;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
require_once 'typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php';
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase;
use TYPO3\CMS\Core\Tests\FunctionalTestCase;
/**
*
*
* @author Andreas Wolf <aw@foundata.net>
*/
class ContentServiceTest extends AbstractDataHandlerActionTestCase {
/**
* @var array
*/
protected $testExtensionsToLoad = array('typo3conf/ext/flux');
protected $scenarioDataSetDirectory = 'typo3conf/ext/flux/Tests/Functional/Service/DataSet/';
const PAGE_ID = 100;
const FLUIDCONTENT_CONTAINER_ID = 200;
const FLUIDCONTENT_CONTENT_ID = 201;
const CONTENT_ID = 202;
public function setUp() {
parent::setUp();
$this->importScenarioDataSet('DefaultElements');
$this->setUpFrontendRootPage(self::PAGE_ID, array('typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts'));
}
/**
* @param string $table The table to paste the contents in
* @param int $targetPageId The target page id.
* @param int $relatedContentId The ID of the related element (= the element to paste after). If 0, element is inserted at the top of the column.
* @param int $parentUid The ID of the parent (Flux) element to insert to.
* @param string $targetArea The area in the parent element the new element should be inserted to.
* @param string|int $targetColumn The target column. Is only used if parent uid/target area are not set (?)
*/
protected function createGetEntryForClipboardPasteOperation($table, $targetPageId, $relatedContentId = 0, $parentUid = 0, $targetArea = '', $targetColumn = 0) {
$_GET['CB'] = array(
'paste' => $table . '|' . $targetPageId . '-paste-' . $relatedContentId . '-' . $parentUid . '-' . $targetArea . '-' . $targetColumn,
);
}
/**
* @test
*/
public function copyFromInsideFluidcontentElementToPageAfterFluidcontentElement() {
$this->createGetEntryForClipboardPasteOperation('tt_content', self::PAGE_ID, self::FLUIDCONTENT_CONTAINER_ID);
$mappingArray = $this->actionService->copyRecord('tt_content', self::FLUIDCONTENT_CONTENT_ID, self::PAGE_ID);
$newContentId = $mappingArray['tt_content'][self::FLUIDCONTENT_CONTENT_ID];
$this->assertNotEmpty($newContentId);
$newRecord = BackendUtility::getRecord('tt_content', $newContentId);
// TODO assert correct sorting
$this->assertEquals(0, $newRecord['colPos'], 'New content in wrong page column');
$this->assertSame('0', $newRecord['tx_flux_parent'], 'New content still in Flux container');
$this->assertSame('', $newRecord['tx_flux_column'], 'New content in wrong Flux column');
}
/**
* @test
*/
public function copyFromInsideFluidcontentElementToDifferentColumnInFluidcontentElement() {
$this->createGetEntryForClipboardPasteOperation('tt_content', self::PAGE_ID, 0, self::FLUIDCONTENT_CONTAINER_ID, 'column2');
$mappingArray = $this->actionService->copyRecord('tt_content', self::FLUIDCONTENT_CONTENT_ID, self::PAGE_ID);
$newContentId = $mappingArray['tt_content'][self::FLUIDCONTENT_CONTENT_ID];
$this->assertGreaterThan(0, $newContentId);
$newRecord = BackendUtility::getRecord('tt_content', $newContentId);
$this->assertEquals(18181, $newRecord['colPos'], 'New content in wrong page column');
$this->assertEquals(self::FLUIDCONTENT_CONTAINER_ID, $newRecord['tx_flux_parent'], 'New content not in Flux container');
$this->assertSame('column2', $newRecord['tx_flux_column'], 'New content in wrong Flux column');
}
/**
* @test
*/
public function copyFromPageToColumnInFluidcontentElement() {
$this->createGetEntryForClipboardPasteOperation('tt_content', self::PAGE_ID, 0, self::FLUIDCONTENT_CONTAINER_ID, 'column1');
$mappingArray = $this->actionService->copyRecord('tt_content', self::CONTENT_ID, self::PAGE_ID);
$newContentId = $mappingArray['tt_content'][self::CONTENT_ID];
$this->assertGreaterThan(0, $newContentId);
$newRecord = BackendUtility::getRecord('tt_content', $newContentId);
$this->assertEquals(18181, $newRecord['colPos'], 'New content in wrong page column');
$this->assertEquals(self::FLUIDCONTENT_CONTAINER_ID, $newRecord['tx_flux_parent'], 'New content not in Flux container');
$this->assertSame('column1', $newRecord['tx_flux_column'], 'New content in wrong Flux column');
}
/**
* @test
*/
public function copyFromPageToAfterElementInFluidcontentElement() {
$this->createGetEntryForClipboardPasteOperation('tt_content', self::PAGE_ID, self::FLUIDCONTENT_CONTENT_ID);
$mappingArray = $this->actionService->copyRecord('tt_content', self::CONTENT_ID, 0 - self::FLUIDCONTENT_CONTENT_ID);
$newContentId = $mappingArray['tt_content'][self::CONTENT_ID];
$this->assertNotEmpty($newContentId);
$newRecord = BackendUtility::getRecord('tt_content', $newContentId);
$this->assertEquals(18181, $newRecord['colPos'], 'New content in wrong page column');
$this->assertEquals(self::FLUIDCONTENT_CONTAINER_ID, $newRecord['tx_flux_parent'], 'New content not in Flux container');
$this->assertSame('headline', $newRecord['tx_flux_column'], 'New content in wrong Flux column');
}
}
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 3. in line 1.
"pages",
,"uid","pid"
,"100","0"
"tt_content",
,"uid","pid","CType","sorting","colPos","header","tx_flux_column","tx_flux_parent"
,"200","100","fluidcontent_content","128","0","fluidcontent element","","0"
,"201","100","text","256","18181","text element in fluidcontent","headline","200"
,"202","100","text","512","0","text element on page after content","","0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment