Skip to content

Commit

Permalink
test: integration test for toolbox, legals, main settings + post_process
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-hours committed Aug 21, 2024
1 parent a5c29fc commit a070437
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions tests/integration/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,127 @@ public function test_admin_help() {
);
}
}

public function test_admin_settings() {
$this->init_with_mock_client();
$this->mock_on_access_token();
$this->mock_basic_stuff();

$admin = new Lengow_Admin();
$admin->current_tab = 'lengow_admin_settings';
ob_start();
$admin->lengow_display();
$output = ob_get_clean();

$expected = [
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'global_setting.screen.notification_alert_title' ) ) ),
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'global_setting.screen.export_title' ) ) ),
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'global_setting.screen.security_title' ) ) ),
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'global_setting.screen.shop_title' ) ) ),
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'global_setting.screen.debug_mode_title' ) ) ),
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'global_setting.screen.log_file_title' ) ) ),
];

foreach ( $expected as $expr ) {
$this->assertMatchesRegularExpression(
'/' . $expr . '/',
$output,
'Output should contain message: ' . $expr
);
}
}

public function test_admin_settings_post_process() {
$post_data = [
'action' => 'process',
'lengow_report_mail_enabled' => 'on',
'lengow_report_mail_address' => '',
'lengow_product_types' => ['simple', 'variable', 'external', 'grouped'],
'lengow_ip_enabled' => 0,
'lengow_authorized_ip' => '',
'lengow_store_enabled' => 'on',
'lengow_catalog_id' => 456, // changed
'lengow_debug_enabled' => 0,
'lengow_plugin_env' => 'preprod',
'lengow_account_id' => 124, // changed
'lengow_access_token' => '****', // changed
'lengow_secret_token' => '****', // changed
];

foreach ( $post_data as $k => $v ) {
$_POST[ $k ] = $v;
}

Lengow_Configuration::update_value( Lengow_Configuration::ACCESS_TOKEN, '***' );
Lengow_Configuration::update_value( Lengow_Configuration::SECRET, '***' );
Lengow_Configuration::update_value( Lengow_Configuration::ACCOUNT_ID, '123' );
Lengow_Configuration::update_value( Lengow_Configuration::CATALOG_IDS, '123' );

$val = Lengow_Configuration::get( 'lengow_catalog_id' );
$this->assertEquals( '123', $val );
$this->assertEquals( [ '123', '***', '***' ], Lengow_Configuration::get_access_id() );

Lengow_Admin_Main_Settings::post_process();

foreach ( $post_data as $k => $v ) {
unset( $_POST[ $k ] );
}

$val = Lengow_Configuration::get( 'lengow_catalog_id' );
$this->assertEquals( '456', $val );
$this->assertEquals( [ '124', '****', '****' ], Lengow_Configuration::get_access_id() );
}

public function test_admin_legals() {
$this->init_with_mock_client();
$this->mock_on_access_token();
$this->mock_basic_stuff();

$admin = new Lengow_Admin();
$admin->current_tab = 'lengow_admin_legals';
ob_start();
$admin->lengow_display();
$output = ob_get_clean();

$expected = [
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'legals.screen.simplified_company' ) ) ),
];

foreach ( $expected as $expr ) {
$this->assertMatchesRegularExpression(
'/' . $expr . '/',
$output,
'Output should contain message: ' . $expr
);
}
}

public function test_admin_toolbox() {
$this->init_with_mock_client();
$this->mock_on_access_token();
$this->mock_basic_stuff();

$admin = new Lengow_Admin();
$admin->current_tab = 'lengow_admin_toolbox';
ob_start();
$admin->lengow_display();
$output = ob_get_clean();

$expected = [
preg_quote( esc_html( ( new Lengow_Translation() )->t( 'toolbox.screen.plugin_version' ) ) ),
'\<b\>' . preg_quote( $GLOBALS['lengow']->version ) . '\<\/b\>'
];

foreach ( $expected as $expr ) {
$this->assertMatchesRegularExpression(
'/' . $expr . '/',
$output,
'Output should contain message: ' . $expr
);
}

if ( preg_match( '/Some files have been changed by the customer/', $output ) ) {
$this->addWarning( 'checkmd5.csv file not up to date !' );
}
}
}

0 comments on commit a070437

Please sign in to comment.