Skip to content

Commit

Permalink
GitHub workflow integration (#285)
Browse files Browse the repository at this point in the history
* Fix #283 - Change usage to jsonLdMulti

* Fix unit tests for JsonLdMulti

* Automated github tests

* Updated composer.json for Laravel 9
  • Loading branch information
J-Brk authored Aug 29, 2022
1 parent 1342849 commit a082a17
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 48 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: tests

on:
push:
pull_request:

jobs:
tests:
runs-on: ubuntu-20.04

strategy:
fail-fast: true
matrix:
php: [7.4, 8.0, 8.1]
laravel: [8.*, 9.*]
dependency-version: [prefer-stable]
exclude:
- php: 7.4
laravel: 9.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --dev --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit --verbose
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"name": "artesaos/seotools",
"description": "SEO Tools for Laravel and Lumen",
"keywords": ["laravel", "lumen" ,"seo", "seotools", "webmaster", "metatags", "opengraph", "json-ld"],
"keywords": [
"laravel",
"lumen",
"seo",
"seotools",
"webmaster",
"metatags",
"opengraph",
"json-ld"
],
"license": "MIT",
"support": {
"issues": "https://github.com/artesaos/seotools/issues",
Expand All @@ -20,8 +29,8 @@
"illuminate/support": "5.8.* || ^6.0 || ^7.0 || ^8.0 || ^9.0"
},
"require-dev": {
"orchestra/testbench": "~3.8.4 || ^4.0 || ^5.0",
"phpspec/phpspec": "~5.1.1 || ^6.0"
"orchestra/testbench": "~3.8.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"phpspec/phpspec": "~5.1.1 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 6 additions & 5 deletions src/SEOTools/SEOTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setTitle($title, $appendDefault = true)
$this->metatags()->setTitle($title, $appendDefault);
$this->opengraph()->setTitle($title);
$this->twitter()->setTitle($title);
$this->jsonLd()->setTitle($title);
$this->jsonLdMulti()->setTitle($title);

return $this;
}
Expand All @@ -72,7 +72,7 @@ public function setDescription($description)
$this->metatags()->setDescription($description);
$this->opengraph()->setDescription($description);
$this->twitter()->setDescription($description);
$this->jsonLd()->setDescription($description);
$this->jsonLdMulti()->setDescription($description);

return $this;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public function addImages($urls)

$this->twitter()->setImage($urls);

$this->jsonLd()->addImage($urls);
$this->jsonLdMulti()->addImage($urls);

return $this;
}
Expand Down Expand Up @@ -128,8 +128,9 @@ public function generate($minify = false)
$html .= PHP_EOL;
$html .= $this->twitter()->generate();
$html .= PHP_EOL;
// if json ld multi is use don't show simple json ld
$html .= $this->jsonLdMulti()->generate() ?? $this->jsonLd()->generate();

// Use jsonLdMulti by default; since it is just a wrapper
$html .= $this->jsonLdMulti()->generate();

This comment has been minimized.

Copy link
@Rattone

Rattone Mar 5, 2024

This change breaks the use of simple jsonLd with SEO::generate.
Yes, it's a wrapper but it doesn't take the set values, only load the defaults @J-Brk

This comment has been minimized.

Copy link
@EpocDotFr

EpocDotFr Sep 20, 2024

Exactly what I was about to write on #321.


return ($minify) ? str_replace(PHP_EOL, '', $html) : $html;
}
Expand Down
58 changes: 18 additions & 40 deletions tests/SEOTools/JsonLdMultiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
*/
class JsonLdMultiTest extends BaseTest
{
/**
* @var string
*/
protected $defaultJsonLdHtml = '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script>';

/**
* @var JsonLdMulti
*/
Expand All @@ -27,24 +22,20 @@ protected function setUp(): void
parent::setUp();

$this->jsonLdMulti = $this->app->make('seotools.json-ld-multi');
$this->jsonLdMulti->newJsonLd();
}

public function test_single_instance()
public function test_defaults()
{
$jsonLdSingle = new JsonLdMulti();

$expected = '<html><head>' . $this->defaultJsonLdHtml . '</head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script></head></html>';

$this->assertEquals($this->makeDomDocument($expected)->C14N(), $this->makeDomDocument($jsonLdSingle->generate())->C14N());
$this->assertEquals($this->makeDomDocument($expected)->C14N(), $this->makeDomDocument($this->jsonLdMulti->generate())->C14N());
}

