feat: add admin notices
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for redirect-driven admin notices.
|
||||
*
|
||||
* @package WPContentSync
|
||||
*/
|
||||
|
||||
namespace WPContentSync\Tests\Unit\Admin;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use WPContentSync\Admin\AdminNoticeRepository;
|
||||
|
||||
class AdminNoticeRepositoryTest extends TestCase {
|
||||
protected function tearDown(): void {
|
||||
$_GET = array();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_it_builds_import_success_notices(): void {
|
||||
$_GET['wpcs_imported'] = '1';
|
||||
$notices = ( new AdminNoticeRepository() )->current();
|
||||
|
||||
self::assertSame( 'success', $notices[0]->type() );
|
||||
self::assertSame( 'The package JSON file was imported successfully.', $notices[0]->message() );
|
||||
}
|
||||
|
||||
public function test_it_sanitizes_error_notices(): void {
|
||||
$_GET['wpcs_import_error'] = '<script>Bad package</script>';
|
||||
$notices = ( new AdminNoticeRepository() )->current();
|
||||
|
||||
self::assertSame( 'error', $notices[0]->type() );
|
||||
self::assertSame( 'Bad package', $notices[0]->message() );
|
||||
}
|
||||
|
||||
public function test_it_builds_settings_connection_logs_and_export_notices(): void {
|
||||
$_GET['wpcs_settings_saved'] = '1';
|
||||
$_GET['wpcs_connection_ok'] = '1';
|
||||
$_GET['wpcs_logs_cleared'] = '1';
|
||||
$_GET['wpcs_connection_error'] = 'REST authentication failed.';
|
||||
$_GET['wpcs_export_error'] = 'Export failed.';
|
||||
|
||||
$notices = ( new AdminNoticeRepository() )->current();
|
||||
|
||||
self::assertSame( 'Settings saved.', $notices[0]->message() );
|
||||
self::assertSame( 'REST connection succeeded.', $notices[1]->message() );
|
||||
self::assertSame( 'Logs cleared.', $notices[2]->message() );
|
||||
self::assertSame( 'REST authentication failed.', $notices[3]->message() );
|
||||
self::assertSame( 'Export failed.', $notices[4]->message() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user