Merge pull request #19800 from eileenmcnaughton/gettypes
[civicrm-core.git] / ext / oauth-client / tests / phpunit / api / v4 / OAuthProviderTest.php
1 <?php
2 use CRM_OAuth_ExtensionUtil as E;
3 use Civi\Test\HeadlessInterface;
4 use Civi\Test\HookInterface;
5 use Civi\Test\TransactionalInterface;
6
7 /**
8 * Read list of OAuth providers
9 *
10 * @group headless
11 */
12 class api_v4_OAuthProviderTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
13
14 public function setUpHeadless() {
15 // Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
16 // See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
17 return \Civi\Test::headless()->install('oauth-client')->apply();
18 }
19
20 public function setUp(): void {
21 parent::setUp();
22 }
23
24 public function tearDown(): void {
25 parent::tearDown();
26 }
27
28 /**
29 * Create, read, and destroy token - with full access to secrets.
30 */
31 public function testGet(): void {
32 \CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
33
34 $examples = Civi\Api4\OAuthProvider::get()
35 ->addWhere('name', 'LIKE', 'test_example%')
36 ->addOrderBy('name', 'DESC')
37 ->execute();
38 $this->assertEquals(2, $examples->count());
39
40 $this->assertEquals('Civi\OAuth\CiviGenericProvider', $examples->last()['class']);
41 $this->assertEquals('My\Example2', $examples->first()['class']);
42 $this->assertEquals('https://example.com/one/auth', $examples->last()['options']['urlAuthorize']);
43 $this->assertEquals('https://example.com/two', $examples->first()['options']['urlAuthorize']);
44 }
45
46 }