Skip to content

Commit c08cb46

Browse files
committed
Raised coverage for importers
1 parent e70d814 commit c08cb46

File tree

9 files changed

+175
-17
lines changed

9 files changed

+175
-17
lines changed

includes/ContentImport/Importers/Terms/ShallowDuplicating.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ class ShallowDuplicating extends BaseImporter {
2020
/**
2121
* @var array
2222
*/
23-
protected $reset_taxonomies = [];
23+
protected $reset_taxonomies = array();
2424

2525
/**
2626
* Returns an array of information about the importer.
2727
*
2828
* @return \stdClass
2929
*/
3030
public static function info() {
31-
return (object) [
31+
return (object) array(
3232
'slug' => static::TYPE,
3333
'name' => __( 'Shallow Duplicating', 'multisite-language-switcher' ),
34-
'description' => __( 'Shallow (one level deep) duplication or assignment of the source post taxonomy terms to the destnation post.',
35-
'multisite-language-switcher' )
36-
];
34+
'description' => __(
35+
'Shallow (one level deep) duplication or assignment of the source post taxonomy terms to the destination post.',
36+
'multisite-language-switcher'
37+
),
38+
);
3739
}
3840

3941
public function import( array $data ) {
@@ -98,14 +100,14 @@ protected function create_local_term( \WP_Term $term, MslsOptionsTax $msls_term,
98100
$dest_term_id = wp_create_term( $term->name, $term->taxonomy );
99101

100102
if ( $dest_term_id instanceof \WP_Error ) {
101-
$this->logger->log_error( "term/created/{$term->taxonomy}", [ $term->name ] );
103+
$this->logger->log_error( "term/created/{$term->taxonomy}", array( $term->name ) );
102104

103105
return false;
104106
}
105107

106108
$dest_term_id = (int) reset( $dest_term_id );
107109
$this->relations->should_create( $msls_term, $dest_lang, $dest_term_id );
108-
$this->logger->log_success( "term/created/{$term->taxonomy}", [ $term->name => $term->term_id ] );
110+
$this->logger->log_success( "term/created/{$term->taxonomy}", array( $term->name => $term->term_id ) );
109111
$meta = $this->filter_term_meta( $meta, $term );
110112
if ( ! empty( $meta ) ) {
111113
foreach ( $meta as $key => $value ) {
@@ -125,18 +127,20 @@ protected function filter_term_meta( array $meta, \WP_Term $term ) {
125127
* @param array $meta
126128
* @param ImportCoordinates $import_coordinates
127129
*/
128-
$blacklist = apply_filters( 'msls_content_import_term_meta_blacklist',
130+
$blacklist = apply_filters(
131+
'msls_content_import_term_meta_blacklist',
129132
array(),
130133
$term,
131134
$meta,
132-
$this->import_coordinates );
135+
$this->import_coordinates
136+
);
133137

134138
return array_diff_key( $meta, array_combine( $blacklist, $blacklist ) );
135139
}
136140

137141
protected function update_object_terms( $object_id, $dest_term_id, $taxonomy ) {
138142
if ( ! in_array( $taxonomy, $this->reset_taxonomies, true ) ) {
139-
wp_set_object_terms( $object_id, [], $taxonomy );
143+
wp_set_object_terms( $object_id, array(), $taxonomy );
140144
$this->reset_taxonomies[] = $taxonomy;
141145
}
142146

includes/ContentImport/MetaBox.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use lloc\Msls\MslsRequest;
1313

1414
class MetaBox extends MslsRegistryInstance {
15-
protected $data = array();
15+
16+
protected array $data = array();
1617

1718
/**
1819
* Renders the content import metabox.

includes/ContentImport/Service.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Service extends MslsRegistryInstance {
1919
*
2020
* @return bool Whether the content import functionality support classes where hooked or not.
2121
*/
22-
public function register() {
22+
public function register(): bool {
2323
if ( ! msls_options()->activate_content_import ) {
2424
return false;
2525
}
@@ -34,11 +34,11 @@ public function register() {
3434
*
3535
* Differently from the `register` method this method will not check for options to hook.
3636
*/
37-
public function hook() {
37+
public function hook(): void {
3838
add_action(
3939
'load-post.php',
4040
function () {
41-
return ContentImporter::instance()->handle_import();
41+
ContentImporter::instance()->handle_import();
4242
}
4343
);
4444
add_action(
@@ -55,7 +55,7 @@ function () {
5555
add_action(
5656
'load-post-new.php',
5757
function () {
58-
return ContentImporter::instance()->handle_import();
58+
ContentImporter::instance()->handle_import();
5959
}
6060
);
6161
add_filter(

tests/phpunit/ContentImport/Importers/TestAttachmentsImporters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestAttachmentsImporters extends MslsUnitTestCase {
99

1010

1111
public function testDetails(): void {
12-
$obj = new AttachmentsImporters();
12+
$test = new AttachmentsImporters();
1313

1414
$expected = (object) array(
1515
'slug' => 'attachments',
@@ -24,6 +24,6 @@ public function testDetails(): void {
2424
'selected' => 'linking',
2525
);
2626

27-
$this->assertEquals( $expected, $obj->details() );
27+
$this->assertEquals( $expected, $test->details() );
2828
}
2929
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers;
4+
5+
use lloc\Msls\ContentImport\ImportCoordinates;
6+
use lloc\Msls\ContentImport\Importers\BaseImporter;
7+
use lloc\Msls\ContentImport\ImportLogger;
8+
use lloc\Msls\ContentImport\Relations;
9+
use lloc\MslsTests\MslsUnitTestCase;
10+
11+
class TestBaseImporter extends MslsUnitTestCase {
12+
13+
public function setUp(): void {
14+
parent::setUp();
15+
16+
$import_coordinates = \Mockery::mock( ImportCoordinates::class );
17+
$this->test = new BaseImporter( $import_coordinates );
18+
}
19+
20+
public function testImport(): void {
21+
$this->assertEquals( array(), $this->test->import( array() ) );
22+
}
23+
24+
public function testSetImportCoordinates(): void {
25+
$import_coordinates = \Mockery::mock( ImportCoordinates::class );
26+
27+
$this->expectNotToPerformAssertions();
28+
$this->test->set_import_coordinates( $import_coordinates );
29+
}
30+
31+
public function testGetLogger() {
32+
$this->assertInstanceOf( ImportLogger::class, $this->test->get_logger() );
33+
}
34+
public function testGetRelations() {
35+
$this->assertInstanceOf( Relations::class, $this->test->get_relations() );
36+
}
37+
38+
public function testInfo() {
39+
$this->assertInstanceOf( \stdClass::class, $this->test->info() );
40+
}
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers;
4+
5+
use lloc\Msls\ContentImport\Importers\PostFieldsImporters;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
8+
class TestPostFieldsImporters extends MslsUnitTestCase {
9+
10+
public function testDetails(): void {
11+
$test = new PostFieldsImporters();
12+
13+
$expected = (object) array(
14+
'slug' => 'post-fields',
15+
'name' => 'Post Fields',
16+
'importers' => array(
17+
'duplicating' => (object) array(
18+
'name' => 'Duplicating',
19+
'description' => 'Copies the source post fields to the destination.',
20+
'slug' => 'duplicating',
21+
),
22+
),
23+
'selected' => 'duplicating',
24+
);
25+
26+
$this->assertEquals( $expected, $test->details() );
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers;
4+
5+
use lloc\Msls\ContentImport\Importers\PostMetaImporters;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
8+
class TestPostMetaImporters extends MslsUnitTestCase {
9+
10+
public function testDetails(): void {
11+
$test = new PostMetaImporters();
12+
13+
$expected = (object) array(
14+
'slug' => 'post-meta',
15+
'name' => 'Meta Fields',
16+
'importers' => array(
17+
'duplicating' => (object) array(
18+
'name' => 'Duplicating',
19+
'description' => 'Copies the source post meta to the destination.',
20+
'slug' => 'duplicating',
21+
),
22+
),
23+
'selected' => 'duplicating',
24+
);
25+
26+
$this->assertEquals( $expected, $test->details() );
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers;
4+
5+
use lloc\Msls\ContentImport\Importers\PostThumbnailImporters;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
8+
class TestPostThumbnailImporters extends MslsUnitTestCase {
9+
10+
public function testDetails(): void {
11+
$test = new PostThumbnailImporters();
12+
13+
$expected = (object) array(
14+
'slug' => 'post-thumbnail',
15+
'name' => 'Featured Image',
16+
'importers' => array(
17+
'linking' => (object) array(
18+
'name' => 'Linking',
19+
'description' => 'Links the featured image from the source post to the destination post; the image is not duplicated.',
20+
'slug' => 'linking',
21+
),
22+
),
23+
'selected' => 'linking',
24+
);
25+
26+
$this->assertEquals( $expected, $test->details() );
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\Importers;
4+
5+
use lloc\Msls\ContentImport\Importers\TermsImporters;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
8+
class TestTermsImporters extends MslsUnitTestCase {
9+
10+
public function testDetails(): void {
11+
$test = new TermsImporters();
12+
13+
$expected = (object) array(
14+
'slug' => 'terms',
15+
'name' => 'Taxonomy Terms',
16+
'importers' => array(
17+
'shallow-duplicating' => (object) array(
18+
'name' => 'Shallow Duplicating',
19+
'description' => 'Shallow (one level deep) duplication or assignment of the source post taxonomy terms to the destination post.',
20+
'slug' => 'shallow-duplicating',
21+
),
22+
),
23+
'selected' => 'shallow-duplicating',
24+
);
25+
26+
$this->assertEquals( $expected, $test->details() );
27+
}
28+
}

0 commit comments

Comments
 (0)