Skip to content

Commit ed76bb6

Browse files
author
James Wigger
committed
Added layout output tests
1 parent 1b243f9 commit ed76bb6

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ function base_asset($path, $manifestDirectory = '')
7878
if (!function_exists('base_layout')) {
7979
function base_layout($file, array $data = [], $return = false)
8080
{
81+
$Base = new Base(realpath(__DIR__ . '/../../../'));
82+
8183
$BaseLayout = BaseLayout::fetch();
8284
$BaseLayout->setLayoutVars($data);
8385

84-
$path = base_public_path('layouts/' . ltrim($file, '/') . '.php');
86+
$path = $Base->getLayoutPath() . DIRECTORY_SEPARATOR . ltrim($file, '/') . '.php';
8587

8688
if (!file_exists($path)) {
8789
throw new Exception("Unable to locate layout file: {$path}. Please check the layout exists");

tests/LayoutsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php use PHPUnit\Framework\TestCase;
2+
3+
class LayoutsTest extends TestCase
4+
{
5+
/**
6+
* @test
7+
*/
8+
public function it_will_output_layout_contents()
9+
{
10+
$this->expectOutputString('Hello World');
11+
12+
base_layout('layout.stub');
13+
}
14+
15+
/**
16+
* @test
17+
*/
18+
public function it_will_return_layout_contents()
19+
{
20+
$result = base_layout('layout.stub', [], true);
21+
22+
$this->assertEquals('Hello World', $result);
23+
}
24+
25+
public function setUp()
26+
{
27+
$externalMock = Mockery::mock('overload:RootStudio\Base');
28+
$externalMock->shouldReceive('getLayoutPath')->once()->andReturn(__DIR__ . '/stubs');
29+
30+
parent::setUp();
31+
}
32+
33+
public function tearDown()
34+
{
35+
Mockery::close();
36+
}
37+
}

tests/stubs/layout.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World

0 commit comments

Comments
 (0)