From 1be98d7b7fea30a929d27e7aa0b1412da3276b2c Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 28 Oct 2017 01:22:59 +0200 Subject: :white_check_mark: Some more work on unit tests. Some small improvements for coverage report. Add more functions from include/text.php Update composer dev libraries for phpunit. --- tests/unit/Access/AccessListTest.php | 4 +++- tests/unit/Access/PermissionsTest.php | 4 ++-- tests/unit/includes/FeedutilsTest.php | 29 +++++++++++++++++++++++++ tests/unit/includes/TextTest.php | 40 ++++++++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/unit/Access/AccessListTest.php b/tests/unit/Access/AccessListTest.php index 3dbe5cd65..dbc19fabb 100644 --- a/tests/unit/Access/AccessListTest.php +++ b/tests/unit/Access/AccessListTest.php @@ -121,7 +121,9 @@ class AccessListTest extends UnitTestCase { /** * set_from_array() calls some other functions, too which are not yet unit tested. - * @uses ::perms2str() + * @uses ::perms2str + * @uses ::sanitise_acl + * @uses ::notags */ public function testSetFromArray() { // array diff --git a/tests/unit/Access/PermissionsTest.php b/tests/unit/Access/PermissionsTest.php index 93c641fb1..73d0e7827 100644 --- a/tests/unit/Access/PermissionsTest.php +++ b/tests/unit/Access/PermissionsTest.php @@ -57,7 +57,7 @@ class PermissionsTest extends UnitTestCase { [], ['perm1' => 0, 'perm2' => 0] ], - 'valild' => [ + 'valid' => [ [['perm1' => 1]], ['perm1' => 1, 'perm2' => 0] ] @@ -145,4 +145,4 @@ class PermissionsTest extends UnitTestCase { ] ]; } -} \ No newline at end of file +} diff --git a/tests/unit/includes/FeedutilsTest.php b/tests/unit/includes/FeedutilsTest.php index d27df4939..e9826a73d 100644 --- a/tests/unit/includes/FeedutilsTest.php +++ b/tests/unit/includes/FeedutilsTest.php @@ -57,4 +57,33 @@ class FeedutilsTest extends UnitTestCase { $this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'nick', 'name', 'uri', 72, 72, 'png', 'http://photourl')); } + + /** + * @uses ::xmlify + */ + public function test_atom_render_author() { + $xchan = [ + 'xchan_addr' => 'chan@hub', + 'xchan_url' => 'http://hub', + 'xchan_name' => 'Chan', + 'xchan_photo_l' => 'http://hub/img', + 'xchan_photo_mimetype' => 'mimetype' + ]; + // There is no input validation in atom_render_author + //$this->assertEquals('', atom_render_author('', $xchan)); + + $a = ' + http://activitystrea.ms/schema/1.0/person + http://hub + chan + http://hub + + + + chan + Chan +'; + + $this->assertXmlStringEqualsXmlString($a, atom_render_author('tag', $xchan)); + } } diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index acc490001..97fa64895 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -5,7 +5,7 @@ namespace Zotlabs\Tests\Unit\includes; use Zotlabs\Tests\Unit\UnitTestCase; /** - * @brief Unit Test case for include/texter.php file. + * @brief Unit Test case for include/text.php file. * * @author ken restivo */ @@ -79,4 +79,42 @@ empty line above'; $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); } + /** + * @dataProvider notagsProvider + */ + public function testNotags($string, $expected) { + $this->assertEquals($expected, notags($string)); + } + public function notagsProvider() { + return [ + 'empty string' => ['', ''], + 'simple tag' => ['', '[value]'], + 'tag pair' => ['text', '[b]text[/b]'], + 'double angle bracket' => ['< ['>', '>'] + ]; + } + + /** + * @dataProvider sanitise_aclProvider + */ + public function testSanitise_acl($string, $expected) { + sanitise_acl($string); + $this->assertEquals($expected, $string); + } + public function sanitise_aclProvider() { + return [ + 'text' => ['value', ''], + 'text with angle bracket' => ['', '<[value]>'], + 'comma separated acls' => ['value1,value2', ''] + ]; + } + + public function testUnsetSanitise_acl() { + $empty = ''; + sanitise_acl($empty); + $this->assertTrue(isset($empty)); // unset() not working? Would expect false + $this->assertEmpty($empty); + } + } -- cgit v1.2.3