summaryrefslogtreecommitdiff
path: root/tests/units/Core
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-09-20 15:53:28 -0400
committerFrederic Guillot <fred@kanboard.net>2015-09-20 15:53:28 -0400
commit2021dccc5a444f60c5ba1673d94b39999912cd26 (patch)
tree5d805496f001456baa83c0776a32bdb24511511b /tests/units/Core
parenta0124b45f9dab8a0f7d4879d4ea147b414b25bf2 (diff)
Move subtask forecast to a plugin
Plugin repo: https://github.com/kanboard/plugin-subtask-forecast
Diffstat (limited to 'tests/units/Core')
-rw-r--r--tests/units/Core/Plugin/HookTest.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/units/Core/Plugin/HookTest.php b/tests/units/Core/Plugin/HookTest.php
new file mode 100644
index 00000000..95434ce4
--- /dev/null
+++ b/tests/units/Core/Plugin/HookTest.php
@@ -0,0 +1,62 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Core\Plugin\Hook;
+
+class HookTest extends Base
+{
+ public function testGetListeners()
+ {
+ $h = new Hook;
+ $this->assertEmpty($h->getListeners('myhook'));
+
+ $h->on('myhook', 'A');
+ $h->on('myhook', 'B');
+
+ $this->assertEquals(array('A', 'B'), $h->getListeners('myhook'));
+ }
+
+ public function testMergeWithNoBinding()
+ {
+ $h = new Hook;
+ $values = array('A', 'B');
+
+ $result = $h->merge('myhook', $values, array('p' => 'c'));
+ $this->assertEquals($values, $result);
+ }
+
+ public function testMergeWithBindings()
+ {
+ $h = new Hook;
+ $values = array('A', 'B');
+ $expected = array('A', 'B', 'c', 'D');
+
+ $h->on('myhook', function($p) {
+ return array($p);
+ });
+
+ $h->on('myhook', function() {
+ return array('D');
+ });
+
+ $result = $h->merge('myhook', $values, array('p' => 'c'));
+ $this->assertEquals($expected, $result);
+ $this->assertEquals($expected, $values);
+ }
+
+ public function testMergeWithBindingButReturningBadData()
+ {
+ $h = new Hook;
+ $values = array('A', 'B');
+ $expected = array('A', 'B');
+
+ $h->on('myhook', function() {
+ return 'string';
+ });
+
+ $result = $h->merge('myhook', $values);
+ $this->assertEquals($expected, $result);
+ $this->assertEquals($expected, $values);
+ }
+}