From db608734db9068842ac5c5e29c0d4b2359cb7ea6 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sat, 14 Sep 2024 12:06:06 +0200 Subject: [PATCH] Widget tested --- phpunit.xml | 2 +- tests/phpunit/TestMslsWidget.php | 23 +++++++++++++++++++++-- tests/phpunit/WP_Widget.php | 18 ++++++++++++++++++ tests/phpunit/bootstrap.php | 3 +++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/WP_Widget.php create mode 100644 tests/phpunit/bootstrap.php diff --git a/phpunit.xml b/phpunit.xml index 292b2e28..a8c3f5df 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/phpunit/TestMslsWidget.php b/tests/phpunit/TestMslsWidget.php index 790faf13..99ca827d 100644 --- a/tests/phpunit/TestMslsWidget.php +++ b/tests/phpunit/TestMslsWidget.php @@ -13,9 +13,19 @@ class TestMslsWidget extends MslsUnitTestCase { protected function setUp(): void { parent::setUp(); - \Mockery::mock( '\WP_Widget' ); + $this->test = new MslsWidget(); + } + + public function test_init(): void { + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'is_excluded' )->once()->andReturn( false ); + + Functions\expect( 'msls_options' )->once()->andReturn( $options ); + Functions\expect( 'register_widget' )->once()->with( MslsWidget::class ); - $this->test = \Mockery::mock( MslsWidget::class )->makePartial(); + $this->expectNotToPerformAssertions(); + + $this->test->init(); } public function test_widget(): void { @@ -53,4 +63,13 @@ public function test_update(): void { $result = $this->test->update( array( 'title' => 'xyz' ), array( 'title' => 'abc' ) ); $this->assertEquals( array( 'title' => 'xyz' ), $result ); } + + public function test_form(): void { + $expected = '

'; + + $this->expectOutputString( $expected ); + + $result = $this->test->form( array() ); + $this->assertEquals( $expected, $result ); + } } diff --git a/tests/phpunit/WP_Widget.php b/tests/phpunit/WP_Widget.php new file mode 100644 index 00000000..8f8191c8 --- /dev/null +++ b/tests/phpunit/WP_Widget.php @@ -0,0 +1,18 @@ +