• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 23675172456

28 Mar 2026 02:10AM UTC coverage: 70.983% (-18.4%) from 89.424%
23675172456

Pull #1003

github

web-flow
Merge 05339093d into 6fb7b226f
Pull Request #1003: devops: WC email template tests, COT cursor HPOS fix, checkout account auth

71 of 81 new or added lines in 5 files covered. (87.65%)

3346 existing lines in 124 files now uncovered.

12576 of 17717 relevant lines covered (70.98%)

55.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.36
/includes/mutation/class-session-update.php
1
<?php
2
/**
3
 * Mutation - updateSession
4
 *
5
 * Registers mutation for updating session meta data.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 0.12.5
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use GraphQL\Error\UserError;
14
use WPGraphQL\WooCommerce\Data\Mutation\Cart_Mutation;
15
use WPGraphQL\WooCommerce\Model\Customer;
16

17
/**
18
 * Class - Session_Update
19
 */
20
class Session_Update {
21
        /**
22
         * Registers mutation
23
         *
24
         * @return void
25
         */
26
        public static function register_mutation() {
27
                register_graphql_mutation(
110✔
28
                        'updateSession',
110✔
29
                        [
110✔
30
                                'inputFields'         => self::get_input_fields(),
110✔
31
                                'outputFields'        => self::get_output_fields(),
110✔
32
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
110✔
33
                        ]
110✔
34
                );
110✔
35
        }
36

37
        /**
38
         * Defines the mutation input field configuration
39
         *
40
         * @return array
41
         */
42
        public static function get_input_fields() {
43
                return [
110✔
44
                        'sessionData' => [
110✔
45
                                'type'        => [ 'list_of' => 'MetaDataInput' ],
110✔
46
                                'description' => __( 'Data to be persisted in the session.', 'wp-graphql-woocommerce' ),
110✔
47
                        ],
110✔
48
                ];
110✔
49
        }
50

51
        /**
52
         * Defines the mutation output field configuration
53
         *
54
         * @return array
55
         */
56
        public static function get_output_fields() {
57
                return [
110✔
58
                        'session'  => [
110✔
59
                                'type'    => [ 'list_of' => 'MetaData' ],
110✔
60
                                'resolve' => static function () {
110✔
61
                                        /**
62
                                         * Session handler.
63
                                         *
64
                                         * @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session
65
                                         */
UNCOV
66
                                        $session      = \WC()->session;
×
UNCOV
67
                                        $session_data = $session->get_session_data();
×
UNCOV
68
                                        $session      = [];
×
UNCOV
69
                                        foreach ( $session_data as $key => $value ) {
×
UNCOV
70
                                                $meta        = new \stdClass();
×
UNCOV
71
                                                $meta->id    = null;
×
UNCOV
72
                                                $meta->key   = $key;
×
UNCOV
73
                                                $meta->value = maybe_unserialize( $value );
×
UNCOV
74
                                                $session[]   = $meta;
×
75
                                        }
76

UNCOV
77
                                        return $session;
×
78
                                },
110✔
79
                        ],
110✔
80
                        'customer' => [
110✔
81
                                'type'    => 'Customer',
110✔
82
                                'resolve' => static function () {
110✔
UNCOV
83
                                        return new Customer( 'session' );
×
84
                                },
110✔
85
                        ],
110✔
86
                ];
110✔
87
        }
88

89
        /**
90
         * Defines the mutation data modification closure.
91
         *
92
         * @return callable
93
         */
94
        public static function mutate_and_get_payload() {
95
                return static function ( $input ) {
110✔
96
                        Cart_Mutation::check_session_token();
1✔
97

98
                        // Guard against missing input.
99
                        if ( empty( $input['sessionData'] ) ) {
1✔
100
                                throw new UserError( __( 'No session data provided', 'wp-graphql-woocommerce' ) );
×
101
                        }
102
                        $session_data_input = $input['sessionData'];
1✔
103

104
                        /**
105
                         * Session handler.
106
                         *
107
                         * @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session
108
                         */
109
                        $session = \WC()->session;
1✔
110

111
                        // Save session data input.
112
                        foreach ( $session_data_input as $meta ) {
1✔
113
                                $session->set( $meta['key'], $meta['value'] );
1✔
114
                        }
115

116
                        if ( is_a( $session, '\WC_Session_Handler' ) ) {
1✔
117
                                $session->save_data();
1✔
118
                        }
119

120
                        do_action( 'woographql_update_session', true );
1✔
121

122
                        // Process errors or return successful.
123
                        $notices = $session->get( 'wc_notices' );
1✔
124
                        if ( ! empty( $notices['error'] ) ) {
1✔
125
                                $error_messages = implode( ' ', array_column( $notices['error'], 'notice' ) );
1✔
126
                                \wc_clear_notices();
1✔
127
                                throw new UserError( $error_messages );
1✔
128
                        } else {
UNCOV
129
                                return [ 'status' => 'SUCCESS' ];
×
130
                        }
131
                };
110✔
132
        }
133
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc