diff --git a/tests/admin/ControllerRetailcrmAdminTest.php b/tests/admin/ControllerRetailcrmAdminTest.php index cfdec6b..de76d0e 100644 --- a/tests/admin/ControllerRetailcrmAdminTest.php +++ b/tests/admin/ControllerRetailcrmAdminTest.php @@ -41,4 +41,62 @@ class ControllerRetailcrmAdminTest extends TestCase $response = $this->dispatchAction('extension/module/retailcrm/uninstall_collector'); $this->assertRegExp('/Connection settings/', $response->getOutput()); } + + public function testGetAvailableTypes() + { + $data = $this->getDataForTestAvailableTypes(); + $sites = $data['sites']; + $types = $data['types']; + + $class = new ReflectionClass(ControllerExtensionModuleRetailcrm::class); + $method = $class->getMethod('getAvailableTypes'); + $method->setAccessible(true); + + $result = $method->invokeArgs(ControllerExtensionModuleRetailcrm::class, [$sites, $types]); + + $this->assertNotEmpty($result['opencart']); + $this->assertNotEmpty($result['retailcrm']); + $this->assertCount(2, $result['retailcrm']); + $this->assertNotEmpty($result['retailcrm']['test1']['code']); + $this->assertNotEmpty($result['retailcrm']['test4']['code']); + } + + private function getDataForTestAvailableTypes(): array + { + return [ + 'sites' => [ + 'opencart' => [ + 'code' => 'opencart', + 'name' => 'OpenCart' + ] + ], + 'types' => [ + 'opencart' => [ + 'test' + ], + 'retailcrm' => [ + 'test1' => [ + 'active' => true, + 'sites' => [], + 'code' => 'test1' + ], + 'test2' => [ + 'active' => false, + 'sites' => [], + 'code' => 'test2' + ], + 'test3' => [ + 'active' => true, + 'sites' => ['otherSite'], + 'code' => 'test3' + ], + 'test4' => [ + 'active' => 'true', + 'sites' => ['cms1', 'cms2', 'opencart'], + 'code' => 'test4' + ] + ] + ] + ]; + } }