summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-08-20 14:32:39 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-08-20 14:32:39 +0200
commitb7853a87ac0575f83793d5d6a7ed44849156e189 (patch)
treeebebae1295d40f6cdfa77138521691c038e8cc59 /application
parentc9d3f108266a8179f3a4e1ca8b09553e16f2a312 (diff)
Test \libraries\Output_cache
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/test/tests/test_libraries_output_cache.php82
-rw-r--r--application/views/tests/echo-fragment.php5
2 files changed, 87 insertions, 0 deletions
diff --git a/application/test/tests/test_libraries_output_cache.php b/application/test/tests/test_libraries_output_cache.php
new file mode 100644
index 000000000..3668bc6b4
--- /dev/null
+++ b/application/test/tests/test_libraries_output_cache.php
@@ -0,0 +1,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");
+ }
+
+}
+
diff --git a/application/views/tests/echo-fragment.php b/application/views/tests/echo-fragment.php
new file mode 100644
index 000000000..f8c26661f
--- /dev/null
+++ b/application/views/tests/echo-fragment.php
@@ -0,0 +1,5 @@
+<?php
+echo "listing ".count($items)." items:\n";
+foreach ($items as $item) {
+ echo $item;
+}