Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
[TASK] Add functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Apr 7, 2020
1 parent 0d2c979 commit 2423912
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/phpunit.xml
/var
.phpunit.result.cache
.ddev
config
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ php:
- 7.3
- 7.4

services:
- mysql

env:
- TYPO3_VERSION="^9.5.0"
- TYPO3_VERSION="^10.2.0"
Expand All @@ -28,6 +31,7 @@ before_install:
- composer self-update
- composer --version
- phpenv config-rm xdebug.ini || return 0
- npm install -g mjml

before_script:
- composer require typo3/minimal=$TYPO3_VERSION
Expand All @@ -53,3 +57,11 @@ script:
echo;
echo "Running php lint";
find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;
- >
echo;
export typo3DatabaseName="typo3";
export typo3DatabaseHost="localhost";
export typo3DatabaseUsername="root";
export typo3DatabasePassword="";
find 'Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; .Build/bin/phpunit --colors -c .Tests/Build/FunctionalTests.xml {}'
49 changes: 30 additions & 19 deletions Classes/Renderer/BinaryRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use RuntimeException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

final class BinaryRenderer implements RendererInterface
{
Expand All @@ -30,28 +32,37 @@ final class BinaryRenderer implements RendererInterface

public function __construct(string $bin)
{
$this->bin = $bin;
$this->bin = trim($bin);
}

public function render(string $content): string
{
$arguments = [
$this->bin,
'-i',
'-s',
'--config.validationLevel',
'--config.minify',
];

$process = new Process($arguments);
$process->setInput($content);

try {
$process->mustRun();
} catch (ProcessFailedException $e) {
throw new RuntimeException('Unable to compile MJML. Stack error: ' . $e->getMessage());
}

return $process->getOutput();
$temporaryFile = GeneralUtility::tempnam('mjml_', '.mjml');

GeneralUtility::writeFileToTypo3tempDir($temporaryFile, $content);

$cmd = $this->bin;
$args = $temporaryFile.' '.'-s --config.beautify true --config.minify true';

$result = [];
$returnValue = '';

CommandUtility::exec($this->getEscapedCommand($cmd, $args), $result, $returnValue);

GeneralUtility::unlink_tempfile($temporaryFile);

return implode('', $result);
}

private function getEscapedCommand(string $cmd, string $args): string
{
$escapedCmd = escapeshellcmd($cmd);

$argsArray = explode(' ', $args);
$escapedArgsArray = CommandUtility::escapeShellArguments($argsArray);
$escapedArgs = implode(' ', $escapedArgsArray);

return $escapedCmd.' '.$escapedArgs;
}
}

10 changes: 10 additions & 0 deletions Classes/ViewHelpers/MjmlToHtmlViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
*/
class MjmlToHtmlViewHelper extends AbstractViewHelper
{
/**
* @var bool
*/
protected $escapeChildren = false;

/**
* @var bool
*/
protected $escapeOutput = false;

/**
* @var RendererInterface
*/
Expand Down
Binary file removed Resources/Public/Icons/Extension.png
Binary file not shown.
28 changes: 28 additions & 0 deletions Resources/Public/Icons/Extension.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Tests/Build/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false"
>
<testsuites>
<testsuite name="typo3_mjml tests">
<directory>../Functional/</directory>
</testsuite>
</testsuites>
</phpunit>
80 changes: 80 additions & 0 deletions Tests/Functional/ConvertMjmlToHtmlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);


namespace Ssch\Typo3Mjml\Tests\Functional;

/*
* 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!
*/

use Doctrine\DBAL\DBALException;
use TYPO3\TestingFramework\Core\Exception;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class ConvertMjmlToHtmlTest extends FunctionalTestCase
{
private const ROOT_PAGE_UID = 1;

/**
* @var string[]
*/
protected $testExtensionsToLoad = [
'typo3conf/ext/typo3_mjml',
];

/**
* @var string[]
*/
protected $coreExtensionsToLoad = ['fluid'];

/**
* @var array
*/
protected $configurationToUseInTestInstance = [
'EXTENSIONS' => [
'typo3_mjml' => [
'type' => 'binary',
'binary_path' => 'mjml'
],
],
];


/**
* @throws DBALException
* @throws Exception
*/
protected function setUp(): void
{
parent::setUp();
$this->importDataSet(__DIR__ . '/Fixtures/Database/pages.xml');
$this->setUpFrontendRootPage(1, ['EXT:typo3_mjml/Tests/Functional/Fixtures/Frontend/Basic.typoscript']);
}

/**
* @test
*/
public function convertToHtml(): void
{
$result = $this->retrieveFrontendRequestResult(
(new InternalRequest())->withPageId(self::ROOT_PAGE_UID),
(new InternalRequestContext()),
false
);
$response = $this->reconstituteFrontendRequestResult($result);

$this->assertStringContainsString($response->getBody()->getContents(),file_get_contents( __DIR__ . '/Fixtures/converted.html'));
}
}
10 changes: 10 additions & 0 deletions Tests/Functional/Fixtures/Database/pages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<pages>
<uid>1</uid>
<pid>0</pid>
<title>Root</title>
<deleted>0</deleted>
<perms_everybody>15</perms_everybody>
</pages>
</dataset>
31 changes: 31 additions & 0 deletions Tests/Functional/Fixtures/Frontend/Basic.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
config {
no_cache = 1
debug = 0
xhtml_cleaning = 0
admPanel = 0
disableAllHeaderCode = 1
sendCacheHeaders = 0
sys_language_uid = 0
sys_language_mode = ignore
sys_language_overlay = 1
absRefPrefix = /
linkVars = L
contentObjectExceptionHandler = 0

spamProtectEmailAddresses = 2
spamProtectEmailAddresses_atSubst = (AT)
spamProtectEmailAddresses_lastDotSubst = (DOT)

intTarget = _blank
}

