Skip to content

Commit 5a75a19

Browse files
authored
Import coordinates 1 (#403)
* ImportCoordinates tested and refactored * Cleanup * Tests added
1 parent cbc6139 commit 5a75a19

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<const name="MSLS_PLUGIN_PATH" value="multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
1919
<const name="MSLS_PLUGIN__FILE__" value="/var/www/html/wp-content/plugins/multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
2020
<const name="WP_DEBUG" value="true"/>
21+
<const name="HOUR_IN_SECONDS" value="3600"/>
2122
</php>
2223
<testsuite name="Internal tests">
2324
<directory prefix="Test" suffix=".php">tests/phpunit</directory>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers\Attachments;
4+
5+
use Brain\Monkey\Functions;
6+
use lloc\Msls\ContentImport\ImportCoordinates;
7+
use lloc\Msls\ContentImport\Importers\Attachments\Linking;
8+
use lloc\MslsTests\MslsUnitTestCase;
9+
10+
class TestLinking extends MslsUnitTestCase {
11+
12+
public function testImport(): void {
13+
$coordinates = \Mockery::mock( ImportCoordinates::class );
14+
15+
$this->assertEquals( array(), ( new Linking( $coordinates ) )->import( array() ) );
16+
}
17+
18+
public function testInfo(): void {
19+
$object = (object) array(
20+
'slug' => 'linking',
21+
'name' => 'Linking',
22+
'description' => 'Links the media attachments from the source post to the destination post; media attachments are not duplicated.',
23+
);
24+
$this->assertEquals( $object, Linking::info() );
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers\PostMeta;
4+
5+
use Brain\Monkey\Functions;
6+
use lloc\Msls\ContentImport\ImportCoordinates;
7+
use lloc\Msls\ContentImport\Importers\PostMeta\Duplicating;
8+
use lloc\MslsTests\MslsUnitTestCase;
9+
10+
use function Brain\Monkey\Functions;
11+
12+
class TestDuplicating extends MslsUnitTestCase {
13+
14+
public function testImport(): void {
15+
Functions\expect( 'switch_to_blog' )->twice();
16+
Functions\expect( 'get_post_custom' )->once()->andReturn( array( 88 => array( 'foo' => 'bar' ) ) );
17+
Functions\expect( 'wp_cache_delete' )->once();
18+
Functions\expect( 'restore_current_blog' )->once();
19+
Functions\expect( 'delete_post_meta' )->once();
20+
Functions\expect( 'maybe_unserialize' )->once()->andReturnFirstArg();
21+
Functions\expect( 'add_post_meta' )->once();
22+
23+
$coordinates = \Mockery::mock( ImportCoordinates::class );
24+
$coordinates->source_blog_id = 1;
25+
$coordinates->source_post_id = 42;
26+
$coordinates->dest_blog_id = 2;
27+
$coordinates->dest_post_id = 13;
28+
29+
$this->assertEquals( array(), ( new Duplicating( $coordinates ) )->import( array() ) );
30+
}
31+
}

tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@
22

33
namespace lloc\MslsTests\ContentImport\LogWriters;
44

5+
use Brain\Monkey\Functions;
6+
use lloc\Msls\ContentImport\ImportCoordinates;
57
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
68
use lloc\MslsTests\MslsUnitTestCase;
79

810
class TestAdminNoticeLogger extends MslsUnitTestCase {
911

10-
1112
public function setUp(): void {
1213
parent::setUp();
1314

1415
$this->test = new AdminNoticeLogger();
1516
}
1617

17-
public function test_get_transient(): void {
18+
public function testGetTransient(): void {
1819
$this->assertEquals( 'msls_last_import_log', $this->test->get_transient() );
1920
}
21+
22+
public function testWrite(): void {
23+
Functions\expect( 'switch_to_blog' )->once();
24+
Functions\expect( 'set_transient' )->once();
25+
26+
$coordinates = \Mockery::mock( ImportCoordinates::class );
27+
$coordinates->source_blog_id = 1;
28+
$coordinates->source_post_id = 42;
29+
$coordinates->dest_blog_id = 2;
30+
$coordinates->dest_post_id = 13;
31+
32+
$this->test->set_import_coordinates( $coordinates );
33+
34+
$data = array( 'info', array( 'foo' ) );
35+
$this->test->write( $data );
36+
37+
$this->expectNotToPerformAssertions();
38+
}
2039
}

0 commit comments

Comments
 (0)