diff --git a/src/Plugin.php b/src/Plugin.php index 4b1838a..3d1f504 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -8,9 +8,13 @@ namespace WPContentSync; use WPContentSync\Admin\AdminPage; +use WPContentSync\Admin\FileImportController; use WPContentSync\Logging\LoggerInterface; use WPContentSync\Logging\OptionLogger; +use WPContentSync\Package\PackageValidator; use WPContentSync\Settings\SettingsRepository; +use WPContentSync\Transport\FileTransportInterface; +use WPContentSync\Transport\JsonFileTransport; use WPContentSync\Url\MetadataUrlTransformer; 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( AdminPage::class, static function () use ( $container ): AdminPage { @@ -71,6 +101,10 @@ final class Plugin { /** @var AdminPage $admin_page */ $admin_page = $this->container->get( AdminPage::class ); + /** @var FileImportController $file_import_controller */ + $file_import_controller = $this->container->get( FileImportController::class ); + $admin_page->register(); + $file_import_controller->register(); } } diff --git a/templates/admin/dashboard.php b/templates/admin/dashboard.php index 98dfb66..e066fa6 100644 --- a/templates/admin/dashboard.php +++ b/templates/admin/dashboard.php @@ -55,4 +55,15 @@ if ( ! defined( 'ABSPATH' ) ) { + +
+ diff --git a/tests/Unit/PluginTest.php b/tests/Unit/PluginTest.php index 9c5a1e5..f7dec7b 100644 --- a/tests/Unit/PluginTest.php +++ b/tests/Unit/PluginTest.php @@ -3,8 +3,10 @@ namespace WPContentSync\Tests\Unit; use PHPUnit\Framework\TestCase; +use WPContentSync\Admin\FileImportController; use WPContentSync\Container; use WPContentSync\Plugin; +use WPContentSync\Transport\FileTransportInterface; use WPContentSync\Url\MetadataUrlTransformer; use WPContentSync\Url\UrlTransformer; @@ -21,6 +23,19 @@ class PluginTest extends TestCase { 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 { $reflection = new \ReflectionClass( $plugin ); $property = $reflection->getProperty( 'container' ); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1b9282d..77520e0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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 ''; + } +} + +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 ''; + } +} + if ( ! function_exists( 'wp_die' ) ) { /** * Minimal WordPress die handler for unit tests.