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

wp-graphql / wp-graphql-woocommerce / 10288284022

07 Aug 2024 04:39PM UTC coverage: 84.506% (-0.08%) from 84.583%
10288284022

push

github

web-flow
feat: QL Session Handler refactored to handle non-GraphQL requests (#870)

* feat: QL Session Handler functionality expanded to support cookies on non-GraphQL requests

* chore: Linter and PHPStan compliance met

* devops: QLSessionHandlerTest patched for suite testing

* chore: Linter and PHPStan compliance met

* fix: More cart session save triggered implemented

* fix: More cart session save triggered implemented

* chore: Linter compliance met

* chore: Linter compliance met

* feat: forgetSession mutation added

* feat: forgetSession mutation added

84 of 124 new or added lines in 18 files covered. (67.74%)

1 existing line in 1 file now uncovered.

12484 of 14773 relevant lines covered (84.51%)

72.58 hits per line

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

97.06
/includes/mutation/class-session-delete.php
1
<?php
2
/**
3
 * Mutation - forgetSession
4
 *
5
 * Registers mutation for deleting sessions from the DB.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since TBD
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use WPGraphQL\WooCommerce\Data\Mutation\Cart_Mutation;
14

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

35
        /**
36
         * Defines the mutation output field configuration
37
         *
38
         * @return array
39
         */
40
        public static function get_output_fields() {
41
                return [
142✔
42
                        'session' => [
142✔
43
                                'type'    => [ 'list_of' => 'MetaData' ],
142✔
44
                                'resolve' => static function ( $payload ) {
142✔
45
                                        // Guard against missing session data.
46
                                        if ( empty( $payload['session'] ) ) {
1✔
NEW
47
                                                return [];
×
48
                                        }
49

50
                                        // Prepare session data.
51
                                        $session = [];
1✔
52
                                        foreach ( $payload['session'] as $key => $value ) {
1✔
53
                                                $meta        = new \stdClass();
1✔
54
                                                $meta->id    = null;
1✔
55
                                                $meta->key   = $key;
1✔
56
                                                $meta->value = maybe_unserialize( $value );
1✔
57
                                                $session[]   = $meta;
1✔
58
                                        }
59

60
                                        return $session;
1✔
61
                                },
142✔
62
                        ],
142✔
63
                ];
142✔
64
        }
65

66
        /**
67
         * Defines the mutation data modification closure.
68
         *
69
         * @return callable
70
         */
71
        public static function mutate_and_get_payload() {
72
                return static function ( $input ) {
142✔
73
                        Cart_Mutation::check_session_token();
1✔
74

75
                        /**
76
                         * Session handler.
77
                         *
78
                         * @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session
79
                         */
80
                        $session = \WC()->session;
1✔
81

82
                        // Get session data.
83
                        $session_data = $session->get_session_data();
1✔
84
                        do_action( 'woographql_before_forget_session', $session_data, $input, $session );
1✔
85

86
                        // Clear session data.
87
                        $session->forget_session();
1✔
88

89
                        do_action( 'woographql_after_forget_session', $session_data, $input, $session );
1✔
90

91
                        // Return payload.
92
                        return [ 'session' => $session_data ];
1✔
93
                };
142✔
94
        }
95
}
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

© 2025 Coveralls, Inc