Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opengraph tests [WIP] #64

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/SEOTools/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ protected function getPackageProviders($app)
{
return ['Artesaos\SEOTools\Providers\SEOToolsServiceProvider'];
}

/**
* @param $str
* @return string
*/
protected function removeBreakLines($str)
{
return str_replace(array("\r", "\n"), '', $str);
}
}
89 changes: 89 additions & 0 deletions tests/SEOTools/OpenGraphTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Artesaos\SEOTools\Tests;

use Artesaos\SEOTools\Contracts\OpenGraph;

/**
* Class OpenGraphTest.
*/
class OpenGraphTest extends BaseTest
{
/**
* @var OpenGraph
*/
protected $openGraph;

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

$this->openGraph = $this->app->make('seotools.opengraph');
}

public function test_generate()
{
$expected = "<meta property=\"og:title\" content=\"Over 9000 Thousand!\" />";
$expected .= "<meta property=\"og:description\" content=\"For those who helped create the Genki Dama\" />";
$this->assertEquals($expected, $this->removeBreakLines($this->openGraph->generate()));
}

public function test_set_title()
{
$this->openGraph->setTitle('Kamehamehaaaaaaaa');

$expected = "<meta property=\"og:title\" content=\"Kamehamehaaaaaaaa\" />";
$expected .= "<meta property=\"og:description\" content=\"For those who helped create the Genki Dama\" />";
$this->assertEquals($expected, $this->removeBreakLines($this->openGraph->generate()));
}

public function test_set_url()
{
$this->openGraph->setUrl('http://localhost');

$expected = "<meta property=\"og:url\" content=\"http://localhost\" />";
$expected .= "<meta property=\"og:title\" content=\"Over 9000 Thousand!\" />";
$expected .= "<meta property=\"og:description\" content=\"For those who helped create the Genki Dama\" />";
$this->assertEquals($expected, $this->removeBreakLines($this->openGraph->generate()));
}

public function test_set_article()
{
$this->openGraph->setArticle([
'published_time' => (new \DateTime()),
'modified_time' => (new \DateTime()),
'expiration_time' => (new \DateTime()),
'author' => 'profile / array',
'section' => 'section',
'tag' => ['tag1', 'tag2']
]);

$expected = "<meta property=\"og:title\" content=\"Over 9000 Thousand!\" />";
$expected .= "<meta property=\"og:description\" content=\"For those who helped create the Genki Dama\" />";
$this->assertEquals($expected, $this->removeBreakLines($this->openGraph->generate()));
}

public function test_set_profile()
{
$this->openGraph->setProfile([
'first_name' => 'string',
'last_name' => 'string',
'username' => 'string',
'gender' => 'male'
]);

$expected = "<meta property=\"og:title\" content=\"Over 9000 Thousand!\" />";
$expected .= "<meta property=\"og:description\" content=\"For those who helped create the Genki Dama\" />";
$this->assertEquals($expected, $this->removeBreakLines($this->openGraph->generate()));
}

public function test_set_type()
{
$this->openGraph->setType('article');

$expected = "<meta property=\"og:type\" content=\"article\" />";
$expected .= "<meta property=\"og:title\" content=\"Over 9000 Thousand!\" />";
$expected .= "<meta property=\"og:description\" content=\"For those who helped create the Genki Dama\" />";
$this->assertEquals($expected, $this->removeBreakLines($this->openGraph->generate()));
}
}