Skip to content

Commit

Permalink
Add more sections unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romanzipp committed Jan 13, 2021
1 parent 1659b30 commit 4ba1013
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/SectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace romanzipp\Seo\Test;

use romanzipp\Seo\Services\SeoService;
use romanzipp\Seo\Structs\Meta;

class SectionsTest extends TestCase
Expand Down Expand Up @@ -54,4 +55,53 @@ public function testSectionsDoNotMatch()
self::assertCount(1, seo()->section('secondary')->getStructs());
self::assertSame('secondary', (string) seo()->section('secondary')->getStruct(Meta::class)->getComputedAttribute('section'));
}

public function testSectionPassedAsParameterToHelper()
{
seo('secondary')->twitter('card', 'default');

self::assertSame(
seo()->section('secondary')->getStructs(),
seo('secondary')->getStructs()
);
}

public function testSectionSetterOnMutableInstance()
{
$seo = app(SeoService::class);

$seo->section('secondary');

$seo->twitter('card', 'default');
$seo->twitter('author', 'Roman');

self::assertCount(2, $seo->getStructs());

self::assertSame(
$seo->getStructs(),
seo('secondary')->getStructs()
);
}

public function testSectionRender()
{
seo()->twitter('card', 'default');

seo()->section('secondary')->twitter('card', 'secondary');

self::assertEquals(
'<meta name="twitter:card" content="default" />',
seo()->render()->toHtml()
);

self::assertEquals(
'<meta name="twitter:card" content="secondary" />',
seo()->section('secondary')->render()->toHtml()
);

self::assertEquals(
'<meta name="twitter:card" content="secondary" />',
seo('secondary')->render()->toHtml()
);
}
}
8 changes: 8 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@

use Orchestra\Testbench\TestCase as BaseTestCase;
use PHPUnit\Framework\Constraint\RegularExpression;
use romanzipp\Seo\Builders\StructBuilder;
use romanzipp\Seo\Facades\Seo;
use romanzipp\Seo\Providers\SeoServiceProvider;

abstract class TestCase extends BaseTestCase
{
public function setUp(): void
{
parent::setUp();

StructBuilder::$separator = PHP_EOL;
StructBuilder::$indent = null;
}
protected function getPackageProviders($app)
{
return [
Expand Down

0 comments on commit 4ba1013

Please sign in to comment.