From a23be70d68299d62ff9fa1aecd2a7689beaee1c2 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 4 Jul 2022 06:34:46 +1000 Subject: [PATCH] fix/reset unit tests --- tests/unit/Access/AccessListTest.php | 201 ----------- tests/unit/Access/PermissionLimitsTest.php | 80 ----- tests/unit/Access/PermissionRolesTest.php | 105 ------ tests/unit/Access/PermissionsTest.php | 336 ------------------- tests/unit/DatabaseTestCase.php | 74 ---- tests/unit/Lib/MarkdownTest.php | 150 --------- tests/unit/Lib/PermissionDescriptionTest.php | 102 ------ tests/unit/Web/HttpSigTest.php | 71 +--- tests/unit/includes/LanguageTest.php | 174 ---------- tests/unit/includes/TextTest.php | 8 +- tests/unit/includes/dba/DBATest.php | 71 ---- tests/unit/includes/dba/_files/account.yml | 9 - tests/unit/includes/dba/dba_pdoTest.php | 212 ------------ 13 files changed, 11 insertions(+), 1582 deletions(-) delete mode 100644 tests/unit/Access/AccessListTest.php delete mode 100644 tests/unit/Access/PermissionLimitsTest.php delete mode 100644 tests/unit/Access/PermissionRolesTest.php delete mode 100644 tests/unit/Access/PermissionsTest.php delete mode 100644 tests/unit/DatabaseTestCase.php delete mode 100644 tests/unit/Lib/MarkdownTest.php delete mode 100644 tests/unit/Lib/PermissionDescriptionTest.php delete mode 100644 tests/unit/includes/LanguageTest.php delete mode 100644 tests/unit/includes/dba/DBATest.php delete mode 100644 tests/unit/includes/dba/_files/account.yml delete mode 100644 tests/unit/includes/dba/dba_pdoTest.php diff --git a/tests/unit/Access/AccessListTest.php b/tests/unit/Access/AccessListTest.php deleted file mode 100644 index 6a61eb2d2..000000000 --- a/tests/unit/Access/AccessListTest.php +++ /dev/null @@ -1,201 +0,0 @@ - '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '' - ]; - - - - public function testConstructor() - { - $channel = [ - 'channel_allow_cid' => '', - 'channel_allow_gid' => '', - 'channel_deny_cid' => '', - 'channel_deny_gid' => '' - ]; - - $accessList = new AccessControl($channel); - - $this->assertEquals($this->expectedResult, $accessList->get()); - $this->assertFalse($accessList->get_explicit()); - } - - /** - * @expectedException PHPUnit\Framework\Error\Error - */ - public function testPHPErrorOnInvalidConstructor() - { - $accessList = new AccessControl('invalid'); - // Causes: "Illegal string offset 'channel_allow_cid'" - } - - public function testDefaultGetExplicit() - { - $accessList = new AccessControl([]); - - $this->assertFalse($accessList->get_explicit()); - } - - public function testDefaultGet() - { - $arr = [ - 'allow_cid' => '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '' - ]; - - $accessList = new AccessControl([]); - - $this->assertEquals($arr, $accessList->get()); - } - - public function testSet() - { - $arr = [ - 'allow_cid' => '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '' - ]; - $accessList = new AccessControl([]); - - // default explicit true - $accessList->set($arr); - - $this->assertEquals($this->expectedResult, $accessList->get()); - $this->assertTrue($accessList->get_explicit()); - - // set explicit false - $accessList->set($arr, false); - - $this->assertEquals($this->expectedResult, $accessList->get()); - $this->assertFalse($accessList->get_explicit()); - } - - /** - * @expectedException PHPUnit\Framework\Error\Error - */ - public function testPHPErrorOnInvalidSet() - { - $accessList = new AccessControl([]); - - $accessList->set('invalid'); - // Causes: "Illegal string offset 'allow_cid'" - } - - /** - * set_from_[] calls some other functions, too which are not yet unit tested. - * @uses ::perms2str - * @uses ::sanitise_acl - * @uses ::notags - */ - public function testSetFromArray() - { - // array - $arraySetFromArray = [ - 'contact_allow' => ['acid', 'acid2'], - 'group_allow' => ['agid'], - 'contact_deny' => [], - 'group_deny' => ['dgid', 'dgid2'] - ]; - $accessList = new AccessControl([]); - $accessList->set_from_array($arraySetFromArray); - - $this->assertEquals($this->expectedResult, $accessList->get()); - $this->assertTrue($accessList->get_explicit()); - - - // string - $stringSetFromArray = [ - 'contact_allow' => 'acid,acid2', - 'group_allow' => 'agid', - 'contact_deny' => '', - 'group_deny' => 'dgid, dgid2' - ]; - $accessList2 = new AccessControl([]); - $accessList2->set_from_array($stringSetFromArray, false); - - $this->assertEquals($this->expectedResult, $accessList2->get()); - $this->assertFalse($accessList2->get_explicit()); - } - - /** - * @dataProvider isprivateProvider - */ - public function testIsPrivate($channel) - { - $accessListPublic = new AccessControl([]); - $this->assertFalse($accessListPublic->is_private()); - - $accessListPrivate = new AccessControl($channel); - $this->assertTrue($accessListPrivate->is_private()); - } - - public function isprivateProvider() - { - return [ - 'all set' => [[ - 'channel_allow_cid' => '', - 'channel_allow_gid' => '', - 'channel_deny_cid' => '', - 'channel_deny_gid' => '' - ]], - 'only one set' => [[ - 'channel_allow_cid' => '', - 'channel_allow_gid' => '', - 'channel_deny_cid' => '', - 'channel_deny_gid' => '' - ]], - 'acid+null' => [[ - 'channel_allow_cid' => '', - 'channel_allow_gid' => null, - 'channel_deny_cid' => '', - 'channel_deny_gid' => '' - ]] - ]; - } -} diff --git a/tests/unit/Access/PermissionLimitsTest.php b/tests/unit/Access/PermissionLimitsTest.php deleted file mode 100644 index 7266b6c2d..000000000 --- a/tests/unit/Access/PermissionLimitsTest.php +++ /dev/null @@ -1,80 +0,0 @@ -getFunctionMock('Code\Access', 't'); - $t->expects($this->exactly($permsCount)); - - $stdlimits = PermissionLimits::Std_Limits(); - $this->assertCount($permsCount, $stdlimits, "There should be $permsCount permissions."); - - $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_stream']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['send_stream']); - $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_profile']); - $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_contacts']); - $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_storage']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['write_storage']); - $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_pages']); - $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_wiki']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['write_pages']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['write_wiki']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_wall']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_comments']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_mail']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_like']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['tag_deliver']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['chat']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['republish']); - $this->assertEquals(PERMS_SPECIFIC, $stdlimits['delegate']); - } -} diff --git a/tests/unit/Access/PermissionRolesTest.php b/tests/unit/Access/PermissionRolesTest.php deleted file mode 100644 index 19f8f9da0..000000000 --- a/tests/unit/Access/PermissionRolesTest.php +++ /dev/null @@ -1,105 +0,0 @@ -assertEquals($expectedVersion, PermissionRoles::version()); - - $pr = new PermissionRoles(); - $this->assertEquals($expectedVersion, $pr->version()); - } - - - public function testRoles() - { - // Create a stub for global function t() with expectation - $t = $this->getFunctionMock('Code\Access', 't'); - $t->expects($this->atLeastOnce())->willReturnCallback( - function ($string) { - return $string; - } - ); - - $roles = PermissionRoles::roles(); - $r = new PermissionRoles(); - $this->assertEquals($roles, $r->roles()); - - $socialNetworking = [ - 'social_federation' => 'Social - Federation', - 'social' => 'Social - Mostly Public', - 'social_restricted' => 'Social - Restricted', - 'social_private' => 'Social - Private' - ]; - - $this->assertArraySubset(['Social Networking' => $socialNetworking], $roles); - $this->assertEquals($socialNetworking, $roles['Social Networking']); - - $this->assertCount(5, $roles, 'There should be 5 permission groups.'); - - $this->assertCount(1, $roles['Other'], "In the 'Other' group should be just one permission role"); - } - - - /** - * @uses ::Hook::call - * @uses Code\Access\PermissionLimits::Std_Limits - * @uses Code\Access\Permissions::Perms - */ - public function testRole_perms() - { - // Create a stub for global function t() - $t = $this->getFunctionMock('Code\Access', 't'); - $t = $this->getFunctionMock('Code\Access', 'get_config'); - - $rp_social = PermissionRoles::role_perms('social'); - $this->assertEquals('social', $rp_social['role']); - - - $rp_custom = PermissionRoles::role_perms('custom'); - $this->assertEquals(['role' => 'custom'], $rp_custom); - - $rp_nonexistent = PermissionRoles::role_perms('nonexistent'); - $this->assertEquals(['role' => 'nonexistent'], $rp_nonexistent); - } -} diff --git a/tests/unit/Access/PermissionsTest.php b/tests/unit/Access/PermissionsTest.php deleted file mode 100644 index bb947aa9b..000000000 --- a/tests/unit/Access/PermissionsTest.php +++ /dev/null @@ -1,336 +0,0 @@ -assertEquals($expectedVersion, Permissions::version()); - - // instance call - $p = new Permissions(); - $this->assertEquals($expectedVersion, $p->version()); - } - - /** - * @coversNothing - */ - public function testVersionEqualsPermissionRoles() - { - $p = new Permissions(); - $pr = new PermissionRoles(); - $this->assertEquals($p->version(), $pr->version()); - } - - /** - * @uses ::Hook::call - */ - public function testPerms() - { - // There are 18 default perms - $permsCount = 18; - - // Create a stub for global function t() with expectation - $t = $this->getFunctionMock('Code\Access', 't'); - $t->expects($this->exactly(2 * $permsCount))->willReturnCallback( - function ($string) { - return $string; - } - ); - - // static method Perms() - $perms = Permissions::Perms(); - - $p = new Permissions(); - $this->assertEquals($perms, $p->Perms()); - - $this->assertEquals($permsCount, count($perms), "There should be $permsCount permissions."); - - $this->assertEquals('Can view my channel stream and posts', $perms['view_stream']); - - // non existent perm should not be set - $this->assertFalse(isset($perms['invalid_perm'])); - } - - /** - * filter parmeter is only used in hook \b permissions_list. So the result - * in this test should be the same as if there was no filter parameter. - * - * @todo Stub Hook::call() function and also test filter - * - * @uses ::Hook::call - */ - public function testPermsFilter() - { - // There are 18 default perms - $permsCount = 18; - - // Create a stub for global function t() with expectation - $t = $this->getFunctionMock('Code\Access', 't'); - $t->expects($this->exactly(2 * $permsCount))->willReturnCallback( - function ($string) { - return $string; - } - ); - - $perms = Permissions::Perms('view_'); - $this->assertEquals($permsCount, count($perms)); - - $this->assertEquals('Can view my channel stream and posts', $perms['view_stream']); - - $perms = Permissions::Perms('invalid_perm'); - $this->assertEquals($permsCount, count($perms)); - } - - /** - * Better should mock Permissions::Perms, but not possible with static methods. - * - * @uses ::Hook::call - * - * @dataProvider FilledPermsProvider - * - * @param array $permarr An indexed permissions array to pass - * @param array $expected The expected result perms array - */ - public function testFilledPerms($permarr, $expected) - { - // Create a stub for global function t() - $t = $this->getFunctionMock('Code\Access', 't'); - - $this->assertEquals($expected, Permissions::FilledPerms($permarr)); - } - /** - * @return array An associative array with test values for FilledPerms() - * * \e array Indexed array which is passed as parameter to FilledPerms() - * * \e array Expected associative result array with filled perms - */ - public function FilledPermsProvider() - { - return [ - 'Empty param array' => [ - [], - [ - 'view_stream' => 0, - 'send_stream' => 0, - 'view_profile' => 0, - 'view_contacts' => 0, - 'view_storage' => 0, - 'write_storage' => 0, - 'view_pages' => 0, - 'view_wiki' => 0, - 'write_pages' => 0, - 'write_wiki' => 0, - 'post_wall' => 0, - 'post_comments' => 0, - 'post_mail' => 0, - 'post_like' => 0, - 'tag_deliver' => 0, - 'chat' => 0, - 'republish' => 0, - 'delegate' => 0 - ] - ], - 'provide view_stream and view_pages as param' => [ - ['view_stream', 'view_pages'], - [ - 'view_stream' => 1, - 'send_stream' => 0, - 'view_profile' => 0, - 'view_contacts' => 0, - 'view_storage' => 0, - 'write_storage' => 0, - 'view_pages' => 1, - 'view_wiki' => 0, - 'write_pages' => 0, - 'write_wiki' => 0, - 'post_wall' => 0, - 'post_comments' => 0, - 'post_mail' => 0, - 'post_like' => 0, - 'tag_deliver' => 0, - 'chat' => 0, - 'republish' => 0, - 'delegate' => 0 - ] - ], - 'provide an unknown param' => [ - ['view_stream', 'unknown_perm'], - [ - 'view_stream' => 1, - 'send_stream' => 0, - 'view_profile' => 0, - 'view_contacts' => 0, - 'view_storage' => 0, - 'write_storage' => 0, - 'view_pages' => 0, - 'view_wiki' => 0, - 'write_pages' => 0, - 'write_wiki' => 0, - 'post_wall' => 0, - 'post_comments' => 0, - 'post_mail' => 0, - 'post_like' => 0, - 'tag_deliver' => 0, - 'chat' => 0, - 'republish' => 0, - 'delegate' => 0 - ] - ] - ]; - } - /** - * @uses ::Hook::call - */ - public function testFilledPermsNull() - { - // Create a stub for global function t() with expectation - $t = $this->getFunctionMock('Code\Access', 't'); - $t->expects($this->atLeastOnce()); - // Create a stub for global function bt() with expectations - $bt = $this->getFunctionMock('Code\Access', 'btlogger'); - $bt->expects($this->once())->with($this->equalTo('FilledPerms: null')); - - $result = [ - 'view_stream' => 0, - 'send_stream' => 0, - 'view_profile' => 0, - 'view_contacts' => 0, - 'view_storage' => 0, - 'write_storage' => 0, - 'view_pages' => 0, - 'view_wiki' => 0, - 'write_pages' => 0, - 'write_wiki' => 0, - 'post_wall' => 0, - 'post_comments' => 0, - 'post_mail' => 0, - 'post_like' => 0, - 'tag_deliver' => 0, - 'chat' => 0, - 'republish' => 0, - 'delegate' => 0 - ]; - - $this->assertEquals($result, Permissions::FilledPerms(null)); - } - - /** - * @dataProvider OPermsProvider - * - * @param array $permarr The params to pass to the OPerms method - * @param array $expected The expected result - */ - public function testOPerms($permarr, $expected) - { - $this->assertEquals($expected, Permissions::OPerms($permarr)); - } - /** - * @return array An associative array with test values for OPerms() - * * \e array Array with perms to test - * * \e array Expected result array - */ - public function OPermsProvider() - { - return [ - 'empty' => [ - [], - [] - ], - 'valid' => [ - ['perm1' => 1, 'perm2' => 0], - [['name' => 'perm1', 'value' => 1], ['name' => 'perm2', 'value' => 0]] - ], - 'null array' => [ - null, - [] - ] - ]; - } - - /** - * @dataProvider permsCompareProvider - * - * @param array $p1 The first permission - * @param array $p2 The second permission - * @param bool $expectedresult The expected result of the tested method - */ - public function testPermsCompare($p1, $p2, $expectedresult) - { - $this->assertEquals($expectedresult, Permissions::PermsCompare($p1, $p2)); - } - /** - * @return array An associative array with test values for PermsCompare() - * * \e array 1st array with perms - * * \e array 2nd array with perms - * * \e boolean expected result for the perms comparison - */ - public function permsCompareProvider() - { - return [ - 'equal' => [ - ['perm1' => 1, 'perm2' => 0], - ['perm1' => 1, 'perm2' => 0], - true - ], - 'different values' => [ - ['perm1' => 1, 'perm2' => 0], - ['perm1' => 0, 'perm2' => 1], - false - ], - 'different order' => [ - ['perm1' => 1, 'perm2' => 0], - ['perm2' => 0, 'perm1' => 1], - true - ], - 'partial first in second' => [ - ['perm1' => 1], - ['perm1' => 1, 'perm2' => 0], - true - ], - 'partial second in first' => [ - ['perm1' => 1, 'perm2' => 0], - ['perm1' => 1], - false - ] - ]; - } -} diff --git a/tests/unit/DatabaseTestCase.php b/tests/unit/DatabaseTestCase.php deleted file mode 100644 index 84f3ac0e3..000000000 --- a/tests/unit/DatabaseTestCase.php +++ /dev/null @@ -1,74 +0,0 @@ -conn === null) { - if (self::$pdo === null) { - $dsn = getenv('hz_db_scheme') . ':host=' . getenv('hz_db_server') - . ';port=' . getenv('hz_db_port') . ';dbname=' . getenv('hz_db_database'); - - self::$pdo = new PDO($dsn, getenv('hz_db_user'), getenv('hz_db_pass')); - } - $this->conn = $this->createDefaultDBConnection(self::$pdo, getenv('hz_db_database')); - } - - return $this->conn; - } -} diff --git a/tests/unit/Lib/MarkdownTest.php b/tests/unit/Lib/MarkdownTest.php deleted file mode 100644 index 40e3e404e..000000000 --- a/tests/unit/Lib/MarkdownTest.php +++ /dev/null @@ -1,150 +0,0 @@ -assertEquals($markdown, Markdown::from_html($html)); - } - - public function html2markdownProvider() - { - return [ - 'empty text' => [ - '', - '' - ], - 'space and nbsp only' => [ - '  ', - '' - ], - - 'strong, b, em, i, bib' => [ - 'strong bold em italic boitalicld', - '**strong** **bold** *em* *italic* **bo*italic*ld**' - ], - - 'empty tags' => [ - 'text1 text2 ', - 'text1 text2' - ], - 'HTML entities, lt does not work' => [ - '& gt > lt <', - '& gt > lt' - ], - 'escaped HTML entities' => [ - '& lt < gt >', - '& lt < gt >' - ], - 'linebreak' => [ - "line1
line2\nline3", - "line1 \nline2 line3" - ], - 'headlines' => [ - '

