Skip to content

Commit

Permalink
Import coordinates 1 (#403)
Browse files Browse the repository at this point in the history
* ImportCoordinates tested and refactored
* Cleanup
* Tests added
  • Loading branch information
lloc authored Nov 17, 2024
1 parent cbc6139 commit 5a75a19
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<const name="MSLS_PLUGIN_PATH" value="multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
<const name="MSLS_PLUGIN__FILE__" value="/var/www/html/wp-content/plugins/multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
<const name="WP_DEBUG" value="true"/>
<const name="HOUR_IN_SECONDS" value="3600"/>
</php>
<testsuite name="Internal tests">
<directory prefix="Test" suffix=".php">tests/phpunit</directory>
Expand Down
26 changes: 26 additions & 0 deletions tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace lloc\MslsTests\ContentImport\Importers\Attachments;

use Brain\Monkey\Functions;
use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Importers\Attachments\Linking;
use lloc\MslsTests\MslsUnitTestCase;

class TestLinking extends MslsUnitTestCase {

public function testImport(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );

$this->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() );
}
}
31 changes: 31 additions & 0 deletions tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace lloc\MslsTests\ContentImport\Importers\PostMeta;

use Brain\Monkey\Functions;
use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Importers\PostMeta\Duplicating;
use lloc\MslsTests\MslsUnitTestCase;

use function Brain\Monkey\Functions;

class TestDuplicating extends MslsUnitTestCase {

public function testImport(): void {
Functions\expect( 'switch_to_blog' )->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() ) );
}
}
23 changes: 21 additions & 2 deletions tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 5a75a19

Please sign in to comment.