1
0
mirror of synced 2025-01-19 01:11:42 +03:00
woocommerce-module/tests/test-wc-retailcrm-plugin.php

190 lines
5.8 KiB
PHP
Raw Normal View History

2018-12-07 13:02:37 +03:00
<?php
class WC_Retailcrm_Plugin_Test extends WC_Retailcrm_Test_Case_Helper
{
protected $apiMock;
protected $responseMock;
public function setUp()
{
$this->responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
->disableOriginalConstructor()
->setMethods(array(
'isSuccessful'
))
->getMock();
$this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
->disableOriginalConstructor()
->setMethods(array(
'marketplaceSettingsEdit'
))
->getMock();
parent::setUp();
}
/**
* @param $retailcrm
* @param $response
* @param $apiVersion
*
* @dataProvider dataProviderIntegrationModule
*/
public function test_integration_module($retailcrm,$response, $apiVersion)
{
$client_id = uniqid();
$result = WC_Retailcrm_Plugin::integration_module($retailcrm, $client_id, $apiVersion);
if (!$retailcrm || $response['success'] == false) {
$this->assertEquals(false, $result);
} else {
$this->assertEquals(true, $result);
}
}
2020-04-05 10:36:45 +03:00
public function test_filter_cron_schedules()
{
$plugin = WC_Retailcrm_Plugin::getInstance(dirname(__DIR__ . '/../src/retailcrm.php'));
$schedules = $plugin->filter_cron_schedules(array());
$this->assertNotEmpty($schedules['five_minutes']);
$this->assertEquals(300, $schedules['five_minutes']['interval']);
$this->assertNotEmpty($schedules['three_hours']);
$this->assertEquals(10800, $schedules['three_hours']['interval']);
$this->assertNotEmpty($schedules['fiveteen_minutes']);
$this->assertEquals(900, $schedules['fiveteen_minutes']['interval']);
}
2018-12-07 13:02:37 +03:00
private function getResponseData()
{
return array(
'v4' => array(
"true" => array(
"success" => true
),
"false" => array(
"success" => false
)
),
'v5' => array(
"true" => array(
"success" => true
),
"false" => array(
"success" => false,
"errorMsg" => "Forbidden"
)
)
);
}
public function dataProviderIntegrationModule()
{
$this->setUp();
return array(
array(
'retailcrm' => $this->getApiMock(
'v4',
$this->getResponseData['v4']['true']
),
'response' => $this->getResponseData['v4']['true'],
'apiVersion' => 'v4'
),
array(
'retailcrm' => false,
'response' => $this->getResponseData['v4']['true'],
'apiVersion' => 'v4'
),
array(
'retailcrm' => $this->getApiMock(
'v4',
$this->getResponseData['v4']['false']
),
'response' => $this->getResponseData['v4']['false'],
'apiVersion' => 'v4'
),
array(
'retailcrm' => false,
'response' => $this->getResponseData['v4']['false'],
'apiVersion' => 'v4'
),
array(
'retailcrm' => $this->getApiMock(
'v5',
$this->getResponseData['v5']['true']
),
'response' => $this->getResponseData['v5']['true'],
'apiVersion' => 'v5'
),
array(
'retailcrm' => false,
'response' => $this->getResponseData['v5']['true'],
'apiVersion' => 'v5'
),
array(
'retailcrm' => $this->getApiMock(
'v5',
$this->getResponseData['v5']['false']
),
'response' => $this->getResponseData['v5']['false'],
'apiVersion' => 'v5'
),
array(
'retailcrm' => false,
'response' => $this->getResponseData['v5']['false'],
'apiVersion' => 'v5'
)
);
}
private function getApiMock($apiVersion, $response)
{
$responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
->disableOriginalConstructor()
->setMethods(array(
'isSuccessful'
))
->getMock();
if ($response['success'] == true) {
$responseMock->expects($this->any())
->method('isSuccessful')
->willReturn(true);
} elseif ($response['success'] == false) {
$responseMock->expects($this->any())
->method('isSuccessful')
->willReturn(false);
}
$responseMock->setResponse($response);
if ($apiVersion == 'v4') {
$apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
->disableOriginalConstructor()
->setMethods(array(
'marketplaceSettingsEdit'
))
->getMock();
$apiMock->expects($this->any())
->method('marketplaceSettingsEdit')
->willReturn($responseMock);
} else {
$apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
->disableOriginalConstructor()
->setMethods(array(
'integrationModulesEdit'
))
->getMock();
$apiMock->expects($this->any())
->method('integrationModulesEdit')
->willReturn($responseMock);
}
return $apiMock;
}
}