Skip to content

Commit c47e8b0

Browse files
SOD96ralphjsmit
andauthored
fix: instantiating TwitterCardTags with image and no fallback image specified (#100)
* fix: Secure URL returning a URLGenerator when we expect a string * WIP * Update TwitterCardTagsTest.php --------- Co-authored-by: Ralph J. Smit <[email protected]>
1 parent c9d545e commit c47e8b0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Tags/TwitterCardTags.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ public static function initialize(SEOData $SEOData): ?static
1919
$collection = new static;
2020

2121
// No generic image that spans multiple pages
22-
if ($SEOData->image && $SEOData->image !== secure_url(config('seo.image.fallback')) && $SEOData->imageMeta?->height > 0) {
22+
$imageFallback = config('seo.image.fallback');
23+
24+
if (
25+
$SEOData->image
26+
&& (
27+
// If no fallback specified, then the image is not the fallback.
28+
! $imageFallback
29+
// If fallback image specified, then verify if the image is not the fallback.
30+
|| $SEOData->image !== secure_url($imageFallback)
31+
)
32+
&& $SEOData->imageMeta?->height !== null
33+
&& $SEOData->imageMeta->height > 0
34+
) {
2335
// Only one Twitter card can be pushed. The `summary_large_image` card
2436
// is tried first, then it falls back to the normal `summary` card.
2537
$imageMetaWidthDividedByHeight = $SEOData->imageMeta->width / $SEOData->imageMeta->height;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use RalphJSmit\Laravel\SEO\Support\SEOData;
4+
use RalphJSmit\Laravel\SEO\Tags\TwitterCardTags;
5+
6+
it('can instantiate the `TwitterCardTags` class when no fallback image has been specified in config', function () {
7+
config()->set('seo.image.fallback', null);
8+
9+
$SEOData = new SEOData(
10+
title: 'Unique Title',
11+
image: '/default/image.jpg',
12+
);
13+
14+
$twitterCardTags = TwitterCardTags::initialize($SEOData);
15+
16+
expect($twitterCardTags)
17+
->toBeInstanceOf(TwitterCardTags::class);
18+
});

0 commit comments

Comments
 (0)