From 8134e4709402edbad0e6ffc708f843f40a7a9f65 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 10 Jul 2018 00:23:42 +0300 Subject: [PATCH 1/7] Run tests with Travis CI. --- .travis.yml | 42 +++++++++++++++ composer.json | 17 +++++- .../tests/src/Kernel/SparqlTaxonomyTest.php | 5 +- rdf_entity.module | 3 -- src/Entity/Query/Sparql/Query.php | 1 - src/Entity/Query/Sparql/SparqlCondition.php | 2 +- src/Entity/RdfEntitySparqlStorage.php | 2 - src/Form/RdfFieldStorageConfigEditForm.php | 1 - src/RdfEntitySparqlStorageInterface.php | 2 +- src/RdfFieldHandler.php | 2 + tests/src/Functional/RdfWebTestBase.php | 54 ------------------- tests/src/Kernel/RdfDateFieldsTest.php | 3 +- tests/src/Kernel/RdfEncodingTest.php | 11 ++-- tests/src/Kernel/RdfEntityCacheTest.php | 3 +- tests/src/Kernel/RdfEntityCreationTest.php | 3 +- .../src/Kernel/RdfEntityLanguageTestBase.php | 3 -- tests/src/Kernel/RdfKernelTestBase.php | 43 +++++++++++++-- tests/src/Kernel/RdfOwnerTest.php | 3 +- tests/src/Kernel/RdfQueryExceptionTest.php | 3 +- tests/src/Kernel/SparqlEntityInsertTest.php | 6 +-- tests/src/Kernel/SparqlEntityQueryTest.php | 6 +-- tests/travis-ci/fixtures/composer.json.dist | 43 +++++++++++++++ tests/travis-ci/fixtures/connection.txt | 8 +++ tests/travis-ci/fixtures/phpunit.xml.dist | 33 ++++++++++++ tests/travis-ci/scripts/run_tests | 39 ++++++++++++++ 25 files changed, 240 insertions(+), 98 deletions(-) create mode 100644 .travis.yml delete mode 100644 tests/src/Functional/RdfWebTestBase.php create mode 100644 tests/travis-ci/fixtures/composer.json.dist create mode 100644 tests/travis-ci/fixtures/connection.txt create mode 100644 tests/travis-ci/fixtures/phpunit.xml.dist create mode 100755 tests/travis-ci/scripts/run_tests diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..d922d9dd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,42 @@ +language: php + +php: + - 7.1 + - 7.2 + +sudo: false + +mysql: + database: rdf_entity_test + username: root + encoding: utf8 + +env: + - TEST=PHP_CodeSniffer + - TEST=PHPUnit + +matrix: + fast_finish: true + exclude: + - php: 7.2 + env: TEST=PHP_CodeSniffer + +before_install: + # Deploy the codebase. + - composer --verbose self-update + - export TESTING_SITE_DIR="$HOME/build/testing_site" + - mkdir -p ${TESTING_SITE_DIR}/web/modules + - cp ./tests/travis-ci/fixtures/composer.json.dist ${TESTING_SITE_DIR}/composer.json + - cp ./tests/travis-ci/fixtures/phpunit.xml.dist ${TESTING_SITE_DIR}/web/phpunit.xml + - cd ${TESTING_SITE_DIR} + - sed -i -e 's#\$TRAVIS_BUILD_DIR#'${TRAVIS_BUILD_DIR}'#g' composer.json + - composer install --no-interaction + + # Virtuoso setup. + - mkdir ${TESTING_SITE_DIR}/virtuoso + - docker run --name virtuoso -p 8890:8890 -p 1111:1111 -e SPARQL_UPDATE=true -v ${TESTING_SITE_DIR}/virtuoso:/data -d tenforce/virtuoso + +script: ${TESTING_SITE_DIR}/web/modules/rdf_entity/tests/travis-ci/scripts/run_tests ${TEST} + +notifications: + email: false diff --git a/composer.json b/composer.json index 61719f40..ceaafb61 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,19 @@ "easyrdf/easyrdf": "0.10.0-alpha.1 as 0.9.2" }, "require-dev": { - "minimaxir/big-list-of-naughty-strings": "dev-master" - } + "minimaxir/big-list-of-naughty-strings": "0.0.1" + }, + "repositories": [ + { + "type": "package", + "package": { + "name": "minimaxir/big-list-of-naughty-strings", + "version": "0.0.1", + "dist": { + "url": "https://github.com/minimaxir/big-list-of-naughty-strings/archive/master.zip", + "type": "zip" + } + } + } + ] } diff --git a/modules/rdf_taxonomy/tests/src/Kernel/SparqlTaxonomyTest.php b/modules/rdf_taxonomy/tests/src/Kernel/SparqlTaxonomyTest.php index 4f26d475..a31a0958 100644 --- a/modules/rdf_taxonomy/tests/src/Kernel/SparqlTaxonomyTest.php +++ b/modules/rdf_taxonomy/tests/src/Kernel/SparqlTaxonomyTest.php @@ -4,7 +4,7 @@ use Drupal\rdf_entity\Entity\Rdf; use Drupal\taxonomy\Entity\Term; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; +use Drupal\Tests\rdf_entity\Kernel\RdfKernelTestBase; /** * Tests Entity Query functionality of the Sparql backend. @@ -13,7 +13,7 @@ * * @group Entity */ -class SparqlTaxonomyTest extends JoinupKernelTestBase { +class SparqlTaxonomyTest extends RdfKernelTestBase { /** * Modules to enable. @@ -22,7 +22,6 @@ class SparqlTaxonomyTest extends JoinupKernelTestBase { */ public static $modules = [ 'field_test', - 'datetime', 'language', 'rdf_taxonomy', 'rdf_taxonomy_test', diff --git a/rdf_entity.module b/rdf_entity.module index d32152ba..4484790e 100755 --- a/rdf_entity.module +++ b/rdf_entity.module @@ -11,8 +11,6 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Database\Database; use Drupal\Core\Entity\BundleEntityFormBase; -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; @@ -23,7 +21,6 @@ use Drupal\field\FieldStorageConfigInterface; use Drupal\rdf_entity\Entity\RdfEntityMapping; use Drupal\rdf_entity\Entity\RdfEntitySparqlStorage; use Drupal\rdf_entity\RdfEntityGraphInterface; -use Drupal\rdf_entity\RdfEntitySparqlStorageInterface; use Drupal\rdf_entity\RdfFieldHandler; use Drupal\rdf_entity\RdfInterface; use EasyRdf\Http; diff --git a/src/Entity/Query/Sparql/Query.php b/src/Entity/Query/Sparql/Query.php index 585cb377..33d3854a 100644 --- a/src/Entity/Query/Sparql/Query.php +++ b/src/Entity/Query/Sparql/Query.php @@ -196,7 +196,6 @@ protected function prepare() { } $this->query .= "\n"; - if (!$this->graphIds) { // If no graph IDs were requested, allow all graphs that Drupal is aware // for this entity type. diff --git a/src/Entity/Query/Sparql/SparqlCondition.php b/src/Entity/Query/Sparql/SparqlCondition.php index 10dfbb2e..28f386cc 100644 --- a/src/Entity/Query/Sparql/SparqlCondition.php +++ b/src/Entity/Query/Sparql/SparqlCondition.php @@ -28,7 +28,7 @@ class SparqlCondition extends ConditionFundamentals implements ConditionInterfac '>=', '<>', 'IN', - 'NOT IN' + 'NOT IN', ]; /** diff --git a/src/Entity/RdfEntitySparqlStorage.php b/src/Entity/RdfEntitySparqlStorage.php index 340a2f82..2c9615d3 100644 --- a/src/Entity/RdfEntitySparqlStorage.php +++ b/src/Entity/RdfEntitySparqlStorage.php @@ -10,7 +10,6 @@ use Drupal\Core\Entity\ContentEntityStorageBase; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -23,7 +22,6 @@ use Drupal\rdf_entity\Exception\DuplicatedIdException; use Drupal\rdf_entity\RdfEntityIdPluginManager; use Drupal\rdf_entity\RdfEntitySparqlStorageInterface; -use Drupal\rdf_entity\RdfFieldHandler; use Drupal\rdf_entity\RdfFieldHandlerInterface; use Drupal\rdf_entity\RdfGraphHandlerInterface; use EasyRdf\Graph; diff --git a/src/Form/RdfFieldStorageConfigEditForm.php b/src/Form/RdfFieldStorageConfigEditForm.php index f18281c2..95223ff9 100644 --- a/src/Form/RdfFieldStorageConfigEditForm.php +++ b/src/Form/RdfFieldStorageConfigEditForm.php @@ -2,7 +2,6 @@ namespace Drupal\rdf_entity\Form; -use Drupal\Core\Form\FormStateInterface; use Drupal\field_ui\Form\FieldStorageConfigEditForm; use Drupal\rdf_entity\Entity\RdfEntitySparqlStorage; diff --git a/src/RdfEntitySparqlStorageInterface.php b/src/RdfEntitySparqlStorageInterface.php index 8dbc5d3a..10001e43 100644 --- a/src/RdfEntitySparqlStorageInterface.php +++ b/src/RdfEntitySparqlStorageInterface.php @@ -149,7 +149,7 @@ public function loadByProperties(array $values = [], array $graph_ids = NULL): a /** * Resets the internal, static entity cache. * - * @param $ids + * @param array|null $ids * (optional) If specified, the cache is reset for the entities with the * given ids only. * @param string[]|null $graph_ids diff --git a/src/RdfFieldHandler.php b/src/RdfFieldHandler.php index 23695167..4fc12431 100644 --- a/src/RdfFieldHandler.php +++ b/src/RdfFieldHandler.php @@ -1,5 +1,7 @@ setUpSparql(); - parent::setUp(); - } - - /** - * {@inheritdoc} - */ - public function tearDown() { - // Delete all data produced by testing module. - foreach ($this->usedGraphs as $graph) { - $query = << { - ?entity ?field ?value - } -} -WHERE { - GRAPH <$graph> { - ?entity ?field ?value - } -} -EndOfQuery; - $this->sparql->query($query); - } - - parent::tearDown(); - } - -} diff --git a/tests/src/Kernel/RdfDateFieldsTest.php b/tests/src/Kernel/RdfDateFieldsTest.php index 50e414bd..9c3f4b35 100644 --- a/tests/src/Kernel/RdfDateFieldsTest.php +++ b/tests/src/Kernel/RdfDateFieldsTest.php @@ -4,14 +4,13 @@ use Drupal\rdf_entity\Entity\Query\Sparql\SparqlArg; use Drupal\rdf_entity\Entity\Rdf; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Tests date fields in rdf entities. * * @group rdf_entity */ -class RdfDateFieldsTest extends JoinupKernelTestBase { +class RdfDateFieldsTest extends RdfKernelTestBase { /** * Tests handling of timestamp field properties. diff --git a/tests/src/Kernel/RdfEncodingTest.php b/tests/src/Kernel/RdfEncodingTest.php index 7b3fbb66..e056aa09 100644 --- a/tests/src/Kernel/RdfEncodingTest.php +++ b/tests/src/Kernel/RdfEncodingTest.php @@ -3,14 +3,13 @@ namespace Drupal\Tests\rdf_entity\Kernel; use Drupal\rdf_entity\Entity\Rdf; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Tests the support of saving various encoded stings in the triple store. * * @group rdf_entity */ -class RdfEncodingTest extends JoinupKernelTestBase { +class RdfEncodingTest extends RdfKernelTestBase { /** * Test that naughty strings can safely be saved to the database. @@ -18,8 +17,12 @@ class RdfEncodingTest extends JoinupKernelTestBase { public function testEncoding() { $path = DRUPAL_ROOT . "/../vendor/minimaxir/big-list-of-naughty-strings/blns.json"; if (!file_exists($path)) { - $this->markTestSkipped('Library minimaxir/big-list-of-naughty-strings is required.'); - return; + // Retry with the vendor directory in the Drupal root. + $path = DRUPAL_ROOT . "/vendor/minimaxir/big-list-of-naughty-strings/blns.json"; + if (!file_exists($path)) { + $this->markTestSkipped('Library minimaxir/big-list-of-naughty-strings is required.'); + return; + } } $json = file_get_contents($path); $naughty_strings = json_decode($json); diff --git a/tests/src/Kernel/RdfEntityCacheTest.php b/tests/src/Kernel/RdfEntityCacheTest.php index dd4d9e31..91d30497 100644 --- a/tests/src/Kernel/RdfEntityCacheTest.php +++ b/tests/src/Kernel/RdfEntityCacheTest.php @@ -4,14 +4,13 @@ use Drupal\Core\Cache\Cache; use Drupal\rdf_entity\Entity\Rdf; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Tests RDF entity caching. * * @group rdf_entity */ -class RdfEntityCacheTest extends JoinupKernelTestBase { +class RdfEntityCacheTest extends RdfKernelTestBase { /** * Tests RDF entity cache tags. diff --git a/tests/src/Kernel/RdfEntityCreationTest.php b/tests/src/Kernel/RdfEntityCreationTest.php index 88237c79..ea42f009 100644 --- a/tests/src/Kernel/RdfEntityCreationTest.php +++ b/tests/src/Kernel/RdfEntityCreationTest.php @@ -4,7 +4,6 @@ use Drupal\rdf_entity\Entity\Rdf; use Drupal\rdf_entity\Exception\DuplicatedIdException; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Provides unit testing for the 'rdf_entity' entity. @@ -13,7 +12,7 @@ * * @group rdf_entity */ -class RdfEntityCreationTest extends JoinupKernelTestBase { +class RdfEntityCreationTest extends RdfKernelTestBase { /** * Tests overlapping IDs. diff --git a/tests/src/Kernel/RdfEntityLanguageTestBase.php b/tests/src/Kernel/RdfEntityLanguageTestBase.php index 33e2b5ea..bbf9a9fd 100644 --- a/tests/src/Kernel/RdfEntityLanguageTestBase.php +++ b/tests/src/Kernel/RdfEntityLanguageTestBase.php @@ -42,8 +42,6 @@ abstract class RdfEntityLanguageTestBase extends RdfKernelTestBase { */ public static $modules = [ 'language', - 'datetime', - 'rdf_entity_test', ]; /** @@ -53,7 +51,6 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('user'); - $this->installConfig(['rdf_entity_test']); $this->languageManager = $this->container->get('language_manager'); $this->installConfig(['language']); // Enable translations for the rdf entity. diff --git a/tests/src/Kernel/RdfKernelTestBase.php b/tests/src/Kernel/RdfKernelTestBase.php index 26a730b9..bafb5be7 100644 --- a/tests/src/Kernel/RdfKernelTestBase.php +++ b/tests/src/Kernel/RdfKernelTestBase.php @@ -6,7 +6,7 @@ use Drupal\Tests\rdf_entity\Traits\RdfDatabaseConnectionTrait; /** - * A base class for the rdf tests. + * A base class for the RDF tests. * * Sets up the SPARQL database connection. */ @@ -14,17 +14,50 @@ abstract class RdfKernelTestBase extends EntityKernelTestBase { use RdfDatabaseConnectionTrait; + /** + * {@inheritdoc} + */ + public static $modules = [ + 'datetime', + 'rdf_draft', + 'rdf_entity', + 'rdf_entity_test', + ]; + /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->setUpSparql(); - - $this->installModule('rdf_entity'); - $this->installModule('rdf_draft'); - $this->installConfig(['rdf_entity', 'rdf_draft']); + $this->installConfig(['rdf_entity', 'rdf_draft', 'rdf_entity_test']); $this->installEntitySchema('rdf_entity'); } + /** + * {@inheritdoc} + */ + public function tearDown() { + // Delete all data produced by testing module. + foreach (['dummy', 'with_owner', 'multifield'] as $bundle) { + foreach (['published', 'draft'] as $graph) { + $query = << { + ?entity ?field ?value + } +} +WHERE { + GRAPH { + ?entity ?field ?value + } +} +EndOfQuery; + $this->sparql->query($query); + } + } + + parent::tearDown(); + } + } diff --git a/tests/src/Kernel/RdfOwnerTest.php b/tests/src/Kernel/RdfOwnerTest.php index fb44cd63..787e8634 100644 --- a/tests/src/Kernel/RdfOwnerTest.php +++ b/tests/src/Kernel/RdfOwnerTest.php @@ -3,14 +3,13 @@ namespace Drupal\Tests\rdf_entity\Kernel; use Drupal\rdf_entity\Entity\Rdf; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Tests rdf_entity owner functionality. * * @group rdf_entity */ -class RdfOwnerTest extends JoinupKernelTestBase { +class RdfOwnerTest extends RdfKernelTestBase { /** * Tests rdf_entity owner functionality. diff --git a/tests/src/Kernel/RdfQueryExceptionTest.php b/tests/src/Kernel/RdfQueryExceptionTest.php index 1b703825..cb1c88b7 100644 --- a/tests/src/Kernel/RdfQueryExceptionTest.php +++ b/tests/src/Kernel/RdfQueryExceptionTest.php @@ -3,14 +3,13 @@ namespace Drupal\Tests\rdf_entity\Kernel; use Drupal\rdf_entity\Exception\SparqlQueryException; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Test that a proper exception is thrown when a query fails. * * @group rdf_entity */ -class RdfQueryExceptionTest extends JoinupKernelTestBase { +class RdfQueryExceptionTest extends RdfKernelTestBase { /** * Exception with query in message thrown for selects. diff --git a/tests/src/Kernel/SparqlEntityInsertTest.php b/tests/src/Kernel/SparqlEntityInsertTest.php index 05a281ac..b2e721d5 100644 --- a/tests/src/Kernel/SparqlEntityInsertTest.php +++ b/tests/src/Kernel/SparqlEntityInsertTest.php @@ -5,14 +5,13 @@ use Drupal\Component\Utility\Random; use Drupal\rdf_entity\Entity\Rdf; use Drupal\rdf_entity\RdfInterface; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Tests Entity Query functionality of the Sparql backend. * - * @group Entity + * @group rdf_entity */ -class SparqlEntityInsertTest extends JoinupKernelTestBase { +class SparqlEntityInsertTest extends RdfKernelTestBase { /** * Modules to enable. @@ -21,7 +20,6 @@ class SparqlEntityInsertTest extends JoinupKernelTestBase { */ public static $modules = [ 'field_test', - 'datetime', 'language', ]; diff --git a/tests/src/Kernel/SparqlEntityQueryTest.php b/tests/src/Kernel/SparqlEntityQueryTest.php index 1f3a9df2..b5a14824 100644 --- a/tests/src/Kernel/SparqlEntityQueryTest.php +++ b/tests/src/Kernel/SparqlEntityQueryTest.php @@ -3,16 +3,15 @@ namespace Drupal\Tests\rdf_entity\Kernel; use Drupal\rdf_entity\Entity\Rdf; -use Drupal\Tests\joinup_core\Kernel\JoinupKernelTestBase; /** * Tests Entity Query functionality of the Sparql backend. * * @see \Drupal\KernelTests\Core\Entity\EntityQueryTest * - * @group Entity + * @group rdf_entity */ -class SparqlEntityQueryTest extends JoinupKernelTestBase { +class SparqlEntityQueryTest extends RdfKernelTestBase { /** * Modules to enable. @@ -21,7 +20,6 @@ class SparqlEntityQueryTest extends JoinupKernelTestBase { */ public static $modules = [ 'field_test', - 'datetime', 'language', ]; diff --git a/tests/travis-ci/fixtures/composer.json.dist b/tests/travis-ci/fixtures/composer.json.dist new file mode 100644 index 00000000..d7690a4c --- /dev/null +++ b/tests/travis-ci/fixtures/composer.json.dist @@ -0,0 +1,43 @@ +{ + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": ">=7.1.0", + "composer/installers": "^1.5.0", + "drupal-composer/drupal-scaffold": "dev-master", + "drupal/core": "~8", + "drupal/rdf_entity": "*", + "drush/drush": "~9", + "easyrdf/easyrdf": "0.10.0-alpha.1 as 0.9.2" + }, + "require-dev": { + "behat/mink-goutte-driver": "~1.2", + "drupal/coder": "^8.2.12", + "mikey179/vfsStream": "~1.2", + "minimaxir/big-list-of-naughty-strings": "0.0.1", + "phpunit/phpunit": "~6.0" + }, + "repositories": [ + { + "type": "path", + "url": "$TRAVIS_BUILD_DIR" + }, + { + "type": "package", + "package": { + "name": "minimaxir/big-list-of-naughty-strings", + "version": "0.0.1", + "dist": { + "url": "https://github.com/minimaxir/big-list-of-naughty-strings/archive/master.zip", + "type": "zip" + } + } + } + ], + "extra": { + "installer-paths": { + "web/core": ["type:drupal-core"], + "web/modules/{$name}": ["type:drupal-module"] + } + } +} diff --git a/tests/travis-ci/fixtures/connection.txt b/tests/travis-ci/fixtures/connection.txt new file mode 100644 index 00000000..32076a46 --- /dev/null +++ b/tests/travis-ci/fixtures/connection.txt @@ -0,0 +1,8 @@ + +$databases['sparql_default']['default'] = array ( + 'prefix' => '', + 'host' => '127.0.0.1', + 'port' => 8890, + 'namespace' => 'Drupal\\rdf_entity\\Database\\Driver\\sparql', + 'driver' => 'sparql', +); diff --git a/tests/travis-ci/fixtures/phpunit.xml.dist b/tests/travis-ci/fixtures/phpunit.xml.dist new file mode 100644 index 00000000..9dd932dd --- /dev/null +++ b/tests/travis-ci/fixtures/phpunit.xml.dist @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + ./modules/rdf_entity + + + + + diff --git a/tests/travis-ci/scripts/run_tests b/tests/travis-ci/scripts/run_tests new file mode 100755 index 00000000..36e6d7b4 --- /dev/null +++ b/tests/travis-ci/scripts/run_tests @@ -0,0 +1,39 @@ +#!/bin/bash + +cd ${TESTING_SITE_DIR} + +case "$1" in + PHP_CodeSniffer) + # Run the code sniffer. + ./vendor/bin/phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer + ./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md ./web/modules/rdf_entity + exit $? + ;; + PHPUnit) + # Create the MySQL database. + mysql -e 'CREATE DATABASE rdf_entity_test' + + # Install Drupal. + ./vendor/bin/drush site:install testing --yes --root=${TESTING_SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/rdf_entity_test + + # Add the SPARQL connection in settings.php. + chmod 0775 ${TESTING_SITE_DIR}/web/sites/default/settings.php + cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${TESTING_SITE_DIR}/web/sites/default/settings.php + + # Enable rdf_entity module. + ./vendor/bin/drush pm:enable rdf_entity --yes --root=${TESTING_SITE_DIR}/web + + # Start the webserver for browser tests. + cd ${TESTING_SITE_DIR}/web + nohup php -S localhost:8888 > /dev/null 2>&1 & + # Wait until the web server is responding. + until curl -s localhost:8888; do true; done > /dev/null + + # Run PHPUnit tests. + ../vendor/bin/phpunit + exit $? + ;; + *) + echo "Unknown test '$1'" + exit 1 +esac From 31731523b00e996ec33d77ec7e33fdcef1971635 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 10 Jul 2018 09:49:30 +0300 Subject: [PATCH 2/7] Fix the coding standards of RdfFieldHandler. --- src/RdfFieldHandler.php | 126 ++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/src/RdfFieldHandler.php b/src/RdfFieldHandler.php index 4fc12431..ea51382e 100644 --- a/src/RdfFieldHandler.php +++ b/src/RdfFieldHandler.php @@ -1,7 +1,5 @@ Date: Tue, 10 Jul 2018 12:30:38 +0300 Subject: [PATCH 3/7] Add a status badge. --- README.md | 2 ++ tests/travis-ci/scripts/run_tests | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60364535..8ca23298 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/ec-europa/rdf_entity.svg?branch=8.x-1.x)](https://travis-ci.org/ec-europa/rdf_entity) + # Getting started A working Sparql endpoint is needed to use the rdf entity module. You could either use a remote Sparql endpoint, or you could set one up locally. diff --git a/tests/travis-ci/scripts/run_tests b/tests/travis-ci/scripts/run_tests index 36e6d7b4..0a474957 100755 --- a/tests/travis-ci/scripts/run_tests +++ b/tests/travis-ci/scripts/run_tests @@ -6,7 +6,7 @@ case "$1" in PHP_CodeSniffer) # Run the code sniffer. ./vendor/bin/phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer - ./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md ./web/modules/rdf_entity + ./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore='*.md' ./web/modules/rdf_entity exit $? ;; PHPUnit) From 9e7398040e9b2a8986faf441b06782d15580bc69 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 10 Jul 2018 14:30:51 +0300 Subject: [PATCH 4/7] Move the environment variable set in the right place. --- .travis.yml | 22 ++++++++++++---------- tests/travis-ci/scripts/run_tests | 12 ++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index d922d9dd..27e522cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,11 @@ mysql: encoding: utf8 env: - - TEST=PHP_CodeSniffer - - TEST=PHPUnit + global: + - SITE_DIR="$HOME/build/testing_site" + matrix: + - TEST=PHP_CodeSniffer + - TEST=PHPUnit matrix: fast_finish: true @@ -24,19 +27,18 @@ matrix: before_install: # Deploy the codebase. - composer --verbose self-update - - export TESTING_SITE_DIR="$HOME/build/testing_site" - - mkdir -p ${TESTING_SITE_DIR}/web/modules - - cp ./tests/travis-ci/fixtures/composer.json.dist ${TESTING_SITE_DIR}/composer.json - - cp ./tests/travis-ci/fixtures/phpunit.xml.dist ${TESTING_SITE_DIR}/web/phpunit.xml - - cd ${TESTING_SITE_DIR} + - mkdir -p ${SITE_DIR}/web/modules + - cp ./tests/travis-ci/fixtures/composer.json.dist ${SITE_DIR}/composer.json + - cp ./tests/travis-ci/fixtures/phpunit.xml.dist ${SITE_DIR}/web/phpunit.xml + - cd ${SITE_DIR} - sed -i -e 's#\$TRAVIS_BUILD_DIR#'${TRAVIS_BUILD_DIR}'#g' composer.json - composer install --no-interaction # Virtuoso setup. - - mkdir ${TESTING_SITE_DIR}/virtuoso - - docker run --name virtuoso -p 8890:8890 -p 1111:1111 -e SPARQL_UPDATE=true -v ${TESTING_SITE_DIR}/virtuoso:/data -d tenforce/virtuoso + - mkdir ${SITE_DIR}/virtuoso + - docker run --name virtuoso -p 8890:8890 -p 1111:1111 -e SPARQL_UPDATE=true -v ${SITE_DIR}/virtuoso:/data -d tenforce/virtuoso -script: ${TESTING_SITE_DIR}/web/modules/rdf_entity/tests/travis-ci/scripts/run_tests ${TEST} +script: ${SITE_DIR}/web/modules/rdf_entity/tests/travis-ci/scripts/run_tests ${TEST} notifications: email: false diff --git a/tests/travis-ci/scripts/run_tests b/tests/travis-ci/scripts/run_tests index 0a474957..1f3698ef 100755 --- a/tests/travis-ci/scripts/run_tests +++ b/tests/travis-ci/scripts/run_tests @@ -1,6 +1,6 @@ #!/bin/bash -cd ${TESTING_SITE_DIR} +cd ${SITE_DIR} case "$1" in PHP_CodeSniffer) @@ -14,17 +14,17 @@ case "$1" in mysql -e 'CREATE DATABASE rdf_entity_test' # Install Drupal. - ./vendor/bin/drush site:install testing --yes --root=${TESTING_SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/rdf_entity_test + ./vendor/bin/drush site:install testing --yes --root=${SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/rdf_entity_test # Add the SPARQL connection in settings.php. - chmod 0775 ${TESTING_SITE_DIR}/web/sites/default/settings.php - cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${TESTING_SITE_DIR}/web/sites/default/settings.php + chmod 0775 ${SITE_DIR}/web/sites/default/settings.php + cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${SITE_DIR}/web/sites/default/settings.php # Enable rdf_entity module. - ./vendor/bin/drush pm:enable rdf_entity --yes --root=${TESTING_SITE_DIR}/web + ./vendor/bin/drush pm:enable rdf_entity --yes --root=${SITE_DIR}/web # Start the webserver for browser tests. - cd ${TESTING_SITE_DIR}/web + cd ${SITE_DIR}/web nohup php -S localhost:8888 > /dev/null 2>&1 & # Wait until the web server is responding. until curl -s localhost:8888; do true; done > /dev/null From 9b91711d5155c8b807e4a12b871dbe8c6f82fb50 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 10 Jul 2018 14:56:36 +0300 Subject: [PATCH 5/7] Install the minimal dependencies whe running code sniffer. --- .travis.yml | 36 ++++++++++++++++++++++++------- tests/travis-ci/scripts/run_tests | 25 ++------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 27e522cb..24c9798a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,20 +25,40 @@ matrix: env: TEST=PHP_CodeSniffer before_install: - # Deploy the codebase. - composer --verbose self-update - mkdir -p ${SITE_DIR}/web/modules - - cp ./tests/travis-ci/fixtures/composer.json.dist ${SITE_DIR}/composer.json - - cp ./tests/travis-ci/fixtures/phpunit.xml.dist ${SITE_DIR}/web/phpunit.xml - cd ${SITE_DIR} - - sed -i -e 's#\$TRAVIS_BUILD_DIR#'${TRAVIS_BUILD_DIR}'#g' composer.json - - composer install --no-interaction + ### PHP_CodeSniffer only: We only needs the PHP Code Sniffer (+Drupal coder). + - test ${TEST} == "PHPUnit" || composer require drupal/coder + + ### PHPUnit only (till the end). + + # Deploy the codebase. + - test ${TEST} == "PHP_CodeSniffer" || cp ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/composer.json.dist ${SITE_DIR}/composer.json + - test ${TEST} == "PHP_CodeSniffer" || cp ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/phpunit.xml.dist ${SITE_DIR}/web/phpunit.xml + - test ${TEST} == "PHP_CodeSniffer" || sed -i -e 's#\$TRAVIS_BUILD_DIR#'${TRAVIS_BUILD_DIR}'#g' composer.json + - test ${TEST} == "PHP_CodeSniffer" || composer install --no-interaction # Virtuoso setup. - - mkdir ${SITE_DIR}/virtuoso - - docker run --name virtuoso -p 8890:8890 -p 1111:1111 -e SPARQL_UPDATE=true -v ${SITE_DIR}/virtuoso:/data -d tenforce/virtuoso + - test ${TEST} == "PHP_CodeSniffer" || mkdir ${SITE_DIR}/virtuoso + - test ${TEST} == "PHP_CodeSniffer" || docker run --name virtuoso -p 8890:8890 -p 1111:1111 -e SPARQL_UPDATE=true -v ${SITE_DIR}/virtuoso:/data -d tenforce/virtuoso + # Create the MySQL database. + - test ${TEST} == "PHP_CodeSniffer" || mysql -e 'CREATE DATABASE rdf_entity_test' + # Install Drupal. + - test ${TEST} == "PHP_CodeSniffer" || ./vendor/bin/drush site:install testing --yes --root=${SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/rdf_entity_test + # Add the SPARQL connection in settings.php. + - test ${TEST} == "PHP_CodeSniffer" || chmod 0775 ${SITE_DIR}/web/sites/default/settings.php + - test ${TEST} == "PHP_CodeSniffer" || cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${SITE_DIR}/web/sites/default/settings.php + # Enable the 'rdf_entity' module. + - test ${TEST} == "PHP_CodeSniffer" || ./vendor/bin/drush pm:enable rdf_entity --yes --root=${SITE_DIR}/web + # Start the webserver for browser tests. + - cd ${SITE_DIR}/web + - test ${TEST} == "PHP_CodeSniffer" || nohup php -S localhost:8888 > /dev/null 2>&1 & + # Wait until the web server is responding. + - test ${TEST} == "PHP_CodeSniffer" || until curl -s localhost:8888; do true; done > /dev/null + - cd .. -script: ${SITE_DIR}/web/modules/rdf_entity/tests/travis-ci/scripts/run_tests ${TEST} +script: ${TRAVIS_BUILD_DIR}/tests/travis-ci/scripts/run_tests ${TEST} notifications: email: false diff --git a/tests/travis-ci/scripts/run_tests b/tests/travis-ci/scripts/run_tests index 1f3698ef..90358260 100755 --- a/tests/travis-ci/scripts/run_tests +++ b/tests/travis-ci/scripts/run_tests @@ -1,35 +1,14 @@ #!/bin/bash -cd ${SITE_DIR} - case "$1" in PHP_CodeSniffer) - # Run the code sniffer. + cd ${SITE_DIR} ./vendor/bin/phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer - ./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore='*.md' ./web/modules/rdf_entity + ./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore='*.md' ${TRAVIS_BUILD_DIR} exit $? ;; PHPUnit) - # Create the MySQL database. - mysql -e 'CREATE DATABASE rdf_entity_test' - - # Install Drupal. - ./vendor/bin/drush site:install testing --yes --root=${SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/rdf_entity_test - - # Add the SPARQL connection in settings.php. - chmod 0775 ${SITE_DIR}/web/sites/default/settings.php - cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${SITE_DIR}/web/sites/default/settings.php - - # Enable rdf_entity module. - ./vendor/bin/drush pm:enable rdf_entity --yes --root=${SITE_DIR}/web - - # Start the webserver for browser tests. cd ${SITE_DIR}/web - nohup php -S localhost:8888 > /dev/null 2>&1 & - # Wait until the web server is responding. - until curl -s localhost:8888; do true; done > /dev/null - - # Run PHPUnit tests. ../vendor/bin/phpunit exit $? ;; From ebab7a3c39a3b1c00edebf789b7597cd00b0846f Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 10 Jul 2018 16:07:28 +0300 Subject: [PATCH 6/7] Improve documentation. --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 24c9798a..e679c8bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,9 @@ before_install: - mkdir -p ${SITE_DIR}/web/modules - cd ${SITE_DIR} - ### PHP_CodeSniffer only: We only needs the PHP Code Sniffer (+Drupal coder). + ### PHP_CodeSniffer only. + + # We only need the PHP Code Sniffer (and the Drupal coder). - test ${TEST} == "PHPUnit" || composer require drupal/coder ### PHPUnit only (till the end). @@ -46,7 +48,7 @@ before_install: - test ${TEST} == "PHP_CodeSniffer" || mysql -e 'CREATE DATABASE rdf_entity_test' # Install Drupal. - test ${TEST} == "PHP_CodeSniffer" || ./vendor/bin/drush site:install testing --yes --root=${SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/rdf_entity_test - # Add the SPARQL connection in settings.php. + # Add the SPARQL connection to settings.php. - test ${TEST} == "PHP_CodeSniffer" || chmod 0775 ${SITE_DIR}/web/sites/default/settings.php - test ${TEST} == "PHP_CodeSniffer" || cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${SITE_DIR}/web/sites/default/settings.php # Enable the 'rdf_entity' module. From 0a9eee82796176b1642cb1b841cfce1c693179ff Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 11 Jul 2018 11:00:59 +0300 Subject: [PATCH 7/7] Always include the very latest list of naughty strings in the tests. We also only need it in the testing Composer file. --- composer.json | 18 +----------------- tests/travis-ci/fixtures/composer.json.dist | 4 ++-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index ceaafb61..c7a4c54e 100644 --- a/composer.json +++ b/composer.json @@ -11,21 +11,5 @@ "require": { "php": ">=7.1", "easyrdf/easyrdf": "0.10.0-alpha.1 as 0.9.2" - }, - "require-dev": { - "minimaxir/big-list-of-naughty-strings": "0.0.1" - }, - "repositories": [ - { - "type": "package", - "package": { - "name": "minimaxir/big-list-of-naughty-strings", - "version": "0.0.1", - "dist": { - "url": "https://github.com/minimaxir/big-list-of-naughty-strings/archive/master.zip", - "type": "zip" - } - } - } - ] + } } diff --git a/tests/travis-ci/fixtures/composer.json.dist b/tests/travis-ci/fixtures/composer.json.dist index d7690a4c..9489ab25 100644 --- a/tests/travis-ci/fixtures/composer.json.dist +++ b/tests/travis-ci/fixtures/composer.json.dist @@ -14,7 +14,7 @@ "behat/mink-goutte-driver": "~1.2", "drupal/coder": "^8.2.12", "mikey179/vfsStream": "~1.2", - "minimaxir/big-list-of-naughty-strings": "0.0.1", + "minimaxir/big-list-of-naughty-strings": "dev-master", "phpunit/phpunit": "~6.0" }, "repositories": [ @@ -26,7 +26,7 @@ "type": "package", "package": { "name": "minimaxir/big-list-of-naughty-strings", - "version": "0.0.1", + "version": "dev-master", "dist": { "url": "https://github.com/minimaxir/big-list-of-naughty-strings/archive/master.zip", "type": "zip"