opencart-module/tests/catalog/ModelRetailcrmCustomerCatalogTest.php

64 lines
2.5 KiB
PHP
Raw Normal View History

2018-06-13 16:13:08 +03:00
<?php
2020-02-19 12:37:03 +03:00
require_once __DIR__ . '/../' . getenv('OPENCART') . '/TestCase.php';
class ModelRetailcrmCustomerCatalogTest extends TestCase
2018-06-13 16:13:08 +03:00
{
private $customerModel;
private $apiClientMock;
const CUSTOMER_ID = 1;
public function setUp()
{
parent::setUp();
$this->customerModel = $this->loadModel('extension/retailcrm/customer');
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
->disableOriginalConstructor()
->setMethods(array(
'customersCreate',
'customersEdit'
))
->getMock();
}
public function testSendToCrm()
{
$customerModel = $this->loadModel('account/customer');
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
$customerSend = $this->customerModel->sendToCrm($customer, $this->apiClientMock);
$this->assertArrayHasKey('externalId', $customerSend);
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
$this->assertArrayHasKey('firstName', $customerSend);
$this->assertEquals('Test', $customerSend['firstName']);
$this->assertArrayHasKey('lastName', $customerSend);
$this->assertEquals('Test', $customerSend['lastName']);
$this->assertArrayHasKey('email', $customerSend);
$this->assertEquals('test@mail.ru', $customerSend['email']);
$this->assertArrayHasKey('phones', $customerSend);
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
}
public function testChangeInCrm()
{
$customerModel = $this->loadModel('account/customer');
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
$customerSend = $this->customerModel->changeInCrm($customer, $this->apiClientMock);
$this->assertArrayHasKey('externalId', $customerSend);
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
$this->assertArrayHasKey('firstName', $customerSend);
$this->assertEquals('Test', $customerSend['firstName']);
$this->assertArrayHasKey('lastName', $customerSend);
$this->assertEquals('Test', $customerSend['lastName']);
$this->assertArrayHasKey('email', $customerSend);
$this->assertEquals('test@mail.ru', $customerSend['email']);
$this->assertArrayHasKey('phones', $customerSend);
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
}
}