Commit 98575e91 authored by Tino Goratsch's avatar Tino Goratsch

covered the ColumnType constraints with unit tests

parent bda2f85c
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Model\DataProcessor\ColumnType\ColumnTypeStrategyInterface;
abstract class AbstractColumnTypeTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ColumnTypeStrategyInterface
*/
protected $columnType;
protected function setUp()
{
$this->instantiateClassToTest();
}
abstract protected function instantiateClassToTest();
abstract public function testDoEscape();
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Model\DataProcessor\ColumnType\BooleanColumnType;
class BooleanColumnTypeTest extends AbstractColumnTypeTest
{
protected function instantiateClassToTest()
{
$this->columnType = new BooleanColumnType();
}
public function testDoEscape()
{
$this->assertTrue(is_bool($this->columnType->doEscape('foo')));
$this->assertTrue(is_bool($this->columnType->doEscape(0)));
$this->assertTrue(is_bool($this->columnType->doEscape('0')));
$this->assertTrue(is_bool($this->columnType->doEscape(null)));
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Date;
use ACP3\Core\Model\DataProcessor\ColumnType\DateTimeColumnType;
class DateTimeColumnTypeTest extends AbstractColumnTypeTest
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $dateMock;
protected function setUp()
{
$this->dateMock = $this->getMockBuilder(Date::class)
->disableOriginalConstructor()
->setMethods(['toSQL'])
->getMock();
parent::setUp();
}
protected function instantiateClassToTest()
{
$this->columnType = new DateTimeColumnType($this->dateMock);
}
public function testDoEscape()
{
$this->setUpDateMockExpectations();
$this->columnType->doEscape('');
$this->columnType->doEscape('2016-10-20');
}
private function setUpDateMockExpectations()
{
$this->dateMock->expects($this->exactly(2))
->method('toSQL')
->withConsecutive([''], ['2016-10-20'])
->willReturnOnConsecutiveCalls('2016-10-22 13:37:00', '2016-10-20 00:00:00');
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Model\DataProcessor\ColumnType\DoubleColumnType;
class DoubleColumnTypeTest extends AbstractColumnTypeTest
{
protected function instantiateClassToTest()
{
$this->columnType = new DoubleColumnType();
}
public function testDoEscape()
{
$this->assertTrue(is_double($this->columnType->doEscape('foo')));
$this->assertTrue(is_double($this->columnType->doEscape('0.00')));
$this->assertTrue(is_double($this->columnType->doEscape('0')));
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Model\DataProcessor\ColumnType\IntegerColumnType;
class IntegerColumnTypeTest extends AbstractColumnTypeTest
{
protected function instantiateClassToTest()
{
$this->columnType = new IntegerColumnType();
}
public function testDoEscape()
{
$this->assertTrue(is_int($this->columnType->doEscape('foo')));
$this->assertTrue(is_int($this->columnType->doEscape('0.00')));
$this->assertTrue(is_int($this->columnType->doEscape('0')));
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Model\DataProcessor\ColumnType\RawColumnType;
class RawColumnTypeTest extends AbstractColumnTypeTest
{
protected function instantiateClassToTest()
{
$this->columnType = new RawColumnType();
}
public function testDoEscape()
{
$this->assertSame('foo', $this->columnType->doEscape('foo'));
$this->assertSame(9, $this->columnType->doEscape(9));
$this->assertSame('foo<html></html>', $this->columnType->doEscape('foo<html></html>'));
$this->assertSame(null, $this->columnType->doEscape(null));
$this->assertSame(true, $this->columnType->doEscape(true));
$this->assertSame(false, $this->columnType->doEscape(false));
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\DataProcessor\ColumnType\TextColumnType;
class TextColumnTypeTest extends AbstractColumnTypeTest
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $secureMock;
protected function setUp()
{
$this->secureMock = $this->getMockBuilder(Secure::class)
->disableOriginalConstructor()
->setMethods(['strEncode'])
->getMock();
parent::setUp();
}
protected function instantiateClassToTest()
{
$this->columnType = new TextColumnType($this->secureMock);
}
public function testDoEscape()
{
$this->setUpSecureMockExpectations();
$this->columnType->doEscape('foo');
}
protected function setUpSecureMockExpectations()
{
$this->secureMock->expects($this->once())
->method('strEncode')
->with('foo')
->willReturn('foo');
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Model\DataProcessor\ColumnType;
use ACP3\Core\Model\DataProcessor\ColumnType\TextWysiwygColumnType;
class TextWysiwygColumnTypeTest extends TextColumnTypeTest
{
protected function instantiateClassToTest()
{
$this->columnType = new TextWysiwygColumnType($this->secureMock);
}
protected function setUpSecureMockExpectations()
{
$this->secureMock->expects($this->once())
->method('strEncode')
->with('foo', true)
->willReturn('foo');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment