diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..61d2be7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,41 @@ +language: php + +cache: + directories: + - vendor + +matrix: + # mark as finished before allow_failures are run + fast_finish: true + include: + - php: 5.5 + - php: 5.6 + - php: 7.0 + +# test only master (+ pull requests) +branches: + only: + - master + +# make sure to update composer to latest available version +before_install: + - phpenv config-add travis.php.ini + - phpenv config-rm xdebug.ini + +# install dependencies +install: composer install + +# execute phpunit as the script command +script: + - ./vendor/bin/phpunit -d memory_limit=-1 --colors -c phpunit.xml + +# disable mail notifications +notification: + email: false + +# reduce depth (history) of git checkout +git: + depth: 30 + +# we don't need sudo +sudo: false diff --git a/README.md b/README.md index 793914b..4b09f3a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Netgen ContentType List Bundle ============================== +[![Build Status](https://img.shields.io/travis/netgen/NetgenContentTypeListBundle.svg?style=flat-square)](https://travis-ci.org/netgen/NetgenContentTypeListBundle) + Netgen ContentType List Bundle is an eZ Publish 5 bundle that provides a field type to select and store a list of content type identifiers. This repository represents eZ Publish 5 rewrite of the original eZ Publish 4 extension located at [http://github.com/netgen/ngclasslist](/netgen/ngclasslist). However, eZ Publish 4 extension is still required to populate field type through the admin interface. diff --git a/Tests/Core/FieldType/ContentTypeList/TypeTest.php b/Tests/Core/FieldType/ContentTypeList/TypeTest.php new file mode 100644 index 0000000..c121746 --- /dev/null +++ b/Tests/Core/FieldType/ContentTypeList/TypeTest.php @@ -0,0 +1,124 @@ +type = new Type(); + $this->value = new Value($this->identifiers); + $this->emptyValue = new Value(); + } + + public function testInstanceOfFieldType() + { + $this->assertInstanceOf(FieldType::class, $this->type); + } + + public function testToHash() + { + $this->assertEquals($this->identifiers, $this->type->toHash($this->value)); + } + + public function testGetFieldTypeIdentifier() + { + $this->assertEquals('ngclasslist', $this->type->getFieldTypeIdentifier()); + } + + public function testGetEmptyValue() + { + $this->assertEquals($this->emptyValue, $this->type->getEmptyValue()); + } + + public function testGetName() + { + $this->assertEquals(implode(', ', $this->identifiers), $this->type->getName($this->value)); + } + + public function testIsEmptyValue() + { + $this->assertFalse($this->type->isEmptyValue($this->value)); + $this->assertTrue($this->type->isEmptyValue($this->emptyValue)); + } + + public function testFromHashWithStringArgument() + { + $this->assertEquals($this->emptyValue, $this->type->fromHash('test')); + } + + public function testFromHashWithArrayOfNumbers() + { + $this->assertEquals($this->emptyValue, $this->type->fromHash(array(123, 456))); + } + + public function testFromHash() + { + $this->assertEquals($this->value, $this->type->fromHash($this->identifiers)); + } + + public function testAcceptValueWithArrayOfStringIdentifiers() + { + $this->type->acceptValue($this->identifiers); + } + + /** + * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType + * @expectedExceptionMessage Argument '$value' is invalid: expected value to be of type 'Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value', got 'array' + */ + public function testAcceptValueWithArrayOfNumbers() + { + $this->type->acceptValue(array(123, 456)); + } + + /** + * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType + * @expectedExceptionMessage Argument '$value->identifiers' is invalid: expected value to be of type 'array', got 'string' + */ + public function testAcceptValueWithValueIdentifiersAsString() + { + $this->value->identifiers = 'test'; + + $this->type->acceptValue($this->value); + } + + /** + * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType + * @expectedExceptionMessage Argument '123' is invalid: expected value to be of type 'Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value', got 'integer' + */ + public function testAcceptValueWithValueIdentifiersAsArrayOfNumbers() + { + $this->value->identifiers = array(123, 456); + + $this->type->acceptValue($this->value); + } + + public function testToPersistenceValue() + { + $this->type->toPersistenceValue($this->value); + } +} diff --git a/Tests/Core/FieldType/ContentTypeList/ValueTest.php b/Tests/Core/FieldType/ContentTypeList/ValueTest.php new file mode 100644 index 0000000..2a9e03d --- /dev/null +++ b/Tests/Core/FieldType/ContentTypeList/ValueTest.php @@ -0,0 +1,35 @@ +value = new Value( + array( + 'identifier0', 'identifier1', + ) + ); + } + + public function testInstanceOfFieldTypeValue() + { + $this->assertInstanceOf(BaseValue::class, $this->value); + } + + public function testToStringMethod() + { + $identifiers = 'identifier0, identifier1'; + + $this->assertEquals($identifiers, strval($this->value)); + } +} diff --git a/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/ContentTypeListConverterTest.php b/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/ContentTypeListConverterTest.php new file mode 100644 index 0000000..b0d11d8 --- /dev/null +++ b/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/ContentTypeListConverterTest.php @@ -0,0 +1,70 @@ +converter = new ContentTypeListConverter(); + } + + public function testInstanceOfConverterInterface() + { + $this->assertInstanceOf(Converter::class, $this->converter); + } + + public function testCreate() + { + $this->assertEquals($this->converter, ContentTypeListConverter::create()); + } + + public function testToStorageFieldDefinition() + { + $fieldDefinition = new FieldDefinition(); + $storageDefinition = new StorageFieldDefinition(); + + $this->converter->toStorageFieldDefinition($fieldDefinition, $storageDefinition); + } + + public function testToFieldDefinition() + { + $fieldDefinition = new FieldDefinition(); + $storageDefinition = new StorageFieldDefinition(); + + $this->converter->toFieldDefinition($storageDefinition, $fieldDefinition); + } + + public function testGetIndexColumn() + { + $this->assertFalse($this->converter->getIndexColumn()); + } + + public function testToFieldValue() + { + $fieldDefinition = new FieldValue(); + $storageDefinition = new StorageFieldValue(); + + $this->converter->toFieldValue($storageDefinition, $fieldDefinition); + } + + public function testToStorageValue() + { + $fieldDefinition = new FieldValue(); + $storageDefinition = new StorageFieldValue(); + + $this->converter->toStorageValue($fieldDefinition, $storageDefinition); + } +} diff --git a/composer.json b/composer.json index 20aa13b..d489354 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,9 @@ "require": { "ezsystems/ezpublish-kernel": "*" }, + "require-dev": { + "phpunit/phpunit": "*" + }, "suggest": { "netgen/ngclasslist": "To edit this field type in legacy administration interface" }, diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..dea997e --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + Tests + + + + + . + + DependencyInjection + Resources + Tests + vendor + NetgenContentTypeListBundle.php + + + + diff --git a/travis.php.ini b/travis.php.ini new file mode 100644 index 0000000..2d2a9b3 --- /dev/null +++ b/travis.php.ini @@ -0,0 +1,3 @@ +[PHP] + +memory_limit = 2G