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

wp-graphql / wp-graphql-woocommerce / 11714183904

07 Nov 2024 12:23AM UTC coverage: 83.665% (-0.8%) from 84.451%
11714183904

push

github

web-flow
devops: Name officially changed to "WPGraphQL for WooCommerce" (#900)

* devops: Name officially changed to "WPGraphQL for WooCommerce"

* devops: GA workflow environment updated

* devops: GA workflow environment updated

* devops: composer-git-hooks downgraded to "2.8.5"

* devops: Unstable session manager tests skipped

* chore: cleanup applied

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

2 of 8 new or added lines in 5 files covered. (25.0%)

268 existing lines in 20 files now uncovered.

12431 of 14858 relevant lines covered (83.67%)

71.79 hits per line

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

50.0
/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 0.21.0
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(
141✔
26
                        'forgetSession',
141✔
27
                        [
141✔
28
                                'inputFields'         => [],
141✔
29
                                'outputFields'        => self::get_output_fields(),
141✔
30
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
141✔
31
                        ]
141✔
32
                );
141✔
33
        }
34

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

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

UNCOV
60
                                        return $session;
×
61
                                },
141✔
62
                        ],
141✔
63
                ];
141✔
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 ) {
141✔
UNCOV
73
                        Cart_Mutation::check_session_token();
×
74

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

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

86
                        // Clear session data.
UNCOV
87
                        $session->forget_session();
×
88

UNCOV
89
                        do_action( 'woographql_after_forget_session', $session_data, $input, $session );
×
90

91
                        // Return payload.
UNCOV
92
                        return [ 'session' => $session_data ];
×
93
                };
141✔
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