diff --git a/.travis.yml b/.travis.yml index 156bb37ea..498e4556a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,44 @@ --- -dist: trusty sudo: false language: php -addons: - chrome: stable +cache: + directories: + - $HOME/.composer/cache/files + services: - mysql -before_script: - - '! find . -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"' - - php -S 0.0.0.0:8000 - - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost:8000s & - - mysql -e 'CREATE DATABASE 2moons;' + +env: + global: + - TEST_BASE_URI=http://localhost:8888 + - DB_HOST=localhost + - DB_USER=travis + - DB_PASSWORD="" + - DB_NAME=2moons + - ADMIN_NAME=admin + - ADMIN_PASSWORD=admin + - ADMIN_MAIL=mail@example.com + php: - '7.0' + +matrix: + fast_finish: true + install: + - mysql -e 'CREATE DATABASE IF NOT EXISTS 2moons;' -uroot - composer install -env: - - DB_HOST: localhost - - DB_USER: travis - - DB_PASSWORD: - - DB_NAME: 2moons - - ADMIN_NAME: admin - - ADMIN_PASSWORD: admin - - ADMIN_MAIL: mail@example.com -cache: - directories: - - $HOME/.composer/cache/files +before_script: + - phpenv config-rm xdebug.ini + - '! find . ! -path "./includes/libs/*" ! -path "./vendor/*" -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"' + # Start a web server on port 8888, run in the background; wait for + # initialization. + - nohup php -d variables_order=EGPCS -S localhost:8888 > /dev/null 2>&1 & + +script: + - 'vendor/bin/phpunit' +# - phpdbg -qrr phpunit -script: '! find . -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"' \ No newline at end of file +notifications: + email: false \ No newline at end of file diff --git a/composer.json b/composer.json index a82ad2498..f3bad3c91 100644 --- a/composer.json +++ b/composer.json @@ -11,5 +11,8 @@ ], "minimum-stability": "stable", "require": {}, - "require-dev": {} + "require-dev": { + "guzzlehttp/guzzle": "~6", + "phpunit/phpunit": "~6" + } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 000000000..087895675 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,5 @@ + + + ./tests/Install/ + + \ No newline at end of file diff --git a/tests/Install/InstallTest.php b/tests/Install/InstallTest.php new file mode 100644 index 000000000..8e057dbf0 --- /dev/null +++ b/tests/Install/InstallTest.php @@ -0,0 +1,66 @@ +http = new GuzzleHttp\Client(['base_uri' => $_SERVER['TEST_BASE_URI']]); + } + + public function tearDown() { + $this->http = null; + } + + public function testInstallRedirect() + { + $response = $this->http->request('GET', '/', ['allow_redirects' => false]); + + $this->assertEquals(302, $response->getStatusCode()); + + $location = $response->getHeaders()["Location"][0]; + $this->assertRegexp('/install\/index.php/', $location); + } + + public function testInstallHome() + { + $response = $this->http->request('GET', '/install/index.php'); + + $this->assertEquals(200, $response->getStatusCode()); + } + + public function testInstallStep2() + { + $response = $this->http->request('GET', '/index.php?mode=install&step=2'); + + $this->assertEquals(200, $response->getStatusCode()); + + $this->assertRegexp('//', $response->getBody()); + $this->assertRegexp('//', $response->getBody()); + } + + public function testInstallStep3() + { + $response = $this->http->request('GET', 'index.php?mode=install&step=3'); + + $this->assertEquals(200, $response->getStatusCode()); + } + + public function testInstallSql() + { + $response = $this->http->request('POST', 'index.php?mode=install&step=3', [ + 'form_params' => [ + 'host' => $_SERVER['DB_HOST'], + 'user' => $_SERVER['DB_USER'], + 'passwort' => $_SERVER['DB_PASSWORD'], + 'dbname' => $_SERVER['DB_NAME'], + 'prefix' => '2moons_', + ] + ]); + + $this->assertEquals(200, $response->getStatusCode()); + } +} \ No newline at end of file diff --git a/tests/run.js b/tests/run.js deleted file mode 100644 index f04a93d25..000000000 --- a/tests/run.js +++ /dev/null @@ -1,9 +0,0 @@ -console.log('Start running 2moons tests'); - -var page = require('webpage').create(); -var prefix = 'http://localhost:8000'; - - -page.open(prefix, function(status) { - console.log(status); -}); \ No newline at end of file