Repository: artesaos/seotools (language: php)

Issue:
Bug - `SeoTools::setTitle` not setting `JsonLdMulti` title
### What steps will reproduce the problem?
Use `SeoTools::setTitle()` or run the unit tests

### What is the expected result?
The title/name to be set correctly in the JsonLD

### What do you get instead?
The default title

```
1) Artesaos\SEOTools\Tests\SEOToolsTest::test_set_title
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'[..]<script type="application/ld+json">
{"@context":"https://schema.org","@type":"WebPage","name":"Kamehamehaaaaaaa","description":"For those who helped create the Genki Dama"}</script>'
+'[..]<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>'
```

### Additional info

| Q                         | A
| ------------------------- | ---
| This Package Version      | v0.22.1



Discussion / hints:

Fix patch:
diff --git a/composer.json b/composer.json
index 2d21914..d1c2e9c 100644
--- a/composer.json
+++ b/composer.json
@@ -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",
@@ -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": {
diff --git a/src/SEOTools/SEOTools.php b/src/SEOTools/SEOTools.php
index ec15543..27945a9 100644
--- a/src/SEOTools/SEOTools.php
+++ b/src/SEOTools/SEOTools.php
@@ -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;
     }
@@ -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;
     }
@@ -100,7 +100,7 @@ public function addImages($urls)
 
         $this->twitter()->setImage($urls);
 
-        $this->jsonLd()->addImage($urls);
+        $this->jsonLdMulti()->addImage($urls);
 
         return $this;
     }
@@ -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();
 
         return ($minify) ? str_replace(PHP_EOL, '', $html) : $html;
     }


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..e4be5a2
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -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
diff --git a/tests/SEOTools/JsonLdMultiTest.php b/tests/SEOTools/JsonLdMultiTest.php
index 0f69c25..35355a6 100644
--- a/tests/SEOTools/JsonLdMultiTest.php
+++ b/tests/SEOTools/JsonLdMultiTest.php
@@ -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
      */
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -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);
     }
@@ -169,8 +150,7 @@ 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);
     }
@@ -178,9 +158,9 @@ public function test_add_values()
     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);
     }
@@ -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);
     }