aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2017-08-16 10:32:35 +0200
committerMario Vavti <mario@mariovavti.com>2017-08-16 10:32:35 +0200
commit4a7384bc0ce1893a432bf4b7d67bca23796fe9db (patch)
tree5623c66a3f66445284529d6207e4ab4a2edb2810 /tests
parentc664a4bdcd1bd578f5ec3c2884f7c97e9f68d2d7 (diff)
parent90bc21f2d560d879d7eaf05a85af6d6dca53ebac (diff)
downloadvolse-hubzilla-4a7384bc0ce1893a432bf4b7d67bca23796fe9db.tar.gz
volse-hubzilla-4a7384bc0ce1893a432bf4b7d67bca23796fe9db.tar.bz2
volse-hubzilla-4a7384bc0ce1893a432bf4b7d67bca23796fe9db.zip
Merge branch '2.6RC'2.6
Diffstat (limited to 'tests')
-rwxr-xr-xtests/travis/prepare_mysql.sh27
-rw-r--r--tests/unit/Access/PermissionsTest.php148
-rw-r--r--tests/unit/includes/MarkdownTest.php149
-rw-r--r--tests/unit/includes/TextTest.php20
4 files changed, 322 insertions, 22 deletions
diff --git a/tests/travis/prepare_mysql.sh b/tests/travis/prepare_mysql.sh
index b3d84253c..095ad7e25 100755
--- a/tests/travis/prepare_mysql.sh
+++ b/tests/travis/prepare_mysql.sh
@@ -27,22 +27,27 @@ set -e
echo "Preparing for MySQL ..."
+if [[ "$MYSQL_VERSION" == "5.7" ]]; then
+ echo "Using MySQL 5.7 in Docker container, need to use TCP"
+ export PROTO="--protocol=TCP"
+fi
+
# Print out some MySQL information
mysql --version
-mysql -e "SELECT VERSION();"
-mysql -e "SHOW VARIABLES LIKE 'max_allowed_packet';"
-mysql -e "SHOW VARIABLES LIKE 'collation_%';"
-mysql -e "SHOW VARIABLES LIKE 'character_set%';"
-mysql -e "SELECT @@sql_mode;"
+mysql $PROTO -e "SELECT VERSION();"
+mysql $PROTO -e "SHOW VARIABLES LIKE 'max_allowed_packet';"
+mysql $PROTO -e "SHOW VARIABLES LIKE 'collation_%';"
+mysql $PROTO -e "SHOW VARIABLES LIKE 'character_set%';"
+mysql $PROTO -e "SELECT @@sql_mode;"
# Create Hubzilla database
-mysql -u root -e "CREATE DATABASE IF NOT EXISTS hubzilla;";
-mysql -u root -e "CREATE USER 'hubzilla'@'localhost' IDENTIFIED BY 'hubzilla';"
-mysql -u root -e "GRANT ALL ON hubzilla.* TO 'hubzilla'@'localhost';"
+mysql $PROTO -u root -e "CREATE DATABASE IF NOT EXISTS hubzilla;";
+mysql $PROTO -u root -e "CREATE USER 'hubzilla'@'localhost' IDENTIFIED BY 'hubzilla';"
+mysql $PROTO -u root -e "GRANT ALL ON hubzilla.* TO 'hubzilla'@'localhost';"
# Import table structure
-mysql -u root hubzilla < ./install/schema_mysql.sql
+mysql $PROTO -u root hubzilla < ./install/schema_mysql.sql
# Show databases and tables
-mysql -u root -e "SHOW DATABASES;"
-mysql -u root -e "USE hubzilla; SHOW TABLES;"
+mysql $PROTO -u root -e "SHOW DATABASES;"
+mysql $PROTO -u root -e "USE hubzilla; SHOW TABLES;"
diff --git a/tests/unit/Access/PermissionsTest.php b/tests/unit/Access/PermissionsTest.php
new file mode 100644
index 000000000..93c641fb1
--- /dev/null
+++ b/tests/unit/Access/PermissionsTest.php
@@ -0,0 +1,148 @@
+<?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\Access;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Access\Permissions;
+
+/**
+ * @brief Unit Test case for Permissions class.
+ *
+ * @covers Zotlabs\Access\Permissions
+ */
+class PermissionsTest extends UnitTestCase {
+
+ /**
+ * @dataProvider FilledPermsProvider
+ */
+ public function testFilledPerms($permarr, $expected) {
+ $this->markTestIncomplete(
+ 'Need to mock static function Permissions::Perms() ...'
+ );
+ //$this->assertEquals($expected, Permissions::FilledPerms($permarr));
+
+/* $perms = $this->getMockBuilder(Permissions::class)
+ ->setMethods(['Perms'])
+ ->getMock();
+ $perms->expects($this->once())
+ ->method('Perms');
+ // still calls the static self::Perms()
+ $perms->FilledPerms($permarr);
+*/
+ }
+ public function FilledPermsProvider() {
+ return [
+ 'empty' => [
+ [],
+ ['perm1' => 0, 'perm2' => 0]
+ ],
+ 'valild' => [
+ [['perm1' => 1]],
+ ['perm1' => 1, 'perm2' => 0]
+ ]
+ ];
+ }
+/* public function testFilledPermsNull() {
+ // need to mock global function btlogger();
+ Permissions::FilledPerms(null);
+ }
+*/
+ /**
+ * @dataProvider OPermsProvider
+ *
+ * @param array $permarr
+ * @param array $expected
+ */
+ public function testOPerms($permarr, $expected) {
+ $this->assertEquals($expected, Permissions::OPerms($permarr));
+ }
+ /**
+ * @return Associative array with test values for OPerms()
+ * * \e array Array to test
+ * * \e array Expect 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
+ * @param array $p2
+ * @param boolean $expectedresult
+ */
+ public function testPermsCompare($p1, $p2, $expectedresult) {
+ $this->assertEquals($expectedresult, Permissions::PermsCompare($p1, $p2));
+ }
+ /**
+ * @return Associative array with test values for PermsCompare()
+ * * \e array 1st array
+ * * \e array 2nd array
+ * * \e boolean expected result for the test
+ */
+ 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
+ ]
+ ];
+ }
+} \ No newline at end of file
diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php
new file mode 100644
index 000000000..3026c633a
--- /dev/null
+++ b/tests/unit/includes/MarkdownTest.php
@@ -0,0 +1,149 @@
+<?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 phpmock\phpunit\PHPMock;
+
+require_once 'include/markdown.php';
+
+/**
+ * @brief Unit Test case for markdown functions.
+ */
+class MarkdownTest extends UnitTestCase {
+ use PHPMock;
+
+ /**
+ * @covers ::html2markdown
+ * @dataProvider html2markdownProvider
+ */
+ public function testHtml2markdown($html, $markdown) {
+ $this->assertEquals($markdown, html2markdown($html));
+ }
+
+ public function html2markdownProvider() {
+ return [
+ 'empty text' => [
+ '',
+ ''
+ ],
+ 'space and nbsp only' => [
+ ' &nbsp;',
+ ''
+ ],
+ 'strong, b, em, i, bib' => [
+ '<strong>strong</strong> <b>bold</b> <em>em</em> <i>italic</i> <b>bo<i>italic</i>ld</b>',
+ '**strong** **bold** _em_ _italic_ **bo_italic_ld**'
+ ],
+ 'empty tags' => [
+ 'text1 <b></b> text2 <i></i>',
+ 'text1 text2'
+ ],
+ 'HTML entities, lt does not work' => [
+ '& gt > lt <',
+ '& gt > lt'
+ ],
+ 'escaped HTML entities' => [
+ '&amp; lt &lt; gt &gt;',
+ '& lt < gt >'
+ ],
+ 'our escaped HTML entities' => [
+ '&_lt_; &_gt_; &_amp_;',
+ '&\_lt\_; &\_gt\_; &\_amp\_;'
+ ],
+ 'linebreak' => [
+ "line1<br>line2\nline3",
+ "line1 \nline2 line3"
+ ],
+ 'headlines' => [
+ '<h1>header1</h1><h3>Header 3</h3>',
+ "header1\n=======\n\n### Header 3"
+ ],
+ 'unordered list' => [
+ '<ul><li>Item 1</li><li>Item 2</li><li>Item <b>3</b></li></ul>',
+ "- Item 1\n- Item 2\n- Item **3**"
+ ],
+ 'ordered list' => [
+ '<ol><li>Item 1</li><li>Item 2</li><li>Item <b>3</b></li></ol>',
+ "1. Item 1\n2. Item 2\n3. Item **3**"
+ ],
+ 'nested lists' => [
+ '<ul><li>Item 1<ol><li>Item 1a</li><li>Item <b>1b</b></ol></li><li>Item 2</li></ul>',
+ "- Item 1\n 1. Item 1a\n 2. Item **1b**\n- Item 2"
+ ],
+ 'img' => [
+ '<img src="/path/to/img.png" alt="alt text" title="title text">',
+ '![alt text](/path/to/img.png "title text")'
+ ],
+ 'link' => [
+ '<a href="http://hubzilla.org" title="Hubzilla">link</a>',
+ '[link](http://hubzilla.org "Hubzilla")'
+ ],
+ 'img link' => [
+ '<a href="http://hubzilla.org" title="Hubzilla"><img src="/img/hubzilla.png" alt="alt img text" title="img title"></a>',
+ '[![alt img text](/img/hubzilla.png "img title")](http://hubzilla.org "Hubzilla")'
+ ],
+ 'script' => [
+ "<script>alert('test');</script>",
+ "<script>alert('test');</script>"
+ ],
+ 'blockquote, issue #793' => [
+ '<blockquote>something</blockquote>blah',
+ "> something\n\nblah"
+ ],
+ 'code' => [
+ '<code>&lt;p&gt;HTML text&lt;/p&gt;</code>',
+ '`<p>HTML text</p>`'
+ ],
+ 'pre' => [
+ '<pre> line with spaces </pre>',
+ '` line with spaces `'
+ ],
+ 'div p' => [
+ '<div>div</div><div><p>p</p></div>',
+ "<div>div</div><div>p\n\n</div>"
+ ]
+ ];
+ }
+
+ /*public function testHtml2markdownException() {
+ //$this->expectException(\InvalidArgumentException::class);
+ // need to stub logger() for this to work
+ $this->assertEquals('', html2markdown('<<invalid'));
+ }*/
+
+/* public function testBB2diasporaMardown() {
+ //stub bbcode() and return our HTML, we just need to test the HTML2Markdown library.
+ $html1 = 'test<b>bold</b><br><i>i</i><ul><li>li1</li><li>li2</li></ul><br>';
+ $bb1 = 'test';
+
+ // php-mock can not mock global functions which is called by a global function.
+ // If the calling function is in a namespace it does work.
+ $bbc = $this->getFunctionMock(__NAMESPACE__, "bbcode");
+ $bbc->expects($this->once())->willReturn('test<b>bold</b><br><i>i</i><ul><li>li1</li><li>li2</li></ul><br>');
+
+ $this->assertEquals($bb1, bb2diaspora($html1));
+ }
+*/
+} \ No newline at end of file
diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php
index e2c7cbb9a..acc490001 100644
--- a/tests/unit/includes/TextTest.php
+++ b/tests/unit/includes/TextTest.php
@@ -11,17 +11,6 @@ use Zotlabs\Tests\Unit\UnitTestCase;
*/
class TextTest extends UnitTestCase {
- public function testGoodEmail() {
- $this->assertTrue(valid_email_regex('ken@spaz.org'));
- $this->assertTrue(valid_email_regex('ken@restivo.org'));
- $this->assertTrue(valid_email_regex('nobody@hubzilla.org'));
- $this->assertTrue(valid_email_regex('foo+nobody@hubzilla.org'));
- }
-
- public function testBadEmail() {
- $this->assertFalse(valid_email_regex('nobody!uses!these!any.more'));
- $this->assertFalse(valid_email_regex('foo@bar@hubzilla.org'));
- }
public function testPurifyHTML() {
// linebreaks
@@ -46,6 +35,9 @@ empty line above';
$this->assertEquals('<ul><li>item1</li></ul>', purify_html('<ul data-accordion-menu-unknown><li>item1</li></ul>'));
}
+ /**
+ * @covers ::purify_html
+ */
public function testPurifyHTML_html() {
$this->assertEquals('<div id="id01"><p class="class01">ids und classes</p></div>', purify_html('<div id="id01"><p class="class01">ids und classes</p></div>'));
$this->assertEquals('<div><p>close missing tags</p></div>', purify_html('<div><p>close missing tags'));
@@ -59,6 +51,9 @@ empty line above';
$this->assertEquals('', purify_html('<iframe width="560" height="315" src="https://www.youtube.com/embed/kiNGx5oL7hk" frameborder="0" allowfullscreen></iframe>'));
}
+ /**
+ * @covers ::purify_html
+ */
public function testPurifyHTML_js() {
$this->assertEquals('<div></div>', purify_html('<div><img src="javascript:evil();" onload="evil();"></div>'));
$this->assertEquals('<a href="#">link</a>', purify_html('<a href="#" onclick="alert(\'xss\')">link</a>'));
@@ -66,6 +61,9 @@ empty line above';
$this->assertEquals('', purify_html('<script>alter("42")</script>'));
}
+ /**
+ * @covers ::purify_html
+ */
public function testPurifyHTML_css() {
$this->assertEquals('<p style="color:#FF0000;background-color:#fff;">red</p>', purify_html('<p style="color:red; background-color:#fff">red</p>'));
$this->assertEquals('<p>invalid color</p>', purify_html('<p style="color:invalid; background-color:#jjkkmm">invalid color</p>'));