Skip to content

Commit 0a14cee

Browse files
authored
Merge pull request #332 from lloc/refactoring-version-2-8
Tests added
2 parents f302e85 + 2981163 commit 0a14cee

File tree

4 files changed

+95
-34
lines changed

4 files changed

+95
-34
lines changed

includes/ContentImport/LogWriters/AdminNoticeLogger.php

+53-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace lloc\Msls\ContentImport\LogWriters;
44

5-
65
use lloc\Msls\ContentImport\ImportCoordinates;
76
use lloc\Msls\MslsRegistryInstance;
87

@@ -15,43 +14,57 @@ class AdminNoticeLogger extends MslsRegistryInstance implements LogWriter {
1514
protected $import_coordinates;
1615

1716
public function write( array $data ) {
18-
$message = '<h3>' . esc_html__( 'Multisite Language Switcher last import report',
19-
'multisite-language-switcher' ) . '</h3>';
17+
/* translators: %1$d: source post ID, %2$d: source blog ID, %3$d: destination post ID, %4$d: destination blog ID */
18+
$format = esc_html__( 'From post %1$d on site %2$d to post %3$d on site %4$d', 'multisite-language-switcher' );
19+
20+
$message = '<h3>' . esc_html__( 'Multisite Language Switcher last import report', 'multisite-language-switcher' ) . '</h3>';
2021
$message .= '<b>' . sprintf(
21-
esc_html__( 'From post %d on site %d to post %d on site %d', 'multisite-language-switcher' ),
22-
$this->import_coordinates->source_post_id,
23-
$this->import_coordinates->source_blog_id,
24-
$this->import_coordinates->dest_post_id,
25-
$this->import_coordinates->dest_blog_id
26-
) . '</b>';
22+
$format,
23+
$this->import_coordinates->source_post_id,
24+
$this->import_coordinates->source_blog_id,
25+
$this->import_coordinates->dest_post_id,
26+
$this->import_coordinates->dest_blog_id
27+
) . '</b>';
2728
if ( ! empty( $data['info'] ) ) {
2829
$section_title = esc_html__( 'General information', 'multisite-language-switcher' );
2930
$entries = $data['info'];
30-
$message .= $this->get_section_html( $section_title, $entries );
31+
$message .= $this->get_section_html( $section_title, $entries );
3132
}
3233

3334
if ( ! empty( $data['success'] ) ) {
3435
$section_title = esc_html__( 'Details', 'multisite-language-switcher' );
3536
$success_data = $data['success'];
36-
$success_entries = [];
37+
$success_entries = array();
3738

3839
if ( isset( $success_data['post-field']['added'] ) ) {
39-
$success_entries[] = esc_html__( 'The following post fields have been set: ',
40-
'multisite-language-switcher' ) .
41-
'<code>' . implode( '</code>, <code>',
42-
array_keys( $success_data['post-field']['added'] ) ) . '</code>.';
40+
$success_entries[] = esc_html__(
41+
'The following post fields have been set: ',
42+
'multisite-language-switcher'
43+
) .
44+
'<code>' . implode(
45+
'</code>, <code>',
46+
array_keys( $success_data['post-field']['added'] )
47+
) . '</code>.';
4348
}
4449
if ( isset( $success_data['meta']['added'] ) ) {
45-
$success_entries[] = esc_html__( 'The following post meta have been set: ',
46-
'multisite-language-switcher' ) .
47-
'<code>' . implode( '</code>, <code>',
48-
array_keys( $success_data['meta']['added'] ) ) . '</code>.';
50+
$success_entries[] = esc_html__(
51+
'The following post meta have been set: ',
52+
'multisite-language-switcher'
53+
) .
54+
'<code>' . implode(
55+
'</code>, <code>',
56+
array_keys( $success_data['meta']['added'] )
57+
) . '</code>.';
4958
}
5059
if ( isset( $success_data['term']['added'] ) ) {
51-
$success_entries[] = esc_html__( 'Terms have been assigned to the post for the following taxonomies: ',
52-
'multisite-language-switcher' ) .
53-
'<code>' . implode( '</code>, <code>',
54-
array_keys( $success_data['term']['added'] ) ) . '</code>.';
60+
$success_entries[] = esc_html__(
61+
'Terms have been assigned to the post for the following taxonomies: ',
62+
'multisite-language-switcher'
63+
) .
64+
'<code>' . implode(
65+
'</code>, <code>',
66+
array_keys( $success_data['term']['added'] )
67+
) . '</code>.';
5568
}
5669
if ( isset( $success_data['post-thumbnail']['set'] ) ) {
5770
$success_entries[] = esc_html__( 'The post thumbnail has been set.', 'multisite-language-switcher' );
@@ -63,18 +76,24 @@ public function write( array $data ) {
6376
if ( ! empty( $data['error'] ) ) {
6477
$section_title = esc_html__( 'Errors:', 'multisite-language-switcher' );
6578
$error_data = $data['error'];
66-
$error_entries = [];
79+
$error_entries = array();
6780
if ( isset( $error_data['term']['added'] ) || isset( $error_data['term']['created'] ) ) {
68-
$taxonomies = isset( $error_data['term']['added'] ) ? array_keys( $error_data['term']['added'] ) : [];
69-
$taxonomies = isset( $error_data['term']['created'] ) ? array_merge( $taxonomies,
70-
array_keys( $error_data['term']['created'] ) ) : $taxonomies;
71-
$error_entries[] = esc_html__( 'There were issues creating or assigning terms for the following taxonomies: ',
72-
'multisite-language-switcher' ) .
73-
'<code>' . implode( '</code>, <code>', $taxonomies ) . '</code>.';
81+
$taxonomies = isset( $error_data['term']['added'] ) ? array_keys( $error_data['term']['added'] ) : array();
82+
$taxonomies = isset( $error_data['term']['created'] ) ? array_merge(
83+
$taxonomies,
84+
array_keys( $error_data['term']['created'] )
85+
) : $taxonomies;
86+
$error_entries[] = esc_html__(
87+
'There were issues creating or assigning terms for the following taxonomies: ',
88+
'multisite-language-switcher'
89+
) .
90+
'<code>' . implode( '</code>, <code>', $taxonomies ) . '</code>.';
7491
}
7592
if ( isset( $error_data['post-thumbnail']['set'] ) || isset( $error_data['post-thumbnail']['created'] ) ) {
76-
$error_entries[] = esc_html__( 'The post thumbnail could not be created or set.',
77-
'multisite-language-switcher' );
93+
$error_entries[] = esc_html__(
94+
'The post thumbnail could not be created or set.',
95+
'multisite-language-switcher'
96+
);
7897
}
7998
$message .= $this->get_section_html( $section_title, $error_entries, false );
8099
}
@@ -87,7 +106,7 @@ public function write( array $data ) {
87106
}
88107

89108
protected function get_section_html( $section_title, $entries, $escape_entries = true ) {
90-
$html = '<h3>' . $section_title . '</h3>';
109+
$html = '<h3>' . $section_title . '</h3>';
91110
$html .= '<ul>';
92111
foreach ( $entries as $entry ) {
93112
if ( $escape_entries ) {
@@ -128,4 +147,4 @@ public function set_import_coordinates( $import_coordinates ) {
128147
public function get_transient() {
129148
return $this->transient;
130149
}
131-
}
150+
}

includes/ContentImport/MetaBox.php

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ function ( $lang ) use ( $mydata ) {
3939

4040
if ( $has_input || $has_translation ) {
4141
add_thickbox();
42+
43+
/* translators: %s: language name */
4244
$label_template = __( 'Import content from %s', 'multisite-language-switcher' );
4345
$output = '<fieldset>';
4446
$output .= '<legend>'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport\LogWriters;
4+
5+
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
8+
class TestAdminNoticeLogger extends MslsUnitTestCase {
9+
10+
11+
public function setUp(): void {
12+
parent::setUp();
13+
14+
$this->test = new AdminNoticeLogger();
15+
}
16+
17+
public function test_get_transient(): void {
18+
$this->assertEquals( 'msls_last_import_log', $this->test->get_transient() );
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport;
4+
5+
use lloc\Msls\ContentImport\MetaBox;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
8+
class TestMetaBox extends MslsUnitTestCase {
9+
10+
11+
public function setUp(): void {
12+
parent::setUp();
13+
14+
$this->test = new MetaBox();
15+
}
16+
17+
public function test_print_modal_html(): void {
18+
$this->assertEquals( '', $this->test->print_modal_html() );
19+
}
20+
}

0 commit comments

Comments
 (0)