Skip to content
Merged
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
6 changes: 3 additions & 3 deletions frontend/page-place-ad.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ public function details_form( $params = array(), $form = array(), $edit = false,
$ui['allow-regions-modification'] = $is_moderator || !$edit || get_awpcp_option( 'allow-regions-modification' );
$ui['price-field'] = get_awpcp_option('displaypricefield') == 1;
$ui['extra-fields'] = $hasextrafieldsmodule && function_exists( 'awpcp_extra_fields_module' );
$ui['terms-of-service'] = !$edit && !$is_moderator && get_awpcp_option('requiredtos');
$ui['terms-of-service'] = ! $edit && get_awpcp_option( 'requiredtos' );
$ui['captcha'] = !$edit && !is_admin() && ( get_awpcp_option( 'captcha-enabled-in-place-listing-form' ) == 1 );

$hidden['step'] = 'save-details';
Expand Down Expand Up @@ -1159,8 +1159,8 @@ protected function validate_details($data=array(), $edit=false, $payment_term =
}

// Terms of service required and accepted?
if (!$edit && !$is_moderator && get_awpcp_option('requiredtos') && empty($data['terms-of-service'])) {
$errors['terms-of-service'] = __("You did not accept the terms of service", 'another-wordpress-classifieds-plugin');
if ( ! $edit && get_awpcp_option( 'requiredtos' ) && empty( $data['terms-of-service'] ) ) {
$errors['terms-of-service'] = __( 'You did not accept the terms of service', 'another-wordpress-classifieds-plugin' );
}

if ( !$edit && !is_admin() && get_awpcp_option( 'captcha-enabled-in-place-listing-form' ) ) {
Expand Down
1 change: 0 additions & 1 deletion includes/class-container-configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function modify( $container ) {
$container['FormFieldsValidator'] = $container->service( function( $container ) {
return new AWPCP_FormFieldsValidator(
$container['ListingAuthorization'],
$container['RolesAndCapabilities'],
$container['Settings']
);
} );
Expand Down
1 change: 0 additions & 1 deletion includes/constructor-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ function awpcp_terms_of_service_form_field( $slug ) {

return new AWPCP_TermsOfServiceFormField(
$slug,
$container['RolesAndCapabilities'],
$container['Settings'],
$container['TemplateRenderer']
);
Expand Down
15 changes: 4 additions & 11 deletions includes/form-fields/class-form-fields-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ class AWPCP_FormFieldsValidator {
*/
private $authorization;

/**
* @var AWPCP_RolesAndCapabilities
*/
private $roles;

/**
* @var object
*/
Expand All @@ -30,13 +25,11 @@ class AWPCP_FormFieldsValidator {
/**
* @since 4.0.0
*
* @param object $authorization An instance of Listing Authorization.
* @param object $roles An instance of Roles and Capabilities.
* @param object $settings An instance of Settings API.
* @param object $authorization An instance of Listing Authorization.
* @param object $settings An instance of Settings API.
*/
public function __construct( $authorization, $roles, $settings ) {
public function __construct( $authorization, $settings ) {
$this->authorization = $authorization;
$this->roles = $roles;
$this->settings = $settings;
}

Expand Down Expand Up @@ -136,7 +129,7 @@ public function get_validation_errors( $data, $post ) {
}
}

if ( $this->settings->get_option( 'requiredtos' ) && ! $this->roles->current_user_is_moderator() ) {
if ( $this->settings->get_option( 'requiredtos' ) ) {
if ( $data['terms_of_service'] !== 'accepted' ) {
$errors['terms_of_service'] = __( 'Please read and accept the Terms of Service.', 'another-wordpress-classifieds-plugin' );
}
Expand Down
12 changes: 1 addition & 11 deletions includes/form-fields/class-terms-of-service-form-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class AWPCP_TermsOfServiceFormField extends AWPCP_FormField {

private $template = 'frontend/form-fields/terms-of-service-form-field.tpl.php';

/**
* @var AWPCP_RolesAndCapabilities
*/
private $roles;

/**
* @var AWPCP_Settings_API
*/
Expand All @@ -32,10 +27,9 @@ class AWPCP_TermsOfServiceFormField extends AWPCP_FormField {
/**
* @since 4.0.2
*/
public function __construct( $slug, $roles, $settings, $template_renderer ) {
public function __construct( $slug, $settings, $template_renderer ) {
parent::__construct( $slug );

$this->roles = $roles;
$this->settings = $settings;
$this->template_renderer = $template_renderer;
}
Expand Down Expand Up @@ -67,10 +61,6 @@ public function is_allowed_in_context( $context ) {
return false;
}

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

return true;
}

Expand Down
10 changes: 0 additions & 10 deletions tests/suite/form-fields/test-form-fields-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
*/
class AWPCP_FormFieldsDataValidatorTest extends AWPCP_UnitTestCase {

/**
* @var mixed
*/
public $roles;

/**
* @var mixed
*/
Expand All @@ -37,8 +32,6 @@ class AWPCP_FormFieldsDataValidatorTest extends AWPCP_UnitTestCase {
public function setUp(): void {
parent::setUp();

$this->roles = Mockery::mock( 'AWPCP_RolesAndCapabilities' );

$this->data = array(
'post_fields' => array(
'post_title' => 'Test Listing',
Expand Down Expand Up @@ -95,8 +88,6 @@ private function get_validation_errors() {
$this->authorization->shouldReceive( 'is_current_user_allowed_to_edit_listing_end_date' )
->andReturn( true );

$this->roles->shouldReceive( 'current_user_is_moderator' )->andReturn( false );

$this->settings->shouldReceive( 'get_option' )->andReturnUsing(
function( $name ) {
$options = array(
Expand Down Expand Up @@ -126,7 +117,6 @@ function( $name ) {
private function get_test_subject() {
return new AWPCP_FormFieldsValidator(
$this->authorization,
$this->roles,
$this->settings
);
}
Expand Down
20 changes: 1 addition & 19 deletions tests/suite/form-fields/test-terms-of-service-form-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
*/
class AWPCP_TermsOfServiceFormFieldTest extends AWPCP_UnitTestCase {

/**
* @var mixed
*/
public $roles;

/**
* @var mixed
*/
Expand All @@ -29,7 +24,6 @@ class AWPCP_TermsOfServiceFormFieldTest extends AWPCP_UnitTestCase {
public function setUp(): void {
parent::setUp();

$this->roles = Mockery::mock( 'AWPCP_RolesAndCapabilities' );
$this->settings = Mockery::mock( 'AWPCP_Settings' );
$this->template_renderer = null;
}
Expand All @@ -39,7 +33,7 @@ public function setUp(): void {
*
* @dataProvider is_allowed_in_context_data_provider
*/
public function test_is_allowed_in_context( $expected_result, $require_tos, $is_moderator, $context = [] ) {
public function test_is_allowed_in_context( $expected_result, $require_tos, $context = [] ) {
$default_context = [
'action' => 'not-search',
];
Expand All @@ -50,9 +44,6 @@ public function test_is_allowed_in_context( $expected_result, $require_tos, $is_
->with( 'requiredtos' )
->andReturn( $require_tos );

$this->roles->shouldReceive( 'current_user_is_moderator' )
->andReturn( $is_moderator );

// Execution.
$is_allowed = $this->get_test_subject()->is_allowed_in_context( $context );

Expand All @@ -68,22 +59,14 @@ public function is_allowed_in_context_data_provider() {
[
'expected_result' => true,
'require_tos' => true,
'is_moderator' => false,
],
[
'expected_result' => false,
'require_tos' => true,
'is_moderator' => true,
],
[
'expected_result' => false,
'require_tos' => false,
'is_moderator' => false,
],
[
'expected_result' => false,
'require_tos' => true,
'is_moderator' => false,
'context' => [ 'action' => 'search' ],
],
];
Expand All @@ -95,7 +78,6 @@ public function is_allowed_in_context_data_provider() {
private function get_test_subject() {
return new AWPCP_TermsOfServiceFormField(
'slug',
$this->roles,
$this->settings,
$this->template_renderer
);
Expand Down
Loading