1
0
mirror of https://github.com/flarum/core.git synced 2025-08-05 07:57:46 +02: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:
Toby Zerner
2014-12-20 16:56:46 +10:30
committed by Alexander Skvortsov
commit 0b657c0b4c
12 changed files with 232 additions and 0 deletions

View File

@@ -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,
];
}
}

View 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();
}
}

View File

@@ -0,0 +1 @@
{}