-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement: Add checks for Hyvä to the self tests
- Loading branch information
1 parent
96fdc1f
commit 321b1a9
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Mollie\SelfTests; | ||
|
||
use Magento\Framework\Module\Manager; | ||
|
||
class AreHyvaModulesInstalled extends AbstractSelfTest | ||
{ | ||
/** | ||
* @var Manager | ||
*/ | ||
private $moduleManager; | ||
|
||
public function __construct( | ||
Manager $moduleManager | ||
) { | ||
$this->moduleManager = $moduleManager; | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
if (!$this->moduleManager->isEnabled('Hyva_Theme')) { | ||
return; | ||
} | ||
|
||
if (!$this->moduleManager->isEnabled('Mollie_HyvaCompatibility')) { | ||
$this->addMessage('error', __('The <a href="https://github.com/mollie/magento2-hyva-compatibility" target="_blank">Mollie Hyvä Compatibility</a> module is not installed. Please install this module to use Mollie with the Hyvä Theme.')); | ||
} | ||
|
||
if ($this->moduleManager->isEnabled('Hyva_Checkout') && | ||
!$this->moduleManager->isEnabled('Mollie_HyvaCheckout') | ||
) { | ||
$this->addMessage('error', __('You have installed the Hyvä Checkout module, but not the Mollie Hyvä Checkout module. Please install this module to use Mollie with the Hyvä Checkout.')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Mollie\SelfTests; | ||
|
||
use Hyva\Theme\Model\HyvaModulesConfig; | ||
use Magento\Framework\Filesystem\Io\File; | ||
use Magento\Framework\Module\Manager; | ||
|
||
class IsHyvaThemesJsonCorrect extends AbstractSelfTest | ||
{ | ||
/** | ||
* @var Manager | ||
*/ | ||
private $moduleManager; | ||
/** | ||
* @var File | ||
*/ | ||
private $file; | ||
|
||
public function __construct( | ||
Manager $moduleManager, | ||
File $file | ||
) { | ||
$this->moduleManager = $moduleManager; | ||
$this->file = $file; | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
if (!$this->moduleManager->isEnabled('Hyva_Theme') || | ||
!class_exists(HyvaModulesConfig::class) | ||
) { | ||
return; | ||
} | ||
|
||
$file = HyvaModulesConfig::FILE; | ||
$path = HyvaModulesConfig::PATH; | ||
|
||
$path = trim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; | ||
// @phpstan-ignore-next-line | ||
$fullPath = BP . DIRECTORY_SEPARATOR . $path . strtolower($file); | ||
|
||
$contents = $this->file->read($fullPath); | ||
|
||
if ($contents === false) { | ||
$this->addMessage('error', __('The Hyva Themes configuration file is missing. Please run the command `bin/magento hyva:modules:config:generate` to generate the file.')); | ||
return; | ||
} | ||
|
||
try { | ||
$json = json_decode($contents, true, 512, JSON_THROW_ON_ERROR); | ||
$this->validateThatModuleIsPresent($json, 'Mollie_HyvaCompatibility'); | ||
$this->validateThatModuleIsPresent($json, 'Mollie_HyvaCheckout'); | ||
} catch (\Exception $exception) { | ||
$this->addMessage('error', __('The Hyva Themes configuration file is not a valid JSON file. Please run the command `bin/magento hyva:modules:config:generate` to generate the file.')); | ||
} | ||
} | ||
|
||
private function validateThatModuleIsPresent(array $json, string $module): void | ||
{ | ||
if (!$this->moduleManager->isEnabled($module)) { | ||
return; | ||
} | ||
|
||
foreach ($json['extensions'] as $extension) { | ||
if (strpos($extension['src'], $module) !== false) { | ||
return; | ||
} | ||
} | ||
|
||
$this->addMessage('error', __( | ||
'The %1 module is not present in the Hyva Themes configuration file. Please run the command `bin/magento hyva:modules:config:generate` to generate the file.', | ||
$module | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters