From ff7e99caba15183ac459f836e2cac02bf634af34 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sun, 17 Nov 2024 13:20:33 +0100 Subject: [PATCH] Tests added --- phpunit.xml | 1 + .../Importers/Attachments/TestLinking.php | 26 ++++++++++++++++ .../Importers/PostMeta/TestDuplicating.php | 31 +++++++++++++++++++ .../LogWriters/TestAdminNoticeLogger.php | 23 ++++++++++++-- 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php create mode 100644 tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php diff --git a/phpunit.xml b/phpunit.xml index c10c51d2..da5a113f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,6 +18,7 @@ + tests/phpunit diff --git a/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php b/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php new file mode 100644 index 00000000..2fa777b6 --- /dev/null +++ b/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php @@ -0,0 +1,26 @@ +assertEquals( array(), ( new Linking( $coordinates ) )->import( array() ) ); + } + + public function testInfo(): void { + $object = (object) array( + 'slug' => 'linking', + 'name' => 'Linking', + 'description' => 'Links the media attachments from the source post to the destination post; media attachments are not duplicated.', + ); + $this->assertEquals( $object, Linking::info() ); + } +} diff --git a/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php b/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php new file mode 100644 index 00000000..98a98929 --- /dev/null +++ b/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php @@ -0,0 +1,31 @@ +twice(); + Functions\expect( 'get_post_custom' )->once()->andReturn( array( 88 => array( 'foo' => 'bar' ) ) ); + Functions\expect( 'wp_cache_delete' )->once(); + Functions\expect( 'restore_current_blog' )->once(); + Functions\expect( 'delete_post_meta' )->once(); + Functions\expect( 'maybe_unserialize' )->once()->andReturnFirstArg(); + Functions\expect( 'add_post_meta' )->once(); + + $coordinates = \Mockery::mock( ImportCoordinates::class ); + $coordinates->source_blog_id = 1; + $coordinates->source_post_id = 42; + $coordinates->dest_blog_id = 2; + $coordinates->dest_post_id = 13; + + $this->assertEquals( array(), ( new Duplicating( $coordinates ) )->import( array() ) ); + } +} diff --git a/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php b/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php index d5f7fdc4..d7665f02 100644 --- a/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php +++ b/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php @@ -2,19 +2,38 @@ namespace lloc\MslsTests\ContentImport\LogWriters; +use Brain\Monkey\Functions; +use lloc\Msls\ContentImport\ImportCoordinates; use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger; use lloc\MslsTests\MslsUnitTestCase; class TestAdminNoticeLogger extends MslsUnitTestCase { - public function setUp(): void { parent::setUp(); $this->test = new AdminNoticeLogger(); } - public function test_get_transient(): void { + public function testGetTransient(): void { $this->assertEquals( 'msls_last_import_log', $this->test->get_transient() ); } + + public function testWrite(): void { + Functions\expect( 'switch_to_blog' )->once(); + Functions\expect( 'set_transient' )->once(); + + $coordinates = \Mockery::mock( ImportCoordinates::class ); + $coordinates->source_blog_id = 1; + $coordinates->source_post_id = 42; + $coordinates->dest_blog_id = 2; + $coordinates->dest_post_id = 13; + + $this->test->set_import_coordinates( $coordinates ); + + $data = array( 'info', array( 'foo' ) ); + $this->test->write( $data ); + + $this->expectNotToPerformAssertions(); + } }