diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-14 06:13:41 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-22 23:34:20 +0300 |
commit | ffaa1205fc781994b4c73c6c46fca1c521bd205d (patch) | |
tree | ba77204ece0fc5c9f1f4419a90ef261c2377cd28 /lib | |
parent | 9980fd09cbc8e5968f660be755ea6bfdc7906509 (diff) |
Remove useless tests - they test app bootstrapping which should be tested in the server
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 31 | ||||
-rw-r--r-- | lib/Listener/AppEnabledListener.php | 49 | ||||
-rw-r--r-- | lib/Listener/BeforeFilesAppTemplateRenderedListener.php (renamed from lib/Listener/LoadAdditionalScriptsListener.php) | 8 | ||||
-rw-r--r-- | lib/Listener/BeforeTemplateRenderedListener.php (renamed from lib/Listener/LoadAdditionalScriptsLoggedInListener.php) | 9 | ||||
-rw-r--r-- | lib/Notification/AppHint.php | 16 |
5 files changed, 70 insertions, 43 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0ea0a526..333df9f2 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -24,41 +24,32 @@ namespace OCA\FirstRunWizard\AppInfo; use OCA\Files\Event\LoadAdditionalScriptsEvent; -use OCA\FirstRunWizard\Listener\LoadAdditionalScriptsListener; -use OCA\FirstRunWizard\Listener\LoadAdditionalScriptsLoggedInListener; -use OCA\FirstRunWizard\Notification\AppHint; +use OCA\FirstRunWizard\Listener\AppEnabledListener; +use OCA\FirstRunWizard\Listener\BeforeFilesAppTemplateRenderedListener; +use OCA\FirstRunWizard\Listener\BeforeTemplateRenderedListener; use OCA\FirstRunWizard\Notification\Notifier; +use OCP\App\ManagerEvent; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\AppFramework\Http\Events\LoadAdditionalScriptsLoggedInEvent; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; class Application extends App implements IBootstrap { - /** @var bool */ - protected $isCLI; - public function __construct() { parent::__construct('firstrunwizard'); - $this->isCLI = \OC::$CLI; } public function register(IRegistrationContext $context): void { - // Display the first run wizard only on the files app - $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); - $context->registerEventListener(LoadAdditionalScriptsLoggedInEvent::class, LoadAdditionalScriptsLoggedInListener::class); + $context->registerEventListener(ManagerEvent::EVENT_APP_ENABLE, AppEnabledListener::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + // Display the first run wizard only on the files app, + $context->registerEventListener(LoadAdditionalScriptsEvent::class, BeforeFilesAppTemplateRenderedListener::class); } public function boot(IBootContext $context): void { - if (!$this->isCLI) { - $serverContainer = $context->getServerContainer(); - $serverContainer->getNotificationManager()->registerNotifierService(Notifier::class); - - $appContainer = $context->getAppContainer(); - /** @var AppHint $appHint */ - $appHint = $appContainer->query(AppHint::class); - $appHint->registerAppListener(); - } + $serverContainer = $context->getServerContainer(); + $serverContainer->getNotificationManager()->registerNotifierService(Notifier::class); } } diff --git a/lib/Listener/AppEnabledListener.php b/lib/Listener/AppEnabledListener.php new file mode 100644 index 00000000..a4ca125f --- /dev/null +++ b/lib/Listener/AppEnabledListener.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> + * + * @author Morris Jobke <hey@morrisjobke.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\FirstRunWizard\Listener; + +use OCA\FirstRunWizard\Notification\AppHint; +use OCP\App\ManagerEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +class AppEnabledListener implements IEventListener { + /** @var AppHint */ + private $appHint; + + public function __construct(AppHint $appHint) { + $this->appHint = $appHint; + } + + public function handle(Event $event): void { + if (!$event instanceof ManagerEvent) { + return; + } + + $this->appHint->dismissNotification($event->getAppID()); + } +} diff --git a/lib/Listener/LoadAdditionalScriptsListener.php b/lib/Listener/BeforeFilesAppTemplateRenderedListener.php index b9bccab3..5730c6d8 100644 --- a/lib/Listener/LoadAdditionalScriptsListener.php +++ b/lib/Listener/BeforeFilesAppTemplateRenderedListener.php @@ -26,8 +26,8 @@ declare(strict_types=1); namespace OCA\FirstRunWizard\Listener; -use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\FirstRunWizard\Notification\AppHint; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\BackgroundJob\IJobList; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -35,7 +35,7 @@ use OCP\IConfig; use OCP\IUser; use OCP\IUserSession; -class LoadAdditionalScriptsListener implements IEventListener { +class BeforeFilesAppTemplateRenderedListener implements IEventListener { /** @var IUserSession */ private $userSession; /** @var IConfig */ @@ -58,10 +58,6 @@ class LoadAdditionalScriptsListener implements IEventListener { } public function handle(Event $event): void { - if (!($event instanceof LoadAdditionalScriptsEvent)) { - return; - } - $user = $this->userSession->getUser(); if (!$user instanceof IUser) { return; diff --git a/lib/Listener/LoadAdditionalScriptsLoggedInListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index ae39c66e..0de4b845 100644 --- a/lib/Listener/LoadAdditionalScriptsLoggedInListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -26,13 +26,16 @@ declare(strict_types=1); namespace OCA\FirstRunWizard\Listener; -use OCP\AppFramework\Http\Events\LoadAdditionalScriptsLoggedInEvent; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -class LoadAdditionalScriptsLoggedInListener implements IEventListener { +class BeforeTemplateRenderedListener implements IEventListener { + public function __construct() { + } + public function handle(Event $event): void { - if (!($event instanceof LoadAdditionalScriptsLoggedInEvent)) { + if (!$event instanceof BeforeTemplateRenderedEvent || !$event->isLoggedIn()) { return; } diff --git a/lib/Notification/AppHint.php b/lib/Notification/AppHint.php index 6e0351b2..b1473f06 100644 --- a/lib/Notification/AppHint.php +++ b/lib/Notification/AppHint.php @@ -24,8 +24,6 @@ namespace OCA\FirstRunWizard\Notification; use OCP\App\IAppManager; -use OCP\App\ManagerEvent; -use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; use OCP\Notification\IManager as INotificationManager; @@ -44,20 +42,16 @@ class AppHint { /** @var IConfig */ protected $config; - /** @var IEventDispatcher */ - private $dispatcher; - /** @var string */ private $userId; const APP_HINT_VERSION = '18'; - public function __construct(INotificationManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IConfig $config, IEventDispatcher $eventDispatcher, $userId) { + public function __construct(INotificationManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IConfig $config, $userId) { $this->notificationManager = $notificationManager; $this->groupManager = $groupManager; $this->appManager =$appManager; $this->config = $config; - $this->dispatcher = $eventDispatcher; $this->userId = $userId; } @@ -72,12 +66,6 @@ class AppHint { } } - public function registerAppListener(): void { - $this->dispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) { - $this->dismissNotification($event->getAppID()); - }); - } - protected function sendNotification(string $app, string $user): void { $notification = $this->generateNotification($app, $user); if ( @@ -93,7 +81,7 @@ class AppHint { } } - protected function dismissNotification(string $app) { + public function dismissNotification(string $app) { $notification = $this->notificationManager->createNotification(); $notification->setApp('firstrunwizard') ->setSubject('apphint-'. $app) |