Skip to content

Commit

Permalink
Updating Seoable Trait + Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 16, 2015
1 parent f0f71c9 commit 4dc8703
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 1 deletion.
86 changes: 85 additions & 1 deletion src/Traits/Seoable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,89 @@
*/
trait Seoable
{
//
/* ------------------------------------------------------------------------------------------------
| Helpers Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the SeoHelper instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoHelper
*/
public function seo()
{
return seo_helper();
}

/**
* Get the SeoMeta instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoMeta
*/
public function seoMeta()
{
return $this->seo()->meta();
}

/**
* Get the SeoOpenGraph instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoOpenGraph
*/
public function seoGraph()
{
return $this->seo()->openGraph();
}

/**
* Get the SeoTwitter instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoTwitter
*/
public function seoCard()
{
return $this->seo()->twitter();
}

/* ------------------------------------------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
*/
/**
* Set title.
*
* @param string $title
* @param string|null $siteName
* @param string|null $separator
*
* @return \Arcanedev\SeoHelper\Contracts\SeoHelper
*/
public function setTitle($title, $siteName = null, $separator = null)
{
return $this->seo()->setTitle($title, $siteName, $separator);
}

/**
* Set description.
*
* @param string $description
*
* @return \Arcanedev\SeoHelper\Contracts\SeoHelper
*/
public function setDescription($description)
{
return $this->seo()->setDescription($description);
}

/**
* Set keywords.
*
* @param array|string $keywords
*
* @return \Arcanedev\SeoHelper\Contracts\SeoHelper
*/
public function setKeywords($keywords)
{
return $this->seo()->setKeywords($keywords);
}
}
18 changes: 18 additions & 0 deletions tests/Stubs/Dummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php namespace Arcanedev\SeoHelper\Tests\Stubs;

use Arcanedev\SeoHelper\Traits\Seoable;

/**
* Class Dummy
*
* @package Arcanedev\SeoHelper\Tests\Stubs
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class Dummy
{
/* ------------------------------------------------------------------------------------------------
| Traits
| ------------------------------------------------------------------------------------------------
*/
use Seoable;
}
174 changes: 174 additions & 0 deletions tests/Traits/SeoableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php namespace Arcanedev\SeoHelper\Tests\Traits;

use Arcanedev\SeoHelper\Tests\Stubs\Dummy;
use Arcanedev\SeoHelper\Tests\TestCase;

/**
* Class SeoableTest
*
* @package Arcanedev\SeoHelper\Tests\Traits
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class SeoableTest extends TestCase
{
/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* @var Dummy
*/
private $dummy;

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
public function setUp()
{
parent::setUp();

$this->dummy = new Dummy;
}

public function tearDown()
{
parent::tearDown();

unset($this->dummy);
}

/* ------------------------------------------------------------------------------------------------
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/** @test */
public function it_can_get_main_helper()
{
$seoHelper = $this->dummy->seo();

$expectations = [
\Arcanedev\SeoHelper\Contracts\SeoHelper::class,
\Arcanedev\SeoHelper\Contracts\Renderable::class,
\Arcanedev\SeoHelper\SeoHelper::class,
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $seoHelper);
}
}

/** @test */
public function it_can_get_meta_helper()
{
$seoMeta = $this->dummy->seoMeta();

$expectations = [
\Arcanedev\SeoHelper\Contracts\SeoMeta::class,
\Arcanedev\SeoHelper\Contracts\Renderable::class,
\Arcanedev\SeoHelper\SeoMeta::class,
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $seoMeta);
}
}

/** @test */
public function it_can_get_open_graph_helper()
{
$seoOpenGraph = $this->dummy->seoGraph();

$expectations = [
\Arcanedev\SeoHelper\Contracts\SeoOpenGraph::class,
\Arcanedev\SeoHelper\Contracts\Renderable::class,
\Arcanedev\SeoHelper\SeoOpenGraph::class,
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $seoOpenGraph);
}
}

/** @test */
public function it_can_get_twitter_card_helper()
{
$seoTwitter = $this->dummy->seoCard();
$expectations = [
\Arcanedev\SeoHelper\Contracts\SeoTwitter::class,
\Arcanedev\SeoHelper\Contracts\Renderable::class,
\Arcanedev\SeoHelper\SeoTwitter::class,
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $seoTwitter);
}
}

/** @test */
public function it_can_set_and_render_title()
{
$title = 'Hello World';
$siteName = 'ARCANEDEV';
$separator = '|';
$expectations = [
"<title>$title $separator $siteName</title>",
'<meta property="og:title" content="' . $title . '">',
'<meta name="twitter:title" content="' . $title . '">',
];

$this->dummy->setTitle($title, $siteName, $separator);

foreach ($expectations as $expected) {
$this->assertContains($expected, $this->dummy->seo()->render());
$this->assertContains($expected, (string) $this->dummy->seo());

$this->assertContains($expected, seo_helper()->render());
$this->assertContains($expected, (string) seo_helper());
}
}

/** @test */
public function it_can_set_and_render_description()
{
$description = 'ARCANEDEV super description';
$expectations = [
'<meta name="description" content="' . $description . '">',
'<meta property="og:description" content="' . $description . '">',
'<meta name="twitter:description" content="' . $description . '">',
];

$this->dummy->setDescription($description);

foreach ($expectations as $expected) {
$this->assertContains($expected, $this->dummy->seo()->render());
$this->assertContains($expected, (string) $this->dummy->seo());

$this->assertContains($expected, seo_helper()->render());
$this->assertContains($expected, (string) seo_helper());
}
}

/** @test */
public function it_can_set_and_render_keywords()
{
$keywords = $this->getSeoHelperConfig('keywords.default');
$expected = '<meta name="keywords" content="' . implode(', ', $keywords) . '">';

$this->dummy->setKeywords($keywords); // Array

$this->assertContains($expected, $this->dummy->seo()->render());
$this->assertContains($expected, (string) $this->dummy->seo());

$this->assertContains($expected, seo_helper()->render());
$this->assertContains($expected, (string) seo_helper());

$this->dummy->setKeywords(implode(',', $keywords)); // String

$this->assertContains($expected, $this->dummy->seo()->render());
$this->assertContains($expected, (string) $this->dummy->seo());

$this->assertContains($expected, seo_helper()->render());
$this->assertContains($expected, (string) seo_helper());
}
}

0 comments on commit 4dc8703

Please sign in to comment.