Permalink
Browse files

feat(tests): adds elgg-cli simpletest command

Simpletests are now executed via elgg-cli simpletest command.

Simpletest classes are now autoloaded using composer. Test case classes
have been moved to /tests/simpletest/ directory
  • Loading branch information...
hypeJunction committed Aug 15, 2017
1 parent 6500726 commit 7b2d459b6223a550a38869ecaed0cc670fb68b0b
Showing with 209 additions and 189 deletions.
  1. +3 −7 .scripts/travis/elgg-config/simpletest.php
  2. +2 −7 .scripts/travis/elgg-config/simpletest_memcached.php
  3. +5 −5 .travis.yml
  4. +5 −2 composer.json
  5. +1 −1 docs/admin/upgrading.rst
  6. +3 −0 docs/intro/elgg-cli.rst
  7. +151 −0 engine/classes/Elgg/Cli/SimpletestCommand.php
  8. +2 −2 engine/lib/access.php
  9. +1 −1 engine/lib/annotations.php
  10. +1 −1 engine/lib/comments.php
  11. +1 −1 engine/lib/configuration.php
  12. +1 −1 engine/lib/database.php
  13. +6 −5 engine/lib/elgglib.php
  14. +11 −11 engine/lib/entities.php
  15. +1 −1 engine/lib/filestore.php
  16. +1 −1 engine/lib/group.php
  17. +1 −1 engine/lib/input.php
  18. +2 −2 engine/lib/metadata.php
  19. +1 −1 engine/lib/metastrings.php
  20. +1 −1 engine/lib/notification.php
  21. +1 −1 engine/lib/plugins.php
  22. +1 −1 engine/lib/relationships.php
  23. +1 −1 engine/lib/river.php
  24. +1 −1 engine/lib/users.php
  25. 0 engine/tests/{ → simpletest}/ElggBatchTest.php
  26. 0 engine/tests/{ → simpletest}/ElggCommentTest.php
  27. 0 engine/tests/{ → simpletest}/ElggCoreAccessCollectionsTest.php
  28. 0 engine/tests/{ → simpletest}/ElggCoreAccessSQLTest.php
  29. 0 engine/tests/{ → simpletest}/ElggCoreAnnotationAPITest.php
  30. 0 engine/tests/{ → simpletest}/ElggCoreAttributeLoaderTest.php
  31. 0 engine/tests/{ → simpletest}/ElggCoreConfigTest.php
  32. 0 engine/tests/{ → simpletest}/ElggCoreDatabaseQueueTest.php
  33. 0 engine/tests/{ → simpletest}/ElggCoreFilestoreTest.php
  34. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesBaseTest.php
  35. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesFromAnnotationsTest.php
  36. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesFromAttributesTest.php
  37. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesFromMetadataTest.php
  38. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesFromPrivateSettingsTest.php
  39. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesFromRelationshipTest.php
  40. 0 engine/tests/{ → simpletest}/ElggCoreGetEntitiesTest.php
  41. 0 engine/tests/{ → simpletest}/ElggCoreHelpersTest.php
  42. 0 engine/tests/{ → simpletest}/ElggCoreMetadataAPITest.php
  43. 0 engine/tests/{ → simpletest}/ElggCoreMetadataCacheTest.php
  44. 0 engine/tests/{ → simpletest}/ElggCoreMetastringsTest.php
  45. +5 −5 engine/tests/{ → simpletest}/ElggCorePluginsAPITest.php
  46. 0 engine/tests/{ → simpletest}/ElggCoreRegressionBugsTest.php
  47. 0 engine/tests/{ → simpletest}/ElggCoreRiverAPITest.php
  48. 0 engine/tests/{ → simpletest}/ElggCoreSkeletonTest.php
  49. 0 engine/tests/{ → simpletest}/ElggCoreUnitTest.php
  50. 0 engine/tests/{ → simpletest}/ElggDataFunctionsTest.php
  51. 0 engine/tests/{ → simpletest}/ElggEntityPreloaderIntegrationTest.php
  52. 0 engine/tests/{ → simpletest}/ElggEntityTest.php
  53. 0 engine/tests/{ → simpletest}/ElggGroupTest.php
  54. 0 engine/tests/{ → simpletest}/ElggHtmLawedTest.php
  55. 0 engine/tests/{ → simpletest}/ElggObjectTest.php
  56. 0 engine/tests/{ → simpletest}/ElggRelationshipTest.php
  57. 0 engine/tests/{ → simpletest}/ElggSiteTest.php
  58. 0 engine/tests/{ → simpletest}/ElggTravisInstallTest.php
  59. 0 engine/tests/{ → simpletest}/ElggUserTest.php
  60. 0 engine/tests/{ → simpletest}/test_files/class_scanner/1.php
  61. 0 engine/tests/{ → simpletest}/test_files/class_scanner/2.php
  62. 0 engine/tests/{ → simpletest}/test_files/class_scanner/3.php
  63. 0 engine/tests/{ → simpletest}/test_files/class_scanner/4.php
  64. 0 engine/tests/{ → simpletest}/test_files/plugin_18/manifest.xml
  65. 0 engine/tests/{ → simpletest}/test_files/plugin_18/start.php
  66. 0 engine/tests/{ → simpletest}/test_files/xxe/external_entity.txt
  67. 0 engine/tests/{ → simpletest}/test_files/xxe/request.xml
  68. +0 −129 engine/tests/suite.php
