diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 0170670..9c239ee 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,5 +1,8 @@ name: E2E Tests -on: [push] +on: + push: + branches-ignore: + - 'main-built' jobs: test: diff --git a/.github/workflows/js.yml b/.github/workflows/js.yml index b5db942..18e19ee 100644 --- a/.github/workflows/js.yml +++ b/.github/workflows/js.yml @@ -1,5 +1,8 @@ name: JS lint & test -on: [push] +on: + push: + branches-ignore: + - 'main-built' jobs: build: diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 36d3190..ee81930 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,5 +1,8 @@ name: PHP lint & test -on: [push] +on: + push: + branches-ignore: + - 'main-built' jobs: lint-test: diff --git a/phpunit-integration.xml b/phpunit-integration.xml index ba53656..bf755a2 100644 --- a/phpunit-integration.xml +++ b/phpunit-integration.xml @@ -1,8 +1,8 @@ - + - ./includes/Api + ./includes diff --git a/tests/integration/FlagTest.php b/tests/integration/FlagTest.php new file mode 100644 index 0000000..37c7b2a --- /dev/null +++ b/tests/integration/FlagTest.php @@ -0,0 +1,53 @@ + 1, 'name' => 'test', 'enabled' => true ]]; + update_option(Flag::$option_name, $optionValue); + + $result = Flag::is_enabled('test'); + + $this->assertTrue($result); + } + + public function test_is_enabled_returns_false_if_flags_exists_and_disabled(): void { + // Set up test data + $optionValue = [['id' => 1, 'name' => 'test', 'enabled' => false ]]; + update_option(Flag::$option_name, $optionValue); + + $result = Flag::is_enabled('test'); + + $this->assertFalse($result); + } + + public function test_is_enabled_returns_false_if_flags_not_exists(): void { + // Set up test data + $optionValue = [['id' => 1, 'name' => 'test2', 'enabled' => true ]]; + update_option(Flag::$option_name, $optionValue); + + $result = Flag::is_enabled('test'); + + $this->assertFalse($result); + } + + public function test_is_enabled_returns_false_if_option_is_empty(): void { + // Set up test data + $optionValue = []; + update_option(Flag::$option_name, $optionValue); + + $result = Flag::is_enabled('test'); + + $this->assertFalse($result); + } + + public function test_is_enabled_returns_false_if_option_not_exists(): void { + + $result = Flag::is_enabled('test'); + + $this->assertFalse($result); + } +} diff --git a/tests/integration/FlagsApiTest.php b/tests/integration/FlagsApiTest.php index 4180429..ed799ec 100644 --- a/tests/integration/FlagsApiTest.php +++ b/tests/integration/FlagsApiTest.php @@ -184,7 +184,7 @@ public function test_create_item_with_default_max_allowed_filter() { $response_message = $response->get_data()['message']; $this->assertErrorResponse( 'flag_limit_exceeded', $response, 400 ); - $this->assertEquals('Maximum allowed flags are 20', $response_message); + $this->assertEquals('Cannot add more than 20 flags', $response_message); } @@ -206,8 +206,7 @@ public function test_create_item_with_custom_max_allowed_filter() { $response_message = $response->get_data()['message']; $this->assertErrorResponse( 'flag_limit_exceeded', $response, 400 ); - $this->assertEquals('Maximum allowed flags are 3', $response_message); - + $this->assertEquals('Cannot add more than 3 flags', $response_message); } public function test_create_item_without_input() { diff --git a/tests/unit/FlagTest.php b/tests/unit/FlagTest.php index eb36615..67736f3 100644 --- a/tests/unit/FlagTest.php +++ b/tests/unit/FlagTest.php @@ -41,5 +41,4 @@ public function test_is_enabled_method_should_return_false_if_flag_name_not_exis $this->assertFalse($result); } - } diff --git a/tests/unit/SettingsTest.php b/tests/unit/SettingsTest.php new file mode 100644 index 0000000..c8ad20e --- /dev/null +++ b/tests/unit/SettingsTest.php @@ -0,0 +1,62 @@ +andReturnUsing(function ($string) { + return $string; // Simulate translation for testing purposes + }); + } + + public function tearDown(): void { + \Brain\Monkey\tearDown(); + parent::tearDown(); + } + + public function testRegisterFeatureSettings() { + $settings = new Settings(); + + \Brain\Monkey\Functions\expect('add_action') + ->once() + ->with('admin_menu', [$settings, 'register_settings']); + + $settings->register_feature_settings(); + } + + public function testRegisterSettings() { + $settings = new Settings(); + + \Brain\Monkey\Functions\expect('add_menu_page') + ->once() + ->with( + 'Feature Flags', + 'Feature Flags', + 'manage_options', + 'mr-feature-flags', + [$settings, 'render_page'], + 'data:image/svg+xml;base64,' . base64_encode( '' ) + ); + + $settings->register_settings(); + } + + public function testRenderPage() { + $settings = new Settings(); + + ob_start(); + + $settings->render_page(); + + $output = ob_get_clean(); + + $this->assertStringContainsString('
', $output); + } +}