Skip to content

Commit

Permalink
Merge pull request #2 from bdunogier/kernel_code
Browse files Browse the repository at this point in the history
Import RichText from ezpublish-kernel and repository-forms
  • Loading branch information
bdunogier committed Mar 28, 2018
2 parents 924dd23 + edc7e2a commit dff63e4
Show file tree
Hide file tree
Showing 299 changed files with 43,609 additions and 7 deletions.
62 changes: 62 additions & 0 deletions .travis.yml
@@ -0,0 +1,62 @@
# Use trusty for better performance (and avoiding mysql/postgres/solr gone issues on precise and container infra)
dist: trusty
sudo: required

language: php

services:
- mysql

# Mysql isn't installed on trusty (only client is), so we need to specifically install it
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6

cache:
directories:
- $HOME/.composer/cache/files

matrix:
fast_finish: true
include:
# 7.1
- php: 7.1
env: TEST_CONFIG="phpunit.xml"
- php: 7.1
env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="mysql" DATABASE="mysql://root@localhost/testdb"
- php: 7.1
env: CHECK_CS=true

# test only master, stable branches and pull requests
branches:
only:
- master
- /^\d.\d+$/

# setup requirements for running unit/integration/behat tests
before_script:
# Disable memory_limit for composer
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
# Prepare system
- ./bin/.travis/prepare_unittest.sh
# Execute Symfony command if specified
- if [ "$SF_CMD" != "" ] ; then cd "$HOME/build/ezplatform"; docker-compose exec --user www-data app sh -c "bin/console $SF_CMD" ; fi
# Detecting timezone issues by testing on random timezone
- TEST_TIMEZONES=("America/New_York" "Asia/Calcutta" "UTC")
- TEST_TIMEZONE=${TEST_TIMEZONES["`shuf -i 0-2 -n 1`"]}

# execute phpunit or behat as the script command
script:
- if [ "$TEST_CONFIG" != "" ] ; then php -d date.timezone=$TEST_TIMEZONE -d memory_limit=-1 vendor/bin/phpunit -c $TEST_CONFIG ; fi
- if [ "$CHECK_CS" = "true" ]; then ./vendor/bin/php-cs-fixer fix -v --dry-run --diff --show-progress=estimating; fi

# disable mail notifications
notifications:
email: false

# reduce depth (history) of git checkout
git:
depth: 30
78 changes: 78 additions & 0 deletions bin/.travis/prepare_unittest.sh
@@ -0,0 +1,78 @@
#!/bin/sh

# File for setting up system for unit/integration testing

# Disable xdebug to speed things up as we don't currently generate coverge on travis
# And make sure we use UTF-8 encoding
if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] ; then
phpenv config-rm xdebug.ini
echo "default_charset = UTF-8" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
fi

# Enable redis
if [ "$CUSTOM_CACHE_POOL" = "singleredis" ] ; then
echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

# Configure redis to work in memory mode and avoid running out of memory
redis-cli config set appendfsync "no"
redis-cli config set maxmemory "60mb"
# commented out to detect if a test uses more then max memory or if clearing is not done correctly between tests
#redis-cli config set maxmemory-policy "allkeys-lru"
redis-cli config set save ""
fi

# Setup DB
if [ "$DB" = "mysql" ] ; then
# https://github.com/travis-ci/travis-ci/issues/3049
# make sure we don't run out of entropy apparently (see link above)
sudo apt-get -y install haveged
sudo service haveged start
# make tmpfs and run MySQL on it for reasonable performance
sudo mkdir /mnt/ramdisk
sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
sudo stop mysql
sudo mv /var/lib/mysql /mnt/ramdisk
sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
sudo start mysql
# Install test db
mysql -e "CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;" -uroot
fi
if [ "$DB" = "postgresql" ] ; then psql -c "CREATE DATABASE testdb;" -U postgres ; psql -c "CREATE EXTENSION pgcrypto;" -U postgres testdb ; fi

# Setup GitHub key to avoid api rate limit (pure auth read only key, no rights, for use by ezsystems repos only!)
composer config -g github-oauth.github.com "d0285ed5c8644f30547572ead2ed897431c1fc09"

COMPOSER_UPDATE=""

