Skip to content

Commit

Permalink
Merge branch 'master' into custom_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
vinicius73 authored May 20, 2024
2 parents 61bf190 + 44920c7 commit 9a12e48
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 40 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 2 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="SEOTools Test Suite">
<directory suffix=".php">./tests</directory>
<directory suffix="Test.php">tests</directory>
<exclude>./tests/SEOTools/BaseTest.php</exclude>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-php" target="build/coverage.serialized"/>
</logging>
</phpunit>
19 changes: 19 additions & 0 deletions src/SEOTools/Contracts/MetaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions src/SEOTools/Facades/SEOMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/SEOTools/OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ public function setProduct($attributes = [])
'gtin',
'isbn',
'mfr_part_no',
'retailer_item_id',

'sale_price:amount',
'sale_price:currency',
Expand Down
30 changes: 29 additions & 1 deletion src/SEOTools/SEOMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ public function generate($minify = false)
}

foreach ($languages as $lang) {
$html[] = "<link rel=\"alternate\" hreflang=\"{$lang['lang']}\" href=\"{$lang['url']}\">";
if (!empty($lang['lang'] && !empty($lang['url']))) {
$html[] = "<link rel=\"alternate\" hreflang=\"{$lang['lang']}\" href=\"{$lang['url']}\">";
}
}

if ($robots) {
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/SEOTools/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Class BaseTest.
*/
abstract class BaseTest extends TestCase
class BaseTest extends TestCase
{
/**
* {@inheritdoc}
Expand Down
68 changes: 66 additions & 2 deletions tests/SEOTools/SEOMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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 = "<title>It's Over 9000!</title>";
$fullHeader .= "<meta name=\"description\" content=\"For those who helped create the Genki Dama\">";
Expand All @@ -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 = "<title>It's Over 9000!</title>";
$fullHeader .= "<meta name=\"description\" content=\"For those who helped create the Genki Dama\">";
$fullHeader .= "<link rel=\"alternate\" hreflang=\"en\" href=\"http://domain.com\">";
$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 = "<title>It's Over 9000!</title>";
$fullHeader .= "<meta name=\"description\" content=\"For those who helped create the Genki Dama\">";
$fullHeader .= "<link rel=\"alternate\" hreflang=\"en\" href=\"http://domain.test\">";
$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 = "<title>It's Over 9000!</title>";
$fullHeader .= "<meta name=\"description\" content=\"For those who helped create the Genki Dama\">";
$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 = "<title>It's Over 9000!</title>";
$fullHeader .= "<meta name=\"description\" content=\"For those who helped create the Genki Dama\">";

$this->seoMeta->setAlternateLanguages([]);
$this->setRightAssertion($fullHeader);
$this->assertEquals([], $this->seoMeta->getAlternateLanguages());
}

public function test_set_reset()
{
$expected = "<title>It's Over 9000!</title>";
Expand Down
2 changes: 1 addition & 1 deletion tests/SEOTools/SEOToolsServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_container_are_provided($contract, $concreteClass)
/**
* @return array
*/
public function bindsListProvider()
public static function bindsListProvider()
{
return [
[
Expand Down

0 comments on commit 9a12e48

Please sign in to comment.