fix: handle invalid package uploads
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace WPContentSync\Tests\Unit\Admin;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use WPContentSync\Settings\Settings;
|
||||
|
||||
class DashboardTemplateTest extends TestCase {
|
||||
protected function tearDown(): void {
|
||||
$_GET = array();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_it_renders_import_error_notices(): void {
|
||||
$_GET['wpcs_import_error'] = 'The selected file is not valid JSON.';
|
||||
|
||||
$output = $this->renderDashboard();
|
||||
|
||||
self::assertStringContainsString( 'notice-error', $output );
|
||||
self::assertStringContainsString( 'The selected file is not valid JSON.', $output );
|
||||
}
|
||||
|
||||
public function test_it_renders_import_success_notices(): void {
|
||||
$_GET['wpcs_imported'] = '1';
|
||||
|
||||
$output = $this->renderDashboard();
|
||||
|
||||
self::assertStringContainsString( 'notice-success', $output );
|
||||
self::assertStringContainsString( 'The package JSON file was validated successfully.', $output );
|
||||
}
|
||||
|
||||
private function renderDashboard(): string {
|
||||
$settings = Settings::fromArray( array() );
|
||||
|
||||
ob_start();
|
||||
include WPCS_PLUGIN_DIR . 'templates/admin/dashboard.php';
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user