diff --git a/projects/packages/account-protection/src/class-settings.php b/projects/packages/account-protection/src/class-settings.php index 6e0f771b63511..51ffa48b5aa0f 100644 --- a/projects/packages/account-protection/src/class-settings.php +++ b/projects/packages/account-protection/src/class-settings.php @@ -7,26 +7,24 @@ namespace Automattic\Jetpack\Account_Protection; -use Automattic\Jetpack\Modules; - /** * Account Protection Settings */ class Settings { /** - * Modules instance. + * Account Protection instance. * - * @var Modules|null + * @var Account_Protection */ - private $modules; + private $account_protection; /** - * Constructor. + * Constructor for dependency injection. * - * @param Modules|null $modules Modules instance. + * @param ?Account_Protection|null $account_protection Account protection dependency. */ - public function __construct( ?Modules $modules = null ) { - $this->modules = $modules ?? new Modules(); + public function __construct( ?Account_Protection $account_protection = null ) { + $this->account_protection = $account_protection ?? new Account_Protection(); } /** @@ -35,11 +33,11 @@ public function __construct( ?Modules $modules = null ) { * @return array */ public function get() { - $account_protection = new Account_Protection( $this->modules ); - - return array( - 'isEnabled' => $account_protection->is_enabled(), - 'isSupported' => $account_protection->is_supported_environment(), + $settings = array( + 'isEnabled' => $this->account_protection->is_enabled(), + 'isSupported' => $this->account_protection->is_supported_environment(), ); + + return $settings; } } diff --git a/projects/packages/account-protection/tests/php/test-settings.php b/projects/packages/account-protection/tests/php/test-settings.php index a9bc6b26b1944..267c8fd516c05 100644 --- a/projects/packages/account-protection/tests/php/test-settings.php +++ b/projects/packages/account-protection/tests/php/test-settings.php @@ -10,17 +10,18 @@ */ class Settings_Test extends BaseTestCase { public function test_base_case() { - $modules_mock = $this->createMock( Modules::class ); - $modules_mock->expects( $this->once() ) - ->method( 'is_active' ) - ->willReturn( true ); + $modules_mock = $this->createMock( Modules::class ); + $modules_mock->expects( $this->once() ) + ->method( 'is_active' ) + ->with( Account_Protection::ACCOUNT_PROTECTION_MODULE_NAME ) + ->willReturn( true ); - $modules_mock->expects( $this->never() ) - ->method( 'activate' ); + $modules_mock->expects( $this->never() ) + ->method( 'activate' ); - $settings = ( new Settings( $modules_mock ) )->get(); + $settings = ( new Settings( new Account_Protection( $modules_mock ) ) )->get(); - $this->assertTrue( $settings['isSupported'] ); - $this->assertTrue( $settings['isEnabled'] ); + $this->assertTrue( $settings['isSupported'] ); + $this->assertTrue( $settings['isEnabled'] ); } } diff --git a/projects/plugins/protect/src/js/routes/settings/index.jsx b/projects/plugins/protect/src/js/routes/settings/index.jsx index 1820a3c9386e2..34e09cea141dd 100644 --- a/projects/plugins/protect/src/js/routes/settings/index.jsx +++ b/projects/plugins/protect/src/js/routes/settings/index.jsx @@ -4,6 +4,8 @@ import { Text, ToggleControl, AdminSectionHero, + Notice, + Button, } from '@automattic/jetpack-components'; import { createInterpolateElement } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; @@ -42,16 +44,39 @@ const SettingsPage = () => {