# solr package search API integration tests
if [ "$TEST_CONFIG" = "phpunit-integration-legacy-solr.xml" ] ; then
echo "> Require ezsystems/ezplatform-solr-search-engine:^1.3.0@dev"
composer require --no-update ezsystems/ezplatform-solr-search-engine:^1.3.0@dev
COMPOSER_UPDATE="true"

# Because of either some changes in travis, composer or git, composer is not able to pick version for "self" on inclusion of solr anymore, so we force it:
export COMPOSER_ROOT_VERSION=`php -r 'echo json_decode(file_get_contents("./composer.json"), true)["extra"]["branch-alias"]["dev-tmp_ci_branch"];'`
fi

# Switch to another Symfony version if asked for
if [ "$SYMFONY_VERSION" != "" ] ; then
echo "> Update symfony/symfony requirement to ${SYMFONY_VERSION}"
composer require --no-update symfony/symfony="${SYMFONY_VERSION}"
# Remove php-cs-fixer as it is not needed for these tests and tends to cause Symfony version conflicts
echo "> Remove php-cs-fixer"
composer remove --dev --no-update friendsofphp/php-cs-fixer
COMPOSER_UPDATE="true"
fi

# Install packages with composer update if asked for to make sure not use composer.lock if present
if [ "$COMPOSER_UPDATE" = "true" ] ; then
echo "> Install dependencies through Composer (using update as other packages was requested)"
composer update --no-progress --no-interaction --prefer-dist
else
echo "> Install dependencies through Composer"
composer install --no-progress --no-interaction --prefer-dist
fi

# Setup Solr / Elastic search if asked for
if [ "$TEST_CONFIG" = "phpunit-integration-legacy-elasticsearch.xml" ] ; then ./bin/.travis/init_elasticsearch.sh ; fi
if [ "$TEST_CONFIG" = "phpunit-integration-legacy-solr.xml" ] ; then ./vendor/ezsystems/ezplatform-solr-search-engine/bin/.travis/init_solr.sh; fi
33 changes: 33 additions & 0 deletions bootstrap.php
@@ -0,0 +1,33 @@
<?php

