forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-sidebar.php
31 lines (29 loc) · 1.1 KB
/
test-timber-sidebar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* @group called-post-constructor
*/
class TestTimberSidebar extends Timber_UnitTestCase
{
public function testTwigSidebar()
{
$context = Timber::context();
$sidebar_post = $this->factory->post->create([
'post_title' => 'Sidebar post content',
]);
$sidebar_context = [];
$sidebar_context['post'] = Timber::get_post($sidebar_post);
$context['sidebar'] = Timber::get_sidebar('assets/sidebar.twig', $sidebar_context);
$result = Timber::compile('assets/main-w-sidebar.twig', $context);
$this->assertEquals('I am the main stuff <h4>Sidebar post content</h4>', trim($result));
}
public function testPHPSidebar()
{
add_filter('timber/context', function ($context) {
$context['sidebar'] = Timber::get_sidebar('assets/my-sidebar.php');
return $context;
});
$context = Timber::context();
$result = Timber::compile('assets/main-w-sidebar-php.twig', $context);
$this->assertEquals("A Fever You Can't Sweat Out by Panic! at the Disco from 2005", trim($result));
}
}