mirror of
https://github.com/flarum/framework.git
synced 2025-02-06 17:21:08 +08:00
Merge pull request #1743 from flarum/fl/test-structure
Improve test suite structure
This commit is contained in:
commit
a96d49a7ee
2
framework/core/.gitignore
vendored
2
framework/core/.gitignore
vendored
|
@ -4,6 +4,6 @@ composer.phar
|
||||||
node_modules
|
node_modules
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
/tests/tmp
|
/tests/integration/tmp
|
||||||
.vagrant
|
.vagrant
|
||||||
.idea/*
|
.idea/*
|
||||||
|
|
|
@ -7,16 +7,14 @@ cache:
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- composer install
|
- composer install
|
||||||
- mysql -e 'CREATE DATABASE flarum;'
|
- mysql -e 'CREATE DATABASE flarum_test;'
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- echo 'error_reporting = E_ALL' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
- echo 'error_reporting = E_ALL' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||||
|
- composer test:setup
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/phpunit --coverage-clover=coverage.xml
|
- composer test
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
|
|
|
@ -86,5 +86,14 @@
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "0.1.x-dev"
|
"dev-master": "0.1.x-dev"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": [
|
||||||
|
"@test:unit",
|
||||||
|
"@test:integration"
|
||||||
|
],
|
||||||
|
"test:unit": "phpunit -c tests/phpunit.unit.xml",
|
||||||
|
"test:integration": "phpunit -c tests/phpunit.integration.xml",
|
||||||
|
"test:setup": "@php tests/integration/setup.php"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,11 @@ class InstalledApp implements AppInterface
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getContainer()
|
||||||
|
{
|
||||||
|
return $this->container;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Psr\Http\Server\RequestHandlerInterface
|
* @return \Psr\Http\Server\RequestHandlerInterface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -72,7 +72,7 @@ class InstalledSite implements SiteInterface
|
||||||
/**
|
/**
|
||||||
* Create and boot a Flarum application instance.
|
* Create and boot a Flarum application instance.
|
||||||
*
|
*
|
||||||
* @return AppInterface
|
* @return InstalledApp
|
||||||
*/
|
*/
|
||||||
public function bootApp(): AppInterface
|
public function bootApp(): AppInterface
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?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\Api\Controller;
|
|
||||||
|
|
||||||
use Flarum\Api\Controller\DeleteDiscussionController;
|
|
||||||
use Flarum\Discussion\Discussion;
|
|
||||||
|
|
||||||
class DeleteDiscussionControllerTest extends ApiControllerTestCase
|
|
||||||
{
|
|
||||||
protected $controller = DeleteDiscussionController::class;
|
|
||||||
protected $discussion;
|
|
||||||
|
|
||||||
protected function init()
|
|
||||||
{
|
|
||||||
$this->discussion = Discussion::start(__CLASS__, $this->getNormalUser());
|
|
||||||
|
|
||||||
$this->discussion->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function admin_can_delete()
|
|
||||||
{
|
|
||||||
$this->actor = $this->getAdminUser();
|
|
||||||
|
|
||||||
$response = $this->callWith([], ['id' => $this->discussion->id]);
|
|
||||||
|
|
||||||
$this->assertEquals(204, $response->getStatusCode());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
<?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\Api\Controller;
|
|
||||||
|
|
||||||
use Flarum\Api\Controller\ListDiscussionsController;
|
|
||||||
use Flarum\Discussion\Discussion;
|
|
||||||
|
|
||||||
class ListDiscussionsControllerTest extends ApiControllerTestCase
|
|
||||||
{
|
|
||||||
protected $controller = ListDiscussionsController::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function shows_index_for_guest()
|
|
||||||
{
|
|
||||||
$response = $this->callWith();
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
|
||||||
$data = json_decode($response->getBody()->getContents(), true);
|
|
||||||
|
|
||||||
$this->assertEquals(Discussion::count(), count($data['data']));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function can_search_for_author()
|
|
||||||
{
|
|
||||||
$user = $this->getNormalUser();
|
|
||||||
|
|
||||||
$response = $this->callWith([], [
|
|
||||||
'filter' => [
|
|
||||||
'q' => 'author:'.$user->username.' foo'
|
|
||||||
],
|
|
||||||
'include' => 'mostRelevantPost'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,86 +0,0 @@
|
||||||
<?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\Api\Controller;
|
|
||||||
|
|
||||||
use Flarum\Api\Controller\ShowDiscussionController;
|
|
||||||
use Flarum\Discussion\Discussion;
|
|
||||||
use Flarum\Tests\Test\Concerns\ManagesContent;
|
|
||||||
|
|
||||||
class ShowDiscussionControllerTest extends ApiControllerTestCase
|
|
||||||
{
|
|
||||||
use ManagesContent;
|
|
||||||
|
|
||||||
protected $controller = ShowDiscussionController::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Discussion
|
|
||||||
*/
|
|
||||||
protected $discussion;
|
|
||||||
|
|
||||||
protected function init()
|
|
||||||
{
|
|
||||||
$this->discussion = Discussion::start(__CLASS__, $this->getNormalUser());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function author_can_see_discussion()
|
|
||||||
{
|
|
||||||
$this->discussion->save();
|
|
||||||
|
|
||||||
$this->actor = $this->getNormalUser();
|
|
||||||
|
|
||||||
$response = $this->callWith([], ['id' => $this->discussion->id]);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
public function guest_cannot_see_empty_discussion()
|
|
||||||
{
|
|
||||||
$this->discussion->save();
|
|
||||||
|
|
||||||
$response = $this->callWith([], ['id' => $this->discussion->id]);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function guest_can_see_discussion()
|
|
||||||
{
|
|
||||||
$this->discussion->save();
|
|
||||||
|
|
||||||
$this->addPostByNormalUser();
|
|
||||||
|
|
||||||
$response = $this->callWith([], ['id' => $this->discussion->id]);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
public function guests_cannot_see_private_discussion()
|
|
||||||
{
|
|
||||||
$this->discussion->is_private = true;
|
|
||||||
$this->discussion->save();
|
|
||||||
|
|
||||||
$this->callWith([], ['id' => $this->discussion->id]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
<?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\Install;
|
|
||||||
|
|
||||||
use Flarum\Install\AdminUser;
|
|
||||||
use Flarum\Install\Installation;
|
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
|
||||||
|
|
||||||
class DefaultInstallationTest extends TestCase
|
|
||||||
{
|
|
||||||
protected $isInstalled = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function allows_forum_installation()
|
|
||||||
{
|
|
||||||
if (file_exists(base_path('config.php'))) {
|
|
||||||
unlink(base_path('config.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Installation $installation */
|
|
||||||
$installation = app(Installation::class);
|
|
||||||
|
|
||||||
$installation
|
|
||||||
->debugMode(true)
|
|
||||||
->baseUrl('http://flarum.local')
|
|
||||||
->databaseConfig($this->getDatabaseConfiguration())
|
|
||||||
->adminUser($this->getAdmin())
|
|
||||||
->settings($this->getSettings())
|
|
||||||
->build()->run();
|
|
||||||
|
|
||||||
$this->assertFileExists(base_path('config.php'));
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$this->getDatabase()->table('users')->find(1)->username,
|
|
||||||
'admin'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getDatabase()
|
|
||||||
{
|
|
||||||
$factory = new ConnectionFactory(app());
|
|
||||||
|
|
||||||
return $factory->make($this->getDatabaseConfiguration()->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getAdmin(): AdminUser
|
|
||||||
{
|
|
||||||
return new AdminUser(
|
|
||||||
'admin',
|
|
||||||
'password',
|
|
||||||
'admin@example.com'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getSettings()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'forum_title' => 'Development Forum',
|
|
||||||
'mail_driver' => 'log',
|
|
||||||
'welcome_title' => 'Welcome to Development Forum',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,141 +0,0 @@
|
||||||
<?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\Test\Concerns;
|
|
||||||
|
|
||||||
use Flarum\Database\DatabaseMigrationRepository;
|
|
||||||
use Flarum\Database\Migrator;
|
|
||||||
use Flarum\Foundation\Application;
|
|
||||||
use Flarum\Foundation\InstalledSite;
|
|
||||||
use Flarum\Foundation\SiteInterface;
|
|
||||||
use Flarum\Foundation\UninstalledSite;
|
|
||||||
use Flarum\Http\Server;
|
|
||||||
use Flarum\Install\Console\DataProviderInterface;
|
|
||||||
use Flarum\Install\DatabaseConfig;
|
|
||||||
use Illuminate\Database\ConnectionInterface;
|
|
||||||
use Illuminate\Database\Connectors\MySqlConnector;
|
|
||||||
use Illuminate\Database\MySqlConnection;
|
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
|
|
||||||
trait CreatesForum
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Server
|
|
||||||
*/
|
|
||||||
protected $http;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var SiteInterface
|
|
||||||
*/
|
|
||||||
protected $site;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Application
|
|
||||||
*/
|
|
||||||
protected $app;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DataProviderInterface
|
|
||||||
*/
|
|
||||||
protected $configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the test set up Flarum as an installed app.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $isInstalled = true;
|
|
||||||
|
|
||||||
protected function createsSite()
|
|
||||||
{
|
|
||||||
$paths = [
|
|
||||||
'base' => __DIR__.'/../../tmp',
|
|
||||||
'public' => __DIR__.'/../../tmp/public',
|
|
||||||
'storage' => __DIR__.'/../../tmp/storage',
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($this->isInstalled) {
|
|
||||||
$this->site = new InstalledSite($paths, $this->getFlarumConfig());
|
|
||||||
} else {
|
|
||||||
$this->site = new UninstalledSite($paths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createsHttpForum()
|
|
||||||
{
|
|
||||||
$this->app = $this->site->bootApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getDatabaseConfiguration(): DatabaseConfig
|
|
||||||
{
|
|
||||||
return new DatabaseConfig(
|
|
||||||
'mysql',
|
|
||||||
env('DB_HOST', 'localhost'),
|
|
||||||
3306,
|
|
||||||
env('DB_DATABASE', 'flarum'),
|
|
||||||
env('DB_USERNAME', 'root'),
|
|
||||||
env('DB_PASSWORD', ''),
|
|
||||||
env('DB_PREFIX', '')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function refreshApplication()
|
|
||||||
{
|
|
||||||
$this->seedsDatabase();
|
|
||||||
|
|
||||||
$this->createsSite();
|
|
||||||
|
|
||||||
$this->createsHttpForum();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function teardownApplication()
|
|
||||||
{
|
|
||||||
/** @var ConnectionInterface $connection */
|
|
||||||
$connection = app(ConnectionInterface::class);
|
|
||||||
$connection->rollBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getFlarumConfig()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'debug' => true,
|
|
||||||
'database' => $this->getDatabaseConfiguration()->toArray(),
|
|
||||||
'url' => 'http://flarum.local',
|
|
||||||
'paths' => [
|
|
||||||
'api' => 'api',
|
|
||||||
'admin' => 'admin',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function seedsDatabase()
|
|
||||||
{
|
|
||||||
if (! $this->isInstalled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbConfig = $this->getDatabaseConfiguration()->toArray();
|
|
||||||
|
|
||||||
$pdo = (new MySqlConnector)->connect($dbConfig);
|
|
||||||
$db = new MySqlConnection($pdo, $dbConfig['database'], $dbConfig['prefix'], $dbConfig);
|
|
||||||
|
|
||||||
$repository = new DatabaseMigrationRepository($db, 'migrations');
|
|
||||||
$migrator = new Migrator($repository, $db, new Filesystem);
|
|
||||||
|
|
||||||
if (! $migrator->getRepository()->repositoryExists()) {
|
|
||||||
$migrator->getRepository()->createRepository();
|
|
||||||
}
|
|
||||||
|
|
||||||
$migrator->run(__DIR__.'/../../../migrations');
|
|
||||||
|
|
||||||
$db->beginTransaction();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
<?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\Test\Concerns;
|
|
||||||
|
|
||||||
use Flarum\Api\Client;
|
|
||||||
use Flarum\User\Guest;
|
|
||||||
use Flarum\User\User;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
|
|
||||||
trait MakesApiRequests
|
|
||||||
{
|
|
||||||
public function call(string $controller, User $actor = null, array $queryParams = [], array $body = []): ResponseInterface
|
|
||||||
{
|
|
||||||
/** @var Client $api */
|
|
||||||
$api = app(Client::class);
|
|
||||||
|
|
||||||
$api->setErrorHandler(null);
|
|
||||||
|
|
||||||
return $api->send($controller, $actor ?? new Guest, $queryParams, $body);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
<?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\Test\Concerns;
|
|
||||||
|
|
||||||
use Flarum\Post\CommentPost;
|
|
||||||
use Flarum\Post\Event\Posted;
|
|
||||||
|
|
||||||
trait ManagesContent
|
|
||||||
{
|
|
||||||
use RetrievesAuthorizedUsers;
|
|
||||||
|
|
||||||
protected function addPostByNormalUser(): CommentPost
|
|
||||||
{
|
|
||||||
$actor = $this->getNormalUser();
|
|
||||||
|
|
||||||
$post = CommentPost::reply(
|
|
||||||
$this->discussion->id,
|
|
||||||
'a normal reply - too-obscure',
|
|
||||||
$actor->id,
|
|
||||||
'127.0.0.1'
|
|
||||||
);
|
|
||||||
|
|
||||||
$post->save();
|
|
||||||
|
|
||||||
if (! $this->discussion->firstPost) {
|
|
||||||
$this->discussion->setFirstPost($post);
|
|
||||||
$this->discussion->setLastPost($post);
|
|
||||||
|
|
||||||
$this->discussion->save();
|
|
||||||
|
|
||||||
event(new Posted($post, $actor));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $post;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
<?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\Test\Concerns;
|
|
||||||
|
|
||||||
use Flarum\User\User;
|
|
||||||
|
|
||||||
trait RetrievesAuthorizedUsers
|
|
||||||
{
|
|
||||||
protected $userAttributes = [
|
|
||||||
'username' => 'normal',
|
|
||||||
'password' => 'too-obscure',
|
|
||||||
'email' => 'normal@machine.local'
|
|
||||||
];
|
|
||||||
|
|
||||||
public function getAdminUser(): User
|
|
||||||
{
|
|
||||||
return User::find(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNormalUser(): User
|
|
||||||
{
|
|
||||||
return User::unguarded(function () {
|
|
||||||
return User::firstOrCreate([
|
|
||||||
'username' => $this->userAttributes['username']
|
|
||||||
], $this->userAttributes);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?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\Test;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase as Test;
|
|
||||||
|
|
||||||
abstract class TestCase extends Test
|
|
||||||
{
|
|
||||||
use Concerns\CreatesForum,
|
|
||||||
Concerns\MakesApiRequests;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$this->refreshApplication();
|
|
||||||
$this->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function init()
|
|
||||||
{
|
|
||||||
// .. allows implementation by children without the need to call the parent.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
framework/core/tests/integration/TestCase.php
Normal file
81
framework/core/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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,13 +9,16 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Auth;
|
namespace Flarum\Tests\integration\api\Auth;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Flarum\Api\ApiKey;
|
use Flarum\Api\ApiKey;
|
||||||
|
use Flarum\Api\Client;
|
||||||
use Flarum\Api\Controller\CreateGroupController;
|
use Flarum\Api\Controller\CreateGroupController;
|
||||||
use Flarum\Tests\Test\Concerns\RetrievesAuthorizedUsers;
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use Flarum\Tests\integration\TestCase;
|
||||||
|
use Flarum\User\Guest;
|
||||||
|
use Flarum\User\User;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
@ -28,6 +31,18 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||||
{
|
{
|
||||||
use RetrievesAuthorizedUsers;
|
use RetrievesAuthorizedUsers;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
protected function key(int $user_id = null): ApiKey
|
protected function key(int $user_id = null): ApiKey
|
||||||
{
|
{
|
||||||
return ApiKey::unguarded(function () use ($user_id) {
|
return ApiKey::unguarded(function () use ($user_id) {
|
||||||
|
@ -45,9 +60,11 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function cannot_authorize_without_key()
|
public function cannot_authorize_without_key()
|
||||||
{
|
{
|
||||||
$this->call(
|
/** @var Client $api */
|
||||||
CreateGroupController::class
|
$api = $this->app()->getContainer()->make(Client::class);
|
||||||
);
|
$api->setErrorHandler(null);
|
||||||
|
|
||||||
|
$api->send(CreateGroupController::class, new Guest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +96,7 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function personal_api_token_cannot_authenticate_as_anyone()
|
public function personal_api_token_cannot_authenticate_as_anyone()
|
||||||
{
|
{
|
||||||
$user = $this->getNormalUser();
|
$user = User::find(2);
|
||||||
|
|
||||||
$key = $this->key($user->id);
|
$key = $this->key($user->id);
|
||||||
|
|
||||||
|
@ -105,7 +122,7 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function personal_api_token_authenticates_user()
|
public function personal_api_token_authenticates_user()
|
||||||
{
|
{
|
||||||
$user = $this->getNormalUser();
|
$user = User::find(2);
|
||||||
|
|
||||||
$key = $this->key($user->id);
|
$key = $this->key($user->id);
|
||||||
|
|
|
@ -9,10 +9,12 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Tests\Test\Concerns\RetrievesAuthorizedUsers;
|
use Flarum\Api\Client;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||||
|
use Flarum\Tests\integration\TestCase;
|
||||||
|
use Flarum\User\Guest;
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
@ -46,9 +48,13 @@ abstract class ApiControllerTestCase extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
public function call(string $controller, User $actor = null, array $queryParams = [], array $body = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$this->actor = null;
|
/** @var Client $api */
|
||||||
parent::tearDown();
|
$api = $this->app()->getContainer()->make(Client::class);
|
||||||
|
|
||||||
|
$api->setErrorHandler(null);
|
||||||
|
|
||||||
|
return $api->send($controller, $actor ?? new Guest, $queryParams, $body);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,11 +9,11 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\CreateDiscussionController;
|
use Flarum\Api\Controller\CreateDiscussionController;
|
||||||
use Flarum\Discussion\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Post\Post;
|
use Flarum\User\User;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class CreateDiscussionControllerTest extends ApiControllerTestCase
|
class CreateDiscussionControllerTest extends ApiControllerTestCase
|
||||||
|
@ -25,12 +25,31 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase
|
||||||
'content' => 'predetermined content for automated testing - too-obscure'
|
'content' => 'predetermined content for automated testing - too-obscure'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'discussions' => [],
|
||||||
|
'posts' => [],
|
||||||
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->adminGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 1, 'group_id' => 1],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function can_create_discussion()
|
public function can_create_discussion()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$response = $this->callWith($this->data);
|
$response = $this->callWith($this->data);
|
||||||
|
|
||||||
|
@ -51,7 +70,7 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function cannot_create_discussion_without_content()
|
public function cannot_create_discussion_without_content()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$data = Arr::except($this->data, 'content');
|
$data = Arr::except($this->data, 'content');
|
||||||
|
|
||||||
|
@ -65,18 +84,10 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function cannot_create_discussion_without_title()
|
public function cannot_create_discussion_without_title()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$data = Arr::except($this->data, 'title');
|
$data = Arr::except($this->data, 'title');
|
||||||
|
|
||||||
$this->callWith($data);
|
$this->callWith($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
Discussion::where('title', $this->data['title'])->delete();
|
|
||||||
// Prevent floodgate from kicking in.
|
|
||||||
Post::where('user_id', $this->getAdminUser()->id)->delete();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -9,10 +9,11 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\CreateGroupController;
|
use Flarum\Api\Controller\CreateGroupController;
|
||||||
use Flarum\Group\Group;
|
use Flarum\Group\Group;
|
||||||
|
use Flarum\User\User;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CreateGroupControllerTest extends ApiControllerTestCase
|
class CreateGroupControllerTest extends ApiControllerTestCase
|
||||||
|
@ -26,6 +27,24 @@ class CreateGroupControllerTest extends ApiControllerTestCase
|
||||||
'color' => null
|
'color' => null
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->adminGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 1, 'group_id' => 1],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @expectedException \Illuminate\Validation\ValidationException
|
* @expectedException \Illuminate\Validation\ValidationException
|
||||||
|
@ -33,7 +52,7 @@ class CreateGroupControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function admin_cannot_create_group_without_data()
|
public function admin_cannot_create_group_without_data()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$this->callWith();
|
$this->callWith();
|
||||||
}
|
}
|
||||||
|
@ -43,7 +62,7 @@ class CreateGroupControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function admin_can_create_group()
|
public function admin_can_create_group()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$response = $this->callWith($this->data);
|
$response = $this->callWith($this->data);
|
||||||
|
|
||||||
|
@ -65,14 +84,8 @@ class CreateGroupControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function unauthorized_user_cannot_create_group()
|
public function unauthorized_user_cannot_create_group()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getNormalUser();
|
$this->actor = User::find(2);
|
||||||
|
|
||||||
$this->callWith($this->data);
|
$this->callWith($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
Group::where('icon', $this->data['icon'])->delete();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -9,10 +9,11 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Flarum\Api\Controller\CreatePostController;
|
use Flarum\Api\Controller\CreatePostController;
|
||||||
use Flarum\Discussion\Discussion;
|
use Flarum\User\User;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class CreatePostControllerTest extends ApiControllerTestCase
|
class CreatePostControllerTest extends ApiControllerTestCase
|
||||||
|
@ -23,17 +24,28 @@ class CreatePostControllerTest extends ApiControllerTestCase
|
||||||
'content' => 'reply with predetermined content for automated testing - too-obscure'
|
'content' => 'reply with predetermined content for automated testing - too-obscure'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
public function setUp()
|
||||||
* @var Discussion
|
|
||||||
*/
|
|
||||||
protected $discussion;
|
|
||||||
|
|
||||||
protected function init()
|
|
||||||
{
|
{
|
||||||
$this->actor = $this->getNormalUser();
|
parent::setUp();
|
||||||
$this->discussion = Discussion::start(__CLASS__, $this->actor);
|
|
||||||
|
|
||||||
$this->discussion->save();
|
$this->prepareDatabase([
|
||||||
|
'discussions' => [
|
||||||
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
|
||||||
|
],
|
||||||
|
'posts' => [],
|
||||||
|
'users' => [
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->memberGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 2, 'group_id' => 3],
|
||||||
|
],
|
||||||
|
'group_permission' => [
|
||||||
|
['permission' => 'viewDiscussions', 'group_id' => 3],
|
||||||
|
]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,9 +53,11 @@ class CreatePostControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function can_create_reply()
|
public function can_create_reply()
|
||||||
{
|
{
|
||||||
|
$this->actor = User::find(2);
|
||||||
|
|
||||||
$body = [];
|
$body = [];
|
||||||
Arr::set($body, 'data.attributes', $this->data);
|
Arr::set($body, 'data.attributes', $this->data);
|
||||||
Arr::set($body, 'data.relationships.discussion.data.id', $this->discussion->id);
|
Arr::set($body, 'data.relationships.discussion.data.id', 1);
|
||||||
|
|
||||||
$response = $this->callWith($body);
|
$response = $this->callWith($body);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\CreateTokenController;
|
use Flarum\Api\Controller\CreateTokenController;
|
||||||
use Flarum\Http\AccessToken;
|
use Flarum\Http\AccessToken;
|
||||||
|
@ -18,24 +18,33 @@ class CreateTokenControllerTest extends ApiControllerTestCase
|
||||||
{
|
{
|
||||||
protected $controller = CreateTokenController::class;
|
protected $controller = CreateTokenController::class;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'users' => [
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function user_generates_token()
|
public function user_generates_token()
|
||||||
{
|
{
|
||||||
$user = $this->getNormalUser();
|
|
||||||
|
|
||||||
$response = $this->call($this->controller, null, [], [
|
$response = $this->call($this->controller, null, [], [
|
||||||
'identification' => $user->username,
|
'identification' => 'normal',
|
||||||
'password' => $this->userAttributes['password']
|
'password' => 'too-obscure'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$data = json_decode($response->getBody()->getContents(), true);
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
|
|
||||||
$this->assertEquals($user->id, $data['userId']);
|
$this->assertEquals(2, $data['userId']);
|
||||||
|
|
||||||
$token = $data['token'];
|
$token = $data['token'];
|
||||||
|
|
||||||
$this->assertEquals($user->id, AccessToken::findOrFail($token)->user_id);
|
$this->assertEquals(2, AccessToken::findOrFail($token)->user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\CreateUserController;
|
use Flarum\Api\Controller\CreateUserController;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
@ -26,6 +26,23 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
||||||
'email' => 'test@machine.local'
|
'email' => 'test@machine.local'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->adminGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 1, 'group_id' => 1],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @expectedException \Illuminate\Validation\ValidationException
|
* @expectedException \Illuminate\Validation\ValidationException
|
||||||
|
@ -60,7 +77,7 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function admins_can_create_activated_users()
|
public function admins_can_create_activated_users()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$response = $this->callWith(array_merge($this->data, [
|
$response = $this->callWith(array_merge($this->data, [
|
||||||
'isEmailConfirmed' => 1
|
'isEmailConfirmed' => 1
|
||||||
|
@ -90,10 +107,4 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
||||||
$settings->set('allow_sign_up', true);
|
$settings->set('allow_sign_up', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
User::where('username', $this->data['username'])->delete();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?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\api\Controller;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Flarum\Api\Controller\DeleteDiscussionController;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
|
class DeleteDiscussionControllerTest extends ApiControllerTestCase
|
||||||
|
{
|
||||||
|
protected $controller = DeleteDiscussionController::class;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'discussions' => [
|
||||||
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
|
||||||
|
],
|
||||||
|
'posts' => [],
|
||||||
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->adminGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 1, 'group_id' => 1],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function admin_can_delete()
|
||||||
|
{
|
||||||
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
|
$response = $this->callWith([], ['id' => 1]);
|
||||||
|
|
||||||
|
$this->assertEquals(204, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?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\api\Controller;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Flarum\Api\Controller\ListDiscussionsController;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
|
class ListDiscussionsControllerTest extends ApiControllerTestCase
|
||||||
|
{
|
||||||
|
protected $controller = ListDiscussionsController::class;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'discussions' => [
|
||||||
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1],
|
||||||
|
],
|
||||||
|
'posts' => [
|
||||||
|
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>'],
|
||||||
|
],
|
||||||
|
'users' => [
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->memberGroup(),
|
||||||
|
$this->guestGroup(),
|
||||||
|
],
|
||||||
|
'group_permission' => [
|
||||||
|
['permission' => 'viewDiscussions', 'group_id' => 2],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function shows_index_for_guest()
|
||||||
|
{
|
||||||
|
$response = $this->callWith();
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
|
|
||||||
|
$this->assertEquals(1, count($data['data']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function can_search_for_author()
|
||||||
|
{
|
||||||
|
$user = User::find(2);
|
||||||
|
|
||||||
|
$response = $this->callWith([], [
|
||||||
|
'filter' => [
|
||||||
|
'q' => 'author:'.$user->username.' foo'
|
||||||
|
],
|
||||||
|
'include' => 'mostRelevantPost'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\ListGroupsController;
|
use Flarum\Api\Controller\ListGroupsController;
|
||||||
use Flarum\Group\Group;
|
use Flarum\Group\Group;
|
|
@ -9,14 +9,26 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\ListNotificationsController;
|
use Flarum\Api\Controller\ListNotificationsController;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
class ListNotificationsControllerTest extends ApiControllerTestCase
|
class ListNotificationsControllerTest extends ApiControllerTestCase
|
||||||
{
|
{
|
||||||
protected $controller = ListNotificationsController::class;
|
protected $controller = ListNotificationsController::class;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'users' => [
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||||
|
@ -31,7 +43,7 @@ class ListNotificationsControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function show_index_for_user()
|
public function show_index_for_user()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getNormalUser();
|
$this->actor = User::find(2);
|
||||||
|
|
||||||
$response = $this->callWith();
|
$response = $this->callWith();
|
||||||
|
|
|
@ -9,14 +9,32 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\ListUsersController;
|
use Flarum\Api\Controller\ListUsersController;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
class ListUsersControllerTest extends ApiControllerTestCase
|
class ListUsersControllerTest extends ApiControllerTestCase
|
||||||
{
|
{
|
||||||
protected $controller = ListUsersController::class;
|
protected $controller = ListUsersController::class;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->adminGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 1, 'group_id' => 1],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||||
|
@ -31,7 +49,7 @@ class ListUsersControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function shows_index_for_admin()
|
public function shows_index_for_admin()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getAdminUser();
|
$this->actor = User::find(1);
|
||||||
|
|
||||||
$response = $this->callWith();
|
$response = $this->callWith();
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
<?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\api\Controller;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Flarum\Api\Controller\ShowDiscussionController;
|
||||||
|
use Flarum\Discussion\Discussion;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
|
class ShowDiscussionControllerTest extends ApiControllerTestCase
|
||||||
|
{
|
||||||
|
protected $controller = ShowDiscussionController::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Discussion
|
||||||
|
*/
|
||||||
|
protected $discussion;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareDatabase([
|
||||||
|
'discussions' => [
|
||||||
|
['id' => 1, 'title' => 'Empty discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0],
|
||||||
|
['id' => 2, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0],
|
||||||
|
['id' => 3, 'title' => 'Private discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 1],
|
||||||
|
],
|
||||||
|
'posts' => [
|
||||||
|
['id' => 1, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '<t><p>a normal reply - too-obscure</p></t>'],
|
||||||
|
],
|
||||||
|
'users' => [
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->guestGroup(),
|
||||||
|
$this->memberGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 2, 'group_id' => 3],
|
||||||
|
],
|
||||||
|
'group_permission' => [
|
||||||
|
['permission' => 'viewDiscussions', 'group_id' => 2],
|
||||||
|
['permission' => 'viewDiscussions', 'group_id' => 3],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function author_can_see_discussion()
|
||||||
|
{
|
||||||
|
$this->actor = User::find(2);
|
||||||
|
|
||||||
|
$response = $this->callWith([], ['id' => 1]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function guest_cannot_see_empty_discussion()
|
||||||
|
{
|
||||||
|
$response = $this->callWith([], ['id' => 1]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function guest_can_see_discussion()
|
||||||
|
{
|
||||||
|
$response = $this->callWith([], ['id' => 2]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function guests_cannot_see_private_discussion()
|
||||||
|
{
|
||||||
|
$this->callWith([], ['id' => 3]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,9 +9,10 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\integration\api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\UpdateUserController;
|
use Flarum\Api\Controller\UpdateUserController;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
class UpdateUserControllerTest extends ApiControllerTestCase
|
class UpdateUserControllerTest extends ApiControllerTestCase
|
||||||
{
|
{
|
||||||
|
@ -21,24 +22,41 @@ class UpdateUserControllerTest extends ApiControllerTestCase
|
||||||
'email' => 'newemail@machine.local',
|
'email' => 'newemail@machine.local',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $userAttributes = [
|
public function setUp()
|
||||||
'username' => 'timtom',
|
{
|
||||||
'password' => 'too-obscure',
|
parent::setUp();
|
||||||
'email' => 'timtom@machine.local',
|
|
||||||
'is_email_confirmed' => true,
|
$this->prepareDatabase([
|
||||||
];
|
'users' => [
|
||||||
|
$this->adminUser(),
|
||||||
|
$this->normalUser(),
|
||||||
|
],
|
||||||
|
'groups' => [
|
||||||
|
$this->adminGroup(),
|
||||||
|
$this->memberGroup(),
|
||||||
|
],
|
||||||
|
'group_user' => [
|
||||||
|
['user_id' => 1, 'group_id' => 1],
|
||||||
|
['user_id' => 2, 'group_id' => 3],
|
||||||
|
],
|
||||||
|
'group_permission' => [
|
||||||
|
['permission' => 'viewUserList', 'group_id' => 3],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function users_can_see_their_private_information()
|
public function users_can_see_their_private_information()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getNormalUser();
|
$this->actor = User::find(2);
|
||||||
$response = $this->callWith([], ['id' => $this->actor->id]);
|
|
||||||
|
$response = $this->callWith([], ['id' => 2]);
|
||||||
|
|
||||||
// Test for successful response and that the email is included in the response
|
// Test for successful response and that the email is included in the response
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$this->assertContains('timtom@machine.local', (string) $response->getBody());
|
$this->assertContains('normal@machine.local', (string) $response->getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,17 +64,12 @@ class UpdateUserControllerTest extends ApiControllerTestCase
|
||||||
*/
|
*/
|
||||||
public function users_can_not_see_other_users_private_information()
|
public function users_can_not_see_other_users_private_information()
|
||||||
{
|
{
|
||||||
$this->actor = $this->getNormalUser();
|
$this->actor = User::find(2);
|
||||||
|
|
||||||
$response = $this->callWith([], ['id' => 1]);
|
$response = $this->callWith([], ['id' => 1]);
|
||||||
|
|
||||||
// Make sure sensitive information is not made public
|
// Make sure sensitive information is not made public
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$this->assertNotContains('admin@example.com', (string) $response->getBody());
|
$this->assertNotContains('admin@machine.local', (string) $response->getBody());
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
74
framework/core/tests/integration/setup.php
Normal file
74
framework/core/tests/integration/setup.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Flarum\Install\AdminUser;
|
||||||
|
use Flarum\Install\DatabaseConfig;
|
||||||
|
use Flarum\Install\Installation;
|
||||||
|
|
||||||
|
require __DIR__.'/../../vendor/autoload.php';
|
||||||
|
|
||||||
|
$host = env('DB_HOST', 'localhost');
|
||||||
|
$port = intval(env('DB_PORT', 3306));
|
||||||
|
$name = env('DB_DATABASE', 'flarum_test');
|
||||||
|
$user = env('DB_USERNAME', 'root');
|
||||||
|
$pass = env('DB_PASSWORD', '');
|
||||||
|
$pref = env('DB_PREFIX', '');
|
||||||
|
|
||||||
|
echo "Connecting to database $name at $host:$port.\n";
|
||||||
|
echo "Logging in as $user with password '$pass'.\n";
|
||||||
|
echo "Table prefix: '$pref'\n";
|
||||||
|
|
||||||
|
echo "\n\nCancel now if that's not what you want...\n";
|
||||||
|
echo "Use the following environment variables for configuration:\n";
|
||||||
|
echo "DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_PREFIX\n";
|
||||||
|
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
echo "\nOff we go...\n";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup installation configuration
|
||||||
|
*/
|
||||||
|
|
||||||
|
$installation = new Installation(
|
||||||
|
__DIR__.'/tmp',
|
||||||
|
__DIR__.'/tmp/public',
|
||||||
|
__DIR__.'/tmp/storage'
|
||||||
|
);
|
||||||
|
|
||||||
|
$pipeline = $installation
|
||||||
|
->configPath('config.php')
|
||||||
|
->debugMode(true)
|
||||||
|
->baseUrl('http://localhost')
|
||||||
|
->databaseConfig(new DatabaseConfig(
|
||||||
|
'mysql',
|
||||||
|
env('DB_HOST', 'localhost'),
|
||||||
|
intval(env('DB_PORT', 3306)),
|
||||||
|
env('DB_DATABASE', 'flarum_test'),
|
||||||
|
env('DB_USERNAME', 'root'),
|
||||||
|
env('DB_PASSWORD', ''),
|
||||||
|
env('DB_PREFIX', '')
|
||||||
|
))
|
||||||
|
->adminUser(new AdminUser(
|
||||||
|
'admin',
|
||||||
|
'secret',
|
||||||
|
'admin@flarum.email'
|
||||||
|
))
|
||||||
|
->settings(['mail_driver' => 'log'])
|
||||||
|
->build();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run the actual configuration
|
||||||
|
*/
|
||||||
|
|
||||||
|
$pipeline->run();
|
||||||
|
|
||||||
|
echo "Installation complete\n";
|
|
@ -11,12 +11,8 @@
|
||||||
syntaxCheck="false">
|
syntaxCheck="false">
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="installation">
|
<testsuite name="Flarum Integration Tests">
|
||||||
<directory suffix="Test.php">./tests/Install</directory>
|
<directory suffix="Test.php">./integration</directory>
|
||||||
</testsuite>
|
|
||||||
<testsuite name="all">
|
|
||||||
<directory suffix="Test.php">./tests</directory>
|
|
||||||
<exclude>./tests/Install</exclude>
|
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<filter>
|
23
framework/core/tests/phpunit.unit.xml
Normal file
23
framework/core/tests/phpunit.unit.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<phpunit backupGlobals="false"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
syntaxCheck="false">
|
||||||
|
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Flarum Unit Tests">
|
||||||
|
<directory suffix="Test.php">./unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">./src/</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\FloodingExceptionHandler;
|
use Flarum\Api\ExceptionHandler\FloodingExceptionHandler;
|
||||||
use Flarum\Post\Exception\FloodingException;
|
use Flarum\Post\Exception\FloodingException;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class FloodingExceptionHandlerTest extends TestCase
|
class FloodingExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new FloodingExceptionHandler;
|
$this->handler = new FloodingExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler;
|
use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler;
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Illuminate\Translation\ArrayLoader;
|
use Illuminate\Translation\ArrayLoader;
|
||||||
use Illuminate\Translation\Translator;
|
use Illuminate\Translation\Translator;
|
||||||
use Illuminate\Validation\Factory;
|
use Illuminate\Validation\Factory;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class IlluminateValidationExceptionHandlerTest extends TestCase
|
class IlluminateValidationExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new IlluminateValidationExceptionHandler;
|
$this->handler = new IlluminateValidationExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\Exception\InvalidAccessTokenException;
|
use Flarum\Api\Exception\InvalidAccessTokenException;
|
||||||
use Flarum\Api\ExceptionHandler\InvalidAccessTokenExceptionHandler;
|
use Flarum\Api\ExceptionHandler\InvalidAccessTokenExceptionHandler;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class InvalidAccessTokenExceptionHandlerTest extends TestCase
|
class InvalidAccessTokenExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new InvalidAccessTokenExceptionHandler;
|
$this->handler = new InvalidAccessTokenExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler;
|
use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler;
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Flarum\User\Exception\InvalidConfirmationTokenException;
|
use Flarum\User\Exception\InvalidConfirmationTokenException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class InvalidConfirmationTokenExceptionHandlerTest extends TestCase
|
class InvalidConfirmationTokenExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new InvalidConfirmationTokenExceptionHandler;
|
$this->handler = new InvalidConfirmationTokenExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\MethodNotAllowedExceptionHandler;
|
use Flarum\Api\ExceptionHandler\MethodNotAllowedExceptionHandler;
|
||||||
use Flarum\Http\Exception\MethodNotAllowedException;
|
use Flarum\Http\Exception\MethodNotAllowedException;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class MethodNotAllowedExceptionHandlerTest extends TestCase
|
class MethodNotAllowedExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new MethodNotAllowedExceptionHandler();
|
$this->handler = new MethodNotAllowedExceptionHandler();
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\ModelNotFoundExceptionHandler;
|
use Flarum\Api\ExceptionHandler\ModelNotFoundExceptionHandler;
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ModelNotFoundExceptionHandlerTest extends TestCase
|
class ModelNotFoundExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new ModelNotFoundExceptionHandler;
|
$this->handler = new ModelNotFoundExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler;
|
use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler;
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Flarum\User\Exception\PermissionDeniedException;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class PermissionDeniedExceptionHandlerTest extends TestCase
|
class PermissionDeniedExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new PermissionDeniedExceptionHandler;
|
$this->handler = new PermissionDeniedExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\RouteNotFoundExceptionHandler;
|
use Flarum\Api\ExceptionHandler\RouteNotFoundExceptionHandler;
|
||||||
use Flarum\Http\Exception\RouteNotFoundException;
|
use Flarum\Http\Exception\RouteNotFoundException;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class RouteNotFoundExceptionHandlerTest extends TestCase
|
class RouteNotFoundExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new RouteNotFoundExceptionHandler();
|
$this->handler = new RouteNotFoundExceptionHandler();
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\TokenMismatchExceptionHandler;
|
use Flarum\Api\ExceptionHandler\TokenMismatchExceptionHandler;
|
||||||
use Flarum\Http\Exception\TokenMismatchException;
|
use Flarum\Http\Exception\TokenMismatchException;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class TokenMismatchExceptionHandlerTest extends TestCase
|
class TokenMismatchExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new TokenMismatchExceptionHandler;
|
$this->handler = new TokenMismatchExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Api\ExceptionHandler;
|
namespace Flarum\Tests\unit\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\ExceptionHandler\ValidationExceptionHandler;
|
use Flarum\Api\ExceptionHandler\ValidationExceptionHandler;
|
||||||
use Flarum\Foundation\ValidationException;
|
use Flarum\Foundation\ValidationException;
|
||||||
use Flarum\Tests\Test\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ValidationExceptionHandlerTest extends TestCase
|
class ValidationExceptionHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->handler = new ValidationExceptionHandler;
|
$this->handler = new ValidationExceptionHandler;
|
||||||
}
|
}
|
|
@ -9,19 +9,19 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Settings;
|
namespace Flarum\Tests\unit\Settings;
|
||||||
|
|
||||||
use Flarum\Settings\DatabaseSettingsRepository;
|
use Flarum\Settings\DatabaseSettingsRepository;
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DatabaseSettingsRepositoryTest extends TestCase
|
class DatabaseSettingsRepositoryTest extends TestCase
|
||||||
{
|
{
|
||||||
private $connection;
|
private $connection;
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->connection = m::mock(ConnectionInterface::class);
|
$this->connection = m::mock(ConnectionInterface::class);
|
||||||
$this->repository = new DatabaseSettingsRepository($this->connection);
|
$this->repository = new DatabaseSettingsRepository($this->connection);
|
|
@ -9,19 +9,19 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Tests\Settings;
|
namespace Flarum\Tests\unit\Settings;
|
||||||
|
|
||||||
use Flarum\Settings\MemoryCacheSettingsRepository;
|
use Flarum\Settings\MemoryCacheSettingsRepository;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Flarum\Tests\Test\TestCase;
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class MemoryCacheSettingsRepositoryTest extends TestCase
|
class MemoryCacheSettingsRepositoryTest extends TestCase
|
||||||
{
|
{
|
||||||
private $baseRepository;
|
private $baseRepository;
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
public function init()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->baseRepository = m::mock(SettingsRepositoryInterface::class);
|
$this->baseRepository = m::mock(SettingsRepositoryInterface::class);
|
||||||
$this->repository = new MemoryCacheSettingsRepository($this->baseRepository);
|
$this->repository = new MemoryCacheSettingsRepository($this->baseRepository);
|
Loading…
Reference in New Issue
Block a user