Skip to content

Commit 81c8d73

Browse files
authored
Merge pull request #341 from lloc/refactoring-2-9
Service tested
2 parents a49a9eb + 8a4e3cd commit 81c8d73

File tree

2 files changed

+75
-25
lines changed

2 files changed

+75
-25
lines changed

includes/ContentImport/Service.php

+46-25
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,56 @@ public function register() {
3636
* Differently from the `register` method this method will not check for options to hook.
3737
*/
3838
public function hook() {
39-
add_action( 'load-post.php', function () {
40-
return ContentImporter::instance()->handle_import();
41-
} );
42-
add_action( 'load-post.php', function () {
43-
add_action( 'admin_notices', function () {
44-
AdminNoticeLogger::instance()->show_last_log();
45-
} );
46-
} );
47-
add_action( 'load-post-new.php', function () {
48-
return ContentImporter::instance()->handle_import();
49-
} );
50-
add_filter( 'wp_insert_post_empty_content', function ( $empty ) {
51-
return ContentImporter::instance()->filter_empty( $empty );
52-
} );
53-
add_filter( 'wp_get_attachment_url', function ( $url, $post_id ) {
54-
return AttachmentPathFinder::instance()->filter_attachment_url( $url, $post_id );
55-
}, 99, 2 );
56-
add_filter( 'wp_calculate_image_srcset',
39+
add_action(
40+
'load-post.php',
41+
function () {
42+
return ContentImporter::instance()->handle_import();
43+
}
44+
);
45+
add_action(
46+
'load-post.php',
47+
function () {
48+
add_action(
49+
'admin_notices',
50+
function () {
51+
AdminNoticeLogger::instance()->show_last_log();
52+
}
53+
);
54+
}
55+
);
56+
add_action(
57+
'load-post-new.php',
58+
function () {
59+
return ContentImporter::instance()->handle_import();
60+
}
61+
);
62+
add_filter(
63+
'wp_insert_post_empty_content',
64+
function ( $empty ) {
65+
return ContentImporter::instance()->filter_empty( $empty );
66+
}
67+
);
68+
add_filter(
69+
'wp_get_attachment_url',
70+
function ( $url, $post_id ) {
71+
return AttachmentPathFinder::instance()->filter_attachment_url( $url, $post_id );
72+
},
73+
99,
74+
2
75+
);
76+
add_filter(
77+
'wp_calculate_image_srcset',
5778
function ( $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId ) {
58-
return AttachmentPathFinder::instance()->filter_srcset( $sources,
79+
return AttachmentPathFinder::instance()->filter_srcset(
80+
$sources,
5981
$sizeArray,
6082
$imageSrc,
6183
$imageMeta,
62-
$attachmentId );
84+
$attachmentId
85+
);
6386
},
6487
99,
65-
5 );
66-
67-
if ( is_admin() ) {
68-
}
88+
5
89+
);
6990
}
70-
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport;
4+
5+
use lloc\Msls\ContentImport\Service;
6+
use lloc\Msls\MslsOptions;
7+
use lloc\MslsTests\MslsUnitTestCase;
8+
use Brain\Monkey\Functions;
9+
10+
class TestService extends MslsUnitTestCase {
11+
12+
public function test_register_not_active_false(): void {
13+
$options = \Mockery::mock( MslsOptions::class );
14+
$options->activate_content_import = false;
15+
16+
Functions\expect( 'msls_options' )->once()->andReturn( $options );
17+
18+
$this->assertFalse( ( new Service() )->register() );
19+
}
20+
21+
public function test_register_active_true(): void {
22+
$options = \Mockery::mock( MslsOptions::class );
23+
$options->activate_content_import = true;
24+
25+
Functions\expect( 'msls_options' )->once()->andReturn( $options );
26+
27+
$this->assertTrue( ( new Service() )->register() );
28+
}
29+
}

0 commit comments

Comments
 (0)