Skip to content

Commit

Permalink
wp-graphql#156-options-queries
Browse files Browse the repository at this point in the history
Updates to tests and making sure the option is cast as the proper type when it's returned
  • Loading branch information
jasonbahl committed Oct 27, 2017
1 parent b745a59 commit 1195c90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Data/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ class DataSource {
* See: https://developer.wordpress.org/reference/functions/register_setting/
*
* @var array $allowed_setting_types
* @access public
* @access protected
*/
public static $allowed_setting_types;
protected static $allowed_setting_types;

/**
* Stores an array of allowed setting groups.
*
* @var array $allowed_setting_groups
* @access protected
*/
protected static $allowed_setting_groups;

/**
Expand Down
12 changes: 11 additions & 1 deletion src/Type/Setting/SettingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,33 @@ class SettingType extends WPObjectType {
/**
* Holds the $fields definition for the SettingType
*
* @var $fields
* @var array $fields
* @access private
*/
private static $fields;

/**
* Holds the $setting_type definition
*
* @var string $setting_type
* @access private
*/
private static $setting_type;

/**
* Holds the $setting_type_array definition which contains
* all of the settings for the given setting_type
*
* @var array $setting_fields
* @access private
*/
private static $setting_fields;

/**
* SettingType constructor.
*
* @param string $setting_type The setting group name
* @access public
*/
public function __construct( $setting_type ) {

Expand Down Expand Up @@ -114,6 +122,7 @@ private static function fields( $setting_fields, $group ) {
'type' => Types::get_type( $setting_field['type'] ),
'description' => $setting_field['description'],
'resolve' => function( $root, $args, AppContext $context, ResolveInfo $info ) use ( $setting_field, $field_key, $key ) {

/**
* Check to see if the user querying the email field has the 'manage_options' capability
* All other options should be public by default
Expand All @@ -125,6 +134,7 @@ private static function fields( $setting_fields, $group ) {
}

$option = ! empty( $setting_field['key'] ) ? get_option( $setting_field['key'] ) : null;

switch ( $setting_field['type'] ) {
case 'integer':
$option = absint( $option );
Expand Down
3 changes: 1 addition & 2 deletions tests/test-setting-queries.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* WPGraphQL Test generalSetting Queries
*
Expand Down Expand Up @@ -237,7 +236,7 @@ public function testDiscussionSettingQuery() {
* Validate the request
*/
wp_set_current_user( $this->admin );

update_option( 'default_comment_status', 'test_value' );
update_option( 'default_ping_status', 'test_value' );

Expand Down

0 comments on commit 1195c90

Please sign in to comment.