aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Access/AccessListTest.php4
-rw-r--r--tests/unit/Access/PermissionsTest.php4
-rw-r--r--tests/unit/includes/FeedutilsTest.php (renamed from tests/unit/includes/FeedutilsText.php)38
-rw-r--r--tests/unit/includes/LanguageTest.php164
-rw-r--r--tests/unit/includes/TextTest.php40
5 files changed, 244 insertions, 6 deletions
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/FeedutilsText.php b/tests/unit/includes/FeedutilsTest.php
index 932a1b3a1..e9826a73d 100644
--- a/tests/unit/includes/FeedutilsText.php
+++ b/tests/unit/includes/FeedutilsTest.php
@@ -24,7 +24,9 @@ class FeedutilsTest extends UnitTestCase {
$b = ['attribs' => ['' => [
'rel' => 'rel_value',
'type' => 'type_value',
- 'href' => 'href_value'
+ 'href' => 'href_value',
+ 'length' => 'length_value',
+ 'title' => 'title_value'
]]];
$blink1 = ['link1' => $b];
$bresult[] = $b['attribs'][''];
@@ -37,6 +39,9 @@ class FeedutilsTest extends UnitTestCase {
//Illegal string offset 'attribs'
}*/
+ /**
+ * @uses ::xmlify
+ */
public function test_atom_author() {
$this->assertEquals('', atom_author('', 'nick', 'name', 'uri', 72, 72, 'png', 'photourl'));
@@ -47,9 +52,38 @@ class FeedutilsTest extends UnitTestCase {
<link rel="photo" type="png" media:width="72" media:height="72" href="http://photourl" />
<link rel="avatar" type="png" media:width="72" media:height="72" href="http://photourl" />
<poco:preferredUsername>nick</poco:preferredUsername>
- <poco:displayName>name<poco:displayName>
+ <poco:displayName>name</poco:displayName>
</tag>';
$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 = '<tag>
+ <as:object-type>http://activitystrea.ms/schema/1.0/person</as:object-type>
+ <id>http://hub</id>
+ <name>chan</name>
+ <uri>http://hub</uri>
+ <link rel="alternate" type="text/html" href="http://hub" />
+ <link rel="photo" type="mimetype" media:width="300" media:height="300" href="http://hub/img" />
+ <link rel="avatar" type="mimetype" media:width="300" media:height="300" href="http://hub/img" />
+ <poco:preferredUsername>chan</poco:preferredUsername>
+ <poco:displayName>Chan</poco:displayName>
+</tag>';
+
+ $this->assertXmlStringEqualsXmlString($a, atom_render_author('tag', $xchan));
+ }
}
diff --git a/tests/unit/includes/LanguageTest.php b/tests/unit/includes/LanguageTest.php
new file mode 100644
index 000000000..dd71115c4
--- /dev/null
+++ b/tests/unit/includes/LanguageTest.php
@@ -0,0 +1,164 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+namespace Zotlabs\Tests\Unit\includes;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Text_LanguageDetect;
+//use phpmock\phpunit\PHPMock;
+
+/**
+ * @brief Unit Test cases for include/language.php file.
+ *
+ * @author Klaus Weidenbach
+ */
+class LanguageTest extends UnitTestCase {
+ //use PHPMock;
+
+ /**
+ * @dataProvider languageExamplesProvider
+ * @coversNothing
+ */
+ public function testDetectLanguage($text, $langCode, $confidence) {
+
+ // php-mock can not mock global functions which is called by a global function.
+ // If the calling function is in a namespace it would work.
+ //$gc = $this->getFunctionMock(__NAMESPACE__, 'get_config');
+ //$gc->expects($this->once())->willReturn(10)
+ //$cg = $this->getFunctionMock('Zotlabs\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'
+ ]
+ ]
+ ];
+ }
+} \ No newline at end of file
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('<div>invalid position removed</div>', purify_html('<div style="top:10p">invalid position removed</div>', true));
}
+ /**
+ * @dataProvider notagsProvider
+ */
+ public function testNotags($string, $expected) {
+ $this->assertEquals($expected, notags($string));
+ }
+ public function notagsProvider() {
+ return [
+ 'empty string' => ['', ''],
+ 'simple tag' => ['<value>', '[value]'],
+ 'tag pair' => ['<b>text</b>', '[b]text[/b]'],
+ 'double angle bracket' => ['<<value', '[[value'],
+ 'HTML entity &gt;' => ['&gt;', '&gt;']
+ ];
+ }
+
+ /**
+ * @dataProvider sanitise_aclProvider
+ */
+ public function testSanitise_acl($string, $expected) {
+ sanitise_acl($string);
+ $this->assertEquals($expected, $string);
+ }
+ public function sanitise_aclProvider() {
+ return [
+ 'text' => ['value', '<value>'],
+ 'text with angle bracket' => ['<value>', '<[value]>'],
+ 'comma separated acls' => ['value1,value2', '<value1,value2>']
+ ];
+ }
+
+ public function testUnsetSanitise_acl() {
+ $empty = '';
+ sanitise_acl($empty);
+ $this->assertTrue(isset($empty)); // unset() not working? Would expect false
+ $this->assertEmpty($empty);
+ }
+
}