Skip to content

Commit 644a452

Browse files
authored
Merge pull request #72 from kidunot89/feature/add-fee-mutation-cap-check
`edit_shop_order` cap check in addFee
2 parents f218dd6 + 75d0d4a commit 644a452

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

src/mutation/class-cart-add-fee.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public static function get_output_fields() {
8585
*/
8686
public static function mutate_and_get_payload() {
8787
return function( $input, AppContext $context, ResolveInfo $info ) {
88-
// Retrieve product database ID if relay ID provided.
88+
if ( ! current_user_can( 'edit_shop_orders' ) ) {
89+
throw new UserError( __( 'You do not have the appropriate capabilities to perform this action', 'wp-graphql' ) );
90+
}
91+
8992
if ( empty( $input['name'] ) ) {
9093
throw new UserError( __( 'No name provided for fee', 'wp-graphql-woocommerce' ) );
9194
}

tests/wpunit/CartMutationsTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
4+
private $shop_manager;
45
private $customer;
56
private $coupon;
67
private $product;
@@ -10,11 +11,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
1011
public function setUp() {
1112
parent::setUp();
1213

13-
$this->customer = $this->getModule('\Helper\Wpunit')->customer();
14-
$this->coupon = $this->getModule('\Helper\Wpunit')->coupon();
15-
$this->product = $this->getModule('\Helper\Wpunit')->product();
16-
$this->variation = $this->getModule('\Helper\Wpunit')->product_variation();
17-
$this->cart = $this->getModule('\Helper\Wpunit')->cart();
14+
$this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
15+
$this->customer = $this->getModule('\Helper\Wpunit')->customer();
16+
$this->coupon = $this->getModule('\Helper\Wpunit')->coupon();
17+
$this->product = $this->getModule('\Helper\Wpunit')->product();
18+
$this->variation = $this->getModule('\Helper\Wpunit')->product_variation();
19+
$this->cart = $this->getModule('\Helper\Wpunit')->cart();
1820
}
1921

2022
public function tearDown() {
@@ -899,6 +901,20 @@ public function testAddFeeMutation() {
899901
// use --debug flag to view.
900902
codecept_debug( $actual );
901903

904+
$this->assertArrayHasKey('errors', $actual );
905+
906+
wp_set_current_user( $this->shop_manager );
907+
$actual = graphql(
908+
array(
909+
'query' => $mutation,
910+
'operation_name' => 'addFee',
911+
'variables' => $variables,
912+
)
913+
);
914+
915+
// use --debug flag to view.
916+
codecept_debug( $actual );
917+
902918
$expected = array(
903919
'data' => array(
904920
'addFee' => array(

vendor/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
require_once __DIR__ . '/composer/autoload_real.php';
66

7-
return ComposerAutoloaderInit7d7a45761e5e9f310de9b228d2235d8e::getLoader();
7+
return ComposerAutoloaderInit04455a9e28ec460217bb4717433625c0::getLoader();

vendor/composer/autoload_real.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// autoload_real.php @generated by Composer
44

5-
class ComposerAutoloaderInit7d7a45761e5e9f310de9b228d2235d8e
5+
class ComposerAutoloaderInit04455a9e28ec460217bb4717433625c0
66
{
77
private static $loader;
88

@@ -19,15 +19,15 @@ public static function getLoader()
1919
return self::$loader;
2020
}
2121

22-
spl_autoload_register(array('ComposerAutoloaderInit7d7a45761e5e9f310de9b228d2235d8e', 'loadClassLoader'), true, true);
22+
spl_autoload_register(array('ComposerAutoloaderInit04455a9e28ec460217bb4717433625c0', 'loadClassLoader'), true, true);
2323
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24-
spl_autoload_unregister(array('ComposerAutoloaderInit7d7a45761e5e9f310de9b228d2235d8e', 'loadClassLoader'));
24+
spl_autoload_unregister(array('ComposerAutoloaderInit04455a9e28ec460217bb4717433625c0', 'loadClassLoader'));
2525

2626
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
2727
if ($useStaticLoader) {
2828
require_once __DIR__ . '/autoload_static.php';
2929

30-
call_user_func(\Composer\Autoload\ComposerStaticInit7d7a45761e5e9f310de9b228d2235d8e::getInitializer($loader));
30+
call_user_func(\Composer\Autoload\ComposerStaticInit04455a9e28ec460217bb4717433625c0::getInitializer($loader));
3131
} else {
3232
$map = require __DIR__ . '/autoload_namespaces.php';
3333
foreach ($map as $namespace => $path) {

vendor/composer/autoload_static.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Composer\Autoload;
66

7-
class ComposerStaticInit7d7a45761e5e9f310de9b228d2235d8e
7+
class ComposerStaticInit04455a9e28ec460217bb4717433625c0
88
{
99
public static $prefixLengthsPsr4 = array (
1010
'W' =>
@@ -115,9 +115,9 @@ class ComposerStaticInit7d7a45761e5e9f310de9b228d2235d8e
115115
public static function getInitializer(ClassLoader $loader)
116116
{
117117
return \Closure::bind(function () use ($loader) {
118-
$loader->prefixLengthsPsr4 = ComposerStaticInit7d7a45761e5e9f310de9b228d2235d8e::$prefixLengthsPsr4;
119-
$loader->prefixDirsPsr4 = ComposerStaticInit7d7a45761e5e9f310de9b228d2235d8e::$prefixDirsPsr4;
120-
$loader->classMap = ComposerStaticInit7d7a45761e5e9f310de9b228d2235d8e::$classMap;
118+
$loader->prefixLengthsPsr4 = ComposerStaticInit04455a9e28ec460217bb4717433625c0::$prefixLengthsPsr4;
119+
$loader->prefixDirsPsr4 = ComposerStaticInit04455a9e28ec460217bb4717433625c0::$prefixDirsPsr4;
120+
$loader->classMap = ComposerStaticInit04455a9e28ec460217bb4717433625c0::$classMap;
121121

122122
}, null, ClassLoader::class);
123123
}

0 commit comments

Comments
 (0)