mirror of
https://github.com/flarum/framework.git
synced 2025-06-03 14:33:07 +08:00
Restore Initial Meaningful Test Infrastructure
This testing package was initially a part of flarum/core, but was extracted during the 0.1.0-beta.16 release cycle. The extraction was made through git's filter-branch tool to preserve some useful history in the repository.
This commit is contained in:
19
php-packages/testing/.editorconfig
Normal file
19
php-packages/testing/.editorconfig
Normal file
@ -0,0 +1,19 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{diff,md}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{php,xml}]
|
||||
indent_size = 4
|
13
php-packages/testing/.gitattributes
vendored
Normal file
13
php-packages/testing/.gitattributes
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.gitmodules export-ignore
|
||||
.github export-ignore
|
||||
.travis export-ignore
|
||||
.travis.yml export-ignore
|
||||
.editorconfig export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
||||
phpunit.xml export-ignore
|
||||
tests export-ignore
|
||||
|
||||
js/dist/* -diff
|
9
php-packages/testing/.gitignore
vendored
Normal file
9
php-packages/testing/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/vendor
|
||||
composer.lock
|
||||
composer.phar
|
||||
node_modules
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
/tests/integration/tmp
|
||||
.vagrant
|
||||
.idea/*
|
18
php-packages/testing/.styleci.yml
Normal file
18
php-packages/testing/.styleci.yml
Normal file
@ -0,0 +1,18 @@
|
||||
preset: recommended
|
||||
|
||||
enabled:
|
||||
- logical_not_operators_with_successor_space
|
||||
|
||||
disabled:
|
||||
- align_double_arrow
|
||||
- blank_line_after_opening_tag
|
||||
- multiline_array_trailing_comma
|
||||
- new_with_braces
|
||||
- phpdoc_align
|
||||
- phpdoc_order
|
||||
- phpdoc_separation
|
||||
- phpdoc_types
|
||||
|
||||
finder:
|
||||
exclude:
|
||||
- "stubs"
|
21
php-packages/testing/LICENSE
Executable file
21
php-packages/testing/LICENSE
Executable file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Stichting Flarum (Flarum Foundation)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
trait RetrievesAuthorizedUsers
|
||||
{
|
||||
protected function adminGroup(): array
|
||||
{
|
||||
return [
|
||||
'id' => 1,
|
||||
'name_singular' => 'Admin',
|
||||
'name_plural' => 'Admins',
|
||||
'color' => '#B72A2A',
|
||||
'icon' => 'fas fa-wrench',
|
||||
];
|
||||
}
|
||||
|
||||
protected function guestGroup(): array
|
||||
{
|
||||
return [
|
||||
'id' => 2,
|
||||
'name_singular' => 'Guest',
|
||||
'name_plural' => 'Guests',
|
||||
'color' => null,
|
||||
'icon' => null,
|
||||
];
|
||||
}
|
||||
|
||||
protected function memberGroup(): array
|
||||
{
|
||||
return [
|
||||
'id' => 3,
|
||||
'name_singular' => 'Member',
|
||||
'name_plural' => 'Members',
|
||||
'color' => null,
|
||||
'icon' => null,
|
||||
];
|
||||
}
|
||||
|
||||
protected function adminUser(): array
|
||||
{
|
||||
return [
|
||||
'id' => 1,
|
||||
'username' => 'admin',
|
||||
'password' => '$2y$10$HMOAe.XaQjOimA778VmFue1OCt7tj5j0wk5vfoL/CMSJq2BQlfBV2', // BCrypt hash for "password"
|
||||
'email' => 'admin@machine.local',
|
||||
'is_email_confirmed' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
protected function normalUser(): array
|
||||
{
|
||||
return [
|
||||
'id' => 2,
|
||||
'username' => 'normal',
|
||||
'password' => '$2y$10$LO59tiT7uggl6Oe23o/O6.utnF6ipngYjvMvaxo1TciKqBttDNKim', // BCrypt hash for "too-obscure"
|
||||
'email' => 'normal@machine.local',
|
||||
'is_email_confirmed' => 1,
|
||||
];
|
||||
}
|
||||
}
|
81
php-packages/testing/tests/integration/TestCase.php
Normal file
81
php-packages/testing/tests/integration/TestCase.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Flarum\Foundation\InstalledSite;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Boot the Flarum app
|
||||
$this->app();
|
||||
}
|
||||
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @return \Flarum\Foundation\InstalledApp
|
||||
*/
|
||||
protected function app()
|
||||
{
|
||||
if (! is_null($this->app)) {
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
$site = new InstalledSite(
|
||||
[
|
||||
'base' => __DIR__.'/tmp',
|
||||
'public' => __DIR__.'/tmp/public',
|
||||
'storage' => __DIR__.'/tmp/storage',
|
||||
],
|
||||
include __DIR__.'/tmp/config.php'
|
||||
);
|
||||
|
||||
return $this->app = $site->bootApp();
|
||||
}
|
||||
|
||||
protected $database;
|
||||
|
||||
protected function database(): ConnectionInterface
|
||||
{
|
||||
if (is_null($this->database)) {
|
||||
$this->database = $this->app()->getContainer()->make(
|
||||
ConnectionInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
protected function prepareDatabase(array $tableData)
|
||||
{
|
||||
// We temporarily disable foreign key checks to simplify this process.
|
||||
$this->database()->getSchemaBuilder()->disableForeignKeyConstraints();
|
||||
|
||||
// First, truncate all referenced tables so that they are empty.
|
||||
foreach (array_keys($tableData) as $table) {
|
||||
$this->database()->table($table)->truncate();
|
||||
}
|
||||
|
||||
// Then, insert all rows required for this test case.
|
||||
foreach ($tableData as $table => $rows) {
|
||||
$this->database()->table($table)->insert($rows);
|
||||
}
|
||||
|
||||
// And finally, turn on foreign key checks again.
|
||||
$this->database()->getSchemaBuilder()->enableForeignKeyConstraints();
|
||||
}
|
||||
}
|
1
php-packages/testing/tests/integration/tmp/vendor/composer/installed.json
vendored
Normal file
1
php-packages/testing/tests/integration/tmp/vendor/composer/installed.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{}
|
Reference in New Issue
Block a user