Skip to content

Commit

Permalink
➕ ADDS: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmoodak committed Sep 5, 2023
1 parent 8457d7e commit 875698d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 0 additions & 1 deletion integrations/integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function activate( string $slug, array $options = [] ): void {

if ( null === $integration ) {
trigger_error( sprintf( 'VIP Integration with slug "%s" is not a registered integration.', esc_html( $slug ) ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
return;
}

$integration->activate( $options );
Expand Down
19 changes: 19 additions & 0 deletions tests/integrations/test-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// phpcs:disable Squiz.Commenting.ClassComment.Missing, Squiz.Commenting.FunctionComment.Missing, Squiz.Commenting.FunctionComment.MissingParamComment

use PHPUnit\Framework\MockObject\MockObject;
use WP_UnitTestCase;

require_once __DIR__ . '/fake-integration.php';
Expand Down Expand Up @@ -36,6 +37,22 @@ public function test__activate_is_setting_up_the_plugins_config(): void {
$this->assertEquals( [ 'config_test' ], $integration->get_config() );
}

public function test__calling_activate_when_the_integration_is_already_loaded_does_not_activate_the_integration_again(): void {
$this->expectException( 'PHPUnit_Framework_Error_Warning' );
$this->expectExceptionMessage( 'Prevented activating of integration with slug "fake" because it is already available via customer code.' );
/**
* Integration mock.
*
* @var MockObject|FakeIntegration
*/
$integration_mock = $this->getMockBuilder( FakeIntegration::class )->setConstructorArgs( [ 'fake' ] )->setMethods( [ 'is_integration_already_available_via_customer' ] )->getMock();
$integration_mock->expects( $this->once() )->method( 'is_integration_already_available_via_customer' )->willReturn( true );

$integration_mock->activate();

$this->assertFalse( $integration_mock->is_active() );
}

public function test__calling_activate_twice_on_same_integration_does_not_activate_the_plugin_second_time(): void {
$this->expectException( 'PHPUnit_Framework_Error_Warning' );
$this->expectExceptionMessage( 'VIP Integration with slug "fake" is already activated.' );
Expand All @@ -44,6 +61,8 @@ public function test__calling_activate_twice_on_same_integration_does_not_activa

$integration->activate();
$integration->activate();

$this->assertFalse( $integration->is_active() );
}

public function test__is_active_returns_false_when_integration_is_not_active(): void {
Expand Down
25 changes: 25 additions & 0 deletions tests/integrations/test-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ public function test__integrations_are_activating_based_on_given_vip_config(): v
$this->assertEquals( [], $integration_3->get_config() );
}

public function test__configure_for_vip_is_getting_called_when_the_integration_is_activated_via_vip_config(): void {
$config_mock = $this->getMockBuilder( IntegrationVipConfig::class )->disableOriginalConstructor()->setMethods( [ 'is_active_via_vip' ] )->getMock();
$config_mock->expects( $this->once() )->method( 'is_active_via_vip' )->willReturn( true );
/**
* Integrations mock.
*
* @var MockObject|Integrations
*/
$integrations_mock = $this->getMockBuilder( Integrations::class )->setMethods( [ 'get_integration_vip_config' ] )->getMock();
$integrations_mock->expects( $this->once() )->method( 'get_integration_vip_config' )->willReturn( $config_mock );
/**
* Integration mock.
*
* @var MockObject|FakeIntegration
*/
$integration_mock = $this->getMockBuilder( FakeIntegration::class )->setConstructorArgs( [ 'fake' ] )->setMethods( [ 'configure_for_vip' ] )->getMock();
$integration_mock->expects( $this->once() )->method( 'configure_for_vip' );

$integrations_mock->register( $integration_mock );
$integrations_mock->activate_platform_integrations();

$this->assertTrue( $integration_mock->is_active() );
$this->assertEquals( [], $integration_mock->get_config() );
}

public function test__get_integration_vip_config_returns_instance_of_IntegrationVipConfig(): void {
$integrations = new Integrations();

Expand Down
21 changes: 21 additions & 0 deletions tests/integrations/test-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
class VIP_Parsely_Integration_Test extends WP_UnitTestCase {
private string $slug = 'parsely';

public function test_is_integration_already_available_via_customer_returns_expected_value(): void {
$parsely_integration = new ParselyIntegration( $this->slug );

if ( is_parsely_disabled() ) {
$this->assertFalse( $parsely_integration->is_integration_already_available_via_customer() );
return;
}

// Indicates enablement via filter or option.
$this->assertTrue( $parsely_integration->is_integration_already_available_via_customer() );
}

public function test__configure_for_vip_is_adding_necessary_hooks_need_for_configuration_on_vip_platform(): void {
$parsely_integration = new ParselyIntegration( $this->slug );

$parsely_integration->configure_for_vip();

$this->assertEquals( 10, has_filter( 'wp_parsely_credentials', [ $parsely_integration, 'wp_parsely_credentials_callback' ] ) );
$this->assertEquals( 10, has_filter( 'wp_parsely_managed_options', [ $parsely_integration, 'wp_parsely_managed_options_callback' ] ) );
}

public function test__load_call_is_defining_the_enabled_constant_if_plugin_is_not_loaded_already(): void {
$parsely_integration = new ParselyIntegration( $this->slug );

Expand Down

0 comments on commit 875698d

Please sign in to comment.