commit 0b657c0b4c0a0fff3b588917d65f555619d2a929 Author: Toby Zerner Date: Sat Dec 20 16:56:46 2014 +1030 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. diff --git a/php-packages/testing/.editorconfig b/php-packages/testing/.editorconfig new file mode 100644 index 000000000..658a43499 --- /dev/null +++ b/php-packages/testing/.editorconfig @@ -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 diff --git a/php-packages/testing/.gitattributes b/php-packages/testing/.gitattributes new file mode 100644 index 000000000..ccbdf6188 --- /dev/null +++ b/php-packages/testing/.gitattributes @@ -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 diff --git a/php-packages/testing/.gitignore b/php-packages/testing/.gitignore new file mode 100644 index 000000000..56b9aaf7d --- /dev/null +++ b/php-packages/testing/.gitignore @@ -0,0 +1,9 @@ +/vendor +composer.lock +composer.phar +node_modules +.DS_Store +Thumbs.db +/tests/integration/tmp +.vagrant +.idea/* diff --git a/php-packages/testing/.styleci.yml b/php-packages/testing/.styleci.yml new file mode 100644 index 000000000..5d07e31ea --- /dev/null +++ b/php-packages/testing/.styleci.yml @@ -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" diff --git a/php-packages/testing/LICENSE b/php-packages/testing/LICENSE new file mode 100755 index 000000000..4bc2a96d2 --- /dev/null +++ b/php-packages/testing/LICENSE @@ -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. diff --git a/php-packages/testing/tests/integration/RetrievesAuthorizedUsers.php b/php-packages/testing/tests/integration/RetrievesAuthorizedUsers.php new file mode 100644 index 000000000..135ef7bec --- /dev/null +++ b/php-packages/testing/tests/integration/RetrievesAuthorizedUsers.php @@ -0,0 +1,70 @@ + + * + * 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, + ]; + } +} diff --git a/php-packages/testing/tests/integration/TestCase.php b/php-packages/testing/tests/integration/TestCase.php new file mode 100644 index 000000000..9d199564e --- /dev/null +++ b/php-packages/testing/tests/integration/TestCase.php @@ -0,0 +1,81 @@ + + * + * 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(); + } +} diff --git a/php-packages/testing/tests/integration/tmp/public/assets/.gitkeep b/php-packages/testing/tests/integration/tmp/public/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/php-packages/testing/tests/integration/tmp/storage/.gitkeep b/php-packages/testing/tests/integration/tmp/storage/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/php-packages/testing/tests/integration/tmp/storage/formatter/.gitkeep b/php-packages/testing/tests/integration/tmp/storage/formatter/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/php-packages/testing/tests/integration/tmp/storage/sessions/.gitkeep b/php-packages/testing/tests/integration/tmp/storage/sessions/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/php-packages/testing/tests/integration/tmp/vendor/composer/installed.json b/php-packages/testing/tests/integration/tmp/vendor/composer/installed.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/php-packages/testing/tests/integration/tmp/vendor/composer/installed.json @@ -0,0 +1 @@ +{}