Download the PHP package raiolanetworks/plugin-seo-test without Composer
On this page you can find all versions of the php package raiolanetworks/plugin-seo-test. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raiolanetworks/plugin-seo-test
More information about raiolanetworks/plugin-seo-test
Files in raiolanetworks/plugin-seo-test
Package plugin-seo-test
Short Description This Composer package provides a seamless integration for testing SEO aspects of your Laravel applications. Compatible with both Pest and PHPUnit, it offers a collection of tools and assertions specifically designed to evaluate on-page SEO elements like meta tags, title tags, canonical URLs, and structured data. By automating SEO testing, this plugin ensures that your application consistently adheres to best SEO practices, helping you catch potential SEO issues early in the development cycle.
License MIT
Homepage https://github.com/RaiolaNetworks/plugin-seo-test
Informations about the package plugin-seo-test
Plugin SEO Test
SEO testing assertions for Laravel applications. Compatible with PHPUnit and Pest.
Test meta tags, titles, canonical URLs, Open Graph, Twitter Cards, robots directives, and more with a fluent API.
Requirements
- PHP 8.2+ (8.3+ required when used with Laravel 13)
- Laravel 11, 12, or 13
- PHPUnit 10, 11, or 12
Table of Contents
- Installation
- Usage
- PHPUnit
- Laravel
- Pest
- API
- SEO Data
- Assertions
- Snapshot testing
Installation
You can install the package via composer:
Usage
Look at the following examples using PHPUnit, Laravel, and Pest.
PHPUnit
Laravel
Pest
SEO Data
You can access the SEO Data yourself by accessing the public property TestSEO->data.
Here are the available methods:
| Method | Returns | Description |
|---|---|---|
title() |
?string |
<title>{this}</title> |
description() |
?string |
<meta name="description" content="{this}"> |
image() |
?Url 🔍 |
<meta name="image" content="{this}"> |
robots() |
Robots 🔍 |
<meta name="robots" content="{this}"> |
canonical() |
?Url 🔍 |
<link rel="canonical" href="{this}"> |
prev() |
?Url 🔍 |
<link rel="prev" href="{this}"> |
next() |
?Url 🔍 |
<link rel="next" href="{this}"> |
openGraph() |
TagCollection 🔍 |
<meta property="og:{key}" content="{value}"> |
twitter() |
TagCollection 🔍 |
<meta name="twitter:{key}" content="{value}"> |
alternateHrefLang() |
AlternateHrefLangCollection 🔍 |
<link name="alternate" hreflang="{hreflang}" href={href}> |
images() |
array<array{src: string, alt: string, title: string}> |
All images in the page. <img src="..."> |
h1s() |
array<string> |
All H1 in the page. <h1>{this}</h1> |
h2s() |
array<string> |
All H2 in the page. <h2>{this}</h2> |
charset() |
?string |
<meta charset="utf-8"> |
The SEOData class is Macroable, so feel free to extend it yourself.
Assertions
| Method | Notes |
|---|---|
assertCanonicalIs(string $expected) |
|
assertCanonicalIsEmpty() |
|
assertRobotsIsEmpty() |
|
assertRobotsIsNoIndexNoFollow() |
Checks that the robots are noindex, nofollow or none |
assertPaginationIsEmpty() |
prev and next are both missing. |
assertAlternateHrefLangIsEmpty() |
|
assertTitleIs(string $expected) |
|
assertTitleContains(string $expected) |
|
assertTitleEndsWith(string $expected) |
|
assertDescriptionIs(string $expected) |
|
assertThereIsOnlyOneH1() |
Make sure there is only one H1 in the entire website. |
assertAllImagesHaveAltText() |
Make sure all images have an alt="..." |
| Suggest your own! | These assertions can help devs to follow the best SEO practices. Make a PR if you think some are missing! |
Snapshots
When it comes to SEO, a snapshot test is a great way to ensure nothing has been changed by accident.
Here is an example:
By default, the SEO tags are serialized using the SimpleSerializer.
You can provide your own serializer by implementing the SnapshotSerializer interface:
Pest Example
Note: this example requires spatie/pest-plugin-snapshots.
Changelog
See Releases for a list of changes.
Contributing
Please see CONTRIBUTING for details.
Credits
- Martin Gomez
- David Eguiluz
- Based on juampi92/test-seo
License
The MIT License (MIT). Please see License File for more information.
All versions of plugin-seo-test with dependencies
illuminate/macroable Version ^11.0|^12.0|^13.0
phpunit/phpunit Version ^10.0|^11.0|^12.0
spatie/url Version ^2.0
symfony/dom-crawler Version ^6.1|^7.0