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

AxeWP / wp-graphql-rank-math / 8399674257

23 Mar 2024 05:20AM UTC coverage: 92.33% (+0.04%) from 92.294%
8399674257

push

github

web-flow
fix: Correctly resolve `seo.openGraph.image` field when parsed value is a string (#77)

* fix: resolve `seo.openGraph.image` field when parsed value is a string.

* chore: lint

1 of 5 new or added lines in 2 files covered. (20.0%)

2540 of 2751 relevant lines covered (92.33%)

11.25 hits per line

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

82.69
/src/Type/WPObject/OpenGraphMeta.php
1
<?php
2
/**
3
 * The Rank Math OpenGraph meta tags GraphQL Object.
4
 *
5
 * @package WPGraphQL\RankMath\Type\WPObject
6
 */
7

8
namespace WPGraphQL\RankMath\Type\WPObject;
9

10
use WPGraphQL\RankMath\Type\Enum\OpenGraphLocaleEnum;
11
use WPGraphQL\RankMath\Type\WPObject\OpenGraph;
12
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Abstracts\ObjectType;
13

14
/**
15
 * Class - OpenGraphMeta
16
 */
17
class OpenGraphMeta extends ObjectType {
18
        /**
19
         * {@inheritDoc}
20
         */
21
        protected static function type_name(): string {
22
                return 'OpenGraphMeta';
18✔
23
        }
24

25
        /**
26
         * {@inheritDoc}
27
         */
28
        public static function get_description(): string {
29
                return __( 'The OpenGraph meta.', 'wp-graphql-rank-math' );
18✔
30
        }
31

32
        /**
33
         * {@inheritDoc}
34
         */
35
        public static function get_fields(): array {
36
                return [
18✔
37
                        'articleMeta'       => [
18✔
38
                                'type'        => OpenGraph\Article::get_type_name(),
18✔
39
                                'description' => __( 'The OpenGraph Article meta.', 'wp-graphql-rank-math' ),
18✔
40
                                'resolve'     => static fn ( $source ): ?array => ! empty( $source['article'] ) ? $source['article'] : null,
18✔
41
                        ],
18✔
42
                        'alternateLocales'  => [
18✔
43
                                'type'        => [ 'list_of' => OpenGraphLocaleEnum::get_type_name() ],
18✔
44
                                'description' => __( 'A list of other locales this page is available in', 'wp-graphql-rank-math' ),
18✔
45
                                'resolve'     => static function ( $source ): ?array {
18✔
46
                                        $value = ! empty( $source['og']['locale:alternate'] ) ? $source['og']['locale:alternate'] : null;
1✔
47

48
                                        if ( is_string( $value ) ) {
1✔
49
                                                $value = [ $value ];
×
50
                                        }
51

52
                                        return $value;
1✔
53
                                },
18✔
54
                        ],
18✔
55
                        'description'       => [
18✔
56
                                'type'        => 'String',
18✔
57
                                'description' => __( 'A brief description of the content, usually between 2 and 4 sentences. ', 'wp-graphql-rank-math' ),
18✔
58
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['description'] ) ? $source['og']['description'] : null,
18✔
59
                        ],
18✔
60
                        'image'             => [
18✔
61
                                'type'        => OpenGraph\Image::get_type_name(),
18✔
62
                                'description' => __( 'The OpenGraph image meta', 'wp-graphql-rank-math' ),
18✔
63
                                'resolve'     => static function ( $source ): ?array {
18✔
NEW
64
                                        $values = ! empty( $source['og']['image'] ) ? $source['og']['image'] : [];
×
65
                                        
NEW
66
                                        if ( ! empty( $source['og']['image'][0] ) ) {
×
NEW
67
                                                $values['url'] = $source['og']['image'][0];
×
68
                                        }
69

70
                                        return ! empty( $values ) ? $values : null;
×
71
                                },
18✔
72
                        ],
18✔
73
                        'facebookMeta'      => [
18✔
74
                                'type'        => OpenGraph\Facebook::get_type_name(),
18✔
75
                                'description' => __( 'The Facebook OpenGraph meta values.', 'wp-graphql-rank-math' ),
18✔
76
                                'resolve'     => static fn ( $source ): ?array => ! empty( $source['fb'] ) ? $source['fb'] : null,
18✔
77
                                
78
                        ],
18✔
79
                        'locale'            => [
18✔
80
                                'type'        => OpenGraphLocaleEnum::get_type_name(),
18✔
81
                                'description' => __( 'The locale of the resource.', 'wp-graphql-rank-math' ),
18✔
82
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['locale'] ) ? $source['og']['locale'] : null,
18✔
83
                        ],
18✔
84
                        'productMeta'       => [
18✔
85
                                'type'        => OpenGraph\Product::get_type_name(),
18✔
86
                                'description' => __( 'The Facebook OpenGraph meta values.', 'wp-graphql-rank-math' ),
18✔
87
                                'resolve'     => static fn ( $source ) => ! empty( $source['product'] ) ? $source['product'] : null,
18✔
88
                        ],
18✔
89
                        'slackEnhancedData' => [
18✔
90
                                'type'        => [ 'list_of' => OpenGraph\SlackEnhancedData::get_type_name() ],
18✔
91
                                'description' => __( 'The Slack Enhanced Data meta values.', 'wp-graphql-rank-math' ),
18✔
92
                                'resolve'     => static function ( $source ): ?array {
18✔
93
                                        $values  = [];
×
94
                                        $counter = 1;
×
95

96
                                        while ( isset( $source['twitter'][ 'label' . $counter ] ) ) {
×
97
                                                $values[] = [
×
98
                                                        'label' => $source['twitter'][ 'label' . $counter ],
×
99
                                                        'data'  => $source['twitter'][ 'data' . $counter ],
×
100
                                                ];
×
101
                                                ++$counter;
×
102
                                        }
103

104
                                        return $values ?: null;
×
105
                                },
18✔
106
                        ],
18✔
107
                        'siteName'          => [
18✔
108
                                'type'        => 'String',
18✔
109
                                'description' => __( 'The name of the site this resource is associated with.', 'wp-graphql-rank-math' ),
18✔
110
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['site_name'] ) ? $source['og']['site_name'] : null,
18✔
111
                        ],
18✔
112
                        'title'             => [
18✔
113
                                'type'        => 'String',
18✔
114
                                'description' => __( 'The title of your object as it should appear within the graph.', 'wp-graphql-rank-math' ),
18✔
115
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['title'] ) ? $source['og']['title'] : null,
18✔
116
                        ],
