Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: E2E Tests
on: [push]
on:
push:
branches-ignore:
- 'main-built'

jobs:
test:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/js.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: JS lint & test
on: [push]
on:
push:
branches-ignore:
- 'main-built'

jobs:
build:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: PHP lint & test
on: [push]
on:
push:
branches-ignore:
- 'main-built'

jobs:
lint-test:
Expand Down
4 changes: 2 additions & 2 deletions phpunit-integration.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/integration/bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./includes/Api</directory>
<directory suffix=".php">./includes</directory>
</include>
</coverage>
<testsuites>
Expand Down
53 changes: 53 additions & 0 deletions tests/integration/FlagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
use MR\FeatureFlags\Flag;
use Yoast\WPTestUtils\WPIntegration\TestCase;

class FlagTest extends TestCase{

public function test_is_enabled_returns_true_if_flags_exists_and_enabled(): void {
// Set up test data
$optionValue = [['id' => 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);
}
}
5 changes: 2 additions & 3 deletions tests/integration/FlagsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand All @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/FlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public function test_is_enabled_method_should_return_false_if_flag_name_not_exis
$this->assertFalse($result);
}


}
62 changes: 62 additions & 0 deletions tests/unit/SettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
use Yoast\WPTestUtils\BrainMonkey\TestCase;
use MR\FeatureFlags\Settings;

class SettingsTest extends TestCase {

public function setUp(): void {
parent::setUp();

\Brain\Monkey\setUp();

// Mock the __ function for translation
\Brain\Monkey\Functions\expect('__')
->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( '<svg width="15" height="18" viewBox="0 0 2000 1792" xmlns="http://www.w3.org/2000/svg"><path fill="black" d="M0 896q0-130 51-248.5t136.5-204 204-136.5 248.5-51h768q130 0 248.5 51t204 136.5 136.5 204 51 248.5-51 248.5-136.5 204-204 136.5-248.5 51h-768q-130 0-248.5-51t-204-136.5-136.5-204-51-248.5zm1408 512q104 0 198.5-40.5t163.5-109.5 109.5-163.5 40.5-198.5-40.5-198.5-109.5-163.5-163.5-109.5-198.5-40.5-198.5 40.5-163.5 109.5-109.5 163.5-40.5 198.5 40.5 198.5 109.5 163.5 163.5 109.5 198.5 40.5z"/></svg>' )
);

$settings->register_settings();
}

public function testRenderPage() {
$settings = new Settings();

ob_start();

$settings->render_page();

$output = ob_get_clean();

$this->assertStringContainsString('<div id="mr_feature_flags_settings_screen"></div>', $output);
}
}