Skip to content

Commit

Permalink
Merge branch 'feature/enhance_tests' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Mar 30, 2020
2 parents ae677c8 + 42bb18c commit 72f73b9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ php:
- nightly

matrix:
allow_failures:
- php: nightly
- env: GLPI_BRANCH=9.5/bugfixes
# - env: GLPI_BRANCH=master

jobs:
exclude:
- php: 5.6
env: GLPI_BRANCH=9.5/bugfixes
- php: 7.0
env: GLPI_BRANCH=9.5/bugfixes
- php: 7.1
env: GLPI_BRANCH=9.5/bugfixes
allow_failures:
- php: nightly
# - env: GLPI_BRANCH=9.5/bugfixes
# - env: GLPI_BRANCH=master

before_script:
- |
Expand All @@ -65,15 +63,15 @@ script:
- if [ "${TRAVIS_PHP_VERSION:0:3}" = "$CS" ] && [ "$GLPI_BRANCH" = "$AFTER_SUCCESS_BRANCH" ]; then COVERAGE="--nccfc CommonTreeDropdown CommonDropdown CommonDBTM CommonGLPI CommonDBConnexity CommonDBRelation"; fi

- # install GLPI with an old schema of the plugin and upgrade it
- export GLPI_CONFIG_DIR="tests/config-$OLD_DB_NAME"
- export TEST_GLPI_CONFIG_DIR="tests/config-$OLD_DB_NAME"
- init_glpi $OLD_DB_NAME $DB_USER $DB_PASSWD && init_plugin
- # upgrade test
- echo status of plugins
- mysql -h$DB_HOST -u$DB_USER -p$DB_PASSWD $OLD_DB_NAME -e "select name,directory,version,state from glpi_plugins WHERE directory IN ('formcreator')"
- plugin_test_upgrade

- # install GLPI with a fresh install of the plugin
- export GLPI_CONFIG_DIR="tests/config-$DB_NAME"
- export TEST_GLPI_CONFIG_DIR="tests/config-$DB_NAME"
- init_glpi $DB_NAME $DB_USER $DB_PASSWD && init_plugin
- # fresh install test
- plugin_test_install
Expand Down
1 change: 1 addition & 0 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public final function updateParameters(PluginFormcreatorQuestion $question, arra
$parameterInput['plugin_formcreator_questions_id'] = $this->question->getID();
if ($parameter->isNewItem()) {
// In case of the parameter vanished in DB, just recreate it
unset($parameterInput['id']);
$parameter->add($parameterInput);
} else {
$parameterInput['id'] = $parameter->getID();
Expand Down
14 changes: 11 additions & 3 deletions inc/fields/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ public function getValueForTargetText($richText) {
} else {
$user = new User();
$user->getFromDB($item);
$value[] = Toolbox::addslashes_deep($user->getRawName());
}
if (method_exists($user, 'getFriendlyName')) {
$value[] = Toolbox::addslashes_deep($user->getFriendlyName());
} else {
$value[] = Toolbox::addslashes_deep($user->getRawName());
}
}
}

if ($richText) {
Expand Down Expand Up @@ -223,7 +227,11 @@ protected function sanitizeValue($value) {
$user->getFromDB($item);
if (!$user->isNewItem()) {
// A user known in the DB
$knownUsers[$user->getID()] = $user->getRawName();
if (method_exists($user, 'getFriendlyName')) {
$knownUsers[$user->getID()] = $user->getFriendlyName();
} else {
$knownUsers[$user->getID()] = $user->getRawName();
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// glpi/inc/oolbox.class.php tests TU_USER to decide if it warns or not about mcrypt extension
define('TU_USER', '_test_user');

if (!$glpiConfigDir = getenv('GLPI_CONFIG_DIR')) {
echo "Environment var GLPI_CONFIG_DIR is not set" . PHP_EOL;
if (!$glpiConfigDir = getenv('TEST_GLPI_CONFIG_DIR')) {
echo "Environment var TEST_GLPI_CONFIG_DIR is not set" . PHP_EOL;
exit(1);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/install_glpi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* This script wraps the installer of GLPI to allow a custom CONFIG_DIR path similarly to cli installer in
* GLPI 9.5
*/
if (!$glpiConfigDir = getenv('GLPI_CONFIG_DIR')) {
echo "Environment var GLPI_CONFIG_DIR is not set" . PHP_EOL;
if (!$glpiConfigDir = getenv('TEST_GLPI_CONFIG_DIR')) {
echo "Environment var TEST_GLPI_CONFIG_DIR is not set" . PHP_EOL;
exit(1);
}

define('GLPI_ROOT', realpath(__DIR__ . '/../../../'));
define("GLPI_CONFIG_DIR", GLPI_ROOT . "/$glpiConfigDir");
unset($glpiConfigDir);
Expand Down
8 changes: 4 additions & 4 deletions tests/script-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ init_glpi() {
mysql -u$2 -p$3 -h$DB_HOST --execute "DROP DATABASE IF EXISTS \`$1\`;"
echo Cleaning up cache directory
rm -r ../../tests/files/_cache/* || true
rm ../../$GLPI_CONFIG_DIR/config_db.php || true
rm ../../$TEST_GLPI_CONFIG_DIR/config_db.php || true
echo Installing GLPI on database $1
mkdir -p ../../$GLPI_CONFIG_DIR
mkdir -p ../../$TEST_GLPI_CONFIG_DIR
if [ -e ../../tools/cliinstall.php ] ; then php ./tests/install_glpi.php --host $DB_HOST --db=$1 --user=$2 --pass=$3 ; fi
if [ -e ../../scripts/cliinstall.php ] ; then php ./tests/install_glpi.php --host $DB_HOST --db=$1 --user=$2 --pass=$3 ; fi
if [ -e ../../bin/console ]; then php ../../bin/console glpi:database:install --db-host=$DB_HOST --db-user=$2 --db-password=$3 --db-name=$1 --config-dir=../../$GLPI_CONFIG_DIR --no-interaction --no-plugins --force; fi
if [ -e ../../bin/console ]; then php ../../bin/console glpi:database:install --db-host=$DB_HOST --db-user=$2 --db-password=$3 --db-name=$1 --config-dir=../../$TEST_GLPI_CONFIG_DIR --no-interaction --no-plugins --force; fi
}

# Plugin upgrade test
plugin_test_upgrade() {
mysql -h$DB_HOST -u$DB_USER -p$DB_PASSWD $OLD_DB_NAME < tests/plugin_formcreator_config_2.5.0.sql
mysql -h$DB_HOST -u$DB_USER -p$DB_PASSWD $OLD_DB_NAME < tests/plugin_formcreator_empty_2.5.0.sql
php scripts/cliinstall.php --tests $GLPI_CONFIG_DIR
php scripts/cliinstall.php --tests $TEST_GLPI_CONFIG_DIR
}

# Plugin test
Expand Down
4 changes: 2 additions & 2 deletions tests/suite-uninstall/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public function testUninstallPlugin() {
});
$plugin->uninstall($plugin->getID());
ob_end_clean();
$this->boolean($plugin->isInstalled($pluginName))->isFalse($log);

// Check the plugin is not installed
$this->boolean($plugin->isInstalled($pluginName))->isFalse();
$plugin->getFromDBbyDir(strtolower($pluginName));
$this->integer((int) $plugin->fields['state'])->isEqualTo(\Plugin::NOTINSTALLED);

// Check all plugin's tables are dropped
$tables = [];
Expand Down

0 comments on commit 72f73b9

Please sign in to comment.