Skip to content

Tests added #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 53 additions & 34 deletions includes/ContentImport/LogWriters/AdminNoticeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace lloc\Msls\ContentImport\LogWriters;


use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\MslsRegistryInstance;

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

public function write( array $data ) {
$message = '<h3>' . esc_html__( 'Multisite Language Switcher last import report',
'multisite-language-switcher' ) . '</h3>';
/* translators: %1$d: source post ID, %2$d: source blog ID, %3$d: destination post ID, %4$d: destination blog ID */
$format = esc_html__( 'From post %1$d on site %2$d to post %3$d on site %4$d', 'multisite-language-switcher' );

$message = '<h3>' . esc_html__( 'Multisite Language Switcher last import report', 'multisite-language-switcher' ) . '</h3>';
$message .= '<b>' . sprintf(
esc_html__( 'From post %d on site %d to post %d on site %d', 'multisite-language-switcher' ),
$this->import_coordinates->source_post_id,
$this->import_coordinates->source_blog_id,
$this->import_coordinates->dest_post_id,
$this->import_coordinates->dest_blog_id
) . '</b>';
$format,
$this->import_coordinates->source_post_id,
$this->import_coordinates->source_blog_id,
$this->import_coordinates->dest_post_id,
$this->import_coordinates->dest_blog_id
) . '</b>';
if ( ! empty( $data['info'] ) ) {
$section_title = esc_html__( 'General information', 'multisite-language-switcher' );
$entries = $data['info'];
$message .= $this->get_section_html( $section_title, $entries );
$message .= $this->get_section_html( $section_title, $entries );
}

if ( ! empty( $data['success'] ) ) {
$section_title = esc_html__( 'Details', 'multisite-language-switcher' );
$success_data = $data['success'];
$success_entries = [];
$success_entries = array();

if ( isset( $success_data['post-field']['added'] ) ) {
$success_entries[] = esc_html__( 'The following post fields have been set: ',
'multisite-language-switcher' ) .
'<code>' . implode( '</code>, <code>',
array_keys( $success_data['post-field']['added'] ) ) . '</code>.';
$success_entries[] = esc_html__(
'The following post fields have been set: ',
'multisite-language-switcher'
) .
'<code>' . implode(
'</code>, <code>',
array_keys( $success_data['post-field']['added'] )
) . '</code>.';
}
if ( isset( $success_data['meta']['added'] ) ) {
$success_entries[] = esc_html__( 'The following post meta have been set: ',
'multisite-language-switcher' ) .
'<code>' . implode( '</code>, <code>',
array_keys( $success_data['meta']['added'] ) ) . '</code>.';
$success_entries[] = esc_html__(
'The following post meta have been set: ',
'multisite-language-switcher'
) .
'<code>' . implode(
'</code>, <code>',
array_keys( $success_data['meta']['added'] )
) . '</code>.';
}
if ( isset( $success_data['term']['added'] ) ) {
$success_entries[] = esc_html__( 'Terms have been assigned to the post for the following taxonomies: ',
'multisite-language-switcher' ) .
'<code>' . implode( '</code>, <code>',
array_keys( $success_data['term']['added'] ) ) . '</code>.';
$success_entries[] = esc_html__(
'Terms have been assigned to the post for the following taxonomies: ',
'multisite-language-switcher'
) .
'<code>' . implode(
'</code>, <code>',
array_keys( $success_data['term']['added'] )
) . '</code>.';
}
if ( isset( $success_data['post-thumbnail']['set'] ) ) {
$success_entries[] = esc_html__( 'The post thumbnail has been set.', 'multisite-language-switcher' );
Expand All @@ -63,18 +76,24 @@ public function write( array $data ) {
if ( ! empty( $data['error'] ) ) {
$section_title = esc_html__( 'Errors:', 'multisite-language-switcher' );
$error_data = $data['error'];
$error_entries = [];
$error_entries = array();
if ( isset( $error_data['term']['added'] ) || isset( $error_data['term']['created'] ) ) {
$taxonomies = isset( $error_data['term']['added'] ) ? array_keys( $error_data['term']['added'] ) : [];
$taxonomies = isset( $error_data['term']['created'] ) ? array_merge( $taxonomies,
array_keys( $error_data['term']['created'] ) ) : $taxonomies;
$error_entries[] = esc_html__( 'There were issues creating or assigning terms for the following taxonomies: ',
'multisite-language-switcher' ) .
'<code>' . implode( '</code>, <code>', $taxonomies ) . '</code>.';
$taxonomies = isset( $error_data['term']['added'] ) ? array_keys( $error_data['term']['added'] ) : array();
$taxonomies = isset( $error_data['term']['created'] ) ? array_merge(
$taxonomies,
array_keys( $error_data['term']['created'] )
) : $taxonomies;
$error_entries[] = esc_html__(
'There were issues creating or assigning terms for the following taxonomies: ',
'multisite-language-switcher'
) .
'<code>' . implode( '</code>, <code>', $taxonomies ) . '</code>.';
}
if ( isset( $error_data['post-thumbnail']['set'] ) || isset( $error_data['post-thumbnail']['created'] ) ) {
$error_entries[] = esc_html__( 'The post thumbnail could not be created or set.',
'multisite-language-switcher' );
$error_entries[] = esc_html__(
'The post thumbnail could not be created or set.',
'multisite-language-switcher'
);
}
$message .= $this->get_section_html( $section_title, $error_entries, false );
}
Expand All @@ -87,7 +106,7 @@ public function write( array $data ) {
}

protected function get_section_html( $section_title, $entries, $escape_entries = true ) {
$html = '<h3>' . $section_title . '</h3>';
$html = '<h3>' . $section_title . '</h3>';
$html .= '<ul>';
foreach ( $entries as $entry ) {
if ( $escape_entries ) {
Expand Down Expand Up @@ -128,4 +147,4 @@ public function set_import_coordinates( $import_coordinates ) {
public function get_transient() {
return $this->transient;
}
}
}
2 changes: 2 additions & 0 deletions includes/ContentImport/MetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function ( $lang ) use ( $mydata ) {

if ( $has_input || $has_translation ) {
add_thickbox();

/* translators: %s: language name */
$label_template = __( 'Import content from %s', 'multisite-language-switcher' );
$output = '<fieldset>';
$output .= '<legend>'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace lloc\MslsTests\ContentImport\LogWriters;

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 {
$this->assertEquals( 'msls_last_import_log', $this->test->get_transient() );
}
}
20 changes: 20 additions & 0 deletions tests/phpunit/ContentImport/TestMetaBox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace lloc\MslsTests\ContentImport;

use lloc\Msls\ContentImport\MetaBox;
use lloc\MslsTests\MslsUnitTestCase;

class TestMetaBox extends MslsUnitTestCase {


public function setUp(): void {
parent::setUp();

$this->test = new MetaBox();
}

public function test_print_modal_html(): void {
$this->assertEquals( '', $this->test->print_modal_html() );
}
}
Loading