2017-12-14 23:26:39 +01:00
< ? php
namespace Saccas\Mjml\Tests\Functional\Domain\Renderer ;
use Saccas\Mjml\Domain\Renderer\Command ;
use Saccas\Mjml\Tests\Unit\AbstractUnitTestCase ;
2018-06-13 10:28:05 +02:00
use TYPO3\CMS\Core\Package\Package ;
use TYPO3\CMS\Core\Package\PackageManager ;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility ;
2017-12-14 23:26:39 +01:00
use TYPO3\CMS\Core\Utility\GeneralUtility ;
use TYPO3\CMS\Extbase\Object\ObjectManager ;
class CommandTest extends AbstractUnitTestCase
{
2021-01-26 10:15:06 +01:00
protected ObjectManager $objectManager ;
2017-12-14 23:26:39 +01:00
2021-01-26 10:15:06 +01:00
public function setUp () : void
2017-12-14 23:26:39 +01:00
{
parent :: setUp ();
$this -> objectManager = GeneralUtility :: makeInstance ( ObjectManager :: class );
}
/**
* @ test
*/
2021-01-26 10:15:06 +01:00
public function htmlIsReturnedForMjml () : void
2017-12-14 23:26:39 +01:00
{
2018-06-13 10:28:05 +02:00
// Mock extension to be active, to enable path fetching to call node binary.
$packageMock = $this -> getMockBuilder ( Package :: class )
-> disableOriginalConstructor ()
-> getMock ();
$packageMock -> expects ( $this -> any ())
-> method ( 'getPackagePath' )
2020-01-24 11:21:16 +01:00
-> willReturn ( dirname ( __FILE__ , 5 ) . '/' );
2018-06-13 10:28:05 +02:00
$packageManagerMock = $this -> getMockBuilder ( PackageManager :: class ) -> getMock ();
$packageManagerMock -> expects ( $this -> any ())
-> method ( 'isPackageActive' )
-> with ( 'mjml' )
-> willReturn ( true );
$packageManagerMock -> expects ( $this -> any ())
-> method ( 'getPackage' )
-> with ( 'mjml' )
-> willReturn ( $packageMock );
ExtensionManagementUtility :: setPackageManager ( $packageManagerMock );
2017-12-14 23:26:39 +01:00
$GLOBALS [ 'TYPO3_CONF_VARS' ][ 'EXT' ][ 'extConf' ][ 'mjml' ] = serialize ([
'nodeBinaryPath' => 'node' ,
2018-06-13 10:28:05 +02:00
'mjmlBinaryPath' => 'node_modules/mjml/bin/' ,
2017-12-14 23:26:39 +01:00
'mjmlBinary' => 'mjml' ,
2018-06-13 10:28:05 +02:00
'mjmlParams' => '-s --config.beautify true --config.minify true' ,
2017-12-14 23:26:39 +01:00
]);
$subject = $this -> objectManager -> get ( Command :: class );
2020-01-24 11:21:16 +01:00
$mjml = file_get_contents ( __DIR__ . '/CommandTestFixture/Basic.mjml' );
$html = $subject -> getHtmlFromMjml ( $mjml );
2018-06-13 10:28:05 +02:00
// remove comment rendered by the outputToConsole https://github.com/mjmlio/mjml/blob/50b08513b7a651c234829abfde254f106a62c859/packages/mjml-cli/src/commands/outputToConsole.js#L4
$html = preg_replace ( '/<!-- FILE: (.*)-->/Uis' , '' , $html );
$this -> assertStringEqualsFile (
2020-01-24 11:21:16 +01:00
__DIR__ . '/CommandTestFixture/Expected.html' ,
2017-12-14 23:26:39 +01:00
$html ,
'Command renderer did not return expected HTML.'
);
}
}