add tests for renderers
This commit is contained in:
bovenliggende
5fda1baecb
commit
61827e7825
@ -27,10 +27,19 @@ class Pretty implements RendererInterface
|
||||
*/
|
||||
public function getContent($rows, $fieldNames) : string
|
||||
{
|
||||
$renderer = oxNew(ArrayToTextTable::class, $rows);
|
||||
$renderer = $this->getArrayToTextTableInstance($rows);
|
||||
return $renderer->getTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rows
|
||||
* @return ArrayToTextTable
|
||||
*/
|
||||
public function getArrayToTextTableInstance($rows)
|
||||
{
|
||||
return oxNew(ArrayToTextTable::class, $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/" tests="24" assertions="56" errors="0" warnings="0" failures="0" skipped="0" time="0.929913">
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" tests="12" assertions="28" errors="0" warnings="0" failures="0" skipped="0" time="0.546801">
|
||||
<testcase name="canGetGroups" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="45" assertions="2" time="0.197758"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest::canGetGroupTasks" tests="2" assertions="4" errors="0" warnings="0" failures="0" skipped="0" time="0.053800">
|
||||
<testcase name="canGetGroupTasks with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="71" assertions="2" time="0.022952"/>
|
||||
<testcase name="canGetGroupTasks with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="71" assertions="2" time="0.030848"/>
|
||||
</testsuite>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest::executePass" tests="2" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.060701">
|
||||
<testcase name="executePass with data set "no debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="109" assertions="4" time="0.030058"/>
|
||||
<testcase name="executePass with data set "debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="109" assertions="5" time="0.030643"/>
|
||||
</testsuite>
|
||||
<testcase name="testConstructor" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="53" assertions="1" time="0.030605"/>
|
||||
<testcase name="runTaskPass" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="76" assertions="1" time="0.031500"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest::runTaskFailed" tests="3" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.117398">
|
||||
<testcase name="runTaskFailed with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="99" assertions="3" time="0.044769"/>
|
||||
<testcase name="runTaskFailed with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="99" assertions="3" time="0.035974"/>
|
||||
<testcase name="runTaskFailed with data set #2" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="99" assertions="3" time="0.036655"/>
|
||||
</testsuite>
|
||||
<testcase name="canGetUserMessages" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="214" assertions="1" time="0.021711"/>
|
||||
<testcase name="canGetHelpUrl" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="229" assertions="1" time="0.033328"/>
|
||||
</testsuite>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" tests="12" assertions="28" errors="0" warnings="0" failures="0" skipped="0" time="0.383112">
|
||||
<testcase name="canGetGroups" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="47" assertions="2" time="0.033427"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest::canGetGroupTasks" tests="2" assertions="4" errors="0" warnings="0" failures="0" skipped="0" time="0.061498">
|
||||
<testcase name="canGetGroupTasks with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="73" assertions="2" time="0.030485"/>
|
||||
<testcase name="canGetGroupTasks with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="73" assertions="2" time="0.031013"/>
|
||||
</testsuite>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest::executePass" tests="2" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.063269">
|
||||
<testcase name="executePass with data set "no debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="111" assertions="4" time="0.032721"/>
|
||||
<testcase name="executePass with data set "debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="111" assertions="5" time="0.030548"/>
|
||||
</testsuite>
|
||||
<testcase name="testConstructor" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="53" assertions="1" time="0.030584"/>
|
||||
<testcase name="runTaskPass" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="76" assertions="1" time="0.031141"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest::runTaskFailed" tests="3" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.117993">
|
||||
<testcase name="runTaskFailed with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="99" assertions="3" time="0.047627"/>
|
||||
<testcase name="runTaskFailed with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="99" assertions="3" time="0.034952"/>
|
||||
<testcase name="runTaskFailed with data set #2" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="99" assertions="3" time="0.035414"/>
|
||||
</testsuite>
|
||||
<testcase name="canGetUserMessages" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="214" assertions="1" time="0.018605"/>
|
||||
<testcase name="canGetHelpUrl" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="229" assertions="1" time="0.026595"/>
|
||||
</testsuite>
|
||||
</testsuite>
|
||||
</testsuites>
|
@ -69,7 +69,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::runTask()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::runTask()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::runTask()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
@ -90,7 +91,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::runTask()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::runTask()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::runTask()
|
||||
* @test
|
||||
* @param $exceptionClass
|
||||
* @throws ReflectionException
|
||||
@ -146,7 +148,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::execute()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::execute()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::execute()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider executePassDataProvider
|
||||
@ -207,7 +210,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getUserMessages()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getUserMessages()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getUserMessages()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
@ -222,7 +226,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getHelpURL()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getHelpURL()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getHelpURL()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
|
111
tests/unit/Application/Model/ExportRenderer/CsvTest.php
Normal file
111
tests/unit/Application/Model/ExportRenderer/CsvTest.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
|
||||
|
||||
use D3\DataWizard\Application\Model\Exceptions\RenderException;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\Csv;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\Writer;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class CsvTest extends ExportRendererTest
|
||||
{
|
||||
/** @var Csv */
|
||||
protected $_oModel;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(Csv::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getContent
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
* @dataProvider canGetContentDataProvider
|
||||
*/
|
||||
public function canGetContent($blThrowException)
|
||||
{
|
||||
$expected = 'expectedReturn';
|
||||
$fieldList = ['field1', 'field2'];
|
||||
$valueList = ['value1', 'value2'];
|
||||
|
||||
/** @var Writer|MockObject $csvMock */
|
||||
$csvMockBuilder = $this->getMockBuilder(Writer::class);
|
||||
$csvMockBuilder->disableOriginalConstructor();
|
||||
$onlyMethods = ['insertOne', 'insertAll'];
|
||||
if (method_exists($csvMockBuilder->getMock(), 'getContent')) {
|
||||
$onlyMethods[] = 'getContent';
|
||||
} else {
|
||||
$csvMockBuilder->addMethods(['getContent']);
|
||||
}
|
||||
$csvMockBuilder->onlyMethods($onlyMethods);
|
||||
$csvMock = $csvMockBuilder->getMock();
|
||||
|
||||
if ($blThrowException) {
|
||||
$csvMock->expects($this->atLeastOnce())->method('getContent')->willThrowException(oxNew(Exception::class));
|
||||
$this->expectException(RenderException::class);
|
||||
} else {
|
||||
$csvMock->expects($this->atLeastOnce())->method('getContent')->willReturn($expected);
|
||||
}
|
||||
$csvMock->expects($this->atLeastOnce())->method('insertOne')->with($fieldList)->willReturn(1);
|
||||
$csvMock->expects($this->atLeastOnce())->method('insertAll')->with($valueList)->willReturn(1);
|
||||
|
||||
/** @var Csv|MockObject $modelMock */
|
||||
$modelMock = $this->getMockBuilder(Csv::class)
|
||||
->onlyMethods(['getCsv'])
|
||||
->getMock();
|
||||
$modelMock->expects($this->atLeastOnce())->method('getCsv')->willReturn($csvMock);
|
||||
$this->_oModel = $modelMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getContent',
|
||||
[$valueList, $fieldList]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function canGetContentDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'exception' => [true],
|
||||
'no exception' => [false]
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetCsv()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Writer::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getCsv'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
|
||||
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
|
||||
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
|
||||
|
||||
abstract class ExportRendererTest extends d3ModCfgUnitTestCase
|
||||
{
|
||||
/** @var RendererInterface */
|
||||
protected $_oModel;
|
||||
|
||||
public function tearDown() : void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getFileExtension
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getFileExtension
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getFileExtension
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetFileExtension()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
"/^[a-z0-9._-]*$/i",
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getFileExtension'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getTitleTranslationId
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getTitleTranslationId
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getTitleTranslationId
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetTitleTranslationId()
|
||||
{
|
||||
$this->assertIsString(
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getTitleTranslationId'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
50
tests/unit/Application/Model/ExportRenderer/JsonTest.php
Normal file
50
tests/unit/Application/Model/ExportRenderer/JsonTest.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
|
||||
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\Json;
|
||||
|
||||
class JsonTest extends ExportRendererTest
|
||||
{
|
||||
/** @var Json */
|
||||
protected $_oModel;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(Json::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getContent
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetContent()
|
||||
{
|
||||
$fieldList = ['field1', 'field2'];
|
||||
$valueList = ['value1', 'value2'];
|
||||
|
||||
$this->assertJson(
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getContent',
|
||||
[$valueList, $fieldList]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
85
tests/unit/Application/Model/ExportRenderer/PrettyTest.php
Normal file
85
tests/unit/Application/Model/ExportRenderer/PrettyTest.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
|
||||
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\Pretty;
|
||||
use MathieuViossat\Util\ArrayToTextTable;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class PrettyTest extends ExportRendererTest
|
||||
{
|
||||
/** @var Pretty */
|
||||
protected $_oModel;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(Pretty::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getContent
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetContent()
|
||||
{
|
||||
$expected = 'expectedReturn';
|
||||
$fieldList = ['field1', 'field2'];
|
||||
$valueList = ['value1', 'value2'];
|
||||
|
||||
/** @var ArrayToTextTable|MockObject $csvMock */
|
||||
$arrayToTextTableMock = $this->getMockBuilder(ArrayToTextTable::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getTable'])
|
||||
->getMock();
|
||||
$arrayToTextTableMock->expects($this->atLeastOnce())->method('getTable')->willReturn($expected);
|
||||
|
||||
/** @var Pretty|MockObject $modelMock */
|
||||
$modelMock = $this->getMockBuilder(Pretty::class)
|
||||
->onlyMethods(['getArrayToTextTableInstance'])
|
||||
->getMock();
|
||||
$modelMock->expects($this->atLeastOnce())->method('getArrayToTextTableInstance')->willReturn($arrayToTextTableMock);
|
||||
$this->_oModel = $modelMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getContent',
|
||||
[$valueList, $fieldList]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getArrayToTextTableInstance
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetArrayToTextTableInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
ArrayToTextTable::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getArrayToTextTableInstance',
|
||||
[['field1', 'field2']]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
|
||||
|
||||
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\Csv;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\Json;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\Pretty;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
|
||||
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class RendererBridgeTest extends d3ModCfgUnitTestCase
|
||||
{
|
||||
/** @var RendererBridge */
|
||||
protected $_oModel;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(RendererBridge::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRendererList
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetRendererList()
|
||||
{
|
||||
$list = $this->callMethod(
|
||||
$this->_oModel,
|
||||
'getRendererList'
|
||||
);
|
||||
|
||||
$this->assertIsArray($list);
|
||||
$this->assertTrue((bool) count($list));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getTranslatedRendererIdList
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canGetTranslatedRendererIdList()
|
||||
{
|
||||
$utlist = $this->callMethod(
|
||||
$this->_oModel,
|
||||
'getRendererList'
|
||||
);
|
||||
|
||||
$list = $this->callMethod(
|
||||
$this->_oModel,
|
||||
'getTranslatedRendererIdList'
|
||||
);
|
||||
|
||||
$this->assertIsArray($list);
|
||||
$this->assertTrue((bool) count($list));
|
||||
$this->assertSame(count($utlist), count($list));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::translateRendererId
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function canTranslateRendererId()
|
||||
{
|
||||
$expected = "expectedTranslation";
|
||||
|
||||
/** @var RendererInterface|MockObject $renderMock */
|
||||
$renderMock = $this->getMockBuilder(Pretty::class)
|
||||
->onlyMethods(['getTitleTranslationId'])
|
||||
->getMock();
|
||||
$renderMock->expects($this->atLeastOnce())->method('getTitleTranslationId')->willReturn($expected);
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'translateRendererId',
|
||||
[$renderMock]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRenderer
|
||||
* @test
|
||||
* @param $format
|
||||
* @param $blThrowException
|
||||
* @throws \ReflectionException
|
||||
* @dataProvider canGetRendererDataProvider
|
||||
*/
|
||||
public function canGetRenderer($format, $blThrowException)
|
||||
{
|
||||
/** @var RendererBridge|MockObject $modelMock */
|
||||
$modelMock = $this->getMockBuilder(RendererBridge::class)
|
||||
->onlyMethods(['getRendererList'])
|
||||
->getMock();
|
||||
$modelMock->expects($this->atLeastOnce())->method('getRendererList')->willReturn(
|
||||
[
|
||||
'CSV' => $this->getMockBuilder(Csv::class)->getMock(),
|
||||
'Pretty' => $this->getMockBuilder(Pretty::class)->getMock(),
|
||||
'JSON' => $this->getMockBuilder(Json::class)->getMock()
|
||||
]
|
||||
);
|
||||
|
||||
$this->_oModel = $modelMock;
|
||||
|
||||
if ($blThrowException) {
|
||||
$this->expectException(NoSuitableRendererException::class);
|
||||
}
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getRenderer',
|
||||
[$format]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function canGetRendererDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'existing renderer'=> [RendererBridge::FORMAT_JSON, false],
|
||||
'unknown renderer'=> ['unknownRenderer', true]
|
||||
];
|
||||
}
|
||||
}
|
Laden…
x
Verwijs in nieuw issue
Block a user