|
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\Attributes\DataProvider; |
6 | 6 | use PHPUnit\Framework\Attributes\Test; |
| 7 | +use Statamic\Facades\Addon; |
| 8 | +use Statamic\Facades\Blink; |
7 | 9 | use Statamic\Facades\URL; |
8 | 10 | use Statamic\SeoPro\SiteDefaults\SiteDefaults; |
9 | 11 |
|
@@ -141,6 +143,46 @@ public function it_uses_localized_site_defaults_in_sitemap_xml($setupTrailingSla |
141 | 143 | $this->assertCount(15, $this->getPagesFromSitemapXml($content)); |
142 | 144 | } |
143 | 145 |
|
| 146 | + #[Test] |
| 147 | + /** |
| 148 | + * https://github.com/statamic/seo-pro/pull/572 |
| 149 | + */ |
| 150 | + public function it_outputs_sitemap_with_loc_when_child_site_inherits_from_parent() |
| 151 | + { |
| 152 | + Addon::get('statamic/seo-pro')->settings()->set('site_defaults_sites', [ |
| 153 | + 'default' => null, |
| 154 | + 'french' => null, |
| 155 | + 'italian' => null, |
| 156 | + 'british' => 'default', |
| 157 | + ])->save(); |
| 158 | + |
| 159 | + SiteDefaults::in('default') |
| 160 | + ->set('canonical_url', '@seo:permalink') |
| 161 | + ->set('change_frequency', 'monthly') |
| 162 | + ->set('priority', 0.5) |
| 163 | + ->save(); |
| 164 | + |
| 165 | + Blink::forget('seo-pro::site-defaults'); |
| 166 | + |
| 167 | + $content = $this |
| 168 | + ->get('http://cool-runnings.com/sitemap.xml') |
| 169 | + ->assertOk() |
| 170 | + ->getContent(); |
| 171 | + |
| 172 | + $pages = $this->getPagesFromSitemapXml($content); |
| 173 | + |
| 174 | + foreach ($pages as $page) { |
| 175 | + $this->assertNotEmpty($page['loc'], 'All pages should have a non-empty <loc> element'); |
| 176 | + $this->assertStringStartsWith('http://cool-runnings.com', $page['loc']); |
| 177 | + } |
| 178 | + |
| 179 | + $britishLocs = collect($pages)->pluck('loc')->filter(fn ($loc) => str_contains($loc, '/en-gb')); |
| 180 | + $this->assertNotEmpty($britishLocs, 'British site entries should be in the sitemap'); |
| 181 | + foreach ($britishLocs as $loc) { |
| 182 | + $this->assertStringStartsWith('http://cool-runnings.com/en-gb', $loc); |
| 183 | + } |
| 184 | + } |
| 185 | + |
144 | 186 | protected function getPagesFromSitemapXml($content) |
145 | 187 | { |
146 | 188 | $data = json_decode(json_encode(simplexml_load_string($content)), true); |
|
0 commit comments