2018-06-13 16:13:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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',
|
2019-02-27 16:05:35 +03:00
|
|
|
'sitesList',
|
|
|
|
'isSuccessful'
|
2018-06-13 16:13:08 +03:00
|
|
|
))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->settingModel = $this->loadModel('setting/setting');
|
|
|
|
$this->retailcrm = new \retailcrm\Retailcrm(self::$registry);
|
|
|
|
|
|
|
|
$this->settingModel->editSetting(
|
|
|
|
$this->retailcrm->getModuleTitle(),
|
|
|
|
array(
|
|
|
|
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
2019-02-27 16:05:35 +03:00
|
|
|
$this->retailcrm->getModuleTitle() . '_special_1' => 'special1',
|
|
|
|
$this->retailcrm->getModuleTitle() . '_special_2' => 'special2'
|
2018-06-13 16:13:08 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUploadPrices()
|
|
|
|
{
|
2019-02-27 16:05:35 +03:00
|
|
|
|
|
|
|
$response = new \RetailcrmApiResponse(
|
|
|
|
201,
|
|
|
|
json_encode(
|
|
|
|
$this->sites()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$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();
|
|
|
|
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock);
|
|
|
|
$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->assertArrayHasKey('prices', $price);
|
|
|
|
$this->assertInternalType('array', $price['prices']);
|
|
|
|
}
|
2019-02-27 16:05:35 +03:00
|
|
|
|
|
|
|
private function sites(){
|
|
|
|
return array(
|
|
|
|
"success"=> true,
|
|
|
|
"sites"=> array(
|
|
|
|
"BitrixMod"=> array(
|
|
|
|
"name"=> "site",
|
|
|
|
"url"=> "http://site.ru",
|
|
|
|
"code"=> "site",
|
|
|
|
"defaultForCrm"=> false,
|
|
|
|
"ymlUrl"=> "http://site.ru/retailcrm.xml",
|
|
|
|
"loadFromYml"=> false,
|
|
|
|
"catalogUpdatedAt"=> "2019-02-08 13:30:37",
|
|
|
|
"catalogLoadingAt"=> "2019-02-11 09:12:18",
|
|
|
|
"contragent"=> array(
|
|
|
|
"contragentType"=> "legal-entity",
|
|
|
|
"legalName"=> "code",
|
|
|
|
"code"=> "code",
|
|
|
|
"countryIso"=> "RU",
|
|
|
|
"vatRate"=> "",
|
|
|
|
),
|
|
|
|
"countryIso"=> "",
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2018-06-13 16:13:08 +03:00
|
|
|
}
|