1
0
mirror of synced 2024-11-25 13:16:01 +03:00
mg-bot-api-client-php/tests/Bot/Tests/ClientListTest.php

235 lines
5.8 KiB
PHP
Raw Normal View History

2019-06-10 16:24:22 +03:00
<?php
/**
* PHP version 7.0
*
* Client Test
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Tests;
use RetailCrm\Mg\Bot\Model\Constants;
2019-06-17 13:59:14 +03:00
use RetailCrm\Mg\Bot\Model\Entity\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
2019-06-14 12:48:13 +03:00
use RetailCrm\Mg\Bot\Model\Entity\Dialog;
2019-06-17 13:59:14 +03:00
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
use RetailCrm\Mg\Bot\Model\Entity\User;
2019-06-10 16:24:22 +03:00
use RetailCrm\Mg\Bot\Model\Request;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class ClientListTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ClientListTest extends TestCase
{
/**
* @group("list")
* @throws \Exception
*/
public function testChannels()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('channels')
);
2019-06-10 16:24:22 +03:00
$request = new Request\ChannelsRequest();
$request->setActive(true);
2019-06-17 13:59:14 +03:00
$request->setTypes([Constants::CHANNEL_TYPE_TELEGRAM, Constants::CHANNEL_TYPE_INSTAGRAM]);
2019-06-10 16:24:22 +03:00
$response = $client->channels($request);
2019-06-19 12:14:40 +03:00
static::assertEquals(4, count($response), "Incorrect channels count");
2019-06-17 13:59:14 +03:00
static::assertTrue($response[0] instanceof Channel\Channel, "Incorrect channel instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testChats()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('chats')
);
2019-06-10 16:24:22 +03:00
$request = new Request\ChatsRequest();
2019-06-17 13:59:14 +03:00
$request->setChannelType(Constants::CHANNEL_TYPE_TELEGRAM);
2019-06-10 16:24:22 +03:00
$response = $client->chats($request);
2019-06-19 12:14:40 +03:00
static::assertEquals(2, count($response), "Incorrect chats count");
2019-06-17 13:59:14 +03:00
static::assertTrue($response[0] instanceof Chat, "Incorrect chat instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testMembers()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('members')
);
2019-06-10 16:24:22 +03:00
$request = new Request\MembersRequest();
$response = $client->members($request);
2019-06-19 12:14:40 +03:00
static::assertEquals(4, count($response), "Incorrect members count");
2019-06-17 13:59:14 +03:00
static::assertTrue($response[0] instanceof ChatMember, "Incorrect member instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testMessages()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('messages')
);
2019-06-10 16:24:22 +03:00
$request = new Request\MessagesRequest();
$request->setChannelType(Constants::CHANNEL_TYPE_INSTAGRAM);
$request->setType(Constants::MESSAGE_TYPE_TEXT);
$response = $client->messages($request);
2019-06-19 12:14:40 +03:00
static::assertEquals(2, count($response), "Incorrect message count");
2019-06-17 13:59:14 +03:00
static::assertTrue($response[0] instanceof Message, "Incorrect message instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testCommands()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('[]')
);
2019-06-10 16:24:22 +03:00
$request = new Request\CommandsRequest();
$response = $client->commands($request);
2019-06-19 12:14:40 +03:00
self::assertEquals(0, count($response), "Invalid commands count");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testBots()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('bots')
);
2019-06-10 16:24:22 +03:00
$request = new Request\BotsRequest();
$request->setActive(1);
$request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]);
2019-06-14 08:56:11 +03:00
$data = $client->bots($request);
2019-06-10 16:24:22 +03:00
2019-06-19 12:14:40 +03:00
static::assertEquals(3, count($data));
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testUsers()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('users')
);
2019-06-10 16:24:22 +03:00
$request = new Request\UsersRequest();
$request->setActive(1);
$request->setOnline(0);
$response = $client->users($request);
2019-06-19 12:14:40 +03:00
self::assertEquals(2, count($response));
self::assertTrue($response[0] instanceof User);
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testDialogs()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('dialogs')
);
2019-06-10 16:24:22 +03:00
$request = new Request\DialogsRequest();
$request->setActive(1);
$request->setAssign(1);
$response = $client->dialogs($request);
2019-06-19 12:14:40 +03:00
self::assertEquals(2, count($response));
self::assertTrue($response[0] instanceof Dialog);
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testCustomers()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('customers')
);
2019-06-10 16:24:22 +03:00
$request = new Request\CustomersRequest();
$response = $client->customers($request);
2019-06-19 12:14:40 +03:00
self::assertEquals(2, count($response));
self::assertTrue($response[0] instanceof Customer);
2019-06-10 16:24:22 +03:00
}
}