Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register the site when opting in if unregistered. #110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
}
}
Loading