Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php artisan serve and dusk testing #9422

Merged
merged 17 commits into from Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.dusk.testing
@@ -0,0 +1,5 @@
APP_URL=http://localhost:8000
APP_KEY=base64:FSjpEaK3F9HnO40orj7FlbRI0loi1vtB3dVBcB9XaDk=
APP_ENV=testing
APP_DEBUG=true
#DB_CONNECTION=memory
16 changes: 13 additions & 3 deletions .travis.yml
@@ -1,14 +1,19 @@
sudo: required
language: php
addons:
chrome: stable
services:
- mysql
env:
global:
APP_ENV=testing
matrix:
fast_finish: true
include:
- php: 7.3
env: SKIP_STYLE_CHECK=1
- php: 7.2
env: SKIP_UNIT_CHECK=1
env: SKIP_UNIT_CHECK=1 BROWSER_TEST=1
- php: 7.1
env: SKIP_STYLE_CHECK=1 EXECUTE_BUILD_DOCS=true

Expand All @@ -25,18 +30,23 @@ before_install:
- cp tests/config/config.test.php config.php

install:
- composer install --prefer-dist --no-interaction
- pip install --user snmpsim pylint mysql-python
- travis_retry composer install --no-interaction --prefer-dist --no-suggest
- pip3 install --user snmpsim
- pip install --user mysql-python pylint

after_failure:
- tail /tmp/snmpsimd.log

before_script:
- test -z "$BROWSER_TEST" || php artisan serve --env=dusk.testing 2>/dev/null &

script:
- set -e
- export FILES=$(git diff --diff-filter=d --name-only master | tr '\n' ' '|sed 's/,*$//g')
- php scripts/pre-commit.php -q -l
- php scripts/pre-commit.php -q -s
- php scripts/pre-commit.php -u --db --snmpsim --fail-fast
- test -z "$BROWSER_TEST" || php artisan dusk
- bash -n daily.sh
- pylint -E poller-wrapper.py discovery-wrapper.py
- bash scripts/deploy-docs.sh
Expand Down
35 changes: 35 additions & 0 deletions app/Application.php
@@ -0,0 +1,35 @@
<?php
/**
* Application.php
*
* Extension of base application class
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/

namespace App;

class Application extends \Illuminate\Foundation\Application
{
public function publicPath()
{
// override the public path
return $this->basePath.DIRECTORY_SEPARATOR.'html';
}
}
2 changes: 1 addition & 1 deletion bootstrap/app.php
Expand Up @@ -11,7 +11,7 @@
|
*/

$app = new Illuminate\Foundation\Application(
$app = new App\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

Expand Down
13 changes: 7 additions & 6 deletions composer.json
Expand Up @@ -52,18 +52,19 @@
"doctrine/dbal": "^2.9"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"barryvdh/laravel-ide-helper": "^2.5",
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"jakub-onderka/php-console-highlighter": "*",
"jakub-onderka/php-parallel-lint": "*",
"justinrainbow/json-schema": "^5.2",
"laravel/dusk": "^5.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^2.9.1",
"jakub-onderka/php-parallel-lint": "*",
"jakub-onderka/php-console-highlighter": "*",
"barryvdh/laravel-ide-helper": "^2.5",
"barryvdh/laravel-debugbar": "^3.2",
"justinrainbow/json-schema": "^5.2"
"squizlabs/php_codesniffer": "^2.9.1"
},
"suggest": {
"ext-memcached": "Required if you utilize distributed polling",
Expand Down
123 changes: 122 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions config/database.php
Expand Up @@ -86,6 +86,12 @@
'prefix_indexes' => true,
],

'memory' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]

],

/*
Expand Down
21 changes: 17 additions & 4 deletions database/factories/ModelFactory.php
Expand Up @@ -16,14 +16,27 @@
use Carbon\Carbon;
use LibreNMS\Util\IPv4;

$factory->define(App\User::class, function (Faker\Generator $faker) {
$factory->define(App\Models\User::class, function (Faker\Generator $faker) {
static $password;

return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'username' => $faker->unique()->userName,
'realname' => $faker->name,
'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'level' => 1,
];
});

$factory->state(App\Models\User::class, 'admin', function ($faker) {
return [
'level' => '10',
];
});

$factory->state(App\Models\User::class, 'read', function ($faker) {
return [
'level' => '5',
];
});

Expand Down
Expand Up @@ -29,6 +29,6 @@ public function up()
*/
public function down()
{
Schema::drop('alert_schedule_items');
Schema::drop('alert_schedulables');
}
}
Expand Up @@ -27,7 +27,7 @@ public function up()
public function down()
{
Schema::table('sensors_to_state_indexes', function (Blueprint $table) {
$table->dropForeign('sensors_to_state_indexes_ibfk_2');
$table->dropForeign('sensors_to_state_indexes_ibfk_1');
$table->dropForeign('sensors_to_state_indexes_sensor_id_foreign');
});
}
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Expand Up @@ -23,6 +23,7 @@
</testsuites>
<groups>
<exclude>
<group>browser</group>
<group>mibs</group>
</exclude>
</groups>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/login-form.blade.php
Expand Up @@ -39,7 +39,7 @@
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-primary btn-block" name="submit" type="submit">
<button type="submit" id="login" class="btn btn-primary btn-block" name="submit" type="submit">
<i class="fa fa-btn fa-sign-in"></i> @lang('Login')
</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions server.php
Expand Up @@ -14,8 +14,8 @@
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
if ($uri !== '/' && file_exists(__DIR__.'/html'.$uri)) {
return false;
}

require_once __DIR__.'/public/index.php';
require_once __DIR__.'/html/index.php';
40 changes: 40 additions & 0 deletions tests/Browser/LoginTest.php
@@ -0,0 +1,40 @@
<?php

namespace LibreNMS\Tests\Browser;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use LibreNMS\Tests\Browser\Pages\LoginPage;
use LibreNMS\Tests\DuskTestCase;

/**
* Class LoginTest
* @package LibreNMS\Tests\Browser
* @group browser
*/
class LoginTest extends DuskTestCase
{
use DatabaseMigrations;

/**
* @throws \Throwable
*/
public function testUserCanLogin()
{
$this->browse(function (Browser $browser) {
$password = 'some_password';
$user = factory(User::class)->create([
'password' => password_hash($password, PASSWORD_DEFAULT)
]);

$browser->visit(new LoginPage())
->type('username', $user->username)
->type('password', $password)
->press('#login')
->assertPathIs('/');

$user->delete();
});
}
}