page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
templateName = Default
templateRootPaths {
20 = EXT:typo3_mjml/Tests/Functional/Fixtures/Frontend/
}
}
}
41 changes: 41 additions & 0 deletions Tests/Functional/Fixtures/Frontend/Default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:m="http://typo3.org/ns/Ssch/Typo3Mjml/ViewHelpers" data-namespace-typo3-fluid="true">
<m:mjmlToHtml>
<mjml>
<mj-body background-color="#F4F4F4" color="#55575d" font-family="Arial, sans-serif">
<mj-section background-color="#000000" background-repeat="no-repeat" text-align="center" vertical-align="top">
<mj-column>
<mj-image align="center" border="none" padding-bottom="30px" padding="10px 25px" src="http://5vph.mj.am/img/5vph/b/1g86w/0g67t.png" target="_blank" title="" width="180px"></mj-image>
<mj-text align="left" color="#55575d" font-family="Arial, sans-serif" font-size="13px" line-height="22px" padding-bottom="0px" padding-top="0px" padding="10px 25px">
<p style="line-height: 18px; margin: 10px 0; text-align: center;font-size:14px;color:#ffffff;font-family:'Times New Roman',Helvetica,Arial,sans-serif">WOMEN&nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; MEN&nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; KIDS</p>
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#000000" background-repeat="no-repeat" text-align="center" vertical-align="top" padding="0 0 0 0">
<mj-column>
<mj-image align="center" border="none" padding-bottom="0px" padding-left="0px" padding-right="0px" padding="0px 25px" src="http://5vph.mj.am/img/5vph/b/1g86w/0696u.jpeg" target="_blank" title="" width="780px"></mj-image>
</mj-column>
</mj-section>
<mj-section background-color="#000000" background-repeat="no-repeat" text-align="center" vertical-align="top" padding="0 0 0 0">
<mj-column>
<mj-text align="left" color="#55575d" font-family="Arial, sans-serif" font-size="13px" line-height="22px" padding-bottom="5px" padding-top="25px" padding="10px 25px">
<p style="line-height: 60px; text-align: center; margin: 10px 0;font-size:55px;color:#fcfcfc;font-family:'Times New Roman',Helvetica,Arial,sans-serif">
<b>Black Friday</b>
</p>
</mj-text>
<mj-text align="left" color="#55575d" font-family="Arial, sans-serif" font-size="13px" line-height="22px" padding-bottom="20px" padding-top="0px" padding="10px 25px">
<p style="line-height: 30px; text-align: center; margin: 10px 0;color:#f5f5f5;font-size:25px;font-family:'Times New Roman',Helvetica,Arial,sans-serif"><b>Take an&nbsp; extra 50% off</b><br/><span style="color:#ffffff;font-size:18px;font-family:'Times New Roman',Helvetica,Arial,sans-serif">Use code SALEONSALE* at checkout</span></p>
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#000000" background-repeat="no-repeat" text-align="center" vertical-align="top" padding-bottom="40px" padding="0 0 0 0">
<mj-column>
<mj-button background-color="#ffffff" border-radius="3px" font-family="Times New Roman, Helvetica, Arial, sans-serif" font-size="18px" font-weight="normal" inner-padding="10px 25px" padding-bottom="30px" padding="10px 25px"><span style="color:#212020">Shop Now</span></mj-button>
<mj-text align="left" color="#55575d" font-family="Arial, sans-serif" font-size="13px" line-height="22px" padding-bottom="0px" padding-top="5px" padding="10px 25px">
<p style="line-height: 16px; text-align: center; margin: 10px 0;font-size:12px;color:#ffffff;font-family:'Times New Roman',Helvetica,Arial,sans-serif">* Offer valid on Allura purchases on 17/29/11 at 11:59 pm. No price adjustments on previous&nbsp;<br/><span style="color:#ffffff;font-family:'Times New Roman',Helvetica,Arial,sans-serif">purchases, offer limited to stock. Cannot be combined with any offer or promotion other than free.</span></p>
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
</m:mjmlToHtml>
</html>
Loading

0 comments on commit 2423912

Please sign in to comment.