opencart-module/tests/admin/ModelRetailcrmPricesAdminTest.php

77 lines
2.6 KiB
PHP
Raw Normal View History

2018-06-13 16:13:08 +03:00
<?php
2018-09-27 16:46:04 +03:00
namespace Tests;
2018-06-13 16:13:08 +03:00
class ModelRetailcrmPricesAdminTest extends OpenCartTest
{
private $pricesModel;
private $apiClientMock;
private $settingModel;
private $retailcrm;
public function setUp()
{
parent::setUp();
$this->pricesModel = $this->loadModel('extension/retailcrm/prices');
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
->disableOriginalConstructor()
->setMethods(array(
'storePricesUpload',
'sitesList'
))
->getMock();
$this->settingModel = $this->loadModel('setting/setting');
2018-09-27 16:46:04 +03:00
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
2018-06-13 16:13:08 +03:00
$this->settingModel->editSetting(
2018-09-27 16:46:04 +03:00
\Retailcrm\Retailcrm::MODULE,
2018-06-13 16:13:08 +03:00
array(
2018-09-27 16:46:04 +03:00
\Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5',
\Retailcrm\Retailcrm::MODULE . '_special_1' => 'special1',
\Retailcrm\Retailcrm::MODULE . '_special_2' => 'special2',
\Retailcrm\Retailcrm::MODULE . '_special_3' => 'special3'
2018-06-13 16:13:08 +03:00
)
);
}
public function testUploadPrices()
{
2018-09-27 16:46:04 +03:00
$response = new \RetailcrmApiResponse(200, json_encode($this->getSites()));
$this->apiClientMock->expects($this->any())->method('sitesList')->willReturn($response);
2018-06-13 16:13:08 +03:00
$productModel = $this->loadModel('catalog/product');
$products = $productModel->getProducts();
2018-09-27 16:46:04 +03:00
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock, $this->retailcrm);
2018-06-13 16:13:08 +03:00
$price = $prices[0][0];
$this->assertInternalType('array', $prices);
$this->assertInternalType('array', $prices[0]);
$this->assertInternalType('array', $price);
$this->assertArrayHasKey('externalId', $price);
$this->assertArrayHasKey('site', $price);
$this->assertSame('test_site', $price['site']);
2018-06-13 16:13:08 +03:00
$this->assertArrayHasKey('prices', $price);
$this->assertInternalType('array', $price['prices']);
$this->assertSame('special1', $price['prices'][0]['code']);
$this->assertSame('special2', $price['prices'][1]['code']);
$this->assertSame('special3', $price['prices'][2]['code']);
$this->assertFalse($price['prices'][0]['price']);
$this->assertFalse($price['prices'][1]['price']);
$this->assertNotFalse($price['prices'][2]['price']);
2018-06-13 16:13:08 +03:00
}
2018-09-27 16:46:04 +03:00
private function getSites()
{
return array(
'success' => true,
'sites' => array(
array(
'code' => 'test_site'
)
)
);
}
2018-06-13 16:13:08 +03:00
}