From 194424f2e0dbdc0b72827a45acf42c8d70a86c07 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Wed, 13 May 2026 13:15:15 +0200 Subject: [PATCH 01/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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;