Skip to content

Commit

Permalink
[TASK] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Sep 22, 2020
1 parent 9cbaa43 commit 1f7ae6f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/Build/Local/report
/Build/Local/.phpunit.result.cache
/Documentation-GENERATED-temp
/tempfile.sh
/out.txt
6 changes: 3 additions & 3 deletions Classes/Hooks/PageLayoutViewHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ protected function enrichRow(array $row): array
$records = $this->getRecords($fieldConfiguration['table'], $settings['settings'][$fieldName]);

if ($fieldConfiguration['multiValue']) {
$row['_extended'][$fieldName] = $records;
$row['_computed'][$fieldName] = $records;
} else {
$row['_extended'][$fieldName] = $records[0] ?: [];
$row['_computed'][$fieldName] = $records[0] ?: [];
}
}
}
$row['_extended']['lll'] = 'LLL:EXT:tt_address/Resources/Private/Language/ff/locallang_ff.xlf:';
$row['_computed']['lll'] = 'LLL:EXT:tt_address/Resources/Private/Language/ff/locallang_ff.xlf:';
return $row;
}

Expand Down
38 changes: 19 additions & 19 deletions Resources/Private/Templates/Backend/PluginPreview.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@
<tbody>
<f:if condition="{flex.displayMode}">
<tr>
<th>{f:translate(key:'{_extended.lll}pi1_flexform.displayMode')}</th>
<th>{f:translate(key:'{_computed.lll}pi1_flexform.displayMode')}</th>
<td>
<f:switch expression="{flex.displayMode}">
<f:case value="list">{f:translate(key:'{_extended.lll}pi1_flexform.displayMode.listView')}</f:case>
<f:case value="single">{f:translate(key:'{_extended.lll}pi1_flexform.displayMode.singleView')}
<f:case value="list">{f:translate(key:'{_computed.lll}pi1_flexform.displayMode.listView')}</f:case>
<f:case value="single">{f:translate(key:'{_computed.lll}pi1_flexform.displayMode.singleView')}
</f:case>
<f:case value="map">{f:translate(key:'{_extended.lll}pi1_flexform.displayMode.map')}</f:case>
<f:case value="map">{f:translate(key:'{_computed.lll}pi1_flexform.displayMode.map')}</f:case>
<f:defaultCase>{flex.displayMode}</f:defaultCase>
</f:switch>
</td>
</tr>
</f:if>
<f:if condition="{_extended.singleRecords}">
<f:if condition="{_computed.singleRecords}">
<tr>
<th>{f:translate(key:'{_extended.lll}pi1_flexform.single_records')}</th>
<th>{f:translate(key:'{_computed.lll}pi1_flexform.single_records')}</th>
<td>
<f:for each="{_extended.singleRecords}" as="row">
<f:for each="{_computed.singleRecords}" as="row">
<f:render section="rowElement" arguments="{table:'tt_address', row:row}"/>
</f:for>
</td>
</tr>
</f:if>
<f:if condition="{_extended.pages}">
<f:if condition="{_computed.pages}">
<tr>
<th>{f:translate(key:'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.startingpoint')}
</th>
<td>
<f:for each="{_extended.pages}" as="row">
<f:for each="{_computed.pages}" as="row">
<f:render section="rowElement" arguments="{table:'pages', row:row}"/>
</f:for>
<f:if condition="{flex.recursive}">
Expand All @@ -50,34 +50,34 @@
</td>
</tr>
</f:if>
<f:if condition="{_extended.singlePid}">
<f:if condition="{_computed.singlePid}">
<tr>
<th>{f:translate(key:'{_extended.lll}pi1_flexform.singlePid')}</th>
<th>{f:translate(key:'{_computed.lll}pi1_flexform.singlePid')}</th>
<td>
<f:render section="rowElement" arguments="{table:'pages', row:_extended.singlePid}"/>
<f:render section="rowElement" arguments="{table:'pages', row:_computed.singlePid}"/>
</td>
</tr>
</f:if>
<f:if condition="{_extended.groups}">
<f:if condition="{_computed.groups}">
<tr>
<th>{f:translate(key:'{_extended.lll}pi1_flexform.group_selection')}</th>
<th>{f:translate(key:'{_computed.lll}pi1_flexform.group_selection')}</th>
<td>
<f:for each="{_extended.groups}" as="row">
<f:for each="{_computed.groups}" as="row">
<f:render section="rowElement" arguments="{table:'sys_category', row:row}"/>
</f:for>
<hr style="margin:1px"/>
<f:if condition="{flex.includeSubcategories}">
<core:icon identifier="actions-check" size="small"/>
{f:translate(key:'{_extended.lll}pi1_flexform.includeSubcategories')}<br>
{f:translate(key:'{_computed.lll}pi1_flexform.includeSubcategories')}<br>
</f:if>
<core:icon identifier="actions-viewmode-photos" size="small"/>
{f:translate(key:'{_extended.lll}pi1_flexform.combination')}:
{f:translate(key:'{_computed.lll}pi1_flexform.combination')}:
<f:if condition="{flex.groupsCombination}">
<f:then>
{f:translate(key:'{_extended.lll}pi1_flexform.combination.or')}<br>
{f:translate(key:'{_computed.lll}pi1_flexform.combination.or')}<br>
</f:then>
<f:else>
{f:translate(key:'{_extended.lll}pi1_flexform.combination.and')}<br>
{f:translate(key:'{_computed.lll}pi1_flexform.combination.and')}<br>
</f:else>
</f:if>
</td>
Expand Down
13 changes: 13 additions & 0 deletions Tests/Functional/Fixtures/pages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<pages>
<uid>7</uid>
<pid>1</pid>
<title>Storage</title>
</pages>
<pages>
<uid>9</uid>
<pid>1</pid>
<title>Single Pid</title>
</pages>
</dataset>
70 changes: 68 additions & 2 deletions Tests/Functional/Fixtures/tt_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
</T3FlexForms>
]]>
</pi_flexform>
</tt_content> <tt_content>
</tt_content>
<tt_content>
<uid>3</uid>
<pid>1</pid>
<list_type>tt_address_pi1</list_type>
Expand All @@ -105,4 +106,69 @@
]]>
</pi_flexform>
</tt_content>
</dataset>
<tt_content>
<uid>4</uid>
<pid>1</pid>
<CType>list</CType>
<list_type>ttaddress_listview</list_type>
<pi_flexform>
<![CDATA[
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3FlexForms>
<data>
<sheet index="sDEF">
<language index="lDEF">
<field index="settings.singleRecords">
<value index="vDEF">2,1</value>
</field>
<field index="settings.groups">
<value index="vDEF">1,2</value>
</field>
<field index="settings.includeSubcategories">
<value index="vDEF">1</value>
</field>
<field index="settings.groupsCombination">
<value index="vDEF">1</value>
</field>
<field index="settings.sortBy">
<value index="vDEF">singleSelection</value>
</field>
<field index="settings.sortOrder">
<value index="vDEF">ASC</value>
</field>
<field index="settings.pages">
<value index="vDEF">7</value>
</field>
<field index="settings.recursive">
<value index="vDEF">3</value>
</field>
<field index="settings.ignoreWithoutCoordinates">
<value index="vDEF">1</value>
</field>
<field index="settings.allowOverride">
<value index="vDEF">1</value>
</field>
</language>
</sheet>
<sheet index="sDISPLAY">
<language index="lDEF">
<field index="settings.displayMode">
<value index="vDEF">list</value>
</field>
<field index="settings.hidePagination">
<value index="vDEF">1</value>
</field>
<field index="settings.paginate.itemsPerPage">
<value index="vDEF">10</value>
</field>
<field index="settings.singlePid">
<value index="vDEF">9</value>
</field>
</language>
</sheet>
</data>
</T3FlexForms>
]]>
</pi_flexform>
</tt_content>
</dataset>
56 changes: 56 additions & 0 deletions Tests/Functional/Hooks/PageLayoutViewHookTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace FriendsOfTYPO3\TtAddress\Tests\Functional\Hooks;

