ApiRequestTest.php in Zoom API 2.0.x
File
tests/src/Functional/ApiRequestTest.php
View source
<?php
namespace Drupal\Tests\zoomapi\Functional;
use Drupal\Core\Url;
use Drupal\Tests\key\Functional\KeyTestTrait;
use Drupal\Tests\BrowserTestBase;
use GuzzleHttp\Exception\RequestException;
class ApiRequestTest extends BrowserTestBase {
use KeyTestTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'zoomapi',
'key',
];
protected $testKey;
protected $user;
protected function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'administer zoom api',
'administer keys',
]);
$this
->drupalLogin($this->user);
}
public function testZoomApiConnection() {
$this
->createTestKey('test_zoomapi_key', 'authentication', 'config');
$this
->createTestKey('test_zoomapi_secret', 'authentication', 'config');
$this
->drupalGet(Url::fromRoute('zoomapi.settings'));
$edit = [
'base_uri' => 'https://api.zoom.us/v2',
'api_key' => 'test_zoomapi_key',
'api_secret' => 'test_zoomapi_secret',
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration');
$client = \Drupal::service('zoomapi.client');
try {
$client
->request('GET', '/users');
} catch (RequestException $exception) {
$message = $exception
->getMessage();
$this
->assertStringContainsString('401 Unauthorized', $message, '401 Unauthorized was returned.');
$this
->assertStringContainsString('Client error', $message, 'Asserting client error exists.');
}
}
}