1
0
mirror of synced 2025-01-18 17:01:41 +03:00
woocommerce-module/tests/test-wc-retailcrm-plugin.php

141 lines
4.4 KiB
PHP
Raw Normal View History

2018-12-07 13:02:37 +03:00
<?php
2022-01-10 12:53:00 +03:00
/**
* PHP version 7.0
2022-01-10 12:53:00 +03:00
*
* Class WC_Retailcrm_Plugin_Test - Testing WC_Retailcrm_Plugin.
*
* @category Integration
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
2018-12-07 13:02:37 +03:00
class WC_Retailcrm_Plugin_Test extends WC_Retailcrm_Test_Case_Helper
{
protected $apiMock;
protected $responseMock;
2021-12-20 11:41:41 +03:00
protected $plugin;
private $path = __DIR__ . '/src/retailcrm.php';
2018-12-07 13:02:37 +03:00
public function setUp()
{
$this->responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
2021-12-20 11:41:41 +03:00
->disableOriginalConstructor()
->setMethods(array('isSuccessful'))
->getMock();
2018-12-07 13:02:37 +03:00
$this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
2021-12-20 11:41:41 +03:00
->disableOriginalConstructor()
->setMethods(array('integrationModulesEdit'))
->getMock();
$this->plugin = WC_Retailcrm_Plugin::getInstance($this->path);
2018-12-07 13:02:37 +03:00
parent::setUp();
}
/**
* @param $retailcrm
2021-12-20 11:41:41 +03:00
* @param $responseStatus
2018-12-07 13:02:37 +03:00
*
* @dataProvider dataProviderIntegrationModule
*/
2021-12-20 11:41:41 +03:00
public function test_integration_module($retailcrm, $responseStatus)
2018-12-07 13:02:37 +03:00
{
2021-12-20 11:41:41 +03:00
$this->setMockResponse($this->responseMock, 'isSuccessful', $responseStatus);
$this->responseMock->setResponse(array('success' => $responseStatus));
if ($retailcrm) {
$this->setMockResponse($retailcrm, 'integrationModulesEdit', $this->responseMock);
}
2018-12-07 13:02:37 +03:00
$client_id = uniqid();
$result = WC_Retailcrm_Plugin::integration_module($retailcrm, $client_id);
2018-12-07 13:02:37 +03:00
2021-12-20 11:41:41 +03:00
if (!$retailcrm || !$responseStatus) {
2018-12-07 13:02:37 +03:00
$this->assertEquals(false, $result);
} else {
$this->assertEquals(true, $result);
2021-12-20 11:41:41 +03:00
}
2018-12-07 13:02:37 +03:00
}
2020-04-05 10:36:45 +03:00
public function test_filter_cron_schedules()
{
2021-12-20 11:41:41 +03:00
$schedules = $this->plugin->filter_cron_schedules(array());
2020-04-05 10:36:45 +03:00
$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']);
}
2021-12-20 11:41:41 +03:00
public function test_deactivate()
2018-12-07 13:02:37 +03:00
{
2021-12-20 11:41:41 +03:00
wp_schedule_event(time(), 'three_hours', 'retailcrm_icml');
wp_schedule_event(time(), 'five_minutes', 'retailcrm_history');
wp_schedule_event(time(), 'fiveteen_minutes', 'retailcrm_inventories');
$this->plugin->deactivate();
$this->assertEquals(false, wp_next_scheduled('retailcrm_icml'));
$this->assertEquals(false, wp_next_scheduled('retailcrm_history'));
$this->assertEquals(false, wp_next_scheduled('retailcrm_inventories'));
}
public function test_register_deactivation_and_activation_hook()
{
global $wp_filter;
$this->plugin->register_activation_hook();
$this->plugin->register_deactivation_hook();
$actions = array();
foreach (array_keys($wp_filter) as $key) {
if (false !== strpos($key, 'retailcrm')) {
if (false !== strpos($key, 'deactivate_')) {
$actions['deactivate'] = $key;
}
if (false !== strpos($key, 'activate_')) {
$actions['activate'] = $key;
}
}
}
$this->assertArrayHasKey('deactivate', $actions);
$this->assertNotEmpty($actions['deactivate']);
$this->assertArrayHasKey('activate', $actions);
$this->assertNotEmpty($actions['activate']);
2018-12-07 13:02:37 +03:00
}
public function dataProviderIntegrationModule()
{
$this->setUp();
return array(
array(
2021-12-20 11:41:41 +03:00
'retailcrm' => $this->apiMock,
'responseStatus' => true
2018-12-07 13:02:37 +03:00
),
array(
'retailcrm' => false,
2021-12-20 11:41:41 +03:00
'responseStatus' => true
2018-12-07 13:02:37 +03:00
),
array(
2021-12-20 11:41:41 +03:00
'retailcrm' => $this->apiMock,
'responseStatus' => false
2018-12-07 13:02:37 +03:00
),
array(
'retailcrm' => false,
2021-12-20 11:41:41 +03:00
'responseStatus' => false
),
2018-12-07 13:02:37 +03:00
);
}
}