summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-01-29 12:15:16 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-01-29 12:15:16 +0000
commitd4c04956282de586ef4b5dcdf193f600967f0366 (patch)
treeb389b51d834076aa89d13c8a4064a63e3043ade0
parent056708d6fc4cd5dd2831180b825a86ca9dd76a0f (diff)
downloadwebtrees-d4c04956282de586ef4b5dcdf193f600967f0366.tar.gz
webtrees-d4c04956282de586ef4b5dcdf193f600967f0366.tar.bz2
webtrees-d4c04956282de586ef4b5dcdf193f600967f0366.zip
Testing
-rw-r--r--app/Module.php17
-rw-r--r--app/Module/ContactsFooterModule.php30
-rw-r--r--app/Module/CookieWarningModule.php20
-rw-r--r--app/Module/HitCountFooterModule.php48
-rw-r--r--app/Schema/SeedBlockTable.php87
-rw-r--r--app/Schema/SeedDatabase.php2
-rw-r--r--tests/TestCase.php11
7 files changed, 58 insertions, 157 deletions
diff --git a/app/Module.php b/app/Module.php
index 8e78f2903b..78e6e0bec3 100644
--- a/app/Module.php
+++ b/app/Module.php
@@ -329,23 +329,6 @@ class Module
}
/**
- * Boot all the modules.
- */
- public static function boot(): void
- {
- foreach (self::all() as $module) {
- if (method_exists($module, 'boot')) {
- try {
- app()->dispatch($module, 'boot');
- } catch (Throwable $ex) {
- $message = '<pre>' . e($ex->getMessage()) . "\n" . e($ex->getTraceAsString()) . '</pre>';
- FlashMessages::addMessage($message, 'danger');
- }
- }
- }
- }
-
- /**
* Load a module in a separate scope, to prevent it from modifying local variables.
*
* @param string $filename
diff --git a/app/Module/ContactsFooterModule.php b/app/Module/ContactsFooterModule.php
index bd3f12addc..0846cf5eba 100644
--- a/app/Module/ContactsFooterModule.php
+++ b/app/Module/ContactsFooterModule.php
@@ -39,6 +39,20 @@ class ContactsFooterModule extends AbstractModule implements ModuleFooterInterfa
protected $user;
/**
+ * Dependency injection.
+ *
+ * @param Tree|null $tree
+ * @param User $user
+ * @param Request $request
+ */
+ public function __construct(?Tree $tree, User $user, Request $request)
+ {
+ $this->tree = $tree;
+ $this->user = $user;
+ $this->request = $request;
+ }
+
+ /**
* How should this module be labelled on tabs, footers, etc.?
*
* @return string
@@ -60,21 +74,7 @@ class ContactsFooterModule extends AbstractModule implements ModuleFooterInterfa
return I18N::translate('A link to the site contacts.');
}
- /**
- * Dependency injection.
- *
- * @param Tree|null $tree
- * @param User $user
- * @param Request $request
- */
- public function boot(?Tree $tree, User $user, Request $request): void
- {
- $this->tree = $tree;
- $this->user = $user;
- $this->request = $request;
- }
-
- /**
+ /**
* The default position for this footer. It can be changed in the control panel.
*
* @return int
diff --git a/app/Module/CookieWarningModule.php b/app/Module/CookieWarningModule.php
index 3f9c22866c..88676334e6 100644
--- a/app/Module/CookieWarningModule.php
+++ b/app/Module/CookieWarningModule.php
@@ -41,6 +41,16 @@ class CookieWarningModule extends AbstractModule implements ModuleFooterInterfac
];
/**
+ * Dependency injection.
+ *
+ * @param Request $request
+ */
+ public function __construct(Request $request)
+ {
+ $this->request = $request;
+ }
+
+ /**
* How should this module be labelled on tabs, footers, etc.?
*
* @return string
@@ -63,16 +73,6 @@ class CookieWarningModule extends AbstractModule implements ModuleFooterInterfac
}
/**
- * Dependency injection.
- *
- * @param Request $request
- */
- public function boot(Request $request): void
- {
- $this->request = $request;
- }
-
- /**
* The default position for this footer. It can be changed in the control panel.
*
* @return int
diff --git a/app/Module/HitCountFooterModule.php b/app/Module/HitCountFooterModule.php
index ceb1b71f6f..85ca953026 100644
--- a/app/Module/HitCountFooterModule.php
+++ b/app/Module/HitCountFooterModule.php
@@ -57,35 +57,13 @@ class HitCountFooterModule extends AbstractModule implements ModuleFooterInterfa
protected $page_hits = 0;
/**
- * How should this module be labelled on tabs, footers, etc.?
- *
- * @return string
- */
- public function title(): string
- {
- /* I18N: Name of a module */
- return I18N::translate('Hit counters');
- }
-
- /**
- * A sentence describing what this module does.
- *
- * @return string
- */
- public function description(): string
- {
- /* I18N: Description of the “Hit counters” module */
- return I18N::translate('Count the visits to each page');
- }
-
- /**
* Dependency injection.
*
* @param Tree|null $tree
* @param User $user
* @param Request $request
*/
- public function boot(?Tree $tree, User $user, Request $request): void
+ public function __construct(?Tree $tree, User $user, Request $request)
{
$this->tree = $tree;
$this->user = $user;
@@ -103,7 +81,7 @@ class HitCountFooterModule extends AbstractModule implements ModuleFooterInterfa
case 'note':
case 'repository':
case 'source':
- $this->page_hits = $this->countHit($page_name, $request->get('xref', ''));
+ $this->page_hits = $this->countHit($page_name, $request->get('xref', ''));
break;
case 'tree-page':
@@ -118,6 +96,28 @@ class HitCountFooterModule extends AbstractModule implements ModuleFooterInterfa
}
/**
+ * How should this module be labelled on tabs, footers, etc.?
+ *
+ * @return string
+ */
+ public function title(): string
+ {
+ /* I18N: Name of a module */
+ return I18N::translate('Hit counters');
+ }
+
+ /**
+ * A sentence describing what this module does.
+ *
+ * @return string
+ */
+ public function description(): string
+ {
+ /* I18N: Description of the “Hit counters” module */
+ return I18N::translate('Count the visits to each page');
+ }
+
+ /**
* The default position for this footer. It can be changed in the control panel.
*
* @return int
diff --git a/app/Schema/SeedBlockTable.php b/app/Schema/SeedBlockTable.php
deleted file mode 100644
index 40045d0e15..0000000000
--- a/app/Schema/SeedBlockTable.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-/**
- * webtrees: online genealogy
- * Copyright (C) 2019 webtrees development team
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-declare(strict_types=1);
-
-namespace Fisharebest\Webtrees\Schema;
-
-use Illuminate\Database\Capsule\Manager as DB;
-
-/**
- * Populate the block table
- */
-class SeedBlockTable implements SeedInterface
-{
- private const DEFAULT_TREE_PAGE_BLOCKS = [
- 'main' => [
- 1 => 'gedcom_stats',
- 2 => 'gedcom_news',
- 3 => 'gedcom_favorites',
- 4 => 'review_changes',
- ],
- 'side' => [
- 1 => 'gedcom_block',
- 2 => 'random_media',
- 3 => 'todays_events',
- 4 => 'logged_in',
- ],
- ];
-
- private const DEFAULT_USER_PAGE_BLOCKS = [
- 'main' => [
- 1 => 'todays_events',
- 2 => 'user_messages',
- 3 => 'user_favorites',
- ],
- 'side' => [
- 1 => 'user_welcome',
- 2 => 'random_media',
- 3 => 'upcoming_events',
- 4 => 'logged_in',
- ],
- ];
-
- /**
- * Run the seeder.
- *
- * @return void
- */
- public function run(): void
- {
- // Set default blocks for new trees
- foreach (self::DEFAULT_TREE_PAGE_BLOCKS as $location => $blocks) {
- foreach ($blocks as $block_order => $module_name) {
- DB::table('block')->insert([
- 'gedcom_id' => -1,
- 'location' => $location,
- 'block_order' => $block_order,
- 'module_name' => $module_name,
- ]);
- }
- }
-
- // Set default blocks for new user
- foreach (self::DEFAULT_USER_PAGE_BLOCKS as $location => $blocks) {
- foreach ($blocks as $block_order => $module_name) {
- DB::table('block')->insert([
- 'user_id' => -1,
- 'location' => $location,
- 'block_order' => $block_order,
- 'module_name' => $module_name,
- ]);
- }
- }
- }
-}
diff --git a/app/Schema/SeedDatabase.php b/app/Schema/SeedDatabase.php
index 9940986ea0..6b86331050 100644
--- a/app/Schema/SeedDatabase.php
+++ b/app/Schema/SeedDatabase.php
@@ -36,7 +36,5 @@ class SeedDatabase implements SeedInterface
(new SeedGedcomTable())->run();
(new SeedGedcomSettingTable())->run();
(new SeedDefaultResnTable())->run();
- Module::all();
- (new SeedBlockTable())->run();
}
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index d9af1c0373..4ee969256a 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -24,6 +24,7 @@ use Illuminate\Cache\ArrayStore;
use Illuminate\Cache\Repository;
use Illuminate\Database\Capsule\Manager as DB;
use function basename;
+use Symfony\Component\HttpFoundation\Request;
/**
* Base class for unit tests
@@ -69,6 +70,14 @@ class TestCase extends \PHPUnit\Framework\TestCase
// Use an array cache for database calls, etc.
app()->instance('cache.array', new Repository(new ArrayStore()));
+ app()->bind(Tree::class, function () {
+ return null;
+ });
+
+ app()->instance(User::class, User::visitor());
+
+ app()->instance(Request::class, Request::createFromGlobals());
+
defined('WT_ROOT') || define('WT_ROOT', dirname(__DIR__) . '/');
defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/');
defined('WT_DATA_DIR') || define('WT_DATA_DIR', WT_ROOT . 'data/');
@@ -76,8 +85,6 @@ class TestCase extends \PHPUnit\Framework\TestCase
if (static::$uses_database) {
DB::connection()->beginTransaction();
-
- Module::boot();
}
}