public function test_set_title()
{
$this->jsonLdMulti->setTitle('Kamehamehaaaaaaaa');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Kamehamehaaaaaaaa","description":"For those who helped create the Genki Dama"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Kamehamehaaaaaaaa","description":"For those who helped create the Genki Dama"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -53,8 +44,7 @@ public function test_set_site()
{
$this->jsonLdMulti->setSite('http://kakaroto.9000');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","url":"http://kakaroto.9000"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","url":"http://kakaroto.9000"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -63,8 +53,7 @@ public function test_set_url()
{
$this->jsonLdMulti->setUrl('http://kakaroto.9000');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","url":"http://kakaroto.9000"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","url":"http://kakaroto.9000"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -76,8 +65,7 @@ public function test_use_current_url()
{
$this->jsonLdMulti->setUrl(null);

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","url":"http://localhost"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","url":"http://localhost"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -86,8 +74,7 @@ public function test_set_description()
{
$this->jsonLdMulti->setDescription('Kamehamehaaaaaaaa');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"Kamehamehaaaaaaaa"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"Kamehamehaaaaaaaa"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -98,8 +85,7 @@ public function test_cleans_description()

$this->jsonLdMulti->setDescription($description);

$expected = htmlspecialchars_decode('<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"\"Foo bar\" -&gt; abc"}</script></head></html>');
$expected = htmlspecialchars_decode('<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"\"Foo bar\" -&gt; abc"}</script></head></html>');

$this->setRightAssertion($expected);
}
Expand All @@ -108,8 +94,7 @@ public function test_set_type()
{
$this->jsonLdMulti->setType('sayajin');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"sayajin","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"sayajin","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -118,8 +103,7 @@ public function test_set_images()
{
$this->jsonLdMulti->setImages(['sayajin.png', 'namekusei.png']);

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","image":["sayajin.png","namekusei.png"]}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","image":["sayajin.png","namekusei.png"]}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -128,8 +112,7 @@ public function test_set_image()
{
$this->jsonLdMulti->setImage('sayajin.png');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","image":"sayajin.png"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","image":"sayajin.png"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -139,8 +122,7 @@ public function test_add_value()
$this->jsonLdMulti->addValue('test', '1-2-3');
$this->jsonLdMulti->addValue('another', 'test-value');

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","test":"1-2-3","another":"test-value"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","test":"1-2-3","another":"test-value"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -153,8 +135,7 @@ public function test_array_add_value()
'url' => 'https://github.com/artesaos/seotools',
]);

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","author":{"@type":"Organization","name":"SeoTools","url":"https://github.com/artesaos/seotools"}}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","author":{"@type":"Organization","name":"SeoTools","url":"https://github.com/artesaos/seotools"}}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -169,18 +150,17 @@ public function test_add_values()
],
]);

$expected = '<html><head>' . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","test":"1-2-3","author":{"@type":"Organization","name":"SeoTools"}}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","test":"1-2-3","author":{"@type":"Organization","name":"SeoTools"}}</script></head></html>';

$this->setRightAssertion($expected);
}

public function test_new_json_ld()
{
$this->jsonLdMulti->newJsonLd();
$this->jsonLdMulti->setType('Product');

$expected = '<html><head>' . $this->defaultJsonLdHtml . $this->defaultJsonLdHtml
. '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script></head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script><script type="application/ld+json">{"@context":"https://schema.org","@type":"Product","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand All @@ -204,9 +184,7 @@ public function test_select()
$this->jsonLdMulti->select(0);
$this->jsonLdMulti->setTitle('Kamehamehaaaaaaaa');

$expected =
'<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Kamehamehaaaaaaaa","description":"For those who helped create the Genki Dama"}</script>'
. $this->defaultJsonLdHtml . '</head></html>';
$expected = '<html><head><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Kamehamehaaaaaaaa","description":"For those who helped create the Genki Dama"}</script></head></html>';

$this->setRightAssertion($expected);
}
Expand Down

0 comments on commit a082a17

Please sign in to comment.