mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-12 01:44:03 +00:00
finished
This commit is contained in:
parent
051a32575c
commit
b12c9ecb55
21 changed files with 750 additions and 86 deletions
38
tests/Pest/BladeTest.php
Normal file
38
tests/Pest/BladeTest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
test('the @seo helper can be used for fetching values', function () {
|
||||
seo(['image' => 'foo']);
|
||||
|
||||
expect(blade('<img src="@seo(\'image\')">'))
|
||||
->toBe('<img src="foo">');
|
||||
});
|
||||
|
||||
test('the @seo helper can be used for setting & fetching values', function () {
|
||||
expect(blade('<img src="@seo(\'image\', \'bar\')">'))
|
||||
->toBe('<img src="bar">');
|
||||
});
|
||||
|
||||
test('the @seo helper can be used for setting values with no output', function () {
|
||||
expect(blade('<img src="@seo([\'image\' => \'foo\'])">'))
|
||||
->toBe('<img src="">');
|
||||
|
||||
expect(seo('image'))->toBe('foo');
|
||||
});
|
||||
|
||||
test("opengraph tags are rendered only if they're set", function () {
|
||||
seo()->title('foo');
|
||||
|
||||
expect(meta())
|
||||
->toContain('og:title')
|
||||
->not()->toContain('og:description');
|
||||
});
|
||||
|
||||
test('twitter tags are rendered only if the extension is enabled', function () {
|
||||
seo()->title('foo');
|
||||
|
||||
expect(meta())->not()->toContain('twitter');
|
||||
|
||||
seo()->twitter()->twitterTitle('bar');
|
||||
|
||||
expect(meta())->toContain('twitter');
|
||||
});
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
it('succeeds', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
|
||||
it('fails', function () {
|
||||
expect(false)->toBeTrue();
|
||||
});
|
||||
72
tests/Pest/ExtensionTest.php
Normal file
72
tests/Pest/ExtensionTest.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
use ArchTech\SEO\Tests\Etc\FacebookExtension;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
test('the twitter extension is disabled by default', function () {
|
||||
expect(seo()->all())
|
||||
->not()->toBeEmpty()
|
||||
->not()->toHaveKey('twitter.title');
|
||||
});
|
||||
|
||||
test('the twitter extension can be enabled by calling twitter', function () {
|
||||
expect(seo()->twitter()->all())
|
||||
->not()->toBeEmpty()
|
||||
->toHaveKey('twitter.title');
|
||||
});
|
||||
|
||||
test('the twitter extension can be disabled by calling twitter with false', function () {
|
||||
expect(seo()->twitter()->twitter(false)->all())
|
||||
->not()->toBeEmpty()
|
||||
->not()->toHaveKey('twitter.title');
|
||||
});
|
||||
|
||||
test('when an extension is enabled, all of its keys are included in the resolved values', function () {
|
||||
expect(seo()->twitter()->all())
|
||||
->not()->toBeEmpty()
|
||||
->toHaveKeys(['twitter.title', 'twitter.description', 'twitter.user', 'twitter.image']);
|
||||
});
|
||||
|
||||
test('extension keys can be set by prefixing the call with the extension name and using camelcase', function () {
|
||||
seo()->extension('foo');
|
||||
|
||||
seo()->fooTitle('bar');
|
||||
|
||||
expect(seo()->all())
|
||||
->toHaveKey('foo.title', 'bar');
|
||||
});
|
||||
|
||||
test('extensions can use custom blade paths', function () {
|
||||
view()->addNamespace('test', __DIR__ . '/../views');
|
||||
|
||||
seo()->extension('facebook', view: 'test::facebook');
|
||||
|
||||
seo()->facebookTitle('abc');
|
||||
|
||||
expect(meta())->toContain('<meta name="facebook:title" content="ABC" />');
|
||||
});
|
||||
|
||||
test('twitter falls back to the default values', function () {
|
||||
seo()->twitter();
|
||||
|
||||
seo()->title('foo');
|
||||
|
||||
seo()->twitterDescription('bar');
|
||||
|
||||
seo()->description('baz');
|
||||
|
||||
expect(seo('twitter.title'))->toBe('foo');
|
||||
expect(seo('twitter.description'))->toBe('bar');
|
||||
expect(seo('description'))->toBe('baz');
|
||||
|
||||
expect(meta())->toContain('<meta name="twitter:title" content="foo">');
|
||||
});
|
||||
|
||||
test('extensions are automatically enabled when values for them are set', function () {
|
||||
expect(seo()->extensions())->not()->toHaveKey('twitter');
|
||||
|
||||
seo()->twitterTitle('foo');
|
||||
|
||||
expect(seo()->extensions())->toHaveKey('twitter');
|
||||
});
|
||||
42
tests/Pest/FlippTest.php
Normal file
42
tests/Pest/FlippTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
test('flipp templates can be set', function () {
|
||||
seo()->flipp('blog', 'abcdefg');
|
||||
|
||||
expect(seo()->meta('flipp.templates'))
|
||||
->toHaveCount(1)
|
||||
->toHaveKey('blog', 'abcdefg');
|
||||
});
|
||||
|
||||
test('flipp templates can be given data', function () {
|
||||
seo()->flipp('blog', 'abcdefg');
|
||||
expect(seo()->flipp('blog', ['title' => 'abc', 'excerpt' => 'def']))
|
||||
->toContain('s.useflipp.com/blog')
|
||||
->toContain(base64_encode(json_encode(['title' => 'abc', 'excerpt' => 'def'])));
|
||||
});
|
||||
|
||||
test('the flipp method returns a link to a signed url', function () {
|
||||
seo()->flipp('blog', 'abcdefg');
|
||||
|
||||
expect(seo()->flipp('blog', ['title' => 'abc']))
|
||||
->toContain('?s=' . hash_hmac('sha256', 'blog' . base64_encode(json_encode(['title' => 'abc'])), config('services.flipp.key')));
|
||||
});
|
||||
|
||||
test("flipp templates use default data when they're not passed any data explicitly", function () {
|
||||
seo()->flipp('blog', 'abcdefg');
|
||||
|
||||
seo()->title('foo')->description('bar');
|
||||
|
||||
expect(seo()->flipp('blog'))
|
||||
->toContain('s.useflipp.com/blog')
|
||||
->toContain(base64_encode(json_encode(['title' => 'foo', 'description' => 'bar'])));
|
||||
});
|
||||
|
||||
test('flipp images are used as the cover images', function () {
|
||||
seo()->flipp('blog', 'abcdefg');
|
||||
|
||||
seo()->title('foo')->description('bar');
|
||||
|
||||
expect(seo()->flipp('blog'))
|
||||
->toBe(seo('image'));
|
||||
});
|
||||
20
tests/Pest/HelperTest.php
Normal file
20
tests/Pest/HelperTest.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
use ArchTech\SEO\SEOManager;
|
||||
|
||||
test('the seo helper returns a SEOManager instance when no arguments are passed', function () {
|
||||
expect(seo())->toBeInstanceOf(SEOManager::class);
|
||||
});
|
||||
|
||||
test('the seo helper returns a value when an argument is passed', function () {
|
||||
seo()->title('foo');
|
||||
|
||||
expect(seo('title'))->toBe('foo');
|
||||
});
|
||||
|
||||
test('the seo helper accepts an array of key-value pairs', function () {
|
||||
seo(['foo' => 'bar', 'abc' => 'xyz']);
|
||||
|
||||
expect(seo('foo'))->toBe('bar');
|
||||
expect(seo('abc'))->toBe('xyz');
|
||||
});
|
||||
68
tests/Pest/ManagerTest.php
Normal file
68
tests/Pest/ManagerTest.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
use ArchTech\SEO\SEOManager;
|
||||
|
||||
test('set returns the set value', function () {
|
||||
expect(seo()->set('foo', 'bar'))->toBe('bar');
|
||||
});
|
||||
|
||||
test('the __call proxy is chainable', function () {
|
||||
expect(seo()->foo('bar'))->toBeInstanceOf(SEOManager::class);
|
||||
});
|
||||
|
||||
test('default values can be set in the proxy call', function () {
|
||||
seo()->title(default: 'foo');
|
||||
expect(seo('title'))->toBe('foo');
|
||||
|
||||
seo()->title('bar');
|
||||
expect(seo('title'))->toBe('bar');
|
||||
});
|
||||
|
||||
test('default values can be set in the proxy call alongside the value', function () {
|
||||
seo()->description('bar', default: 'foo');
|
||||
|
||||
expect(seo('description'))->toBe('bar');
|
||||
});
|
||||
|
||||
test('metadata can be used as strings', function () {
|
||||
seo()->meta('foo', 'bar');
|
||||
|
||||
expect(seo()->meta('foo'))->toBe('bar');
|
||||
});
|
||||
|
||||
test('metadata can be used as arrays', function () {
|
||||
seo()->meta('abc', ['def' => 'xyz']);
|
||||
expect(seo()->meta('abc.def'))->toBe('xyz');
|
||||
|
||||
seo()->meta('abc.def', 'xxx');
|
||||
expect(seo()->meta('abc.def'))->toBe('xxx');
|
||||
|
||||
seo()->meta(['abc.def' => 'yyy']);
|
||||
expect(seo()->meta('abc.def'))->toBe('yyy');
|
||||
});
|
||||
|
||||
test('values can be set magically', function () {
|
||||
seo()->foo = 'bar';
|
||||
|
||||
expect(seo('foo'))->toBe('bar');
|
||||
expect(seo()->foo)->toBe('bar');
|
||||
});
|
||||
|
||||
test('magic access respects modifiers', function () {
|
||||
seo()->foo(modify: 'strtoupper');
|
||||
|
||||
seo()->foo = 'bar';
|
||||
|
||||
expect(seo('foo'))->toBe('BAR');
|
||||
expect(seo()->foo)->toBe('BAR');
|
||||
});
|
||||
|
||||
test('magic access gets converted to dot syntax', function () {
|
||||
seo()->fooBar('baz');
|
||||
expect(seo('foo.bar'))->toBe('baz');
|
||||
expect(seo()->fooBar)->toBe('baz');
|
||||
|
||||
seo()->abcDef = 'xyz';
|
||||
expect(seo('abc.def'))->toBe('xyz');
|
||||
expect(seo()->abcDef)->toBe('xyz');
|
||||
});
|
||||
21
tests/Pest/ModifierTest.php
Normal file
21
tests/Pest/ModifierTest.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
test('values can be modified using modifiers', function () {
|
||||
seo()->title(modify: fn (string $title) => $title . ' | ArchTech');
|
||||
|
||||
seo()->title('About us');
|
||||
|
||||
expect(seo('title'))->toBe('About us | ArchTech');
|
||||
});
|
||||
|
||||
test('modifiers are applied on values returned from set', function () {
|
||||
seo()->title(modify: fn (string $title) => $title . ' | ArchTech');
|
||||
|
||||
expect(seo(['title' => 'Blog']))->toHaveKey('title', 'Blog | ArchTech');
|
||||
});
|
||||
|
||||
test('modifiers are not applied on default values', function () {
|
||||
seo()->title(modify: fn (string $title) => $title . ' | ArchTech', default: 'ArchTech — Web development agency');
|
||||
|
||||
expect(seo('title'))->toBe('ArchTech — Web development agency');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue