|
| 1 | +<?php |
| 2 | +use MR\FeatureFlags\Flag; |
| 3 | +use Yoast\WPTestUtils\WPIntegration\TestCase; |
| 4 | + |
| 5 | +class FlagTest extends TestCase{ |
| 6 | + |
| 7 | + public function test_is_enabled_returns_true_if_flags_exists_and_enabled(): void { |
| 8 | + // Set up test data |
| 9 | + $optionValue = [['id' => 1, 'name' => 'test', 'enabled' => true ]]; |
| 10 | + update_option(Flag::$option_name, $optionValue); |
| 11 | + |
| 12 | + $result = Flag::is_enabled('test'); |
| 13 | + |
| 14 | + $this->assertTrue($result); |
| 15 | + } |
| 16 | + |
| 17 | + public function test_is_enabled_returns_false_if_flags_exists_and_disabled(): void { |
| 18 | + // Set up test data |
| 19 | + $optionValue = [['id' => 1, 'name' => 'test', 'enabled' => false ]]; |
| 20 | + update_option(Flag::$option_name, $optionValue); |
| 21 | + |
| 22 | + $result = Flag::is_enabled('test'); |
| 23 | + |
| 24 | + $this->assertFalse($result); |
| 25 | + } |
| 26 | + |
| 27 | + public function test_is_enabled_returns_false_if_flags_not_exists(): void { |
| 28 | + // Set up test data |
| 29 | + $optionValue = [['id' => 1, 'name' => 'test2', 'enabled' => true ]]; |
| 30 | + update_option(Flag::$option_name, $optionValue); |
| 31 | + |
| 32 | + $result = Flag::is_enabled('test'); |
| 33 | + |
| 34 | + $this->assertFalse($result); |
| 35 | + } |
| 36 | + |
| 37 | + public function test_is_enabled_returns_false_if_option_is_empty(): void { |
| 38 | + // Set up test data |
| 39 | + $optionValue = []; |
| 40 | + update_option(Flag::$option_name, $optionValue); |
| 41 | + |
| 42 | + $result = Flag::is_enabled('test'); |
| 43 | + |
| 44 | + $this->assertFalse($result); |
| 45 | + } |
| 46 | + |
| 47 | + public function test_is_enabled_returns_false_if_option_not_exists(): void { |
| 48 | + |
| 49 | + $result = Flag::is_enabled('test'); |
| 50 | + |
| 51 | + $this->assertFalse($result); |
| 52 | + } |
| 53 | +} |
0 commit comments