mirror of
https://github.com/archtechx/laravel-pages.git
synced 2025-12-12 18:04:02 +00:00
add source code
This commit is contained in:
commit
e534ddd14c
23 changed files with 798 additions and 0 deletions
22
tests/CreatesApplication.php
Normal file
22
tests/CreatesApplication.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
79
tests/Feature/PagesTest.php
Normal file
79
tests/Feature/PagesTest.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
use ArchTech\Pages\Page;
|
||||
|
||||
beforeEach(function () {
|
||||
Page::routes();
|
||||
|
||||
Page::query()->delete();
|
||||
|
||||
view()->addNamespace('test', __DIR__ . '/../views');
|
||||
|
||||
config([
|
||||
'pages.views.layout' => 'test::layout',
|
||||
'pages.views.path' => 'test::',
|
||||
'orbit.paths.content' => __DIR__ . '/../orbit/content',
|
||||
'orbit.paths.cache' => __DIR__ . '/../orbit/cache',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a view is shown if it exists')
|
||||
->get('/example')
|
||||
->assertSee('Test view');
|
||||
|
||||
test('markdown is rendered if it exists', function () {
|
||||
Page::create([
|
||||
'slug' => 'test',
|
||||
'title' => 'Markdown page',
|
||||
'content' => 'This is a **test page**'
|
||||
]);
|
||||
|
||||
using($this)
|
||||
->get('/test')
|
||||
->assertSee('Markdown page')
|
||||
->assertSee('<strong>test page</strong>', false);
|
||||
});
|
||||
|
||||
test('view takes precedence over markdown', function () {
|
||||
Page::create([
|
||||
'slug' => 'example',
|
||||
'title' => 'Test page',
|
||||
'content' => 'This is a test page'
|
||||
]);
|
||||
|
||||
using($this)
|
||||
->get('/example')
|
||||
->assertSee('Test view')
|
||||
->assertDontSee('Test page');
|
||||
});
|
||||
|
||||
test('404 is returned if no view or markdown is found')
|
||||
->get('/foo')
|
||||
->assertNotFound();
|
||||
|
||||
test('a custom layout can be used', function () {
|
||||
config(['pages.views.layout' => 'test::layout2']);
|
||||
|
||||
Page::create([
|
||||
'slug' => 'test',
|
||||
'title' => 'Test page',
|
||||
'content' => 'This is a test page'
|
||||
]);
|
||||
|
||||
using($this)
|
||||
->get('/test')
|
||||
->assertSee('second layout');
|
||||
});
|
||||
|
||||
test('SEO metadata is set on markdown pages', function () {
|
||||
Page::create([
|
||||
'slug' => 'test',
|
||||
'title' => 'Test page',
|
||||
'content' => 'This is a test page'
|
||||
]);
|
||||
|
||||
using($this)
|
||||
->get('/test')
|
||||
->assertSee('<meta property="og:title" content="Test page" />', false)
|
||||
->assertSee('<meta property="og:description" content="This is a test page" />', false);
|
||||
});
|
||||
47
tests/Pest.php
Normal file
47
tests/Pest.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
use ArchTech\Pages\Tests\TestCase;
|
||||
|
||||
uses(ArchTech\Pages\Tests\TestCase::class)->in('Feature');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||
|
|
||||
*/
|
||||
|
||||
expect()->extend('toBeOne', function () {
|
||||
return $this->toBe(1);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your test files.
|
||||
|
|
||||
*/
|
||||
|
||||
function using($test): TestCase
|
||||
{
|
||||
return $test;
|
||||
}
|
||||
20
tests/TestCase.php
Normal file
20
tests/TestCase.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace ArchTech\Pages\Tests;
|
||||
|
||||
use Orchestra\Testbench\TestCase as TestbenchTestCase;
|
||||
use ArchTech\Pages\PagesServiceProvider;
|
||||
use ArchTech\SEO\SEOServiceProvider;
|
||||
use Orbit\OrbitServiceProvider;
|
||||
|
||||
class TestCase extends TestbenchTestCase
|
||||
{
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
SEOServiceProvider::class,
|
||||
OrbitServiceProvider::class,
|
||||
PagesServiceProvider::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
7
tests/orbit/content/pages/example.md
Normal file
7
tests/orbit/content/pages/example.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
slug: example
|
||||
title: 'Test page'
|
||||
updated_at: 2021-08-06T02:25:15+00:00
|
||||
created_at: 2021-08-06T02:25:15+00:00
|
||||
---
|
||||
This is a test page
|
||||
7
tests/orbit/content/pages/test.md
Normal file
7
tests/orbit/content/pages/test.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
slug: test
|
||||
title: 'Test page'
|
||||
updated_at: 2021-08-06T02:25:15+00:00
|
||||
created_at: 2021-08-06T02:25:15+00:00
|
||||
---
|
||||
This is a test page
|
||||
4
tests/views/components/layout.blade.php
Normal file
4
tests/views/components/layout.blade.php
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<div class="first layout">
|
||||
<x-seo::meta />
|
||||
{{ $slot }}
|
||||
</div>
|
||||
3
tests/views/components/layout2.blade.php
Normal file
3
tests/views/components/layout2.blade.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<div class="second layout">
|
||||
{{ $slot }}
|
||||
</div>
|
||||
3
tests/views/example.blade.php
Normal file
3
tests/views/example.blade.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<x-test::layout>
|
||||
Test view
|
||||
</x-test::layout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue