-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e08891
commit 12a2e9e
Showing
12 changed files
with
4,270 additions
and
1,455 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Tests\Mock; | ||
|
||
use Tab; | ||
|
||
/** | ||
* @see \PrestaShopBundle\Entity\Repository\TabRepository | ||
*/ | ||
final class MockPsTabRepository extends MockPsEntityRepository | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(Tab::class); | ||
} | ||
|
||
/** | ||
* @param string $moduleName | ||
* | ||
* @return Tab[] | ||
*/ | ||
public function findByModule(string $moduleName): array | ||
{ | ||
return $this | ||
->findBy(['module' => $moduleName]) | ||
->all(); | ||
} | ||
|
||
/** | ||
* @param int $idParent | ||
* | ||
* @return Tab[] | ||
*/ | ||
public function findByParentId(int $idParent): array | ||
{ | ||
return $this | ||
->findBy(['idParent' => $idParent]) | ||
->all(); | ||
} | ||
|
||
/** | ||
* @param string $className | ||
* | ||
* @return Tab|null | ||
*/ | ||
public function findOneByClassName(string $className): ?Tab | ||
{ | ||
return $this->findOneBy(['className' => $className]); | ||
} | ||
|
||
/** | ||
* @param string $className | ||
* | ||
* @return int|null | ||
*/ | ||
public function findOneIdByClassName(string $className) | ||
{ | ||
$tab = $this->findOneByClassName($className); | ||
|
||
if ($tab) { | ||
return $tab->getId(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/Unit/Pdk/Installer/Service/PsInstallerServiceTest.php
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,48 @@ | ||
<?php | ||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
|
||
/** @noinspection StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Pdk\Installer\Service; | ||
|
||
use MyParcelNL\Pdk\Facade\Installer; | ||
use MyParcelNL\Pdk\Facade\Pdk; | ||
use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPlugin; | ||
use MyParcelNL\Sdk\src\Support\Collection; | ||
use Tab; | ||
use function MyParcelNL\Pdk\Tests\usesShared; | ||
use function MyParcelNL\PrestaShop\psFactory; | ||
|
||
usesShared(new UsesMockPlugin()); | ||
|
||
it('installs tabs', function () { | ||
/** @var \MyParcelNL $module */ | ||
$module = Pdk::get('moduleInstance'); | ||
/** @var \PrestaShopBundle\Entity\Repository\TabRepository $tabRepository */ | ||
$tabRepository = Pdk::get('ps.tabRepository'); | ||
|
||
expect($tabRepository->findAll())->toBeEmpty(); | ||
Installer::install($module); | ||
|
||
$this->assertMatchesJsonSnapshot( | ||
json_encode((new Collection($tabRepository->findByModule($module->name)))->toArray()) | ||
); | ||
}); | ||
|
||
it('doesn\'t add same tab twice', function () { | ||
/** @var \MyParcelNL $module */ | ||
$module = Pdk::get('moduleInstance'); | ||
/** @var \PrestaShopBundle\Entity\Repository\TabRepository $tabRepository */ | ||
$tabRepository = Pdk::get('ps.tabRepository'); | ||
|
||
psFactory(Tab::class) | ||
->withModule($module->name) | ||
->withClassName(Pdk::get('legacyControllerSettings')) | ||
->store(); | ||
|
||
expect($tabRepository->findByModule($module->name))->toHaveCount(1); | ||
Installer::install($module); | ||
expect($tabRepository->findByModule($module->name))->toHaveCount(1); | ||
}); |
15 changes: 15 additions & 0 deletions
15
tests/__snapshots__/PsInstallerServiceTest__it_installs_tabs__1.json
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,15 @@ | ||
{ | ||
"1": { | ||
"id_lang": null, | ||
"id_shop": null, | ||
"active": 1, | ||
"class_name": "MyParcelNLAdminSettings", | ||
"route_name": "myparcelnl_settings", | ||
"name": { | ||
"1": "MyParcelNL" | ||
}, | ||
"id_parent": null, | ||
"module": "myparcelnl", | ||
"id": 1 | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use MyParcelNL\PrestaShop\Tests\Factory\AbstractPsObjectModelFactory; | ||
use MyParcelNL\PrestaShop\Tests\Factory\Contract\WithLang; | ||
use MyParcelNL\PrestaShop\Tests\Factory\Contract\WithShop; | ||
|
||
/** | ||
* @method $this withIdParent(int $idParent) | ||
* @method $this withActive(bool $active) | ||
* @method $this withClassName(string $className) | ||
* @method $this withModule(string $module) | ||
* @method $this withName(array $name) | ||
* @method $this withRouteName(string $routeName) | ||
*/ | ||
final class TabFactory extends AbstractPsObjectModelFactory implements WithLang, WithShop | ||
{ | ||
protected function getObjectModelClass(): string | ||
{ | ||
return Tab::class; | ||
} | ||
} |
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
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