From abb3ff38f5aea6231f981fd2e6d417f09de7a6e6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 7 Nov 2015 16:13:08 +0100 Subject: [PATCH] Add unit tests for the QRCode plugin + coding style --- plugins/qrcode/qrcode.php | 13 +++++-- tests/plugins/PlugQrcodeTest.php | 67 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 tests/plugins/PlugQrcodeTest.php diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 5db40929..1080c964 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -1,11 +1,15 @@ $str, + 'links' => array( + array( + 'url' => $str, + ) + ) + ); + + $data = hook_qrcode_render_linklist($data); + $link = $data['links'][0]; + // data shouldn't be altered + $this->assertEquals($str, $data['title']); + $this->assertEquals($str, $link['url']); + + // plugin data + $this->assertEquals(1, count($link['link_plugin'])); + $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); + } + + /** + * Test render_footer hook. + */ + function testQrcodeFooter() + { + $str = 'stuff'; + $data = array($str => $str); + $data['_PAGE_'] = Router::$PAGE_LINKLIST; + + $data = hook_qrcode_render_footer($data); + $this->assertEquals($str, $data[$str]); + $this->assertEquals(1, count($data['js_files'])); + + $data = array($str => $str); + $data['_PAGE_'] = $str; + $this->assertEquals($str, $data[$str]); + $this->assertArrayNotHasKey('js_files', $data); + } +} -- 2.41.0