diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6323faa..12f582b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,22 +11,18 @@ jobs: strategy: fail-fast: true matrix: - php: [7.4, 8.0, 8.1, 8.2] - laravel: [8.*, 9.*, 10.*] + php: [8.1, 8.2, 8.3] + laravel: [10.*, 11.*] dependency-version: [prefer-stable] exclude: - - php: 7.4 - laravel: 9.* - - php: 7.4 - laravel: 10.* - - php: 8.0 - laravel: 10.* + - php: 8.1 + laravel: 11.* name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -42,4 +38,4 @@ jobs: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests - run: vendor/bin/phpunit --verbose + run: vendor/bin/phpunit diff --git a/README.md b/README.md index 890929c..7536e18 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ use Artesaos\SEOTools\Facades\JsonLdMulti; // OR use Artesaos\SEOTools\Facades\SEOTools; -class CommomController extends Controller +class CommonController extends Controller { public function index() { @@ -432,7 +432,7 @@ namespace App\Http\Controllers; use Artesaos\SEOTools\Traits\SEOTools as SEOToolsTrait; -class CommomController extends Controller +class CommonController extends Controller { use SEOToolsTrait; @@ -552,6 +552,8 @@ SEOMeta::addKeyword($keyword); SEOMeta::addMeta($meta, $value = null, $name = 'name'); SEOMeta::addAlternateLanguage($lang, $url); SEOMeta::addAlternateLanguages(array $languages); +SEOMeta::setAlternateLanguage($lang, $url); +SEOMeta::setAlternateLanguages(array $languages); SEOMeta::setTitleSeparator($separator); SEOMeta::setTitle($title); SEOMeta::setTitleDefault($default); diff --git a/composer.json b/composer.json index b24a4a6..d26ffde 100644 --- a/composer.json +++ b/composer.json @@ -23,15 +23,15 @@ } ], "require": { - "php": ">=7.1|^8.0", + "php": "^8.1", "ext-json": "*", - "illuminate/config": "5.8.* || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/support": "5.8.* || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" + "illuminate/config": "^10.0 || ^11.0", + "illuminate/support": "^10.0 || ^11.0" }, "require-dev": { - "orchestra/testbench": "~3.8.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0", + "orchestra/testbench": "^8.0 || ^9.0", "phpspec/phpspec": "~5.1.1 || ^6.0 || ^7.0", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.0 || ^10.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a1bcfca..940da59 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,14 @@ - ./tests + tests + ./tests/SEOTools/BaseTest.php - - - ./src - - - - - - - - - diff --git a/src/SEOTools/Contracts/MetaTags.php b/src/SEOTools/Contracts/MetaTags.php index 5a65b65..ffdaf85 100644 --- a/src/SEOTools/Contracts/MetaTags.php +++ b/src/SEOTools/Contracts/MetaTags.php @@ -206,6 +206,25 @@ public function addAlternateLanguage($lang, $url); */ public function addAlternateLanguages(array $languages); + /** + * Set an alternate language. + * + * @param string $lang language code in format ISO 639-1 + * @param string $url + * + * @return static + */ + public function setAlternateLanguage($lang, $url); + + /** + * Set alternate languages. + * + * @param array $languages + * + * @return static + */ + public function setAlternateLanguages(array $languages); + /** * Get the title formatted for display. * diff --git a/src/SEOTools/Facades/SEOMeta.php b/src/SEOTools/Facades/SEOMeta.php index 6dff39e..1a1a7c1 100644 --- a/src/SEOTools/Facades/SEOMeta.php +++ b/src/SEOTools/Facades/SEOMeta.php @@ -25,6 +25,8 @@ * @method static \Artesaos\SEOTools\Contracts\MetaTags setNext(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags addAlternateLanguage(string $lang, string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags addAlternateLanguages(array $languages) + * @method static \Artesaos\SEOTools\Contracts\MetaTags setAlternateLanguage(string $lang, string $url) + * @method static \Artesaos\SEOTools\Contracts\MetaTags setAlternateLanguages(array $languages) * @method static string getTitle() * @method static string getTitleSession() * @method static string getTitleSeparator() diff --git a/src/SEOTools/OpenGraph.php b/src/SEOTools/OpenGraph.php index 99fe5af..60f1518 100644 --- a/src/SEOTools/OpenGraph.php +++ b/src/SEOTools/OpenGraph.php @@ -674,6 +674,7 @@ public function setProduct($attributes = []) 'gtin', 'isbn', 'mfr_part_no', + 'retailer_item_id', 'sale_price:amount', 'sale_price:currency', diff --git a/src/SEOTools/SEOMeta.php b/src/SEOTools/SEOMeta.php index 1a2fc18..9ab473f 100644 --- a/src/SEOTools/SEOMeta.php +++ b/src/SEOTools/SEOMeta.php @@ -225,7 +225,9 @@ public function generate($minify = false) } foreach ($languages as $lang) { - $html[] = ""; + if (!empty($lang['lang'] && !empty($lang['url']))) { + $html[] = ""; + } } if ($robots) { @@ -436,6 +438,32 @@ public function addAlternateLanguages(array $languages) return $this; } + /** + * {@inheritdoc} + */ + public function setAlternateLanguage($lang, $url) + { + // Remove language if already existing + $this->alternateLanguages = array_filter($this->alternateLanguages, function ($arr) use ($lang) { + return $arr['lang'] !== $lang; + }); + + // Append (updated) language + $this->alternateLanguages[] = ['lang' => $lang, 'url' => $url]; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function setAlternateLanguages(array $languages) + { + $this->alternateLanguages = $languages; + + return $this; + } + /** * Sets the meta robots. * diff --git a/tests/SEOTools/BaseTest.php b/tests/SEOTools/BaseTest.php index 07a3ec4..7eb4bf2 100644 --- a/tests/SEOTools/BaseTest.php +++ b/tests/SEOTools/BaseTest.php @@ -9,7 +9,7 @@ /** * Class BaseTest. */ -abstract class BaseTest extends TestCase +class BaseTest extends TestCase { /** * {@inheritdoc} diff --git a/tests/SEOTools/SEOMetaTest.php b/tests/SEOTools/SEOMetaTest.php index eb96108..22f4777 100644 --- a/tests/SEOTools/SEOMetaTest.php +++ b/tests/SEOTools/SEOMetaTest.php @@ -168,7 +168,7 @@ public function test_set_canonical() $this->assertEquals($canonical, $this->seoMeta->getCanonical()); } - public function dataTestUrls() + public static function dataTestUrls() { return [ ['http://localhost/hello/world', 'http://localhost/hello/world'], @@ -251,7 +251,7 @@ public function test_set_prev() $this->assertEquals($prev, $this->seoMeta->getPrev()); } - public function test_set_alternate_languages() + public function test_add_alternate_languages() { $fullHeader = "It's Over 9000!"; $fullHeader .= ""; @@ -270,6 +270,70 @@ public function test_set_alternate_languages() $this->assertEquals(array_merge($expectedLangs, $expectedLangs), $this->seoMeta->getAlternateLanguages()); } + public function test_set_alternate_languages() + { + $fullHeader = "It's Over 9000!"; + $fullHeader .= ""; + $fullHeader .= ""; + $lang = 'en'; + $langUrl = 'http://domain.com'; + + $expectedLangs = [['lang' => $lang, 'url' => $langUrl]]; + $this->seoMeta->setAlternateLanguage($lang, $langUrl); + + $this->setRightAssertion($fullHeader); + $this->assertEquals($expectedLangs, $this->seoMeta->getAlternateLanguages()); + + $this->seoMeta->setAlternateLanguages($expectedLangs); + + $this->assertEquals($expectedLangs, $this->seoMeta->getAlternateLanguages()); + } + + public function test_set_override_alternate_language() + { + $fullHeader = "It's Over 9000!"; + $fullHeader .= ""; + $fullHeader .= ""; + $lang = 'en'; + $langUrl = 'http://domain.com'; + $langUrlOverridden = 'http://domain.test'; + + $expectedLangs = [['lang' => $lang, 'url' => $langUrl]]; + $expectedLangsOverridden = [['lang' => $lang, 'url' => $langUrlOverridden]]; + + $this->seoMeta->setAlternateLanguage($lang, $langUrl); + $this->assertEquals($expectedLangs, $this->seoMeta->getAlternateLanguages()); + + $this->seoMeta->setAlternateLanguage($lang, $langUrlOverridden); + $this->setRightAssertion($fullHeader); + $this->assertEquals($expectedLangsOverridden, $this->seoMeta->getAlternateLanguages()); + } + + public function test_remove_alternate_language() + { + $fullHeader = "It's Over 9000!"; + $fullHeader .= ""; + $lang = 'en'; + $langUrl = 'http://domain.com'; + + $expectedLangs = [['lang' => $lang, 'url' => false]]; + + $this->seoMeta->setAlternateLanguage($lang, $langUrl); + $this->seoMeta->setAlternateLanguage($lang, false); + $this->setRightAssertion($fullHeader); + $this->assertEquals($expectedLangs, $this->seoMeta->getAlternateLanguages()); + } + + public function test_remove_alternate_languages() + { + $fullHeader = "It's Over 9000!"; + $fullHeader .= ""; + + $this->seoMeta->setAlternateLanguages([]); + $this->setRightAssertion($fullHeader); + $this->assertEquals([], $this->seoMeta->getAlternateLanguages()); + } + public function test_set_reset() { $expected = "It's Over 9000!"; diff --git a/tests/SEOTools/SEOToolsServiceProviderTest.php b/tests/SEOTools/SEOToolsServiceProviderTest.php index f85b7a4..e0eeee3 100644 --- a/tests/SEOTools/SEOToolsServiceProviderTest.php +++ b/tests/SEOTools/SEOToolsServiceProviderTest.php @@ -26,7 +26,7 @@ public function test_container_are_provided($contract, $concreteClass) /** * @return array */ - public function bindsListProvider() + public static function bindsListProvider() { return [ [