summaryrefslogtreecommitdiffstats
path: root/application/test/tests/test_libraries_output_cache.php
blob: 3668bc6b49c5752fc6abb6cb3c8ccd0d4c99bb47 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
 * Copyright 2016 Florian "Bluewind" Pritz <bluewind@server-speed.net>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

namespace test\tests;

class test_libraries_output_cache extends \test\Test {

	public function __construct()
	{
		parent::__construct();
	}

	public function init()
	{
	}

	public function cleanup()
	{
	}

	public function test_add()
	{
		$oc = new \libraries\Output_cache();
		$oc->add("teststring");

		ob_start();
		$oc->render();
		$output = ob_get_clean();

		$this->t->is($output, "teststring", "Simple add renders correctly");
	}

	public function test_add_function()
	{
		$oc = new \libraries\Output_cache();
		$oc->add_function(function() {echo "teststring";});

		ob_start();
		$oc->render();
		$output = ob_get_clean();

		$this->t->is($output, "teststring", "Simple add_function renders correctly");
	}

	public function test_add_merge()
	{

		$oc = new \libraries\Output_cache();
		$oc->add_merge(['items' => ["test1\n"]], 'tests/echo-fragment');
		$oc->add_merge(['items' => ["test2\n"]], 'tests/echo-fragment');

		ob_start();
		$oc->render();
		$output = ob_get_clean();

		$this->t->is($output, "listing 2 items:\ntest1\ntest2\n", "Simple add renders correctly");
	}

	public function test_add_merge_mixedViews()
	{

		$oc = new \libraries\Output_cache();
		$oc->add_merge(['items' => ["test1\n"]], 'tests/echo-fragment');
		$oc->add_merge(['items' => ["test2\n"]], 'tests/echo-fragment');
		$oc->add("blub\n");
		$oc->add_merge(['items' => ["test3\n"]], 'tests/echo-fragment');

		ob_start();
		$oc->render();
		$output = ob_get_clean();

		$this->t->is($output, "listing 2 items:\ntest1\ntest2\nblub\nlisting 1 items:\ntest3\n", "Simple add renders correctly");
	}

}