add tests for renderers
Dieser Commit ist enthalten in:
111
tests/unit/Application/Model/ExportRenderer/CsvTest.php
Normale Datei
111
tests/unit/Application/Model/ExportRenderer/CsvTest.php
Normale Datei
@ -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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
65
tests/unit/Application/Model/ExportRenderer/ExportRendererTest.php
Normale Datei
65
tests/unit/Application/Model/ExportRenderer/ExportRendererTest.php
Normale Datei
@ -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
Normale Datei
50
tests/unit/Application/Model/ExportRenderer/JsonTest.php
Normale Datei
@ -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
Normale Datei
85
tests/unit/Application/Model/ExportRenderer/PrettyTest.php
Normale Datei
@ -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']]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
151
tests/unit/Application/Model/ExportRenderer/RendererBridgeTest.php
Normale Datei
151
tests/unit/Application/Model/ExportRenderer/RendererBridgeTest.php
Normale Datei
@ -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]
|
||||
];
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren