-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace romanzipp\Seo\Services\Traits; | ||
|
||
use Spatie\SchemaOrg\Type; | ||
|
||
trait SchemaOrgTrait | ||
{ | ||
/** | ||
* Get spatie/schema-org types. | ||
* | ||
* @return array | ||
*/ | ||
public function getSchemes(): array | ||
{ | ||
return $this->schemeOrgTypes; | ||
} | ||
|
||
/** | ||
* Add spatie/schema-org object. | ||
* | ||
* @param Type $schema schema.org Type | ||
*/ | ||
public function addSchema(Type $schema): self | ||
{ | ||
$this->schemeOrgTypes[] = $schema; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set array of spatie/schema-org objects. | ||
* | ||
* @param array $types | ||
*/ | ||
public function setSchemes(array $types): self | ||
{ | ||
$this->schemeOrgTypes = $types; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace romanzipp\Seo\Test; | ||
|
||
use romanzipp\Seo\Facades\Seo; | ||
use romanzipp\Seo\Test\TestCase; | ||
use Spatie\SchemaOrg\Schema; | ||
|
||
class SchemaOrgTest extends TestCase | ||
{ | ||
public function testAppending() | ||
{ | ||
seo()->addSchema( | ||
Schema::localBusiness()->name('Spatie') | ||
); | ||
|
||
$this->assertCount( | ||
1, | ||
seo()->renderContentsArray() | ||
); | ||
} | ||
|
||
public function testSetter() | ||
{ | ||
seo()->addSchema( | ||
Schema::localBusiness()->name('Spatie') | ||
); | ||
|
||
seo()->setSchemes([ | ||
Schema::airline()->name('Spatie'), | ||
]); | ||
|
||
$this->assertCount( | ||
1, | ||
seo()->renderContentsArray() | ||
); | ||
} | ||
|
||
public function testBasicRender() | ||
{ | ||
seo()->addSchema( | ||
Schema::localBusiness()->name('Spatie') | ||
); | ||
|
||
$this->assertStringStartsWith( | ||
'<script type="application/ld+json">', | ||
seo()->render()->toHtml() | ||
); | ||
} | ||
} |