Skip to content

Commit

Permalink
Merge pull request #1 from MarioBlazek/master
Browse files Browse the repository at this point in the history
Implemented PHPUnit tests
  • Loading branch information
emodric authored Jun 28, 2016
2 parents 78f34d4 + 8f0a276 commit 07c6dba
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
124 changes: 124 additions & 0 deletions Tests/Core/FieldType/ContentTypeList/TypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Netgen\Bundle\ContentTypeListBundle\Tests\Core\FieldType\ContentTypeList;

use eZ\Publish\Core\FieldType\FieldType;
use Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Type;
use Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value;

class TypeTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Type
*/
protected $type;

/**
* @var array
*/
protected $identifiers = array('identifier0', 'identifier1');

/**
* @var Value
*/
protected $value;

/**
* @var Value
*/
protected $emptyValue;

public function setUp()
{
$this->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);
}
}
35 changes: 35 additions & 0 deletions Tests/Core/FieldType/ContentTypeList/ValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Netgen\Bundle\ContentTypeListBundle\Tests\Core\FieldType\ContentTypeList;

use eZ\Publish\Core\FieldType\Value as BaseValue;
use Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value;

class ValueTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Value
*/
protected $value;

public function setUp()
{
$this->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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Netgen\Bundle\ContentTypeListBundle\Tests\Core\Persistence\Legacy\Content\FieldValue\Converter;

use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
use eZ\Publish\SPI\Persistence\Content\FieldValue;
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
use Netgen\Bundle\ContentTypeListBundle\Core\Persistence\Legacy\Content\FieldValue\Converter\ContentTypeListConverter;
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;

class ContentTypeListConverterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ContentTypeListConverter
*/
protected $converter;

public function setUp()
{
$this->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);
}
}
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"require": {
"ezsystems/ezpublish-kernel": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"suggest": {
"netgen/ngclasslist": "To edit this field type in legacy administration interface"
},
Expand Down
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="true"
>
<testsuites>
<testsuite name="Netgen\ContentTypeList\Tests">
<directory>Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>DependencyInjection</directory>
<directory>Resources</directory>
<directory>Tests</directory>
<directory>vendor</directory>
<file>NetgenContentTypeListBundle.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
3 changes: 3 additions & 0 deletions travis.php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[PHP]

memory_limit = 2G

0 comments on commit 07c6dba

Please sign in to comment.