Skip to content

Commit

Permalink
Merge branch 'develop' into feature/issue-3763
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia authored Feb 11, 2025
2 parents b3f96cf + 35f1037 commit 19ed654
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 0 deletions.
3 changes: 3 additions & 0 deletions includes/classes/REST/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function get_args() {
case 'toggle':
$property['type'] = 'boolean';
break;
case 'number':
$property['type'] = 'number';
break;
case 'url':
$property['type'] = 'string';
$property['format'] = 'uri';
Expand Down
89 changes: 89 additions & 0 deletions tests/php/REST/TestFeatures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Test the Features REST controller
*
* @since 5.3.0
* @package elasticpress
*/

namespace ElasticPressTest\REST;

use ElasticPress\REST\Features;

/**
* TestFeatures test class
*/
class TestFeatures extends \ElasticPressTest\BaseTestCase {
/**
* Test get_args.
*
* @group rest
* @group rest-features
*/
public function test_get_args() {
$features_rest = new Features();
$features_instance = \ElasticPress\Features::factory();

$features_instance->register_feature(
new \ElasticPressTest\SettingsSchemaFeature()
);

$args = $features_rest->get_args();

$test_settings_schema = [
'description' => 'Test Settings Schema',
'type' => 'object',
'properties' => [
'active' => [
'description' => 'Enable',
'type' => 'boolean',
],
'test-select' => [
'description' => 'Test Select',
'type' => 'string',
'enum' => [
'option_1',
'option_2',
],
],
'test-radio' => [
'description' => 'Test Radio',
'type' => 'string',
'enum' => [
'radio_1',
'radio_2',
],
],
'test-toggle' => [
'description' => 'Test Toggle',
'type' => 'boolean',
],
'test-number' => [
'description' => 'Test Number',
'type' => 'number',
],
'test-url' => [
'description' => 'Test URL',
'type' => 'string',
'format' => 'uri',
],
'test-text' => [
'description' => 'Test Text',
'type' => 'string',
],
'test-non-existent' => [
'description' => 'Test Non Existent',
'type' => 'string',
],
'test-string' => [
'description' => 'Test String',
'type' => 'string',
],
],
];

$this->assertEquals( $test_settings_schema, $args['test_settings_schema'] );

unset( $features_instance->registered_features['test_settings_schema'] );
}
}
1 change: 1 addition & 0 deletions tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function drop_wc_order_table( $query ) {
require_once __DIR__ . '/includes/classes/FeatureTest.php';
require_once __DIR__ . '/includes/classes/FunctionsCallCounter.php';
require_once __DIR__ . '/includes/classes/mock/Global/Feature.php';
require_once __DIR__ . '/includes/classes/mock/SettingsSchemaFeature.php';
require_once __DIR__ . '/includes/classes/mock/class-wp-cli-command.php';
require_once __DIR__ . '/includes/classes/mock/class-wp-cli.php';
require_once __DIR__ . '/includes/wp-cli-utils.php';
107 changes: 107 additions & 0 deletions tests/php/includes/classes/mock/SettingsSchemaFeature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* SettingsSchemaFeature feature
*
* @since 5.3.0
* @package elasticpress
*/

namespace ElasticPressTest;

use ElasticPress\Indexables;

/**
* SettingsSchemaFeature class
*/
class SettingsSchemaFeature extends \ElasticPress\Feature {
/**
* Initialize feature setting it's config
*/
public function __construct() {
$this->slug = 'test_settings_schema';
$this->title = 'Test Settings Schema';

parent::__construct();
}

/**
* Required implementation
*/
public function setup() {}

/**
* Output feature box long text
*/
public function output_feature_box_long() {}

/**
* Set the `settings_schema` attribute
*/
protected function set_settings_schema() {
$this->settings_schema = array_merge(
$this->settings_schema,
[
'test-select' => [
'key' => 'test-select',
'label' => 'Test Select',
'type' => 'select',
'options' => [
[
'label' => 'Option 1',
'value' => 'option_1',
],
[
'label' => 'Option 2',
'value' => 'option_2',
],
],
],
'test-radio' => [
'key' => 'test-radio',
'label' => 'Test Radio',
'type' => 'radio',
'options' => [
[
'label' => 'Radio 1',
'value' => 'radio_1',
],
[
'label' => 'Radio 2',
'value' => 'radio_2',
],
],
],
'test-toggle' => [
'key' => 'test-toggle',
'label' => 'Test Toggle',
'type' => 'toggle',
],
'test-number' => [
'key' => 'test-number',
'label' => 'Test Number',
'type' => 'number',
],
'test-url' => [
'key' => 'test-url',
'label' => 'Test URL',
'type' => 'url',
],
'test-text' => [
'key' => 'test-text',
'label' => 'Test Text',
'type' => 'text',
],
'test-non-existent' => [
'key' => 'test-non-existent',
'label' => 'Test Non Existent',
'type' => 'non-existent',
],
'test-string' => [
'key' => 'test-string',
'label' => 'Test String',
'type' => 'string',
],
]
);
}
}

0 comments on commit 19ed654

Please sign in to comment.