Skip to content

Commit

Permalink
test(wpunit) add coverage for OAuth flags
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Sep 3, 2024
1 parent 8fc4cca commit 84747bd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Uplink/Resources/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Service extends Resource {
/**
* @inheritDoc
*/
public static function register( $slug, $name, $version, $path, $class, string $license_class = null, bool $oauth = false) {
public static function register( $slug, $name, $version, $path, $class, string $license_class = null, $oauth = false) {
return parent::register_resource( static::class, $slug, $name, $version, $path, $class, $license_class, $oauth );
}
}
60 changes: 59 additions & 1 deletion tests/wpunit/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace wpunit;

use StellarWP\Uplink\Config;
use StellarWP\Uplink\Resources\Resource;
use StellarWP\Uplink\Tests\UplinkTestCase;
use StellarWP\Uplink\Register;
use StellarWP\Uplink\Resources\Collection;
use StellarWP\Uplink\Tests\TestUtils;
use StellarWP\Uplink\Uplink;

class RegisterTest extends UplinkTestCase {

Expand Down Expand Up @@ -38,11 +40,67 @@ public function it_should_register_resource( $resource ) {
$resource['path'],
$resource['class'],
null,
$is_oauth,
$is_oauth
);

$this->assertTrue( $collection->offsetExists( $resource['slug'] ) );

$this->assertEquals( $is_oauth, $collection->get( $resource['slug'] )->is_using_oauth() );
}

/**
* @test
*/
public function is_should_register_service_with_oauth_using_int():void{
$collection = Config::get_container()->get( Collection::class );

$this->assertFalse( $collection->offsetExists( 'service-with-oauth-int' ) );

Register::service(
'service-with-oauth-int',
'Service With OAuth Int',
'1.0.10',
$this->get_base() . '/service-with-oauth-int.php',
Uplink::class,
Uplink::class,
Resource::OAUTH_REQUIRED
);

$this->assertTrue( $collection->offsetExists( 'service-with-oauth-int' ) );
$this->assertTrue( $collection->get( 'service-with-oauth-int' )->is_using_oauth() );
$this->assertFalse( $collection->get( 'service-with-oauth-int' )->oauth_requires_license_key() );
}

public function is_should_register_service_with_oauth_and_license_key_using_int():void{
$collection = Config::get_container()->get( Collection::class );

$this->assertFalse( $collection->offsetExists( 'service-with-oauth-int-2' ) );
$this->assertFalse( $collection->offsetExists( 'service-with-oauth-int-3' ) );

// Include the Resource::OAUTH_REQUIRES_LICENSE_KEY flag.
Register::service(
'service-with-oauth-int-2',
'Service With OAuth Int 2',
'1.0.10',
$this->get_base() . '/service-with-oauth-int-2.php',
Uplink::class,
Uplink::class,
Resource::OAUTH_REQUIRED | Resource::OAUTH_REQUIRES_LICENSE_KEY
);

// Omit the Resource::OAUTH_REQUIRED flag, it should be implied.
Register::service(
'service-with-oauth-int-3',
'Service With OAuth Int 3',
'1.0.10',
$this->get_base() . '/service-with-oauth-int-2.php',
Uplink::class,
Uplink::class,
Resource::OAUTH_REQUIRES_LICENSE_KEY
);

$this->assertTrue( $collection->offsetExists( 'service-with-oauth-int-3' ) );
$this->assertTrue( $collection->get( 'service-with-oauth-int-3' )->is_using_oauth() );
$this->assertTrue( $collection->get( 'service-with-oauth-int-3' )->oauth_requires_license_key() );
}
}

0 comments on commit 84747bd

Please sign in to comment.