@@ -1,11 +1,7 @@
<?php
global $CONFIG;
if (!isset($CONFIG)) {
$CONFIG = new \stdClass;
}
$CONFIG->debug = 'NOTICE';
include \Elgg\Application::elggDir()->getPath('elgg-config/settings.php');
global $CONFIG;
$CONFIG->debug = 'NOTICE';
@@ -1,12 +1,8 @@
<?php
global $CONFIG;
if (!isset($CONFIG)) {
$CONFIG = new \stdClass;
}
include \Elgg\Application::elggDir()->getPath('elgg-config/settings.php');
$CONFIG->debug = 'NOTICE';
global $CONFIG;
// Memcached configuration for Travis
$CONFIG->memcache = true;
@@ -15,4 +11,3 @@
];
$CONFIG->memcache_namespace_prefix = 'elgg_';
View
@@ -84,7 +84,7 @@ matrix:
script:
- php -f ./.scripts/is_memcached_enabled.php
- ./vendor/bin/phpunit --configuration ./.scripts/travis/phpunit-memcached.xml
- php ./engine/tests/suite.php --config ./.scripts/travis/elgg-config/simpletest_memcached.php
- php ./elgg-cli simpletest -p all -c ./.scripts/travis/elgg-config/simpletest_memcached.php
after_script:
- composer database:seeder:unseed
@@ -99,7 +99,7 @@ matrix:
- composer travis:install-with-mysql
script:
- ./vendor/bin/phpunit
- php -f ./engine/tests/suite.php
- php ./elgg-cli simpletest -p all
# End to end tests
- php: 5.6
@@ -116,7 +116,7 @@ matrix:
script:
- curl -o - http://localhost:8888/ | grep "<title>Elgg Travis Site</title>"
- ./vendor/bin/phpunit
- php -f ./engine/tests/suite.php
- php ./elgg-cli simpletest -p all
after_script:
- composer database:seeder:unseed
@@ -139,7 +139,7 @@ matrix:
- php -f ./.scripts/travis/upgrade.php
script:
#- ./vendor/bin/phpunit # not necessary
- php -f ./engine/tests/suite.php
- php ./elgg-cli simpletest -p all
- php -S localhost:8888 index.php &
- sleep 3 # give Web server some time to bind to sockets, etc
- curl -o - http://localhost:8888/ | grep "<title>Elgg Travis Site</title>"
@@ -157,7 +157,7 @@ install: composer travis:install-with-mysql
script:
- ./vendor/bin/phpunit
- php -f ./engine/tests/suite.php
- php ./elgg-cli simpletest -p all
notifications:
email:
View
@@ -64,7 +64,7 @@
"mysql -e 'create database elgg;'",
"echo \"USE mysql; UPDATE user SET password=PASSWORD('password') WHERE user='root'; FLUSH PRIVILEGES;\" | mysql -u root",
"mkdir \"${HOME}/elgg_data/\"",
"php ./elgg-cli install --config=./install/cli/travis.php"
"php ./elgg-cli install --config ./install/cli/travis.php"
],
"database:seeder:seed": "php -f ./.scripts/seeder/seed.php",
"database:seeder:unseed": "php -f ./.scripts/seeder/unseed.php"
@@ -79,7 +79,10 @@
},
"autoload-dev": {
"psr-0": {
"": "engine/tests/phpunit/"
"": [
"engine/tests/phpunit/",
"engine/tests/simpletest/"
]
}
},
"require-dev": {
View
@@ -93,7 +93,7 @@ Testing
-------
Simpletests can no longer be executed from the admin interface of the developers plugin.
Use cli command: ``php -f engine/tests/suite.php``
Use Elgg cli command: ``elgg-cli simpletest``
From 2.2 to 2.3
View
@@ -30,6 +30,9 @@ Available commands
# Install Elgg
elgg-cli install [-c|--config CONFIG]
# Run Simpletest test suite
elgg-cli simpletest [-c|--config CONFIG] [-p|--plugins PLUGINS]
Adding custom commands
======================
@@ -0,0 +1,151 @@
<?php
namespace Elgg\Cli;
use Elgg\Application;
use Elgg\Config;
use Exception;
use RuntimeException;
use Symfony\Component\Console\Input\InputOption;
use TestSuite;
use TextReporter;
/**
* elgg-cli simpletest [--config] [--plugins]
*/
class SimpletestCommand extends Command {
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('simpletest')
->setDescription('Run simpletest test suite')
->addOption('config', 'c', InputOption::VALUE_OPTIONAL,
'Path to settings file that the Elgg Application should be bootstrapped with'
)
->addOption('plugins', 'p', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
'A list of plugins to enable for testing or "all" to enable all plugins'
);
}
/**
* {@inheritdoc}
*/
protected function command() {
if (!class_exists('ElggCoreUnitTest')) {
elgg_log('You must install your Elgg application using "composer install --dev"', 'ERROR');
return 1;
}
// Disable maximum execution time.
// Tests take a while...
set_time_limit(0);
ob_start();
$error = 0;
try {
$settings_path = $this->option('config');
if ($settings_path) {
$sp = _elgg_services();
$app = Application::factory([
'settings_path' => $settings_path,
'service_provider' => $sp,
]);
Application::setInstance($app);
}
_elgg_services()->hooks->registerHandler('forward', 'all', [
$this,
'dumpRegisters'
]);
_elgg_services()->hooks->registerHandler('send:before', 'http_response', [
$this,
'dumpData'
]);
// turn off system log
_elgg_services()->hooks->unregisterHandler('all', 'all', 'system_log_listener');
_elgg_services()->hooks->unregisterHandler('log', 'systemlog', 'system_log_default_logger');
$admin = array_shift(elgg_get_admins(['limit' => 1]));
if (!login($admin)) {
throw new RuntimeException("Failed to login as administrator.");
}
// disable emails
elgg_set_email_transport(new \Zend\Mail\Transport\InMemory());
$plugins = $this->option('plugins');
if (in_array('all', $plugins)) {
$plugins = [];
$plugin_entities = elgg_get_plugins('inactive');
foreach ($plugin_entities as $plugin_entity) {
$plugins[] = $plugin_entity->getID();
}
} else if (empty($plugins)) {
// plugins that contain unit tests
$plugins = [
'groups',
'thewire',
'web_services'
];
}
// activate plugins that are not activated on install
foreach ($plugins as $key => $id) {
$plugin = elgg_get_plugin_from_id($id);
if (!$plugin || $plugin->isActive()) {
unset($plugins[$key]);
continue;
}
$plugin->activate();
}
$suite = new TestSuite('Elgg Core Unit Tests');
$test_cases = _elgg_services()->hooks->trigger('unit_test', 'system', null, []);
foreach ($test_cases as $file) {
if (substr($file, -4, 4) === '.php') {
$suite->addFile($file);
} else if (class_exists($file)) {
$suite->add($file);
}
}
$start_time = microtime(true);
$reporter = new TextReporter();
$result = $suite->Run($reporter);
// deactivate plugins that were activated for test suite
foreach ($plugins as $key => $id) {
$plugin = elgg_get_plugin_from_id($id);
$plugin->deactivate();
}
echo PHP_EOL . sprintf("Time: %.2f seconds, Memory: %.2fMb\n",
microtime(true) - $start_time,
memory_get_peak_usage() / 1048576.0 // in megabytes
) . PHP_EOL;
if (!$result) {
throw new RuntimeException('One or more tests have failed');
}
} catch (Exception $e) {
$error = 1;
elgg_log("Test suite has failed with " . get_class($e) . ': ' . $e->getMessage(), 'ERROR');
}
forward();
$this->write(STDOUT, ob_get_clean());
return $error;
}
}
View
@@ -522,8 +522,8 @@ function access_init() {
* @access private
*/
function access_test($hook, $type, $value, $params) {
$value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessCollectionsTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessSQLTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessCollectionsTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessSQLTest.php';
return $value;
}
@@ -335,7 +335,7 @@ function _elgg_set_comment_url($hook, $type, $url, $params) {
* @access private
*/
function _elgg_annotations_test($hook, $type, $tests) {
$tests[] = Paths::project() . 'engine/tests/ElggCoreAnnotationAPITest.php';
$tests[] = Paths::project() . 'engine/tests/simpletest/ElggCoreAnnotationAPITest.php';
return $tests;
}
View
@@ -443,7 +443,7 @@ function _elgg_comments_prepare_notification($hook, $type, $returnvalue, $params
* @access private
*/
function _elgg_comments_test($hook, $type, $value, $params) {
$value[] = Paths::elgg() . "engine/tests/ElggCommentTest.php";
$value[] = Paths::elgg() . "engine/tests/simpletest/ElggCommentTest.php";
return $value;
}
@@ -151,7 +151,7 @@ function _elgg_config() {
* @access private
*/
function _elgg_config_test($hook, $type, $tests) {
$tests[] = Paths::elgg() . "engine/tests/ElggCoreConfigTest.php";
$tests[] = Paths::elgg() . "engine/tests/simpletest/ElggCoreConfigTest.php";
return $tests;
}
View
@@ -272,7 +272,7 @@ function _elgg_db_run_delayed_queries() {
* @access private
*/
function _elgg_db_test($hook, $type, $value) {
$value[] = elgg_get_engine_path() . '/tests/ElggDataFunctionsTest.php';
$value[] = elgg_get_engine_path() . '/tests/simpletest/ElggDataFunctionsTest.php';
return $value;
}
View
@@ -1816,8 +1816,9 @@ function _elgg_init() {
*/
function _elgg_init_cli_commands(\Elgg\Hook $hook) {
$defaults = [
\Elgg\Cli\SimpletestCommand::class,
];
return array_merge($defaults, (array) $hook->getValue());
}
@@ -1843,10 +1844,10 @@ function _elgg_delete_autoload_cache() {
* @access private
*/
function _elgg_api_test($hook, $type, $value, $params) {
$value[] = Paths::elgg() . 'engine/tests/ElggTravisInstallTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreHelpersTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreRegressionBugsTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggBatchTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggTravisInstallTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreHelpersTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreRegressionBugsTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggBatchTest.php';
return $value;
}
View
@@ -850,17 +850,17 @@ function update_entity_last_action($guid, $posted = null) {
* @access private
*/
function _elgg_entities_test($hook, $type, $value) {
$value[] = Paths::elgg() . 'engine/tests/ElggEntityTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreAttributeLoaderTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreGetEntitiesTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreGetEntitiesFromAnnotationsTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreGetEntitiesFromMetadataTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreGetEntitiesFromPrivateSettingsTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreGetEntitiesFromRelationshipTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggCoreGetEntitiesFromAttributesTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggEntityPreloaderIntegrationTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggSiteTest.php';
$value[] = Paths::elgg() . 'engine/tests/ElggObjectTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggEntityTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAttributeLoaderTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreGetEntitiesTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreGetEntitiesFromAnnotationsTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreGetEntitiesFromMetadataTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreGetEntitiesFromPrivateSettingsTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreGetEntitiesFromRelationshipTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreGetEntitiesFromAttributesTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggEntityPreloaderIntegrationTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggSiteTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggObjectTest.php';
return $value;
}
View
@@ -420,7 +420,7 @@ function _elgg_filestore_parse_simpletype($hook, $type, $simple_type, $params) {
* @access private
*/
function _elgg_filestore_test($hook, $type, $value) {
$value[] = Paths::elgg() . "engine/tests/ElggCoreFilestoreTest.php";
$value[] = Paths::elgg() . "engine/tests/simpletest/ElggCoreFilestoreTest.php";
return $value;
}
View
@@ -109,7 +109,7 @@ function _elgg_groups_container_override($hook, $type, $result, $params) {
* @access private
*/
function _elgg_groups_test($hook, $type, $value) {
$value[] = Paths::elgg() . 'engine/tests/ElggGroupTest.php';
$value[] = Paths::elgg() . 'engine/tests/simpletest/ElggGroupTest.php';
return $value;
}
Oops, something went wrong.

0 comments on commit 7b2d459

Please sign in to comment.