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

Allow TOS agreement before Jetpack is fully active so we track the connection flow #14041

Merged
merged 4 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 5 additions & 10 deletions packages/terms-of-service/src/class-terms-of-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function reject() {
/**
* Acton fired when the master user has revoked their agreement to the terms of service.
*
* @since 7.9.0
* @since 7.9.1
*/
do_action( 'jetpack_reject_to_terms_of_service' );
do_action( 'jetpack_reject_terms_of_service' );
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -60,15 +60,11 @@ public function reject() {
* @return bool
*/
public function has_agreed() {
if ( ! $this->get_raw_has_agreed() ) {
return false;
}

if ( $this->is_development_mode() ) {
return false;
}

return $this->is_active();
return $this->get_raw_has_agreed() || $this->is_active();
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -88,8 +84,7 @@ protected function is_development_mode() {
* @return bool
*/
protected function is_active() {
$manager = new Manager();
return $manager->is_active();
return ( new Manager() )->is_active();
}

/**
Expand All @@ -99,7 +94,7 @@ protected function is_active() {
* @return bool
*/
protected function get_raw_has_agreed() {
return \Jetpack_Options::get_option( self::OPTION_NAME );
return \Jetpack_Options::get_option( self::OPTION_NAME, false );
}

/**
Expand Down
33 changes: 9 additions & 24 deletions packages/terms-of-service/tests/php/test_TermsOfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Test_Terms_Of_Service extends TestCase {
*/
public function setUp() {
$this->terms_of_service = $this->createPartialMock( __NAMESPACE__ .'\\Terms_Of_Service',
[ 'get_raw_has_agreed', 'is_development_mode', 'is_active', 'set_agree', 'set_reject' ]
[ 'get_raw_has_agreed', 'is_development_mode', 'set_agree', 'is_active', 'set_reject' ]
);
}

Expand All @@ -29,7 +29,7 @@ public function tearDown() {
*/
public function test_agree() {
$this->mock_function( 'do_action', null, 'jetpack_agreed_to_terms_of_service' );
$this->terms_of_service->expects( $this->once() )->method( 'set_agree' )->willReturn( null );
$this->terms_of_service->expects( $this->once() )->method( 'set_agree' );

$this->terms_of_service->agree();
}
Expand All @@ -38,36 +38,35 @@ public function test_agree() {
* @covers Automattic\Jetpack\Terms_Of_Service->revoke
*/
public function test_revoke() {
$this->mock_function( 'do_action', null, 'jetpack_reject_to_terms_of_service' );
$this->terms_of_service->expects( $this->once() )->method( 'set_reject' )->willReturn( null );
$this->mock_function( 'do_action', null, 'jetpack_reject_terms_of_service' );
$this->terms_of_service->expects( $this->once() )->method( 'set_reject' );

$this->terms_of_service->reject();
}

/**
* @covers Automattic\Jetpack\Terms_Of_Service->has_agreed
*/
public function test_has_agreed_before_the_site_agrees() {
public function test_returns_false_if_not_agreed() {
$this->terms_of_service->expects( $this->once() )->method( 'get_raw_has_agreed' )->willReturn( false );
$this->assertFalse( $this->terms_of_service->has_agreed() );
}

/**
* @covers Automattic\Jetpack\Terms_Of_Service->has_agreed
*/
public function test_has_agreed_is_development_mode() {
$this->terms_of_service->expects( $this->once() )->method( 'get_raw_has_agreed' )->willReturn( true );
public function test_returns_false_if_has_agreed_but_is_development_mode() {
// is_development_mode
$this->terms_of_service->method( 'get_raw_has_agreed' )->willReturn( true );
$this->terms_of_service->expects( $this->once() )->method( 'is_development_mode' )->willReturn( true );
$this->assertFalse( $this->terms_of_service->has_agreed() );
}

/**
* @covers Automattic\Jetpack\Terms_Of_Service->has_agreed
*/
public function test_has_agreed_is_active_mode() {
$this->terms_of_service->expects( $this->once() )->method( 'get_raw_has_agreed' )->willReturn( true );
// Not in dev mode...
public function test_returns_true_if_active_even_if_not_agreed() {
$this->terms_of_service->expects( $this->once() )->method( 'get_raw_has_agreed' )->willReturn( false );
$this->terms_of_service->expects( $this->once() )->method( 'is_development_mode' )->willReturn( false );

// Jetpack is active
Expand All @@ -76,20 +75,6 @@ public function test_has_agreed_is_active_mode() {
$this->assertTrue( $this->terms_of_service->has_agreed() );
}

/**
* @covers Automattic\Jetpack\Terms_Of_Service->has_agreed
*/
public function test_has_agreed_is_not_active_mode() {
$this->terms_of_service->expects( $this->once() )->method( 'get_raw_has_agreed' )->willReturn( true );
// not in dev mode...
$this->terms_of_service->expects( $this->once() )->method( 'is_development_mode' )->willReturn( false );

// Jetpack is not active
$this->terms_of_service->expects( $this->once() )->method( 'is_active' )->willReturn( false );

$this->assertFalse( $this->terms_of_service->has_agreed() );
}

/**
* Mock a global function and make it return a certain value.
*
Expand Down