1
0
mirror of synced 2025-02-22 01:43:14 +03:00
woocommerce-module/tests/test-wc-retailcrm-cart.php
Kocmonavtik be5aedef94 ref #88120 Adding API methods for handling cart (#296)
* Adding and testing new cart API methods
* Fix the causes of errors in old tests

---------

Co-authored-by: Ivan Chaplygin <chaplygin@retailcrm.ru>
2023-03-29 14:14:08 +03:00

73 lines
2.2 KiB
PHP

<?php
use datasets\DataCartRetailCrm;
/**
* PHP version 7.0
*
* Class WC_Retailcrm_Cart_Test
*
* @category Integration
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
class WC_Retailcrm_Cart_Test extends WC_Retailcrm_Test_Case_Helper
{
protected $apiClientMock;
protected $responseMock;
public function setUp()
{
$this->responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
->disableOriginalConstructor()
->setMethods(
[
'isSuccessful',
'offsetExists',
]
)
->getMock();
$this->responseMock->setResponse(['id' => 1]);
$this->apiClientMock = $this->getMockBuilder('\WC_Retailcrm_Client_V5')
->disableOriginalConstructor()
->setMethods(
[
'cartGet',
'cartSet',
'cartClear',
]
)
->getMock();
$this->setMockResponse($this->responseMock, 'isSuccessful', true);
$this->setMockResponse($this->responseMock, 'offsetExists', true);
$this->setMockResponse($this->apiClientMock, 'cartSet', $this->responseMock);
$this->setMockResponse($this->apiClientMock, 'cartClear', $this->responseMock);
$this->setMockResponse($this->apiClientMock, 'cartGet',$this->responseMock);
}
public function testGetCart()
{
$this->responseMock->setResponse(DataCartRetailCrm::dataGetCart());
$response = $this->apiClientMock->cartGet(1, 'test-site');
$this->assertNotEmpty($response->__get('cart'));
$this->assertTrue($response->__get('success'));
}
public function testSetCart()
{
$response = $this->apiClientMock->cartSet(DataCartRetailCrm::dataSetCart(), 'test-site');
$this->assertEquals(1, $response->__get('id'));
}
public function testClearCart()
{
$response = $this->apiClientMock->cartClear(DataCartRetailCrm::dataClearCart(), 'test-site');
$this->assertEquals(1, $response->__get('id'));
}
}