Skip to content

Commit

Permalink
Register the site when opting in if unregistered.
Browse files Browse the repository at this point in the history
Fixes #109.
  • Loading branch information
TimothyBJacobs committed Jan 25, 2024
1 parent a4bc84f commit c5d110e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Telemetry/Opt_In/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use StellarWP\Telemetry\Config;
use StellarWP\Telemetry\Core;
use StellarWP\Telemetry\Telemetry\Telemetry;

/**
* Class for handling the Opt-in status for the site.
Expand Down Expand Up @@ -240,7 +241,13 @@ public function set_status( bool $status, string $stellar_slug = '' ) {

$option['plugins'][ $stellar_slug ]['optin'] = $status;

return update_option( $this->get_option_name(), $option );
$updated = update_option( $this->get_option_name(), $option );

if ( $updated && $status && ! $this->get_token() ) {
Config::get_container()->get( Opt_In_Subscriber::class )->opt_in( $stellar_slug );
}

return $updated;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/wpunit/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Codeception\TestCase\WPTestCase;
use StellarWP\Telemetry\Config;
use StellarWP\Telemetry\Core;
use StellarWP\Telemetry\Opt_In\Opt_In_Subscriber;
use StellarWP\Telemetry\Opt_In\Status;
use StellarWP\Telemetry\Tests\Container;
use StellarWP\Telemetry\Tests\Support\Traits\With_Test_Container;
use StellarWP\Telemetry\Tests\Support\Traits\With_Uopz;

Expand Down Expand Up @@ -511,4 +513,20 @@ public function test_it_returns_false_if_plugin_not_in_option() {

$this->assertFalse( $plugin_removed );
}

public function test_it_registers_the_site_when_opting_in() {

$subscriber_mock = $this->createMock( Opt_In_Subscriber::class );
$subscriber_mock->expects( $this->once() )
->method( 'opt_in' )
->with( 'the-events-calendar' );

$this->set_container();
$container = new Container();
$container->bind(Opt_In_Subscriber::class, $subscriber_mock );
Config::set_container($container);

$status = new Status();
$status->set_status( true, 'the-events-calendar' );
}
}

0 comments on commit c5d110e

Please sign in to comment.