2018-06-13 16:13:08 +03:00
|
|
|
<?php
|
|
|
|
|
2020-02-19 21:50:16 +03:00
|
|
|
require_once __DIR__ . '/../' . getenv('TEST_SUITE') . '/TestCase.php';
|
2020-02-19 12:37:03 +03:00
|
|
|
|
|
|
|
class ControllerRetailcrmAdminTest extends TestCase
|
2018-06-13 16:13:08 +03:00
|
|
|
{
|
|
|
|
const MODULE_TITLE = 'retailcrm';
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2020-02-20 15:26:18 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2018-06-13 16:13:08 +03:00
|
|
|
$query = $this->db->query("SELECT permission from ".DB_PREFIX."user_group WHERE name = 'Administrator'");
|
|
|
|
$permissions = json_decode($query->row['permission'],true);
|
|
|
|
|
2020-02-20 15:26:18 +03:00
|
|
|
if (!in_array('extension/module/retailcrm', $permissions['access'])) {
|
2018-06-13 16:13:08 +03:00
|
|
|
$permissions['access'][] = 'extension/module/retailcrm';
|
|
|
|
$this->db->query("UPDATE ".DB_PREFIX."user_group SET permission='".$this->db->escape(json_encode($permissions))."' WHERE name = 'Administrator'");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->retailcrm = $this->getMockBuilder('\retailcrm\Retailcrm')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
2020-08-07 12:39:59 +03:00
|
|
|
public function testController()
|
2018-06-13 16:13:08 +03:00
|
|
|
{
|
|
|
|
$this->login('admin', 'admin');
|
|
|
|
|
|
|
|
$response = $this->dispatchAction('extension/module/retailcrm');
|
|
|
|
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
|
|
|
|
|
|
|
$response = $this->dispatchAction('extension/module/retailcrm/icml');
|
|
|
|
|
|
|
|
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
|
|
|
$this->assertFileExists(DIR_SYSTEM . '../' . 'retailcrm.xml');
|
|
|
|
|
|
|
|
$response = $this->dispatchAction('extension/module/retailcrm/install_collector');
|
|
|
|
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
|
|
|
|
|
|
|
$response = $this->dispatchAction('extension/module/retailcrm/uninstall_collector');
|
|
|
|
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
|
|
|
}
|
2023-06-02 16:27:31 +03:00
|
|
|
|
|
|
|
public function testGetAvailableTypes()
|
|
|
|
{
|
|
|
|
$data = $this->getDataForTestAvailableTypes();
|
2023-06-07 13:01:59 +03:00
|
|
|
$sites = end($data['site']);
|
2023-06-02 16:27:31 +03:00
|
|
|
$types = $data['types'];
|
|
|
|
|
2023-06-05 17:18:10 +03:00
|
|
|
$retailCrm = new ControllerExtensionModuleRetailcrm(self::$registry);
|
|
|
|
$class = new ReflectionClass($retailCrm);
|
2023-06-02 16:27:31 +03:00
|
|
|
$method = $class->getMethod('getAvailableTypes');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
2023-06-05 17:18:10 +03:00
|
|
|
$result = $method->invokeArgs($retailCrm, [$sites, $types]);
|
2023-06-02 16:27:31 +03:00
|
|
|
|
|
|
|
$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 [
|
2023-06-07 13:01:59 +03:00
|
|
|
'site' => [
|
2023-06-02 16:27:31 +03:00
|
|
|
'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' => [
|
2023-06-05 17:18:10 +03:00
|
|
|
'active' => true,
|
2023-06-02 16:27:31 +03:00
|
|
|
'sites' => ['cms1', 'cms2', 'opencart'],
|
|
|
|
'code' => 'test4'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2018-06-13 16:13:08 +03:00
|
|
|
}
|