/**
* This file is part of the "tt_address" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use FriendsOfTYPO3\TtAddress\Hooks\PageLayoutViewHook;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class PageLayoutViewHookTest extends FunctionalTestCase
{
protected $testExtensionsToLoad = ['typo3conf/ext/tt_address'];

public function setUp()
{
parent::setUp();

$this->importDataSet(__DIR__ . '/../Fixtures/tt_address.xml');
$this->importDataSet(__DIR__ . '/../Fixtures/tt_content.xml');
$this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
}

/**
* @test
*/
public function previewRowIsEnriched(): void
{
$languageService = $this->getAccessibleMock(LanguageService::class, ['sl'], [], '', false, false);
$languageService->expects($this->any())->method('sl')->willReturn('dummy label');

$GLOBALS['LANG'] = $languageService;

$pageLayoutViewMock = $this->getAccessibleMock(PageLayoutView::class, ['dummy'], [], '', false);
$drawItem = true;
$headerContent = 'header';
$itemContent = 'item';
$row = BackendUtility::getRecord('tt_content', 4);
$subject = new PageLayoutViewHook();
$subject->preProcess($pageLayoutViewMock, $drawItem, $headerContent, $itemContent, $row);

$this->assertEquals('John', $row['_computed']['singleRecords'][0]['first_name']);
$this->assertEquals('Jane', $row['_computed']['singleRecords'][1]['first_name']);
$this->assertEquals('Madrid', $row['_computed']['groups'][0]['title']);
$this->assertEquals('Kiev', $row['_computed']['groups'][1]['title']);
$this->assertEquals('Storage', $row['_computed']['pages'][0]['title']);
$this->assertEquals('Single Pid', $row['_computed']['singlePid']['title']);
}
}

0 comments on commit 1f7ae6f

Please sign in to comment.