18✔
117
                        'twitterMeta'       => [
18✔
118
                                'type'        => OpenGraph\Twitter::get_type_name(),
18✔
119
                                'description' => __( 'The Twitter OpenGraph meta values.', 'wp-graphql-rank-math' ),
18✔
120
                                'resolve'     => static fn ( $source ): ?array => ! empty( $source['twitter'] ) ? $source['twitter'] : null,
18✔
121
                        ],
18✔
122
                        
123
                        'type'              => [
18✔
124
                                'type'        => 'String',
18✔
125
                                'description' => __( 'The OpenGraph object type.', 'wp-graphql-rank-math' ),
18✔
126
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['type'] ) ? $source['og']['type'] : null,
18✔
127
                        ],
18✔
128
                        'updatedTime'       => [
18✔
129
                                'type'        => 'String',
18✔
130
                                'description' => __( 'The updated time', 'wp-graphql-rank-math' ),
18✔
131
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['updated_time'] ) ? $source['og']['updated_time'] : null,
18✔
132
                        ],
18✔
133
                        'url'               => [
18✔
134
                                'type'        => 'String',
18✔
135
                                'description' => __( 'The canonical URL of your object that will be used as its permanent ID in the graph.', 'wp-graphql-rank-math' ),
18✔
136
                                'resolve'     => static fn ( $source ): ?string => ! empty( $source['og']['url'] ) ? $source['og']['url'] : null,
18✔
137
                        ],
18✔
138
                        'videoMeta'         => [
18✔
139
                                'type'        => OpenGraph\Video::get_type_name(),
18✔
140
                                'description' => __( 'The Twitter OpenGraph meta values.', 'wp-graphql-rank-math' ),
18✔
141
                                'resolve'     => static function ( $source ): ?array {
18✔
142
                                        $values = ! empty( $source['video'] ) ? $source['video'] : [];
×
143

144
                                        if ( isset( $source['og']['video'] ) ) {
×
145
                                                $values['url'] = $source['og']['video'];
×
146
                                        }
147

148
                                        return $values ?: null;
×
149
                                },
18✔
150
                        ],
18✔
151
                ];
18✔
152
        }
153
}
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