diff --git a/.travis.yml b/.travis.yml index 92b8480..7ded2d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,16 @@ language: php -php: - - 5.5 - - 5.6 - - 7.0 - - hhvm - matrix: include: - - php: 5.5 - env: DEPENDENCIES='low' - php: 7.0 + # Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version + #- php: hhvm-3.12 + # sudo: required + # dist: trusty + # group: edge + - php: 7.0 + env: DEPENDENCIES='low' + - php: 7.1 env: DEPENDENCIES='dev' allow_failures: - env: DEPENDENCIES='dev' @@ -29,4 +29,4 @@ install: - if [ "$DEPENDENCIES" == "low" ]; then travis_retry composer update --prefer-lowest; fi; script: - - phpunit --configuration phpunit.xml.dist --verbose + - vendor/bin/phpunit --configuration phpunit.xml.dist --verbose diff --git a/composer.json b/composer.json index 87c91e3..bd7ef68 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "rollerworks/datagrid", - "description": "A powerful Datagrid component", - "keywords": ["rollerworks", "component", "datagrid", "table"], + "description": "Datagrid system with a modular design and customizable", + "keywords": ["rollerworks", "component", "datagrid", "table", "ui"], "type": "library", "license": "MIT", "authors": [ @@ -11,14 +11,17 @@ }, { "name": "Community contributions", - "homepage": "https://github.com/Rollerworks/RollerworksSearch/contributors" + "homepage": "https://github.com/rollerworks/datagrid/contributors" } ], "require": { - "php": "~5.5|~7.0", - "symfony/property-access": "~2.8|~3.0", - "symfony/options-resolver": "^2.7.7|~3.0", - "symfony/intl": "~2.3|~3.0" + "php": "^7.0", + "symfony/property-access": "^3.0", + "symfony/options-resolver": "^3.0", + "symfony/intl": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.5" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 92c275e..ed0e8af 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ registry = $this->getMock(ColumnTypeRegistryInterface::class); - $this->resolvedTypeFactory = $this->getMock(ResolvedColumnTypeFactoryInterface::class); + $this->registry = $this->createMock(ColumnTypeRegistryInterface::class); + $this->resolvedTypeFactory = $this->createMock(ResolvedColumnTypeFactoryInterface::class); $this->factory = new DatagridFactory($this->registry); } @@ -61,9 +61,9 @@ public function testCreateGridBuilder() public function testCreateColumn() { - $type = $this->getMock(ResolvedColumnTypeInterface::class); + $type = $this->createMock(ResolvedColumnTypeInterface::class); - $column = $this->getMock(ColumnInterface::class); + $column = $this->createMock(ColumnInterface::class); $column->expects($this->once()) ->method('getOptions') ->will($this->returnValue(['foo' => 'bar'])); diff --git a/tests/DatagridRowViewTest.php b/tests/DatagridRowViewTest.php index 762faaf..e939dd6 100644 --- a/tests/DatagridRowViewTest.php +++ b/tests/DatagridRowViewTest.php @@ -38,7 +38,7 @@ protected function setUp() $this->datagridView = $this->getMockBuilder(DatagridView::class)->disableOriginalConstructor()->getMock(); $this->cellView = $this->getMockBuilder(CellView::class)->disableOriginalConstructor()->getMock(); - $column = $this->getMock(ColumnInterface::class); + $column = $this->createMock(ColumnInterface::class); $column->expects($this->once()) ->method('getName') diff --git a/tests/DatagridViewTest.php b/tests/DatagridViewTest.php index 00b27e3..fac067e 100644 --- a/tests/DatagridViewTest.php +++ b/tests/DatagridViewTest.php @@ -27,7 +27,7 @@ class DatagridViewTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $column = $this->getMock(ColumnInterface::class); + $column = $this->createMock(ColumnInterface::class); $column->expects($this->atLeastOnce()) ->method('getName') @@ -37,7 +37,7 @@ protected function setUp() ->method('createHeaderView') ->willReturn($this->getMockBuilder(HeaderView::class)->disableOriginalConstructor()->getMock()); - $datagrid = $this->getMock(DatagridInterface::class); + $datagrid = $this->createMock(DatagridInterface::class); $datagrid->expects($this->once()) ->method('getColumns') @@ -70,7 +70,7 @@ public function testGetColumn() public function testThrowsExceptionWhenGettingUnRegisteredColumn() { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->gridView->getColumn('bar'); } diff --git a/tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php index 9ad5287..06fd782 100644 --- a/tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php +++ b/tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php @@ -54,17 +54,17 @@ public static function assertEquals($expected, $actual, $message = '', $delta = public function dataProvider() { return [ - [\IntlDateFormatter::SHORT, null, null, '03.02.2010 04:05', '2010-02-03 04:05:00 UTC'], - [\IntlDateFormatter::MEDIUM, null, null, '03.02.2010 04:05', '2010-02-03 04:05:00 UTC'], - [\IntlDateFormatter::LONG, null, null, '03. Februar 2010 04:05', '2010-02-03 04:05:00 UTC'], - [\IntlDateFormatter::FULL, null, null, 'Mittwoch, 03. Februar 2010 04:05', '2010-02-03 04:05:00 UTC'], + [\IntlDateFormatter::SHORT, null, null, '03.02.2010, 04:05', '2010-02-03 04:05:00 UTC'], + [\IntlDateFormatter::MEDIUM, null, null, '03.02.2010, 04:05', '2010-02-03 04:05:00 UTC'], + [\IntlDateFormatter::LONG, null, null, '3. Februar 2010 um 04:05', '2010-02-03 04:05:00 UTC'], + [\IntlDateFormatter::FULL, null, null, 'Mittwoch, 3. Februar 2010 um 04:05', '2010-02-03 04:05:00 UTC'], [\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, null, '03.02.2010', '2010-02-03 00:00:00 UTC'], [\IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE, null, '03.02.2010', '2010-02-03 00:00:00 UTC'], - [\IntlDateFormatter::LONG, \IntlDateFormatter::NONE, null, '03. Februar 2010', '2010-02-03 00:00:00 UTC'], - [\IntlDateFormatter::FULL, \IntlDateFormatter::NONE, null, 'Mittwoch, 03. Februar 2010', '2010-02-03 00:00:00 UTC'], - [null, \IntlDateFormatter::SHORT, null, '03.02.2010 04:05', '2010-02-03 04:05:00 UTC'], - [null, \IntlDateFormatter::MEDIUM, null, '03.02.2010 04:05:06', '2010-02-03 04:05:06 UTC'], - [null, \IntlDateFormatter::LONG, null, '03.02.2010 04:05:06 GMT', '2010-02-03 04:05:06 UTC'], + [\IntlDateFormatter::LONG, \IntlDateFormatter::NONE, null, '3. Februar 2010', '2010-02-03 00:00:00 UTC'], + [\IntlDateFormatter::FULL, \IntlDateFormatter::NONE, null, 'Mittwoch, 3. Februar 2010', '2010-02-03 00:00:00 UTC'], + [null, \IntlDateFormatter::SHORT, null, '03.02.2010, 04:05', '2010-02-03 04:05:00 UTC'], + [null, \IntlDateFormatter::MEDIUM, null, '03.02.2010, 04:05:06', '2010-02-03 04:05:06 UTC'], + [null, \IntlDateFormatter::LONG, null, '03.02.2010, 04:05:06 GMT', '2010-02-03 04:05:06 UTC'], // see below for extra test case for time format FULL [\IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, null, '04:05', '1970-01-01 04:05:00 UTC'], [\IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM, null, '04:05:06', '1970-01-01 04:05:06 UTC'], @@ -106,7 +106,7 @@ public function testTransformFullTime() { $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL); - $this->assertEquals('03.02.2010 04:05:06 GMT', $transformer->transform($this->dateTime)); + $this->assertEquals('03.02.2010, 04:05:06 GMT', $transformer->transform($this->dateTime)); } public function testTransformToDifferentLocale() @@ -134,7 +134,7 @@ public function testTransformWithDifferentTimezones() $dateTime = clone $input; $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); - $this->assertEquals($dateTime->format('d.m.Y H:i'), $transformer->transform($input)); + $this->assertEquals($dateTime->format('d.m.Y, H:i'), $transformer->transform($input)); } public function testTransformWithDifferentPatterns() diff --git a/tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php b/tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php index b9fffd9..be37150 100644 --- a/tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php +++ b/tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php @@ -57,8 +57,8 @@ public function testTransform($from, $to, $locale) public function provideTransformationsWithGrouping() { return [ - [1234.5, '1.234,5', 'de_AT'], - [12345.912, '12.345,912', 'de_AT'], + [1234.5, '1 234,5', 'de_AT'], + [12345.912, '12 345,912', 'de_AT'], [1234.5, '1 234,5', 'fr'], [1234.5, '1 234,5', 'ru'], [1234.5, '1 234,5', 'fi'], diff --git a/tests/Extension/Core/Type/BaseTypeTest.php b/tests/Extension/Core/Type/BaseTypeTest.php index 97ba4a0..cb08bba 100644 --- a/tests/Extension/Core/Type/BaseTypeTest.php +++ b/tests/Extension/Core/Type/BaseTypeTest.php @@ -15,29 +15,4 @@ abstract class BaseTypeTest extends ColumnTypeTestCase { - public function testPassLabelToView() - { - $column = $this->factory->createColumn( - 'id', - $this->getTestedType(), - [ - 'label' => 'My label', - 'data_provider' => function ($data) { - return $data->key; - }, - ] - ); - - $datagrid = $this->factory->createDatagrid('grid', [$column]); - - $object = new \stdClass(); - $object->key = ' foo '; - - $datagrid->setData([1 => $object]); - - $view = $datagrid->createView(); - $view = $column->createHeaderView($view); - - $this->assertSame('My label', $view->label); - } } diff --git a/tests/Extension/Core/Type/ColumnTypeTest.php b/tests/Extension/Core/Type/ColumnTypeTest.php index d416509..02dfdf0 100644 --- a/tests/Extension/Core/Type/ColumnTypeTest.php +++ b/tests/Extension/Core/Type/ColumnTypeTest.php @@ -16,6 +16,32 @@ class ColumnTypeTest extends BaseTypeTest { + public function testPassLabelToView() + { + $column = $this->factory->createColumn( + 'id', + $this->getTestedType(), + [ + 'label' => 'My label', + 'data_provider' => function ($data) { + return $data->key; + }, + ] + ); + + $datagrid = $this->factory->createDatagrid('grid', [$column]); + + $object = new \stdClass(); + $object->key = new \DateTime(); + + $datagrid->setData([1 => $object]); + + $view = $datagrid->createView(); + $view = $column->createHeaderView($view); + + $this->assertSame('My label', $view->label); + } + public function testAutoConfigurationDataProvider() { $object = new \stdClass(); diff --git a/tests/Extension/Core/Type/DateTimeTypeTest.php b/tests/Extension/Core/Type/DateTimeTypeTest.php index 11942ae..bd26928 100644 --- a/tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/tests/Extension/Core/Type/DateTimeTypeTest.php @@ -16,6 +16,32 @@ class DateTimeTypeTest extends BaseTypeTest { + public function testPassLabelToView() + { + $column = $this->factory->createColumn( + 'id', + $this->getTestedType(), + [ + 'label' => 'My label', + 'data_provider' => function ($data) { + return $data->key; + }, + ] + ); + + $datagrid = $this->factory->createDatagrid('grid', [$column]); + + $object = new \stdClass(); + $object->key = new \DateTime(); + + $datagrid->setData([1 => $object]); + + $view = $datagrid->createView(); + $view = $column->createHeaderView($view); + + $this->assertSame('My label', $view->label); + } + protected function getTestedType() { return DateTimeType::class; diff --git a/tests/Extension/Core/Type/MoneyTypeTest.php b/tests/Extension/Core/Type/MoneyTypeTest.php index bc03f58..ff5c9fb 100644 --- a/tests/Extension/Core/Type/MoneyTypeTest.php +++ b/tests/Extension/Core/Type/MoneyTypeTest.php @@ -30,6 +30,32 @@ protected function setUp() parent::setUp(); } + public function testPassLabelToView() + { + $column = $this->factory->createColumn( + 'id', + $this->getTestedType(), + [ + 'label' => 'My label', + 'data_provider' => function ($data) { + return $data->key; + }, + ] + ); + + $datagrid = $this->factory->createDatagrid('grid', [$column]); + + $object = new \stdClass(); + $object->key = '20.00'; + + $datagrid->setData([1 => $object]); + + $view = $datagrid->createView(); + $view = $column->createHeaderView($view); + + $this->assertSame('My label', $view->label); + } + public function testEURWithUS() { \Locale::setDefault('en_US'); @@ -62,13 +88,15 @@ public function testForDifferentCurrencies() $column = $this->factory->createColumn('price', $this->getTestedType(), ['currency' => 'EUR']); $column2 = $this->factory->createColumn('price2', $this->getTestedType(), ['currency' => 'GBP']); + $datagrid = $this->factory->createDatagrid('grid', [$column, $column2]); + $object = new \stdClass(); $object->price = '1.23'; $object->price2 = '1.23'; $data = [1 => $object]; - $this->datagrid->setData($data); - $datagridView = $this->datagrid->createView(); + $datagrid->setData($data); + $datagridView = $datagrid->createView(); $view = $column->createCellView($datagridView, $data[1], 1); $this->assertSame('1,23 €', $view->value); @@ -82,28 +110,46 @@ public function testDifferentCurrencyByMapping() \Locale::setDefault('de_DE'); $column = $this->factory->createColumn('price', $this->getTestedType(), ['currency' => 'EUR']); - $column2 = $this->factory->createColumn('price2', $this->getTestedType(), ['input_field' => 'price2', 'currency_field' => 'currency']); + $column2 = $this->factory->createColumn( + 'price2', + $this->getTestedType(), + [ + 'input_field' => 'price2', + 'currency_field' => 'currency', + 'data_provider' => function ($value) { + return (array) $value; + }, + ] + ); + + $datagrid = $this->factory->createDatagrid('grid', [$column, $column2]); $object = new \stdClass(); $object->price = '1.23'; $object->price2 = '1.23'; - $object->currency = 'GBP'; - $data = [1 => $object]; + $object->currency = null; - $this->datagrid->setData($data); - $datagridView = $this->datagrid->createView(); + $object2 = new \stdClass(); + $object2->price = '1.23'; + $object2->price2 = '1.23'; + $object2->currency = 'GBP'; + + $data = [1 => $object, 2 => $object2]; + + $datagrid->setData($data); + $datagridView = $datagrid->createView(); $view = $column->createCellView($datagridView, $data[1], 1); $this->assertSame('1,23 €', $view->value); - $view = $column2->createCellView($datagridView, $data[1], 1); + $view = $column2->createCellView($datagridView, $data[2], 1); $this->assertSame('1,23 £', $view->value); } public function testPrecision() { - // Note changing the precision does not work nl and en_US - // I'm unable to find the cause, please provide a fix you have one + // Note changing the precision does not work for nl and en_US + // I'm unable to find the cause, please provide a fix if you have one - Sebastiaan Stok (@sstok) \Locale::setDefault('de_DE'); $this->assertCellValueEquals('1,2355 €', '1.2355', ['currency' => 'EUR', 'precision' => 4]);