-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from thephpleague/fix-tests
Fix Tests
- Loading branch information
Showing
24 changed files
with
449 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use League\Plates\Engine; | ||
|
||
describe('Plates', function() { | ||
it('can render templates with layouts, sections, relative paths, absolute paths, and folders', function() { | ||
$plates = new Engine(['base_dir' => __DIR__ . '/fixtures/standard']); | ||
$plates->addFolder('components', ['partials/components', '']); | ||
$res = $plates->render('main', [ | ||
'name' => 'RJ & Emily', | ||
'sidebar_style' => 'simple', | ||
]); | ||
$html = <<<html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Profile - RJ & Emily</title> | ||
</head> | ||
<body> | ||
<div class="alert success"> | ||
<p>Success!</p> | ||
</div> | ||
<div class="alert error"> | ||
<p>Sorry...</p> | ||
</div> | ||
<h1>Hi RJ & Emily</h1> | ||
<div id="sidebar" class="simple"></div> | ||
<script type="text/javascript" id="main"></script> | ||
<script type="text/javascript" id="sidebar"></script> | ||
</body> | ||
</html> | ||
html; | ||
expect($res)->equal($html); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
use League\Plates\Extension\LayoutSections\{ | ||
LayoutRenderTemplate, | ||
Sections | ||
}; | ||
use League\Plates\{ | ||
Template, | ||
RenderTemplate\MockRenderTemplate, | ||
Extension\RenderContext\FuncArgs | ||
}; | ||
use const League\Plates\Extension\LayoutSections\{ | ||
START_APPEND, | ||
START_PREPEND, | ||
START_REPLACE | ||
}; | ||
use function League\Plates\Extension\LayoutSections\{startFunc}; | ||
use function League\Plates\Extension\RenderContext\{endFunc}; | ||
|
||
|
||
describe('Extension\LayoutSections', function() { | ||
describe('Sections', function() { | ||
it('can add a section', function() { | ||
$sections = new Sections(['foo' => 'bar']); | ||
$sections->add('foo', 'foobar'); | ||
expect($sections->get('foo'))->equal('foobar'); | ||
}); | ||
it('can append a section', function() { | ||
$sections = new Sections(['foo' => 'foo']); | ||
$sections->append('foo', 'bar'); | ||
expect($sections->get('foo'))->equal('foobar'); | ||
}); | ||
it('can prepend a section', function() { | ||
$sections = new Sections(['foo' => 'bar']); | ||
$sections->prepend('foo', 'foo'); | ||
expect($sections->get('foo'))->equal('foobar'); | ||
}); | ||
it('can clear a section', function() { | ||
$sections = new Sections(['foo' => 'bar']); | ||
$sections->clear('foo'); | ||
expect($sections->get('foo'))->equal(null); | ||
}); | ||
it('can get a section', function() { | ||
$sections = new Sections(['foo' => 'bar']); | ||
expect($sections->get('foo'))->equal('bar'); | ||
}); | ||
it('returns null if section does not exist', function() { | ||
$sections = new Sections(); | ||
expect($sections->get('foo'))->equal(null); | ||
}); | ||
}); | ||
|
||
describe('LayoutRenderTemplate', function() { | ||
it('recursively renders a layout template if there is one', function() { | ||
$rt = new MockRenderTemplate([ | ||
'main' => function($template) { | ||
$template->with('layout', $template->fork('sub-layout')->reference); | ||
return 'c'; | ||
}, | ||
'sub-layout' => function($template) { | ||
$template = $template->with('layout', $template->fork('layout')->reference); | ||
$content = $template->get('sections')->get('content'); | ||
return "b{$content}b"; | ||
}, | ||
'layout' => function($template) { | ||
return "a{$template->get('sections')->get('content')}a"; | ||
}, | ||
]); | ||
$rt = new LayoutRenderTemplate($rt); | ||
expect($rt->renderTemplate(new Template('main', [], ['sections' => new Sections()])))->equal('abcba'); | ||
}); | ||
}); | ||
|
||
describe('Funcs', function() { | ||
beforeEach(function() { | ||
$this->render = new MockRenderTemplate([]); | ||
$this->template = (new Template('', [], ['sections' => new Sections()]))->reference; | ||
$this->args = new FuncArgs($this->render, $this->template, '', []); | ||
}); | ||
xdescribe('layoutFunc', function() { | ||
it('forks a template and sets the layout'); | ||
}); | ||
xdescribe('sectionFunc', function() { | ||
it('gets a section from the template sections'); | ||
}); | ||
describe('startFunc', function() { | ||
$create_test = function($update_text, $update, $expected) { | ||
it("can start buffering and {$update_text} the section", function() use ($update, $expected) { | ||
($this->template)()->get('sections')->add('foo', 'baz'); | ||
startFunc($update)($this->args->withArgs(['foo'])); | ||
echo "bar"; | ||
endFunc()($this->args); | ||
expect(($this->template)()->get('sections')->get('foo'))->equal($expected); | ||
}); | ||
}; | ||
$create_test('replace', START_REPLACE, 'bar'); | ||
$create_test('append', START_APPEND, 'bazbar'); | ||
$create_test('prepend', START_PREPEND, 'barbaz'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
use League\Plates\Extension\Path\ResolvePathArgs; | ||
use League\Plates\Template; | ||
use function League\Plates\{ | ||
Extension\Path\idResolvePath, | ||
Extension\Path\relativeResolvePath, | ||
Extension\Path\prefixResolvePath, | ||
Extension\Path\extResolvePath, | ||
Util\joinPath, | ||
Util\stack | ||
}; | ||
|
||
describe('Extension\Path', function() { | ||
beforeEach(function() { | ||
$this->args = new ResolvePathArgs('', [], new Template('a')); | ||
}); | ||
|
||
describe('idResolvePath', function() { | ||
it('returns the name passed in', function() { | ||
$path = stack([idResolvePath()])($this->args->withPath('foo')); | ||
expect($path)->equal('foo'); | ||
}); | ||
}); | ||
describe('relativeResolvePath', function() { | ||
beforeEach(function() { | ||
$this->args->template = new Template('a', [], [], null, (new Template('b', [], ['path' => 'foo/b.phtml']))->reference); | ||
$this->resolve = stack([relativeResolvePath(), idResolvePath()]); | ||
}); | ||
it('resolves the name relative to the current_directory in context', function() { | ||
$resolve = $this->resolve; | ||
$path = $resolve($this->args->withPath('./bar')); | ||
$parent_path = $resolve($this->args->withPath('../bar')); | ||
expect([$path, $parent_path])->equal([ | ||
joinPath(['foo', './bar']), | ||
joinPath(['foo', '../bar']) | ||
]); | ||
}); | ||
it('does nothing if the path does not start with a relative path', function() { | ||
$resolve = $this->resolve; | ||
expect([ | ||
$resolve($this->args->withPath('.../foo')), | ||
$resolve($this->args->withPath('/foo')), | ||
$resolve($this->args->withPath('foo')), | ||
])->equal([ | ||
'.../foo', | ||
'/foo', | ||
'foo', | ||
]); | ||
}); | ||
}); | ||
describe('prefixResolvePath', function() { | ||
beforeEach(function() { | ||
$this->resolve = stack([prefixResolvePath(['/foo', '/bar'], function() { | ||
return true; | ||
}), idResolvePath()]); | ||
}); | ||
it('prefixes non absolute paths with a base path', function() { | ||
$path = ($this->resolve)($this->args->withPath('bar')); | ||
expect($path)->equal(joinPath(['/foo', 'bar'])); | ||
}); | ||
it('does nothing if path starts with /', function() { | ||
$path = ($this->resolve)($this->args->withPath('/acme')); | ||
expect($path)->equal('/acme'); | ||
}); | ||
xit('applies the prefixes in order until it finds a valid path'); | ||
xit('strips the prefix from absolute paths while finding the proper prefix'); | ||
}); | ||
describe('extResolvePath', function() { | ||
it('appends an extension to the name', function() { | ||
$resolve = stack([extResolvePath('bar'), idResolvePath()]); | ||
$path = $resolve($this->args->withPath('foo')); | ||
expect($path)->equal('foo.bar'); | ||
}); | ||
it('does not append the name if ext already exists', function() { | ||
$resolve = stack([extResolvePath('bar'), idResolvePath()]); | ||
$path = $resolve($this->args->withPath('foo.bar')); | ||
expect($path)->equal('foo.bar'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.