* @license http://retailcrm.ru Proprietary * @link http://retailcrm.ru * @see http://help.retailcrm.ru */ class WC_Retailcrm_Loyalty_Test extends WC_Retailcrm_Test_Case_Helper { protected $responseMock; protected $apiMock; /** @var \WC_Retailcrm_Loyalty */ protected $loyalty; public function setUp() { $this->responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper') ->disableOriginalConstructor() ->setMethods(['isSuccessful']) ->getMock() ; $this->responseMock->setResponse(['success' => true]); $this->setMockResponse($this->responseMock, 'isSuccessful', true); $this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Client_V5') ->disableOriginalConstructor() ->setMethods(['customersGet', 'getLoyaltyAccountList', 'createLoyaltyAccount', 'activateLoyaltyAccount']) ->getMock() ; $this->setMockResponse($this->apiMock, 'customersGet', ['customer' => ['id' => 1]]); $this->setMockResponse($this->apiMock, 'createLoyaltyAccount', $this->responseMock); $this->setMockResponse($this->apiMock, 'activateLoyaltyAccount', $this->responseMock); $this->loyalty = new WC_Retailcrm_Loyalty($this->apiMock, []); } /** * @dataProvider responseLoyalty */ public function testGetForm($isSuccessful, $body, $expected) { $response = new WC_Retailcrm_Response($isSuccessful ? 200 : 400, $body); $this->setMockResponse($this->apiMock, 'getLoyaltyAccountList', $response); $this->loyalty = new WC_Retailcrm_Loyalty($this->apiMock, []); $result = $this->loyalty->getForm(1); if (isset($result['form'])) { $this->assertTrue((bool) stripos($result['form'], $expected)); } } public function testRegistrationLoyalty() { $result = $this->loyalty->registerCustomer(1, '89999999999', 'test'); $this->assertTrue($result); } public function testActivateLoyalty() { $result = $this->loyalty->activateLoyaltyCustomer(1); $this->assertTrue($result); } public function responseLoyalty() { return DataLoyaltyRetailCrm::getDataLoyalty(); } }