header1

Header 3

', - "header1\n=======\n\n### Header 3" - ], - 'unordered list' => [ - '
  • Item 1
  • Item 2
  • Item 3
', - "- Item 1\n- Item 2\n- Item **3**" - ], - 'ordered list' => [ - '
  1. Item 1
  2. Item 2
  3. Item 3
', - "1. Item 1\n2. Item 2\n3. Item **3**" - ], - 'nested lists' => [ - '
  • Item 1
    1. Item 1a
    2. Item 1b
  • Item 2
', - "- Item 1\n 1. Item 1a\n 2. Item **1b**\n- Item 2" - ], - 'img' => [ - 'alt text', - '![alt text](/path/to/img.png "title text")' - ], - 'link' => [ - 'link', - '[link](http://hubzilla.org "Hubzilla")' - ], - 'img link' => [ - 'alt img text', - '[![alt img text](/img/hubzilla.png "img title")](http://hubzilla.org "Hubzilla")' - ], - 'script' => [ - "", - "" - ], - 'blockquote, issue #793' => [ - '
something
blah', - "> something\n\nblah" - ], - 'code' => [ - '<p>HTML text</p>', - '`

HTML text

`' - ], - 'pre' => [ - '
  one line with spaces  
', - "```\n one line with spaces \n```" - ], - 'div p' => [ - '
div

p

', - "
div
p\n\n
" - ] - ]; - } - - /*public function testHtml2markdownException() { - //$this->expectException(\InvalidArgumentException::class); - // need to stub logger() for this to work - $this->assertEquals('', Markdown::from_html('<getFunctionMock(__NAMESPACE__, "bbcode"); - $bbc->expects($this->once())->willReturn('testbold
i
  • li1
  • li2

'); - - $this->assertEquals($bb1, Markdown::from_bbcode($html1)); - } -*/ -} diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php deleted file mode 100644 index 91efc6f30..000000000 --- a/tests/unit/Lib/PermissionDescriptionTest.php +++ /dev/null @@ -1,102 +0,0 @@ -assertEquals($permDesc, $permDesc2); - $this->assertNotEquals($permDesc, $permDesc3); - } - - public function testFromStandalonePermission() - { - // Create a stub for global function t() - $t = $this->getFunctionMock('Code\Lib', 't'); - $t->expects($this->atLeastOnce())->willReturnCallback( - function ($string) { - return $string; - } - ); - // Create a mock for global function logger() - $this->getFunctionMock('Code\Lib', 'logger'); - - $permDescUnknown = PermissionDescription::fromStandalonePermission(-1); - $permDescSelf = PermissionDescription::fromStandalonePermission(0); - - $this->assertNull($permDescUnknown); - $this->assertNotNull($permDescSelf); - } - - public function testFromGlobalPermission() - { - //$permDesc = PermissionDescription::fromGlobalPermission('view_profile'); - - $this->markTestIncomplete( - 'The method fromGlobalPermission() is not yet testable ...' - ); - } - - public function testGetPermissionDescription() - { - // Create a stub for global function t() - $t = $this->getFunctionMock('Code\Lib', 't'); - $t->expects($this->atLeastOnce())->willReturnCallback( - function ($string) { - return $string; - } - ); - // Create a mock for global function logger() - $this->getFunctionMock('Code\Lib', 'logger'); - - // Create a stub for the PermissionDescription class - $stub = $this->createMock(PermissionDescription::class); - $stub->method('get_permission_description') - ->will($this->returnArgument(0)); - - $permDescSelf = PermissionDescription::fromStandalonePermission(0); - $this->assertInstanceOf(PermissionDescription::class, $permDescSelf); - $this->assertEquals($permDescSelf->get_permission_description(), 'Only me'); - - $permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC); - $this->assertEquals($permDescPublic->get_permission_description(), 'Public'); - } -} diff --git a/tests/unit/Web/HttpSigTest.php b/tests/unit/Web/HttpSigTest.php index 5b1e3a99e..41ef06341 100644 --- a/tests/unit/Web/HttpSigTest.php +++ b/tests/unit/Web/HttpSigTest.php @@ -33,7 +33,7 @@ use Code\Web\HTTPSig; * * @covers Code\Web\HTTPSig */ -class PermissionDescriptionTest extends UnitTestCase +class HttpSigTest extends UnitTestCase { use PHPMock; @@ -45,7 +45,7 @@ class PermissionDescriptionTest extends UnitTestCase { $this->assertSame( $digest, - HTTPSig::generate_digest($text, false) + HTTPSig::generate_digest_header($text, 'sha256') ); } @@ -54,15 +54,15 @@ class PermissionDescriptionTest extends UnitTestCase return [ 'empty body text' => [ '', - '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' + 'SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' ], 'sample body text' => [ 'body text', - '2fu8kUkvuzuo5XyhWwORNOcJgDColXgxWkw1T5EXzPI=' + 'SHA-256=2fu8kUkvuzuo5XyhWwORNOcJgDColXgxWkw1T5EXzPI=' ], 'NULL body text' => [ null, - '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' + 'SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' ], ]; } @@ -70,67 +70,10 @@ class PermissionDescriptionTest extends UnitTestCase public function testGeneratedDigestsOfDifferentTextShouldNotBeEqual() { $this->assertNotSame( - HTTPSig::generate_digest('text1', false), - HTTPSig::generate_digest('text2', false) + HTTPSig::generate_digest_header('text1'), + HTTPSig::generate_digest_header('text2') ); } - /** - * Process separation needed for header() check. - * @runInSeparateProcess - */ - public function testGenerate_digestSendsHttpHeader() - { - $ret = HTTPSig::generate_digest('body text', true); - $this->assertSame('2fu8kUkvuzuo5XyhWwORNOcJgDColXgxWkw1T5EXzPI=', $ret); - $this->assertContains( - 'Digest: SHA-256=2fu8kUkvuzuo5XyhWwORNOcJgDColXgxWkw1T5EXzPI=', - xdebug_get_headers(), - 'HTTP header Digest does not match' - ); - } - - /** - * @uses ::crypto_unencapsulate - */ - public function testDecrypt_sigheader() - { - $header = 'Header: iv="value_iv" key="value_key" alg="value_alg" data="value_data"'; - $result = [ - 'iv' => 'value_iv', - 'key' => 'value_key', - 'alg' => 'value_alg', - 'data' => 'value_data' - ]; - - $this->assertSame($result, HTTPSig::decrypt_sigheader($header, 'site private key')); - } - - /** - * @uses ::crypto_unencapsulate - */ - public function testDecrypt_sigheaderUseSitePrivateKey() - { - // Create a stub for global function get_config() with expectation - $t = $this->getFunctionMock('Code\Web', 'get_config'); - $t->expects($this->once())->willReturn('system.prvkey'); - - $header = 'Header: iv="value_iv" key="value_key" alg="value_alg" data="value_data"'; - $result = [ - 'iv' => 'value_iv', - 'key' => 'value_key', - 'alg' => 'value_alg', - 'data' => 'value_data' - ]; - - $this->assertSame($result, HTTPSig::decrypt_sigheader($header)); - } - - public function testDecrypt_sigheaderIncompleteHeaderShouldReturnEmptyString() - { - $header = 'Header: iv="value_iv" key="value_key"'; - - $this->assertEmpty(HTTPSig::decrypt_sigheader($header, 'site private key')); - } } diff --git a/tests/unit/includes/LanguageTest.php b/tests/unit/includes/LanguageTest.php deleted file mode 100644 index 02c33b60b..000000000 --- a/tests/unit/includes/LanguageTest.php +++ /dev/null @@ -1,174 +0,0 @@ -getFunctionMock(__NAMESPACE__, 'get_config'); - //$gc->expects($this->once())->willReturn(10) - //$cg = $this->getFunctionMock('Code\Lib\Config', 'Get'); - //$cg->expects($this->once())->willReturn(10); - //$this->assertEquals($langCode, detect_language($text)); - - - // Can not unit test detect_language(), therefore test the used library - // only for now to find regressions on library updates. - $l = new Text_LanguageDetect(); - // return 2-letter ISO 639-1 (en) language code - $l->setNameMode(2); - $lng = $l->detectConfidence($text); - - $this->assertEquals($langCode, $lng['language']); - $this->assertEquals($confidence, round($lng['confidence'], 6)); - } - - public function languageExamplesProvider() - { - return [ - 'empty text' => [ - '', - '', - null - ], - 'English' => [ - 'English is a West Germanic language that was first spoken in early medieval England and is now a global lingua franca.[4][5] Named after the Angles, one of the Germanic tribes that migrated to England, it ultimately derives its name from the Anglia (Angeln) peninsula in the Baltic Sea. It is closely related to the Frisian languages, but its vocabulary has been significantly influenced by other Germanic languages, particularly Norse (a North Germanic language), as well as by Latin and Romance languages, especially French.', - 'en', - 0.078422 - ], - 'German' => [ - 'Deutschland ist ein Bundesstaat in Mitteleuropa. Er besteht aus 16 Ländern und ist als freiheitlich-demokratischer und sozialer Rechtsstaat verfasst. Die Bundesrepublik Deutschland stellt die jüngste Ausprägung des deutschen Nationalstaates dar. Mit rund 82,8 Millionen Einwohnern (31. Dezember 2016) zählt Deutschland zu den dicht besiedelten Flächenstaaten.', - 'de', - 0.134339 - ], - 'Norwegian' => [ - 'Kongeriket Norge er et nordisk, europeisk land og en selvstendig stat vest på Den skandinaviske halvøy. Landet er langt og smalt, og kysten strekker seg langs Nord-Atlanteren, hvor også Norges kjente fjorder befinner seg. Totalt dekker det relativt tynt befolkede landet 385 000 kvadratkilometer med litt over fem millioner innbyggere (2016).', - 'no', - 0.007076 - ] - ]; - } - - - /** - * @covers ::get_language_name - * @dataProvider getLanguageNameProvider - */ - public function testGetLanguageName($lang, $name, $trans) - { - $this->assertEquals($name, get_language_name($lang)); - foreach ($trans as $k => $v) { - //echo "$k -> $v"; - $this->assertEquals($v, get_language_name($lang, $k)); - } - } - - public function getLanguageNameProvider() - { - return [ - 'empty language code' => [ - '', - '', - ['de' => ''] - ], - 'invalid language code' => [ - 'zz', - 'zz', - ['de' => 'zz'] - ], - 'de' => [ - 'de', - 'German', - [ - 'de' => 'Deutsch', - 'nb' => 'tysk' - ] - ], - 'de-de' => [ - 'de-de', - 'German', - [ - 'de-de' => 'Deutsch', - 'nb' => 'Deutsch' // should be tysk, seems to be a bug upstream - ] - ], - 'en' => [ - 'en', - 'English', - [ - 'de' => 'Englisch', - 'nb' => 'engelsk' - ] - ], - 'en-gb' => [ - 'en-gb', - 'British English', - [ - 'de' => 'Britisches Englisch', - 'nb' => 'engelsk (Storbritannia)' - ] - ], - 'en-au' => [ - 'en-au', - 'Australian English', - [ - 'de' => 'Australisches Englisch', - 'nb' => 'engelsk (Australia)' - ] - ], - 'nb' => [ - 'nb', - 'Norwegian Bokmål', - [ - 'de' => 'Norwegisch Bokmål', - 'nb' => 'norsk bokmål' - ] - ] - ]; - } -} diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index 826e65e53..a66cf25e6 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -76,12 +76,12 @@ empty line above'; // test our own CSS configuration $this->assertEquals('
position removed
', purify_html('
position removed
')); - $this->assertEquals('
position preserved
', purify_html('
position preserved
', true)); - $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); + $this->assertEquals('
position preserved
', purify_html('
position preserved
', ['allow_position'])); + $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', ['allow_position'])); $this->assertEquals('
position removed
', purify_html('
position removed
')); - $this->assertEquals('
position preserved
', purify_html('
position preserved
', true)); - $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); + $this->assertEquals('
position preserved
', purify_html('
position preserved
', ['allow_position'])); + $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', ['allow_position'])); } /** diff --git a/tests/unit/includes/dba/DBATest.php b/tests/unit/includes/dba/DBATest.php deleted file mode 100644 index 1bcb36e93..000000000 --- a/tests/unit/includes/dba/DBATest.php +++ /dev/null @@ -1,71 +0,0 @@ -assertNull(DBA::$dba); - - $ret = DBA::dba_factory('server', 'port', 'user', 'pass', 'db', '0'); - $this->assertInstanceOf('dba_pdo', $ret); - $this->assertFalse($ret->connected); - - $this->assertSame('mysql', DBA::$scheme); - $this->assertSame('schema_mysql.sql', DBA::$install_script); - $this->assertSame('0001-01-01 00:00:00', DBA::$null_date); - $this->assertSame('UTC_TIMESTAMP()', DBA::$utc_now); - $this->assertSame('`', DBA::$tquot); - } - - public function testDbaFactoryPostgresql() - { - $this->assertNull(DBA::$dba); - - $ret = DBA::dba_factory('server', 'port', 'user', 'pass', 'db', '1'); - $this->assertInstanceOf('dba_pdo', $ret); - $this->assertFalse($ret->connected); - - $this->assertSame('pgsql', DBA::$scheme); - $this->assertSame('schema_postgres.sql', DBA::$install_script); - $this->assertSame('0001-01-01 00:00:00', DBA::$null_date); - $this->assertSame("now() at time zone 'UTC'", DBA::$utc_now); - $this->assertSame('"', DBA::$tquot); - } -} diff --git a/tests/unit/includes/dba/_files/account.yml b/tests/unit/includes/dba/_files/account.yml deleted file mode 100644 index 344bdb799..000000000 --- a/tests/unit/includes/dba/_files/account.yml +++ /dev/null @@ -1,9 +0,0 @@ -account: - - - account_id: 42 - account_email: "hubzilla@example.com" - account_language: "no" - - - account_id: 43 - account_email: "hubzilla@example.org" - account_language: "de" diff --git a/tests/unit/includes/dba/dba_pdoTest.php b/tests/unit/includes/dba/dba_pdoTest.php deleted file mode 100644 index 446e48d98..000000000 --- a/tests/unit/includes/dba/dba_pdoTest.php +++ /dev/null @@ -1,212 +0,0 @@ -dba = new dba_pdo( - getenv('hz_db_server'), - getenv('hz_db_scheme'), - getenv('hz_db_port'), - getenv('hz_db_user'), - getenv('hz_db_pass'), - getenv('hz_db_database') - ); - } - protected function assertPreConditions() - { - $this->assertSame('pdo', $this->dba->getdriver(), "Driver is expected to be 'pdo'."); - $this->assertInstanceOf('dba_driver', $this->dba); - $this->assertTrue($this->dba->connected, 'Pre condition failed, DB is not connected.'); - $this->assertInstanceOf('PDO', $this->dba->db); - } - protected function tearDown() - { - $this->dba = null; - } - - - /** - * @group mysql - */ - public function testQuoteintervalOnMysql() - { - $this->assertSame('value', $this->dba->quote_interval('value')); - } - /** - * @group postgresql - */ - public function testQuoteintervalOnPostgresql() - { - $this->assertSame("'value'", $this->dba->quote_interval('value')); - } - - /** - * @group mysql - */ - public function testGenerateMysqlConcatSql() - { - $this->assertSame('GROUP_CONCAT(DISTINCT field SEPARATOR \';\')', $this->dba->concat('field', ';')); - $this->assertSame('GROUP_CONCAT(DISTINCT field2 SEPARATOR \' \')', $this->dba->concat('field2', ' ')); - } - /** - * @group postgresql - */ - public function testGeneratePostgresqlConcatSql() - { - $this->assertSame('string_agg(field,\';\')', $this->dba->concat('field', ';')); - $this->assertSame('string_agg(field2,\' \')', $this->dba->concat('field2', ' ')); - } - - - public function testConnectToSqlServer() - { - // connect() is done in dba_pdo constructor which is called in setUp() - $this->assertTrue($this->dba->connected); - } - - /** - * @depends testConnectToSqlServer - */ - public function testCloseSqlServerConnection() - { - $this->dba->close(); - - $this->assertNull($this->dba->db); - $this->assertFalse($this->dba->connected); - } - - /** - * @depends testConnectToSqlServer - */ - public function testSelectQueryShouldReturnArray() - { - $ret = $this->dba->q('SELECT * FROM account'); - - $this->assertTrue(is_array($ret)); - } - - /** - * @depends testConnectToSqlServer - */ - public function testInsertQueryShouldReturnPdostatement() - { - // Fixture account.yml adds two entries to account table - $this->assertEquals(2, $this->getConnection()->getRowCount('account'), 'Pre-Condition'); - - $ret = $this->dba->q('INSERT INTO account - (account_id, account_email, account_language) - VALUES (100, \'insert@example.com\', \'de\') - '); - $this->assertInstanceOf('PDOStatement', $ret); - - $this->assertEquals(3, $this->getConnection()->getRowCount('account'), 'Inserting failed'); - } - - - public function testConnectToWrongSqlServer() - { - $nodba = new dba_pdo( - 'wrongserver', - getenv('hz_db_scheme'), - getenv('hz_db_port'), - getenv('hz_db_user'), - getenv('hz_db_pass'), - getenv('hz_db_database') - ); - - $this->assertSame('pdo', $nodba->getdriver()); - $this->assertInstanceOf('dba_pdo', $nodba); - $this->assertFalse($nodba->connected); - $this->assertNull($nodba->db); - - $this->assertFalse($nodba->q('SELECT * FROM account')); - } - - /** - * @depends testConnectToSqlServer - */ - public function testSelectQueryToNonExistentTableShouldReturnFalse() - { - $ret = $this->dba->q('SELECT * FROM non_existent_table'); - - $this->assertFalse($ret); - } - - /** - * @depends testConnectToSqlServer - */ - public function testInsertQueryToNonExistentTableShouldReturnEmptyArray() - { - $ret = $this->dba->q('INSERT INTO non_existent_table - (account_email, account_language) - VALUES (\'email@example.com\', \'en\') - '); - - $this->assertNotInstanceOf('PDOStatement', $ret); - $this->isEmpty($ret); - } -}