/**
* File containing the bootstrapping of eZ Publish API for unit test use.
*
* Setups class loading.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

// Get global config.php settings
if (!file_exists(__DIR__ . '/config.php')) {
if (!copy(__DIR__ . '/vendor/ezsystems/ezpublish-kernel/config.php-DEVELOPMENT', __DIR__ . '/config.php')) {
throw new \RuntimeException('Could not copy config.php-DEVELOPMENT to config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!');
}
}

if (!file_exists(__DIR__ . '/vendor/ezsystems/ezpublish-kernel/config.php')) {
if (!copy(__DIR__ . '/vendor/ezsystems/ezpublish-kernel/config.php-DEVELOPMENT', __DIR__ . '/vendor/ezsystems/ezpublish-kernel/config.php')) {
throw new \RuntimeException('Could not copy config.php-DEVELOPMENT to config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!');
}
}

if (!($settings = include(__DIR__ . '/config.php'))) {
throw new \RuntimeException('Could not read config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!');
}

// Class alias used for BC
// Enables old code which still extends non namespaced TestCase to work
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');

require_once __DIR__ . '/vendor/autoload.php';
9 changes: 7 additions & 2 deletions composer.json
Expand Up @@ -7,10 +7,13 @@
"require": {
"php": "^7.1",
"ext-xsl": "*",
"symfony/symfony": "^3.4"
"symfony/symfony": "^3.4",
"ezsystems/ezpublish-kernel": "^7.0",
"ezsystems/repository-forms": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"matthiasnoback/symfony-dependency-injection-test": "~3.0",
"friendsofphp/php-cs-fixer": "~2.7.1"
},
"autoload": {
Expand All @@ -21,7 +24,9 @@
},
"autoload-dev": {
"psr-4": {
"EzSystems\\Tests\\EzPlatformRichTextFieldType\\": "tests/lib"
"EzSystems\\Tests\\EzPlatformRichTextFieldType\\": "tests/lib",
"EzSystems\\Tests\\EzPlatformRichTextFieldTypeBundle\\": "tests/bundle",
"EzSystems\\IntegrationTests\\EzPlatformRichTextFieldType\\": "tests/integration"
}
},
"scripts": {
Expand Down
25 changes: 25 additions & 0 deletions phpunit-integration-legacy.xml
@@ -0,0 +1,25 @@
<?xml version = '1.0' encoding = 'utf-8'?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap.php"
processIsolation="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
>
<php>
<env name="setupFactory" value="EzSystems\IntegrationTests\EzPlatformRichTextFieldType\eZ\API\LegacySetupFactory" />
<env name="backendVersion" value="5" />
<env name="fixtureDir" value="Legacy" />
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="RichText FieldType">
<file>tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php</file>
<directory>eZ/Publish/API/Repository/Tests/Values/User/Limitation</directory>
<directory>eZ/Publish/API/Repository/Tests/FieldType/</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 14 additions & 2 deletions phpunit.xml
@@ -1,7 +1,19 @@
<phpunit bootstrap="vendor/autoload.php">
<phpunit
bootstrap="bootstrap.php"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
>
<testsuites>
<testsuite name="ezrichtext_field_type">
<directory>tests</directory>
<directory>tests/lib</directory>
<exclude>
<directory>tests/lib/eZ/API</directory>
</exclude>
</testsuite>
</testsuites>
</phpunit>
60 changes: 60 additions & 0 deletions src/bundle/DependencyInjection/Compiler/KernelRichTextPass.php
@@ -0,0 +1,60 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformRichTextFieldTypeBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Handles compatibility with kernel 7.x.
*/
class KernelRichTextPass implements CompilerPassInterface
{
private $servicesToRemove = [
'ezpublish.fieldType.ezrichtext',
'ezpublish.fieldType.ezrichtext.converter',
'ezpublish.fieldType.indexable.ezrichtext',
'ezpublish_rest.field_type_processor.ezrichtext',
'EzSystems\\RepositoryForms\\FieldType\\Mapper\\RichTextFormMapper',
];

public function process(ContainerBuilder $container)
{
array_map(
function ($service) use ($container) {
if ($container->hasDefinition($service)) {
$container->log($this, "Removed ezpublish-kernel richtext service: $service");
$container->removeDefinition($service);
}
},
$this->servicesToRemove
);

$def = $container->getDefinition('ezpublish.persistence.legacy.field_value_converter.registry');
$methodCalls = [];
foreach ($def->getMethodCalls() as $methodCall) {
if ($methodCall[0] != 'register') {
$methodCalls[] = $methodCall;
continue;
}

if ($methodCall[1][0] != 'ezrichtext') {
$methodCalls[] = $methodCall;
continue;
}

if (!$methodCall[1][1] instanceof Reference || (string)$methodCall[1][1] !== 'ezpublish.fieldType.ezrichtext.converter') {
$methodCalls[] = $methodCall;
continue;
}
}
$def->setMethodCalls($methodCalls);
}
}
@@ -0,0 +1,70 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
/**
* File containing the RichTextEzxmlInputConverterPass class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

namespace EzSystems\EzPlatformRichTextFieldTypeBundle\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* @todo [package] is this file used at all ?
*
* Compiler pass for the RichText EZXML input Aggregate converter tags.
*
* @see \EzSystems\EzPlatformRichTextFieldType\eZ\RichText\Converter\Aggregate
*/
class RichTextEzxmlInputConverterPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezrichtext.converter.input.ezxml')) {
return;
}

$ezxmlInputConverterDefinition = $container->getDefinition('ezrichtext.converter.input.ezxml');
$taggedServiceIds = $container->findTaggedServiceIds('ezpublish.ezrichtext.converter.input.ezxml');

$convertersByPriority = [];
foreach ($taggedServiceIds as $id => $tags) {
foreach ($tags as $tag) {
$priority = isset($tag['priority']) ? (int)$tag['priority'] : 0;
$convertersByPriority[$priority][] = new Reference($id);
}
}

if (count($convertersByPriority) > 0) {
$ezxmlInputConverterDefinition->setArguments(
[
$this->sortConverters($convertersByPriority),
]
);
}
}

/**
* Transforms a two-dimensional array of converters, indexed by priority,
* into a flat array of Reference objects.
*
* @param array $convertersByPriority
*
* @return \Symfony\Component\DependencyInjection\Reference[]
*/
protected function sortConverters(array $convertersByPriority)
{
ksort($convertersByPriority);

return array_merge(...$convertersByPriority);
}
}

0 comments on commit dff63e4

Please sign in to comment.