-
-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathSingletonCanonicalTest.php
More file actions
45 lines (37 loc) · 1.58 KB
/
Copy pathSingletonCanonicalTest.php
File metadata and controls
45 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Bolt\Tests\Controller\Frontend;
use Bolt\Entity\Content;
use Bolt\Tests\DbAwareTestCase;
/**
* End-to-end: a singleton is reachable both at its slugless URL (`/about`) and at
* the record-detail route (`/about/{slug}`). Both must declare the slugless URL
* as their canonical, so the two URLs consolidate to one.
*/
class SingletonCanonicalTest extends DbAwareTestCase
{
public function testSingletonRecordUrlCanonicalizesToSluglessUrl(): void
{
/** @var Content|null $record */
$record = $this->getEm()->getRepository(Content::class)
->findOneBy(['contentType' => 'about']);
$this->assertNotNull($record, 'Expected the "about" singleton fixture to be seeded.');
$singularSlug = $record->getContentTypeSingularSlug();
$slug = $record->getSlug();
$expectedCanonical = 'http://localhost/' . $singularSlug;
// The slugged record URL must canonicalize to the slugless singleton URL.
$crawler = $this->client->request('GET', sprintf('/%s/%s', $singularSlug, $slug));
$this->assertResponseIsSuccessful();
$this->assertSame(
$expectedCanonical,
$crawler->filter('link[rel="canonical"]')->attr('href')
);
// The slugless URL itself is self-referential (same canonical).
$crawler = $this->client->request('GET', '/' . $singularSlug);
$this->assertResponseIsSuccessful();
$this->assertSame(
$expectedCanonical,
$crawler->filter('link[rel="canonical"]')->attr('href')
);
}
}