webex_client-1.0.5/tests/src/Kernel/WebexEntityTest.php
tests/src/Kernel/WebexEntityTest.php
<?php
namespace Drupal\Tests\webex_client\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\webex_client\Entity\Webex;
/**
* Functional test for the Webex configuration entity.
*
* @group webex
*/
class WebexEntityTest extends KernelTestBase {
/**
* The list of modules to enable for this test.
*
* @var array
*/
protected static $modules = [
'webex',
];
/**
* The ID of the Webex entity to create and test.
*
* @var string
*/
protected $id = 'test_webex';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Install the configuration for the Webex entity.
$this->installConfig(['webex_client']);
}
/**
* Tests the getters and setters of the Webex config entity.
*/
public function testWebexEntityProperties(): void {
// Create a new Webex entity instance.
/** @var \Drupal\webex_client\Entity\Webex $entity */
$entity = Webex::create([
'id' => $this->id,
'label' => 'Test Webex',
]);
// Test client ID and secret.
$entity->setClientId('my-client-id')
->setClientSecret('my-client-secret');
// Test scope, expiration, and token type.
$entity->setScope('scope1 scope2')
->setExpiresIn(3600)
->setRefreshTokenExpiresIn(7200)
->setTokenType('Bearer');
// Test default flag.
$entity->setDefault();
// Test OAuth tokens: code, access token, and refresh token.
$entity->setCode('auth-code-123')
->setAccessToken('access-token-xyz')
->setRefreshToken('refresh-token-abc');
// Save and reload the entity.
$entity->save();
$loaded = Webex::load($this->id);
// Assertions for client ID and secret.
$this->assertEquals('my-client-id', $loaded->getClientId(), 'Client ID was saved and retrieved correctly.');
$this->assertEquals('my-client-secret', $loaded->getClientSecret(), 'Client Secret was saved and retrieved correctly.');
// Assertions for scope, expires, and token type.
$this->assertEquals('scope1 scope2', $loaded->getScope(), 'Scope was saved and retrieved correctly.');
$this->assertEquals(3600, $loaded->getExpiresIn(), 'ExpiresIn was saved and retrieved correctly.');
$this->assertEquals(7200, $loaded->getRefreshTokenExpiresIn(), 'RefreshTokenExpiresIn was saved and retrieved correctly.');
$this->assertEquals('Bearer', $loaded->getTokenType(), 'TokenType was saved and retrieved correctly.');
// Assertion for default flag.
$this->assertTrue($loaded->isDefault(), 'Default flag was saved and retrieved correctly.');
// Assertions for OAuth tokens.
$this->assertEquals('auth-code-123', $loaded->getCode(), 'Authorization code was saved and retrieved correctly.');
$this->assertEquals('access-token-xyz', $loaded->getAccessToken(), 'Access token was saved and retrieved correctly.');
$this->assertEquals('refresh-token-abc', $loaded->getRefreshToken(), 'Refresh token was saved and retrieved correctly.');
}
}
