From 3ba3f880768d4a31d1663a39c764395e082e4d8a Mon Sep 17 00:00:00 2001 From: Bugo Date: Mon, 16 Dec 2024 18:57:52 +0500 Subject: [PATCH] Refactor code --- src/Sources/Optimus/Handlers/CoreHandler.php | 45 +++++++++++++++++++ .../Optimus/Handlers/HandlerLoader.php | 1 + src/Sources/Optimus/Prime.php | 20 --------- src/Sources/Optimus/Utils/Copyright.php | 4 +- tests/Handlers/CoreHandlerTest.php | 23 ++++++++++ tests/PrimeTest.php | 18 +------- tests/Utils/CopyrightTest.php | 9 +--- 7 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 src/Sources/Optimus/Handlers/CoreHandler.php create mode 100644 tests/Handlers/CoreHandlerTest.php diff --git a/src/Sources/Optimus/Handlers/CoreHandler.php b/src/Sources/Optimus/Handlers/CoreHandler.php new file mode 100644 index 0000000..544e087 --- /dev/null +++ b/src/Sources/Optimus/Handlers/CoreHandler.php @@ -0,0 +1,45 @@ +dispatch(new AddonEvent(AddonInterface::HOOK_EVENT, $this)); } - - public function loadTheme(): void - { - Lang::load('Optimus/Optimus'); - } - - public function credits(): void - { - Utils::$context['credits_modifications'][] = Copyright::getLink() . Copyright::getYears(); - } } diff --git a/src/Sources/Optimus/Utils/Copyright.php b/src/Sources/Optimus/Utils/Copyright.php index 5279b2d..9885b92 100644 --- a/src/Sources/Optimus/Utils/Copyright.php +++ b/src/Sources/Optimus/Utils/Copyright.php @@ -30,10 +30,10 @@ public static function getLink(): string ->setAttribute('target', '_blank') ->setAttribute('rel', 'noopener') ->setAttribute('title', OP_VERSION) - ->toHtml(); + ->toHtml() . self::getYears(); } - public static function getYears(): string + protected static function getYears(): string { return ' © 2010–' . date('Y') . ', Bugo'; } diff --git a/tests/Handlers/CoreHandlerTest.php b/tests/Handlers/CoreHandlerTest.php new file mode 100644 index 0000000..971ae22 --- /dev/null +++ b/tests/Handlers/CoreHandlerTest.php @@ -0,0 +1,23 @@ +handler = new CoreHandler(); +}); + +it('loads languages', function () { + $this->handler->loadTheme(); + + expect(Lang::$txt['optimus_title']) + ->toEqual('Search Engine Optimization'); +}); + +it('adds copyright', function () { + $this->handler->credits(); + + expect(Utils::$context['credits_modifications']) + ->not->toBeEmpty(); +}); diff --git a/tests/PrimeTest.php b/tests/PrimeTest.php index bb53bbd..fd9fbbd 100644 --- a/tests/PrimeTest.php +++ b/tests/PrimeTest.php @@ -1,27 +1,11 @@ prime = new Prime(); + $this->prime = new Prime(); }); it('runs __invoke', function () { expect((new Prime())())->toBeNull(); }); - -it('loads languages', function () { - $this->prime->loadTheme(); - - expect(Lang::$txt['optimus_title']) - ->toEqual('Search Engine Optimization'); -}); - -it('adds copyright', function () { - $this->prime->credits(); - - expect(Utils::$context['credits_modifications']) - ->not->toBeEmpty(); -}); diff --git a/tests/Utils/CopyrightTest.php b/tests/Utils/CopyrightTest.php index 2d65341..fa12163 100644 --- a/tests/Utils/CopyrightTest.php +++ b/tests/Utils/CopyrightTest.php @@ -14,13 +14,8 @@ $link = Copyright::getLink(); - expect($link)->toContain('https://dragomano.ru/mods/optimus'); + expect($link)->toContain('https://dragomano.ru/mods/optimus') + ->and($link)->toContain(' © 2010–' . date('Y') . ', Bugo'); unset(Lang::$txt['lang_dictionary']); }); - -it('gets years', function () { - $years = Copyright::getYears(); - - expect($years)->toEqual(' © 2010–' . date('Y') . ', Bugo'); -});