Skip to content

Commit

Permalink
Merge pull request #379 from lloc/raise-coverage
Browse files Browse the repository at this point in the history
Tests added
  • Loading branch information
lloc authored Sep 21, 2024
2 parents 4c5b37f + 6c3fae1 commit 5fe6277
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 13 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"squizlabs/php_codesniffer": "^3.9",
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^3.0",
"smeghead/php-class-diagram": "^1.3"
"smeghead/php-class-diagram": "^1.3",
"phpstan/phpstan-mockery": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion includes/ContentImport/AttachmentPathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AttachmentPathFinder extends MslsRegistryInstance {
* @param string $imageSrc
* @param mixed $imageMeta
* @param int $attachmentId
* @return array
* @return array<string, string>
*/
public function filter_srcset( array $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId ): array {
if ( ! $msls_imported = $this->has_import_data( $attachmentId ) ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/MslsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
class MslsWidget extends \WP_Widget {

public $id_base = 'mslswidget';
public const ID_BASE = 'mslswidget';

public function __construct() {
$name = apply_filters(
'msls_widget_title',
__( 'Multisite Language Switcher', 'multisite-language-switcher' )
);

parent::__construct( $this->id_base, $name, array( 'show_instance_in_rest' => true ) );
parent::__construct( self::ID_BASE, $name, array( 'show_instance_in_rest' => true ) );
}

public static function init(): void {
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ parameters:
- includes
excludePaths:
- vendor
- tests
bootstrapFiles:
- tests/phpstan/bootstrap.php
8 changes: 7 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/phpunit/bootstrap.php" backupGlobals="true" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/phpunit/bootstrap.php"
backupGlobals="true"
colors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
cacheDirectory=".phpunit.cache">
<php>
<const name="MSLS_PLUGIN_PATH" value="multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
<const name="MSLS_PLUGIN__FILE__" value="/var/www/html/wp-content/plugins/multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
Expand Down
5 changes: 3 additions & 2 deletions tests/phpunit/TestMslsPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public function test_edit_input(): void {
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_tag' ) );

$term = \Mockery::mock( \WP_Term::class );
$term = \Mockery::mock( \WP_Term::class );
$term->name = 'test-term-name';

Functions\expect( 'msls_content_types' )->atLeast()->once()->andReturn( $taxonomy );
Functions\expect( 'get_queried_object_id' )->atLeast()->once()->andReturn( 42 );
Expand All @@ -115,7 +116,7 @@ public function test_edit_input(): void {
</th>
<td>
<input type="hidden" id="msls_id_" name="msls_input_de_DE" value="42"/>
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value=""/>
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value="test-term-name"/>
</td>
</tr><tr class="form-field">
<th scope="row">
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/TestMslsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function test_update(): void {
}

public function test_form(): void {
$expected = '<p><label for="title">Title:</label> <input class="widefat" id="title" name="title" type="text" value="" /></p>';
$expected = '<p><label for="field-id-title">Title:</label> <input class="widefat" id="field-id-title" name="field-name-title" type="text" value="" /></p>';

$this->expectOutputString( $expected );

Expand Down
34 changes: 30 additions & 4 deletions tests/phpunit/WP_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,43 @@

namespace lloc\MslsTests;

#[AllowDynamicProperties]
class WP_Widget {

public $id_base;

/**
* PHP5 constructor.
*
* @since 2.8.0
*
* @param string $id_base Base ID for the widget, lowercase and unique. If left empty,
* a portion of the widget's PHP class name will be used. Has to be unique.
* @param string $name Name for the widget displayed on the configuration page.
* @param array $widget_options Optional. Widget options. See wp_register_sidebar_widget() for
* information on accepted arguments. Default empty array.
* @param array $control_options Optional. Widget control options. See wp_register_widget_control() for
* information on accepted arguments. Default empty array.
*/
public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
}

public function get_field_id( $id ) {
return $id;

/**
* @param string $field_name Field name.
*
* @return string ID attribute for `$field_name`.
*/
public function get_field_id( string $field_name ) {
return sprintf( 'field-id-%s', esc_attr( $field_name ) );
}

public function get_field_name( $name ) {
return $name;
/**
* @param string $field_name Field name.
*
* @return string Name attribute for `$field_name`.
*/
public function get_field_name( $field_name ) {
return sprintf( 'field-name-%s', esc_attr( $field_name ) );
}
}

0 comments on commit 5fe6277

Please sign in to comment.