From 194424f2e0dbdc0b72827a45acf42c8d70a86c07 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 13:15:15 +0200 Subject: [PATCH 01/13] Fix weak typing --- includes/Component/Input/Text.php | 2 +- includes/MslsAdmin.php | 7 +-- includes/MslsAdminIcon.php | 76 ++++--------------------------- includes/MslsJson.php | 6 ++- includes/MslsMetaBox.php | 8 ++-- includes/MslsPostTag.php | 5 +- 6 files changed, 26 insertions(+), 78 deletions(-) diff --git a/includes/Component/Input/Text.php b/includes/Component/Input/Text.php index 149d72797..16b0e7440 100644 --- a/includes/Component/Input/Text.php +++ b/includes/Component/Input/Text.php @@ -36,7 +36,7 @@ final class Text extends Component { */ public function __construct( string $key, ?string $value, int $size = self::DEFAULT_SIZE, bool $read_only = false ) { $this->key = $key; - $this->value = $value; + $this->value = $value ?? ''; $this->size = $size; $this->readonly = $read_only ? ' readonly="readonly"' : ''; } diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php index 1c0a1173a..b21f30ef4 100644 --- a/includes/MslsAdmin.php +++ b/includes/MslsAdmin.php @@ -98,7 +98,7 @@ public function get_options_page_link(): string { * * @return mixed */ - public function __call( $method, $args ) { + public function __call( string $method, $args ) { $parts = explode( '_', $method, 2 ); if ( 2 === count( $parts ) && 'rewrite' === $parts[0] ) { $this->render_rewrite( $parts[1] ); @@ -433,8 +433,9 @@ public function content_priority(): void { * @param mixed $key */ public function render_rewrite( $key ): void { - $rewrite = get_post_type_object( $key )->rewrite; - $value = $rewrite['slug'] ?? ''; + $pt_object = get_post_type_object( $key ); + $rewrite = $pt_object ? $pt_object->rewrite : array(); + $value = $rewrite['slug'] ?? ''; // phpcs:ignore WordPress.Security.EscapeOutput echo ( new Text( "rewrite_{$key}", $value, 30, true ) )->render(); diff --git a/includes/MslsAdminIcon.php b/includes/MslsAdminIcon.php index 1245c5dce..4faa0cc06 100644 --- a/includes/MslsAdminIcon.php +++ b/includes/MslsAdminIcon.php @@ -13,23 +13,21 @@ */ class MslsAdminIcon { - protected string $icon_type = 'action'; - protected string $language; - public string $origin_language; - protected string $src; - protected string $href; - protected int $blog_id; - protected string $type; - protected string $path = 'post-new.php'; - protected int $id; + protected string $icon_type = 'action'; + protected string $language = ''; + public string $origin_language = ''; + protected string $src = ''; + protected string $href = ''; + protected int $blog_id = 0; + protected string $type = ''; + protected string $path = 'post-new.php'; + protected int $id = 0; const TYPE_FLAG = 'flag'; const TYPE_LABEL = 'label'; /** * Constructor - * - * @param string $type */ public function __construct( ?string $type = null ) { $this->type = $type ?? ''; @@ -37,16 +35,11 @@ public function __construct( ?string $type = null ) { $this->set_path(); } - /** - * @return string - */ - public function __toString() { + public function __toString(): string { return $this->get_a(); } /** - * @param ?string $type - * * @return MslsAdminIcon|MslsAdminIconTaxonomy */ public static function create( ?string $type = null ) { @@ -61,10 +54,6 @@ public static function create( ?string $type = null ) { /** * Set the icon path - * - * @param string $icon_type - * - * @return MslsAdminIcon */ public function set_icon_type( string $icon_type ): MslsAdminIcon { $this->icon_type = $icon_type; @@ -74,8 +63,6 @@ public function set_icon_type( string $icon_type ): MslsAdminIcon { /** * Set the path by type - * - * @return MslsAdminIcon */ public function set_path(): MslsAdminIcon { if ( 'post' !== $this->type ) { @@ -86,39 +73,18 @@ public function set_path(): MslsAdminIcon { return $this; } - /** - * Set language - * - * @param string $language - * - * @return MslsAdminIcon - */ public function set_language( string $language ): MslsAdminIcon { $this->language = $language; return $this; } - /** - * Set src - * - * @param string $src - * - * @return MslsAdminIcon - */ public function set_src( string $src ): MslsAdminIcon { $this->src = $src; return $this; } - /** - * Set href - * - * @param int $id - * - * @return MslsAdminIcon - */ public function set_href( int $id ): MslsAdminIcon { $this->href = get_edit_post_link( $id ) ?? ''; @@ -127,10 +93,6 @@ public function set_href( int $id ): MslsAdminIcon { /** * Sets the id of the object this icon is for - * - * @param int $id - * - * @return MslsAdminIcon */ public function set_id( int $id ): MslsAdminIcon { $this->id = $id; @@ -140,10 +102,6 @@ public function set_id( int $id ): MslsAdminIcon { /** * Sets the origin language for this icon - * - * @param string $origin_language - * - * @return MslsAdminIcon */ public function set_origin_language( string $origin_language ): MslsAdminIcon { $this->origin_language = $origin_language; @@ -153,8 +111,6 @@ public function set_origin_language( string $origin_language ): MslsAdminIcon { /** * Get image as html-tag - * - * @return string */ public function get_img(): string { return sprintf( '%s', $this->language, $this->src ); @@ -162,8 +118,6 @@ public function get_img(): string { /** * Get link as html-tag - * - * @return string */ public function get_a(): string { if ( empty( $this->href ) ) { @@ -185,18 +139,12 @@ public function get_a(): string { return sprintf( '%3$s ', esc_attr( $title ), esc_url( $href ), $this->get_icon() ); } - /** - * @return bool - */ protected function should_quick_create(): bool { return 0 !== $this->id && '' !== $this->origin_language && msls_options()->activate_quick_create; } - /** - * @return string - */ protected function get_quick_create_a(): string { $collection = msls_blog_collection(); $source_blog_id = $collection->get_blog_id( $this->origin_language ); @@ -218,8 +166,6 @@ protected function get_quick_create_a(): string { /** * Get icon as html-tag - * - * @return string */ public function get_icon(): string { if ( ! $this->language ) { @@ -254,8 +200,6 @@ public function get_icon(): string { /** * Creates new admin link - * - * @return string */ public function get_edit_new(): string { $path = $this->path; diff --git a/includes/MslsJson.php b/includes/MslsJson.php index 7aaa0937f..7aabd10ff 100644 --- a/includes/MslsJson.php +++ b/includes/MslsJson.php @@ -40,7 +40,7 @@ public function add( $value, $label ) { * * @return int */ - public static function compare( array $a, array $b ) { + public static function compare( array $a, array $b ): int { return strnatcmp( $a['label'], $b['label'] ); } @@ -63,7 +63,9 @@ public function get(): array { * @return string */ public function encode(): string { - return wp_json_encode( $this->get() ); + $json_string = wp_json_encode( $this->get() ); + + return is_string( $json_string ) ? $json_string : ''; } /** diff --git a/includes/MslsMetaBox.php b/includes/MslsMetaBox.php index 58b0f4a58..8cf607a04 100644 --- a/includes/MslsMetaBox.php +++ b/includes/MslsMetaBox.php @@ -10,6 +10,7 @@ use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\MetaBox as ContentImportMetaBox; use WP_Post; +use WP_Post_Type; /** * Meta box for the edit mode of the (custom) post types @@ -206,10 +207,9 @@ public function render_select(): void { $icon->set_href( $linked_post_id ); } - $selects = ''; - $p_object = get_post_type_object( $type ); - - if ( $p_object->hierarchical ) { + $selects = ''; + $pt_object = get_post_type_object( $type ); + if ( $pt_object instanceof WP_Post_Type && $pt_object->hierarchical ) { $args = array( 'post_type' => $type, 'selected' => $mydata->$language, diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php index 27d497d1a..d5a156862 100644 --- a/includes/MslsPostTag.php +++ b/includes/MslsPostTag.php @@ -7,6 +7,7 @@ } use lloc\Msls\Component\Component; +use WP_Term; /** * Post Tag @@ -91,7 +92,7 @@ public static function suggest(): void { ) ); - wp_die( wp_json_encode( $results ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + wp_die( (string) wp_json_encode( $results ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } public static function init(): void { @@ -208,7 +209,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo if ( $mydata->has_value( $language ) ) { $term = get_term( $mydata->$language, $type ); - if ( is_object( $term ) ) { + if ( $term instanceof WP_Term ) { $icon->set_href( (int) $mydata->$language ); $value = $mydata->$language; $title = $term->name; From 43bf7d90e1bd3040ddafc339a85da44f295da65a Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 16:36:36 +0200 Subject: [PATCH 02/13] PHPStan issues fixed --- includes/MslsAdmin.php | 11 ++++++----- includes/MslsJson.php | 10 +++++----- includes/MslsLink.php | 2 +- includes/MslsShortCode.php | 12 ++++++++---- includes/MslsSqlCacher.php | 19 +++++++++++++++++-- tests/phpunit/TestMslsAdminIcon.php | 2 +- tests/phpunit/TestMslsShortCode.php | 2 +- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php index b21f30ef4..c13b767b5 100644 --- a/includes/MslsAdmin.php +++ b/includes/MslsAdmin.php @@ -11,6 +11,7 @@ use lloc\Msls\Component\Input\Label; use lloc\Msls\Component\Input\Text; use lloc\Msls\Component\Input\Select; +use WP_Post_Type; /** * Administration of the options @@ -93,12 +94,12 @@ public function get_options_page_link(): string { /** * You can use every method of the decorated object * - * @param string $method - * @param mixed $args + * @param string $method + * @param mixed[] $args * * @return mixed */ - public function __call( string $method, $args ) { + public function __call( string $method, array $args ) { $parts = explode( '_', $method, 2 ); if ( 2 === count( $parts ) && 'rewrite' === $parts[0] ) { $this->render_rewrite( $parts[1] ); @@ -434,8 +435,8 @@ public function content_priority(): void { */ public function render_rewrite( $key ): void { $pt_object = get_post_type_object( $key ); - $rewrite = $pt_object ? $pt_object->rewrite : array(); - $value = $rewrite['slug'] ?? ''; + $rewrite = $pt_object instanceof WP_Post_Type ? $pt_object->rewrite : null; + $value = is_array( $rewrite ) ? ( $rewrite['slug'] ?? '' ) : ''; // phpcs:ignore WordPress.Security.EscapeOutput echo ( new Text( "rewrite_{$key}", $value, 30, true ) )->render(); diff --git a/includes/MslsJson.php b/includes/MslsJson.php index 7aabd10ff..6cb9b1b95 100644 --- a/includes/MslsJson.php +++ b/includes/MslsJson.php @@ -11,7 +11,7 @@ class MslsJson { /** - * @var array> + * @var array */ protected array $arr = array(); @@ -35,8 +35,8 @@ public function add( $value, $label ) { /** * Compare the item with the key "label" of the array $a and the array $b * - * @param array $a - * @param array $b + * @param array{value: int, label: string} $a + * @param array{value: int, label: string} $b * * @return int */ @@ -47,12 +47,12 @@ public static function compare( array $a, array $b ): int { /** * Get the array container sorted by label * - * @return array> + * @return array */ public function get(): array { $arr = $this->arr; - usort( $arr, array( __CLASS__, 'compare' ) ); + usort( $arr, \Closure::fromCallable( array( __CLASS__, 'compare' ) ) ); return $arr; } diff --git a/includes/MslsLink.php b/includes/MslsLink.php index 6d25860d2..8f6eb330c 100644 --- a/includes/MslsLink.php +++ b/includes/MslsLink.php @@ -19,7 +19,7 @@ class MslsLink extends MslsGetSet implements LinkInterface { /** * Gets all link types as an array with "id => name"-items * - * @return string[] + * @return array */ public static function get_types() { return array( diff --git a/includes/MslsShortCode.php b/includes/MslsShortCode.php index 4e5cf2a1a..ea5df3308 100644 --- a/includes/MslsShortCode.php +++ b/includes/MslsShortCode.php @@ -5,16 +5,20 @@ class MslsShortCode { public static function init(): void { - add_shortcode( 'sc_msls_widget', array( __CLASS__, 'render_widget' ) ); + add_shortcode( 'sc_msls_widget', \Closure::fromCallable( array( __CLASS__, 'render_widget' ) ) ); add_shortcode( 'sc_msls', 'msls_get_switcher' ); } /** * Renders output using the widget's output * - * @return string|false + * @param array|string $atts + * @param string|null $content + * @param string $tag + * + * @return string */ - public static function render_widget() { + public static function render_widget( $atts = array(), ?string $content = null, string $tag = '' ): string { if ( msls_options()->is_excluded() ) { return ''; } @@ -23,6 +27,6 @@ public static function render_widget() { the_widget( MslsWidget::class ); $output = ob_get_clean(); - return $output; + return false === $output ? '' : $output; } } diff --git a/includes/MslsSqlCacher.php b/includes/MslsSqlCacher.php index 0e10bfecd..34d9acabb 100644 --- a/includes/MslsSqlCacher.php +++ b/includes/MslsSqlCacher.php @@ -94,15 +94,30 @@ public function __get( string $name ) { */ public function __call( string $method, array $args ) { if ( 'get_' !== substr( $method, 0, 4 ) ) { - return call_user_func_array( array( $this->db, $method ), $args ); + return $this->invoke( $method, $args ); } $result = wp_cache_get( $this->cache_key, self::CACHE_GROUP ); if ( false === $result ) { - $result = call_user_func_array( array( $this->db, $method ), $args ); + $result = $this->invoke( $method, $args ); wp_cache_set( $this->cache_key, $result, self::CACHE_GROUP, $this->expire ); } return $result; } + + /** + * @param string $method + * @param array $args + * + * @return mixed + */ + protected function invoke( string $method, array $args ) { + $callback = array( $this->db, $method ); + if ( ! is_callable( $callback ) ) { + return null; + } + + return $callback( ...$args ); + } } diff --git a/tests/phpunit/TestMslsAdminIcon.php b/tests/phpunit/TestMslsAdminIcon.php index 00b0a8211..77e4d5935 100644 --- a/tests/phpunit/TestMslsAdminIcon.php +++ b/tests/phpunit/TestMslsAdminIcon.php @@ -152,7 +152,7 @@ public function test_get_img_post_page(): void { } public function test_set_id_with_null_constructor(): void { - Functions\expect( 'add_query_arg' )->once(); + Functions\expect( 'add_query_arg' )->once()->andReturn( 'post-new.php' ); $obj = new MslsAdminIcon( null ); diff --git a/tests/phpunit/TestMslsShortCode.php b/tests/phpunit/TestMslsShortCode.php index f3e441b77..58bced8f5 100644 --- a/tests/phpunit/TestMslsShortCode.php +++ b/tests/phpunit/TestMslsShortCode.php @@ -9,7 +9,7 @@ final class TestMslsShortCode extends MslsUnitTestCase { public function test_init(): void { - Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls_widget', array( MslsShortCode::class, 'render_widget' ) ); + Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls_widget', \Mockery::type( \Closure::class ) ); Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls', 'msls_get_switcher' ); $this->expectNotToPerformAssertions(); From 898662e828772745173066cb24618240478c1a02 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 16:44:12 +0200 Subject: [PATCH 03/13] Fix PHPStan errors in factory classes --- includes/MslsLink.php | 15 +++++++-------- includes/MslsOptions.php | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/includes/MslsLink.php b/includes/MslsLink.php index 8f6eb330c..da28f8838 100644 --- a/includes/MslsLink.php +++ b/includes/MslsLink.php @@ -19,7 +19,7 @@ class MslsLink extends MslsGetSet implements LinkInterface { /** * Gets all link types as an array with "id => name"-items * - * @return array + * @return array> */ public static function get_types() { return array( @@ -42,13 +42,13 @@ public static function get_description(): string { /** * Gets an array with all link descriptions * - * @return array + * @return array */ public static function get_types_description(): array { $types = array(); foreach ( self::get_types() as $key => $class ) { - $types[ $key ] = call_user_func( array( $class, 'get_description' ) ); + $types[ $key ] = $class::get_description(); } return $types; @@ -70,11 +70,10 @@ public static function create( ?int $display ): LinkInterface { $obj = new $types[ $display ](); if ( has_filter( 'msls_link_create' ) ) { - /** - * @param LinkInterface $obj - * @param int $display - */ - $obj = apply_filters( 'msls_link_create', $obj, $display ); + $filtered = apply_filters( 'msls_link_create', $obj, $display ); + if ( $filtered instanceof LinkInterface ) { + $obj = $filtered; + } } return $obj; diff --git a/includes/MslsOptions.php b/includes/MslsOptions.php index 286b0956f..95372835d 100644 --- a/includes/MslsOptions.php +++ b/includes/MslsOptions.php @@ -101,12 +101,12 @@ public static function create( $id = 0 ) { } elseif ( self::is_tax_page() ) { $options = MslsOptionsTax::create(); } elseif ( self::is_query_page() ) { - $options = MslsOptionsQuery::create(); + $options = MslsOptionsQuery::create() ?? new MslsOptions(); } else { $options = new MslsOptionsPost( get_queried_object_id() ); } - add_filter( self::MSLS_GET_POSTLINK_HOOK, array( $options, 'check_for_blog_slug' ), 10, 2 ); + add_filter( self::MSLS_GET_POSTLINK_HOOK, \Closure::fromCallable( array( self::class, 'check_for_blog_slug' ) ), 10, 2 ); return $options; } From bdb77a96357dbc530b62225b323016141d92a28a Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 16:57:43 +0200 Subject: [PATCH 04/13] Admin classes clean --- includes/MslsAdmin.php | 13 +++++++++++-- includes/MslsBlogCollection.php | 12 +++++++----- includes/MslsMain.php | 9 +++++---- includes/MslsMetaBox.php | 25 +++++++++++++++++++------ includes/MslsPostTag.php | 8 ++++++-- includes/MslsTranslationPickerTable.php | 4 ++++ 6 files changed, 52 insertions(+), 19 deletions(-) diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php index c13b767b5..e5b31ae3c 100644 --- a/includes/MslsAdmin.php +++ b/includes/MslsAdmin.php @@ -127,8 +127,13 @@ public function __call( string $method, array $args ) { ); if ( isset( $checkboxes[ $method ] ) ) { + $value = $this->options->$method; + if ( is_bool( $value ) ) { + $value = $value ? '1' : ''; + } + $group = ( new Group() ) - ->add( new Checkbox( $method, $this->options->$method ) ) + ->add( new Checkbox( $method, $value ) ) ->add( new Label( $method, $checkboxes[ $method ] ) ); echo $group->render(); // phpcs:ignore WordPress.Security.EscapeOutput @@ -334,7 +339,11 @@ public function rewrites_section(): int { */ protected function add_settings_fields( array $map, string $section ): int { foreach ( $map as $id => $title ) { - add_settings_field( $id, $title, array( $this, $id ), __CLASS__, $section, array( 'label_for' => $id ) ); + $callback = array( $this, $id ); + if ( ! is_callable( $callback ) ) { + continue; + } + add_settings_field( $id, $title, $callback, __CLASS__, $section, array( 'label_for' => $id ) ); } /** diff --git a/includes/MslsBlogCollection.php b/includes/MslsBlogCollection.php index 910fbc03c..fbfa5ba31 100644 --- a/includes/MslsBlogCollection.php +++ b/includes/MslsBlogCollection.php @@ -95,7 +95,10 @@ public function __construct() { } } - uasort( $this->objects, array( MslsBlog::class, $this->objects_order ) ); + $compare = array( MslsBlog::class, $this->objects_order ); + if ( is_callable( $compare ) ) { + uasort( $this->objects, $compare ); + } } } @@ -134,12 +137,11 @@ public function get_blogs_of_reference_user( MslsOptions $options ) { $options->reference_user : current( $this->get_users( 'ID', 1 ) ); - $blogs = get_blogs_of_user( $reference_user ); - foreach ( $blogs as $key => $blog ) { - $blogs[ $key ]->blog_id = $blog->userblog_id; + if ( ! is_int( $reference_user ) ) { + $reference_user = 0; } - return $blogs; + return get_blogs_of_user( $reference_user ); } /** diff --git a/includes/MslsMain.php b/includes/MslsMain.php index e8d552ecf..8929e3e80 100644 --- a/includes/MslsMain.php +++ b/includes/MslsMain.php @@ -125,8 +125,8 @@ public function delete( $object_id ): void { /** * Save * - * @param int $object_id - * @param string $class_name + * @param int $object_id + * @param class-string $class_name * * @codeCoverageIgnore */ @@ -145,13 +145,14 @@ protected function save( $object_id, $class_name ): void { return; } - if ( ! $this->collection->has_current_blog() ) { + $current_blog = $this->collection->get_current_blog(); + if ( ! $current_blog instanceof MslsBlog ) { $this->debugger( 'BlogCollection returns false when calling has_current_blog.' ); return; } - $language = $this->collection->get_current_blog()->get_language(); + $language = $current_blog->get_language(); $msla = new MslsLanguageArray( $this->get_input_array( $object_id ) ); $options = new $class_name( $object_id ); $temp = $options->get_arr(); diff --git a/includes/MslsMetaBox.php b/includes/MslsMetaBox.php index 8cf607a04..d25d7e200 100644 --- a/includes/MslsMetaBox.php +++ b/includes/MslsMetaBox.php @@ -89,7 +89,7 @@ public static function suggest(): void { ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - wp_die( wp_json_encode( $results ) ); + wp_die( wp_json_encode( $results ) ?: '' ); } /** @@ -109,14 +109,19 @@ public static function get_suggested_fields( MslsJson $json, array $args ): Msls $args = (array) apply_filters( 'msls_meta_box_suggest_args', $args ); foreach ( get_posts( $args ) as $post ) { + if ( ! $post instanceof \WP_Post ) { + continue; + } + /** * Manipulates the WP_Post object before using it * - * @param WP_Post $post - * * @since 0.9.9 */ - $post = apply_filters( 'msls_meta_box_suggest_post', $post ); + $filtered = apply_filters( 'msls_meta_box_suggest_post', $post ); + if ( $filtered instanceof \WP_Post ) { + $post = $filtered; + } $json->add( $post->ID, get_the_title( $post ) ); } @@ -181,7 +186,11 @@ public function render_select(): void { if ( $blogs ) { global $post; - $type = get_post_type( $post->ID ); + $type = get_post_type( $post->ID ); + if ( false === $type ) { + return; + } + $mydata = new MslsOptionsPost( $post->ID ); $origin_language = MslsBlogCollection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); @@ -321,7 +330,11 @@ public function render_input(): void { if ( $blogs ) { global $post; - $post_type = get_post_type( $post->ID ); + $post_type = get_post_type( $post->ID ); + if ( false === $post_type ) { + return; + } + $my_data = new MslsOptionsPost( $post->ID ); $origin_language = MslsBlogCollection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php index d5a156862..d77d1212b 100644 --- a/includes/MslsPostTag.php +++ b/includes/MslsPostTag.php @@ -55,8 +55,12 @@ public static function suggest(): void { * * @since 0.9.9 */ - $args = (array) apply_filters( 'msls_post_tag_suggest_args', $args ); - foreach ( get_terms( $args ) as $term ) { + $args = (array) apply_filters( 'msls_post_tag_suggest_args', $args ); + $terms = get_terms( $args ); + if ( ! is_array( $terms ) ) { + $terms = array(); + } + foreach ( $terms as $term ) { /** * Manipulates the term object before using it * diff --git a/includes/MslsTranslationPickerTable.php b/includes/MslsTranslationPickerTable.php index b8bf1c861..f389315cb 100644 --- a/includes/MslsTranslationPickerTable.php +++ b/includes/MslsTranslationPickerTable.php @@ -191,6 +191,10 @@ public function prepare_items(): void { $taxonomies = array_keys( $this->get_admin_column_taxonomies() ); foreach ( $query->posts as $post ) { + if ( ! $post instanceof \WP_Post ) { + continue; + } + $terms_by_tax = array(); foreach ( $taxonomies as $tax_name ) { $terms = get_the_terms( $post->ID, $tax_name ); From 27392d2a7b50ba3891783bc7992bd4e31a74569e Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 17:25:07 +0200 Subject: [PATCH 05/13] Content Import subsystem --- includes/ContentImport/ContentImporter.php | 64 ++++++++++--------- includes/ContentImport/ImportCoordinates.php | 7 ++ includes/ContentImport/ImportLogger.php | 16 +++-- .../Importers/AttachmentsImporters.php | 2 +- .../Importers/ImportersBaseFactory.php | 5 +- .../Importers/PostFieldsImporters.php | 2 +- .../Importers/PostMetaImporters.php | 2 +- .../Importers/PostThumbnail/Linking.php | 15 +++-- .../Importers/PostThumbnailImporters.php | 2 +- .../Importers/Terms/ShallowDuplicating.php | 13 ++-- .../Importers/TermsImporters.php | 2 +- includes/ContentImport/MetaBox.php | 9 ++- includes/ContentImport/Relations.php | 14 ++-- .../ContentImport/TestContentImporter.php | 2 +- 14 files changed, 100 insertions(+), 55 deletions(-) diff --git a/includes/ContentImport/ContentImporter.php b/includes/ContentImport/ContentImporter.php index b6530ee3f..94f0b73a5 100644 --- a/includes/ContentImport/ContentImporter.php +++ b/includes/ContentImport/ContentImporter.php @@ -99,8 +99,12 @@ public function set_relations( Relations $relations ): void { * @return string[] The updated, if needed, data array. */ public function handle_import( array $data = array() ) { + if ( ! $this->pre_flight_check() ) { + return $data; + } + $sources = $this->parse_sources(); - if ( ! $this->pre_flight_check() || false === $sources ) { + if ( null === $sources ) { return $data; } @@ -176,21 +180,21 @@ protected function pre_flight_check() { /** * Parses the source blog and post IDs from the $_POST array validating them. * - * @return int[]|bool + * @return array{0: int, 1: int}|null */ - public function parse_sources() { + public function parse_sources(): ?array { if ( ! MslsRequest::has_var( 'msls_import' ) ) { - return false; + return null; } $msls_import = MslsRequest::get_var( 'msls_import' ); - $import_data = array_filter( explode( '|', trim( $msls_import ) ), 'is_numeric' ); + $import_data = array_values( array_filter( explode( '|', trim( $msls_import ) ), 'is_numeric' ) ); if ( count( $import_data ) !== 2 ) { - return false; + return null; } - return array_map( 'intval', $import_data ); + return array( (int) $import_data[0], (int) $import_data[1] ); } /** @@ -198,12 +202,12 @@ public function parse_sources() { * * @return int */ - protected function get_the_blog_post_ID( $blog_id ) { + protected function get_the_blog_post_ID( $blog_id ): int { switch_to_blog( $blog_id ); $id = get_the_ID(); - if ( ! empty( $id ) ) { + if ( false !== $id && ! empty( $id ) ) { restore_current_blog(); return $id; @@ -226,11 +230,11 @@ protected function get_the_blog_post_ID( $blog_id ) { * @param int $blog_id * @param array $data * - * @return bool|int + * @return int */ - protected function insert_blog_post( $blog_id, array $data = array() ) { + protected function insert_blog_post( $blog_id, array $data = array() ): int { if ( empty( $data ) ) { - return false; + return 0; } switch_to_blog( $blog_id ); @@ -238,7 +242,7 @@ protected function insert_blog_post( $blog_id, array $data = array() ) { if ( ! empty( $data['post_type'] ) && ! post_type_exists( $data['post_type'] ) ) { restore_current_blog(); - return false; + return 0; } $this->handle( false ); @@ -249,7 +253,7 @@ protected function insert_blog_post( $blog_id, array $data = array() ) { } $this->handle( true ); - $this->has_created_post = $post_id > 0 ? $post_id : false; + $this->has_created_post = $post_id > 0 ? $post_id : 0; restore_current_blog(); @@ -319,29 +323,29 @@ public function import_content( ImportCoordinates $import_coordinates, array $po $importers = Map::instance()->make( $import_coordinates ); } - if ( is_null( $this->get_logger() ) ) { - $this->set_logger( new ImportLogger( $import_coordinates ) ); - } + $logger = $this->logger ?? new ImportLogger( $import_coordinates ); + $this->set_logger( $logger ); - if ( is_null( $this->get_relations() ) ) { - $this->set_relations( new Relations( $import_coordinates ) ); - } + $relations = $this->relations ?? new Relations( $import_coordinates ); + $this->set_relations( $relations ); if ( ! empty( $importers ) ) { $source_post_id = $import_coordinates->source_post_id; $dest_lang = $import_coordinates->dest_lang; $dest_post_id = $import_coordinates->dest_post_id; - $this->relations->should_create( MslsOptionsPost::create( $source_post_id ), $dest_lang, $dest_post_id ); + $relations->should_create( MslsOptionsPost::create( $source_post_id ), $dest_lang, $dest_post_id ); foreach ( $importers as $key => $importer ) { - /** @var Importer $importer */ + if ( ! $importer instanceof Importer ) { + continue; + } $post_fields = $importer->import( $post_fields ); - $this->logger->merge( $importer->get_logger() ); - $this->relations->merge( $importer->get_relations() ); + $logger->merge( $importer->get_logger() ); + $relations->merge( $importer->get_relations() ); } - $this->relations->create(); - $this->logger->save(); + $relations->create(); + $logger->save(); } /** @@ -353,7 +357,7 @@ public function import_content( ImportCoordinates $import_coordinates, array $po * * @since TBD */ - do_action( self::MSLS_AFTER_IMPORT_ACTION, $import_coordinates, $this->logger, $this->relations ); + do_action( self::MSLS_AFTER_IMPORT_ACTION, $import_coordinates, $logger, $relations ); /** * Filters the data after the import ran. @@ -367,8 +371,8 @@ public function import_content( ImportCoordinates $import_coordinates, array $po 'msls_content_import_data_after_import', $post_fields, $import_coordinates, - $this->logger, - $this->relations + $logger, + $relations ); } @@ -395,7 +399,7 @@ protected function update_inserted_blog_post_data( $blog_id, $post_id, array $da */ protected function redirect_to_blog_post( $dest_blog_id, $post_id ) { switch_to_blog( $dest_blog_id ); - $edit_post_link = html_entity_decode( get_edit_post_link( $post_id ) ); + $edit_post_link = html_entity_decode( get_edit_post_link( $post_id ) ?? '' ); wp_safe_redirect( $edit_post_link ); die(); } diff --git a/includes/ContentImport/ImportCoordinates.php b/includes/ContentImport/ImportCoordinates.php index 12c3d46fb..9a18455cf 100644 --- a/includes/ContentImport/ImportCoordinates.php +++ b/includes/ContentImport/ImportCoordinates.php @@ -97,7 +97,14 @@ public function parse_importers_from_request(): void { } } + if ( ! is_array( $importers ) ) { + return; + } + foreach ( $importers as $importer_type => $slug ) { + if ( ! is_string( $slug ) ) { + continue; + } $this->set_importer_for( $importer_type, $slug ); } } diff --git a/includes/ContentImport/ImportLogger.php b/includes/ContentImport/ImportLogger.php index 23d6749f3..c510fab4b 100644 --- a/includes/ContentImport/ImportLogger.php +++ b/includes/ContentImport/ImportLogger.php @@ -8,7 +8,7 @@ class ImportLogger { /** - * @var string + * @var non-empty-string */ protected string $levels_delimiter = '/'; @@ -154,9 +154,9 @@ public function get_levels_delimiter(): string { /** * Sets the string that will be used to split paths into levels. * - * @param string $levels_delimiter + * @param non-empty-string $levels_delimiter */ - public function set_levels_delimiter( $levels_delimiter ): void { + public function set_levels_delimiter( string $levels_delimiter ): void { $this->levels_delimiter = $levels_delimiter; } @@ -197,9 +197,17 @@ public function get_error( $where ) { protected function get_nested_value( $where ) { $path = $this->build_path( $where ); - $data = $this->data[ array_shift( $path ) ]; + $first = array_shift( $path ); + if ( null === $first || ! isset( $this->data[ $first ] ) ) { + return null; + } + + $data = $this->data[ $first ]; foreach ( $path as $frag ) { + if ( ! is_array( $data ) || ! isset( $data[ $frag ] ) ) { + return null; + } $data = $data[ $frag ]; } diff --git a/includes/ContentImport/Importers/AttachmentsImporters.php b/includes/ContentImport/Importers/AttachmentsImporters.php index f1f333993..96947764d 100644 --- a/includes/ContentImport/Importers/AttachmentsImporters.php +++ b/includes/ContentImport/Importers/AttachmentsImporters.php @@ -9,7 +9,7 @@ class AttachmentsImporters extends ImportersBaseFactory { const TYPE = 'attachments'; /** - * @var array + * @var array> */ protected array $importers_map = array( Linking::TYPE => Linking::class, diff --git a/includes/ContentImport/Importers/ImportersBaseFactory.php b/includes/ContentImport/Importers/ImportersBaseFactory.php index 122d316af..885de3496 100644 --- a/includes/ContentImport/Importers/ImportersBaseFactory.php +++ b/includes/ContentImport/Importers/ImportersBaseFactory.php @@ -13,7 +13,7 @@ abstract class ImportersBaseFactory extends MslsRegistryInstance implements Impo const TYPE = 'none'; /** - * @var array An array defining the slug and Importer class relationships in + * @var array> An array defining the slug and Importer class relationships in * the shape [ => ] */ protected array $importers_map = array(); @@ -67,6 +67,9 @@ public function make( ImportCoordinates $import_coordinates ) { // If there is some incoherence, return the null-doing base importer. $class = ! empty( $slug ) && isset( $map[ $slug ] ) ? $map[ $slug ] : BaseImporter::class; + if ( ! is_string( $class ) || ! is_a( $class, Importer::class, true ) ) { + $class = BaseImporter::class; + } return new $class( $import_coordinates ); } diff --git a/includes/ContentImport/Importers/PostFieldsImporters.php b/includes/ContentImport/Importers/PostFieldsImporters.php index 2e0d989e9..7313b786e 100644 --- a/includes/ContentImport/Importers/PostFieldsImporters.php +++ b/includes/ContentImport/Importers/PostFieldsImporters.php @@ -9,7 +9,7 @@ class PostFieldsImporters extends ImportersBaseFactory { const TYPE = 'post-fields'; /** - * @var array + * @var array> */ protected array $importers_map = array( Duplicating::TYPE => Duplicating::class, diff --git a/includes/ContentImport/Importers/PostMetaImporters.php b/includes/ContentImport/Importers/PostMetaImporters.php index 8930ff9dd..4d7de1bc5 100644 --- a/includes/ContentImport/Importers/PostMetaImporters.php +++ b/includes/ContentImport/Importers/PostMetaImporters.php @@ -9,7 +9,7 @@ class PostMetaImporters extends ImportersBaseFactory { const TYPE = 'post-meta'; /** - * @var array + * @var array> */ protected array $importers_map = array( Duplicating::TYPE => Duplicating::class, diff --git a/includes/ContentImport/Importers/PostThumbnail/Linking.php b/includes/ContentImport/Importers/PostThumbnail/Linking.php index d276c9a10..65bafd4f5 100644 --- a/includes/ContentImport/Importers/PostThumbnail/Linking.php +++ b/includes/ContentImport/Importers/PostThumbnail/Linking.php @@ -63,15 +63,20 @@ public function import( array $data ) { // In some instances, the folder sep. `/` might be duplicated, we de-duplicate it. array_walk( $source_upload_dir, - function ( &$entry ) { - $entry = str_replace( '//', '/', $entry ); + function ( &$entry ): void { + if ( is_string( $entry ) ) { + $entry = str_replace( '//', '/', $entry ); + } } ); + $subdir = is_string( $source_upload_dir['subdir'] ) ? $source_upload_dir['subdir'] : ''; + $path = is_string( $source_upload_dir['path'] ) ? $source_upload_dir['path'] : ''; + $source_uploads_dir = untrailingslashit( str_replace( - $source_upload_dir['subdir'], + $subdir, '', - $source_upload_dir['path'] + $path ) ); $source_post_thumbnail_file = $source_uploads_dir . '/' . $source_post_thumbnail_meta['_wp_attached_file']; @@ -91,7 +96,7 @@ function ( &$entry ) { $found = get_posts( array( 'post_type' => 'attachment', - 'title' => $attachment['post_title'], + 'title' => $attachment['post_title'] ?? '', ) ); if ( isset( $found[0]->ID ) ) { diff --git a/includes/ContentImport/Importers/PostThumbnailImporters.php b/includes/ContentImport/Importers/PostThumbnailImporters.php index d1cb0716e..a658b42dd 100644 --- a/includes/ContentImport/Importers/PostThumbnailImporters.php +++ b/includes/ContentImport/Importers/PostThumbnailImporters.php @@ -9,7 +9,7 @@ class PostThumbnailImporters extends ImportersBaseFactory { const TYPE = 'post-thumbnail'; /** - * @var array + * @var array> */ protected array $importers_map = array( Linking::TYPE => Linking::class, diff --git a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php index 49ac1479b..9120f3bec 100644 --- a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php +++ b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php @@ -53,7 +53,13 @@ public function import( array $data ) { switch_to_blog( $source_blog_id ); - $source_terms = wp_get_post_terms( $source_post_id, get_taxonomies() ); + $source_terms = wp_get_post_terms( $source_post_id, get_taxonomies() ); + if ( is_wp_error( $source_terms ) ) { + restore_current_blog(); + + return $data; + } + $source_terms_ids = wp_list_pluck( $source_terms, 'term_id' ); $msls_terms = array_combine( $source_terms_ids, @@ -62,7 +68,6 @@ public function import( array $data ) { switch_to_blog( $this->import_coordinates->dest_blog_id ); - /** @var \WP_Term $term */ foreach ( $source_terms as $term ) { // is there a translation for the term in this blog? $msls_term = $msls_terms[ $term->term_id ]; @@ -72,7 +77,7 @@ public function import( array $data ) { $dest_term_id = $this->create_local_term( $term, $msls_term, $dest_lang ); } - if ( false === $dest_term_id ) { + if ( ! is_int( $dest_term_id ) ) { continue; } @@ -82,7 +87,7 @@ public function import( array $data ) { // While we think the term translation exists it might not, let's create it. $dest_term_id = $this->create_local_term( $term, $msls_term, $dest_lang ); - if ( false === $dest_term_id ) { + if ( ! is_int( $dest_term_id ) ) { continue; } diff --git a/includes/ContentImport/Importers/TermsImporters.php b/includes/ContentImport/Importers/TermsImporters.php index 21b7d86d9..a06bd34c5 100644 --- a/includes/ContentImport/Importers/TermsImporters.php +++ b/includes/ContentImport/Importers/TermsImporters.php @@ -9,7 +9,7 @@ class TermsImporters extends ImportersBaseFactory { const TYPE = 'terms'; /** - * @var array + * @var array> */ protected array $importers_map = array( ShallowDuplicating::TYPE => ShallowDuplicating::class, diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index 9457cef69..577657d1d 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -23,7 +23,11 @@ class MetaBox extends MslsRegistryInstance { * Renders the content import metabox. */ public function render(): void { - $post = get_post(); + $post = get_post(); + if ( ! $post instanceof \WP_Post ) { + return; + } + $mydata = new MslsOptionsPost( $post->ID ); $languages = MslsOptionsPost::instance()->get_available_languages(); $current = MslsBlogCollection::get_blog_language( get_current_blog_id() ); @@ -185,6 +189,9 @@ protected function inline_thickbox_html( $output = true, array $data = array() ) > + * @var array */ protected array $local_options = array(); @@ -93,7 +93,7 @@ protected function create_local_to_source(): void { * @param mixed $created If not `null` then the class will not create the local to source relation. * @param int $local_id * @param int $source_id - * @param MslsOptions $source_option + * @param OptionsInterface $source_option */ $created = apply_filters( 'msls_content_import_relation_local_to_source_create', @@ -106,9 +106,15 @@ protected function create_local_to_source(): void { continue; } + if ( ! $source_option instanceof MslsOptions ) { + continue; + } + $option_class = get_class( $source_option ); - $local_option = call_user_func( array( $option_class, 'create' ), $local_id ); - $local_option->save( array( $this->import_coordinates->source_lang => $source_id ) ); + $local_option = $option_class::create( $local_id ); + if ( $local_option instanceof MslsOptions ) { + $local_option->save( array( $this->import_coordinates->source_lang => $source_id ) ); + } } } diff --git a/tests/phpunit/ContentImport/TestContentImporter.php b/tests/phpunit/ContentImport/TestContentImporter.php index a94d24304..a80879191 100644 --- a/tests/phpunit/ContentImport/TestContentImporter.php +++ b/tests/phpunit/ContentImport/TestContentImporter.php @@ -43,7 +43,7 @@ public function test_handle_import(): void { public function test_parse_sources_no_post(): void { $test = $this->ContentImporterFactory(); - $this->assertFalse( $test->parse_sources() ); + $this->assertNull( $test->parse_sources() ); } public function test_handle_false(): void { From cde0c748d3a0558750f22e88054e821d9ccb94f9 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 17:55:18 +0200 Subject: [PATCH 06/13] Issues that came up during review fixed --- includes/MslsJson.php | 2 +- includes/MslsOptions.php | 2 +- includes/MslsShortCode.php | 2 +- tests/phpunit/TestMslsShortCode.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/MslsJson.php b/includes/MslsJson.php index 6cb9b1b95..a224dbf0e 100644 --- a/includes/MslsJson.php +++ b/includes/MslsJson.php @@ -52,7 +52,7 @@ public static function compare( array $a, array $b ): int { public function get(): array { $arr = $this->arr; - usort( $arr, \Closure::fromCallable( array( __CLASS__, 'compare' ) ) ); + usort( $arr, array( __CLASS__, 'compare' ) ); return $arr; } diff --git a/includes/MslsOptions.php b/includes/MslsOptions.php index 95372835d..82f2f0011 100644 --- a/includes/MslsOptions.php +++ b/includes/MslsOptions.php @@ -106,7 +106,7 @@ public static function create( $id = 0 ) { $options = new MslsOptionsPost( get_queried_object_id() ); } - add_filter( self::MSLS_GET_POSTLINK_HOOK, \Closure::fromCallable( array( self::class, 'check_for_blog_slug' ) ), 10, 2 ); + add_filter( self::MSLS_GET_POSTLINK_HOOK, array( self::class, 'check_for_blog_slug' ), 10, 2 ); return $options; } diff --git a/includes/MslsShortCode.php b/includes/MslsShortCode.php index ea5df3308..6e21db094 100644 --- a/includes/MslsShortCode.php +++ b/includes/MslsShortCode.php @@ -5,7 +5,7 @@ class MslsShortCode { public static function init(): void { - add_shortcode( 'sc_msls_widget', \Closure::fromCallable( array( __CLASS__, 'render_widget' ) ) ); + add_shortcode( 'sc_msls_widget', array( __CLASS__, 'render_widget' ) ); add_shortcode( 'sc_msls', 'msls_get_switcher' ); } diff --git a/tests/phpunit/TestMslsShortCode.php b/tests/phpunit/TestMslsShortCode.php index 58bced8f5..f3e441b77 100644 --- a/tests/phpunit/TestMslsShortCode.php +++ b/tests/phpunit/TestMslsShortCode.php @@ -9,7 +9,7 @@ final class TestMslsShortCode extends MslsUnitTestCase { public function test_init(): void { - Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls_widget', \Mockery::type( \Closure::class ) ); + Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls_widget', array( MslsShortCode::class, 'render_widget' ) ); Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls', 'msls_get_switcher' ); $this->expectNotToPerformAssertions(); From be7bd7362360fd9d7639c130c70dd7f740934992 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 18:28:40 +0200 Subject: [PATCH 07/13] MslsOptions classes moved --- MultisiteLanguageSwitcher.php | 33 +++++++------- includes/ContentImport/ContentImporter.php | 4 +- .../Importers/Terms/ShallowDuplicating.php | 5 +-- includes/ContentImport/MetaBox.php | 6 +-- includes/ContentImport/Relations.php | 8 ++-- includes/MslsAdminBar.php | 6 ++- includes/MslsBlock.php | 8 ++-- includes/MslsBlogCollection.php | 6 ++- includes/MslsContentFilter.php | 8 ++-- includes/MslsCustomColumn.php | 3 +- includes/MslsCustomColumnTaxonomy.php | 4 +- includes/MslsMain.php | 14 +++--- includes/MslsMetaBox.php | 13 +++--- includes/MslsOutput.php | 7 +-- includes/MslsPlugin.php | 9 ++-- includes/MslsPostTag.php | 5 ++- includes/MslsPostTagClassic.php | 3 +- includes/MslsRestApi.php | 10 +++-- .../{MslsOptions.php => Options/Options.php} | 24 +++++----- .../OptionsPost.php} | 8 ++-- .../OptionsQuery.php} | 26 ++++++----- .../OptionsQueryAuthor.php} | 7 +-- .../OptionsQueryDay.php} | 7 +-- .../OptionsQueryMonth.php} | 7 +-- .../OptionsQueryPostType.php} | 8 ++-- .../OptionsQueryYear.php} | 5 ++- .../OptionsTax.php} | 18 ++++---- .../OptionsTaxTerm.php} | 14 +++--- .../OptionsTaxTermCategory.php} | 8 ++-- tests/phpunit/ContentImport/TestService.php | 6 +-- .../TestOptions.php} | 23 +++++----- .../TestOptionsPost.php} | 24 +++++----- .../TestOptionsQuery.php} | 38 ++++++++-------- .../TestOptionsQueryAuthor.php} | 18 ++++---- .../TestOptionsQueryDay.php} | 18 ++++---- .../TestOptionsQueryMonth.php} | 18 ++++---- .../TestOptionsQueryPostType.php} | 18 ++++---- .../TestOptionsQueryYear.php} | 18 ++++---- .../TestOptionsTax.php} | 44 ++++++++++--------- .../TestOptionsTaxTerm.php} | 28 ++++++------ .../TestOptionsTaxTermCategory.php} | 10 +++-- tests/phpunit/TestMslsAdmin.php | 6 +-- tests/phpunit/TestMslsAdminBar.php | 6 +-- tests/phpunit/TestMslsBlock.php | 6 +-- tests/phpunit/TestMslsBlog.php | 12 ++--- tests/phpunit/TestMslsBlogCollection.php | 6 +-- tests/phpunit/TestMslsContentFilter.php | 14 +++--- tests/phpunit/TestMslsCustomColumn.php | 12 ++--- .../phpunit/TestMslsCustomColumnTaxonomy.php | 10 ++--- tests/phpunit/TestMslsCustomFilter.php | 4 +- tests/phpunit/TestMslsMain.php | 4 +- tests/phpunit/TestMslsMetaBox.php | 30 ++++++------- tests/phpunit/TestMslsOutput.php | 22 +++++----- tests/phpunit/TestMslsPlugin.php | 14 +++--- tests/phpunit/TestMslsPostTag.php | 18 ++++---- tests/phpunit/TestMslsPostTagClassic.php | 6 +-- tests/phpunit/TestMslsShortCode.php | 6 +-- tests/phpunit/TestMslsTaxonomy.php | 4 +- tests/phpunit/TestMslsWidget.php | 6 +-- 59 files changed, 396 insertions(+), 337 deletions(-) rename includes/{MslsOptions.php => Options/Options.php} (94%) rename includes/{MslsOptionsPost.php => Options/OptionsPost.php} (81%) rename includes/{MslsOptionsQuery.php => Options/OptionsQuery.php} (70%) rename includes/{MslsOptionsQueryAuthor.php => Options/OptionsQueryAuthor.php} (89%) rename includes/{MslsOptionsQueryDay.php => Options/OptionsQueryDay.php} (91%) rename includes/{MslsOptionsQueryMonth.php => Options/OptionsQueryMonth.php} (90%) rename includes/{MslsOptionsQueryPostType.php => Options/OptionsQueryPostType.php} (88%) rename includes/{MslsOptionsQueryYear.php => Options/OptionsQueryYear.php} (91%) rename includes/{MslsOptionsTax.php => Options/OptionsTax.php} (86%) rename includes/{MslsOptionsTaxTerm.php => Options/OptionsTaxTerm.php} (81%) rename includes/{MslsOptionsTaxTermCategory.php => Options/OptionsTaxTermCategory.php} (58%) rename tests/phpunit/{TestMslsOptions.php => Options/TestOptions.php} (92%) rename tests/phpunit/{TestMslsOptionsPost.php => Options/TestOptionsPost.php} (78%) rename tests/phpunit/{TestMslsOptionsQuery.php => Options/TestOptionsQuery.php} (73%) rename tests/phpunit/{TestMslsOptionsQueryAuthor.php => Options/TestOptionsQueryAuthor.php} (59%) rename tests/phpunit/{TestMslsOptionsQueryDay.php => Options/TestOptionsQueryDay.php} (56%) rename tests/phpunit/{TestMslsOptionsQueryMonth.php => Options/TestOptionsQueryMonth.php} (53%) rename tests/phpunit/{TestMslsOptionsQueryPostType.php => Options/TestOptionsQueryPostType.php} (73%) rename tests/phpunit/{TestMslsOptionsQueryYear.php => Options/TestOptionsQueryYear.php} (60%) rename tests/phpunit/{TestMslsOptionsTax.php => Options/TestOptionsTax.php} (80%) rename tests/phpunit/{TestMslsOptionsTaxTerm.php => Options/TestOptionsTaxTerm.php} (71%) rename tests/phpunit/{TestMslsOptionsTaxTermCategory.php => Options/TestOptionsTaxTermCategory.php} (50%) diff --git a/MultisiteLanguageSwitcher.php b/MultisiteLanguageSwitcher.php index 5e992ea2f..6eaa368db 100644 --- a/MultisiteLanguageSwitcher.php +++ b/MultisiteLanguageSwitcher.php @@ -49,6 +49,7 @@ define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) ); define( 'MSLS_PLUGIN__FILE__', __FILE__ ); + require_once __DIR__ . '/includes/aliases.php'; require_once __DIR__ . '/includes/deprectated.php'; /** @@ -93,7 +94,7 @@ function msls_the_switcher( array $arr = array() ): void { * @return string */ function msls_get_flag_url( string $locale ): string { - return ( new \lloc\Msls\MslsOptions() )->get_flag_url( $locale ); + return ( new \lloc\Msls\Options\Options() )->get_flag_url( $locale ); } /** @@ -123,7 +124,7 @@ function msls_get_permalink( string $locale, string $preset = '' ): string { $blog = msls_blog( $locale ); if ( $blog ) { - $options = \lloc\Msls\MslsOptions::create(); + $options = \lloc\Msls\Options\Options::create(); $url = $blog->get_url( $options ); } @@ -151,12 +152,12 @@ function msls_blog_collection(): \lloc\Msls\MslsBlogCollection { } /** - * Gets the MslsOptions instance + * Gets the Options instance * - * @return \lloc\Msls\MslsOptions + * @return \lloc\Msls\Options\Options */ - function msls_options(): \lloc\Msls\MslsOptions { - return \lloc\Msls\MslsOptions::instance(); + function msls_options(): \lloc\Msls\Options\Options { + return \lloc\Msls\Options\Options::instance(); } /** @@ -196,17 +197,17 @@ function msls_output(): \lloc\Msls\MslsOutput { } /** - * Retrieves the MslsOptionsPost instance. + * Retrieves the OptionsPost instance. * * @param int $id - * @return \lloc\Msls\MslsOptionsPost + * @return \lloc\Msls\Options\OptionsPost */ - function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost { - return new \lloc\Msls\MslsOptionsPost( $id ); + function msls_get_post( int $id ): \lloc\Msls\Options\OptionsPost { + return new \lloc\Msls\Options\OptionsPost( $id ); } /** - * Retrieves the MslsOptionsTax instance. + * Retrieves the OptionsTax instance. * * Determines the current query based on conditional tags: * - is_category @@ -217,11 +218,11 @@ function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost { * @return \lloc\Msls\OptionsTaxInterface */ function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface { - return \lloc\Msls\MslsOptionsTax::create( $id ); + return \lloc\Msls\Options\OptionsTax::create( $id ); } /** - * Retrieves the MslsOptionsQuery instance. + * Retrieves the OptionsQuery instance. * * Determines the current query based on conditional tags: * - is_day @@ -230,10 +231,10 @@ function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface { * - is_author * - is_post_type_archive * - * @return ?\lloc\Msls\MslsOptionsQuery + * @return ?\lloc\Msls\Options\OptionsQuery */ - function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery { - return \lloc\Msls\MslsOptionsQuery::create(); + function msls_get_query(): ?\lloc\Msls\Options\OptionsQuery { + return \lloc\Msls\Options\OptionsQuery::create(); } /** diff --git a/includes/ContentImport/ContentImporter.php b/includes/ContentImport/ContentImporter.php index 94f0b73a5..71d430e19 100644 --- a/includes/ContentImport/ContentImporter.php +++ b/includes/ContentImport/ContentImporter.php @@ -11,7 +11,7 @@ use lloc\Msls\ContentImport\Importers\WithRequestPostAttributes; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsMain; -use lloc\Msls\MslsOptionsPost; +use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsRegistryInstance; use lloc\Msls\MslsRequest; @@ -333,7 +333,7 @@ public function import_content( ImportCoordinates $import_coordinates, array $po $source_post_id = $import_coordinates->source_post_id; $dest_lang = $import_coordinates->dest_lang; $dest_post_id = $import_coordinates->dest_post_id; - $relations->should_create( MslsOptionsPost::create( $source_post_id ), $dest_lang, $dest_post_id ); + $relations->should_create( OptionsPost::create( $source_post_id ), $dest_lang, $dest_post_id ); foreach ( $importers as $key => $importer ) { if ( ! $importer instanceof Importer ) { diff --git a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php index 9120f3bec..f705da575 100644 --- a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php +++ b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php @@ -4,8 +4,7 @@ use lloc\Msls\ContentImport\ImportCoordinates; use lloc\Msls\ContentImport\Importers\BaseImporter; -use lloc\Msls\MslsOptionsTax; -use lloc\Msls\MslsOptionsTaxTerm; +use lloc\Msls\Options\OptionsTaxTerm; use lloc\Msls\OptionsTaxInterface; /** @@ -63,7 +62,7 @@ public function import( array $data ) { $source_terms_ids = wp_list_pluck( $source_terms, 'term_id' ); $msls_terms = array_combine( $source_terms_ids, - array_map( array( MslsOptionsTaxTerm::class, 'create' ), $source_terms_ids ) + array_map( array( OptionsTaxTerm::class, 'create' ), $source_terms_ids ) ); switch_to_blog( $this->import_coordinates->dest_blog_id ); diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index 577657d1d..5fcac23f5 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -7,7 +7,7 @@ use lloc\Msls\ContentImport\Importers\Map; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; -use lloc\Msls\MslsOptionsPost; +use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsPlugin; use lloc\Msls\MslsRegistryInstance; use lloc\Msls\MslsRequest; @@ -28,8 +28,8 @@ public function render(): void { return; } - $mydata = new MslsOptionsPost( $post->ID ); - $languages = MslsOptionsPost::instance()->get_available_languages(); + $mydata = new OptionsPost( $post->ID ); + $languages = OptionsPost::instance()->get_available_languages(); $current = MslsBlogCollection::get_blog_language( get_current_blog_id() ); $languages = array_diff_key( $languages, array( $current => $current ) ); $input_lang = MslsRequest::get( MslsFields::FIELD_MSLS_LANG, null ); diff --git a/includes/ContentImport/Relations.php b/includes/ContentImport/Relations.php index a33adba24..44f94b048 100644 --- a/includes/ContentImport/Relations.php +++ b/includes/ContentImport/Relations.php @@ -2,7 +2,7 @@ namespace lloc\Msls\ContentImport; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\OptionsInterface; use lloc\Msls\OptionsTaxInterface; @@ -72,7 +72,7 @@ protected function create_source_to_local(): void { switch_to_blog( $this->import_coordinates->source_blog_id ); foreach ( $this->to_create as $relation ) { - /** @var MslsOptions $option */ + /** @var Options $option */ list( $option, $lang, $id ) = $relation; $option->save( array( $lang => $id ) ); $source_id = $option->get_arg( 0, $id ); @@ -106,13 +106,13 @@ protected function create_local_to_source(): void { continue; } - if ( ! $source_option instanceof MslsOptions ) { + if ( ! $source_option instanceof Options ) { continue; } $option_class = get_class( $source_option ); $local_option = $option_class::create( $local_id ); - if ( $local_option instanceof MslsOptions ) { + if ( $local_option instanceof Options ) { $local_option->save( array( $this->import_coordinates->source_lang => $source_id ) ); } } diff --git a/includes/MslsAdminBar.php b/includes/MslsAdminBar.php index c0fb5fc1e..455037dbe 100644 --- a/includes/MslsAdminBar.php +++ b/includes/MslsAdminBar.php @@ -6,6 +6,8 @@ exit; } +use lloc\Msls\Options\Options; + class MslsAdminBar { /** @@ -19,10 +21,10 @@ class MslsAdminBar { protected MslsBlogCollection $blog_collection; /** - * @param MslsOptions $options + * @param Options $options * @param MslsBlogCollection $blog_collection */ - public function __construct( MslsOptions $options, MslsBlogCollection $blog_collection ) { + public function __construct( Options $options, MslsBlogCollection $blog_collection ) { $this->icon_type = $options->get_icon_type(); $this->blog_collection = $blog_collection; } diff --git a/includes/MslsBlock.php b/includes/MslsBlock.php index 1e05405a0..ee25afed3 100644 --- a/includes/MslsBlock.php +++ b/includes/MslsBlock.php @@ -2,16 +2,18 @@ namespace lloc\Msls; +use lloc\Msls\Options\Options; + class MslsBlock { /** * The options instance. * - * @var MslsOptions + * @var Options */ - protected MslsOptions $options; + protected Options $options; - public function __construct( MslsOptions $options ) { + public function __construct( Options $options ) { $this->options = $options; } diff --git a/includes/MslsBlogCollection.php b/includes/MslsBlogCollection.php index fbfa5ba31..918810a7d 100644 --- a/includes/MslsBlogCollection.php +++ b/includes/MslsBlogCollection.php @@ -6,6 +6,8 @@ exit; } +use lloc\Msls\Options\Options; + /** * Collection of blog-objects * @@ -128,11 +130,11 @@ public static function get_configured_blog_description( int $blog_id, $descripti * The first available user of the blog will be used if there is no * refrence user configured * - * @param MslsOptions $options + * @param Options $options * * @return object[]|\stdClass[] */ - public function get_blogs_of_reference_user( MslsOptions $options ) { + public function get_blogs_of_reference_user( Options $options ) { $reference_user = $options->has_value( 'reference_user' ) ? $options->reference_user : current( $this->get_users( 'ID', 1 ) ); diff --git a/includes/MslsContentFilter.php b/includes/MslsContentFilter.php index 313be0dad..59bd3ec15 100644 --- a/includes/MslsContentFilter.php +++ b/includes/MslsContentFilter.php @@ -6,16 +6,18 @@ exit; } +use lloc\Msls\Options\Options; + class MslsContentFilter { /** * The options instance. * - * @var MslsOptions + * @var Options */ - protected MslsOptions $options; + protected Options $options; - public function __construct( MslsOptions $options ) { + public function __construct( Options $options ) { $this->options = $options; } diff --git a/includes/MslsCustomColumn.php b/includes/MslsCustomColumn.php index 849f98b19..b16ed61a1 100644 --- a/includes/MslsCustomColumn.php +++ b/includes/MslsCustomColumn.php @@ -7,6 +7,7 @@ } use lloc\Msls\Component\Component; +use lloc\Msls\Options\Options; /** * Handling of existing/not existing translations in the backend listings of @@ -80,7 +81,7 @@ public function td( $column_name, $item_id ): void { $blogs = $this->collection->get(); $origin_language = MslsBlogCollection::get_blog_language(); if ( $blogs ) { - $mydata = MslsOptions::create( $item_id ); + $mydata = Options::create( $item_id ); foreach ( $blogs as $blog ) { switch_to_blog( $blog->userblog_id ); diff --git a/includes/MslsCustomColumnTaxonomy.php b/includes/MslsCustomColumnTaxonomy.php index 9bae247f9..5171acfb2 100644 --- a/includes/MslsCustomColumnTaxonomy.php +++ b/includes/MslsCustomColumnTaxonomy.php @@ -6,6 +6,8 @@ exit; } +use lloc\Msls\Options\OptionsTax; + /** * Handling of existing/not existing translations in the backend * listings of various taxonomies @@ -43,6 +45,6 @@ public function column_default( $deprecated, $column_name, $item_id ): void { * @param int $object_id */ public function delete( $object_id ): void { - $this->save( $object_id, MslsOptionsTax::class ); + $this->save( $object_id, OptionsTax::class ); } } diff --git a/includes/MslsMain.php b/includes/MslsMain.php index 8929e3e80..51906d43a 100644 --- a/includes/MslsMain.php +++ b/includes/MslsMain.php @@ -3,6 +3,8 @@ namespace lloc\Msls; use lloc\Msls\Component\Component; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\OptionsPost; /** * Abstraction for the hook classes @@ -16,7 +18,7 @@ class MslsMain { /** * Instance of options * - * @var MslsOptions + * @var Options */ protected $options; @@ -30,10 +32,10 @@ class MslsMain { /** * Constructor * - * @param MslsOptions $options + * @param Options $options * @param MslsBlogCollection $collection */ - final public function __construct( MslsOptions $options, MslsBlogCollection $collection ) { + final public function __construct( Options $options, MslsBlogCollection $collection ) { $this->options = $options; $this->collection = $collection; } @@ -119,14 +121,14 @@ public function verify_nonce(): bool { * @codeCoverageIgnore */ public function delete( $object_id ): void { - $this->save( $object_id, MslsOptionsPost::class ); + $this->save( $object_id, OptionsPost::class ); } /** * Save * - * @param int $object_id - * @param class-string $class_name + * @param int $object_id + * @param class-string $class_name * * @codeCoverageIgnore */ diff --git a/includes/MslsMetaBox.php b/includes/MslsMetaBox.php index d25d7e200..9bda2b65d 100644 --- a/includes/MslsMetaBox.php +++ b/includes/MslsMetaBox.php @@ -9,6 +9,7 @@ use lloc\Msls\Component\Component; use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\MetaBox as ContentImportMetaBox; +use lloc\Msls\Options\OptionsPost; use WP_Post; use WP_Post_Type; @@ -191,7 +192,7 @@ public function render_select(): void { return; } - $mydata = new MslsOptionsPost( $post->ID ); + $mydata = new OptionsPost( $post->ID ); $origin_language = MslsBlogCollection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); @@ -335,7 +336,7 @@ public function render_input(): void { return; } - $my_data = new MslsOptionsPost( $post->ID ); + $my_data = new OptionsPost( $post->ID ); $origin_language = MslsBlogCollection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); @@ -486,17 +487,17 @@ public function set( $post_id ): void { return; } - $this->save( $post_id, MslsOptionsPost::class ); + $this->save( $post_id, OptionsPost::class ); } /** * Sets the selected element in the data from the `$_GET` superglobal, if any. * - * @param MslsOptionsPost $mydata + * @param OptionsPost $mydata * - * @return MslsOptionsPost + * @return OptionsPost */ - public function maybe_set_linked_post( MslsOptionsPost $mydata ) { + public function maybe_set_linked_post( OptionsPost $mydata ) { if ( ! MslsRequest::isset( array( MslsFields::FIELD_MSLS_ID, MslsFields::FIELD_MSLS_LANG ) ) ) { return $mydata; } diff --git a/includes/MslsOutput.php b/includes/MslsOutput.php index 06068b06d..5d7fb71cb 100644 --- a/includes/MslsOutput.php +++ b/includes/MslsOutput.php @@ -3,6 +3,7 @@ namespace lloc\Msls; use lloc\Msls\Map\HrefLang; +use lloc\Msls\Options\Options; /** * Output in the frontend @@ -52,7 +53,7 @@ public function get( ?int $display, bool $filter = false, $exists = false ): arr $blogs = $this->collection->get_filtered( $filter ); if ( $blogs ) { - $mydata = MslsOptions::create(); + $mydata = Options::create(); $link = MslsLink::create( $display ); foreach ( $blogs as $blog ) { @@ -117,7 +118,7 @@ public function get( ?int $display, bool $filter = false, $exists = false ): arr public function get_alternate_links() { $blogs = msls_blog_collection(); $href_lang = new HrefLang( $blogs ); - $options = MslsOptions::create(); + $options = Options::create(); $arr = array(); $default = ''; @@ -218,6 +219,6 @@ public function is_requirements_not_fulfilled( $thing, $exists, $language ) { return $exists; } - return MslsOptions::class !== get_class( $thing ) && ! $thing->has_value( $language ) && $exists; + return Options::class !== get_class( $thing ) && ! $thing->has_value( $language ) && $exists; } } diff --git a/includes/MslsPlugin.php b/includes/MslsPlugin.php index f88580733..5e89a27dc 100644 --- a/includes/MslsPlugin.php +++ b/includes/MslsPlugin.php @@ -6,6 +6,7 @@ exit; } +use lloc\Msls\Options\Options; use lloc\Msls\Query\BlogsInNetworkQuery; use lloc\Msls\Query\CleanupOptionsQuery; @@ -17,18 +18,18 @@ class MslsPlugin { /** - * Injected MslsOptions object + * Injected Options object * - * @var MslsOptions + * @var Options */ protected $options; /** * MslsPlugin constructor. * - * @param MslsOptions $options + * @param Options $options */ - public function __construct( MslsOptions $options ) { + public function __construct( Options $options ) { $this->options = $options; } diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php index d77d1212b..804dd661f 100644 --- a/includes/MslsPostTag.php +++ b/includes/MslsPostTag.php @@ -7,6 +7,7 @@ } use lloc\Msls\Component\Component; +use lloc\Msls\Options\OptionsTax; use WP_Term; /** @@ -190,7 +191,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo $blogs = $this->collection->get(); if ( $blogs ) { $term_id = $tag->term_id ?? 0; - $mydata = MslsOptionsTax::create( $term_id ); + $mydata = OptionsTax::create( $term_id ); $type = msls_content_types()->get_request(); $this->maybe_set_linked_term( $mydata ); @@ -247,7 +248,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo */ public function set( $term_id ): void { if ( msls_content_types()->acl_request() ) { - $this->save( $term_id, MslsOptionsTax::class ); + $this->save( $term_id, OptionsTax::class ); } } diff --git a/includes/MslsPostTagClassic.php b/includes/MslsPostTagClassic.php index 74b179c25..95f9d2e58 100644 --- a/includes/MslsPostTagClassic.php +++ b/includes/MslsPostTagClassic.php @@ -3,6 +3,7 @@ namespace lloc\Msls; use lloc\Msls\Component\Component; +use lloc\Msls\Options\OptionsTax; /** * Post Tag Classic @@ -85,7 +86,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo $blogs = $this->collection->get(); if ( ! empty( $blogs ) ) { $term_id = $tag->term_id ?? 0; - $mydata = MslsOptionsTax::create( $term_id ); + $mydata = OptionsTax::create( $term_id ); $type = msls_content_types()->get_request(); $this->maybe_set_linked_term( $mydata ); diff --git a/includes/MslsRestApi.php b/includes/MslsRestApi.php index 25799992b..a9676ee01 100644 --- a/includes/MslsRestApi.php +++ b/includes/MslsRestApi.php @@ -2,6 +2,8 @@ namespace lloc\Msls; +use lloc\Msls\Options\OptionsPost; +use lloc\Msls\Options\OptionsTax; use lloc\Msls\Query\TranslatedPostIdQuery; if ( ! defined( 'ABSPATH' ) ) { @@ -518,8 +520,8 @@ protected function prepare_taxonomies( $mapped_terms = array(); foreach ( $terms as $term_id ) { - /** @var MslsOptionsTax $term_options */ - $term_options = MslsOptionsTax::create( $term_id ); + /** @var OptionsTax $term_options */ + $term_options = OptionsTax::create( $term_id ); if ( $term_options->has_value( $target_lang ) ) { $mapped_terms[] = (int) $term_options->$target_lang; @@ -588,7 +590,7 @@ protected function establish_link( // Read existing links from the source post switch_to_blog( $source_blog_id ); - $source_options = new MslsOptionsPost( $source_post_id ); + $source_options = new OptionsPost( $source_post_id ); $existing_links = $source_options->get_arr(); restore_current_blog(); @@ -611,7 +613,7 @@ protected function establish_link( switch_to_blog( $blog_id ); - $options = new MslsOptionsPost( $post_id ); + $options = new OptionsPost( $post_id ); $save_data = $link_map; unset( $save_data[ $lang ] ); diff --git a/includes/MslsOptions.php b/includes/Options/Options.php similarity index 94% rename from includes/MslsOptions.php rename to includes/Options/Options.php index 82f2f0011..0b5566bd8 100644 --- a/includes/MslsOptions.php +++ b/includes/Options/Options.php @@ -1,12 +1,16 @@ is_taxonomy() ) { - return MslsOptionsTax::create( $id ); + return OptionsTax::create( $id ); } - return new MslsOptionsPost( $id ); + return new OptionsPost( $id ); } if ( self::is_main_page() ) { - $options = new MslsOptions(); + $options = new Options(); } elseif ( self::is_tax_page() ) { - $options = MslsOptionsTax::create(); + $options = OptionsTax::create(); } elseif ( self::is_query_page() ) { - $options = MslsOptionsQuery::create() ?? new MslsOptions(); + $options = OptionsQuery::create() ?? new Options(); } else { - $options = new MslsOptionsPost( get_queried_object_id() ); + $options = new OptionsPost( get_queried_object_id() ); } add_filter( self::MSLS_GET_POSTLINK_HOOK, array( self::class, 'check_for_blog_slug' ), 10, 2 ); @@ -394,8 +398,8 @@ public function get_available_languages(): array { /** * The 'blog'-slug-problem :/ * - * @param mixed $url - * @param MslsOptions $options + * @param mixed $url + * @param Options $options * * @return string */ diff --git a/includes/MslsOptionsPost.php b/includes/Options/OptionsPost.php similarity index 81% rename from includes/MslsOptionsPost.php rename to includes/Options/OptionsPost.php index 57e72ee9c..f1c6aa639 100644 --- a/includes/MslsOptionsPost.php +++ b/includes/Options/OptionsPost.php @@ -1,13 +1,13 @@ has_value( $language ) ) { $post_link = $this->get_current_link(); if ( ! empty( $post_link ) ) { - $post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', MslsOptions::MSLS_GET_POSTLINK_HOOK ); + $post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', Options::MSLS_GET_POSTLINK_HOOK ); - return apply_filters( MslsOptions::MSLS_GET_POSTLINK_HOOK, $post_link, $this ); + return apply_filters( Options::MSLS_GET_POSTLINK_HOOK, $post_link, $this ); } } diff --git a/includes/MslsOptionsQueryAuthor.php b/includes/Options/OptionsQueryAuthor.php similarity index 89% rename from includes/MslsOptionsQueryAuthor.php rename to includes/Options/OptionsQueryAuthor.php index bc46add48..168379d5c 100644 --- a/includes/MslsOptionsQueryAuthor.php +++ b/includes/Options/OptionsQueryAuthor.php @@ -1,15 +1,16 @@ handle_rewrite(); @@ -91,9 +93,9 @@ public function get_postlink( $language ) { $post_link = $this->get_term_link( (int) $this->__get( $language ) ); } - $post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', MslsOptions::MSLS_GET_POSTLINK_HOOK ); + $post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', Options::MSLS_GET_POSTLINK_HOOK ); - return apply_filters( MslsOptions::MSLS_GET_POSTLINK_HOOK, $post_link, $this ); + return apply_filters( Options::MSLS_GET_POSTLINK_HOOK, $post_link, $this ); } public function get_permalink( string $language ): string { diff --git a/includes/MslsOptionsTaxTerm.php b/includes/Options/OptionsTaxTerm.php similarity index 81% rename from includes/MslsOptionsTaxTerm.php rename to includes/Options/OptionsTaxTerm.php index 9147748b0..1a2daaf68 100644 --- a/includes/MslsOptionsTaxTerm.php +++ b/includes/Options/OptionsTaxTerm.php @@ -1,17 +1,19 @@ activate_content_import = false; @@ -20,7 +20,7 @@ public function test_register_not_active_false(): void { } public function test_register_active_true(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_content_import = true; diff --git a/tests/phpunit/TestMslsOptions.php b/tests/phpunit/Options/TestOptions.php similarity index 92% rename from tests/phpunit/TestMslsOptions.php rename to tests/phpunit/Options/TestOptions.php index 1b62491a3..2d99c569a 100644 --- a/tests/phpunit/TestMslsOptions.php +++ b/tests/phpunit/Options/TestOptions.php @@ -1,38 +1,39 @@ justReturn( 'https://lloc.de' ); Functions\when( 'get_option' )->justReturn( array() ); Functions\when( 'update_option' )->justReturn( true ); - return new MslsOptions(); + return new Options(); } public function test_is_main_page(): void { Functions\when( 'is_front_page' )->justReturn( true ); - $this->assertIsBool( MslsOptions::is_main_page() ); + $this->assertIsBool( Options::is_main_page() ); } public function test_is_tax_page(): void { Functions\when( 'is_category' )->justReturn( true ); - $this->assertIsBool( MslsOptions::is_tax_page() ); + $this->assertIsBool( Options::is_tax_page() ); } public function test_is_query_page(): void { Functions\when( 'is_date' )->justReturn( true ); - $this->assertIsBool( MslsOptions::is_query_page() ); + $this->assertIsBool( Options::is_query_page() ); } public function test_create(): void { @@ -44,7 +45,7 @@ public function test_create(): void { Functions\expect( 'is_admin' )->once()->andReturnTrue(); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $this->assertInstanceOf( MslsOptions::class, MslsOptions::create() ); + $this->assertInstanceOf( Options::class, Options::create() ); } public function test_get_arg(): void { @@ -216,7 +217,7 @@ public static function provide_data_for_slug_check(): array { public function test_check_for_blog_slug( ?string $url, string $expected, bool $with_front, bool $is_subdomain_install, bool $using_permalinks, string $permalink_structure, bool $is_main_site ): void { global $wp_rewrite, $current_site; - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->with_front = $with_front; $wp_rewrite = \Mockery::mock( '\WP_Rewrite' ); $wp_rewrite->shouldReceive( 'using_permalinks' )->andReturn( $using_permalinks ); @@ -232,7 +233,7 @@ function ( $url = '' ) { Functions\when( 'get_blog_option' )->justReturn( $permalink_structure ); Functions\when( 'is_main_site' )->justReturn( $is_main_site ); - $this->assertEquals( $expected, MslsOptions::check_for_blog_slug( $url, $options ) ); + $this->assertEquals( $expected, Options::check_for_blog_slug( $url, $options ) ); } public function test_get_slug(): void { diff --git a/tests/phpunit/TestMslsOptionsPost.php b/tests/phpunit/Options/TestOptionsPost.php similarity index 78% rename from tests/phpunit/TestMslsOptionsPost.php rename to tests/phpunit/Options/TestOptionsPost.php index 1683e5132..231c0a898 100644 --- a/tests/phpunit/TestMslsOptionsPost.php +++ b/tests/phpunit/Options/TestOptionsPost.php @@ -1,21 +1,23 @@ once()->andReturn( array( 'de_DE' => 42 ) ); - return new MslsOptionsPost( 42 ); + return new OptionsPost( 42 ); } public function test_get_postlink_not_has_value(): void { - $test = $this->MslsOptionsPostFactory(); + $test = $this->OptionsPostFactory(); $this->assertEquals( '', $test->get_postlink( 'es_ES' ) ); } @@ -23,7 +25,7 @@ public function test_get_postlink_not_has_value(): void { public function test_get_postlink_post_is_null(): void { Functions\expect( 'get_post' )->once()->andReturnNull(); - $test = $this->MslsOptionsPostFactory(); + $test = $this->OptionsPostFactory(); $this->assertEquals( '', $test->get_postlink( 'de_DE' ) ); } @@ -34,7 +36,7 @@ public function test_get_postlink_post_is_draft(): void { Functions\expect( 'get_post' )->once()->andReturn( $post ); - $test = $this->MslsOptionsPostFactory(); + $test = $this->OptionsPostFactory(); $this->assertEquals( '', $test->get_postlink( 'de_DE' ) ); } @@ -48,7 +50,7 @@ public function test_get_postlink_post_is_published(): void { Functions\expect( 'get_post_type_object' )->once()->andReturn( (object) array( 'rewrite' => array( 'with_front' => true ) ) ); Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.de/a-post' ); - $test = $this->MslsOptionsPostFactory(); + $test = $this->OptionsPostFactory(); Filters\expectApplied( 'check_url' )->once()->with( 'https://example.de/a-post', $test ); @@ -58,13 +60,13 @@ public function test_get_postlink_post_is_published(): void { public function test_get_current_link(): void { Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/a-post' ); - $test = $this->MslsOptionsPostFactory(); + $test = $this->OptionsPostFactory(); $this->assertEquals( 'https://msls.co/a-post', $test->get_current_link() ); } public function test_get_option_name(): void { - $test = $this->MslsOptionsPostFactory(); + $test = $this->OptionsPostFactory(); $this->assertSame( 'msls_42', $test->get_option_name() ); } diff --git a/tests/phpunit/TestMslsOptionsQuery.php b/tests/phpunit/Options/TestOptionsQuery.php similarity index 73% rename from tests/phpunit/TestMslsOptionsQuery.php rename to tests/phpunit/Options/TestOptionsQuery.php index e95ccfbc8..896f3bf4e 100644 --- a/tests/phpunit/TestMslsOptionsQuery.php +++ b/tests/phpunit/Options/TestOptionsQuery.php @@ -1,17 +1,19 @@ assertEquals( array(), MslsOptionsQuery::get_params() ); + $this->assertEquals( array(), OptionsQuery::get_params() ); } public function test_create_is_day(): void { @@ -30,7 +32,7 @@ public function test_create_is_day(): void { Functions\expect( 'get_query_var' )->times( 6 )->andReturnValues( array( 1969, 6, 26 ) ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( MslsOptionsQueryDay::class, MslsOptionsQuery::create() ); + $this->assertInstanceOf( OptionsQueryDay::class, OptionsQuery::create() ); } public function test_create_is_month(): void { Functions\expect( 'is_day' )->once()->andReturn( false ); @@ -38,7 +40,7 @@ public function test_create_is_month(): void { Functions\expect( 'get_query_var' )->times( 4 )->andReturnValues( array( 1969, 6 ) ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( MslsOptionsQueryMonth::class, MslsOptionsQuery::create() ); + $this->assertInstanceOf( OptionsQueryMonth::class, OptionsQuery::create() ); } public function test_create_is_year(): void { @@ -48,7 +50,7 @@ public function test_create_is_year(): void { Functions\expect( 'get_query_var' )->times( 2 )->andReturn( 1969 ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( MslsOptionsQueryYear::class, MslsOptionsQuery::create() ); + $this->assertInstanceOf( OptionsQueryYear::class, OptionsQuery::create() ); } public function test_create_is_author(): void { @@ -59,7 +61,7 @@ public function test_create_is_author(): void { Functions\expect( 'get_queried_object_id' )->times( 2 )->andReturn( 42 ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( MslsOptionsQueryAuthor::class, MslsOptionsQuery::create() ); + $this->assertInstanceOf( OptionsQueryAuthor::class, OptionsQuery::create() ); } public function test_create_is_post_type_archive(): void { @@ -71,7 +73,7 @@ public function test_create_is_post_type_archive(): void { Functions\expect( 'get_query_var' )->times( 2 )->andReturn( 'book' ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( MslsOptionsQueryPostType::class, MslsOptionsQuery::create() ); + $this->assertInstanceOf( OptionsQueryPostType::class, OptionsQuery::create() ); } public function test_create_is_null(): void { @@ -81,7 +83,7 @@ public function test_create_is_null(): void { Functions\expect( 'is_author' )->once()->andReturn( false ); Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); - $this->assertNull( MslsOptionsQuery::create() ); + $this->assertNull( OptionsQuery::create() ); } public function test_current_get_postlink(): void { @@ -92,7 +94,7 @@ public function test_current_get_postlink(): void { $sql_cache = \Mockery::mock( MslsSqlCacher::class ); - $this->assertEquals( $home_url, ( new MslsOptionsQuery( $sql_cache ) )->get_postlink( 'de_DE' ) ); + $this->assertEquals( $home_url, ( new OptionsQuery( $sql_cache ) )->get_postlink( 'de_DE' ) ); } public function test_non_existent_get_postlink(): void { @@ -100,7 +102,7 @@ public function test_non_existent_get_postlink(): void { $sql_cache = \Mockery::mock( MslsSqlCacher::class ); - $this->assertEquals( '', ( new MslsOptionsQuery( $sql_cache ) )->get_postlink( 'fr_FR' ) ); + $this->assertEquals( '', ( new OptionsQuery( $sql_cache ) )->get_postlink( 'fr_FR' ) ); } public function test_get_permalink_returns_empty_when_no_translation(): void { @@ -108,6 +110,6 @@ public function test_get_permalink_returns_empty_when_no_translation(): void { $sql_cache = \Mockery::mock( MslsSqlCacher::class ); - $this->assertSame( '', ( new MslsOptionsQuery( $sql_cache ) )->get_permalink( 'fr_FR' ) ); + $this->assertSame( '', ( new OptionsQuery( $sql_cache ) )->get_permalink( 'fr_FR' ) ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryAuthor.php b/tests/phpunit/Options/TestOptionsQueryAuthor.php similarity index 59% rename from tests/phpunit/TestMslsOptionsQueryAuthor.php rename to tests/phpunit/Options/TestOptionsQueryAuthor.php index c34068e36..5a8bc9e2d 100644 --- a/tests/phpunit/TestMslsOptionsQueryAuthor.php +++ b/tests/phpunit/Options/TestOptionsQueryAuthor.php @@ -1,14 +1,16 @@ once()->andReturn( array() ); Functions\expect( 'get_queried_object_id' )->once()->andReturn( $author_id ); @@ -16,20 +18,20 @@ private function MslsOptionsQueryAuthorFactory( int $author_id ): MslsOptionsQue $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new MslsOptionsQueryAuthor( $sql_cacher ); + return new OptionsQueryAuthor( $sql_cacher ); } public function test_has_value_true(): void { - $this->assertTrue( $this->MslsOptionsQueryAuthorFactory( 17 )->has_value( 'de_DE' ) ); + $this->assertTrue( $this->OptionsQueryAuthorFactory( 17 )->has_value( 'de_DE' ) ); } public function test_has_value_false(): void { - $this->assertFalse( $this->MslsOptionsQueryAuthorFactory( 0 )->has_value( 'de_DE' ) ); + $this->assertFalse( $this->OptionsQueryAuthorFactory( 0 )->has_value( 'de_DE' ) ); } public function test_get_current_link_method(): void { Functions\expect( 'get_author_posts_url' )->once()->andReturn( 'https://msls.co/queried-author' ); - $this->assertEquals( 'https://msls.co/queried-author', $this->MslsOptionsQueryAuthorFactory( 42 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-author', $this->OptionsQueryAuthorFactory( 42 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryDay.php b/tests/phpunit/Options/TestOptionsQueryDay.php similarity index 56% rename from tests/phpunit/TestMslsOptionsQueryDay.php rename to tests/phpunit/Options/TestOptionsQueryDay.php index 8363f82d1..24b1f5b58 100644 --- a/tests/phpunit/TestMslsOptionsQueryDay.php +++ b/tests/phpunit/Options/TestOptionsQueryDay.php @@ -1,14 +1,16 @@ once()->andReturn( array() ); @@ -18,20 +20,20 @@ private function MslsOptionsQueryDayFactory( int $year, int $monthnum, int $day $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new MslsOptionsQueryDay( $sql_cacher ); + return new OptionsQueryDay( $sql_cacher ); } public function test_has_value_true(): void { - $this->assertTrue( $this->MslsOptionsQueryDayFactory( 1998, 12, 31 )->has_value( 'de_DE' ) ); + $this->assertTrue( $this->OptionsQueryDayFactory( 1998, 12, 31 )->has_value( 'de_DE' ) ); } public function test_has_value(): void { - $this->assertFalse( $this->MslsOptionsQueryDayFactory( 0, 0, 0 )->has_value( 'de_DE' ) ); + $this->assertFalse( $this->OptionsQueryDayFactory( 0, 0, 0 )->has_value( 'de_DE' ) ); } public function test_get_current_link(): void { Functions\expect( 'get_day_link' )->once()->andReturn( 'https://msls.co/queried-day' ); - $this->assertEquals( 'https://msls.co/queried-day', $this->MslsOptionsQueryDayFactory( 2015, 07, 02 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-day', $this->OptionsQueryDayFactory( 2015, 07, 02 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryMonth.php b/tests/phpunit/Options/TestOptionsQueryMonth.php similarity index 53% rename from tests/phpunit/TestMslsOptionsQueryMonth.php rename to tests/phpunit/Options/TestOptionsQueryMonth.php index 0124ebe26..ec36547db 100644 --- a/tests/phpunit/TestMslsOptionsQueryMonth.php +++ b/tests/phpunit/Options/TestOptionsQueryMonth.php @@ -1,14 +1,16 @@ once()->andReturn( array() ); Functions\expect( 'get_query_var' )->times( 2 )->andReturn( $year, $monthnum ); @@ -16,20 +18,20 @@ private function MslsOptionsQueryMonthFactory( int $year, int $monthnum ): MslsO $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new MslsOptionsQueryMonth( $sql_cacher ); + return new OptionsQueryMonth( $sql_cacher ); } public function test_has_value_true(): void { - $this->assertTrue( $this->MslsOptionsQueryMonthFactory( 1998, 12 )->has_value( 'de_DE' ) ); + $this->assertTrue( $this->OptionsQueryMonthFactory( 1998, 12 )->has_value( 'de_DE' ) ); } public function test_has_value_false(): void { - $this->assertFalse( $this->MslsOptionsQueryMonthFactory( 0, 0 )->has_value( 'de_DE' ) ); + $this->assertFalse( $this->OptionsQueryMonthFactory( 0, 0 )->has_value( 'de_DE' ) ); } public function test_get_current_link(): void { Functions\expect( 'get_month_link' )->once()->andReturn( 'https://msls.co/queried-month' ); - $this->assertEquals( 'https://msls.co/queried-month', $this->MslsOptionsQueryMonthFactory( 2015, 7 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-month', $this->OptionsQueryMonthFactory( 2015, 7 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryPostType.php b/tests/phpunit/Options/TestOptionsQueryPostType.php similarity index 73% rename from tests/phpunit/TestMslsOptionsQueryPostType.php rename to tests/phpunit/Options/TestOptionsQueryPostType.php index 89c93914c..763fc11e0 100644 --- a/tests/phpunit/TestMslsOptionsQueryPostType.php +++ b/tests/phpunit/Options/TestOptionsQueryPostType.php @@ -1,14 +1,16 @@ once()->andReturn( array() ); Functions\expect( 'get_query_var' )->once()->andReturn( 'queried-posttype' ); @@ -16,7 +18,7 @@ private function MslsOptionsQueryPostTypeFactory(): MslsOptionsQueryPostType { $sql_cacher->shouldReceive( 'prepare' )->never(); $sql_cacher->shouldReceive( 'get_var' )->never(); - return new MslsOptionsQueryPostType( $sql_cacher ); + return new OptionsQueryPostType( $sql_cacher ); } public function test_has_value_existing(): void { @@ -29,7 +31,7 @@ public function test_has_value_existing(): void { ) ); - $test = $this->MslsOptionsQueryPostTypeFactory(); + $test = $this->OptionsQueryPostTypeFactory(); $this->assertTrue( $test->has_value( 'de_DE' ) ); } @@ -38,7 +40,7 @@ public function test_has_value_not_existing(): void { $post_type = \Mockery::mock( '\WP_Post_Type' ); Functions\expect( 'get_post_type_object' )->once()->andReturn( $post_type ); - $test = $this->MslsOptionsQueryPostTypeFactory(); + $test = $this->OptionsQueryPostTypeFactory(); $this->assertTrue( $test->has_value( 'it_IT' ) ); } @@ -46,7 +48,7 @@ public function test_has_value_not_existing(): void { public function test_get_current_link(): void { Functions\expect( 'get_post_type_archive_link' )->once()->andReturn( 'https://msls.co/queried-posttype' ); - $test = $this->MslsOptionsQueryPostTypeFactory(); + $test = $this->OptionsQueryPostTypeFactory(); $this->assertEquals( 'https://msls.co/queried-posttype', $test->get_current_link() ); } diff --git a/tests/phpunit/TestMslsOptionsQueryYear.php b/tests/phpunit/Options/TestOptionsQueryYear.php similarity index 60% rename from tests/phpunit/TestMslsOptionsQueryYear.php rename to tests/phpunit/Options/TestOptionsQueryYear.php index d941bbde7..08f61695a 100644 --- a/tests/phpunit/TestMslsOptionsQueryYear.php +++ b/tests/phpunit/Options/TestOptionsQueryYear.php @@ -1,14 +1,16 @@ once()->andReturn( array() ); Functions\expect( 'get_query_var' )->once()->andReturn( $year ); @@ -16,21 +18,21 @@ private function MslsOptionsQueryYearFactory( int $year ): MslsOptionsQueryYear $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new MslsOptionsQueryYear( $sql_cacher ); + return new OptionsQueryYear( $sql_cacher ); } public function test_has_value_true(): void { - $this->assertTrue( $this->MslsOptionsQueryYearFactory( 1998 )->has_value( 'de_DE' ) ); + $this->assertTrue( $this->OptionsQueryYearFactory( 1998 )->has_value( 'de_DE' ) ); } public function test_has_value_false(): void { - $this->assertFalse( $this->MslsOptionsQueryYearFactory( 0 )->has_value( 'de_DE' ) ); + $this->assertFalse( $this->OptionsQueryYearFactory( 0 )->has_value( 'de_DE' ) ); } public function test_get_current_link_method(): void { Functions\expect( 'get_year_link' )->once()->andReturn( 'https://msls.co/queried-year' ); - $test = $this->MslsOptionsQueryYearFactory( 2015 ); + $test = $this->OptionsQueryYearFactory( 2015 ); $this->assertEquals( 'https://msls.co/queried-year', $test->get_current_link() ); } diff --git a/tests/phpunit/TestMslsOptionsTax.php b/tests/phpunit/Options/TestOptionsTax.php similarity index 80% rename from tests/phpunit/TestMslsOptionsTax.php rename to tests/phpunit/Options/TestOptionsTax.php index b55a38229..53a284b5c 100644 --- a/tests/phpunit/TestMslsOptionsTax.php +++ b/tests/phpunit/Options/TestOptionsTax.php @@ -1,18 +1,20 @@ atLeast()->once()->andReturn( array( 'de_DE' => 42 ) ); - return new MslsOptionsTax(); + return new OptionsTax(); } public function test_create_category(): void { @@ -21,7 +23,7 @@ public function test_create_category(): void { Functions\expect( 'is_category' )->once()->with( 42 )->andReturnTrue(); Functions\expect( 'get_option' )->atLeast()->once()->andReturn( array( 'de_DE' => 42 ) ); - $this->assertInstanceOf( MslsOptionsTaxTermCategory::class, MslsOptionsTax::create() ); + $this->assertInstanceOf( OptionsTaxTermCategory::class, OptionsTax::create() ); } public function test_create_post_tag(): void { @@ -31,13 +33,13 @@ public function test_create_post_tag(): void { Functions\expect( 'is_tag' )->once()->andReturnTrue(); Functions\expect( 'get_option' )->atLeast()->once()->andReturn( array( 'de_DE' => 42 ) ); - $this->assertInstanceOf( MslsOptionsTaxTerm::class, MslsOptionsTax::create() ); + $this->assertInstanceOf( OptionsTaxTerm::class, OptionsTax::create() ); } public function test_get_tax_query(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( '', $test->get_tax_query() ); } @@ -56,7 +58,7 @@ public function test_get_tax_query_woo(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( true ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( $expected, $test->get_tax_query() ); } @@ -75,7 +77,7 @@ public function test_get_tax_query_set(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( $expected, $test->get_tax_query( array() ) ); } @@ -83,7 +85,7 @@ public function test_get_tax_query_set(): void { public function test_get_postlink(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( '', $test->get_postlink( 'de_DE' ) ); } @@ -91,13 +93,13 @@ public function test_get_postlink(): void { public function test_get_postlink_empty(): void { Functions\expect( 'is_woocommerce' )->never(); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( '', $test->get_postlink( 'it_IT' ) ); } public function test_get_current_link(): void { - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertIsString( $test->get_current_link() ); } @@ -118,7 +120,7 @@ public function test_get_term_link(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); Functions\expect( 'get_term_link' )->once()->andReturn( $expected ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( $expected, $test->get_term_link( 42 ) ); } @@ -139,7 +141,7 @@ public function test_get_term_link_wp_error(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); Functions\expect( 'get_term_link' )->once()->andReturn( $wp_error ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertEquals( '', $test->get_term_link( 42 ) ); } @@ -147,11 +149,11 @@ public function test_get_term_link_wp_error(): void { public function test_get_term_link_empty(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); - $this->assertEquals( '', $this->MslsOptionsTaxFactory()->get_term_link( 42 ) ); + $this->assertEquals( '', $this->OptionsTaxFactory()->get_term_link( 42 ) ); } public function test_get_permalink_returns_empty_when_no_translation(): void { - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertSame( '', $test->get_permalink( 'fr_FR' ) ); } @@ -172,12 +174,12 @@ public function test_get_permalink_returns_url_when_term_link_succeeds(): void { Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); Functions\expect( 'get_term_link' )->once()->andReturn( $expected ); - $test = $this->MslsOptionsTaxFactory(); + $test = $this->OptionsTaxFactory(); $this->assertSame( $expected, $test->get_permalink( 'de_DE' ) ); } public function test_get_base_option() { - $this->assertEquals( '', MslsOptionsTax::get_base_option() ); + $this->assertEquals( '', OptionsTax::get_base_option() ); } } diff --git a/tests/phpunit/TestMslsOptionsTaxTerm.php b/tests/phpunit/Options/TestOptionsTaxTerm.php similarity index 71% rename from tests/phpunit/TestMslsOptionsTaxTerm.php rename to tests/phpunit/Options/TestOptionsTaxTerm.php index a4e30adf4..d71fdd41a 100644 --- a/tests/phpunit/TestMslsOptionsTaxTerm.php +++ b/tests/phpunit/Options/TestOptionsTaxTerm.php @@ -1,13 +1,15 @@ times( $get_option_exec_times )->andReturnUsing( function ( $value ) { if ( 'msls_term_42' === $value ) { @@ -22,19 +24,19 @@ function ( $value ) { } ); - return new MslsOptionsTaxTerm( 42 ); + return new OptionsTaxTerm( 42 ); } public function test_get_postlink_empty(): void { - $test = $this->MslsOptionsTaxTermFactory( 1 ); + $test = $this->OptionsTaxTermFactory( 1 ); $this->assertEquals( '', $test->get_postlink( '' ) ); } public function test_check_url_empty(): void { - $options = \Mockery::mock( MslsOptionsTaxTerm::class ); + $options = \Mockery::mock( OptionsTaxTerm::class ); - $test = $this->MslsOptionsTaxTermFactory( 1 ); + $test = $this->OptionsTaxTermFactory( 1 ); $this->assertEquals( '', $test->check_base( null, $options ) ); $this->assertEquals( '', $test->check_base( '', $options ) ); @@ -47,12 +49,12 @@ public function test_check_url(): void { $wp_rewrite = \Mockery::mock( 'WP_Rewrite' ); $wp_rewrite->shouldReceive( 'get_extra_permastruct' )->andReturn( '/schlagwort/' ); - $options = \Mockery::mock( MslsOptionsTaxTerm::class ); + $options = \Mockery::mock( OptionsTaxTerm::class ); $options->shouldReceive( 'get_tax_query' )->andReturn( '' ); $expected = 'https://example.de/tag/keyword'; - $test = $this->MslsOptionsTaxTermFactory(); + $test = $this->OptionsTaxTermFactory(); $this->assertEquals( $expected, $test->check_base( 'https://example.de/schlagwort/keyword', $options ) ); } @@ -63,18 +65,18 @@ public function test_check_url_permastruct_false(): void { $wp_rewrite = \Mockery::mock( 'WP_Rewrite' ); $wp_rewrite->shouldReceive( 'get_extra_permastruct' )->andReturn( false ); - $options = \Mockery::mock( MslsOptionsTaxTerm::class ); + $options = \Mockery::mock( OptionsTaxTerm::class ); $options->shouldReceive( 'get_tax_query' )->andReturn( '' ); $expected = 'https://example.de/schlagwort/keyword'; - $test = $this->MslsOptionsTaxTermFactory(); + $test = $this->OptionsTaxTermFactory(); $this->assertEquals( $expected, $test->check_base( $expected, $options ) ); } public function test_get_option_name(): void { - $test = $this->MslsOptionsTaxTermFactory( 1 ); + $test = $this->OptionsTaxTermFactory( 1 ); $this->assertSame( 'msls_term_42', $test->get_option_name() ); } diff --git a/tests/phpunit/TestMslsOptionsTaxTermCategory.php b/tests/phpunit/Options/TestOptionsTaxTermCategory.php similarity index 50% rename from tests/phpunit/TestMslsOptionsTaxTermCategory.php rename to tests/phpunit/Options/TestOptionsTaxTermCategory.php index cb2bb6c3e..07767962a 100644 --- a/tests/phpunit/TestMslsOptionsTaxTermCategory.php +++ b/tests/phpunit/Options/TestOptionsTaxTermCategory.php @@ -1,16 +1,18 @@ once()->andReturn( array() ); - $obj = new MslsOptionsTaxTermCategory( 0 ); + $obj = new OptionsTaxTermCategory( 0 ); $this->assertIsSTring( $obj->get_postlink( '' ) ); } diff --git a/tests/phpunit/TestMslsAdmin.php b/tests/phpunit/TestMslsAdmin.php index 20349eff1..91192104e 100644 --- a/tests/phpunit/TestMslsAdmin.php +++ b/tests/phpunit/TestMslsAdmin.php @@ -6,7 +6,7 @@ use lloc\Msls\MslsAdmin; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsAdmin extends MslsUnitTestCase { @@ -19,7 +19,7 @@ private function MslsAdminFactory( array $users = array() ): MslsAdmin { Functions\when( 'get_admin_url' )->justReturn( 'wp-admin' ); Functions\when( 'get_locale' )->justReturn( 'de_DE' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_empty' )->andReturns( false ); $options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE', 'it_IT' ) ); $options->shouldReceive( 'get_icon_type' )->andReturns( 'flag' ); @@ -72,7 +72,7 @@ public function test_has_problems( array $languages, bool $is_empty, string $reg Functions\when( 'get_current_blog_id' )->justReturn( 1 ); Functions\when( 'admin_url' )->justReturn( '' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_available_languages' )->zeroOrMoreTimes()->andReturns( $languages ); $collection = \Mockery::mock( MslsBlogCollection::class ); diff --git a/tests/phpunit/TestMslsAdminBar.php b/tests/phpunit/TestMslsAdminBar.php index 38c76c7d7..96cbe81b7 100644 --- a/tests/phpunit/TestMslsAdminBar.php +++ b/tests/phpunit/TestMslsAdminBar.php @@ -8,12 +8,12 @@ use lloc\Msls\MslsAdminIcon; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsAdminBar extends MslsUnitTestCase { private function MslsAdminBarFactory(): MslsAdminBar { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'label' ); $blog_a = \Mockery::mock( MslsBlog::class ); @@ -36,7 +36,7 @@ private function MslsAdminBarFactory(): MslsAdminBar { } public function test_init(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( MslsAdminIcon::TYPE_LABEL ); $collection = \Mockery::mock( MslsBlogCollection::class ); diff --git a/tests/phpunit/TestMslsBlock.php b/tests/phpunit/TestMslsBlock.php index 8738f8a75..7bf70b66c 100644 --- a/tests/phpunit/TestMslsBlock.php +++ b/tests/phpunit/TestMslsBlock.php @@ -4,12 +4,12 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlock; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsBlock extends MslsUnitTestCase { public function test_register_block_excluded_true(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( true ); $this->assertFalse( ( new MslsBlock( $options ) )->register_block() ); @@ -17,7 +17,7 @@ public function test_register_block_excluded_true(): void { public function test_register_block_excluded_false(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); Functions\expect( 'register_block_type' )->once(); diff --git a/tests/phpunit/TestMslsBlog.php b/tests/phpunit/TestMslsBlog.php index 96196c38b..d33c07464 100644 --- a/tests/phpunit/TestMslsBlog.php +++ b/tests/phpunit/TestMslsBlog.php @@ -5,7 +5,7 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsBlog extends MslsUnitTestCase { @@ -31,7 +31,7 @@ public function test_get_description(): void { public function test_get_url_current(): void { $url = 'https://msls.co/'; - $option = \Mockery::mock( MslsOptions::class ); + $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'get_current_link' )->andReturn( $url ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -45,7 +45,7 @@ public function test_get_url_current(): void { public function test_get_frontpage(): void { $url = 'https://msls.co/'; - $option = \Mockery::mock( MslsOptions::class ); + $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -63,7 +63,7 @@ public function test_get_frontpage(): void { public function test_get_url(): void { $url = 'https://msls.co/'; - $option = \Mockery::mock( MslsOptions::class ); + $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); $option->shouldReceive( 'has_value' )->once()->andReturn( true ); @@ -82,7 +82,7 @@ public function test_get_url(): void { public function test_get_posts_page(): void { $url = 'https://msls.co/sv/blogg/'; - $option = \Mockery::mock( MslsOptions::class ); + $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'has_value' )->once()->andReturn( false ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -102,7 +102,7 @@ public function test_get_posts_page(): void { public function test_get_posts_page_with_translation(): void { $url = 'https://msls.co/sv/blogg/'; - $option = \Mockery::mock( MslsOptions::class ); + $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); $option->shouldReceive( 'has_value' )->once()->andReturn( true ); diff --git a/tests/phpunit/TestMslsBlogCollection.php b/tests/phpunit/TestMslsBlogCollection.php index 1ab2329dc..c29f0ce31 100644 --- a/tests/phpunit/TestMslsBlogCollection.php +++ b/tests/phpunit/TestMslsBlogCollection.php @@ -5,7 +5,7 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsBlogCollection extends MslsUnitTestCase { @@ -16,7 +16,7 @@ protected function setUp(): void { Functions\when( 'count_users' )->justReturn( array( 'total_users' => self::TOTAL_USERS ) ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_order' )->andReturn( 'description' ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); $options->shouldReceive( 'has_value' )->andReturn( false ); @@ -86,7 +86,7 @@ public function test_get_configured_blog_description_empty(): void { public function test_get_blogs_of_reference_user(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'has_value' )->andReturn( true ); $obj = new MslsBlogCollection(); diff --git a/tests/phpunit/TestMslsContentFilter.php b/tests/phpunit/TestMslsContentFilter.php index ee0adde50..2e12b39f2 100644 --- a/tests/phpunit/TestMslsContentFilter.php +++ b/tests/phpunit/TestMslsContentFilter.php @@ -7,12 +7,12 @@ use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsContentFilter; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsContentFilter extends MslsUnitTestCase { public function test_init(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); @@ -39,7 +39,7 @@ public function test_content_filter_empty( string $content, string $expected, bo Functions\when( 'is_front_page' )->justReturn( $is_front_page ); Functions\when( 'is_singular' )->justReturn( $is_singular ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( $is_content_filter ); $test = new MslsContentFilter( $options ); @@ -56,7 +56,7 @@ public function test_content_filter_one_link(): void { $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( false ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( true ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); @@ -99,7 +99,7 @@ public function test_content_filter_zero_links(): void { $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array() ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( true ); $post = \Mockery::mock( 'WP_Post' ); @@ -141,7 +141,7 @@ public function test_content_filter_more_links(): void { $collection->shouldReceive( 'get_filtered' )->once()->andReturn( $blogs ); $collection->shouldReceive( 'is_current_blog' )->times( $times )->andReturn( false ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( true ); $options->shouldReceive( 'get_flag_url' )->times( $times )->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); @@ -196,7 +196,7 @@ public function test_content_filter_with_filter(): void { $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( false ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( true ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); diff --git a/tests/phpunit/TestMslsCustomColumn.php b/tests/phpunit/TestMslsCustomColumn.php index 764695d43..2b93ffdd0 100644 --- a/tests/phpunit/TestMslsCustomColumn.php +++ b/tests/phpunit/TestMslsCustomColumn.php @@ -9,13 +9,13 @@ use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsCustomColumn; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsPostType; final class TestMslsCustomColumn extends MslsUnitTestCase { private function MslsCustomColumnFactory(): MslsCustomColumn { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'flag' ); $locales = array( @@ -40,7 +40,7 @@ private function MslsCustomColumnFactory(): MslsCustomColumn { } public function test_add_hooks_excluded(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( true ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -53,7 +53,7 @@ public function test_add_hooks_excluded(): void { } public function test_add_hooks(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -87,7 +87,7 @@ public function test_th(): void { } public function test_th_empty(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get' )->once()->andReturn( array() ); @@ -114,7 +114,7 @@ public function test_td(): void { Functions\expect( 'get_edit_post_link' )->once()->andReturn( 'edit-post-link' ); Functions\expect( 'add_query_arg' )->once()->andReturn( 'added-query-args' ); Functions\expect( 'get_admin_url' )->once()->andReturn( 'admin-url' ); - Functions\expect( 'msls_options' )->andReturn( \Mockery::mock( MslsOptions::class ) ); + Functions\expect( 'msls_options' )->andReturn( \Mockery::mock( Options::class ) ); $output = '  '; diff --git a/tests/phpunit/TestMslsCustomColumnTaxonomy.php b/tests/phpunit/TestMslsCustomColumnTaxonomy.php index 12d566403..591148eab 100644 --- a/tests/phpunit/TestMslsCustomColumnTaxonomy.php +++ b/tests/phpunit/TestMslsCustomColumnTaxonomy.php @@ -7,13 +7,13 @@ use Brain\Monkey\Actions; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsCustomColumnTaxonomy; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsTaxonomy; final class TestMslsCustomColumnTaxonomy extends MslsUnitTestCase { public function test_add_hooks_excluded(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( true ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -26,7 +26,7 @@ public function test_add_hooks_excluded(): void { } public function test_add_hooks(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -48,7 +48,7 @@ public function test_add_hooks(): void { } public function test_th(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get' )->andReturn( array() )->once(); @@ -59,7 +59,7 @@ public function test_th(): void { } public function test_column_default(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); diff --git a/tests/phpunit/TestMslsCustomFilter.php b/tests/phpunit/TestMslsCustomFilter.php index 9a70a7dcd..94807e749 100644 --- a/tests/phpunit/TestMslsCustomFilter.php +++ b/tests/phpunit/TestMslsCustomFilter.php @@ -8,12 +8,12 @@ use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsCustomFilter; use lloc\Msls\MslsFields; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsCustomFilter extends MslsUnitTestCase { private function MslsCustomFilterFactory(): MslsCustomFilter { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $blog = \Mockery::mock( MslsBlog::class ); $blog->userblog_id = 1; diff --git a/tests/phpunit/TestMslsMain.php b/tests/phpunit/TestMslsMain.php index d9116c3f3..af7c4b8d9 100644 --- a/tests/phpunit/TestMslsMain.php +++ b/tests/phpunit/TestMslsMain.php @@ -6,12 +6,12 @@ use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsMain; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; final class TestMslsMain extends MslsUnitTestCase { private function MslsMainFactory(): MslsMain { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $blog = \Mockery::mock( MslsBlog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); diff --git a/tests/phpunit/TestMslsMetaBox.php b/tests/phpunit/TestMslsMetaBox.php index d58acbbe1..da77acbe6 100644 --- a/tests/phpunit/TestMslsMetaBox.php +++ b/tests/phpunit/TestMslsMetaBox.php @@ -11,8 +11,8 @@ use lloc\Msls\MslsFields; use lloc\Msls\MslsJson; use lloc\Msls\MslsMetaBox; -use lloc\Msls\MslsOptions; -use lloc\Msls\MslsOptionsPost; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsPostType; final class TestMslsMetaBox extends MslsUnitTestCase { @@ -23,7 +23,7 @@ private function MslsMetaBoxFactory(): MslsMetaBox { $blog = \Mockery::mock( MslsBlog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'flag' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -36,7 +36,7 @@ private function MslsMetaBoxFactory(): MslsMetaBox { } public function test_init(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -170,7 +170,7 @@ public static function add_data_provider(): array { * @dataProvider add_data_provider */ public function test_add( $post_type, $content_import, $autocomplete ) { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_content_import = $content_import; $options->activate_autocomplete = $autocomplete; @@ -192,7 +192,7 @@ public function test_render_select_not_hierarchical(): void { $post = \Mockery::mock( 'WP_Post' ); $post->ID = 42; - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_quick_create = false; $post_type = \Mockery::mock( MslsPostType::class ); @@ -273,7 +273,7 @@ public function test_render_input( $option, $the_title_times, $current_blog_id_t $post = \Mockery::mock( 'WP_Post' ); $post->ID = 42; - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_quick_create = false; $post_type = \Mockery::mock( MslsPostType::class ); @@ -302,7 +302,7 @@ public function test_render_input( $option, $the_title_times, $current_blog_id_t } public function test_render_select_only_one_blog(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); @@ -316,7 +316,7 @@ public function test_render_select_only_one_blog(): void { } public function test_render_input_only_one_blog(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); @@ -375,7 +375,7 @@ public function test_maybe_set_linked_post() { $test = $this->MslsMetaBoxFactory(); - $mydata = new MslsOptionsPost(); + $mydata = new OptionsPost(); $mydata = $test->maybe_set_linked_post( $mydata ); $this->assertEquals( 42, $mydata->de_DE ); @@ -393,14 +393,14 @@ public function test_maybe_set_linked_post_with_no_post() { $test = $this->MslsMetaBoxFactory(); - $mydata = new MslsOptionsPost(); + $mydata = new OptionsPost(); $mydata = $test->maybe_set_linked_post( $mydata ); $this->assertNull( $mydata->de_DE ); } function test_maybe_set_linked_post_with_no_blog_id() { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get_blog_id' )->andReturn( null ); @@ -413,14 +413,14 @@ function test_maybe_set_linked_post_with_no_blog_id() { Functions\expect( 'filter_input' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_ID, FILTER_SANITIZE_NUMBER_INT )->andReturn( 42 ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new MslsOptionsPost(); + $mydata = new OptionsPost(); $mydata = $test->maybe_set_linked_post( $mydata ); $this->assertNull( $mydata->de_DE ); } function test_maybe_set_linked_post_with_mydata_already_set() { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -431,7 +431,7 @@ function test_maybe_set_linked_post_with_mydata_already_set() { Functions\expect( 'filter_input' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_LANG, FILTER_SANITIZE_FULL_SPECIAL_CHARS )->andReturn( 'de_DE' ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new MslsOptionsPost(); + $mydata = new OptionsPost(); $mydata->de_DE = 42; $mydata = $test->maybe_set_linked_post( $mydata ); diff --git a/tests/phpunit/TestMslsOutput.php b/tests/phpunit/TestMslsOutput.php index 280f5f7dc..dd52dc119 100644 --- a/tests/phpunit/TestMslsOutput.php +++ b/tests/phpunit/TestMslsOutput.php @@ -6,14 +6,14 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; -use lloc\Msls\MslsOptionsPost; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsOutput; final class TestMslsOutput extends MslsUnitTestCase { private function MslsOutputFactory(): MslsOutput { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'has_current_blog' )->andReturn( true ); @@ -160,7 +160,7 @@ public function test___toString_output(): void { $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -195,7 +195,7 @@ public function test___toString_current_blog(): void { $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -226,7 +226,7 @@ public function test___toString_filter(): void { $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -258,7 +258,7 @@ public function test_get_not_fulfilled(): void { $blog = \Mockery::mock( MslsBlog::class ); $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -307,7 +307,7 @@ public function test_is_requirements_not_fulfilled_with_null(): void { public function test_is_requirements_not_fulfilled_with_mslsoptions(): void { Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new MslsOptions(); + $mydata = new Options(); $test = $this->MslsOutputFactory(); @@ -318,7 +318,7 @@ public function test_is_requirements_not_fulfilled_with_mslsoptions(): void { public function test_is_requirements_not_fulfilled_with_mslsoptionspost(): void { Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new MslsOptionsPost(); + $mydata = new OptionsPost(); $test = $this->MslsOutputFactory(); @@ -364,7 +364,7 @@ public function test_get_skips_empty_url(): void { $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); $blog->userblog_id = 2; - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -390,7 +390,7 @@ public function test_get_skips_empty_url(): void { public function test_init(): void { Functions\expect( '_deprecated_function' )->once(); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); diff --git a/tests/phpunit/TestMslsPlugin.php b/tests/phpunit/TestMslsPlugin.php index 9534af9cb..fc68db789 100644 --- a/tests/phpunit/TestMslsPlugin.php +++ b/tests/phpunit/TestMslsPlugin.php @@ -4,7 +4,7 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsOutput; use lloc\Msls\MslsPlugin; @@ -15,7 +15,7 @@ function test_admin_menu_without_autocomplete(): void { Functions\expect( 'wp_enqueue_style' )->twice(); Functions\expect( 'plugins_url' )->twice()->andReturn( 'https://msls.co/wp-content/plugins' ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $test = new MslsPlugin( $options ); @@ -29,7 +29,7 @@ function test_admin_menu_with_autocomplete(): void { Functions\expect( 'plugins_url' )->times( 3 )->andReturn( 'https://msls.co/wp-content/plugins' ); Functions\expect( 'wp_enqueue_script' )->once(); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_autocomplete = true; @@ -45,7 +45,7 @@ function test_admin_menu_with_quick_create(): void { Functions\expect( 'plugins_url' )->times( 3 )->andReturn( 'https://msls.co/wp-content/plugins' ); Functions\expect( 'wp_enqueue_script' )->once(); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_quick_create = true; @@ -58,7 +58,7 @@ function test_admin_menu_with_quick_create(): void { function test_admin_menu_admin_bar_not_showing(): void { Functions\expect( 'is_admin_bar_showing' )->once()->andReturnFalse(); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_autocomplete = true; @@ -100,7 +100,7 @@ function test_uninstall(): void { Functions\expect( 'wp_cache_get' )->once()->andReturn( $blogs ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); Functions\expect( 'switch_to_blog' )->times( count( $blogs ) ); @@ -150,7 +150,7 @@ public function test_print_alternate_links(): void { Functions\expect( 'is_front_page' )->once()->andReturn( true ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get_objects' )->twice()->andReturn( array() ); diff --git a/tests/phpunit/TestMslsPostTag.php b/tests/phpunit/TestMslsPostTag.php index 8b677d3f4..e56f398d3 100644 --- a/tests/phpunit/TestMslsPostTag.php +++ b/tests/phpunit/TestMslsPostTag.php @@ -8,8 +8,8 @@ use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; -use lloc\Msls\MslsOptions; -use lloc\Msls\MslsOptionsTax; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\OptionsTax; use lloc\Msls\MslsPostTag; use lloc\Msls\MslsTaxonomy; @@ -27,7 +27,7 @@ private function MslsPostTagFacory(): MslsPostTag { $blogs[] = $blog; } - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'label' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -44,7 +44,7 @@ function ( $language ) { } public function test_init(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->activate_autocomplete = true; $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -211,7 +211,7 @@ public function test_add_input(): void { } public function test_the_input_no_blogs(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); @@ -234,7 +234,7 @@ public function test_set() { } public function test_maybe_set_linked_term_origin_lang(): void { - $mydata = \Mockery::mock( MslsOptionsTax::class ); + $mydata = \Mockery::mock( OptionsTax::class ); $mydata->de_DE = 42; Functions\expect( 'filter_has_var' )->twice()->andReturnTrue(); @@ -247,7 +247,7 @@ public function test_maybe_set_linked_term_origin_lang(): void { } public function test_maybe_set_linked_term_blog_id_null(): void { - $mydata = \Mockery::mock( MslsOptionsTax::class ); + $mydata = \Mockery::mock( OptionsTax::class ); $mydata->de_DE = 42; Functions\expect( 'filter_has_var' )->twice()->andReturnTrue(); @@ -260,7 +260,7 @@ public function test_maybe_set_linked_term_blog_id_null(): void { } public function test_maybe_set_linked_term_origin_term_wrong(): void { - $mydata = \Mockery::mock( MslsOptionsTax::class ); + $mydata = \Mockery::mock( OptionsTax::class ); $mydata->shouldReceive( 'get_base_option' )->andReturn( 'term' ); $mydata->en_US = 42; @@ -277,7 +277,7 @@ public function test_maybe_set_linked_term_origin_term_wrong(): void { } public function test_maybe_set_linked_term_happy_path(): void { - $mydata = \Mockery::mock( MslsOptionsTax::class ); + $mydata = \Mockery::mock( OptionsTax::class ); $mydata->shouldReceive( 'get_base_option' )->andReturn( 'term' ); $mydata->en_US = 42; diff --git a/tests/phpunit/TestMslsPostTagClassic.php b/tests/phpunit/TestMslsPostTagClassic.php index b8719742f..4bc056428 100644 --- a/tests/phpunit/TestMslsPostTagClassic.php +++ b/tests/phpunit/TestMslsPostTagClassic.php @@ -6,7 +6,7 @@ use Brain\Monkey\Actions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsPostTagClassic; final class TestMslsPostTagClassic extends MslsUnitTestCase { @@ -28,7 +28,7 @@ private function MslsPostTagClassicFactory(): MslsPostTagClassic { $blogs[] = $blog; } - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'label' ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -161,7 +161,7 @@ public function test_add_input(): void { } public function test_the_input_no_blogs(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); diff --git a/tests/phpunit/TestMslsShortCode.php b/tests/phpunit/TestMslsShortCode.php index f3e441b77..295bb16cc 100644 --- a/tests/phpunit/TestMslsShortCode.php +++ b/tests/phpunit/TestMslsShortCode.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests; use Brain\Monkey\Functions; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsShortCode; final class TestMslsShortCode extends MslsUnitTestCase { @@ -17,7 +17,7 @@ public function test_init(): void { } public function test_block_render_excluded_true(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( true ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); @@ -27,7 +27,7 @@ public function test_block_render_excluded_true(): void { public function test_block_render_excluded_false(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); diff --git a/tests/phpunit/TestMslsTaxonomy.php b/tests/phpunit/TestMslsTaxonomy.php index cad65149f..2e43e3b39 100644 --- a/tests/phpunit/TestMslsTaxonomy.php +++ b/tests/phpunit/TestMslsTaxonomy.php @@ -4,13 +4,13 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsFields; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsTaxonomy; final class TestMslsTaxonomy extends MslsUnitTestCase { private function MslsTaxonomyFactory( bool $exluded = false ): MslsTaxonomy { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( $exluded ); Functions\expect( 'msls_options' )->zeroOrMoreTimes()->andReturn( $options ); diff --git a/tests/phpunit/TestMslsWidget.php b/tests/phpunit/TestMslsWidget.php index bd271e58c..1644ec3ac 100644 --- a/tests/phpunit/TestMslsWidget.php +++ b/tests/phpunit/TestMslsWidget.php @@ -4,14 +4,14 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\MslsOptions; +use lloc\Msls\Options\Options; use lloc\Msls\MslsOutput; use lloc\Msls\MslsWidget; final class TestMslsWidget extends MslsUnitTestCase { public function test_init(): void { - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->once()->andReturn( false ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); @@ -35,7 +35,7 @@ public function test_widget(): void { $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array() ); - $options = \Mockery::mock( MslsOptions::class ); + $options = \Mockery::mock( Options::class ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); From 9eb157a4ee70d5095e2a90d767952912095ada2a Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 18:29:10 +0200 Subject: [PATCH 08/13] aliases added --- includes/aliases.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 includes/aliases.php diff --git a/includes/aliases.php b/includes/aliases.php new file mode 100644 index 000000000..f9fff9089 --- /dev/null +++ b/includes/aliases.php @@ -0,0 +1,38 @@ + Date: Thu, 14 May 2026 08:07:01 +0200 Subject: [PATCH 09/13] Fix issue found during PR --- includes/Options/Options.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Options/Options.php b/includes/Options/Options.php index 0b5566bd8..0f6d09523 100644 --- a/includes/Options/Options.php +++ b/includes/Options/Options.php @@ -110,7 +110,9 @@ public static function create( $id = 0 ) { $options = new OptionsPost( get_queried_object_id() ); } - add_filter( self::MSLS_GET_POSTLINK_HOOK, array( self::class, 'check_for_blog_slug' ), 10, 2 ); + if ( ! has_filter( self::MSLS_GET_POSTLINK_HOOK, array( self::class, 'check_for_blog_slug' ) ) ) { + add_filter( self::MSLS_GET_POSTLINK_HOOK, array( self::class, 'check_for_blog_slug' ), 10, 2 ); + } return $options; } From c9d951ac101b5ed470a80869d7e02d7aa931098b Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Thu, 14 May 2026 11:06:21 +0200 Subject: [PATCH 10/13] Restructuring MslsOptions* --- MultisiteLanguageSwitcher.php | 15 +++---- includes/ContentImport/ContentImporter.php | 4 +- .../Importers/Terms/ShallowDuplicating.php | 4 +- includes/ContentImport/MetaBox.php | 6 +-- includes/MslsCustomColumnTaxonomy.php | 4 +- includes/MslsMain.php | 4 +- includes/MslsMetaBox.php | 15 ++++--- includes/MslsPostTag.php | 6 +-- includes/MslsPostTagClassic.php | 4 +- includes/MslsRestApi.php | 12 +++--- includes/Options/Options.php | 13 +++--- .../{OptionsPost.php => Post/Post.php} | 6 ++- .../Author.php} | 4 +- .../{OptionsQueryDay.php => Query/Day.php} | 4 +- .../Month.php} | 4 +- .../PostType.php} | 4 +- .../{OptionsQuery.php => Query/Query.php} | 19 +++++---- .../{OptionsQueryYear.php => Query/Year.php} | 4 +- .../Category.php} | 4 +- .../Options/{OptionsTax.php => Tax/Tax.php} | 11 ++--- .../{OptionsTaxTerm.php => Tax/Term.php} | 9 ++-- includes/aliases.php | 40 +++++++++--------- .../TestPost.php} | 16 ++++---- .../TestAuthor.php} | 15 +++---- .../TestDay.php} | 15 +++---- .../TestMonth.php} | 15 +++---- .../{ => Query}/TestOptionsQueryYear.php | 13 +++--- .../TestPostType.php} | 15 +++---- .../TestQuery.php} | 41 ++++++++++--------- .../TestCategory.php} | 11 ++--- .../{TestOptionsTax.php => Tax/TestTax.php} | 23 ++++++----- .../TestTerm.php} | 19 +++++---- tests/phpunit/TestMslsMetaBox.php | 15 ++++--- tests/phpunit/TestMslsOutput.php | 6 +-- tests/phpunit/TestMslsPostTag.php | 14 +++---- 35 files changed, 216 insertions(+), 198 deletions(-) rename includes/Options/{OptionsPost.php => Post/Post.php} (92%) rename includes/Options/{OptionsQueryAuthor.php => Query/Author.php} (93%) rename includes/Options/{OptionsQueryDay.php => Query/Day.php} (94%) rename includes/Options/{OptionsQueryMonth.php => Query/Month.php} (94%) rename includes/Options/{OptionsQueryPostType.php => Query/PostType.php} (92%) rename includes/Options/{OptionsQuery.php => Query/Query.php} (81%) rename includes/Options/{OptionsQueryYear.php => Query/Year.php} (94%) rename includes/Options/{OptionsTaxTermCategory.php => Tax/Category.php} (72%) rename includes/Options/{OptionsTax.php => Tax/Tax.php} (92%) rename includes/Options/{OptionsTaxTerm.php => Tax/Term.php} (90%) rename tests/phpunit/Options/{TestOptionsPost.php => Post/TestPost.php} (88%) rename tests/phpunit/Options/{TestOptionsQueryAuthor.php => Query/TestAuthor.php} (79%) rename tests/phpunit/Options/{TestOptionsQueryDay.php => Query/TestDay.php} (84%) rename tests/phpunit/Options/{TestOptionsQueryMonth.php => Query/TestMonth.php} (83%) rename tests/phpunit/Options/{ => Query}/TestOptionsQueryYear.php (84%) rename tests/phpunit/Options/{TestOptionsQueryPostType.php => Query/TestPostType.php} (84%) rename tests/phpunit/Options/{TestOptionsQuery.php => Query/TestQuery.php} (74%) rename tests/phpunit/Options/{TestOptionsTaxTermCategory.php => Tax/TestCategory.php} (58%) rename tests/phpunit/Options/{TestOptionsTax.php => Tax/TestTax.php} (90%) rename tests/phpunit/Options/{TestOptionsTaxTerm.php => Tax/TestTerm.php} (85%) diff --git a/MultisiteLanguageSwitcher.php b/MultisiteLanguageSwitcher.php index 6eaa368db..355d8a1a3 100644 --- a/MultisiteLanguageSwitcher.php +++ b/MultisiteLanguageSwitcher.php @@ -200,10 +200,11 @@ function msls_output(): \lloc\Msls\MslsOutput { * Retrieves the OptionsPost instance. * * @param int $id - * @return \lloc\Msls\Options\OptionsPost + * + * @return \lloc\Msls\Options\Post\Post */ - function msls_get_post( int $id ): \lloc\Msls\Options\OptionsPost { - return new \lloc\Msls\Options\OptionsPost( $id ); + function msls_get_post( int $id ): \lloc\Msls\Options\Post\Post { + return new \lloc\Msls\Options\Post\Post( $id ); } /** @@ -218,7 +219,7 @@ function msls_get_post( int $id ): \lloc\Msls\Options\OptionsPost { * @return \lloc\Msls\OptionsTaxInterface */ function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface { - return \lloc\Msls\Options\OptionsTax::create( $id ); + return \lloc\Msls\Options\Tax\Tax::create( $id ); } /** @@ -231,10 +232,10 @@ function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface { * - is_author * - is_post_type_archive * - * @return ?\lloc\Msls\Options\OptionsQuery + * @return ?\lloc\Msls\Options\Query\Query */ - function msls_get_query(): ?\lloc\Msls\Options\OptionsQuery { - return \lloc\Msls\Options\OptionsQuery::create(); + function msls_get_query(): ?\lloc\Msls\Options\Query\Query { + return \lloc\Msls\Options\Query\Query::create(); } /** diff --git a/includes/ContentImport/ContentImporter.php b/includes/ContentImport/ContentImporter.php index 71d430e19..d44a3fa4e 100644 --- a/includes/ContentImport/ContentImporter.php +++ b/includes/ContentImport/ContentImporter.php @@ -11,9 +11,9 @@ use lloc\Msls\ContentImport\Importers\WithRequestPostAttributes; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsMain; -use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsRegistryInstance; use lloc\Msls\MslsRequest; +use lloc\Msls\Options\Post\Post; /** * Class ContentImporter @@ -333,7 +333,7 @@ public function import_content( ImportCoordinates $import_coordinates, array $po $source_post_id = $import_coordinates->source_post_id; $dest_lang = $import_coordinates->dest_lang; $dest_post_id = $import_coordinates->dest_post_id; - $relations->should_create( OptionsPost::create( $source_post_id ), $dest_lang, $dest_post_id ); + $relations->should_create( Post::create( $source_post_id ), $dest_lang, $dest_post_id ); foreach ( $importers as $key => $importer ) { if ( ! $importer instanceof Importer ) { diff --git a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php index f705da575..ec297b2b0 100644 --- a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php +++ b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php @@ -4,7 +4,7 @@ use lloc\Msls\ContentImport\ImportCoordinates; use lloc\Msls\ContentImport\Importers\BaseImporter; -use lloc\Msls\Options\OptionsTaxTerm; +use lloc\Msls\Options\Tax\Term; use lloc\Msls\OptionsTaxInterface; /** @@ -62,7 +62,7 @@ public function import( array $data ) { $source_terms_ids = wp_list_pluck( $source_terms, 'term_id' ); $msls_terms = array_combine( $source_terms_ids, - array_map( array( OptionsTaxTerm::class, 'create' ), $source_terms_ids ) + array_map( array( Term::class, 'create' ), $source_terms_ids ) ); switch_to_blog( $this->import_coordinates->dest_blog_id ); diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index 5fcac23f5..044b6f83b 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -7,10 +7,10 @@ use lloc\Msls\ContentImport\Importers\Map; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; -use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsPlugin; use lloc\Msls\MslsRegistryInstance; use lloc\Msls\MslsRequest; +use lloc\Msls\Options\Post\Post; class MetaBox extends MslsRegistryInstance { @@ -28,8 +28,8 @@ public function render(): void { return; } - $mydata = new OptionsPost( $post->ID ); - $languages = OptionsPost::instance()->get_available_languages(); + $mydata = new Post( $post->ID ); + $languages = Post::instance()->get_available_languages(); $current = MslsBlogCollection::get_blog_language( get_current_blog_id() ); $languages = array_diff_key( $languages, array( $current => $current ) ); $input_lang = MslsRequest::get( MslsFields::FIELD_MSLS_LANG, null ); diff --git a/includes/MslsCustomColumnTaxonomy.php b/includes/MslsCustomColumnTaxonomy.php index 5171acfb2..0b1b674fa 100644 --- a/includes/MslsCustomColumnTaxonomy.php +++ b/includes/MslsCustomColumnTaxonomy.php @@ -6,7 +6,7 @@ exit; } -use lloc\Msls\Options\OptionsTax; +use lloc\Msls\Options\Tax\Tax; /** * Handling of existing/not existing translations in the backend @@ -45,6 +45,6 @@ public function column_default( $deprecated, $column_name, $item_id ): void { * @param int $object_id */ public function delete( $object_id ): void { - $this->save( $object_id, OptionsTax::class ); + $this->save( $object_id, Tax::class ); } } diff --git a/includes/MslsMain.php b/includes/MslsMain.php index 51906d43a..7de12e335 100644 --- a/includes/MslsMain.php +++ b/includes/MslsMain.php @@ -4,7 +4,7 @@ use lloc\Msls\Component\Component; use lloc\Msls\Options\Options; -use lloc\Msls\Options\OptionsPost; +use lloc\Msls\Options\Post\Post; /** * Abstraction for the hook classes @@ -121,7 +121,7 @@ public function verify_nonce(): bool { * @codeCoverageIgnore */ public function delete( $object_id ): void { - $this->save( $object_id, OptionsPost::class ); + $this->save( $object_id, Post::class ); } /** diff --git a/includes/MslsMetaBox.php b/includes/MslsMetaBox.php index 9bda2b65d..03d2b4712 100644 --- a/includes/MslsMetaBox.php +++ b/includes/MslsMetaBox.php @@ -9,8 +9,7 @@ use lloc\Msls\Component\Component; use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\MetaBox as ContentImportMetaBox; -use lloc\Msls\Options\OptionsPost; -use WP_Post; +use lloc\Msls\Options\Post\Post; use WP_Post_Type; /** @@ -192,7 +191,7 @@ public function render_select(): void { return; } - $mydata = new OptionsPost( $post->ID ); + $mydata = new Post( $post->ID ); $origin_language = MslsBlogCollection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); @@ -336,7 +335,7 @@ public function render_input(): void { return; } - $my_data = new OptionsPost( $post->ID ); + $my_data = new Post( $post->ID ); $origin_language = MslsBlogCollection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); @@ -487,17 +486,17 @@ public function set( $post_id ): void { return; } - $this->save( $post_id, OptionsPost::class ); + $this->save( $post_id, Post::class ); } /** * Sets the selected element in the data from the `$_GET` superglobal, if any. * - * @param OptionsPost $mydata + * @param Post $mydata * - * @return OptionsPost + * @return Post */ - public function maybe_set_linked_post( OptionsPost $mydata ) { + public function maybe_set_linked_post( Post $mydata ) { if ( ! MslsRequest::isset( array( MslsFields::FIELD_MSLS_ID, MslsFields::FIELD_MSLS_LANG ) ) ) { return $mydata; } diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php index 804dd661f..f9ff10a10 100644 --- a/includes/MslsPostTag.php +++ b/includes/MslsPostTag.php @@ -7,7 +7,7 @@ } use lloc\Msls\Component\Component; -use lloc\Msls\Options\OptionsTax; +use lloc\Msls\Options\Tax\Tax; use WP_Term; /** @@ -191,7 +191,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo $blogs = $this->collection->get(); if ( $blogs ) { $term_id = $tag->term_id ?? 0; - $mydata = OptionsTax::create( $term_id ); + $mydata = Tax::create( $term_id ); $type = msls_content_types()->get_request(); $this->maybe_set_linked_term( $mydata ); @@ -248,7 +248,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo */ public function set( $term_id ): void { if ( msls_content_types()->acl_request() ) { - $this->save( $term_id, OptionsTax::class ); + $this->save( $term_id, Tax::class ); } } diff --git a/includes/MslsPostTagClassic.php b/includes/MslsPostTagClassic.php index 95f9d2e58..56b0dcc00 100644 --- a/includes/MslsPostTagClassic.php +++ b/includes/MslsPostTagClassic.php @@ -3,7 +3,7 @@ namespace lloc\Msls; use lloc\Msls\Component\Component; -use lloc\Msls\Options\OptionsTax; +use lloc\Msls\Options\Tax\Tax; /** * Post Tag Classic @@ -86,7 +86,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo $blogs = $this->collection->get(); if ( ! empty( $blogs ) ) { $term_id = $tag->term_id ?? 0; - $mydata = OptionsTax::create( $term_id ); + $mydata = Tax::create( $term_id ); $type = msls_content_types()->get_request(); $this->maybe_set_linked_term( $mydata ); diff --git a/includes/MslsRestApi.php b/includes/MslsRestApi.php index a9676ee01..77da4f1f6 100644 --- a/includes/MslsRestApi.php +++ b/includes/MslsRestApi.php @@ -2,8 +2,8 @@ namespace lloc\Msls; -use lloc\Msls\Options\OptionsPost; -use lloc\Msls\Options\OptionsTax; +use lloc\Msls\Options\Post\Post; +use lloc\Msls\Options\Tax\Tax; use lloc\Msls\Query\TranslatedPostIdQuery; if ( ! defined( 'ABSPATH' ) ) { @@ -520,8 +520,8 @@ protected function prepare_taxonomies( $mapped_terms = array(); foreach ( $terms as $term_id ) { - /** @var OptionsTax $term_options */ - $term_options = OptionsTax::create( $term_id ); + /** @var Tax $term_options */ + $term_options = Tax::create( $term_id ); if ( $term_options->has_value( $target_lang ) ) { $mapped_terms[] = (int) $term_options->$target_lang; @@ -590,7 +590,7 @@ protected function establish_link( // Read existing links from the source post switch_to_blog( $source_blog_id ); - $source_options = new OptionsPost( $source_post_id ); + $source_options = new Post( $source_post_id ); $existing_links = $source_options->get_arr(); restore_current_blog(); @@ -613,7 +613,7 @@ protected function establish_link( switch_to_blog( $blog_id ); - $options = new OptionsPost( $post_id ); + $options = new Post( $post_id ); $save_data = $link_map; unset( $save_data[ $lang ] ); diff --git a/includes/Options/Options.php b/includes/Options/Options.php index 0f6d09523..1b371a689 100644 --- a/includes/Options/Options.php +++ b/includes/Options/Options.php @@ -10,6 +10,9 @@ use lloc\Msls\MslsAdminIcon; use lloc\Msls\MslsGetSet; use lloc\Msls\MslsPlugin; +use lloc\Msls\Options\Post\Post; +use lloc\Msls\Options\Query\Query; +use lloc\Msls\Options\Tax\Tax; use lloc\Msls\OptionsInterface; /** @@ -94,20 +97,20 @@ public static function create( $id = 0 ) { $id = (int) $id; if ( msls_content_types()->is_taxonomy() ) { - return OptionsTax::create( $id ); + return Tax::create( $id ); } - return new OptionsPost( $id ); + return new Post( $id ); } if ( self::is_main_page() ) { $options = new Options(); } elseif ( self::is_tax_page() ) { - $options = OptionsTax::create(); + $options = Tax::create(); } elseif ( self::is_query_page() ) { - $options = OptionsQuery::create() ?? new Options(); + $options = Query::create() ?? new Options(); } else { - $options = new OptionsPost( get_queried_object_id() ); + $options = new Post( get_queried_object_id() ); } if ( ! has_filter( self::MSLS_GET_POSTLINK_HOOK, array( self::class, 'check_for_blog_slug' ) ) ) { diff --git a/includes/Options/OptionsPost.php b/includes/Options/Post/Post.php similarity index 92% rename from includes/Options/OptionsPost.php rename to includes/Options/Post/Post.php index f1c6aa639..1bb708fe5 100644 --- a/includes/Options/OptionsPost.php +++ b/includes/Options/Post/Post.php @@ -1,13 +1,15 @@ handle_rewrite(); diff --git a/includes/Options/OptionsTaxTerm.php b/includes/Options/Tax/Term.php similarity index 90% rename from includes/Options/OptionsTaxTerm.php rename to includes/Options/Tax/Term.php index 1a2daaf68..63011da14 100644 --- a/includes/Options/OptionsTaxTerm.php +++ b/includes/Options/Tax/Term.php @@ -1,11 +1,12 @@ once()->andReturn( array( 'de_DE' => 42 ) ); - return new OptionsPost( 42 ); + return new Post( 42 ); } public function test_get_postlink_not_has_value(): void { diff --git a/tests/phpunit/Options/TestOptionsQueryAuthor.php b/tests/phpunit/Options/Query/TestAuthor.php similarity index 79% rename from tests/phpunit/Options/TestOptionsQueryAuthor.php rename to tests/phpunit/Options/Query/TestAuthor.php index 5a8bc9e2d..b883a9a28 100644 --- a/tests/phpunit/Options/TestOptionsQueryAuthor.php +++ b/tests/phpunit/Options/Query/TestAuthor.php @@ -1,16 +1,17 @@ once()->andReturn( array() ); Functions\expect( 'get_queried_object_id' )->once()->andReturn( $author_id ); @@ -18,7 +19,7 @@ private function OptionsQueryAuthorFactory( int $author_id ): OptionsQueryAuthor $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new OptionsQueryAuthor( $sql_cacher ); + return new Author( $sql_cacher ); } public function test_has_value_true(): void { diff --git a/tests/phpunit/Options/TestOptionsQueryDay.php b/tests/phpunit/Options/Query/TestDay.php similarity index 84% rename from tests/phpunit/Options/TestOptionsQueryDay.php rename to tests/phpunit/Options/Query/TestDay.php index 24b1f5b58..a48d1b190 100644 --- a/tests/phpunit/Options/TestOptionsQueryDay.php +++ b/tests/phpunit/Options/Query/TestDay.php @@ -1,16 +1,17 @@ once()->andReturn( array() ); @@ -20,7 +21,7 @@ private function OptionsQueryDayFactory( int $year, int $monthnum, int $day ): O $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new OptionsQueryDay( $sql_cacher ); + return new Day( $sql_cacher ); } public function test_has_value_true(): void { diff --git a/tests/phpunit/Options/TestOptionsQueryMonth.php b/tests/phpunit/Options/Query/TestMonth.php similarity index 83% rename from tests/phpunit/Options/TestOptionsQueryMonth.php rename to tests/phpunit/Options/Query/TestMonth.php index ec36547db..4c2b461e7 100644 --- a/tests/phpunit/Options/TestOptionsQueryMonth.php +++ b/tests/phpunit/Options/Query/TestMonth.php @@ -1,16 +1,17 @@ once()->andReturn( array() ); Functions\expect( 'get_query_var' )->times( 2 )->andReturn( $year, $monthnum ); @@ -18,7 +19,7 @@ private function OptionsQueryMonthFactory( int $year, int $monthnum ): OptionsQu $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new OptionsQueryMonth( $sql_cacher ); + return new Month( $sql_cacher ); } public function test_has_value_true(): void { diff --git a/tests/phpunit/Options/TestOptionsQueryYear.php b/tests/phpunit/Options/Query/TestOptionsQueryYear.php similarity index 84% rename from tests/phpunit/Options/TestOptionsQueryYear.php rename to tests/phpunit/Options/Query/TestOptionsQueryYear.php index 08f61695a..5f59c7cc5 100644 --- a/tests/phpunit/Options/TestOptionsQueryYear.php +++ b/tests/phpunit/Options/Query/TestOptionsQueryYear.php @@ -1,16 +1,17 @@ once()->andReturn( array() ); Functions\expect( 'get_query_var' )->once()->andReturn( $year ); @@ -18,7 +19,7 @@ private function OptionsQueryYearFactory( int $year ): OptionsQueryYear { $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); - return new OptionsQueryYear( $sql_cacher ); + return new Year( $sql_cacher ); } public function test_has_value_true(): void { diff --git a/tests/phpunit/Options/TestOptionsQueryPostType.php b/tests/phpunit/Options/Query/TestPostType.php similarity index 84% rename from tests/phpunit/Options/TestOptionsQueryPostType.php rename to tests/phpunit/Options/Query/TestPostType.php index 763fc11e0..f76fc2f23 100644 --- a/tests/phpunit/Options/TestOptionsQueryPostType.php +++ b/tests/phpunit/Options/Query/TestPostType.php @@ -1,16 +1,17 @@ once()->andReturn( array() ); Functions\expect( 'get_query_var' )->once()->andReturn( 'queried-posttype' ); @@ -18,7 +19,7 @@ private function OptionsQueryPostTypeFactory(): OptionsQueryPostType { $sql_cacher->shouldReceive( 'prepare' )->never(); $sql_cacher->shouldReceive( 'get_var' )->never(); - return new OptionsQueryPostType( $sql_cacher ); + return new PostType( $sql_cacher ); } public function test_has_value_existing(): void { diff --git a/tests/phpunit/Options/TestOptionsQuery.php b/tests/phpunit/Options/Query/TestQuery.php similarity index 74% rename from tests/phpunit/Options/TestOptionsQuery.php rename to tests/phpunit/Options/Query/TestQuery.php index 896f3bf4e..9407683e9 100644 --- a/tests/phpunit/Options/TestOptionsQuery.php +++ b/tests/phpunit/Options/Query/TestQuery.php @@ -1,19 +1,20 @@ assertEquals( array(), OptionsQuery::get_params() ); + $this->assertEquals( array(), Query::get_params() ); } public function test_create_is_day(): void { @@ -32,7 +33,7 @@ public function test_create_is_day(): void { Functions\expect( 'get_query_var' )->times( 6 )->andReturnValues( array( 1969, 6, 26 ) ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( OptionsQueryDay::class, OptionsQuery::create() ); + $this->assertInstanceOf( Day::class, Query::create() ); } public function test_create_is_month(): void { Functions\expect( 'is_day' )->once()->andReturn( false ); @@ -40,7 +41,7 @@ public function test_create_is_month(): void { Functions\expect( 'get_query_var' )->times( 4 )->andReturnValues( array( 1969, 6 ) ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( OptionsQueryMonth::class, OptionsQuery::create() ); + $this->assertInstanceOf( Month::class, Query::create() ); } public function test_create_is_year(): void { @@ -50,7 +51,7 @@ public function test_create_is_year(): void { Functions\expect( 'get_query_var' )->times( 2 )->andReturn( 1969 ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( OptionsQueryYear::class, OptionsQuery::create() ); + $this->assertInstanceOf( Year::class, Query::create() ); } public function test_create_is_author(): void { @@ -61,7 +62,7 @@ public function test_create_is_author(): void { Functions\expect( 'get_queried_object_id' )->times( 2 )->andReturn( 42 ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( OptionsQueryAuthor::class, OptionsQuery::create() ); + $this->assertInstanceOf( Author::class, Query::create() ); } public function test_create_is_post_type_archive(): void { @@ -73,7 +74,7 @@ public function test_create_is_post_type_archive(): void { Functions\expect( 'get_query_var' )->times( 2 )->andReturn( 'book' ); Functions\expect( 'get_option' )->once(); - $this->assertInstanceOf( OptionsQueryPostType::class, OptionsQuery::create() ); + $this->assertInstanceOf( PostType::class, Query::create() ); } public function test_create_is_null(): void { @@ -83,7 +84,7 @@ public function test_create_is_null(): void { Functions\expect( 'is_author' )->once()->andReturn( false ); Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); - $this->assertNull( OptionsQuery::create() ); + $this->assertNull( Query::create() ); } public function test_current_get_postlink(): void { @@ -94,7 +95,7 @@ public function test_current_get_postlink(): void { $sql_cache = \Mockery::mock( MslsSqlCacher::class ); - $this->assertEquals( $home_url, ( new OptionsQuery( $sql_cache ) )->get_postlink( 'de_DE' ) ); + $this->assertEquals( $home_url, ( new Query( $sql_cache ) )->get_postlink( 'de_DE' ) ); } public function test_non_existent_get_postlink(): void { @@ -102,7 +103,7 @@ public function test_non_existent_get_postlink(): void { $sql_cache = \Mockery::mock( MslsSqlCacher::class ); - $this->assertEquals( '', ( new OptionsQuery( $sql_cache ) )->get_postlink( 'fr_FR' ) ); + $this->assertEquals( '', ( new Query( $sql_cache ) )->get_postlink( 'fr_FR' ) ); } public function test_get_permalink_returns_empty_when_no_translation(): void { @@ -110,6 +111,6 @@ public function test_get_permalink_returns_empty_when_no_translation(): void { $sql_cache = \Mockery::mock( MslsSqlCacher::class ); - $this->assertSame( '', ( new OptionsQuery( $sql_cache ) )->get_permalink( 'fr_FR' ) ); + $this->assertSame( '', ( new Query( $sql_cache ) )->get_permalink( 'fr_FR' ) ); } } diff --git a/tests/phpunit/Options/TestOptionsTaxTermCategory.php b/tests/phpunit/Options/Tax/TestCategory.php similarity index 58% rename from tests/phpunit/Options/TestOptionsTaxTermCategory.php rename to tests/phpunit/Options/Tax/TestCategory.php index 07767962a..2a33dc960 100644 --- a/tests/phpunit/Options/TestOptionsTaxTermCategory.php +++ b/tests/phpunit/Options/Tax/TestCategory.php @@ -1,18 +1,19 @@ once()->andReturn( array() ); - $obj = new OptionsTaxTermCategory( 0 ); + $obj = new Category( 0 ); $this->assertIsSTring( $obj->get_postlink( '' ) ); } diff --git a/tests/phpunit/Options/TestOptionsTax.php b/tests/phpunit/Options/Tax/TestTax.php similarity index 90% rename from tests/phpunit/Options/TestOptionsTax.php rename to tests/phpunit/Options/Tax/TestTax.php index 53a284b5c..4774fb60c 100644 --- a/tests/phpunit/Options/TestOptionsTax.php +++ b/tests/phpunit/Options/Tax/TestTax.php @@ -1,20 +1,21 @@ atLeast()->once()->andReturn( array( 'de_DE' => 42 ) ); - return new OptionsTax(); + return new Tax(); } public function test_create_category(): void { @@ -23,7 +24,7 @@ public function test_create_category(): void { Functions\expect( 'is_category' )->once()->with( 42 )->andReturnTrue(); Functions\expect( 'get_option' )->atLeast()->once()->andReturn( array( 'de_DE' => 42 ) ); - $this->assertInstanceOf( OptionsTaxTermCategory::class, OptionsTax::create() ); + $this->assertInstanceOf( Category::class, Tax::create() ); } public function test_create_post_tag(): void { @@ -33,7 +34,7 @@ public function test_create_post_tag(): void { Functions\expect( 'is_tag' )->once()->andReturnTrue(); Functions\expect( 'get_option' )->atLeast()->once()->andReturn( array( 'de_DE' => 42 ) ); - $this->assertInstanceOf( OptionsTaxTerm::class, OptionsTax::create() ); + $this->assertInstanceOf( Term::class, Tax::create() ); } public function test_get_tax_query(): void { @@ -180,6 +181,6 @@ public function test_get_permalink_returns_url_when_term_link_succeeds(): void { } public function test_get_base_option() { - $this->assertEquals( '', OptionsTax::get_base_option() ); + $this->assertEquals( '', Tax::get_base_option() ); } } diff --git a/tests/phpunit/Options/TestOptionsTaxTerm.php b/tests/phpunit/Options/Tax/TestTerm.php similarity index 85% rename from tests/phpunit/Options/TestOptionsTaxTerm.php rename to tests/phpunit/Options/Tax/TestTerm.php index d71fdd41a..f1c57c30e 100644 --- a/tests/phpunit/Options/TestOptionsTaxTerm.php +++ b/tests/phpunit/Options/Tax/TestTerm.php @@ -1,15 +1,16 @@ times( $get_option_exec_times )->andReturnUsing( function ( $value ) { if ( 'msls_term_42' === $value ) { @@ -24,7 +25,7 @@ function ( $value ) { } ); - return new OptionsTaxTerm( 42 ); + return new Term( 42 ); } public function test_get_postlink_empty(): void { @@ -34,7 +35,7 @@ public function test_get_postlink_empty(): void { } public function test_check_url_empty(): void { - $options = \Mockery::mock( OptionsTaxTerm::class ); + $options = \Mockery::mock( Term::class ); $test = $this->OptionsTaxTermFactory( 1 ); @@ -49,7 +50,7 @@ public function test_check_url(): void { $wp_rewrite = \Mockery::mock( 'WP_Rewrite' ); $wp_rewrite->shouldReceive( 'get_extra_permastruct' )->andReturn( '/schlagwort/' ); - $options = \Mockery::mock( OptionsTaxTerm::class ); + $options = \Mockery::mock( Term::class ); $options->shouldReceive( 'get_tax_query' )->andReturn( '' ); $expected = 'https://example.de/tag/keyword'; @@ -65,7 +66,7 @@ public function test_check_url_permastruct_false(): void { $wp_rewrite = \Mockery::mock( 'WP_Rewrite' ); $wp_rewrite->shouldReceive( 'get_extra_permastruct' )->andReturn( false ); - $options = \Mockery::mock( OptionsTaxTerm::class ); + $options = \Mockery::mock( Term::class ); $options->shouldReceive( 'get_tax_query' )->andReturn( '' ); $expected = 'https://example.de/schlagwort/keyword'; diff --git a/tests/phpunit/TestMslsMetaBox.php b/tests/phpunit/TestMslsMetaBox.php index da77acbe6..0a0b617d4 100644 --- a/tests/phpunit/TestMslsMetaBox.php +++ b/tests/phpunit/TestMslsMetaBox.php @@ -2,18 +2,17 @@ namespace lloc\MslsTests; -use Brain\Monkey\Functions; use Brain\Monkey\Actions; use Brain\Monkey\Filters; - +use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; use lloc\Msls\MslsJson; use lloc\Msls\MslsMetaBox; -use lloc\Msls\Options\Options; -use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsPostType; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\Post\Post; final class TestMslsMetaBox extends MslsUnitTestCase { @@ -375,7 +374,7 @@ public function test_maybe_set_linked_post() { $test = $this->MslsMetaBoxFactory(); - $mydata = new OptionsPost(); + $mydata = new Post(); $mydata = $test->maybe_set_linked_post( $mydata ); $this->assertEquals( 42, $mydata->de_DE ); @@ -393,7 +392,7 @@ public function test_maybe_set_linked_post_with_no_post() { $test = $this->MslsMetaBoxFactory(); - $mydata = new OptionsPost(); + $mydata = new Post(); $mydata = $test->maybe_set_linked_post( $mydata ); $this->assertNull( $mydata->de_DE ); @@ -413,7 +412,7 @@ function test_maybe_set_linked_post_with_no_blog_id() { Functions\expect( 'filter_input' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_ID, FILTER_SANITIZE_NUMBER_INT )->andReturn( 42 ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new OptionsPost(); + $mydata = new Post(); $mydata = $test->maybe_set_linked_post( $mydata ); $this->assertNull( $mydata->de_DE ); @@ -431,7 +430,7 @@ function test_maybe_set_linked_post_with_mydata_already_set() { Functions\expect( 'filter_input' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_LANG, FILTER_SANITIZE_FULL_SPECIAL_CHARS )->andReturn( 'de_DE' ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new OptionsPost(); + $mydata = new Post(); $mydata->de_DE = 42; $mydata = $test->maybe_set_linked_post( $mydata ); diff --git a/tests/phpunit/TestMslsOutput.php b/tests/phpunit/TestMslsOutput.php index dd52dc119..112e43de1 100644 --- a/tests/phpunit/TestMslsOutput.php +++ b/tests/phpunit/TestMslsOutput.php @@ -6,9 +6,9 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; -use lloc\Msls\Options\Options; -use lloc\Msls\Options\OptionsPost; use lloc\Msls\MslsOutput; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\Post\Post; final class TestMslsOutput extends MslsUnitTestCase { @@ -318,7 +318,7 @@ public function test_is_requirements_not_fulfilled_with_mslsoptions(): void { public function test_is_requirements_not_fulfilled_with_mslsoptionspost(): void { Functions\expect( 'get_option' )->once()->andReturn( array() ); - $mydata = new OptionsPost(); + $mydata = new Post(); $test = $this->MslsOutputFactory(); diff --git a/tests/phpunit/TestMslsPostTag.php b/tests/phpunit/TestMslsPostTag.php index e56f398d3..f048ec602 100644 --- a/tests/phpunit/TestMslsPostTag.php +++ b/tests/phpunit/TestMslsPostTag.php @@ -2,16 +2,16 @@ namespace lloc\MslsTests; -use Brain\Monkey\Functions; use Brain\Monkey\Actions; use Brain\Monkey\Filters; +use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; -use lloc\Msls\Options\Options; -use lloc\Msls\Options\OptionsTax; use lloc\Msls\MslsPostTag; use lloc\Msls\MslsTaxonomy; +use lloc\Msls\Options\Options; +use lloc\Msls\Options\Tax\Tax; final class TestMslsPostTag extends MslsUnitTestCase { @@ -234,7 +234,7 @@ public function test_set() { } public function test_maybe_set_linked_term_origin_lang(): void { - $mydata = \Mockery::mock( OptionsTax::class ); + $mydata = \Mockery::mock( Tax::class ); $mydata->de_DE = 42; Functions\expect( 'filter_has_var' )->twice()->andReturnTrue(); @@ -247,7 +247,7 @@ public function test_maybe_set_linked_term_origin_lang(): void { } public function test_maybe_set_linked_term_blog_id_null(): void { - $mydata = \Mockery::mock( OptionsTax::class ); + $mydata = \Mockery::mock( Tax::class ); $mydata->de_DE = 42; Functions\expect( 'filter_has_var' )->twice()->andReturnTrue(); @@ -260,7 +260,7 @@ public function test_maybe_set_linked_term_blog_id_null(): void { } public function test_maybe_set_linked_term_origin_term_wrong(): void { - $mydata = \Mockery::mock( OptionsTax::class ); + $mydata = \Mockery::mock( Tax::class ); $mydata->shouldReceive( 'get_base_option' )->andReturn( 'term' ); $mydata->en_US = 42; @@ -277,7 +277,7 @@ public function test_maybe_set_linked_term_origin_term_wrong(): void { } public function test_maybe_set_linked_term_happy_path(): void { - $mydata = \Mockery::mock( OptionsTax::class ); + $mydata = \Mockery::mock( Tax::class ); $mydata->shouldReceive( 'get_base_option' )->andReturn( 'term' ); $mydata->en_US = 42; From eeff4d7970b12ac0c5fffb8e5205074fa702b8c4 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Thu, 14 May 2026 15:06:14 +0200 Subject: [PATCH 11/13] Restructuring --- MultisiteLanguageSwitcher.php | 18 +++---- .../ContentTypes.php} | 11 +++-- .../PostType.php} | 6 ++- .../Taxonomy.php} | 6 ++- .../ImageOnly.php} | 6 ++- includes/{MslsLink.php => Link/Link.php} | 13 +++-- .../TextImage.php} | 6 ++- .../TextOnly.php} | 6 ++- includes/LinkInterface.php | 4 +- includes/MslsAdmin.php | 5 +- includes/MslsAdminIconTaxonomy.php | 6 ++- includes/MslsOutput.php | 3 +- includes/MslsTranslationPickerPage.php | 8 +-- includes/aliases.php | 49 +++++++++++++++---- .../phpunit/ContentTypes/TestContentTypes.php | 25 ++++++++++ .../TestPostType.php} | 13 +++-- .../TestTaxonomy.php} | 13 +++-- tests/phpunit/Link/TestImageOnly.php | 13 +++++ .../{TestMslsLink.php => Link/TestLink.php} | 28 ++++++----- tests/phpunit/Link/TestTextImage.php | 13 +++++ tests/phpunit/Link/TestTextOnly.php | 13 +++++ tests/phpunit/Options/TestOptions.php | 4 +- tests/phpunit/TestMslsContentTypes.php | 22 --------- tests/phpunit/TestMslsCustomColumn.php | 11 ++--- .../phpunit/TestMslsCustomColumnTaxonomy.php | 8 +-- tests/phpunit/TestMslsLinkImageOnly.php | 13 ----- tests/phpunit/TestMslsLinkTextImage.php | 13 ----- tests/phpunit/TestMslsLinkTextOnly.php | 13 ----- tests/phpunit/TestMslsMetaBox.php | 8 +-- tests/phpunit/TestMslsPostTag.php | 10 ++-- 30 files changed, 216 insertions(+), 151 deletions(-) rename includes/{MslsContentTypes.php => ContentTypes/ContentTypes.php} (80%) rename includes/{MslsPostType.php => ContentTypes/PostType.php} (91%) rename includes/{MslsTaxonomy.php => ContentTypes/Taxonomy.php} (94%) rename includes/{MslsLinkImageOnly.php => Link/ImageOnly.php} (76%) rename includes/{MslsLink.php => Link/Link.php} (90%) rename includes/{MslsLinkTextImage.php => Link/TextImage.php} (77%) rename includes/{MslsLinkTextOnly.php => Link/TextOnly.php} (76%) create mode 100644 tests/phpunit/ContentTypes/TestContentTypes.php rename tests/phpunit/{TestMslsPostType.php => ContentTypes/TestPostType.php} (62%) rename tests/phpunit/{TestMslsTaxonomy.php => ContentTypes/TestTaxonomy.php} (91%) create mode 100644 tests/phpunit/Link/TestImageOnly.php rename tests/phpunit/{TestMslsLink.php => Link/TestLink.php} (53%) create mode 100644 tests/phpunit/Link/TestTextImage.php create mode 100644 tests/phpunit/Link/TestTextOnly.php delete mode 100644 tests/phpunit/TestMslsContentTypes.php delete mode 100644 tests/phpunit/TestMslsLinkImageOnly.php delete mode 100644 tests/phpunit/TestMslsLinkTextImage.php delete mode 100644 tests/phpunit/TestMslsLinkTextOnly.php diff --git a/MultisiteLanguageSwitcher.php b/MultisiteLanguageSwitcher.php index 355d8a1a3..7681bb6a3 100644 --- a/MultisiteLanguageSwitcher.php +++ b/MultisiteLanguageSwitcher.php @@ -163,28 +163,28 @@ function msls_options(): \lloc\Msls\Options\Options { /** * Gets the MslsContentTypes instance * - * @return \lloc\Msls\MslsContentTypes + * @return \lloc\Msls\ContentTypes\ContentTypes */ - function msls_content_types(): \lloc\Msls\MslsContentTypes { - return \lloc\Msls\MslsContentTypes::create(); + function msls_content_types(): \lloc\Msls\ContentTypes\ContentTypes { + return \lloc\Msls\ContentTypes\ContentTypes::create(); } /** * Gets the MslsPostType instance * - * @return \lloc\Msls\MslsPostType + * @return \lloc\Msls\ContentTypes\PostType */ - function msls_post_type(): \lloc\Msls\MslsPostType { - return \lloc\Msls\MslsPostType::instance(); + function msls_post_type(): \lloc\Msls\ContentTypes\PostType { + return \lloc\Msls\ContentTypes\PostType::instance(); } /** * Gets the MslsTaxonomy instance * - * @return \lloc\Msls\MslsTaxonomy + * @return \lloc\Msls\ContentTypes\Taxonomy */ - function msls_taxonomy(): \lloc\Msls\MslsTaxonomy { - return \lloc\Msls\MslsTaxonomy::instance(); + function msls_taxonomy(): \lloc\Msls\ContentTypes\Taxonomy { + return \lloc\Msls\ContentTypes\Taxonomy::instance(); } /** diff --git a/includes/MslsContentTypes.php b/includes/ContentTypes/ContentTypes.php similarity index 80% rename from includes/MslsContentTypes.php rename to includes/ContentTypes/ContentTypes.php index 6b570579b..c3f9b3b45 100644 --- a/includes/MslsContentTypes.php +++ b/includes/ContentTypes/ContentTypes.php @@ -1,13 +1,16 @@ options->display ) ) )->render(); + echo ( new Select( 'display', Link::get_types_description(), strval( $this->options->display ) ) )->render(); } /** diff --git a/includes/MslsAdminIconTaxonomy.php b/includes/MslsAdminIconTaxonomy.php index 0850631ec..311e84585 100644 --- a/includes/MslsAdminIconTaxonomy.php +++ b/includes/MslsAdminIconTaxonomy.php @@ -2,6 +2,8 @@ namespace lloc\Msls; +use lloc\Msls\ContentTypes\Taxonomy; + /** * Handles backend icons for taxonomies * @@ -20,7 +22,7 @@ class MslsAdminIconTaxonomy extends MslsAdminIcon { * @uses get_edit_term_link() */ public function set_href( int $id ): MslsAdminIcon { - $object_type = MslsTaxonomy::instance()->get_post_type(); + $object_type = Taxonomy::instance()->get_post_type(); $this->href = get_edit_term_link( $id, $this->type, $object_type ) ?? ''; @@ -35,7 +37,7 @@ public function set_href( int $id ): MslsAdminIcon { public function set_path(): MslsAdminIcon { $args = array( 'taxonomy' => $this->type ); - $post_type = MslsTaxonomy::instance()->get_post_type(); + $post_type = Taxonomy::instance()->get_post_type(); if ( '' !== $post_type ) { $args['post_type'] = $post_type; } diff --git a/includes/MslsOutput.php b/includes/MslsOutput.php index 5d7fb71cb..8a2fc5a66 100644 --- a/includes/MslsOutput.php +++ b/includes/MslsOutput.php @@ -2,6 +2,7 @@ namespace lloc\Msls; +use lloc\Msls\Link\Link; use lloc\Msls\Map\HrefLang; use lloc\Msls\Options\Options; @@ -54,7 +55,7 @@ public function get( ?int $display, bool $filter = false, $exists = false ): arr $blogs = $this->collection->get_filtered( $filter ); if ( $blogs ) { $mydata = Options::create(); - $link = MslsLink::create( $display ); + $link = Link::create( $display ); foreach ( $blogs as $blog ) { $language = $blog->get_language(); diff --git a/includes/MslsTranslationPickerPage.php b/includes/MslsTranslationPickerPage.php index 2eb3a0cc1..909f4e599 100644 --- a/includes/MslsTranslationPickerPage.php +++ b/includes/MslsTranslationPickerPage.php @@ -2,6 +2,8 @@ namespace lloc\Msls; +use lloc\Msls\ContentTypes\PostType; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -83,7 +85,7 @@ public static function register(): void { return; } - foreach ( MslsPostType::get() as $post_type ) { + foreach ( PostType::get() as $post_type ) { $parent = self::parent_slug( $post_type ); if ( '' === $parent ) { continue; @@ -160,7 +162,7 @@ public static function reorder_submenu(): void { return; } - foreach ( MslsPostType::get() as $post_type ) { + foreach ( PostType::get() as $post_type ) { $parent = self::parent_slug( $post_type ); $slug = self::page_slug( $post_type ); @@ -304,7 +306,7 @@ public static function render(): void { $post_type = substr( $page, strlen( self::BASE_SLUG ) + 1 ); } - if ( ! in_array( $post_type, MslsPostType::get(), true ) ) { + if ( ! in_array( $post_type, PostType::get(), true ) ) { $post_type = 'post'; } diff --git a/includes/aliases.php b/includes/aliases.php index 1d8678957..45140f021 100644 --- a/includes/aliases.php +++ b/includes/aliases.php @@ -13,17 +13,36 @@ exit; } +use lloc\Msls\Link\{ + Link, + ImageOnly, + TextImage, + TextOnly +}; + use lloc\Msls\Options\Options; use lloc\Msls\Options\Post\Post; -use lloc\Msls\Options\Query\Author; -use lloc\Msls\Options\Query\Day; -use lloc\Msls\Options\Query\Month; -use lloc\Msls\Options\Query\PostType; -use lloc\Msls\Options\Query\Query; -use lloc\Msls\Options\Query\Year; -use lloc\Msls\Options\Tax\Category; -use lloc\Msls\Options\Tax\Tax; -use lloc\Msls\Options\Tax\Term; + +use lloc\Msls\Options\Query\{ + Author, + Day, + Month, + PostType as QueryPostType, + Query, + Year +}; + +use lloc\Msls\Options\Tax\{ + Category, + Tax, + Term +}; + +use lloc\Msls\ContentTypes\{ + ContentTypes, + PostType as ContentPostType, + Taxonomy +}; class_alias( Options::class, 'lloc\\Msls\\MslsOptions' ); class_alias( Post::class, 'lloc\\Msls\\MslsOptionsPost' ); @@ -31,8 +50,18 @@ class_alias( Query::class, 'lloc\\Msls\\MslsOptionsQuery' ); class_alias( Author::class, 'lloc\\Msls\\MslsOptionsQueryAuthor' ); class_alias( Day::class, 'lloc\\Msls\\MslsOptionsQueryDay' ); class_alias( Month::class, 'lloc\\Msls\\MslsOptionsQueryMonth' ); -class_alias( PostType::class, 'lloc\\Msls\\MslsOptionsQueryPostType' ); +class_alias( QueryPostType::class, 'lloc\\Msls\\MslsOptionsQueryPostType' ); class_alias( Year::class, 'lloc\\Msls\\MslsOptionsQueryYear' ); + class_alias( Tax::class, 'lloc\\Msls\\MslsOptionsTax' ); class_alias( Term::class, 'lloc\\Msls\\MslsOptionsTaxTerm' ); class_alias( Category::class, 'lloc\\Msls\\MslsOptionsTaxTermCategory' ); + +class_alias( Link::class, 'lloc\\Msls\\MslsLink' ); +class_alias( ImageOnly::class, 'lloc\\Msls\\MslsLinkImageOnly' ); +class_alias( TextImage::class, 'lloc\\Msls\\MslsLinkTextImage' ); +class_alias( TextOnly::class, 'lloc\\Msls\\MslsLinkTextOnly' ); + +class_alias( ContentTypes::class, 'lloc\\Msls\\MslsContentTypes' ); +class_alias( ContentPostType::class, 'lloc\\Msls\\MslsPostType' ); +class_alias( Taxonomy::class, 'lloc\\Msls\\MslsTaxonomy' ); diff --git a/tests/phpunit/ContentTypes/TestContentTypes.php b/tests/phpunit/ContentTypes/TestContentTypes.php new file mode 100644 index 000000000..a8c082451 --- /dev/null +++ b/tests/phpunit/ContentTypes/TestContentTypes.php @@ -0,0 +1,25 @@ +twice()->andReturn( array() ); + + $obj = ContentTypes::create(); + + $this->assertInstanceOf( PostType::class, $obj ); + } + + public function test_is_taxonomy(): void { + $this->assertFalse( ContentTypes::create()->is_taxonomy() ); + } +} diff --git a/tests/phpunit/TestMslsPostType.php b/tests/phpunit/ContentTypes/TestPostType.php similarity index 62% rename from tests/phpunit/TestMslsPostType.php rename to tests/phpunit/ContentTypes/TestPostType.php index d70ec805d..e96419936 100644 --- a/tests/phpunit/TestMslsPostType.php +++ b/tests/phpunit/ContentTypes/TestPostType.php @@ -1,17 +1,20 @@ justReturn( array() ); Functions\when( 'get_post_type' )->justReturn( array() ); - return new MslsPostType(); + return new PostType(); } public function test_is_post_type(): void { diff --git a/tests/phpunit/TestMslsTaxonomy.php b/tests/phpunit/ContentTypes/TestTaxonomy.php similarity index 91% rename from tests/phpunit/TestMslsTaxonomy.php rename to tests/phpunit/ContentTypes/TestTaxonomy.php index 2e43e3b39..e9bbbd3c0 100644 --- a/tests/phpunit/TestMslsTaxonomy.php +++ b/tests/phpunit/ContentTypes/TestTaxonomy.php @@ -1,15 +1,18 @@ shouldReceive( 'is_excluded' )->andReturn( $exluded ); @@ -17,7 +20,7 @@ private function MslsTaxonomyFactory( bool $exluded = false ): MslsTaxonomy { Functions\expect( 'apply_filters' )->atLeast()->once(); Functions\expect( 'get_taxonomies' )->atLeast()->once()->andReturn( array() ); - return new MslsTaxonomy(); + return new Taxonomy(); } public function test_acl_request_included(): void { diff --git a/tests/phpunit/Link/TestImageOnly.php b/tests/phpunit/Link/TestImageOnly.php new file mode 100644 index 000000000..47f0c5d2f --- /dev/null +++ b/tests/phpunit/Link/TestImageOnly.php @@ -0,0 +1,13 @@ +assertIsSTring( ImageOnly::get_description() ); + } +} diff --git a/tests/phpunit/TestMslsLink.php b/tests/phpunit/Link/TestLink.php similarity index 53% rename from tests/phpunit/TestMslsLink.php rename to tests/phpunit/Link/TestLink.php index 7cc632fbc..000dc4c06 100644 --- a/tests/phpunit/TestMslsLink.php +++ b/tests/phpunit/Link/TestLink.php @@ -1,44 +1,48 @@ once()->with( 'msls_link_create' )->andReturn( true ); - $obj = new MslsLink(); + $obj = new Link(); $display = 0; Filters\expectApplied( 'msls_link_create' )->once()->andReturn( $obj ); - $obj = MslsLink::create( $display ); + $obj = Link::create( $display ); - $this->assertInstanceOf( MslsLink::class, $obj ); + $this->assertInstanceOf( Link::class, $obj ); } public function test_get_types(): void { - $this->assertCount( 4, MslsLink::get_types() ); + $this->assertCount( 4, Link::get_types() ); } public function test_get_description(): void { - $this->assertEquals( 'Flag and description', MslsLink::get_description() ); + $this->assertEquals( 'Flag and description', Link::get_description() ); } public function test_get_types_description(): void { - $this->assertCount( 4, MslsLink::get_types_description() ); + $this->assertCount( 4, Link::get_types_description() ); } public function test_callback(): void { - $this->assertEquals( '{Test}', MslsLink::callback( 'Test' ) ); + $this->assertEquals( '{Test}', Link::callback( 'Test' ) ); } public function test_object2string_conversion(): void { - $obj = MslsLink::create( 0 ); + $obj = Link::create( 0 ); $this->assertEquals( '{alt} {txt}', strval( $obj ) ); } diff --git a/tests/phpunit/Link/TestTextImage.php b/tests/phpunit/Link/TestTextImage.php new file mode 100644 index 000000000..0ad78f23a --- /dev/null +++ b/tests/phpunit/Link/TestTextImage.php @@ -0,0 +1,13 @@ +assertIsSTring( TextImage::get_description() ); + } +} diff --git a/tests/phpunit/Link/TestTextOnly.php b/tests/phpunit/Link/TestTextOnly.php new file mode 100644 index 000000000..557962a63 --- /dev/null +++ b/tests/phpunit/Link/TestTextOnly.php @@ -0,0 +1,13 @@ +assertIsSTring( TextOnly::get_description() ); + } +} diff --git a/tests/phpunit/Options/TestOptions.php b/tests/phpunit/Options/TestOptions.php index 2d99c569a..1971ef2a7 100644 --- a/tests/phpunit/Options/TestOptions.php +++ b/tests/phpunit/Options/TestOptions.php @@ -3,8 +3,8 @@ namespace lloc\MslsTests\Options; use Brain\Monkey\Functions; +use lloc\Msls\ContentTypes\PostType; use lloc\Msls\MslsAdminIcon; -use lloc\Msls\MslsPostType; use lloc\Msls\Options\Options; use lloc\MslsTests\MslsUnitTestCase; @@ -37,7 +37,7 @@ public function test_is_query_page(): void { } public function test_create(): void { - $post_type = \Mockery::mock( MslsPostType::class ); + $post_type = \Mockery::mock( PostType::class ); $post_type->shouldReceive( 'is_taxonomy' )->once()->andReturnFalse(); Functions\expect( 'msls_content_types' )->once()->andReturn( $post_type ); diff --git a/tests/phpunit/TestMslsContentTypes.php b/tests/phpunit/TestMslsContentTypes.php deleted file mode 100644 index 422104d8b..000000000 --- a/tests/phpunit/TestMslsContentTypes.php +++ /dev/null @@ -1,22 +0,0 @@ -twice()->andReturn( array() ); - - $obj = MslsContentTypes::create(); - - $this->assertInstanceOf( MslsPostType::class, $obj ); - } - - public function test_is_taxonomy(): void { - $this->assertFalse( MslsContentTypes::create()->is_taxonomy() ); - } -} diff --git a/tests/phpunit/TestMslsCustomColumn.php b/tests/phpunit/TestMslsCustomColumn.php index 2b93ffdd0..a312cfa98 100644 --- a/tests/phpunit/TestMslsCustomColumn.php +++ b/tests/phpunit/TestMslsCustomColumn.php @@ -2,15 +2,14 @@ namespace lloc\MslsTests; -use Brain\Monkey\Functions; -use Brain\Monkey\Filters; use Brain\Monkey\Actions; - +use Brain\Monkey\Filters; +use Brain\Monkey\Functions; +use lloc\Msls\ContentTypes\PostType; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsCustomColumn; use lloc\Msls\Options\Options; -use lloc\Msls\MslsPostType; final class TestMslsCustomColumn extends MslsUnitTestCase { @@ -58,7 +57,7 @@ public function test_add_hooks(): void { $collection = \Mockery::mock( MslsBlogCollection::class ); - $post_type = \Mockery::mock( MslsPostType::class ); + $post_type = \Mockery::mock( PostType::class ); $post_type->shouldReceive( 'get_request' )->andReturn( 'post' ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); @@ -100,7 +99,7 @@ public function test_th_empty(): void { public function test_td(): void { $item_id = 42; - $post_type = \Mockery::mock( MslsPostType::class ); + $post_type = \Mockery::mock( PostType::class ); $post_type->shouldReceive( 'is_taxonomy' )->times( 3 )->andReturnFalse(); $post_type->shouldReceive( 'get_request' )->twice()->andReturn( 'post' ); diff --git a/tests/phpunit/TestMslsCustomColumnTaxonomy.php b/tests/phpunit/TestMslsCustomColumnTaxonomy.php index 591148eab..3e5eba8ac 100644 --- a/tests/phpunit/TestMslsCustomColumnTaxonomy.php +++ b/tests/phpunit/TestMslsCustomColumnTaxonomy.php @@ -2,13 +2,13 @@ namespace lloc\MslsTests; -use Brain\Monkey\Functions; -use Brain\Monkey\Filters; use Brain\Monkey\Actions; +use Brain\Monkey\Filters; +use Brain\Monkey\Functions; +use lloc\Msls\ContentTypes\Taxonomy; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsCustomColumnTaxonomy; use lloc\Msls\Options\Options; -use lloc\Msls\MslsTaxonomy; final class TestMslsCustomColumnTaxonomy extends MslsUnitTestCase { @@ -31,7 +31,7 @@ public function test_add_hooks(): void { $collection = \Mockery::mock( MslsBlogCollection::class ); - $taxonomy = \Mockery::mock( MslsTaxonomy::class ); + $taxonomy = \Mockery::mock( Taxonomy::class ); $taxonomy->shouldReceive( 'get_request' )->andReturn( 'post_tag' ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); diff --git a/tests/phpunit/TestMslsLinkImageOnly.php b/tests/phpunit/TestMslsLinkImageOnly.php deleted file mode 100644 index 2ae4c23ac..000000000 --- a/tests/phpunit/TestMslsLinkImageOnly.php +++ /dev/null @@ -1,13 +0,0 @@ -assertIsSTring( MslsLinkImageOnly::get_description() ); - } -} diff --git a/tests/phpunit/TestMslsLinkTextImage.php b/tests/phpunit/TestMslsLinkTextImage.php deleted file mode 100644 index 1f6170ad3..000000000 --- a/tests/phpunit/TestMslsLinkTextImage.php +++ /dev/null @@ -1,13 +0,0 @@ -assertIsSTring( MslsLinkTextImage::get_description() ); - } -} diff --git a/tests/phpunit/TestMslsLinkTextOnly.php b/tests/phpunit/TestMslsLinkTextOnly.php deleted file mode 100644 index c35c32c65..000000000 --- a/tests/phpunit/TestMslsLinkTextOnly.php +++ /dev/null @@ -1,13 +0,0 @@ -assertIsSTring( MslsLinkTextOnly::get_description() ); - } -} diff --git a/tests/phpunit/TestMslsMetaBox.php b/tests/phpunit/TestMslsMetaBox.php index 0a0b617d4..58fad2012 100644 --- a/tests/phpunit/TestMslsMetaBox.php +++ b/tests/phpunit/TestMslsMetaBox.php @@ -5,12 +5,12 @@ use Brain\Monkey\Actions; use Brain\Monkey\Filters; use Brain\Monkey\Functions; +use lloc\Msls\ContentTypes\PostType; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; use lloc\Msls\MslsJson; use lloc\Msls\MslsMetaBox; -use lloc\Msls\MslsPostType; use lloc\Msls\Options\Options; use lloc\Msls\Options\Post\Post; @@ -194,7 +194,7 @@ public function test_render_select_not_hierarchical(): void { $options = \Mockery::mock( Options::class ); $options->activate_quick_create = false; - $post_type = \Mockery::mock( MslsPostType::class ); + $post_type = \Mockery::mock( PostType::class ); $post_type->shouldReceive( 'is_taxonomy' )->once()->andReturnFalse(); Functions\expect( 'msls_content_types' )->once()->andReturn( $post_type ); @@ -229,7 +229,7 @@ public function test_render_select_hierarchical(): void { $post = \Mockery::mock( 'WP_Post' ); $post->ID = 42; - $post_type = \Mockery::mock( MslsPostType::class ); + $post_type = \Mockery::mock( PostType::class ); $post_type->shouldReceive( 'is_taxonomy' )->once()->andReturnFalse(); Functions\expect( 'msls_content_types' )->once()->andReturn( $post_type ); @@ -275,7 +275,7 @@ public function test_render_input( $option, $the_title_times, $current_blog_id_t $options = \Mockery::mock( Options::class ); $options->activate_quick_create = false; - $post_type = \Mockery::mock( MslsPostType::class ); + $post_type = \Mockery::mock( PostType::class ); $post_type->shouldReceive( 'is_taxonomy' )->once()->andReturnFalse(); $post_type->shouldReceive( 'get_request' )->once()->andReturn( 'post' ); diff --git a/tests/phpunit/TestMslsPostTag.php b/tests/phpunit/TestMslsPostTag.php index f048ec602..2b6de70c8 100644 --- a/tests/phpunit/TestMslsPostTag.php +++ b/tests/phpunit/TestMslsPostTag.php @@ -5,11 +5,11 @@ use Brain\Monkey\Actions; use Brain\Monkey\Filters; use Brain\Monkey\Functions; +use lloc\Msls\ContentTypes\Taxonomy; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; use lloc\Msls\MslsPostTag; -use lloc\Msls\MslsTaxonomy; use lloc\Msls\Options\Options; use lloc\Msls\Options\Tax\Tax; @@ -49,7 +49,7 @@ public function test_init(): void { $collection = \Mockery::mock( MslsBlogCollection::class ); - $taxonomy = \Mockery::mock( MslsTaxonomy::class ); + $taxonomy = \Mockery::mock( Taxonomy::class ); $taxonomy->shouldReceive( 'acl_request' )->once()->andReturn( 'post_tag' ); Functions\expect( 'msls_options' )->atLeast()->once()->andReturn( $options ); @@ -121,7 +121,7 @@ function ( $output ) { } public function test_edit_input(): void { - $taxonomy = \Mockery::mock( MslsTaxonomy::class ); + $taxonomy = \Mockery::mock( Taxonomy::class ); $taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturn( true ); $taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' ); $taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( 'taxonomy' ); @@ -175,7 +175,7 @@ public function test_edit_input(): void { } public function test_add_input(): void { - $taxonomy = \Mockery::mock( MslsTaxonomy::class ); + $taxonomy = \Mockery::mock( Taxonomy::class ); $taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturnTrue(); $taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' ); $taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( 'taxonomy' ); @@ -221,7 +221,7 @@ public function test_the_input_no_blogs(): void { } public function test_set() { - $taxonomy = \Mockery::mock( MslsTaxonomy::class ); + $taxonomy = \Mockery::mock( Taxonomy::class ); $taxonomy->shouldReceive( 'acl_request' )->once()->andReturn( 'post_tag' ); Functions\expect( 'msls_content_types' )->once()->andReturn( $taxonomy ); From 583eb0ba9bc9e8070001ced689ae923b5d26220f Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sat, 16 May 2026 16:30:58 +0200 Subject: [PATCH 12/13] Restructuring reloaded --- MultisiteLanguageSwitcher.php | 28 ++--- includes/{MslsAdmin.php => Admin/Admin.php} | 15 ++- includes/{MslsAdminBar.php => Admin/Bar.php} | 24 ++-- .../CustomColumn.php} | 12 +- .../CustomColumnTaxonomy.php} | 4 +- .../CustomFilter.php} | 12 +- .../{MslsAdminIcon.php => Admin/Icon.php} | 22 ++-- .../IconTaxonomy.php} | 12 +- .../{MslsMetaBox.php => Admin/MetaBox.php} | 22 ++-- .../PostListActions.php} | 10 +- .../TranslationPicker/Page.php} | 35 +++--- .../TranslationPicker/Table.php} | 18 +-- includes/{MslsBlog.php => Blog/Blog.php} | 23 ++-- .../Collection.php} | 39 +++--- includes/{MslsCli.php => Cli/Cli.php} | 4 +- .../ContentImport/AttachmentPathFinder.php | 4 +- includes/ContentImport/ContentImporter.php | 10 +- includes/ContentImport/ImportCoordinates.php | 6 +- .../Importers/ImportersBaseFactory.php | 4 +- includes/ContentImport/Importers/Map.php | 4 +- .../Importers/Terms/ShallowDuplicating.php | 2 +- .../LogWriters/AdminNoticeLogger.php | 4 +- includes/ContentImport/MetaBox.php | 8 +- includes/ContentImport/Relations.php | 4 +- includes/ContentImport/Service.php | 4 +- includes/ContentTypes/ContentTypes.php | 4 +- includes/Db/Query/AbstractQuery.php | 29 +++++ .../Query/AuthorPostsCounterQuery.php | 2 +- .../{ => Db}/Query/BlogsInNetworkQuery.php | 2 +- .../{ => Db}/Query/CleanupOptionsQuery.php | 2 +- .../{ => Db}/Query/DatePostsCounterQuery.php | 2 +- .../{ => Db}/Query/MonthPostsCounterQuery.php | 2 +- .../{ => Db}/Query/TranslatedPostIdQuery.php | 2 +- .../{ => Db}/Query/YearPostsCounterQuery.php | 2 +- .../{MslsSqlCacher.php => Db/SqlCacher.php} | 4 +- .../{MslsBlock.php => Frontend/Block.php} | 5 +- .../ContentFilter.php} | 6 +- includes/{ => Frontend}/Map/HrefLang.php | 10 +- .../{MslsOutput.php => Frontend/Output.php} | 17 +-- .../ShortCode.php} | 6 +- .../{MslsWidget.php => Frontend/Widget.php} | 4 +- includes/Link/ImageOnly.php | 2 - includes/Link/Link.php | 1 - includes/{ => Link}/LinkInterface.php | 4 +- includes/Link/TextImage.php | 2 - includes/Link/TextOnly.php | 2 - includes/MslsGetSet.php | 4 +- includes/MslsMain.php | 12 +- includes/MslsPlugin.php | 67 ++++++---- includes/Options/Options.php | 5 +- includes/{ => Options}/OptionsInterface.php | 2 +- includes/Options/Query/Author.php | 6 +- includes/Options/Query/Day.php | 6 +- includes/Options/Query/Month.php | 6 +- includes/Options/Query/PostType.php | 4 +- includes/Options/Query/Query.php | 10 +- includes/Options/Query/Year.php | 8 +- includes/Options/Tax/Category.php | 2 - .../{ => Options/Tax}/OptionsTaxInterface.php | 4 +- includes/Options/Tax/Tax.php | 1 - includes/Options/Tax/Term.php | 1 - .../Classic.php} | 13 +- .../{MslsPostTag.php => PostTag/PostTag.php} | 14 ++- includes/Query/AbstractQuery.php | 29 ----- .../Instance.php} | 12 +- .../Registry.php} | 8 +- .../{MslsRestApi.php => RestApi/RestApi.php} | 20 +-- includes/aliases.php | 116 +++++++++++++++++- .../TestAdmin.php} | 81 ++++++------ .../TestBar.php} | 35 +++--- .../TestCustomColumn.php} | 37 +++--- .../TestCustomColumnTaxonomy.php} | 25 ++-- .../TestCustomFilter.php} | 29 ++--- .../TestIcon.php} | 53 ++++---- .../TestIconTaxonomy.php} | 19 +-- .../TestMetaBox.php} | 71 +++++------ .../TranslationPicker/TestPage.php} | 33 ++--- .../{TestMslsBlog.php => Blog/TestBlog.php} | 61 ++++----- .../TestCollection.php} | 63 +++++----- .../{TestMslsCli.php => Cli/TestCli.php} | 15 +-- .../Query/TestTranslatedPostsQuery.php | 8 +- .../TestSqlCacher.php} | 17 +-- .../{ => Frontend}/Map/TestHrefLang.php | 12 +- .../TestBlock.php} | 11 +- .../TestContentFilter.php} | 41 ++++--- .../TestOutput.php} | 93 +++++++------- .../TestShortCode.php} | 15 +-- .../TestWidget.php} | 25 ++-- tests/phpunit/Options/Query/TestAuthor.php | 4 +- tests/phpunit/Options/Query/TestDay.php | 4 +- tests/phpunit/Options/Query/TestMonth.php | 4 +- .../Options/Query/TestOptionsQueryYear.php | 4 +- tests/phpunit/Options/Query/TestPostType.php | 4 +- tests/phpunit/Options/Query/TestQuery.php | 8 +- tests/phpunit/Options/TestOptions.php | 2 +- .../TestClassic.php} | 29 ++--- .../TestPostTag.php} | 33 ++--- .../TestRegistry.php} | 9 +- .../TestRestApi.php} | 49 ++++---- tests/phpunit/TestMslsMain.php | 8 +- tests/phpunit/TestMslsPlugin.php | 8 +- 101 files changed, 941 insertions(+), 759 deletions(-) rename includes/{MslsAdmin.php => Admin/Admin.php} (97%) rename includes/{MslsAdminBar.php => Admin/Bar.php} (78%) rename includes/{MslsCustomColumn.php => Admin/CustomColumn.php} (89%) rename includes/{MslsCustomColumnTaxonomy.php => Admin/CustomColumnTaxonomy.php} (92%) rename includes/{MslsCustomFilter.php => Admin/CustomFilter.php} (88%) rename includes/{MslsAdminIcon.php => Admin/Icon.php} (89%) rename includes/{MslsAdminIconTaxonomy.php => Admin/IconTaxonomy.php} (74%) rename includes/{MslsMetaBox.php => Admin/MetaBox.php} (95%) rename includes/{MslsPostListActions.php => Admin/PostListActions.php} (89%) rename includes/{MslsTranslationPickerPage.php => Admin/TranslationPicker/Page.php} (95%) rename includes/{MslsTranslationPickerTable.php => Admin/TranslationPicker/Table.php} (94%) rename includes/{MslsBlog.php => Blog/Blog.php} (90%) rename includes/{MslsBlogCollection.php => Blog/Collection.php} (90%) rename includes/{MslsCli.php => Cli/Cli.php} (95%) create mode 100644 includes/Db/Query/AbstractQuery.php rename includes/{ => Db}/Query/AuthorPostsCounterQuery.php (94%) rename includes/{ => Db}/Query/BlogsInNetworkQuery.php (95%) rename includes/{ => Db}/Query/CleanupOptionsQuery.php (92%) rename includes/{ => Db}/Query/DatePostsCounterQuery.php (95%) rename includes/{ => Db}/Query/MonthPostsCounterQuery.php (94%) rename includes/{ => Db}/Query/TranslatedPostIdQuery.php (96%) rename includes/{ => Db}/Query/YearPostsCounterQuery.php (92%) rename includes/{MslsSqlCacher.php => Db/SqlCacher.php} (98%) rename includes/{MslsBlock.php => Frontend/Block.php} (90%) rename includes/{MslsContentFilter.php => Frontend/ContentFilter.php} (94%) rename includes/{ => Frontend}/Map/HrefLang.php (87%) rename includes/{MslsOutput.php => Frontend/Output.php} (93%) rename includes/{MslsShortCode.php => Frontend/ShortCode.php} (89%) rename includes/{MslsWidget.php => Frontend/Widget.php} (97%) rename includes/{ => Link}/LinkInterface.php (85%) rename includes/{ => Options}/OptionsInterface.php (88%) rename includes/{ => Options/Tax}/OptionsTaxInterface.php (73%) rename includes/{MslsPostTagClassic.php => PostTag/Classic.php} (89%) rename includes/{MslsPostTag.php => PostTag/PostTag.php} (95%) delete mode 100644 includes/Query/AbstractQuery.php rename includes/{MslsRegistryInstance.php => Registry/Instance.php} (54%) rename includes/{MslsRegistry.php => Registry/Registry.php} (92%) rename includes/{MslsRestApi.php => RestApi/RestApi.php} (96%) rename tests/phpunit/{TestMslsAdmin.php => Admin/TestAdmin.php} (86%) rename tests/phpunit/{TestMslsAdminBar.php => Admin/TestBar.php} (72%) rename tests/phpunit/{TestMslsCustomColumn.php => Admin/TestCustomColumn.php} (83%) rename tests/phpunit/{TestMslsCustomColumnTaxonomy.php => Admin/TestCustomColumnTaxonomy.php} (71%) rename tests/phpunit/{TestMslsCustomFilter.php => Admin/TestCustomFilter.php} (81%) rename tests/phpunit/{TestMslsAdminIcon.php => Admin/TestIcon.php} (83%) rename tests/phpunit/{TestMslsAdminIconTaxonomy.php => Admin/TestIconTaxonomy.php} (72%) rename tests/phpunit/{TestMslsMetaBox.php => Admin/TestMetaBox.php} (92%) rename tests/phpunit/{TestMslsTranslationPickerPage.php => Admin/TranslationPicker/TestPage.php} (58%) rename tests/phpunit/{TestMslsBlog.php => Blog/TestBlog.php} (78%) rename tests/phpunit/{TestMslsBlogCollection.php => Blog/TestCollection.php} (83%) rename tests/phpunit/{TestMslsCli.php => Cli/TestCli.php} (61%) rename tests/phpunit/{ => Db}/Query/TestTranslatedPostsQuery.php (82%) rename tests/phpunit/{TestMslsSqlCacher.php => Db/TestSqlCacher.php} (55%) rename tests/phpunit/{ => Frontend}/Map/TestHrefLang.php (86%) rename tests/phpunit/{TestMslsBlock.php => Frontend/TestBlock.php} (65%) rename tests/phpunit/{TestMslsContentFilter.php => Frontend/TestContentFilter.php} (91%) rename tests/phpunit/{TestMslsOutput.php => Frontend/TestOutput.php} (87%) rename tests/phpunit/{TestMslsShortCode.php => Frontend/TestShortCode.php} (72%) rename tests/phpunit/{TestMslsWidget.php => Frontend/TestWidget.php} (75%) rename tests/phpunit/{TestMslsPostTagClassic.php => PostTag/TestClassic.php} (88%) rename tests/phpunit/{TestMslsPostTag.php => PostTag/TestPostTag.php} (94%) rename tests/phpunit/{TestMslsRegistry.php => Registry/TestRegistry.php} (65%) rename tests/phpunit/{TestMslsRestApi.php => RestApi/TestRestApi.php} (92%) diff --git a/MultisiteLanguageSwitcher.php b/MultisiteLanguageSwitcher.php index 7681bb6a3..df3e72202 100644 --- a/MultisiteLanguageSwitcher.php +++ b/MultisiteLanguageSwitcher.php @@ -132,23 +132,23 @@ function msls_get_permalink( string $locale, string $preset = '' ): string { } /** - * Looks for the MslsBlog instance for a specific locale + * Looks for the Blog instance for a specific locale * * @param string $locale * - * @return \lloc\Msls\MslsBlog|null + * @return \lloc\Msls\Blog\Blog|null */ - function msls_blog( string $locale ): ?\lloc\Msls\MslsBlog { + function msls_blog( string $locale ): ?\lloc\Msls\Blog\Blog { return msls_blog_collection()->get_blog( $locale ); } /** - * Gets the MslsBlogCollection instance + * Gets the Blog Collection instance * - * @return \lloc\Msls\MslsBlogCollection + * @return \lloc\Msls\Blog\Collection */ - function msls_blog_collection(): \lloc\Msls\MslsBlogCollection { - return \lloc\Msls\MslsBlogCollection::instance(); + function msls_blog_collection(): \lloc\Msls\Blog\Collection { + return \lloc\Msls\Blog\Collection::instance(); } /** @@ -188,12 +188,12 @@ function msls_taxonomy(): \lloc\Msls\ContentTypes\Taxonomy { } /** - * Gets the MslsOutput instance + * Gets the Output instance * - * @return \lloc\Msls\MslsOutput + * @return \lloc\Msls\Frontend\Output */ - function msls_output(): \lloc\Msls\MslsOutput { - return \lloc\Msls\MslsOutput::create(); + function msls_output(): \lloc\Msls\Frontend\Output { + return \lloc\Msls\Frontend\Output::create(); } /** @@ -216,9 +216,9 @@ function msls_get_post( int $id ): \lloc\Msls\Options\Post\Post { * - is_tax * * @param int $id - * @return \lloc\Msls\OptionsTaxInterface + * @return \lloc\Msls\Options\Tax\OptionsTaxInterface */ - function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface { + function msls_get_tax( int $id ): \lloc\Msls\Options\Tax\OptionsTaxInterface { return \lloc\Msls\Options\Tax\Tax::create( $id ); } @@ -247,5 +247,5 @@ function msls_return_void(): void { } lloc\Msls\MslsPlugin::init(); - lloc\Msls\MslsCli::init(); + lloc\Msls\Cli\Cli::init(); } diff --git a/includes/MslsAdmin.php b/includes/Admin/Admin.php similarity index 97% rename from includes/MslsAdmin.php rename to includes/Admin/Admin.php index ac37546c6..78c70ad27 100644 --- a/includes/MslsAdmin.php +++ b/includes/Admin/Admin.php @@ -1,6 +1,6 @@ __( 'Flag', 'multisite-language-switcher' ), - MslsAdminIcon::TYPE_LABEL => __( 'Label', 'multisite-language-switcher' ), + Icon::TYPE_FLAG => __( 'Flag', 'multisite-language-switcher' ), + Icon::TYPE_LABEL => __( 'Label', 'multisite-language-switcher' ), ), $this->options->get_icon_type() ); diff --git a/includes/MslsAdminBar.php b/includes/Admin/Bar.php similarity index 78% rename from includes/MslsAdminBar.php rename to includes/Admin/Bar.php index 455037dbe..544d6379a 100644 --- a/includes/MslsAdminBar.php +++ b/includes/Admin/Bar.php @@ -1,14 +1,16 @@ icon_type = $options->get_icon_type(); $this->blog_collection = $blog_collection; } @@ -33,7 +35,7 @@ public function __construct( Options $options, MslsBlogCollection $blog_collecti * @return void */ public static function init(): void { - $obj = new MslsAdminBar( msls_options(), msls_blog_collection() ); + $obj = new Bar( msls_options(), msls_blog_collection() ); if ( is_admin_bar_showing() ) { add_action( 'admin_bar_menu', array( $obj, 'update_admin_bar' ), 999 ); @@ -90,12 +92,12 @@ public function add_node( \WP_Admin_Bar $wp_admin_bar, string $node_id, string $ * * It uses a blavatar icon as prefix if $blavatar is set to true * - * @param MslsBlog|null $blog - * @param bool $blavatar + * @param Blog|null $blog + * @param bool $blavatar * * @return string|null */ - protected function get_title( ?MslsBlog $blog, bool $blavatar = false ): ?string { + protected function get_title( ?Blog $blog, bool $blavatar = false ): ?string { if ( is_null( $blog ) ) { return $blog; } diff --git a/includes/MslsCustomColumn.php b/includes/Admin/CustomColumn.php similarity index 89% rename from includes/MslsCustomColumn.php rename to includes/Admin/CustomColumn.php index b16ed61a1..365346566 100644 --- a/includes/MslsCustomColumn.php +++ b/includes/Admin/CustomColumn.php @@ -1,12 +1,14 @@ get_language(); $icon_type = $this->options->get_icon_type(); - $icon = ( new MslsAdminIcon() )->set_language( $language )->set_icon_type( $icon_type ); + $icon = ( new Icon() )->set_language( $language )->set_icon_type( $icon_type ); $post_id = get_the_ID(); if ( false !== $post_id ) { @@ -79,7 +81,7 @@ public function th( array $columns ) { public function td( $column_name, $item_id ): void { if ( 'mslscol' === $column_name ) { $blogs = $this->collection->get(); - $origin_language = MslsBlogCollection::get_blog_language(); + $origin_language = Collection::get_blog_language(); if ( $blogs ) { $mydata = Options::create( $item_id ); foreach ( $blogs as $blog ) { @@ -87,7 +89,7 @@ public function td( $column_name, $item_id ): void { $language = $blog->get_language(); - $icon = MslsAdminIcon::create(); + $icon = Icon::create(); $icon->set_language( $language ); $icon->set_id( $item_id ); $icon->set_origin_language( $origin_language ); diff --git a/includes/MslsCustomColumnTaxonomy.php b/includes/Admin/CustomColumnTaxonomy.php similarity index 92% rename from includes/MslsCustomColumnTaxonomy.php rename to includes/Admin/CustomColumnTaxonomy.php index 0b1b674fa..d042ff3e1 100644 --- a/includes/MslsCustomColumnTaxonomy.php +++ b/includes/Admin/CustomColumnTaxonomy.php @@ -1,6 +1,6 @@ options->is_excluded() ) { diff --git a/includes/MslsCustomFilter.php b/includes/Admin/CustomFilter.php similarity index 88% rename from includes/MslsCustomFilter.php rename to includes/Admin/CustomFilter.php index 9af745264..a98e5563a 100644 --- a/includes/MslsCustomFilter.php +++ b/includes/Admin/CustomFilter.php @@ -1,20 +1,24 @@ query_vars['post__not_in'] = ( new TranslatedPostIdQuery( $sql_cache ) )( $blog->get_language() ); diff --git a/includes/MslsAdminIcon.php b/includes/Admin/Icon.php similarity index 89% rename from includes/MslsAdminIcon.php rename to includes/Admin/Icon.php index 4faa0cc06..659d3fa9b 100644 --- a/includes/MslsAdminIcon.php +++ b/includes/Admin/Icon.php @@ -1,6 +1,6 @@ get_request(); } - return $obj->is_taxonomy() ? new MslsAdminIconTaxonomy( $type ) : new MslsAdminIcon( $type ); + return $obj->is_taxonomy() ? new IconTaxonomy( $type ) : new Icon( $type ); } /** * Set the icon path */ - public function set_icon_type( string $icon_type ): MslsAdminIcon { + public function set_icon_type( string $icon_type ): Icon { $this->icon_type = $icon_type; return $this; @@ -64,7 +64,7 @@ public function set_icon_type( string $icon_type ): MslsAdminIcon { /** * Set the path by type */ - public function set_path(): MslsAdminIcon { + public function set_path(): Icon { if ( 'post' !== $this->type ) { $query_vars = array( 'post_type' => $this->type ); $this->path = add_query_arg( $query_vars, $this->path ); @@ -73,19 +73,19 @@ public function set_path(): MslsAdminIcon { return $this; } - public function set_language( string $language ): MslsAdminIcon { + public function set_language( string $language ): Icon { $this->language = $language; return $this; } - public function set_src( string $src ): MslsAdminIcon { + public function set_src( string $src ): Icon { $this->src = $src; return $this; } - public function set_href( int $id ): MslsAdminIcon { + public function set_href( int $id ): Icon { $this->href = get_edit_post_link( $id ) ?? ''; return $this; @@ -94,7 +94,7 @@ public function set_href( int $id ): MslsAdminIcon { /** * Sets the id of the object this icon is for */ - public function set_id( int $id ): MslsAdminIcon { + public function set_id( int $id ): Icon { $this->id = $id; return $this; @@ -103,7 +103,7 @@ public function set_id( int $id ): MslsAdminIcon { /** * Sets the origin language for this icon */ - public function set_origin_language( string $origin_language ): MslsAdminIcon { + public function set_origin_language( string $origin_language ): Icon { $this->origin_language = $origin_language; return $this; diff --git a/includes/MslsAdminIconTaxonomy.php b/includes/Admin/IconTaxonomy.php similarity index 74% rename from includes/MslsAdminIconTaxonomy.php rename to includes/Admin/IconTaxonomy.php index 311e84585..4bf08c924 100644 --- a/includes/MslsAdminIconTaxonomy.php +++ b/includes/Admin/IconTaxonomy.php @@ -1,6 +1,6 @@ get_post_type(); $this->href = get_edit_term_link( $id, $this->type, $object_type ) ?? ''; @@ -32,9 +32,9 @@ public function set_href( int $id ): MslsAdminIcon { /** * Set the path by type * - * @return MslsAdminIconTaxonomy + * @return IconTaxonomy */ - public function set_path(): MslsAdminIcon { + public function set_path(): Icon { $args = array( 'taxonomy' => $this->type ); $post_type = Taxonomy::instance()->get_post_type(); diff --git a/includes/MslsMetaBox.php b/includes/Admin/MetaBox.php similarity index 95% rename from includes/MslsMetaBox.php rename to includes/Admin/MetaBox.php index 03d2b4712..e420c4075 100644 --- a/includes/MslsMetaBox.php +++ b/includes/Admin/MetaBox.php @@ -1,14 +1,20 @@ ID ); - $origin_language = MslsBlogCollection::get_blog_language(); + $origin_language = Collection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); $this->maybe_set_linked_post( $mydata ); @@ -208,7 +214,7 @@ public function render_select(): void { $language = $blog->get_language(); $icon_type = $this->options->get_icon_type(); - $icon = MslsAdminIcon::create( $type )->set_language( $language )->set_icon_type( $icon_type ); + $icon = Icon::create( $type )->set_language( $language )->set_icon_type( $icon_type ); $linked_post_id = null; if ( $mydata->has_value( $language ) ) { @@ -336,7 +342,7 @@ public function render_input(): void { } $my_data = new Post( $post->ID ); - $origin_language = MslsBlogCollection::get_blog_language(); + $origin_language = Collection::get_blog_language(); $is_saved = 'auto-draft' !== get_post_status( $post ); $this->maybe_set_linked_post( $my_data ); @@ -351,7 +357,7 @@ public function render_input(): void { $language = $blog->get_language(); $icon_type = $this->options->get_icon_type(); - $icon = MslsAdminIcon::create()->set_language( $language )->set_icon_type( $icon_type ); + $icon = Icon::create()->set_language( $language )->set_icon_type( $icon_type ); $value = ''; $title = ''; @@ -439,7 +445,7 @@ private function get_create_new_link( string $type, string $language, int $post_ } if ( msls_options()->activate_quick_create ) { - $action_icon = ( new MslsAdminIcon( $type ) ) + $action_icon = ( new Icon( $type ) ) ->set_language( $language ) ->set_icon_type( 'action' ) ->set_id( $post_id ) @@ -448,7 +454,7 @@ private function get_create_new_link( string $type, string $language, int $post_ return $action_icon->get_a(); } - $action_icon = ( new MslsAdminIcon( $type ) ) + $action_icon = ( new Icon( $type ) ) ->set_language( $language ) ->set_icon_type( 'action' ) ->set_id( $post_id ) diff --git a/includes/MslsPostListActions.php b/includes/Admin/PostListActions.php similarity index 89% rename from includes/MslsPostListActions.php rename to includes/Admin/PostListActions.php index aeefe2989..8c1783bca 100644 --- a/includes/MslsPostListActions.php +++ b/includes/Admin/PostListActions.php @@ -1,21 +1,23 @@ get_request(); - $url = MslsTranslationPickerPage::url( $post_type ); + $url = TranslationPickerPage::url( $post_type ); $label = __( 'Add from Translation', 'multisite-language-switcher' ); $script = sprintf( diff --git a/includes/MslsTranslationPickerPage.php b/includes/Admin/TranslationPicker/Page.php similarity index 95% rename from includes/MslsTranslationPickerPage.php rename to includes/Admin/TranslationPicker/Page.php index 909f4e599..e1bf6758c 100644 --- a/includes/MslsTranslationPickerPage.php +++ b/includes/Admin/TranslationPicker/Page.php @@ -1,8 +1,11 @@ get_columns(); } ); @@ -339,7 +342,7 @@ public static function render(): void { ); echo '
'; - if ( $target instanceof MslsBlog ) { + if ( $target instanceof Blog ) { printf( '

%1$s %2$s %3$s

', esc_html__( 'Creating drafts in:', 'multisite-language-switcher' ), @@ -363,10 +366,10 @@ public static function render(): void { } /** - * @param string $post_type - * @param int $source - * @param string $search - * @param array $blogs + * @param string $post_type + * @param int $source + * @param string $search + * @param array $blogs * * @codeCoverageIgnore */ @@ -398,10 +401,10 @@ private static function render_filter_form( string $post_type, int $source, stri * Renders a row of clickable flag-buttons — one per source blog. * Navigating between sources no longer needs a select + Apply. * - * @param string $post_type - * @param int $source - * @param string $search - * @param array $blogs + * @param string $post_type + * @param int $source + * @param string $search + * @param array $blogs * * @codeCoverageIgnore */ @@ -422,9 +425,9 @@ private static function render_source_flags( string $post_type, int $source, str $blog_id = (int) $blog->userblog_id; $is_active = ( $source === $blog_id ); - $icon = ( new MslsAdminIcon( null ) ) + $icon = ( new Icon( null ) ) ->set_language( $blog->get_language() ) - ->set_icon_type( MslsAdminIcon::TYPE_FLAG ) + ->set_icon_type( Icon::TYPE_FLAG ) ->get_icon(); $url = add_query_arg( @@ -459,7 +462,7 @@ private static function render_list_table( int $source, string $post_type, strin require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } - $table = new MslsTranslationPickerTable( $source, $post_type, $search ); + $table = new Table( $source, $post_type, $search ); $table->prepare_items(); // The form's submit is intercepted client-side and dispatched through diff --git a/includes/MslsTranslationPickerTable.php b/includes/Admin/TranslationPicker/Table.php similarity index 94% rename from includes/MslsTranslationPickerTable.php rename to includes/Admin/TranslationPicker/Table.php index f389315cb..ed4a9b76e 100644 --- a/includes/MslsTranslationPickerTable.php +++ b/includes/Admin/TranslationPicker/Table.php @@ -1,8 +1,10 @@ 'msls_source_post', 'plural' => 'msls_source_posts', 'ajax' => false, - 'screen' => MslsTranslationPickerPage::BASE_SLUG, + 'screen' => Page::BASE_SLUG, ) ); @@ -161,16 +163,16 @@ public function prepare_items(): void { $hidden = get_hidden_columns( $this->screen ); $this->_column_headers = array( $columns, $hidden, array() ); - $target_lang = MslsBlogCollection::get_blog_language( get_current_blog_id() ); + $target_lang = Collection::get_blog_language( get_current_blog_id() ); $current_page = $this->get_pagenum(); - $per_page = (int) $this->get_items_per_page( MslsTranslationPickerPage::PER_PAGE_OPTION, self::PER_PAGE ); + $per_page = (int) $this->get_items_per_page( Page::PER_PAGE_OPTION, self::PER_PAGE ); switch_to_blog( $this->source_blog_id ); // Cache key includes the source blog id so a non-blog-aware object // cache backend can't leak ids from one switched-to blog to another. $cache_params = array( __METHOD__, (string) $this->source_blog_id, $target_lang ); - $translated_ids = ( new TranslatedPostIdQuery( MslsSqlCacher::create( __CLASS__, $cache_params ) ) )( $target_lang ); + $translated_ids = ( new TranslatedPostIdQuery( SqlCacher::create( __CLASS__, $cache_params ) ) )( $target_lang ); $args = array( 'post_type' => $this->post_type, diff --git a/includes/MslsBlog.php b/includes/Blog/Blog.php similarity index 90% rename from includes/MslsBlog.php rename to includes/Blog/Blog.php index fd1427ce2..a918c8cb2 100644 --- a/includes/MslsBlog.php +++ b/includes/Blog/Blog.php @@ -1,6 +1,9 @@ obj = $obj; - $this->language = MslsBlogCollection::get_blog_language( $this->obj->userblog_id ); + $this->language = Collection::get_blog_language( $this->obj->userblog_id ); } $this->description = (string) $description; @@ -82,7 +85,7 @@ public function get_description(): string { * @return string */ public function get_title( string $icon_type = 'flag' ): string { - $icon = ( new MslsAdminIcon( null ) )->set_language( $this->language )->set_icon_type( $icon_type ); + $icon = ( new Icon( null ) )->set_language( $this->language )->set_icon_type( $icon_type ); return sprintf( '%1$s %2$s', @@ -172,24 +175,24 @@ public static function internal_cmp( $a, $b ) { /** * Sort objects by language * - * @param MslsBlog $a - * @param MslsBlog $b + * @param Blog $a + * @param Blog $b * * @return int */ - public static function language( MslsBlog $a, MslsBlog $b ) { + public static function language( Blog $a, Blog $b ) { return self::internal_cmp( $a->get_language(), $b->get_language() ); } /** * Sort objects by description * - * @param MslsBlog $a - * @param MslsBlog $b + * @param Blog $a + * @param Blog $b * * @return int */ - public static function description( MslsBlog $a, MslsBlog $b ) { + public static function description( Blog $a, Blog $b ) { return self::internal_cmp( $a->get_description(), $b->get_description() ); } diff --git a/includes/MslsBlogCollection.php b/includes/Blog/Collection.php similarity index 90% rename from includes/MslsBlogCollection.php rename to includes/Blog/Collection.php index 918810a7d..c1c8f0a1b 100644 --- a/includes/MslsBlogCollection.php +++ b/includes/Blog/Collection.php @@ -1,11 +1,14 @@ objects[ $blog->userblog_id ] = new MslsBlog( $blog, $description ); + $this->objects[ $blog->userblog_id ] = new Blog( $blog, $description ); } } - $compare = array( MslsBlog::class, $this->objects_order ); + $compare = array( Blog::class, $this->objects_order ); if ( is_callable( $compare ) ) { uasort( $this->objects, $compare ); } @@ -151,7 +154,7 @@ public function get_blogs_of_reference_user( Options $options ) { * * @param string $language * - * @return MslsBlog|null + * @return Blog|null */ public function get_blog( $language ) { $blog = null; @@ -192,11 +195,11 @@ public function get_current_blog_id() { /** * Checks if blog is the current blog * - * @param MslsBlog $blog + * @param Blog $blog * * @return bool */ - public function is_current_blog( MslsBlog $blog ) { + public function is_current_blog( Blog $blog ) { return $blog->userblog_id === $this->get_current_blog_id(); } @@ -212,7 +215,7 @@ public function has_current_blog() { /** * Gets current blog as object * - * @return MslsBlog|null + * @return Blog|null */ public function get_current_blog() { return $this->has_current_blog() ? $this->objects[ $this->get_current_blog_id() ] : null; @@ -221,7 +224,7 @@ public function get_current_blog() { /** * Gets an array with all blog-objects * - * @return MslsBlog[] + * @return Blog[] */ public function get_objects(): array { return apply_filters( 'msls_blog_collection_get_objects', $this->objects ); @@ -232,9 +235,9 @@ public function get_objects(): array { * * @param int $blog_id * - * @return ?MslsBlog + * @return ?Blog */ - public function get_object( int $blog_id ): ?MslsBlog { + public function get_object( int $blog_id ): ?Blog { return $this->get_objects()[ $blog_id ] ?? null; } @@ -263,7 +266,7 @@ public function is_plugin_active( $blog_id ) { /** * Gets only blogs where the plugin is active * - * @return MslsBlog[] + * @return Blog[] */ public function get_plugin_active_blogs() { $arr = array(); @@ -280,7 +283,7 @@ public function get_plugin_active_blogs() { /** * Gets an array of all - but not the current - blog-objects * - * @return MslsBlog[] + * @return Blog[] */ public function get() { $objects = $this->get_objects(); @@ -297,7 +300,7 @@ public function get() { * * @param bool $filter * - * @return MslsBlog[] + * @return Blog[] */ public function get_filtered( bool $filter = false ): array { return ! $filter && $this->current_blog_output ? $this->get_objects() : $this->get(); @@ -311,12 +314,12 @@ public function get_filtered( bool $filter = false ): array { * * @return array */ - public function get_users( $fields = 'all', int $number = MslsAdmin::MAX_REFERENCE_USERS ): array { + public function get_users( $fields = 'all', int $number = Admin::MAX_REFERENCE_USERS ): array { $args = array( 'blog_id' => $this->current_blog_id, 'orderby' => 'registered', 'fields' => $fields, - 'number' => $number > 0 ? $number : MslsAdmin::MAX_REFERENCE_USERS, + 'number' => $number > 0 ? $number : Admin::MAX_REFERENCE_USERS, 'count_total' => false, ); diff --git a/includes/MslsCli.php b/includes/Cli/Cli.php similarity index 95% rename from includes/MslsCli.php rename to includes/Cli/Cli.php index f71c1a3f9..144f3bdd7 100644 --- a/includes/MslsCli.php +++ b/includes/Cli/Cli.php @@ -1,8 +1,8 @@ get_the_blog_post_ID( $dest_blog_id ); diff --git a/includes/ContentImport/ImportCoordinates.php b/includes/ContentImport/ImportCoordinates.php index 9a18455cf..570b2081c 100644 --- a/includes/ContentImport/ImportCoordinates.php +++ b/includes/ContentImport/ImportCoordinates.php @@ -2,7 +2,7 @@ namespace lloc\Msls\ContentImport; -use lloc\Msls\MslsBlogCollection; +use lloc\Msls\Blog\Collection; class ImportCoordinates { @@ -64,10 +64,10 @@ public function validate() { return false; } - if ( MslsBlogCollection::get_blog_language( $this->source_blog_id ) !== $this->source_lang ) { + if ( Collection::get_blog_language( $this->source_blog_id ) !== $this->source_lang ) { return false; } - if ( MslsBlogCollection::get_blog_language( $this->dest_blog_id ) !== $this->dest_lang ) { + if ( Collection::get_blog_language( $this->dest_blog_id ) !== $this->dest_lang ) { return false; } diff --git a/includes/ContentImport/Importers/ImportersBaseFactory.php b/includes/ContentImport/Importers/ImportersBaseFactory.php index 885de3496..c26fec4ea 100644 --- a/includes/ContentImport/Importers/ImportersBaseFactory.php +++ b/includes/ContentImport/Importers/ImportersBaseFactory.php @@ -3,9 +3,9 @@ namespace lloc\Msls\ContentImport\Importers; use lloc\Msls\ContentImport\ImportCoordinates; -use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\Registry\Instance; -abstract class ImportersBaseFactory extends MslsRegistryInstance implements ImportersFactory { +abstract class ImportersBaseFactory extends Instance implements ImportersFactory { /** * The type of this importers factory; should be overridden by child classes. diff --git a/includes/ContentImport/Importers/Map.php b/includes/ContentImport/Importers/Map.php index 2a8666390..0813ae3d0 100644 --- a/includes/ContentImport/Importers/Map.php +++ b/includes/ContentImport/Importers/Map.php @@ -3,9 +3,9 @@ namespace lloc\Msls\ContentImport\Importers; use lloc\Msls\ContentImport\ImportCoordinates; -use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\Registry\Instance; -class Map extends MslsRegistryInstance { +class Map extends Instance { /** * Builds and returns an array of importers for the specified import coordinates. * diff --git a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php index ec297b2b0..4487c1edb 100644 --- a/includes/ContentImport/Importers/Terms/ShallowDuplicating.php +++ b/includes/ContentImport/Importers/Terms/ShallowDuplicating.php @@ -4,8 +4,8 @@ use lloc\Msls\ContentImport\ImportCoordinates; use lloc\Msls\ContentImport\Importers\BaseImporter; +use lloc\Msls\Options\Tax\OptionsTaxInterface; use lloc\Msls\Options\Tax\Term; -use lloc\Msls\OptionsTaxInterface; /** * Class ShallowDuplicating diff --git a/includes/ContentImport/LogWriters/AdminNoticeLogger.php b/includes/ContentImport/LogWriters/AdminNoticeLogger.php index bbf4fa4b7..390241ec9 100644 --- a/includes/ContentImport/LogWriters/AdminNoticeLogger.php +++ b/includes/ContentImport/LogWriters/AdminNoticeLogger.php @@ -4,9 +4,9 @@ use lloc\Msls\Component\Component; use lloc\Msls\ContentImport\ImportCoordinates; -use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\Registry\Instance; -class AdminNoticeLogger extends MslsRegistryInstance implements LogWriter { +class AdminNoticeLogger extends Instance implements LogWriter { /** * The transient where the last import log will be stored. diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index 044b6f83b..e1f96ef31 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -2,17 +2,17 @@ namespace lloc\Msls\ContentImport; +use lloc\Msls\Blog\Collection; use lloc\Msls\Component\Component; use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\Importers\Map; -use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; use lloc\Msls\MslsPlugin; -use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\Registry\Instance; use lloc\Msls\MslsRequest; use lloc\Msls\Options\Post\Post; -class MetaBox extends MslsRegistryInstance { +class MetaBox extends Instance { /** * @var array @@ -30,7 +30,7 @@ public function render(): void { $mydata = new Post( $post->ID ); $languages = Post::instance()->get_available_languages(); - $current = MslsBlogCollection::get_blog_language( get_current_blog_id() ); + $current = Collection::get_blog_language( get_current_blog_id() ); $languages = array_diff_key( $languages, array( $current => $current ) ); $input_lang = MslsRequest::get( MslsFields::FIELD_MSLS_LANG, null ); $input_id = MslsRequest::get( MslsFields::FIELD_MSLS_ID, null ); diff --git a/includes/ContentImport/Relations.php b/includes/ContentImport/Relations.php index 44f94b048..e1544ff3b 100644 --- a/includes/ContentImport/Relations.php +++ b/includes/ContentImport/Relations.php @@ -3,8 +3,8 @@ namespace lloc\Msls\ContentImport; use lloc\Msls\Options\Options; -use lloc\Msls\OptionsInterface; -use lloc\Msls\OptionsTaxInterface; +use lloc\Msls\Options\OptionsInterface; +use lloc\Msls\Options\Tax\OptionsTaxInterface; /** * Class Relations diff --git a/includes/ContentImport/Service.php b/includes/ContentImport/Service.php index c0c99618f..2081d2bbd 100644 --- a/includes/ContentImport/Service.php +++ b/includes/ContentImport/Service.php @@ -7,7 +7,7 @@ } use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger; -use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\Registry\Instance; /** * Class Service @@ -16,7 +16,7 @@ * * @package lloc\Msls\ContentImport */ -class Service extends MslsRegistryInstance { +class Service extends Instance { /** * Hooks the classes that provide the content import functionality if the content import option is active. diff --git a/includes/ContentTypes/ContentTypes.php b/includes/ContentTypes/ContentTypes.php index c3f9b3b45..8c5a7ace0 100644 --- a/includes/ContentTypes/ContentTypes.php +++ b/includes/ContentTypes/ContentTypes.php @@ -2,7 +2,7 @@ namespace lloc\Msls\ContentTypes; -use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\Registry\Instance; use lloc\Msls\MslsRequest; /** @@ -10,7 +10,7 @@ * * @package Msls */ -abstract class ContentTypes extends MslsRegistryInstance { +abstract class ContentTypes extends Instance { /** * Request diff --git a/includes/Db/Query/AbstractQuery.php b/includes/Db/Query/AbstractQuery.php new file mode 100644 index 000000000..724987c5a --- /dev/null +++ b/includes/Db/Query/AbstractQuery.php @@ -0,0 +1,29 @@ +sql_cache = $sql_cache; + } +} diff --git a/includes/Query/AuthorPostsCounterQuery.php b/includes/Db/Query/AuthorPostsCounterQuery.php similarity index 94% rename from includes/Query/AuthorPostsCounterQuery.php rename to includes/Db/Query/AuthorPostsCounterQuery.php index 81178b56f..e856d22e5 100644 --- a/includes/Query/AuthorPostsCounterQuery.php +++ b/includes/Db/Query/AuthorPostsCounterQuery.php @@ -1,6 +1,6 @@ ', $post = '

' ) { - $links_arr = MslsOutput::create()->get( 1, true, true ); + $links_arr = Output::create()->get( 1, true, true ); $links_str = $this->format_available_languages( $links_arr ); /* translators: %s: list of languages */ diff --git a/includes/Map/HrefLang.php b/includes/Frontend/Map/HrefLang.php similarity index 87% rename from includes/Map/HrefLang.php rename to includes/Frontend/Map/HrefLang.php index 297a91d65..ec2638939 100644 --- a/includes/Map/HrefLang.php +++ b/includes/Frontend/Map/HrefLang.php @@ -1,13 +1,13 @@ get_objects() as $blog ) { $map[ $blog->get_alpha2() ][] = $blog->get_language(); diff --git a/includes/MslsOutput.php b/includes/Frontend/Output.php similarity index 93% rename from includes/MslsOutput.php rename to includes/Frontend/Output.php index 8a2fc5a66..95186e510 100644 --- a/includes/MslsOutput.php +++ b/includes/Frontend/Output.php @@ -1,17 +1,20 @@ tags = wp_parse_args( $this->get_tags(), $arr ); return $this; diff --git a/includes/MslsShortCode.php b/includes/Frontend/ShortCode.php similarity index 89% rename from includes/MslsShortCode.php rename to includes/Frontend/ShortCode.php index 6e21db094..2b7ac71f3 100644 --- a/includes/MslsShortCode.php +++ b/includes/Frontend/ShortCode.php @@ -1,8 +1,8 @@ diff --git a/includes/MslsMain.php b/includes/MslsMain.php index 7de12e335..98a634848 100644 --- a/includes/MslsMain.php +++ b/includes/MslsMain.php @@ -2,6 +2,8 @@ namespace lloc\Msls; +use lloc\Msls\Blog\Blog; +use lloc\Msls\Blog\Collection; use lloc\Msls\Component\Component; use lloc\Msls\Options\Options; use lloc\Msls\Options\Post\Post; @@ -25,17 +27,17 @@ class MslsMain { /** * Collection of blog objects * - * @var MslsBlogCollection + * @var Collection */ protected $collection; /** * Constructor * - * @param Options $options - * @param MslsBlogCollection $collection + * @param Options $options + * @param Collection $collection */ - final public function __construct( Options $options, MslsBlogCollection $collection ) { + final public function __construct( Options $options, Collection $collection ) { $this->options = $options; $this->collection = $collection; } @@ -148,7 +150,7 @@ protected function save( $object_id, $class_name ): void { } $current_blog = $this->collection->get_current_blog(); - if ( ! $current_blog instanceof MslsBlog ) { + if ( ! $current_blog instanceof Blog ) { $this->debugger( 'BlogCollection returns false when calling has_current_blog.' ); return; diff --git a/includes/MslsPlugin.php b/includes/MslsPlugin.php index 5e89a27dc..6bb1d21fc 100644 --- a/includes/MslsPlugin.php +++ b/includes/MslsPlugin.php @@ -6,9 +6,24 @@ exit; } +use lloc\Msls\Admin\Admin; +use lloc\Msls\Admin\Bar as AdminBar; +use lloc\Msls\Admin\CustomColumn; +use lloc\Msls\Admin\CustomColumnTaxonomy; +use lloc\Msls\Admin\CustomFilter; +use lloc\Msls\Admin\MetaBox; +use lloc\Msls\Admin\PostListActions; +use lloc\Msls\Frontend\Block; +use lloc\Msls\Frontend\ContentFilter; +use lloc\Msls\Frontend\ShortCode; +use lloc\Msls\Frontend\Widget; +use lloc\Msls\Db\SqlCacher; +use lloc\Msls\Db\Query\BlogsInNetworkQuery; +use lloc\Msls\Db\Query\CleanupOptionsQuery; use lloc\Msls\Options\Options; -use lloc\Msls\Query\BlogsInNetworkQuery; -use lloc\Msls\Query\CleanupOptionsQuery; +use lloc\Msls\PostTag\PostTag; +use lloc\Msls\RestApi\RestApi; +use lloc\Msls\Admin\TranslationPicker\Page as TranslationPickerPage; /** * Provides functionalities for general hooks and activation/deactivation @@ -45,12 +60,12 @@ public static function init(): void { add_action( 'admin_enqueue_scripts', array( $obj, 'custom_enqueue' ) ); add_action( 'wp_enqueue_scripts', array( $obj, 'custom_enqueue' ) ); - add_action( 'rest_api_init', array( MslsRestApi::class, 'init' ) ); - add_action( 'init', array( MslsAdminBar::class, 'init' ) ); - add_action( 'init', array( MslsBlock::class, 'init' ) ); - add_action( 'init', array( MslsShortCode::class, 'init' ) ); - add_action( 'init', array( MslsContentFilter::class, 'init' ) ); - add_action( 'widgets_init', array( MslsWidget::class, 'init' ) ); + add_action( 'rest_api_init', array( RestApi::class, 'init' ) ); + add_action( 'init', array( AdminBar::class, 'init' ) ); + add_action( 'init', array( Block::class, 'init' ) ); + add_action( 'init', array( ShortCode::class, 'init' ) ); + add_action( 'init', array( ContentFilter::class, 'init' ) ); + add_action( 'widgets_init', array( Widget::class, 'init' ) ); add_action( 'wp_head', array( __CLASS__, 'print_alternate_links' ) ); add_filter( 'msls_get_output', 'msls_output' ); @@ -58,34 +73,34 @@ public static function init(): void { \lloc\Msls\ContentImport\Service::instance()->register(); if ( is_admin() ) { - add_action( 'admin_menu', array( MslsAdmin::class, 'init' ) ); - MslsTranslationPickerPage::init(); - add_action( 'load-post.php', array( MslsMetaBox::class, 'init' ) ); - add_action( 'load-post-new.php', array( MslsMetaBox::class, 'init' ) ); - add_action( 'load-edit.php', array( MslsCustomColumn::class, 'init' ) ); - add_action( 'load-edit.php', array( MslsCustomFilter::class, 'init' ) ); - add_action( 'load-edit.php', array( MslsPostListActions::class, 'init' ) ); - - add_action( 'load-edit-tags.php', array( MslsCustomColumnTaxonomy::class, 'init' ) ); - add_action( 'load-edit-tags.php', array( MslsPostTag::class, 'init' ) ); - add_action( 'load-term.php', array( MslsPostTag::class, 'init' ) ); + add_action( 'admin_menu', array( Admin::class, 'init' ) ); + TranslationPickerPage::init(); + add_action( 'load-post.php', array( MetaBox::class, 'init' ) ); + add_action( 'load-post-new.php', array( MetaBox::class, 'init' ) ); + add_action( 'load-edit.php', array( CustomColumn::class, 'init' ) ); + add_action( 'load-edit.php', array( CustomFilter::class, 'init' ) ); + add_action( 'load-edit.php', array( PostListActions::class, 'init' ) ); + + add_action( 'load-edit-tags.php', array( CustomColumnTaxonomy::class, 'init' ) ); + add_action( 'load-edit-tags.php', array( PostTag::class, 'init' ) ); + add_action( 'load-term.php', array( PostTag::class, 'init' ) ); if ( MslsRequest::has_var( MslsFields::FIELD_ACTION ) ) { switch ( MslsRequest::get_var( MslsFields::FIELD_ACTION ) ) { case 'add-tag': - add_action( 'admin_init', array( MslsPostTag::class, 'init' ) ); + add_action( 'admin_init', array( PostTag::class, 'init' ) ); break; case 'inline-save': - add_action( 'admin_init', array( MslsCustomColumn::class, 'init' ) ); + add_action( 'admin_init', array( CustomColumn::class, 'init' ) ); break; case 'inline-save-tax': - add_action( 'admin_init', array( MslsCustomColumnTaxonomy::class, 'init' ) ); + add_action( 'admin_init', array( CustomColumnTaxonomy::class, 'init' ) ); break; } } - add_action( 'wp_ajax_suggest_posts', array( MslsMetaBox::class, 'suggest' ) ); - add_action( 'wp_ajax_suggest_terms', array( MslsPostTag::class, 'suggest' ) ); + add_action( 'wp_ajax_suggest_posts', array( MetaBox::class, 'suggest' ) ); + add_action( 'wp_ajax_suggest_terms', array( PostTag::class, 'suggest' ) ); } } else { add_action( @@ -227,7 +242,7 @@ public static function uninstall(): void { * restore_current_blog */ if ( function_exists( 'is_multisite' ) && is_multisite() ) { - $sql_cache = MslsSqlCacher::create( __CLASS__, __METHOD__ ); + $sql_cache = SqlCacher::create( __CLASS__, __METHOD__ ); $blog_ids = ( new BlogsInNetworkQuery( $sql_cache ) )(); foreach ( $blog_ids as $new_blog_id ) { @@ -250,7 +265,7 @@ public static function uninstall(): void { */ public static function cleanup() { if ( delete_option( 'msls' ) ) { - $sql_cache = MslsSqlCacher::create( __CLASS__, __METHOD__ ); + $sql_cache = SqlCacher::create( __CLASS__, __METHOD__ ); return ( new CleanupOptionsQuery( $sql_cache ) )(); } diff --git a/includes/Options/Options.php b/includes/Options/Options.php index 1b371a689..fcef6f393 100644 --- a/includes/Options/Options.php +++ b/includes/Options/Options.php @@ -6,14 +6,13 @@ exit; } +use lloc\Msls\Admin\Icon as AdminIcon; use lloc\Msls\Component\Icon\IconPng; -use lloc\Msls\MslsAdminIcon; use lloc\Msls\MslsGetSet; use lloc\Msls\MslsPlugin; use lloc\Msls\Options\Post\Post; use lloc\Msls\Options\Query\Query; use lloc\Msls\Options\Tax\Tax; -use lloc\Msls\OptionsInterface; /** * General options class @@ -448,6 +447,6 @@ public static function check_for_blog_slug( $url, $options ) { * @return string */ public function get_icon_type(): string { - return MslsAdminIcon::TYPE_LABEL === $this->admin_display ? MslsAdminIcon::TYPE_LABEL : MslsAdminIcon::TYPE_FLAG; + return AdminIcon::TYPE_LABEL === $this->admin_display ? AdminIcon::TYPE_LABEL : AdminIcon::TYPE_FLAG; } } diff --git a/includes/OptionsInterface.php b/includes/Options/OptionsInterface.php similarity index 88% rename from includes/OptionsInterface.php rename to includes/Options/OptionsInterface.php index fff1bd268..8775e53f3 100644 --- a/includes/OptionsInterface.php +++ b/includes/Options/OptionsInterface.php @@ -1,6 +1,6 @@ author_id = self::get_params()['author_id']; diff --git a/includes/Options/Query/Day.php b/includes/Options/Query/Day.php index e7ea6ec8c..9f6558465 100644 --- a/includes/Options/Query/Day.php +++ b/includes/Options/Query/Day.php @@ -2,8 +2,8 @@ namespace lloc\Msls\Options\Query; -use lloc\Msls\MslsSqlCacher; -use lloc\Msls\Query\DatePostsCounterQuery; +use lloc\Msls\Db\SqlCacher; +use lloc\Msls\Db\Query\DatePostsCounterQuery; /** * OptionsQueryDay @@ -27,7 +27,7 @@ class Day extends Query { */ protected int $day; - public function __construct( MslsSqlCacher $sql_cache ) { + public function __construct( SqlCacher $sql_cache ) { parent::__construct( $sql_cache ); $params = self::get_params(); diff --git a/includes/Options/Query/Month.php b/includes/Options/Query/Month.php index 1f7500992..ff42d6760 100644 --- a/includes/Options/Query/Month.php +++ b/includes/Options/Query/Month.php @@ -2,8 +2,8 @@ namespace lloc\Msls\Options\Query; -use lloc\Msls\MslsSqlCacher; -use lloc\Msls\Query\MonthPostsCounterQuery; +use lloc\Msls\Db\SqlCacher; +use lloc\Msls\Db\Query\MonthPostsCounterQuery; /** * OptionsQueryMonth @@ -22,7 +22,7 @@ class Month extends Query { */ protected int $monthnum; - public function __construct( MslsSqlCacher $sql_cache ) { + public function __construct( SqlCacher $sql_cache ) { parent::__construct( $sql_cache ); $params = self::get_params(); diff --git a/includes/Options/Query/PostType.php b/includes/Options/Query/PostType.php index 70862f3d7..324cafa00 100644 --- a/includes/Options/Query/PostType.php +++ b/includes/Options/Query/PostType.php @@ -2,7 +2,7 @@ namespace lloc\Msls\Options\Query; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; /** * OptionsQueryPostType @@ -18,7 +18,7 @@ class PostType extends Query { */ protected string $post_type; - public function __construct( MslsSqlCacher $sql_cache ) { + public function __construct( SqlCacher $sql_cache ) { parent::__construct( $sql_cache ); $this->post_type = self::get_params()['post_type']; diff --git a/includes/Options/Query/Query.php b/includes/Options/Query/Query.php index 848b5221a..80be9f52c 100644 --- a/includes/Options/Query/Query.php +++ b/includes/Options/Query/Query.php @@ -2,7 +2,7 @@ namespace lloc\Msls\Options\Query; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Options; /** @@ -20,11 +20,11 @@ class Query extends Options { public ?bool $with_front = true; /** - * @var MslsSqlCacher + * @var SqlCacher */ - protected MslsSqlCacher $sql_cache; + protected SqlCacher $sql_cache; - public function __construct( MslsSqlCacher $sql_cache ) { + public function __construct( SqlCacher $sql_cache ) { parent::__construct(); $this->sql_cache = $sql_cache; @@ -61,7 +61,7 @@ public static function create( $id = 0 ): ?Query { return null; } - $sql_cache = MslsSqlCacher::create( $query_class, $query_class::get_params() ); + $sql_cache = SqlCacher::create( $query_class, $query_class::get_params() ); return new $query_class( $sql_cache ); } diff --git a/includes/Options/Query/Year.php b/includes/Options/Query/Year.php index a09aa2246..64cc21546 100644 --- a/includes/Options/Query/Year.php +++ b/includes/Options/Query/Year.php @@ -2,8 +2,8 @@ namespace lloc\Msls\Options\Query; -use lloc\Msls\MslsSqlCacher; -use lloc\Msls\Query\YearPostsCounterQuery; +use lloc\Msls\Db\SqlCacher; +use lloc\Msls\Db\Query\YearPostsCounterQuery; /** * OptionsQueryYear @@ -22,9 +22,9 @@ class Year extends Query { /** * Constructor. * - * @param MslsSqlCacher $sql_cache The SQL Cacher instance. + * @param SqlCacher $sql_cache The SQL Cacher instance. */ - public function __construct( MslsSqlCacher $sql_cache ) { + public function __construct( SqlCacher $sql_cache ) { parent::__construct( $sql_cache ); $this->year = self::get_params()['year']; diff --git a/includes/Options/Tax/Category.php b/includes/Options/Tax/Category.php index a3500e028..5096a58f5 100644 --- a/includes/Options/Tax/Category.php +++ b/includes/Options/Tax/Category.php @@ -2,8 +2,6 @@ namespace lloc\Msls\Options\Tax; -use lloc\Msls\OptionsTaxInterface; - /** * OptionsTaxTermCategory * diff --git a/includes/OptionsTaxInterface.php b/includes/Options/Tax/OptionsTaxInterface.php similarity index 73% rename from includes/OptionsTaxInterface.php rename to includes/Options/Tax/OptionsTaxInterface.php index 10b1476ae..e2fb9efe9 100644 --- a/includes/OptionsTaxInterface.php +++ b/includes/Options/Tax/OptionsTaxInterface.php @@ -1,6 +1,8 @@ userblog_id ); $language = $blog->get_language(); $icon_type = $this->options->get_icon_type(); - $icon = MslsAdminIcon::create()->set_language( $language )->set_icon_type( $icon_type ); + $icon = Icon::create()->set_language( $language )->set_icon_type( $icon_type ); if ( $mydata->has_value( $language ) ) { $icon->set_href( (int) $mydata->$language ); diff --git a/includes/MslsPostTag.php b/includes/PostTag/PostTag.php similarity index 95% rename from includes/MslsPostTag.php rename to includes/PostTag/PostTag.php index f9ff10a10..dea361e7f 100644 --- a/includes/MslsPostTag.php +++ b/includes/PostTag/PostTag.php @@ -1,12 +1,18 @@ activate_autocomplete ? self::class : MslsPostTagClassic::class; + $class = $options->activate_autocomplete ? self::class : Classic::class; $obj = new $class( $options, $collection ); $taxonomy = msls_content_types()->acl_request(); @@ -208,7 +214,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo $language = $blog->get_language(); $icon_type = $this->options->get_icon_type(); - $icon = MslsAdminIcon::create()->set_language( $language )->set_icon_type( $icon_type ); + $icon = Icon::create()->set_language( $language )->set_icon_type( $icon_type ); $value = ''; $title = ''; diff --git a/includes/Query/AbstractQuery.php b/includes/Query/AbstractQuery.php deleted file mode 100644 index 1492b8153..000000000 --- a/includes/Query/AbstractQuery.php +++ /dev/null @@ -1,29 +0,0 @@ -sql_cache = $sql_cache; - } -} diff --git a/includes/MslsRegistryInstance.php b/includes/Registry/Instance.php similarity index 54% rename from includes/MslsRegistryInstance.php rename to includes/Registry/Instance.php index d41b50b22..1f29f7c2a 100644 --- a/includes/MslsRegistryInstance.php +++ b/includes/Registry/Instance.php @@ -1,13 +1,13 @@ prepare_post_data( $source_post ); $post_data = $this->prepare_taxonomies( $source_post, $source_blog_id, $target_blog_id, $target_lang, $post_data ); @@ -384,7 +386,7 @@ public function list_untranslated_posts( \WP_REST_Request $request ) { $post_type = (string) $request->get_param( 'post_type' ); $search = (string) $request->get_param( 'search' ); - $target_lang = MslsBlogCollection::get_blog_language( $target_blog_id ); + $target_lang = Collection::get_blog_language( $target_blog_id ); switch_to_blog( $source_blog_id ); @@ -398,7 +400,7 @@ public function list_untranslated_posts( \WP_REST_Request $request ) { ); } - $translated_ids = ( new TranslatedPostIdQuery( MslsSqlCacher::create( __CLASS__, __METHOD__ ) ) )( $target_lang ); + $translated_ids = ( new TranslatedPostIdQuery( SqlCacher::create( __CLASS__, __METHOD__ ) ) )( $target_lang ); $query_args = array( 'post_type' => $post_type, @@ -478,7 +480,7 @@ protected function prepare_post_data( \WP_Post $source_post ): array { * @return array */ public static function prefix_source_language( array $post_data, \WP_Post $source_post, int $source_blog_id, int $target_blog_id ): array { - $lang_code = substr( MslsBlogCollection::get_blog_language( $source_blog_id ), 0, 2 ); + $lang_code = substr( Collection::get_blog_language( $source_blog_id ), 0, 2 ); $post_data['post_title'] = sprintf( /* translators: 1: language code, 2: original post title */ @@ -585,8 +587,8 @@ protected function establish_link( int $target_blog_id ): void { $collection = msls_blog_collection(); - $source_lang = MslsBlogCollection::get_blog_language( $source_blog_id ); - $target_lang = MslsBlogCollection::get_blog_language( $target_blog_id ); + $source_lang = Collection::get_blog_language( $source_blog_id ); + $target_lang = Collection::get_blog_language( $target_blog_id ); // Read existing links from the source post switch_to_blog( $source_blog_id ); diff --git a/includes/aliases.php b/includes/aliases.php index 45140f021..259ef4208 100644 --- a/includes/aliases.php +++ b/includes/aliases.php @@ -1,10 +1,13 @@ justReturn( array() ); Functions\when( 'update_option' )->justReturn( true ); Functions\when( 'get_current_blog_id' )->justReturn( 1 ); @@ -24,7 +25,7 @@ private function MslsAdminFactory( array $users = array() ): MslsAdmin { $options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE', 'it_IT' ) ); $options->shouldReceive( 'get_icon_type' )->andReturns( 'flag' ); - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_title' )->andReturns( 'abc (DEF)' ); $blog->shouldReceive( 'get_description' )->andReturns( 'DEF' ); $blog->userblog_id = 1; @@ -32,7 +33,7 @@ private function MslsAdminFactory( array $users = array() ): MslsAdmin { $blogs[] = $blog; - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_title' )->andReturns( 'uvw (XYZ)' ); $blog->shouldReceive( 'get_description' )->andReturns( 'XYZ' ); $blog->userblog_id = 2; @@ -48,12 +49,12 @@ private function MslsAdminFactory( array $users = array() ): MslsAdmin { ); } - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog_id' )->andReturns( 1 ); $collection->shouldReceive( 'get_plugin_active_blogs' )->andReturns( $blogs ); $collection->shouldReceive( 'get_users' )->andReturns( $users ); - return new MslsAdmin( $options, $collection ); + return new Admin( $options, $collection ); } public static function has_problems_data(): array { @@ -75,16 +76,16 @@ public function test_has_problems( array $languages, bool $is_empty, string $reg $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_available_languages' )->zeroOrMoreTimes()->andReturns( $languages ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $options->shouldReceive( 'is_empty' )->once()->andReturns( $is_empty ); $this->expectOutputRegex( $regex ); - ( new MslsAdmin( $options, $collection ) )->has_problems(); + ( new Admin( $options, $collection ) )->has_problems(); } public function test_subsubsub(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $expected = ''; @@ -92,14 +93,14 @@ public function test_subsubsub(): void { } public function test_blog_language(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputRegex( '/^' @@ -108,7 +109,7 @@ public function test_display(): void { } public function test_admin_display(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( '' @@ -119,14 +120,14 @@ public function test_admin_display(): void { public function test_reference_user_over_max(): void { $users = array( 1 => 'realloc' ); Functions\expect( 'wp_list_pluck' )->once()->andReturn( $users ); - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputRegex( '/^ ' @@ -135,7 +136,7 @@ public function test_activate_autocomplete(): void { } public function test_sort_by_description(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( ' ' @@ -145,7 +146,7 @@ public function test_sort_by_description(): void { public function test_exclude_current_blog(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( ' ' @@ -154,7 +155,7 @@ public function test_exclude_current_blog(): void { } function test_only_with_translation(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( ' ' @@ -163,7 +164,7 @@ function test_only_with_translation(): void { } function test_output_current_blog(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( ' ' @@ -172,7 +173,7 @@ function test_output_current_blog(): void { } function test_description(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( '' @@ -181,7 +182,7 @@ function test_description(): void { } function test_before_output(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( '' @@ -190,7 +191,7 @@ function test_before_output(): void { } function test_after_output(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( '' @@ -199,7 +200,7 @@ function test_after_output(): void { } function test_before_item(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( '' @@ -208,7 +209,7 @@ function test_before_item(): void { } function test_after_item(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( '' @@ -217,7 +218,7 @@ function test_after_item(): void { } function test_rewrite_tizio(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $post_type = \Mockery::mock( \WP_Post_Type::class ); $post_type->rewrite = false; @@ -231,7 +232,7 @@ function test_rewrite_tizio(): void { } function test_rewrite_pinko(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $post_type = \Mockery::mock( \WP_Post_Type::class ); $post_type->rewrite = true; // this should not be possible @@ -245,7 +246,7 @@ function test_rewrite_pinko(): void { } function test_rewrite_pallino(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $post_type = \Mockery::mock( \WP_Post_Type::class ); $post_type->rewrite = array( 'slug' => 'pallino_slug' ); @@ -259,7 +260,7 @@ function test_rewrite_pallino(): void { } function test_content_filter(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputString( ' ' @@ -268,14 +269,14 @@ function test_content_filter(): void { } function test_content_priority(): void { - $obj = $this->MslsAdminFactory(); + $obj = $this->AdminFactory(); $this->expectOutputRegex( '/^' ); - $test = $this->MslsCustomFilterFactory(); + $test = $this->CustomFilterFactory(); $test->add_filter(); } @@ -89,7 +90,7 @@ public function test_add_no_selected_blog(): void { $this->expectOutputString( '' ); - $test = $this->MslsCustomFilterFactory(); + $test = $this->CustomFilterFactory(); $test->add_filter(); } } diff --git a/tests/phpunit/TestMslsAdminIcon.php b/tests/phpunit/Admin/TestIcon.php similarity index 83% rename from tests/phpunit/TestMslsAdminIcon.php rename to tests/phpunit/Admin/TestIcon.php index 77e4d5935..d28aeb852 100644 --- a/tests/phpunit/TestMslsAdminIcon.php +++ b/tests/phpunit/Admin/TestIcon.php @@ -1,11 +1,12 @@ post_type ) ) + private function IconFactory( $post ): Icon { + return ( new Icon( $post->post_type ) ) ->set_path() ->set_language( $this->lang ) ->set_src( $this->src ) @@ -59,7 +60,7 @@ public function test_get_a_not_empty_post(): void { Functions\expect( 'get_edit_post_link' )->once()->andReturn( $edit_link ); $post = $this->get_post( $post_type, 2 ); - $obj = $this->MslsAdminIconFactory( $post ); + $obj = $this->IconFactory( $post ); $value = ' '; $this->assertEquals( $value, $obj->get_a() ); @@ -73,7 +74,7 @@ public function test_get_a_not_empty_page(): void { Functions\expect( 'get_edit_post_link' )->once()->andReturn( $edit_link ); $post = $this->get_post( $post_type, 2 ); - $obj = $this->MslsAdminIconFactory( $post ); + $obj = $this->IconFactory( $post ); $value = ' '; $this->assertEquals( $value, $obj->get_a() ); @@ -88,9 +89,9 @@ public function test_get_a_empty_post(): void { Functions\expect( 'get_edit_post_link' )->twice()->andReturn( null ); $post = $this->get_post( $post_type ); - $obj = $this->MslsAdminIconFactory( $post ); + $obj = $this->IconFactory( $post ); - $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_href( 0 ) ); + $this->assertInstanceOf( Icon::class, $obj->set_href( 0 ) ); $value = sprintf( ' ', @@ -109,9 +110,9 @@ public function test_get_a_empty_page(): void { Functions\expect( 'get_edit_post_link' )->twice()->andReturn( null ); $post = $this->get_post( $post_type ); - $obj = $this->MslsAdminIconFactory( $post ); + $obj = $this->IconFactory( $post ); - $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_href( 0 ) ); + $this->assertInstanceOf( Icon::class, $obj->set_href( 0 ) ); $value = sprintf( ' ', @@ -129,7 +130,7 @@ public function test_get_img_post(): void { Functions\expect( 'get_edit_post_link' )->once()->andReturn( $edit_link ); $post = $this->get_post( $post_type ); - $obj = $this->MslsAdminIconFactory( $post ); + $obj = $this->IconFactory( $post ); $this->assertEquals( 'de_DE', $obj->get_img() ); $this->assertIsSTring( $obj->get_edit_new() ); @@ -145,7 +146,7 @@ public function test_get_img_post_page(): void { Functions\expect( 'get_edit_post_link' )->once()->andReturn( $edit_link ); $post = $this->get_post( $post_type ); - $obj = $this->MslsAdminIconFactory( $post ); + $obj = $this->IconFactory( $post ); $this->assertEquals( 'de_DE', $obj->get_img() ); $this->assertIsSTring( $obj->get_edit_new() ); @@ -154,27 +155,27 @@ public function test_get_img_post_page(): void { public function test_set_id_with_null_constructor(): void { Functions\expect( 'add_query_arg' )->once()->andReturn( 'post-new.php' ); - $obj = new MslsAdminIcon( null ); + $obj = new Icon( null ); - $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_id( 1 ) ); + $this->assertInstanceOf( Icon::class, $obj->set_id( 1 ) ); } public function test_set_id(): void { - $obj = new MslsAdminIcon( 'post' ); + $obj = new Icon( 'post' ); - $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_id( 1 ) ); + $this->assertInstanceOf( Icon::class, $obj->set_id( 1 ) ); } public function test_set_origin_language(): void { - $obj = new MslsAdminIcon( 'post' ); + $obj = new Icon( 'post' ); - $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_origin_language( 'it_IT' ) ); + $this->assertInstanceOf( Icon::class, $obj->set_origin_language( 'it_IT' ) ); } public function test_set_icon_type(): void { - $obj = new MslsAdminIcon( 'post' ); + $obj = new Icon( 'post' ); - $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_icon_type( 'flag' ) ); + $this->assertInstanceOf( Icon::class, $obj->set_icon_type( 'flag' ) ); } public static function icon_type_provider(): array { @@ -188,9 +189,9 @@ public static function icon_type_provider(): array { * @dataProvider icon_type_provider */ public function test_get_icon_flag( ?string $icon_type, ?string $language, string $expected ): void { - Functions\expect( 'plugin_dir_path' )->andReturn( dirname( __DIR__, 2 ) . '/' ); + Functions\expect( 'plugin_dir_path' )->andReturn( dirname( __DIR__, 3 ) . '/' ); - $obj = new MslsAdminIcon( 'post' ); + $obj = new Icon( 'post' ); $obj->set_icon_type( $icon_type ); if ( ! is_null( $language ) ) { @@ -201,9 +202,9 @@ public function test_get_icon_flag( ?string $icon_type, ?string $language, strin } public function test_get_icon_label(): void { - Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 2 ) . '/' ); + Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 3 ) . '/' ); - $obj = new MslsAdminIcon( 'post' ); + $obj = new Icon( 'post' ); $obj->set_icon_type( 'flag' ); $this->assertEquals( '', $obj->get_icon() ); @@ -214,7 +215,7 @@ public function test_get_icon_label(): void { } public function test_get_edit_new(): void { - $obj = new MslsAdminIcon( 'post' ); + $obj = new Icon( 'post' ); $obj->set_id( 123 ); $obj->set_origin_language( 'de_DE' ); diff --git a/tests/phpunit/TestMslsAdminIconTaxonomy.php b/tests/phpunit/Admin/TestIconTaxonomy.php similarity index 72% rename from tests/phpunit/TestMslsAdminIconTaxonomy.php rename to tests/phpunit/Admin/TestIconTaxonomy.php index 24bd096db..35a154b25 100644 --- a/tests/phpunit/TestMslsAdminIconTaxonomy.php +++ b/tests/phpunit/Admin/TestIconTaxonomy.php @@ -1,11 +1,12 @@ once()->andReturn( 'post_tag' ); Functions\expect( 'get_taxonomies' )->once()->andReturn( array() ); - $obj = ( new MslsAdminIconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( + $obj = ( new IconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( self::IMAGE_SRC ); @@ -35,7 +36,7 @@ public function test_get_edit_new(): void { Functions\expect( 'get_admin_url' )->once()->andReturn( $admin_url ); Functions\expect( 'get_current_blog_id' )->once()->andReturn( 1 ); - $obj = ( new MslsAdminIconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( + $obj = ( new IconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( self::IMAGE_SRC ); @@ -45,11 +46,11 @@ public function test_get_edit_new(): void { public function test_set_href(): void { Functions\expect( 'get_edit_term_link' )->once()->andReturn( 'get-edit-post-link' ); - $obj = ( new MslsAdminIconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( + $obj = ( new IconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( self::IMAGE_SRC ); - $this->assertInstanceOf( MslsAdminIconTaxonomy::class, $obj->set_href( 42 ) ); + $this->assertInstanceOf( IconTaxonomy::class, $obj->set_href( 42 ) ); $expected = ' '; @@ -62,11 +63,11 @@ public function test_set_href_empty(): void { Functions\expect( 'get_edit_term_link' )->once()->andReturn( '' ); Functions\expect( 'get_admin_url' )->twice()->andReturn( 'admin-url-empty' ); - $obj = ( new MslsAdminIconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( + $obj = ( new IconTaxonomy( 'post_tag' ) )->set_path()->set_language( self::LANGUAGE )->set_src( self::IMAGE_SRC ); - $this->assertInstanceOf( MslsAdminIconTaxonomy::class, $obj->set_href( 0 ) ); + $this->assertInstanceOf( IconTaxonomy::class, $obj->set_href( 0 ) ); $expected = ' '; diff --git a/tests/phpunit/TestMslsMetaBox.php b/tests/phpunit/Admin/TestMetaBox.php similarity index 92% rename from tests/phpunit/TestMslsMetaBox.php rename to tests/phpunit/Admin/TestMetaBox.php index 58fad2012..edfed52c4 100644 --- a/tests/phpunit/TestMslsMetaBox.php +++ b/tests/phpunit/Admin/TestMetaBox.php @@ -1,44 +1,45 @@ justReturn( dirname( __DIR__, 2 ) . '/' ); + private function MetaBoxFactory(): MetaBox { + Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 3 ) . '/' ); - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'flag' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get' )->andReturn( array( $blog ) ); $collection->shouldReceive( 'has_current_blog' )->andReturnTrue(); $collection->shouldReceive( 'get_current_blog' )->andReturn( $blog ); $collection->shouldReceive( 'get_blog_id' )->andReturn( 1 ); - return new MslsMetaBox( $options, $collection ); + return new MetaBox( $options, $collection ); } public function test_init(): void { $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_excluded' )->andReturn( false ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -48,7 +49,7 @@ public function test_init(): void { Actions\expectAdded( 'trashed_post' )->once(); $this->expectNotToPerformAssertions(); - MslsMetaBox::init(); + MetaBox::init(); } public function test_suggest(): void { @@ -76,7 +77,7 @@ function ( $output ) { $this->expectOutputString( '[{"value":42,"label":"Test"}]' ); - MslsMetaBox::suggest(); + MetaBox::suggest(); } public function test_suggest_applies_results_filter(): void { @@ -113,7 +114,7 @@ function ( $output ) { $this->expectOutputString( '[{"value":42,"label":"Test Post"}]' ); - MslsMetaBox::suggest(); + MetaBox::suggest(); } public function test_get_suggested_fields_no_posts(): void { @@ -123,14 +124,14 @@ public function test_get_suggested_fields_no_posts(): void { $json = \Mockery::mock( MslsJson::class ); $args = array(); - $this->assertEquals( $json, MslsMetaBox::get_suggested_fields( $json, $args ) ); + $this->assertEquals( $json, MetaBox::get_suggested_fields( $json, $args ) ); } public function test_render_option_selected(): void { Functions\expect( 'selected' )->once()->andReturn( 'selected="selected"' ); Functions\expect( 'get_the_title' )->once()->andReturn( 'Test' ); - $test = $this->MslsMetaBoxFactory(); + $test = $this->MetaBoxFactory(); $this->assertEquals( '', $test->render_option( 1, 1 ) ); } @@ -139,7 +140,7 @@ public function test_render_option_not_selected(): void { Functions\expect( 'selected' )->once()->andReturn( '' ); Functions\expect( 'get_the_title' )->once()->andReturn( 'Test' ); - $test = $this->MslsMetaBoxFactory(); + $test = $this->MetaBoxFactory(); $this->assertEquals( '', $test->render_option( 1, 2 ) ); } @@ -153,7 +154,7 @@ public function test_render_options(): void { Functions\expect( 'selected' )->once()->andReturn( 'selected="selected"' ); Functions\expect( 'get_the_title' )->once()->andReturn( 'A random title' ); - $test = $this->MslsMetaBoxFactory(); + $test = $this->MetaBoxFactory(); $this->assertEquals( '', $test->render_options( 'post', 42 ) ); } @@ -182,7 +183,7 @@ public function test_add( $post_type, $content_import, $autocomplete ) { $this->expectNotToPerformAssertions(); - $this->MslsMetaBoxFactory()->add(); + $this->MetaBoxFactory()->add(); } public function test_render_select_not_hierarchical(): void { @@ -220,7 +221,7 @@ public function test_render_select_not_hierarchical(): void { $expected = ''; $this->expectOutputString( $expected ); - $this->MslsMetaBoxFactory()->render_select(); + $this->MetaBoxFactory()->render_select(); } public function test_render_select_hierarchical(): void { @@ -253,7 +254,7 @@ public function test_render_select_hierarchical(): void { $expected = ''; $this->expectOutputString( $expected ); - $this->MslsMetaBoxFactory()->render_select(); + $this->MetaBoxFactory()->render_select(); } public static function render_input_provider(): array { @@ -297,16 +298,16 @@ public function test_render_input( $option, $the_title_times, $current_blog_id_t $this->expectOutputString( $expected ); - $this->MslsMetaBoxFactory()->render_input(); + $this->MetaBoxFactory()->render_input(); } public function test_render_select_only_one_blog(): void { $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); - $test = new MslsMetaBox( $options, $collection ); + $test = new MetaBox( $options, $collection ); $expected = '

You should define at least another blog in a different language in order to have some benefit from this plugin!

'; $this->expectOutputString( $expected ); @@ -317,10 +318,10 @@ public function test_render_select_only_one_blog(): void { public function test_render_input_only_one_blog(): void { $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); - $test = new MslsMetaBox( $options, $collection ); + $test = new MetaBox( $options, $collection ); $expected = '

You should define at least another blog in a different language in order to have some benefit from this plugin!

'; $this->expectOutputString( $expected ); @@ -333,7 +334,7 @@ public function test_set_no_request(): void { $this->expectNotToPerformAssertions(); - $this->MslsMetaBoxFactory()->set( 13 ); + $this->MetaBoxFactory()->set( 13 ); } public function test_set_with_request_current_user_cannot(): void { @@ -343,7 +344,7 @@ public function test_set_with_request_current_user_cannot(): void { Functions\expect( 'current_user_can' )->once()->andReturnFalse(); $this->expectNotToPerformAssertions(); - $this->MslsMetaBoxFactory()->set( 13 ); + $this->MetaBoxFactory()->set( 13 ); } public function test_set_with_request(): void { @@ -357,7 +358,7 @@ public function test_set_with_request(): void { Functions\expect( 'restore_current_blog' )->once(); $this->expectNotToPerformAssertions(); - $this->MslsMetaBoxFactory()->set( 13 ); + $this->MetaBoxFactory()->set( 13 ); } public function test_maybe_set_linked_post() { @@ -372,7 +373,7 @@ public function test_maybe_set_linked_post() { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $test = $this->MslsMetaBoxFactory(); + $test = $this->MetaBoxFactory(); $mydata = new Post(); $mydata = $test->maybe_set_linked_post( $mydata ); @@ -390,7 +391,7 @@ public function test_maybe_set_linked_post_with_no_post() { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $test = $this->MslsMetaBoxFactory(); + $test = $this->MetaBoxFactory(); $mydata = new Post(); $mydata = $test->maybe_set_linked_post( $mydata ); @@ -401,10 +402,10 @@ public function test_maybe_set_linked_post_with_no_post() { function test_maybe_set_linked_post_with_no_blog_id() { $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_blog_id' )->andReturn( null ); - $test = new MslsMetaBox( $options, $collection ); + $test = new MetaBox( $options, $collection ); Functions\expect( 'filter_has_var' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_ID )->andReturnTrue(); Functions\expect( 'filter_has_var' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_LANG )->andReturnTrue(); @@ -421,9 +422,9 @@ function test_maybe_set_linked_post_with_no_blog_id() { function test_maybe_set_linked_post_with_mydata_already_set() { $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); - $test = new MslsMetaBox( $options, $collection ); + $test = new MetaBox( $options, $collection ); Functions\expect( 'filter_has_var' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_ID )->andReturnTrue(); Functions\expect( 'filter_has_var' )->once()->with( INPUT_GET, MslsFields::FIELD_MSLS_LANG )->andReturnTrue(); diff --git a/tests/phpunit/TestMslsTranslationPickerPage.php b/tests/phpunit/Admin/TranslationPicker/TestPage.php similarity index 58% rename from tests/phpunit/TestMslsTranslationPickerPage.php rename to tests/phpunit/Admin/TranslationPicker/TestPage.php index 439804ddd..e80ea942d 100644 --- a/tests/phpunit/TestMslsTranslationPickerPage.php +++ b/tests/phpunit/Admin/TranslationPicker/TestPage.php @@ -1,29 +1,30 @@ assertSame( 'msls-translation-picker-post', MslsTranslationPickerPage::page_slug( 'post' ) ); - $this->assertSame( 'msls-translation-picker-page', MslsTranslationPickerPage::page_slug( 'page' ) ); - $this->assertSame( 'msls-translation-picker-event', MslsTranslationPickerPage::page_slug( 'event' ) ); + $this->assertSame( 'msls-translation-picker-post', Page::page_slug( 'post' ) ); + $this->assertSame( 'msls-translation-picker-page', Page::page_slug( 'page' ) ); + $this->assertSame( 'msls-translation-picker-event', Page::page_slug( 'event' ) ); } public function test_parent_slug_for_built_in_post(): void { - $this->assertSame( 'edit.php', MslsTranslationPickerPage::parent_slug( 'post' ) ); + $this->assertSame( 'edit.php', Page::parent_slug( 'post' ) ); } public function test_parent_slug_for_other_post_types(): void { - $this->assertSame( 'edit.php?post_type=page', MslsTranslationPickerPage::parent_slug( 'page' ) ); - $this->assertSame( 'edit.php?post_type=event', MslsTranslationPickerPage::parent_slug( 'event' ) ); + $this->assertSame( 'edit.php?post_type=page', Page::parent_slug( 'page' ) ); + $this->assertSame( 'edit.php?post_type=event', Page::parent_slug( 'event' ) ); } public function test_parent_slug_for_empty_post_type(): void { - $this->assertSame( '', MslsTranslationPickerPage::parent_slug( '' ) ); + $this->assertSame( '', Page::parent_slug( '' ) ); } public function test_url_uses_admin_url_and_query_arg(): void { @@ -40,7 +41,7 @@ function ( $args, $url ) { } ); - $result = MslsTranslationPickerPage::url( 'post' ); + $result = Page::url( 'post' ); $this->assertSame( 'https://example.tld/wp-admin/edit.php?page=msls-translation-picker-post', @@ -62,7 +63,7 @@ function ( $args, $url ) { } ); - $result = MslsTranslationPickerPage::url( 'page' ); + $result = Page::url( 'page' ); $this->assertSame( 'https://example.tld/wp-admin/edit.php?post_type=page&page=msls-translation-picker-page', @@ -73,20 +74,20 @@ function ( $args, $url ) { public function test_save_per_page_option_returns_int_for_picker_option(): void { $this->assertSame( 42, - MslsTranslationPickerPage::save_per_page_option( false, 'msls_tp_per_page', '42' ) + Page::save_per_page_option( false, 'msls_tp_per_page', '42' ) ); } public function test_save_per_page_option_falls_back_for_non_positive(): void { $this->assertSame( - MslsTranslationPickerPage::PER_PAGE_DEFAULT, - MslsTranslationPickerPage::save_per_page_option( false, 'msls_tp_per_page', '0' ) + Page::PER_PAGE_DEFAULT, + Page::save_per_page_option( false, 'msls_tp_per_page', '0' ) ); } public function test_save_per_page_option_passes_through_other_options(): void { $this->assertFalse( - MslsTranslationPickerPage::save_per_page_option( false, 'unrelated_option', '5' ) + Page::save_per_page_option( false, 'unrelated_option', '5' ) ); } } diff --git a/tests/phpunit/TestMslsBlog.php b/tests/phpunit/Blog/TestBlog.php similarity index 78% rename from tests/phpunit/TestMslsBlog.php rename to tests/phpunit/Blog/TestBlog.php index d33c07464..e28aab203 100644 --- a/tests/phpunit/TestMslsBlog.php +++ b/tests/phpunit/Blog/TestBlog.php @@ -1,31 +1,32 @@ once()->andReturn( 'it_IT' ); - Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 2 ) . '/' ); + Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 3 ) . '/' ); $blog = new \stdClass(); $blog->userblog_id = 1; $blog->blogname = 'Test'; - return new MslsBlog( $blog, 'Italiano' ); + return new Blog( $blog, 'Italiano' ); } public function test_get_userblog_id(): void { - $this->assertEquals( 1, $this->MslsBlogFactory()->userblog_id ); + $this->assertEquals( 1, $this->BlogFactory()->userblog_id ); } public function test_get_description(): void { - $this->assertEquals( 'Italiano', $this->MslsBlogFactory()->get_description() ); + $this->assertEquals( 'Italiano', $this->BlogFactory()->get_description() ); } public function test_get_url_current(): void { @@ -34,12 +35,12 @@ public function test_get_url_current(): void { $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'get_current_link' )->andReturn( $url ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog_id' )->andReturn( 1 ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); - $this->assertEquals( $url, $this->MslsBlogFactory()->get_url( $option ) ); + $this->assertEquals( $url, $this->BlogFactory()->get_url( $option ) ); } public function test_get_frontpage(): void { @@ -48,7 +49,7 @@ public function test_get_frontpage(): void { $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog_id' )->andReturn( 2 ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -57,7 +58,7 @@ public function test_get_frontpage(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $this->assertEquals( $url, $this->MslsBlogFactory()->get_url( $option ) ); + $this->assertEquals( $url, $this->BlogFactory()->get_url( $option ) ); } public function test_get_url(): void { @@ -67,7 +68,7 @@ public function test_get_url(): void { $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); $option->shouldReceive( 'has_value' )->once()->andReturn( true ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog_id' )->andReturn( 2 ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -76,7 +77,7 @@ public function test_get_url(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $this->assertEquals( $url, $this->MslsBlogFactory()->get_url( $option ) ); + $this->assertEquals( $url, $this->BlogFactory()->get_url( $option ) ); } public function test_get_posts_page(): void { @@ -85,7 +86,7 @@ public function test_get_posts_page(): void { $option = \Mockery::mock( Options::class ); $option->shouldReceive( 'has_value' )->once()->andReturn( false ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog_id' )->andReturn( 2 ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -96,7 +97,7 @@ public function test_get_posts_page(): void { Functions\expect( 'get_option' )->atLeast()->once()->andReturn( 42 ); Functions\expect( 'get_permalink' )->once()->with( 42 )->andReturn( $url ); - $this->assertEquals( $url, $this->MslsBlogFactory()->get_url( $option ) ); + $this->assertEquals( $url, $this->BlogFactory()->get_url( $option ) ); } public function test_get_posts_page_with_translation(): void { @@ -106,7 +107,7 @@ public function test_get_posts_page_with_translation(): void { $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); $option->shouldReceive( 'has_value' )->once()->andReturn( true ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog_id' )->andReturn( 2 ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -115,15 +116,15 @@ public function test_get_posts_page_with_translation(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $this->assertEquals( $url, $this->MslsBlogFactory()->get_url( $option ) ); + $this->assertEquals( $url, $this->BlogFactory()->get_url( $option ) ); } public function test_get_language(): void { - $this->assertEquals( 'it_IT', $this->MslsBlogFactory()->get_language() ); + $this->assertEquals( 'it_IT', $this->BlogFactory()->get_language() ); } public function test_get_alpha2(): void { - $this->assertEquals( 'it', $this->MslsBlogFactory()->get_alpha2() ); + $this->assertEquals( 'it', $this->BlogFactory()->get_alpha2() ); } public function test_get_title(): void { @@ -131,7 +132,7 @@ public function test_get_title(): void { $this->assertEquals( 'Test it_IT', - $this->MslsBlogFactory()->get_title() + $this->BlogFactory()->get_title() ); } @@ -156,9 +157,9 @@ public static function compareProvider(): array { * @dataProvider compareProvider */ public function test__cmp_method( int $a, int $b, int $expected ): void { - $this->assertEquals( $expected, MslsBlog::internal_cmp( $a, $b ) ); + $this->assertEquals( $expected, Blog::internal_cmp( $a, $b ) ); - $obj = new MslsBlog( null, null ); + $obj = new Blog( null, null ); $this->assertEquals( $expected, $obj->internal_cmp( $a, $b ) ); } @@ -166,8 +167,8 @@ public function test__cmp_method( int $a, int $b, int $expected ): void { * Verify the language-method */ public function test_language_cmp(): void { - $a = new MslsBlog( null, null ); - $b = new MslsBlog( null, null ); + $a = new Blog( null, null ); + $b = new Blog( null, null ); $this->assertEquals( 0, $a->language( $a, $b ) ); } @@ -176,8 +177,8 @@ public function test_language_cmp(): void { * Verify the description-method */ public function test_description_cmp(): void { - $a = new MslsBlog( null, null ); - $b = new MslsBlog( null, null ); + $a = new Blog( null, null ); + $b = new Blog( null, null ); $this->assertEquals( 0, $a->description( $a, $b ) ); } @@ -191,7 +192,7 @@ public function test_get_blavatar_lazy(): void { $this->assertEquals( '', - $this->MslsBlogFactory()->get_blavatar() + $this->BlogFactory()->get_blavatar() ); } @@ -204,7 +205,7 @@ public function test_get_blavatar(): void { $this->assertEquals( '', - $this->MslsBlogFactory()->get_blavatar() + $this->BlogFactory()->get_blavatar() ); } } diff --git a/tests/phpunit/TestMslsBlogCollection.php b/tests/phpunit/Blog/TestCollection.php similarity index 83% rename from tests/phpunit/TestMslsBlogCollection.php rename to tests/phpunit/Blog/TestCollection.php index c29f0ce31..551ec03ef 100644 --- a/tests/phpunit/TestMslsBlogCollection.php +++ b/tests/phpunit/Blog/TestCollection.php @@ -1,18 +1,19 @@ justReturn( array( 'total_users' => self::TOTAL_USERS ) ); @@ -23,9 +24,9 @@ protected function setUp(): void { Functions\expect( 'msls_options' )->atLeast()->once()->andReturn( $options ); - $a = \Mockery::mock( MslsBlog::class ); - $b = \Mockery::mock( MslsBlog::class ); - $c = \Mockery::mock( MslsBlog::class ); + $a = \Mockery::mock( Blog::class ); + $b = \Mockery::mock( Blog::class ); + $c = \Mockery::mock( Blog::class ); $a->userblog_id = 1; $b->userblog_id = 2; @@ -72,7 +73,7 @@ function ( $blog_id, $option ) { public function test_get_configured_blog_description_empty(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertEquals( 'Test', $obj->get_configured_blog_description( 0, 'Test' ) ); @@ -89,7 +90,7 @@ public function test_get_blogs_of_reference_user(): void { $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'has_value' )->andReturn( true ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get_blogs_of_reference_user( $options ) ); } @@ -97,7 +98,7 @@ public function test_get_blogs_of_reference_user(): void { public function test_get_current_blog_id(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsInt( $obj->get_current_blog_id() ); } @@ -105,7 +106,7 @@ public function test_get_current_blog_id(): void { public function test_has_current_blog(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsBool( $obj->has_current_blog() ); } @@ -113,9 +114,9 @@ public function test_has_current_blog(): void { public function test_is_current_blog_true(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->userblog_id = 1; $this->assertTrue( $obj->is_current_blog( $blog ) ); @@ -124,9 +125,9 @@ public function test_is_current_blog_true(): void { public function test_is_current_blog_false(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->userblog_id = 2; $this->assertFalse( $obj->is_current_blog( $blog ) ); @@ -135,7 +136,7 @@ public function test_is_current_blog_false(): void { public function test_get_objects(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get_objects() ); } @@ -143,9 +144,9 @@ public function test_get_objects(): void { public function test_get_object(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); - $this->assertInstanceOf( MslsBlog::class, $obj->get_object( 1 ) ); + $this->assertInstanceOf( Blog::class, $obj->get_object( 1 ) ); $this->assertNull( $obj->get_object( 4 ) ); } @@ -154,7 +155,7 @@ public function test_is_plugin_active_networkwide(): void { array( 'multisite-language-switcher/MultisiteLanguageSwitcher.php' => 'Multisite Language Switcher' ) ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertTrue( $obj->is_plugin_active( 4 ) ); } @@ -162,7 +163,7 @@ public function test_is_plugin_active_networkwide(): void { public function test_is_plugin_active(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertTrue( $obj->is_plugin_active( 1 ) ); $this->assertTrue( $obj->is_plugin_active( 2 ) ); @@ -173,7 +174,7 @@ public function test_is_plugin_active(): void { public function test_get_plugin_active_blogs(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get_plugin_active_blogs() ); } @@ -181,7 +182,7 @@ public function test_get_plugin_active_blogs(): void { public function test_get(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get() ); } @@ -189,7 +190,7 @@ public function test_get(): void { public function test_get_filtered(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get_filtered() ); $this->assertIsArray( $obj->get_filtered( true ) ); @@ -198,7 +199,7 @@ public function test_get_filtered(): void { public function test_get_users_single(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get_users( array( 'ID' ), 1 ) ); } @@ -206,7 +207,7 @@ public function test_get_users_single(): void { public function test_get_users_massive(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertIsArray( $obj->get_users( array( 'ID' ), self::TOTAL_USERS ) ); } @@ -216,7 +217,7 @@ public function test_get_users_max() { $max_users = 100; - $obj = new MslsBlogCollection(); + $obj = new Collection(); set_error_handler( static function ( $errno, $errstr ) { @@ -235,15 +236,15 @@ static function ( $errno, $errstr ) { public function test_get_current_blog(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); - $this->assertInstanceOf( MslsBlog::class, $obj->get_current_blog() ); + $this->assertInstanceOf( Blog::class, $obj->get_current_blog() ); } public function test_get_blog_language(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertEquals( 'de_DE', $obj->get_blog_language( 1 ) ); $this->assertEquals( 'it_IT', $obj->get_blog_language( 2 ) ); @@ -255,7 +256,7 @@ public function test_get_blog_language(): void { public function test_get_blog_id(): void { Functions\expect( 'get_site_option' )->once()->andReturn( array() ); - $obj = new MslsBlogCollection(); + $obj = new Collection(); $this->assertEquals( 1, $obj->get_blog_id( 'de_DE' ) ); $this->assertEquals( 2, $obj->get_blog_id( 'it_IT' ) ); diff --git a/tests/phpunit/TestMslsCli.php b/tests/phpunit/Cli/TestCli.php similarity index 61% rename from tests/phpunit/TestMslsCli.php rename to tests/phpunit/Cli/TestCli.php index 200cdce4b..f408e9366 100644 --- a/tests/phpunit/TestMslsCli.php +++ b/tests/phpunit/Cli/TestCli.php @@ -1,14 +1,15 @@ expectOutputString( 'Blog ID 1 has locale de_DE!' ); - $this->MslsCliFacotry()->blog( array( 'de_DE' ), array() ); + $this->CliFactory()->blog( array( 'de_DE' ), array() ); } public function test_blog_error(): void { @@ -24,6 +25,6 @@ public function test_blog_error(): void { $this->expectOutputString( 'No blog with locale de_DE found!' ); - $this->MslsCliFacotry()->blog( array( 'de_DE' ), array() ); + $this->CliFactory()->blog( array( 'de_DE' ), array() ); } } diff --git a/tests/phpunit/Query/TestTranslatedPostsQuery.php b/tests/phpunit/Db/Query/TestTranslatedPostsQuery.php similarity index 82% rename from tests/phpunit/Query/TestTranslatedPostsQuery.php rename to tests/phpunit/Db/Query/TestTranslatedPostsQuery.php index 3eb17eac5..10507a5c5 100644 --- a/tests/phpunit/Query/TestTranslatedPostsQuery.php +++ b/tests/phpunit/Db/Query/TestTranslatedPostsQuery.php @@ -2,14 +2,14 @@ namespace lloc\MslsTests\Query; -use lloc\Msls\MslsSqlCacher; -use lloc\Msls\Query\TranslatedPostIdQuery; +use lloc\Msls\Db\SqlCacher; +use lloc\Msls\Db\Query\TranslatedPostIdQuery; use lloc\MslsTests\MslsUnitTestCase; final class TestTranslatedPostsQuery extends MslsUnitTestCase { public function test_invoke_empty_string(): void { - $sql_cache = \Mockery::mock( MslsSqlCacher::class ); + $sql_cache = \Mockery::mock( SqlCacher::class ); $this->assertEquals( array(), ( new TranslatedPostIdQuery( $sql_cache ) )( '' ) ); } @@ -30,7 +30,7 @@ public function test_invoke_with_string(): void { ), ); - $sql_cache = \Mockery::mock( MslsSqlCacher::class ); + $sql_cache = \Mockery::mock( SqlCacher::class ); $sql_cache->shouldReceive( 'prepare' )->once(); $sql_cache->shouldReceive( 'get_results' )->once()->andReturn( $result ); diff --git a/tests/phpunit/TestMslsSqlCacher.php b/tests/phpunit/Db/TestSqlCacher.php similarity index 55% rename from tests/phpunit/TestMslsSqlCacher.php rename to tests/phpunit/Db/TestSqlCacher.php index e176ccb87..6f23bc77c 100644 --- a/tests/phpunit/TestMslsSqlCacher.php +++ b/tests/phpunit/Db/TestSqlCacher.php @@ -1,21 +1,22 @@ assertInstanceOf( MslsSqlCacher::class, MslsSqlCacher::create( 'MslsSqlCacherTest', '' ) ); - $this->assertInstanceOf( MslsSqlCacher::class, MslsSqlCacher::create( 'MslsSqlCacherTest', 'abc' ) ); - $this->assertInstanceOf( MslsSqlCacher::class, MslsSqlCacher::create( 'MslsSqlCacherTest', array() ) ); - $this->assertInstanceOf( MslsSqlCacher::class, MslsSqlCacher::create( 'MslsSqlCacherTest', array( 'abc', 'def' ) ) ); + $this->assertInstanceOf( SqlCacher::class, SqlCacher::create( 'MslsSqlCacherTest', '' ) ); + $this->assertInstanceOf( SqlCacher::class, SqlCacher::create( 'MslsSqlCacherTest', 'abc' ) ); + $this->assertInstanceOf( SqlCacher::class, SqlCacher::create( 'MslsSqlCacherTest', array() ) ); + $this->assertInstanceOf( SqlCacher::class, SqlCacher::create( 'MslsSqlCacherTest', array( 'abc', 'def' ) ) ); } public function test_set_params_method(): void { @@ -29,7 +30,7 @@ public function test_set_params_method(): void { Functions\when( 'wp_cache_get' )->justReturn( false ); Functions\when( 'wp_cache_set' )->justReturn( true ); - $test = new MslsSqlCacher( $wpdb, 'MslsSqlCacherTest' ); + $test = new SqlCacher( $wpdb, 'MslsSqlCacherTest' ); $sql = $test->prepare( "SELECT blog_id FROM {$test->blogs} WHERE blog_id != %d AND site_id = %d", diff --git a/tests/phpunit/Map/TestHrefLang.php b/tests/phpunit/Frontend/Map/TestHrefLang.php similarity index 86% rename from tests/phpunit/Map/TestHrefLang.php rename to tests/phpunit/Frontend/Map/TestHrefLang.php index c16ac5289..acfdae1d1 100644 --- a/tests/phpunit/Map/TestHrefLang.php +++ b/tests/phpunit/Frontend/Map/TestHrefLang.php @@ -1,12 +1,12 @@ $alpha2 ) { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_alpha2' )->andReturn( $alpha2 ); $blog->shouldReceive( 'get_language' )->andReturn( $locale ); $blogs[] = $blog; } - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_objects' )->andReturn( $blogs ); return new HrefLang( $collection ); diff --git a/tests/phpunit/TestMslsBlock.php b/tests/phpunit/Frontend/TestBlock.php similarity index 65% rename from tests/phpunit/TestMslsBlock.php rename to tests/phpunit/Frontend/TestBlock.php index 7bf70b66c..cabfba702 100644 --- a/tests/phpunit/TestMslsBlock.php +++ b/tests/phpunit/Frontend/TestBlock.php @@ -1,18 +1,19 @@ shouldReceive( 'is_excluded' )->andReturn( true ); - $this->assertFalse( ( new MslsBlock( $options ) )->register_block() ); + $this->assertFalse( ( new Block( $options ) )->register_block() ); } @@ -23,6 +24,6 @@ public function test_register_block_excluded_false(): void { Functions\expect( 'register_block_type' )->once(); Functions\expect( 'plugin_dir_path' )->once(); - $this->assertTrue( ( new MslsBlock( $options ) )->register_block() ); + $this->assertTrue( ( new Block( $options ) )->register_block() ); } } diff --git a/tests/phpunit/TestMslsContentFilter.php b/tests/phpunit/Frontend/TestContentFilter.php similarity index 91% rename from tests/phpunit/TestMslsContentFilter.php rename to tests/phpunit/Frontend/TestContentFilter.php index 2e12b39f2..89805c7c7 100644 --- a/tests/phpunit/TestMslsContentFilter.php +++ b/tests/phpunit/Frontend/TestContentFilter.php @@ -1,15 +1,16 @@ once(); $this->expectNotToPerformAssertions(); - MslsContentFilter::init(); + ContentFilter::init(); } public static function provide_content_filter_data(): array { @@ -42,17 +43,17 @@ public function test_content_filter_empty( string $content, string $expected, bo $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( $is_content_filter ); - $test = new MslsContentFilter( $options ); + $test = new ContentFilter( $options ); $this->assertEquals( $expected, $test->content_filter( $content ) ); } public function test_content_filter_one_link(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( false ); @@ -88,7 +89,7 @@ public function test_content_filter_one_link(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $test = new MslsContentFilter( $options ); + $test = new ContentFilter( $options ); $content = '

Test>/p>'; $expected = '

Test>/p>

This post is also available in Deutsch.

'; @@ -96,7 +97,7 @@ public function test_content_filter_one_link(): void { } public function test_content_filter_zero_links(): void { - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array() ); $options = \Mockery::mock( Options::class ); @@ -114,7 +115,7 @@ public function test_content_filter_zero_links(): void { Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); - $test = new MslsContentFilter( $options ); + $test = new ContentFilter( $options ); $content = '

Test>/p>'; $expected = '

Test>/p>'; @@ -122,22 +123,22 @@ public function test_content_filter_zero_links(): void { } public function test_content_filter_more_links(): void { - $a = \Mockery::mock( MslsBlog::class ); + $a = \Mockery::mock( Blog::class ); $a->shouldReceive( 'get_language' )->once()->andReturn( 'it_IT' ); $a->shouldReceive( 'get_description' )->once()->andReturn( 'Italiano' ); - $b = \Mockery::mock( MslsBlog::class ); + $b = \Mockery::mock( Blog::class ); $b->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); $b->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); - $c = \Mockery::mock( MslsBlog::class ); + $c = \Mockery::mock( Blog::class ); $c->shouldReceive( 'get_language' )->once()->andReturn( 'fr_FR' ); $c->shouldReceive( 'get_description' )->once()->andReturn( 'Français' ); $blogs = array( $a, $b, $c ); $times = count( $blogs ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( $blogs ); $collection->shouldReceive( 'is_current_blog' )->times( $times )->andReturn( false ); @@ -180,7 +181,7 @@ public function test_content_filter_more_links(): void { Functions\expect( 'switch_to_blog' )->times( $times ); Functions\expect( 'restore_current_blog' )->times( $times ); - $test = new MslsContentFilter( $options ); + $test = new ContentFilter( $options ); $content = '

Test>/p>'; $expected = '

Test>/p>

This post is also available in Italiano, Deutsch and Français.

'; @@ -188,11 +189,11 @@ public function test_content_filter_more_links(): void { } public function test_content_filter_with_filter(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( false ); @@ -229,7 +230,7 @@ public function test_content_filter_with_filter(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $test = new MslsContentFilter( $options ); + $test = new ContentFilter( $options ); $content = '

Test>/p>'; $filter = 'This post is also available in Deutsch.'; diff --git a/tests/phpunit/TestMslsOutput.php b/tests/phpunit/Frontend/TestOutput.php similarity index 87% rename from tests/phpunit/TestMslsOutput.php rename to tests/phpunit/Frontend/TestOutput.php index 112e43de1..c671c69ad 100644 --- a/tests/phpunit/TestMslsOutput.php +++ b/tests/phpunit/Frontend/TestOutput.php @@ -1,30 +1,31 @@ shouldReceive( 'has_current_blog' )->andReturn( true ); $collection->shouldReceive( 'get_current_blog' )->andReturn( 1 ); $collection->shouldReceive( 'get_filtered' )->andReturn( array() ); - return new MslsOutput( $options, $collection ); + return new Output( $options, $collection ); } public function test_get_method(): void { - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertEquals( array(), $test->get( 0 ) ); } @@ -32,7 +33,7 @@ public function test_get_method(): void { public function test_get_alternate_links_two_url(): void { $blogs = array(); - $a = \Mockery::mock( MslsBlog::class ); + $a = \Mockery::mock( Blog::class ); $a->shouldReceive( 'get_alpha2' )->andReturn( 'de' ); $a->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $a->shouldReceive( 'get_url' )->andReturn( 'https://example.de/' ); @@ -40,7 +41,7 @@ public function test_get_alternate_links_two_url(): void { $blogs[] = $a; - $b = \Mockery::mock( MslsBlog::class ); + $b = \Mockery::mock( Blog::class ); $b->shouldReceive( 'get_alpha2' )->andReturn( 'it' ); $b->shouldReceive( 'get_language' )->andReturn( 'it_IT' ); $b->shouldReceive( 'get_url' )->andReturn( 'https://example.it/' ); @@ -48,7 +49,7 @@ public function test_get_alternate_links_two_url(): void { $blogs[] = $b; - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_objects' )->andReturn( $blogs ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -71,7 +72,7 @@ public function test_get_alternate_links_two_url(): void { '' . PHP_EOL . ''; - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertEquals( $expected, $test->get_alternate_links() ); } @@ -79,14 +80,14 @@ public function test_get_alternate_links_two_url(): void { public function test_get_alternate_links_null_url(): void { $blogs = array(); - $a = \Mockery::mock( MslsBlog::class ); + $a = \Mockery::mock( Blog::class ); $a->shouldReceive( 'get_alpha2' )->andReturn( 'de' ); $a->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $a->shouldReceive( 'get_url' )->andReturnNull(); $blogs[] = $a; - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_objects' )->andReturn( $blogs ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -103,7 +104,7 @@ public function test_get_alternate_links_null_url(): void { Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertEquals( '', $test->get_alternate_links() ); } @@ -111,7 +112,7 @@ public function test_get_alternate_links_null_url(): void { public function test_get_alternate_links_one_url(): void { $blogs = array(); - $a = \Mockery::mock( MslsBlog::class ); + $a = \Mockery::mock( Blog::class ); $a->shouldReceive( 'get_alpha2' )->andReturn( 'de' ); $a->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $a->shouldReceive( 'get_url' )->andReturn( 'https://example.de/' ); @@ -119,7 +120,7 @@ public function test_get_alternate_links_one_url(): void { $blogs[] = $a; - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_objects' )->andReturn( $blogs ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -140,7 +141,7 @@ public function test_get_alternate_links_one_url(): void { $expected = ''; - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertEquals( $expected, $test->get_alternate_links() ); } @@ -150,20 +151,20 @@ public function test___toString_no_translation(): void { Filters\expectApplied( 'msls_output_no_translation_found' )->once()->andReturn( $expected ); - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertEquals( $expected, strval( $test ) ); } public function test___toString_output(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->andReturn( false ); @@ -185,20 +186,20 @@ public function test___toString_output(): void { $expected = 'de_DE Deutsch'; - $test = new MslsOutput( $options, $collection ); + $test = new Output( $options, $collection ); $this->assertEquals( $expected, strval( $test ) ); } public function test___toString_current_blog(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->andReturn( true ); @@ -218,18 +219,18 @@ public function test___toString_current_blog(): void { $expected = 'de_DE Deutsch'; - $this->assertEquals( $expected, strval( new MslsOutput( $options, $collection ) ) ); + $this->assertEquals( $expected, strval( new Output( $options, $collection ) ) ); } public function test___toString_filter(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->andReturn( true ); @@ -251,17 +252,17 @@ public function test___toString_filter(): void { $expected = ' de_DEDeutsch'; Filters\expectApplied( 'msls_output_get' )->once()->andReturn( $expected ); - $this->assertEquals( $expected, strval( new MslsOutput( $options, $collection ) ) ); + $this->assertEquals( $expected, strval( new Output( $options, $collection ) ) ); } public function test_get_not_fulfilled(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->andReturn( false ); @@ -280,11 +281,11 @@ public function test_get_not_fulfilled(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $this->assertEquals( array(), ( new MslsOutput( $options, $collection ) )->get( 0, false, true ) ); + $this->assertEquals( array(), ( new Output( $options, $collection ) )->get( 0, false, true ) ); } public function test_get_tags(): void { - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertIsArray( $test->get_tags() ); } @@ -292,13 +293,13 @@ public function test_get_tags(): void { public function test_set_tags(): void { Functions\expect( 'wp_parse_args' )->once()->andReturn( array() ); - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); - $this->assertInstanceOf( MslsOutput::class, $test->set_tags() ); + $this->assertInstanceOf( Output::class, $test->set_tags() ); } public function test_is_requirements_not_fulfilled_with_null(): void { - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertFalse( $test->is_requirements_not_fulfilled( null, false, 'de_DE' ) ); $this->assertTrue( $test->is_requirements_not_fulfilled( null, true, 'de_DE' ) ); @@ -309,7 +310,7 @@ public function test_is_requirements_not_fulfilled_with_mslsoptions(): void { $mydata = new Options(); - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertFalse( $test->is_requirements_not_fulfilled( $mydata, false, 'de_DE' ) ); $this->assertFalse( $test->is_requirements_not_fulfilled( $mydata, true, 'de_DE' ) ); @@ -320,7 +321,7 @@ public function test_is_requirements_not_fulfilled_with_mslsoptionspost(): void $mydata = new Post(); - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertFalse( $test->is_requirements_not_fulfilled( $mydata, false, 'de_DE' ) ); $this->assertTrue( $test->is_requirements_not_fulfilled( $mydata, true, 'de_DE' ) ); @@ -329,14 +330,14 @@ public function test_is_requirements_not_fulfilled_with_mslsoptionspost(): void public function test_get_alternate_links_empty_url(): void { $blogs = array(); - $a = \Mockery::mock( MslsBlog::class ); + $a = \Mockery::mock( Blog::class ); $a->shouldReceive( 'get_alpha2' )->andReturn( 'de' ); $a->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $a->shouldReceive( 'get_url' )->andReturn( '' ); $blogs[] = $a; - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_objects' )->andReturn( $blogs ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); @@ -353,13 +354,13 @@ public function test_get_alternate_links_empty_url(): void { Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - $test = $this->MslsOutputFactory(); + $test = $this->OutputFactory(); $this->assertEquals( '', $test->get_alternate_links() ); } public function test_get_skips_empty_url(): void { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); $blog->userblog_id = 2; @@ -367,7 +368,7 @@ public function test_get_skips_empty_url(): void { $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); $collection->shouldReceive( 'is_current_blog' )->andReturn( false ); @@ -384,18 +385,18 @@ public function test_get_skips_empty_url(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); - $this->assertEquals( array(), ( new MslsOutput( $options, $collection ) )->get( 0 ) ); + $this->assertEquals( array(), ( new Output( $options, $collection ) )->get( 0 ) ); } public function test_init(): void { Functions\expect( '_deprecated_function' )->once(); $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); - $this->assertInstanceOf( MslsOutput::class, MslsOutput::init() ); + $this->assertInstanceOf( Output::class, Output::init() ); } } diff --git a/tests/phpunit/TestMslsShortCode.php b/tests/phpunit/Frontend/TestShortCode.php similarity index 72% rename from tests/phpunit/TestMslsShortCode.php rename to tests/phpunit/Frontend/TestShortCode.php index 295bb16cc..3cb8fae94 100644 --- a/tests/phpunit/TestMslsShortCode.php +++ b/tests/phpunit/Frontend/TestShortCode.php @@ -1,19 +1,20 @@ once()->with( 'sc_msls_widget', array( MslsShortCode::class, 'render_widget' ) ); + Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls_widget', array( ShortCode::class, 'render_widget' ) ); Functions\expect( 'add_shortcode' )->once()->with( 'sc_msls', 'msls_get_switcher' ); $this->expectNotToPerformAssertions(); - MslsShortCode::init(); + ShortCode::init(); } public function test_block_render_excluded_true(): void { @@ -22,7 +23,7 @@ public function test_block_render_excluded_true(): void { Functions\expect( 'msls_options' )->once()->andReturn( $options ); - $this->assertEquals( '', MslsShortCode::render_widget() ); + $this->assertEquals( '', ShortCode::render_widget() ); } @@ -36,6 +37,6 @@ public function test_block_render_excluded_false(): void { Functions\when( 'the_widget' )->justEcho( $expected ); - $this->assertEquals( $expected, MslsShortCode::render_widget() ); + $this->assertEquals( $expected, ShortCode::render_widget() ); } } diff --git a/tests/phpunit/TestMslsWidget.php b/tests/phpunit/Frontend/TestWidget.php similarity index 75% rename from tests/phpunit/TestMslsWidget.php rename to tests/phpunit/Frontend/TestWidget.php index 1644ec3ac..60499bb26 100644 --- a/tests/phpunit/TestMslsWidget.php +++ b/tests/phpunit/Frontend/TestWidget.php @@ -1,25 +1,26 @@ shouldReceive( 'is_excluded' )->once()->andReturn( false ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); - Functions\expect( 'register_widget' )->once()->with( MslsWidget::class ); + Functions\expect( 'register_widget' )->once()->with( Widget::class ); $this->expectNotToPerformAssertions(); - MslsWidget::init(); + Widget::init(); } public function test_widget(): void { @@ -32,17 +33,17 @@ public function test_widget(): void { Functions\expect( 'wp_parse_args' )->once()->andReturn( $arr ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array() ); $options = \Mockery::mock( Options::class ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); - Functions\expect( 'msls_output' )->once()->andReturn( MslsOutput::create() ); + Functions\expect( 'msls_output' )->once()->andReturn( Output::create() ); $this->expectOutputString( '

Test

No available translations found
' ); - ( new MslsWidget() )->widget( array(), array( 'title' => 'Test' ) ); + ( new Widget() )->widget( array(), array( 'title' => 'Test' ) ); } public static function update_provider(): array { @@ -59,7 +60,7 @@ public static function update_provider(): array { public function test_update( array $new_instance, array $old_instance, array $expected, int $times ): void { Functions\expect( 'wp_strip_all_tags' )->times( $times )->andReturnFirstArg(); - $result = ( new MslsWidget() )->update( $new_instance, $old_instance ); + $result = ( new Widget() )->update( $new_instance, $old_instance ); $this->assertEquals( $expected, $result ); } @@ -68,7 +69,7 @@ public function test_form(): void { $this->expectOutputString( $expected ); - $result = ( new MslsWidget() )->form( array() ); + $result = ( new Widget() )->form( array() ); $this->assertEquals( $expected, $result ); } } diff --git a/tests/phpunit/Options/Query/TestAuthor.php b/tests/phpunit/Options/Query/TestAuthor.php index b883a9a28..98672d2bb 100644 --- a/tests/phpunit/Options/Query/TestAuthor.php +++ b/tests/phpunit/Options/Query/TestAuthor.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests\Options\Query; use Brain\Monkey\Functions; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Query\Author; use lloc\MslsTests\MslsUnitTestCase; @@ -15,7 +15,7 @@ private function OptionsQueryAuthorFactory( int $author_id ): Author { Functions\expect( 'get_option' )->once()->andReturn( array() ); Functions\expect( 'get_queried_object_id' )->once()->andReturn( $author_id ); - $sql_cacher = \Mockery::mock( MslsSqlCacher::class ); + $sql_cacher = \Mockery::mock( SqlCacher::class ); $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); diff --git a/tests/phpunit/Options/Query/TestDay.php b/tests/phpunit/Options/Query/TestDay.php index a48d1b190..8ef4f1c57 100644 --- a/tests/phpunit/Options/Query/TestDay.php +++ b/tests/phpunit/Options/Query/TestDay.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests\Options\Query; use Brain\Monkey\Functions; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Query\Day; use lloc\MslsTests\MslsUnitTestCase; @@ -17,7 +17,7 @@ private function OptionsQueryDayFactory( int $year, int $monthnum, int $day ): D Functions\expect( 'get_option' )->once()->andReturn( array() ); Functions\expect( 'get_query_var' )->times( 3 )->andReturn( $year, $monthnum, $day ); - $sql_cacher = \Mockery::mock( MslsSqlCacher::class ); + $sql_cacher = \Mockery::mock( SqlCacher::class ); $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); diff --git a/tests/phpunit/Options/Query/TestMonth.php b/tests/phpunit/Options/Query/TestMonth.php index 4c2b461e7..9b543b215 100644 --- a/tests/phpunit/Options/Query/TestMonth.php +++ b/tests/phpunit/Options/Query/TestMonth.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests\Options\Query; use Brain\Monkey\Functions; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Query\Month; use lloc\MslsTests\MslsUnitTestCase; @@ -15,7 +15,7 @@ private function OptionsQueryMonthFactory( int $year, int $monthnum ): Month { Functions\expect( 'get_option' )->once()->andReturn( array() ); Functions\expect( 'get_query_var' )->times( 2 )->andReturn( $year, $monthnum ); - $sql_cacher = \Mockery::mock( MslsSqlCacher::class ); + $sql_cacher = \Mockery::mock( SqlCacher::class ); $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); diff --git a/tests/phpunit/Options/Query/TestOptionsQueryYear.php b/tests/phpunit/Options/Query/TestOptionsQueryYear.php index 5f59c7cc5..517e7c984 100644 --- a/tests/phpunit/Options/Query/TestOptionsQueryYear.php +++ b/tests/phpunit/Options/Query/TestOptionsQueryYear.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests\Options\Query; use Brain\Monkey\Functions; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Query\Year; use lloc\MslsTests\MslsUnitTestCase; @@ -15,7 +15,7 @@ private function OptionsQueryYearFactory( int $year ): Year { Functions\expect( 'get_option' )->once()->andReturn( array() ); Functions\expect( 'get_query_var' )->once()->andReturn( $year ); - $sql_cacher = \Mockery::mock( MslsSqlCacher::class ); + $sql_cacher = \Mockery::mock( SqlCacher::class ); $sql_cacher->shouldReceive( 'prepare' )->andReturn( 'SQL Query String' ); $sql_cacher->shouldReceive( 'get_var' )->andReturn( random_int( 1, 10 ) ); diff --git a/tests/phpunit/Options/Query/TestPostType.php b/tests/phpunit/Options/Query/TestPostType.php index f76fc2f23..25a99e074 100644 --- a/tests/phpunit/Options/Query/TestPostType.php +++ b/tests/phpunit/Options/Query/TestPostType.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests\Options\Query; use Brain\Monkey\Functions; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Query\PostType; use lloc\MslsTests\MslsUnitTestCase; @@ -15,7 +15,7 @@ private function OptionsQueryPostTypeFactory(): PostType { Functions\expect( 'get_option' )->once()->andReturn( array() ); Functions\expect( 'get_query_var' )->once()->andReturn( 'queried-posttype' ); - $sql_cacher = \Mockery::mock( MslsSqlCacher::class ); + $sql_cacher = \Mockery::mock( SqlCacher::class ); $sql_cacher->shouldReceive( 'prepare' )->never(); $sql_cacher->shouldReceive( 'get_var' )->never(); diff --git a/tests/phpunit/Options/Query/TestQuery.php b/tests/phpunit/Options/Query/TestQuery.php index 9407683e9..0d303504a 100644 --- a/tests/phpunit/Options/Query/TestQuery.php +++ b/tests/phpunit/Options/Query/TestQuery.php @@ -3,7 +3,7 @@ namespace lloc\MslsTests\Options\Query; use Brain\Monkey\Functions; -use lloc\Msls\MslsSqlCacher; +use lloc\Msls\Db\SqlCacher; use lloc\Msls\Options\Query\Author; use lloc\Msls\Options\Query\Day; use lloc\Msls\Options\Query\Month; @@ -93,7 +93,7 @@ public function test_current_get_postlink(): void { Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); Functions\expect( 'home_url' )->once()->andReturn( $home_url ); - $sql_cache = \Mockery::mock( MslsSqlCacher::class ); + $sql_cache = \Mockery::mock( SqlCacher::class ); $this->assertEquals( $home_url, ( new Query( $sql_cache ) )->get_postlink( 'de_DE' ) ); } @@ -101,7 +101,7 @@ public function test_current_get_postlink(): void { public function test_non_existent_get_postlink(): void { Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); - $sql_cache = \Mockery::mock( MslsSqlCacher::class ); + $sql_cache = \Mockery::mock( SqlCacher::class ); $this->assertEquals( '', ( new Query( $sql_cache ) )->get_postlink( 'fr_FR' ) ); } @@ -109,7 +109,7 @@ public function test_non_existent_get_postlink(): void { public function test_get_permalink_returns_empty_when_no_translation(): void { Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); - $sql_cache = \Mockery::mock( MslsSqlCacher::class ); + $sql_cache = \Mockery::mock( SqlCacher::class ); $this->assertSame( '', ( new Query( $sql_cache ) )->get_permalink( 'fr_FR' ) ); } diff --git a/tests/phpunit/Options/TestOptions.php b/tests/phpunit/Options/TestOptions.php index 1971ef2a7..1710dc42f 100644 --- a/tests/phpunit/Options/TestOptions.php +++ b/tests/phpunit/Options/TestOptions.php @@ -3,8 +3,8 @@ namespace lloc\MslsTests\Options; use Brain\Monkey\Functions; +use lloc\Msls\Admin\Icon as MslsAdminIcon; use lloc\Msls\ContentTypes\PostType; -use lloc\Msls\MslsAdminIcon; use lloc\Msls\Options\Options; use lloc\MslsTests\MslsUnitTestCase; diff --git a/tests/phpunit/TestMslsPostTagClassic.php b/tests/phpunit/PostTag/TestClassic.php similarity index 88% rename from tests/phpunit/TestMslsPostTagClassic.php rename to tests/phpunit/PostTag/TestClassic.php index 4bc056428..5ed0d78d2 100644 --- a/tests/phpunit/TestMslsPostTagClassic.php +++ b/tests/phpunit/PostTag/TestClassic.php @@ -1,17 +1,18 @@ andReturn( array( 'de_DE' => 42, @@ -22,7 +23,7 @@ private function MslsPostTagClassicFactory(): MslsPostTagClassic { Functions\expect( 'get_post_types' )->andReturn( array( 'post', 'page' ) ); foreach ( array( 'de_DE', 'en_US' ) as $locale ) { - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( $locale ); $blogs[] = $blog; @@ -31,10 +32,10 @@ private function MslsPostTagClassicFactory(): MslsPostTagClassic { $options = \Mockery::mock( Options::class ); $options->shouldReceive( 'get_icon_type' )->andReturn( 'label' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get' )->andReturn( $blogs ); - return new MslsPostTagClassic( $options, $collection ); + return new Classic( $options, $collection ); } /** @@ -45,7 +46,7 @@ public function test_suggest(): void { self::expectOutputString( '' ); - MslsPostTagClassic::suggest(); + Classic::suggest(); } public function test_edit_input(): void { @@ -76,7 +77,7 @@ public function test_edit_input(): void { Functions\expect( 'msls_content_types' )->atLeast()->once()->andReturn( $taxonomy ); - Actions\expectDone( MslsPostTagClassic::MSLS_EDIT_INPUT_ACTION ); + Actions\expectDone( Classic::MSLS_EDIT_INPUT_ACTION ); $output = ' @@ -139,7 +140,7 @@ public function test_add_input(): void { Functions\expect( 'msls_content_types' )->atLeast()->once()->andReturn( $taxonomy ); - Actions\expectDone( MslsPostTagClassic::MSLS_ADD_INPUT_ACTION ); + Actions\expectDone( Classic::MSLS_ADD_INPUT_ACTION ); $output = '

Multisite Language Switcher

@@ -212,10 +213,10 @@ public function test_add_input(): void { public function test_the_input_no_blogs(): void { $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get' )->andReturn( array() ); - $value = ( new MslsPostTag( $options, $collection ) )->the_input( null, '', '' ); + $value = ( new PostTag( $options, $collection ) )->the_input( null, '', '' ); $this->assertFalse( $value ); } diff --git a/tests/phpunit/TestMslsRegistry.php b/tests/phpunit/Registry/TestRegistry.php similarity index 65% rename from tests/phpunit/TestMslsRegistry.php rename to tests/phpunit/Registry/TestRegistry.php index 0e61df696..48bf34196 100644 --- a/tests/phpunit/TestMslsRegistry.php +++ b/tests/phpunit/Registry/TestRegistry.php @@ -1,13 +1,14 @@ assertEquals( null, $obj->get_object( 'test_var' ) ); $obj->set_object( 'test_var', 1 ); diff --git a/tests/phpunit/TestMslsRestApi.php b/tests/phpunit/RestApi/TestRestApi.php similarity index 92% rename from tests/phpunit/TestMslsRestApi.php rename to tests/phpunit/RestApi/TestRestApi.php index 7fdfe09fc..eeb1d8f84 100644 --- a/tests/phpunit/TestMslsRestApi.php +++ b/tests/phpunit/RestApi/TestRestApi.php @@ -1,13 +1,14 @@ once()->with( 'edit_posts' )->andReturn( true ); Functions\expect( 'restore_current_blog' )->twice(); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertTrue( $api->check_permission( $request ) ); } @@ -53,7 +54,7 @@ public function test_check_permission_no_read_access(): void { Functions\expect( 'current_user_can' )->once()->with( 'read_post', 10 )->andReturn( false ); Functions\expect( 'restore_current_blog' )->once(); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertFalse( $api->check_permission( $request ) ); } @@ -75,7 +76,7 @@ public function test_capability_filter_can_grant_access_without_read_cap(): void ->with( true, 10, 1, 2, 'create' ) ->andReturn( true ); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertTrue( $api->check_permission( $request ) ); } @@ -93,7 +94,7 @@ public function test_capability_filter_can_deny_access_with_default_caps(): void ->with( true, 10, 1, 2, 'read' ) ->andReturn( false ); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertFalse( $api->check_permission( $request ) ); } @@ -108,7 +109,7 @@ public function test_check_permission_no_edit_access(): void { Functions\expect( 'current_user_can' )->once()->with( 'edit_posts' )->andReturn( false ); Functions\expect( 'restore_current_blog' )->twice(); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertFalse( $api->check_permission( $request ) ); } @@ -122,7 +123,7 @@ public function test_create_translation_source_not_found(): void { Functions\expect( 'get_post' )->once()->with( 999 )->andReturn( null ); Functions\expect( 'restore_current_blog' )->once(); - $api = new MslsRestApi(); + $api = new RestApi(); $result = $api->create_translation( $request ); $this->assertInstanceOf( \WP_Error::class, $result ); @@ -154,7 +155,7 @@ public function test_create_translation_success(): void { Functions\expect( 'add_option' )->andReturn( true ); Functions\expect( 'delete_option' )->andReturn( true ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_blog_id' )->andReturn( 1, 2 ); Functions\expect( 'msls_blog_collection' )->andReturn( $collection ); @@ -168,7 +169,7 @@ function ( $hook, $value ) { Functions\expect( 'do_action' )->andReturnNull(); - $api = new MslsRestApi(); + $api = new RestApi(); $result = $api->create_translation( $request ); $this->assertInstanceOf( \WP_REST_Response::class, $result ); @@ -192,7 +193,7 @@ public function test_prefix_source_language(): void { 'post_content' => 'Inhalt', ); - $result = MslsRestApi::prefix_source_language( $post_data, $source_post, 1, 2 ); + $result = RestApi::prefix_source_language( $post_data, $source_post, 1, 2 ); $this->assertEquals( 'From de: Hallo Welt', $result['post_title'] ); $this->assertEquals( 'Inhalt', $result['post_content'] ); @@ -200,11 +201,11 @@ public function test_prefix_source_language(): void { public function test_prefix_source_language_is_removable(): void { $this->assertTrue( - method_exists( MslsRestApi::class, 'prefix_source_language' ), + method_exists( RestApi::class, 'prefix_source_language' ), 'prefix_source_language must be a public static method for use with remove_filter' ); - $reflection = new \ReflectionMethod( MslsRestApi::class, 'prefix_source_language' ); + $reflection = new \ReflectionMethod( RestApi::class, 'prefix_source_language' ); $this->assertTrue( $reflection->isPublic() ); $this->assertTrue( $reflection->isStatic() ); } @@ -222,7 +223,7 @@ public function test_check_list_permission_denied_when_cannot_read_source(): voi ->with( false, 0, 1, 2, 'read' ) ->andReturn( false ); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertFalse( $api->check_list_permission( $request ) ); } @@ -243,7 +244,7 @@ public function test_check_list_permission_filter_can_grant_access(): void { ->with( true, 0, 1, 2, 'create' ) ->andReturn( true ); - $api = new MslsRestApi(); + $api = new RestApi(); $this->assertTrue( $api->check_list_permission( $request ) ); } @@ -278,7 +279,7 @@ public function test_list_untranslated_posts_returns_filtered_items(): void { Functions\expect( 'mysql2date' )->once()->with( 'Y-m-d\TH:i:s', '2026-04-20 12:00:00', false )->andReturn( '2026-04-20T12:00:00' ); Functions\expect( 'get_permalink' )->once()->with( $post )->andReturn( 'https://example.tld/?p=42' ); - $api = new MslsRestApi(); + $api = new RestApi(); $result = $api->list_untranslated_posts( $request ); $this->assertInstanceOf( \WP_REST_Response::class, $result ); @@ -297,9 +298,9 @@ public function test_remember_source_blog_writes_user_meta(): void { Functions\expect( 'get_current_user_id' )->once()->andReturn( 7 ); Functions\expect( 'update_user_meta' ) ->once() - ->with( 7, MslsRestApi::LAST_SOURCE_USER_META, 3 ); + ->with( 7, RestApi::LAST_SOURCE_USER_META, 3 ); - MslsRestApi::remember_source_blog( 42, \Mockery::mock( \WP_Post::class ), 3 ); + RestApi::remember_source_blog( 42, \Mockery::mock( \WP_Post::class ), 3 ); $this->assertTrue( true ); } @@ -308,7 +309,7 @@ public function test_remember_source_blog_skips_guest(): void { Functions\expect( 'get_current_user_id' )->once()->andReturn( 0 ); Functions\expect( 'update_user_meta' )->never(); - MslsRestApi::remember_source_blog( 42, \Mockery::mock( \WP_Post::class ), 3 ); + RestApi::remember_source_blog( 42, \Mockery::mock( \WP_Post::class ), 3 ); $this->assertTrue( true ); } @@ -317,10 +318,10 @@ public function test_get_last_source_blog_id_returns_value(): void { Functions\expect( 'get_current_user_id' )->once()->andReturn( 7 ); Functions\expect( 'get_user_meta' ) ->once() - ->with( 7, MslsRestApi::LAST_SOURCE_USER_META, true ) + ->with( 7, RestApi::LAST_SOURCE_USER_META, true ) ->andReturn( '5' ); - $this->assertSame( 5, MslsRestApi::get_last_source_blog_id() ); + $this->assertSame( 5, RestApi::get_last_source_blog_id() ); } public function test_list_untranslated_posts_rejects_unknown_post_type(): void { @@ -335,7 +336,7 @@ public function test_list_untranslated_posts_rejects_unknown_post_type(): void { Functions\expect( 'post_type_exists' )->once()->with( 'nonsense' )->andReturn( false ); Functions\expect( 'restore_current_blog' )->once(); - $api = new MslsRestApi(); + $api = new RestApi(); $result = $api->list_untranslated_posts( $request ); $this->assertInstanceOf( \WP_Error::class, $result ); diff --git a/tests/phpunit/TestMslsMain.php b/tests/phpunit/TestMslsMain.php index af7c4b8d9..810264482 100644 --- a/tests/phpunit/TestMslsMain.php +++ b/tests/phpunit/TestMslsMain.php @@ -3,8 +3,8 @@ namespace lloc\MslsTests; use Brain\Monkey\Functions; -use lloc\Msls\MslsBlog; -use lloc\Msls\MslsBlogCollection; +use lloc\Msls\Blog\Blog; +use lloc\Msls\Blog\Collection; use lloc\Msls\MslsMain; use lloc\Msls\Options\Options; @@ -13,10 +13,10 @@ final class TestMslsMain extends MslsUnitTestCase { private function MslsMainFactory(): MslsMain { $options = \Mockery::mock( Options::class ); - $blog = \Mockery::mock( MslsBlog::class ); + $blog = \Mockery::mock( Blog::class ); $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_current_blog' )->andReturn( $blog ); return new MslsMain( $options, $collection ); diff --git a/tests/phpunit/TestMslsPlugin.php b/tests/phpunit/TestMslsPlugin.php index fc68db789..e84df7d68 100644 --- a/tests/phpunit/TestMslsPlugin.php +++ b/tests/phpunit/TestMslsPlugin.php @@ -3,9 +3,9 @@ namespace lloc\MslsTests; use Brain\Monkey\Functions; -use lloc\Msls\MslsBlogCollection; +use lloc\Msls\Frontend\Output; +use lloc\Msls\Blog\Collection; use lloc\Msls\Options\Options; -use lloc\Msls\MslsOutput; use lloc\Msls\MslsPlugin; final class TestMslsPlugin extends MslsUnitTestCase { @@ -152,12 +152,12 @@ public function test_print_alternate_links(): void { $options = \Mockery::mock( Options::class ); - $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection = \Mockery::mock( Collection::class ); $collection->shouldReceive( 'get_objects' )->twice()->andReturn( array() ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->twice()->andReturn( $collection ); - Functions\expect( 'msls_output' )->once()->andReturn( MslsOutput::create() ); + Functions\expect( 'msls_output' )->once()->andReturn( Output::create() ); $this->expectOutputString( '' . PHP_EOL ); From f17893653c8e9a64d0002bfd65a96adafc87ebba Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sat, 16 May 2026 17:08:32 +0200 Subject: [PATCH 13/13] Version 3.0.0 prep --- MultisiteLanguageSwitcher.php | 201 +----------------- includes/Admin/Admin.php | 7 +- includes/Admin/CustomColumn.php | 3 +- includes/Admin/CustomFilter.php | 19 +- includes/{MslsMain.php => Admin/Main.php} | 14 +- includes/Admin/MetaBox.php | 51 +++-- includes/{ => Admin}/PostTag/Classic.php | 2 +- includes/{ => Admin}/PostTag/PostTag.php | 38 ++-- includes/Admin/TranslationPicker/Page.php | 4 +- includes/Blog/Collection.php | 4 +- includes/Component/Icon/IconPng.php | 4 +- includes/Component/Icon/IconSvg.php | 4 +- includes/ContentImport/ContentImporter.php | 22 +- .../Importers/WithRequestPostAttributes.php | 4 +- includes/ContentImport/MetaBox.php | 14 +- includes/ContentTypes/ContentTypes.php | 4 +- includes/ContentTypes/PostType.php | 4 +- includes/ContentTypes/Taxonomy.php | 4 +- includes/{MslsJson.php => Data/Json.php} | 6 +- .../LanguageArray.php} | 6 +- includes/Frontend/Block.php | 4 +- includes/Frontend/Output.php | 6 +- includes/Link/Link.php | 4 +- includes/Options/Options.php | 8 +- includes/{MslsPlugin.php => Plugin.php} | 18 +- .../{MslsGetSet.php => Registry/GetSet.php} | 8 +- includes/Registry/Registry.php | 7 + .../{MslsFields.php => Request/Fields.php} | 4 +- .../{MslsRequest.php => RestApi/Request.php} | 8 +- includes/aliases.php | 98 +++------ includes/api.php | 201 ++++++++++++++++++ .../{ => Admin}/PostTag/TestClassic.php | 19 +- .../{ => Admin}/PostTag/TestPostTag.php | 29 ++- tests/phpunit/Admin/TestCustomFilter.php | 12 +- tests/phpunit/Admin/TestIconTaxonomy.php | 5 +- .../{TestMslsMain.php => Admin/TestMain.php} | 13 +- tests/phpunit/Admin/TestMetaBox.php | 58 ++--- .../ContentImport/TestContentImporter.php | 6 +- .../phpunit/ContentTypes/TestContentTypes.php | 2 + tests/phpunit/ContentTypes/TestTaxonomy.php | 8 +- .../{TestMslsJson.php => Data/TestJson.php} | 11 +- .../TestLanguageArray.php} | 11 +- tests/phpunit/MslsUnitTestCase.php | 3 + .../TestGetSet.php} | 19 +- tests/phpunit/Request/TestMslsRequest.php | 82 +++++++ tests/phpunit/TestMslsRequest.php | 79 ------- .../{TestMslsPlugin.php => TestPlugin.php} | 28 +-- 47 files changed, 584 insertions(+), 582 deletions(-) rename includes/{MslsMain.php => Admin/Main.php} (90%) rename includes/{ => Admin}/PostTag/Classic.php (99%) rename includes/{ => Admin}/PostTag/PostTag.php (88%) rename includes/{MslsJson.php => Data/Json.php} (96%) rename includes/{MslsLanguageArray.php => Data/LanguageArray.php} (94%) rename includes/{MslsPlugin.php => Plugin.php} (97%) rename includes/{MslsGetSet.php => Registry/GetSet.php} (94%) rename includes/{MslsFields.php => Request/Fields.php} (97%) rename includes/{MslsRequest.php => RestApi/Request.php} (95%) create mode 100644 includes/api.php rename tests/phpunit/{ => Admin}/PostTag/TestClassic.php (91%) rename tests/phpunit/{ => Admin}/PostTag/TestPostTag.php (93%) rename tests/phpunit/{TestMslsMain.php => Admin/TestMain.php} (87%) rename tests/phpunit/{TestMslsJson.php => Data/TestJson.php} (62%) rename tests/phpunit/{TestMslsLanguageArray.php => Data/TestLanguageArray.php} (79%) rename tests/phpunit/{TestMslsGetSet.php => Registry/TestGetSet.php} (79%) create mode 100644 tests/phpunit/Request/TestMslsRequest.php delete mode 100644 tests/phpunit/TestMslsRequest.php rename tests/phpunit/{TestMslsPlugin.php => TestPlugin.php} (88%) diff --git a/MultisiteLanguageSwitcher.php b/MultisiteLanguageSwitcher.php index df3e72202..48740743c 100644 --- a/MultisiteLanguageSwitcher.php +++ b/MultisiteLanguageSwitcher.php @@ -3,7 +3,7 @@ * Multisite Language Switcher Plugin * * Plugin Name: Multisite Language Switcher - * Version: 2.10.1 + * Version: 3.0.0 * Plugin URI: http://msls.co/ * Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation. * Author: Dennis Ploetner @@ -45,207 +45,14 @@ * @author Dennis Ploetner */ if ( ! defined( 'MSLS_PLUGIN_VERSION' ) ) { - define( 'MSLS_PLUGIN_VERSION', '2.10.1' ); + define( 'MSLS_PLUGIN_VERSION', '3.0.0' ); define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) ); define( 'MSLS_PLUGIN__FILE__', __FILE__ ); require_once __DIR__ . '/includes/aliases.php'; require_once __DIR__ . '/includes/deprectated.php'; + require_once __DIR__ . '/includes/api.php'; - /** - * Get the output for using the links to the translations in your code - * - * @package Msls - * @param mixed $attr - * @return string - */ - function msls_get_switcher( $attr ): string { - $arr = is_array( $attr ) ? $attr : array(); - $obj = apply_filters( 'msls_get_output', null ); - - return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : ''; - } - - /** - * Output the links to the translations in your template - * - * You can call this function directly like that - * - * if ( function_exists ( 'the_msls' ) ) - * the_msls(); - * - * or just use it as shortcode [sc_msls] - * - * @package Msls - * @uses get_the_msls - * - * @param string[] $arr - */ - function msls_the_switcher( array $arr = array() ): void { - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo msls_get_switcher( $arr ); - } - - /** - * Gets the URL of the country flag-icon for a specific locale - * - * @param string $locale - * - * @return string - */ - function msls_get_flag_url( string $locale ): string { - return ( new \lloc\Msls\Options\Options() )->get_flag_url( $locale ); - } - - /** - * Gets the description for a blog for a specific locale - * - * @param string $locale - * @param string $preset - * - * @return string - */ - function msls_get_blog_description( string $locale, string $preset = '' ): string { - $blog = msls_blog( $locale ); - - return $blog ? $blog->get_description() : $preset; - } - - /** - * Gets the permalink for a translation of the current post in a given language - * - * @param string $locale - * @param string $preset - * - * @return string - */ - function msls_get_permalink( string $locale, string $preset = '' ): string { - $url = null; - $blog = msls_blog( $locale ); - - if ( $blog ) { - $options = \lloc\Msls\Options\Options::create(); - $url = $blog->get_url( $options ); - } - - return $url ?? $preset; - } - - /** - * Looks for the Blog instance for a specific locale - * - * @param string $locale - * - * @return \lloc\Msls\Blog\Blog|null - */ - function msls_blog( string $locale ): ?\lloc\Msls\Blog\Blog { - return msls_blog_collection()->get_blog( $locale ); - } - - /** - * Gets the Blog Collection instance - * - * @return \lloc\Msls\Blog\Collection - */ - function msls_blog_collection(): \lloc\Msls\Blog\Collection { - return \lloc\Msls\Blog\Collection::instance(); - } - - /** - * Gets the Options instance - * - * @return \lloc\Msls\Options\Options - */ - function msls_options(): \lloc\Msls\Options\Options { - return \lloc\Msls\Options\Options::instance(); - } - - /** - * Gets the MslsContentTypes instance - * - * @return \lloc\Msls\ContentTypes\ContentTypes - */ - function msls_content_types(): \lloc\Msls\ContentTypes\ContentTypes { - return \lloc\Msls\ContentTypes\ContentTypes::create(); - } - - /** - * Gets the MslsPostType instance - * - * @return \lloc\Msls\ContentTypes\PostType - */ - function msls_post_type(): \lloc\Msls\ContentTypes\PostType { - return \lloc\Msls\ContentTypes\PostType::instance(); - } - - /** - * Gets the MslsTaxonomy instance - * - * @return \lloc\Msls\ContentTypes\Taxonomy - */ - function msls_taxonomy(): \lloc\Msls\ContentTypes\Taxonomy { - return \lloc\Msls\ContentTypes\Taxonomy::instance(); - } - - /** - * Gets the Output instance - * - * @return \lloc\Msls\Frontend\Output - */ - function msls_output(): \lloc\Msls\Frontend\Output { - return \lloc\Msls\Frontend\Output::create(); - } - - /** - * Retrieves the OptionsPost instance. - * - * @param int $id - * - * @return \lloc\Msls\Options\Post\Post - */ - function msls_get_post( int $id ): \lloc\Msls\Options\Post\Post { - return new \lloc\Msls\Options\Post\Post( $id ); - } - - /** - * Retrieves the OptionsTax instance. - * - * Determines the current query based on conditional tags: - * - is_category - * - is_tag - * - is_tax - * - * @param int $id - * @return \lloc\Msls\Options\Tax\OptionsTaxInterface - */ - function msls_get_tax( int $id ): \lloc\Msls\Options\Tax\OptionsTaxInterface { - return \lloc\Msls\Options\Tax\Tax::create( $id ); - } - - /** - * Retrieves the OptionsQuery instance. - * - * Determines the current query based on conditional tags: - * - is_day - * - is_month - * - is_year - * - is_author - * - is_post_type_archive - * - * @return ?\lloc\Msls\Options\Query\Query - */ - function msls_get_query(): ?\lloc\Msls\Options\Query\Query { - return \lloc\Msls\Options\Query\Query::create(); - } - - /** - * Trivial void function for actions that do not return anything. - * - * @return void - */ - function msls_return_void(): void { - } - - lloc\Msls\MslsPlugin::init(); + lloc\Msls\Plugin::init(); lloc\Msls\Cli\Cli::init(); } diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index 78c70ad27..0bddacc1d 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -12,8 +12,7 @@ use lloc\Msls\Component\Input\Select; use lloc\Msls\Component\Input\Text; use lloc\Msls\Link\Link; -use lloc\Msls\MslsMain; -use lloc\Msls\MslsPlugin; +use lloc\Msls\Plugin; use lloc\Msls\Registry\Registry; use WP_Post_Type; @@ -34,7 +33,7 @@ * * @package Msls */ -final class Admin extends MslsMain { +final class Admin extends Main { const MSLS_REGISTER_ACTION = 'msls_admin_register'; @@ -175,7 +174,7 @@ public function has_problems(): void { ); } - MslsPlugin::message_handler( $message, 'updated fade' ); + Plugin::message_handler( $message, 'updated fade' ); } /** diff --git a/includes/Admin/CustomColumn.php b/includes/Admin/CustomColumn.php index 365346566..38aba4bb1 100644 --- a/includes/Admin/CustomColumn.php +++ b/includes/Admin/CustomColumn.php @@ -8,7 +8,6 @@ use lloc\Msls\Blog\Collection; use lloc\Msls\Component\Component; -use lloc\Msls\MslsMain; use lloc\Msls\Options\Options; /** @@ -17,7 +16,7 @@ * * @package Msls */ -class CustomColumn extends MslsMain { +class CustomColumn extends Main { public static function init(): void { $options = msls_options(); diff --git a/includes/Admin/CustomFilter.php b/includes/Admin/CustomFilter.php index a98e5563a..7d4f8141e 100644 --- a/includes/Admin/CustomFilter.php +++ b/includes/Admin/CustomFilter.php @@ -7,18 +7,17 @@ } use lloc\Msls\Component\Input\Select; -use lloc\Msls\MslsFields; -use lloc\Msls\MslsMain; -use lloc\Msls\MslsRequest; -use lloc\Msls\Db\SqlCacher; use lloc\Msls\Db\Query\TranslatedPostIdQuery; +use lloc\Msls\Db\SqlCacher; +use lloc\Msls\Request\Fields; +use lloc\Msls\RestApi\Request; /** * Adding custom filter to posts/pages table. * * @package Msls */ -final class CustomFilter extends MslsMain { +final class CustomFilter extends Main { /** * @codeCoverageIgnore @@ -36,7 +35,7 @@ public static function init(): void { add_filter( Select::RENDER_FILTER, function () { - return MslsFields::FIELD_MSLS_FILTER; + return Fields::FIELD_MSLS_FILTER; } ); } @@ -59,10 +58,10 @@ public function add_filter(): void { $options[ strval( $blog->userblog_id ) ] = sprintf( $format, $blog->get_description() ); } - $id = MslsRequest::get( MslsFields::FIELD_MSLS_FILTER, 0 ); + $id = Request::get( Fields::FIELD_MSLS_FILTER, 0 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo ( new Select( MslsFields::FIELD_MSLS_FILTER, $options, strval( $id ) ) )->render(); + echo ( new Select( Fields::FIELD_MSLS_FILTER, $options, strval( $id ) ) )->render(); } } @@ -74,11 +73,11 @@ public function add_filter(): void { * @return bool|\WP_Query */ public function execute_filter( \WP_Query $query ) { - if ( ! MslsRequest::has_var( MslsFields::FIELD_MSLS_FILTER ) ) { + if ( ! Request::has_var( Fields::FIELD_MSLS_FILTER ) ) { return false; } - $id = MslsRequest::get_var( MslsFields::FIELD_MSLS_FILTER ); + $id = Request::get_var( Fields::FIELD_MSLS_FILTER ); $blog = $this->collection->get_object( intval( $id ) ); if ( ! $blog ) { return false; diff --git a/includes/MslsMain.php b/includes/Admin/Main.php similarity index 90% rename from includes/MslsMain.php rename to includes/Admin/Main.php index 98a634848..6840d1112 100644 --- a/includes/MslsMain.php +++ b/includes/Admin/Main.php @@ -1,19 +1,23 @@ collection = $collection; } - public static function create(): MslsMain { + public static function create(): Main { return new static( msls_options(), msls_blog_collection() ); } @@ -112,7 +116,7 @@ public function is_autosave( $post_id ): bool { * @return boolean */ public function verify_nonce(): bool { - return MslsRequest::has_var( MslsFields::FIELD_MSLS_NONCENAME ) && wp_verify_nonce( MslsRequest::get_var( MslsFields::FIELD_MSLS_NONCENAME ), MslsPlugin::path() ); + return Request::has_var( Fields::FIELD_MSLS_NONCENAME ) && wp_verify_nonce( Request::get_var( Fields::FIELD_MSLS_NONCENAME ), Plugin::path() ); } /** @@ -157,7 +161,7 @@ protected function save( $object_id, $class_name ): void { } $language = $current_blog->get_language(); - $msla = new MslsLanguageArray( $this->get_input_array( $object_id ) ); + $msla = new LanguageArray( $this->get_input_array( $object_id ) ); $options = new $class_name( $object_id ); $temp = $options->get_arr(); diff --git a/includes/Admin/MetaBox.php b/includes/Admin/MetaBox.php index e420c4075..c3ca8b1cb 100644 --- a/includes/Admin/MetaBox.php +++ b/includes/Admin/MetaBox.php @@ -10,12 +10,11 @@ use lloc\Msls\Component\Component; use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\MetaBox as ContentImportMetaBox; -use lloc\Msls\MslsFields; -use lloc\Msls\MslsJson; -use lloc\Msls\MslsMain; -use lloc\Msls\MslsPlugin; -use lloc\Msls\MslsRequest; +use lloc\Msls\Data\Json; use lloc\Msls\Options\Post\Post; +use lloc\Msls\Plugin; +use lloc\Msls\Request\Fields; +use lloc\Msls\RestApi\Request; use WP_Post_Type; /** @@ -23,7 +22,7 @@ * * @package Msls */ -final class MetaBox extends MslsMain { +final class MetaBox extends Main { public static function init(): void { $options = msls_options(); @@ -43,25 +42,25 @@ public static function init(): void { * the requested search-term and then die silently */ public static function suggest(): void { - $json = new MslsJson(); + $json = new Json(); - if ( MslsRequest::has_var( MslsFields::FIELD_BLOG_ID, INPUT_POST ) ) { - switch_to_blog( MslsRequest::get_var( MslsFields::FIELD_BLOG_ID, INPUT_POST ) ); + if ( Request::has_var( Fields::FIELD_BLOG_ID, INPUT_POST ) ) { + switch_to_blog( Request::get_var( Fields::FIELD_BLOG_ID, INPUT_POST ) ); $args = array( 'post_status' => get_post_stati( array( 'internal' => '' ) ), 'posts_per_page' => 10, ); - if ( MslsRequest::has_var( MslsFields::FIELD_POST_TYPE, INPUT_POST ) ) { + if ( Request::has_var( Fields::FIELD_POST_TYPE, INPUT_POST ) ) { $args['post_type'] = sanitize_text_field( - MslsRequest::get_var( MslsFields::FIELD_POST_TYPE, INPUT_POST ) + Request::get_var( Fields::FIELD_POST_TYPE, INPUT_POST ) ); } - if ( MslsRequest::has_var( MslsFields::FIELD_S, INPUT_POST ) ) { + if ( Request::has_var( Fields::FIELD_S, INPUT_POST ) ) { $value_s = sanitize_text_field( - MslsRequest::get_var( MslsFields::FIELD_S, INPUT_POST ) + Request::get_var( Fields::FIELD_S, INPUT_POST ) ); /** @@ -87,10 +86,10 @@ public static function suggest(): void { 'msls_meta_box_suggest_results', $json->get(), array( - 'blog_id' => MslsRequest::get_var( MslsFields::FIELD_BLOG_ID, INPUT_POST ), - 'post_type' => MslsRequest::get_var( MslsFields::FIELD_POST_TYPE, INPUT_POST ), - 's' => MslsRequest::get_var( MslsFields::FIELD_S, INPUT_POST ), - 'source_id' => MslsRequest::get_var( MslsFields::FIELD_SOURCE_ID, INPUT_POST ), + 'blog_id' => Request::get_var( Fields::FIELD_BLOG_ID, INPUT_POST ), + 'post_type' => Request::get_var( Fields::FIELD_POST_TYPE, INPUT_POST ), + 's' => Request::get_var( Fields::FIELD_S, INPUT_POST ), + 'source_id' => Request::get_var( Fields::FIELD_SOURCE_ID, INPUT_POST ), ) ); @@ -99,12 +98,12 @@ public static function suggest(): void { } /** - * @param MslsJson $json + * @param Json $json * @param array $args * - * @return MslsJson + * @return Json */ - public static function get_suggested_fields( MslsJson $json, array $args ): MslsJson { + public static function get_suggested_fields( Json $json, array $args ): Json { /** * Overrides the query-args for the 'suggest' fields in the MetaBox * @@ -205,7 +204,7 @@ public function render_select(): void { $temp = $post; - wp_nonce_field( MslsPlugin::path(), 'msls_noncename' ); + wp_nonce_field( Plugin::path(), 'msls_noncename' ); $lis = ''; @@ -350,7 +349,7 @@ public function render_input(): void { $temp = $post; $items = ''; - wp_nonce_field( MslsPlugin::path(), 'msls_noncename' ); + wp_nonce_field( Plugin::path(), 'msls_noncename' ); foreach ( $blogs as $blog ) { switch_to_blog( $blog->userblog_id ); @@ -485,7 +484,7 @@ public function set( $post_id ): void { return; } - $post_type = MslsRequest::get_var( MslsFields::FIELD_POST_TYPE ); + $post_type = Request::get_var( Fields::FIELD_POST_TYPE ); $capability = 'page' === $post_type ? 'edit_page' : 'edit_post'; if ( ! current_user_can( $capability, $post_id ) ) { @@ -503,17 +502,17 @@ public function set( $post_id ): void { * @return Post */ public function maybe_set_linked_post( Post $mydata ) { - if ( ! MslsRequest::isset( array( MslsFields::FIELD_MSLS_ID, MslsFields::FIELD_MSLS_LANG ) ) ) { + if ( ! Request::isset( array( Fields::FIELD_MSLS_ID, Fields::FIELD_MSLS_LANG ) ) ) { return $mydata; } - $origin_lang = MslsRequest::get_var( MslsFields::FIELD_MSLS_LANG ); + $origin_lang = Request::get_var( Fields::FIELD_MSLS_LANG ); if ( isset( $mydata->{$origin_lang} ) ) { return $mydata; } - $origin_post_id = MslsRequest::get_var( MslsFields::FIELD_MSLS_ID ); + $origin_post_id = Request::get_var( Fields::FIELD_MSLS_ID ); $origin_blog_id = $this->collection->get_blog_id( $origin_lang ); if ( null === $origin_blog_id ) { diff --git a/includes/PostTag/Classic.php b/includes/Admin/PostTag/Classic.php similarity index 99% rename from includes/PostTag/Classic.php rename to includes/Admin/PostTag/Classic.php index 6ca449e70..fc767b4fc 100644 --- a/includes/PostTag/Classic.php +++ b/includes/Admin/PostTag/Classic.php @@ -1,6 +1,6 @@ sanitize_text_field( $post_type ), 'orderby' => 'name', @@ -49,9 +49,9 @@ public static function suggest(): void { 'hide_empty' => 0, ); - if ( MslsRequest::has_var( MslsFields::FIELD_S ) ) { + if ( Request::has_var( Fields::FIELD_S ) ) { $args['search'] = sanitize_text_field( - MslsRequest::get_var( MslsFields::FIELD_S ) + Request::get_var( Fields::FIELD_S ) ); } @@ -96,10 +96,10 @@ public static function suggest(): void { 'msls_post_tag_suggest_results', $json->get(), array( - 'blog_id' => MslsRequest::get_var( MslsFields::FIELD_BLOG_ID ), - 'taxonomy' => MslsRequest::get_var( MslsFields::FIELD_POST_TYPE ), - 's' => MslsRequest::get_var( MslsFields::FIELD_S ), - 'source_id' => MslsRequest::get_var( MslsFields::FIELD_SOURCE_ID ), + 'blog_id' => Request::get_var( Fields::FIELD_BLOG_ID ), + 'taxonomy' => Request::get_var( Fields::FIELD_POST_TYPE ), + 's' => Request::get_var( Fields::FIELD_S ), + 'source_id' => Request::get_var( Fields::FIELD_SOURCE_ID ), ) ); @@ -266,17 +266,17 @@ public function set( $term_id ): void { * @return OptionsTaxInterface */ public function maybe_set_linked_term( OptionsTaxInterface $mydata ) { - if ( ! MslsRequest::isset( array( MslsFields::FIELD_MSLS_ID, MslsFields::FIELD_MSLS_LANG ) ) ) { + if ( ! Request::isset( array( Fields::FIELD_MSLS_ID, Fields::FIELD_MSLS_LANG ) ) ) { return $mydata; } - $origin_lang = MslsRequest::get_var( MslsFields::FIELD_MSLS_LANG ); + $origin_lang = Request::get_var( Fields::FIELD_MSLS_LANG ); if ( isset( $mydata->{$origin_lang} ) ) { return $mydata; } - $origin_term_id = MslsRequest::get_var( MslsFields::FIELD_MSLS_ID ); + $origin_term_id = Request::get_var( Fields::FIELD_MSLS_ID ); $origin_blog_id = $this->collection->get_blog_id( $origin_lang ); diff --git a/includes/Admin/TranslationPicker/Page.php b/includes/Admin/TranslationPicker/Page.php index e1bf6758c..dbde13544 100644 --- a/includes/Admin/TranslationPicker/Page.php +++ b/includes/Admin/TranslationPicker/Page.php @@ -5,7 +5,7 @@ use lloc\Msls\Admin\Icon; use lloc\Msls\Blog\Blog; use lloc\Msls\ContentTypes\PostType; -use lloc\Msls\MslsPlugin; +use lloc\Msls\Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -263,7 +263,7 @@ public static function enqueue( int $target_blog_id ): void { wp_enqueue_script( self::SCRIPT_HANDLE, - MslsPlugin::plugins_url( "$folder/msls-translation-picker.js" ), + Plugin::plugins_url( "$folder/msls-translation-picker.js" ), array( 'jquery', 'wp-api-fetch' ), $ver, array( 'in_footer' => true ) diff --git a/includes/Blog/Collection.php b/includes/Blog/Collection.php index c1c8f0a1b..f71f5c052 100644 --- a/includes/Blog/Collection.php +++ b/includes/Blog/Collection.php @@ -7,7 +7,7 @@ } use lloc\Msls\Admin\Admin; -use lloc\Msls\MslsPlugin; +use lloc\Msls\Plugin; use lloc\Msls\Registry\Instance; use lloc\Msls\Options\Options; @@ -253,7 +253,7 @@ public function is_plugin_active( $blog_id ) { $this->active_plugins = get_site_option( 'active_sitewide_plugins', array() ); } - $path = MslsPlugin::path(); + $path = Plugin::path(); if ( isset( $this->active_plugins[ $path ] ) ) { return true; } diff --git a/includes/Component/Icon/IconPng.php b/includes/Component/Icon/IconPng.php index eb60e2f8f..b8afb98d0 100644 --- a/includes/Component/Icon/IconPng.php +++ b/includes/Component/Icon/IconPng.php @@ -3,7 +3,7 @@ namespace lloc\Msls\Component\Icon; use lloc\Msls\Component\Icon; -use lloc\Msls\MslsPlugin; +use lloc\Msls\Plugin; /** * Class IconPng @@ -18,7 +18,7 @@ final class IconPng extends Icon { * @return string */ protected function get_include(): string { - return MslsPlugin::plugin_dir_path( self::FLAGS_FILE ); + return Plugin::plugin_dir_path( self::FLAGS_FILE ); } /** diff --git a/includes/Component/Icon/IconSvg.php b/includes/Component/Icon/IconSvg.php index c1f019671..fd43c3675 100644 --- a/includes/Component/Icon/IconSvg.php +++ b/includes/Component/Icon/IconSvg.php @@ -3,7 +3,7 @@ namespace lloc\Msls\Component\Icon; use lloc\Msls\Component\Icon; -use lloc\Msls\MslsPlugin; +use lloc\Msls\Plugin; /** * Class IconSvg @@ -18,7 +18,7 @@ final class IconSvg extends Icon { * @return string */ protected function get_include(): string { - return MslsPlugin::plugin_dir_path( self::FLAGS_FILE ); + return Plugin::plugin_dir_path( self::FLAGS_FILE ); } /** diff --git a/includes/ContentImport/ContentImporter.php b/includes/ContentImport/ContentImporter.php index f9293f8b0..dbc56e3cc 100644 --- a/includes/ContentImport/ContentImporter.php +++ b/includes/ContentImport/ContentImporter.php @@ -6,14 +6,14 @@ exit; } +use lloc\Msls\Admin\Main; use lloc\Msls\Blog\Collection; use lloc\Msls\ContentImport\Importers\Importer; use lloc\Msls\ContentImport\Importers\Map; use lloc\Msls\ContentImport\Importers\WithRequestPostAttributes; -use lloc\Msls\MslsMain; -use lloc\Msls\Registry\Instance; -use lloc\Msls\MslsRequest; use lloc\Msls\Options\Post\Post; +use lloc\Msls\Registry\Instance; +use lloc\Msls\RestApi\Request; /** * Class ContentImporter @@ -30,9 +30,9 @@ class ContentImporter extends Instance { const MSLS_AFTER_IMPORT_ACTION = 'msls_content_import_after_import'; /** - * @var MslsMain + * @var Main */ - protected MslsMain $main; + protected Main $main; /** * @var ImportLogger|null @@ -57,10 +57,10 @@ class ContentImporter extends Instance { /** * ContentImporter constructor. * - * @param ?MslsMain $main + * @param ?Main $main */ - public function __construct( ?MslsMain $main = null ) { - $this->main = ! is_null( $main ) ? $main : MslsMain::create(); + public function __construct( ?Main $main = null ) { + $this->main = ! is_null( $main ) ? $main : Main::create(); } /** @@ -183,11 +183,11 @@ protected function pre_flight_check() { * @return array{0: int, 1: int}|null */ public function parse_sources(): ?array { - if ( ! MslsRequest::has_var( 'msls_import' ) ) { + if ( ! Request::has_var( 'msls_import' ) ) { return null; } - $msls_import = MslsRequest::get_var( 'msls_import' ); + $msls_import = Request::get_var( 'msls_import' ); $import_data = array_values( array_filter( explode( '|', trim( $msls_import ) ), 'is_numeric' ) ); if ( count( $import_data ) !== 2 ) { @@ -213,7 +213,7 @@ protected function get_the_blog_post_ID( $blog_id ): int { return $id; } - $request = MslsRequest::get_request( array( 'post' ) ); + $request = Request::get_request( array( 'post' ) ); if ( ! empty( $request['post'] ) ) { return (int) $request['post']; } diff --git a/includes/ContentImport/Importers/WithRequestPostAttributes.php b/includes/ContentImport/Importers/WithRequestPostAttributes.php index 69b41f740..d4a605f82 100644 --- a/includes/ContentImport/Importers/WithRequestPostAttributes.php +++ b/includes/ContentImport/Importers/WithRequestPostAttributes.php @@ -10,7 +10,7 @@ namespace lloc\Msls\ContentImport\Importers; -use lloc\Msls\MslsRequest; +use lloc\Msls\RestApi\Request; /** * Trait WithRequestPostAttributes @@ -28,7 +28,7 @@ trait WithRequestPostAttributes { * @return string Either the post type read from the `$_REQUEST` super-global, or the default value. */ protected function read_post_type_from_request( $preset = 'post' ) { - $request = MslsRequest::get_request( array( 'post_type' ), $preset ); + $request = Request::get_request( array( 'post_type' ), $preset ); return $request['post_type']; } diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index e1f96ef31..3e67ef83d 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -6,11 +6,11 @@ use lloc\Msls\Component\Component; use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\Importers\Map; -use lloc\Msls\MslsFields; -use lloc\Msls\MslsPlugin; -use lloc\Msls\Registry\Instance; -use lloc\Msls\MslsRequest; use lloc\Msls\Options\Post\Post; +use lloc\Msls\Plugin; +use lloc\Msls\Registry\Instance; +use lloc\Msls\Request\Fields; +use lloc\Msls\RestApi\Request; class MetaBox extends Instance { @@ -32,8 +32,8 @@ public function render(): void { $languages = Post::instance()->get_available_languages(); $current = Collection::get_blog_language( get_current_blog_id() ); $languages = array_diff_key( $languages, array( $current => $current ) ); - $input_lang = MslsRequest::get( MslsFields::FIELD_MSLS_LANG, null ); - $input_id = MslsRequest::get( MslsFields::FIELD_MSLS_ID, null ); + $input_lang = Request::get( Fields::FIELD_MSLS_LANG, null ); + $input_id = Request::get( Fields::FIELD_MSLS_ID, null ); $has_input = null !== $input_lang && null !== $input_id; $blogs = msls_blog_collection(); $available = array_filter( @@ -141,7 +141,7 @@ protected function inline_thickbox_html( $output = true, array $data = array() )