Skip to content

Commit

Permalink
artesaos#167: add JsonLd::setName()
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Aug 13, 2019
1 parent 98aaabd commit 898035f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/SEOTools/Contracts/JsonLd.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function addValue($key, $value);
public function setType($type);

/**
* @param string $name
*
* @return static
*/
public function setName($name);

/**
* Alias of {@see setName()}.
*
* @param string $title
*
* @return static
Expand Down
18 changes: 13 additions & 5 deletions src/SEOTools/JsonLd.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class JsonLd implements JsonLdContract
/**
* @var string
*/
protected $title = '';
protected $name = '';

/**
* @var string
Expand Down Expand Up @@ -73,8 +73,8 @@ public function generate($minify = false)
}


if (!empty($this->title)) {
$generated['name'] = $this->title;
if (!empty($this->name)) {
$generated['name'] = $this->name;
}


Expand Down Expand Up @@ -118,13 +118,21 @@ public function setType($type)
/**
* {@inheritdoc}
*/
public function setTitle($title)
public function setName($name)
{
$this->title = $title;
$this->name = $name;

return $this;
}

/**
* {@inheritdoc}
*/
public function setTitle($title)
{
return $this->setName($title);
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/SEOTools/SEOTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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->jsonLd()->setName($title);

return $this;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/SEOTools/JsonLdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ protected function setUp(): void
$this->jsonLd = $this->app->make('seotools.json-ld');
}

public function test_set_name()
{
$this->jsonLd->setName('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></head></html>';

$this->setRightAssertion($expected);
}

/**
* @depends test_set_name
*/
public function test_set_title()
{
$this->jsonLd->setTitle('Kamehamehaaaaaaaa');
Expand Down

0 comments on commit 898035f

Please sign in to comment.