Skip to content

Commit 593de3a

Browse files
authored
Merge pull request #374 from lloc/raise-coverage
Widget tested
2 parents 7a54a93 + db60873 commit 593de3a

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
2+
<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">
33
<php>
44
<const name="MSLS_PLUGIN_PATH" value="multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
55
<const name="MSLS_PLUGIN__FILE__" value="/var/www/html/wp-content/plugins/multisite-language-switcher/MultisiteLanguageSwitcher.php"/>

tests/phpunit/TestMslsWidget.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ class TestMslsWidget extends MslsUnitTestCase {
1313
protected function setUp(): void {
1414
parent::setUp();
1515

16-
\Mockery::mock( '\WP_Widget' );
16+
$this->test = new MslsWidget();
17+
}
18+
19+
public function test_init(): void {
20+
$options = \Mockery::mock( MslsOptions::class );
21+
$options->shouldReceive( 'is_excluded' )->once()->andReturn( false );
22+
23+
Functions\expect( 'msls_options' )->once()->andReturn( $options );
24+
Functions\expect( 'register_widget' )->once()->with( MslsWidget::class );
1725

18-
$this->test = \Mockery::mock( MslsWidget::class )->makePartial();
26+
$this->expectNotToPerformAssertions();
27+
28+
$this->test->init();
1929
}
2030

2131
public function test_widget(): void {
@@ -53,4 +63,13 @@ public function test_update(): void {
5363
$result = $this->test->update( array( 'title' => 'xyz' ), array( 'title' => 'abc' ) );
5464
$this->assertEquals( array( 'title' => 'xyz' ), $result );
5565
}
66+
67+
public function test_form(): void {
68+
$expected = '<p><label for="title">Title:</label> <input class="widefat" id="title" name="title" type="text" value="" /></p>';
69+
70+
$this->expectOutputString( $expected );
71+
72+
$result = $this->test->form( array() );
73+
$this->assertEquals( $expected, $result );
74+
}
5675
}

tests/phpunit/WP_Widget.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace lloc\MslsTests;
4+
5+
class WP_Widget {
6+
7+
8+
public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
9+
}
10+
11+
public function get_field_id( $id ) {
12+
return $id;
13+
}
14+
15+
public function get_field_name( $name ) {
16+
return $name;
17+
}
18+
}

tests/phpunit/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
class_alias( \lloc\MslsTests\WP_Widget::class, '\WP_Widget' );

0 commit comments

Comments
 (0)