Skip to content

Commit

Permalink
Add setUrl convenience method to SeoHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor North committed Apr 3, 2019
1 parent a73ef47 commit 237bd3f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/SeoHelper.php
Expand Up @@ -253,6 +253,21 @@ public function setImage($imageUrl)
return $this; return $this;
} }


/**
* Set the current URL.
*
* @param string $url
*
* @return \Arcanedev\SeoHelper\SeoHelper
*/
public function setUrl($url)
{
$this->meta()->setUrl($url);
$this->openGraph()->setUrl($url);

return $this;
}

/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
| Main Methods | Main Methods
| ----------------------------------------------------------------- | -----------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions tests/SeoHelperTest.php
Expand Up @@ -229,6 +229,23 @@ public function it_can_set_and_render_image()
static::assertStringContainsString($expected, $rendered); static::assertStringContainsString($expected, $rendered);
} }
} }

/** @test */
public function it_can_set_and_render_url()
{
$this->seoHelper->setUrl($url = 'http://localhost/path');

$expectations = [
'<link rel="canonical" href="'.$url.'">',
'<meta property="og:url" content="'.$url.'">'
];

$rendered = $this->seoHelper->render();

foreach ($expectations as $expected) {
static::assertStringContainsString($expected, $rendered);
}
}


/** @test */ /** @test */
public function it_can_render_all() public function it_can_render_all()
Expand Down

0 comments on commit 237bd3f

Please sign in to comment.