• 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

0.0
/includes/utils/class-transfer-session-handler.php
1
<?php
2
/**
3
 * Handles data for the current customers session.
4
 *
5
 * @package WPGraphQL\WooCommerce\Utils
6
 * @since 0.12.5
7
 */
8

9
namespace WPGraphQL\WooCommerce\Utils;
10

11
/**
12
 * Class Transfer_Session_Handler
13
 *
14
 * @property string|int $_customer_id
15
 *
16
 * @package WPGraphQL\WooCommerce\Utils
17
 */
18
class Transfer_Session_Handler extends \WC_Session_Handler {
19
        /**
20
         * Setup cookie and customer ID.
21
         *
22
         * @return void
23
         */
24
        public function init_session_cookie() {
25
                // Retrieve a customer's previous session from DB.
UNCOV
26
                $this->set_session_expiration();
×
UNCOV
27
                $this->_customer_id = $this->generate_customer_id();
×
UNCOV
28
                $this->_data        = $this->get_session_data();
×
29
        }
30

31
        /**
32
         * Return true, if valid credential exists
33
         *
34
         * @return bool
35
         */
36
        protected function verify_auth_request_credentials_exists() {
UNCOV
37
                $possible_nonces = array_values( Protected_Router::get_nonce_names() );
×
38
                // Return false if not nonce names set.
UNCOV
39
                if ( empty( $possible_nonces ) ) {
×
40
                        return false;
×
41
                }
42

43
                // Return false if no matching nonces found in query parameters.
UNCOV
44
                $query_params = array_keys( $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
×
UNCOV
45
                if ( empty( array_intersect( $possible_nonces, $query_params ) ) ) {
×
UNCOV
46
                        return false;
×
47
                }
48

UNCOV
49
                return true;
×
50
        }
51

52
        /**
53
         * Returns "session_id" if proper conditions met.
54
         *
55
         * @return int|string
56
         */
57
        protected function get_posted_session_id() {
UNCOV
58
                if ( ! $this->verify_auth_request_credentials_exists() ) {
×
UNCOV
59
                        return 0;
×
60
                }
UNCOV
61
                if ( ! isset( $_REQUEST['session_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
×
UNCOV
62
                        return 0;
×
63
                }
64

UNCOV
65
                return sanitize_text_field( wp_unslash( $_REQUEST['session_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
×
66
        }
67

68
        /**
69
         * Reads in customer ID from query parameters if specific conditions are met otherwise
70
         * a guest ID are generated as usual.
71
         *
72
         * @return int|string
73
         */
74
        public function generate_customer_id() {
UNCOV
75
                $session_id = $this->get_posted_session_id();
×
UNCOV
76
                if ( 0 !== $session_id ) {
×
UNCOV
77
                        return $session_id;
×
78
                }
79

UNCOV
80
                return parent::generate_customer_id();
×
81
        }
82

83
        /**
84
         * Returns client session ID.
85
         *
86
         * @return string
87
         */
88
        public function get_client_session_id() {
UNCOV
89
                $session_id = $this->get_posted_session_id();
×
90
                /**
91
                 * Get session data.
92
                 *
93
                 * @var null|array{ client_session_id: string, client_session_id_expiration: int } $session_data
94
                 */
UNCOV
95
                $session_data = 0 !== $session_id ? $this->get_session( (string) $session_id ) : null;
×
96

UNCOV
97
                if ( ! empty( $session_data ) ) {
×
UNCOV
98
                        $client_session_id            = ! empty( $session_data['client_session_id'] ) ? $session_data['client_session_id'] : false;
×
UNCOV
99
                        $client_session_id_expiration = ! empty( $session_data['client_session_id_expiration'] ) ? $session_data['client_session_id_expiration'] : 0;
×
100
                } else {
UNCOV
101
                        $client_session_id            = $this->get( 'client_session_id', false );
×
UNCOV
102
                        $client_session_id_expiration = absint( $this->get( 'client_session_id_expiration', 0 ) );
×
103
                }
104

UNCOV
105
                if ( false !== $client_session_id && time() < $client_session_id_expiration ) {
×
106
                        // @phpstan-ignore-next-line
UNCOV
107
                        return $client_session_id;
×
108
                }
109

UNCOV
110
                return '';
×
111
        }
112
}
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