Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphjsmit committed Jun 15, 2024
1 parent 389e9ed commit e1ace45
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Support/AlternateTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public function __construct(
string $href,
) {
parent::__construct('alternate', $href);

$this->attributes['hreflang'] = $hreflang;
}
}
4 changes: 1 addition & 3 deletions src/Support/SchemaTagCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static function initialize(?SEOData $SEOData = null): ?static
$collection = new static();

foreach ($schemas as $schema) {
$collection->push(
new CustomSchema(value($schema, $SEOData))
);
$collection->push(new CustomSchema(value($schema, $SEOData)));
}

foreach ($schemas->markup as $markupClass => $markupBuilders) {
Expand Down
3 changes: 0 additions & 3 deletions src/Support/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;

/**
* A representation of a HTML tag
*/
abstract class Tag implements Renderable
{
const ATTRIBUTES_ORDER = ['rel', 'hreflang', 'title', 'name', 'href', 'property', 'description', 'content'];
Expand Down
42 changes: 40 additions & 2 deletions tests/Feature/JSON-LD/SchemaCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@
it('can correctly render a custom JSON-LD Schemas markup', function () {
$page = Page::create([]);

$faqPageSchema = $this->faqTestSchema;
$faqPageSchema = [
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => [
'@type' => 'Question',
'name' => 'Can this package add FaqPage to the schema?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Yes!',
],
],
[
'@type' => 'Question',
'name' => 'Does it support multiple questions?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Of course.',
],
],
];

$page::$overrides = [
'schema' => SchemaCollection::make()->add($faqPageSchema),
Expand Down Expand Up @@ -246,7 +265,26 @@
it('can correctly render multiple custom JSON-LD Schemas markup', function () {
$page = Page::create([]);

$faqPageSchema = $this->faqTestSchema;
$faqPageSchema = [
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => [
'@type' => 'Question',
'name' => 'Can this package add FaqPage to the schema?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Yes!',
],
],
[
'@type' => 'Question',
'name' => 'Does it support multiple questions?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Of course.',
],
],
];

$now = now();
$yesterday = now()->yesterday();
Expand Down
21 changes: 0 additions & 21 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@

class TestCase extends Orchestra
{
public array $faqTestSchema = [
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => [
'@type' => 'Question',
'name' => 'Can this package add FaqPage to the schema?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Yes!',
],
],
[
'@type' => 'Question',
'name' => 'Does it support multiple questions?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Of course.',
],
],
];

protected function setUp(): void
{
parent::setUp();
Expand Down
42 changes: 40 additions & 2 deletions tests/Unit/Schema/CustomSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,48 @@
use RalphJSmit\Laravel\SEO\Schema\CustomSchema;

it('can construct a custom faq schema', function () {
$schema = new CustomSchema($this->faqTestSchema);
$schema = new CustomSchema([
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => [
'@type' => 'Question',
'name' => 'Can this package add FaqPage to the schema?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Yes!',
],
],
[
'@type' => 'Question',
'name' => 'Does it support multiple questions?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Of course.',
],
],
]);

expect((string) $schema->render())
->toBe(
'<script type="application/ld+json">' . json_encode($this->faqTestSchema) . '</script>'
'<script type="application/ld+json">' . json_encode([
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => [
'@type' => 'Question',
'name' => 'Can this package add FaqPage to the schema?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Yes!',
],
],
[
'@type' => 'Question',
'name' => 'Does it support multiple questions?',
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => 'Of course.',
],
],
]) . '</script>'
);
});

0 comments on commit e1ace45

Please sign in to comment.