feat: wire file transport services
This commit is contained in:
@@ -8,9 +8,13 @@
|
|||||||
namespace WPContentSync;
|
namespace WPContentSync;
|
||||||
|
|
||||||
use WPContentSync\Admin\AdminPage;
|
use WPContentSync\Admin\AdminPage;
|
||||||
|
use WPContentSync\Admin\FileImportController;
|
||||||
use WPContentSync\Logging\LoggerInterface;
|
use WPContentSync\Logging\LoggerInterface;
|
||||||
use WPContentSync\Logging\OptionLogger;
|
use WPContentSync\Logging\OptionLogger;
|
||||||
|
use WPContentSync\Package\PackageValidator;
|
||||||
use WPContentSync\Settings\SettingsRepository;
|
use WPContentSync\Settings\SettingsRepository;
|
||||||
|
use WPContentSync\Transport\FileTransportInterface;
|
||||||
|
use WPContentSync\Transport\JsonFileTransport;
|
||||||
use WPContentSync\Url\MetadataUrlTransformer;
|
use WPContentSync\Url\MetadataUrlTransformer;
|
||||||
use WPContentSync\Url\UrlTransformer;
|
use WPContentSync\Url\UrlTransformer;
|
||||||
|
|
||||||
@@ -54,6 +58,32 @@ final class Plugin {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$container->factory(
|
||||||
|
PackageValidator::class,
|
||||||
|
static function (): PackageValidator {
|
||||||
|
return new PackageValidator();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$container->factory(
|
||||||
|
FileTransportInterface::class,
|
||||||
|
static function () use ( $container ): FileTransportInterface {
|
||||||
|
return new JsonFileTransport(
|
||||||
|
$container->get( PackageValidator::class )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$container->factory(
|
||||||
|
FileImportController::class,
|
||||||
|
static function () use ( $container ): FileImportController {
|
||||||
|
return new FileImportController(
|
||||||
|
$container->get( FileTransportInterface::class ),
|
||||||
|
$container->get( LoggerInterface::class )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$container->factory(
|
$container->factory(
|
||||||
AdminPage::class,
|
AdminPage::class,
|
||||||
static function () use ( $container ): AdminPage {
|
static function () use ( $container ): AdminPage {
|
||||||
@@ -71,6 +101,10 @@ final class Plugin {
|
|||||||
/** @var AdminPage $admin_page */
|
/** @var AdminPage $admin_page */
|
||||||
$admin_page = $this->container->get( AdminPage::class );
|
$admin_page = $this->container->get( AdminPage::class );
|
||||||
|
|
||||||
|
/** @var FileImportController $file_import_controller */
|
||||||
|
$file_import_controller = $this->container->get( FileImportController::class );
|
||||||
|
|
||||||
$admin_page->register();
|
$admin_page->register();
|
||||||
|
$file_import_controller->register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,4 +55,15 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<h2><?php echo esc_html__( 'File Package Import', 'wp-content-sync' ); ?></h2>
|
||||||
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="action" value="wpcs_import_package" />
|
||||||
|
<?php wp_nonce_field( 'wpcs_import_package', 'wpcs_import_package_nonce' ); ?>
|
||||||
|
<p>
|
||||||
|
<label for="wpcs-package-file"><?php echo esc_html__( 'Package JSON file', 'wp-content-sync' ); ?></label>
|
||||||
|
<input id="wpcs-package-file" type="file" name="wpcs_package_file" accept="application/json,.json" />
|
||||||
|
</p>
|
||||||
|
<?php submit_button( __( 'Validate Package', 'wp-content-sync' ), 'secondary' ); ?>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace WPContentSync\Tests\Unit;
|
namespace WPContentSync\Tests\Unit;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use WPContentSync\Admin\FileImportController;
|
||||||
use WPContentSync\Container;
|
use WPContentSync\Container;
|
||||||
use WPContentSync\Plugin;
|
use WPContentSync\Plugin;
|
||||||
|
use WPContentSync\Transport\FileTransportInterface;
|
||||||
use WPContentSync\Url\MetadataUrlTransformer;
|
use WPContentSync\Url\MetadataUrlTransformer;
|
||||||
use WPContentSync\Url\UrlTransformer;
|
use WPContentSync\Url\UrlTransformer;
|
||||||
|
|
||||||
@@ -21,6 +23,19 @@ class PluginTest extends TestCase {
|
|||||||
self::assertSame( $metadata_transformer, $container->get( MetadataUrlTransformer::class ) );
|
self::assertSame( $metadata_transformer, $container->get( MetadataUrlTransformer::class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_registers_file_transport_services(): void {
|
||||||
|
$container = $this->getPluginContainer( Plugin::create() );
|
||||||
|
|
||||||
|
self::assertInstanceOf(
|
||||||
|
FileTransportInterface::class,
|
||||||
|
$container->get( FileTransportInterface::class )
|
||||||
|
);
|
||||||
|
self::assertInstanceOf(
|
||||||
|
FileImportController::class,
|
||||||
|
$container->get( FileImportController::class )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function getPluginContainer( Plugin $plugin ): Container {
|
private function getPluginContainer( Plugin $plugin ): Container {
|
||||||
$reflection = new \ReflectionClass( $plugin );
|
$reflection = new \ReflectionClass( $plugin );
|
||||||
$property = $reflection->getProperty( 'container' );
|
$property = $reflection->getProperty( 'container' );
|
||||||
|
|||||||
@@ -395,6 +395,32 @@ if ( ! function_exists( 'add_query_arg' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'wp_nonce_field' ) ) {
|
||||||
|
/**
|
||||||
|
* Minimal nonce field renderer for unit tests.
|
||||||
|
*
|
||||||
|
* @param string $action Nonce action.
|
||||||
|
* @param string $name Field name.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function wp_nonce_field( $action, $name ) {
|
||||||
|
echo '<input type="hidden" name="' . esc_attr( $name ) . '" value="' . esc_attr( $action ) . '" />';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'submit_button' ) ) {
|
||||||
|
/**
|
||||||
|
* Minimal submit button renderer for unit tests.
|
||||||
|
*
|
||||||
|
* @param string $text Button text.
|
||||||
|
* @param string $type Button type.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function submit_button( $text, $type = 'primary' ) {
|
||||||
|
echo '<button class="button button-' . esc_attr( $type ) . '" type="submit">' . esc_html( $text ) . '</button>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! function_exists( 'wp_die' ) ) {
|
if ( ! function_exists( 'wp_die' ) ) {
|
||||||
/**
|
/**
|
||||||
* Minimal WordPress die handler for unit tests.
|
* Minimal WordPress die handler for unit tests.
|
||||||
|
|||||||
Reference in New Issue
Block a user