From f162508ad18b1fca9a5201f4956d52022bd941a8 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Fri, 5 May 2017 23:13:54 +0200 Subject: :construction_worker::white_check_mark::bug: Import table structure in TravisCI. Fix a syntax error in schema_postres.sql which was discovered while working on this. --- tests/travis/prepare_mysql.sh | 11 ++++++++++- tests/travis/prepare_pgsql.sh | 13 ++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/travis/prepare_mysql.sh b/tests/travis/prepare_mysql.sh index 92c720205..b3d84253c 100755 --- a/tests/travis/prepare_mysql.sh +++ b/tests/travis/prepare_mysql.sh @@ -36,4 +36,13 @@ mysql -e "SHOW VARIABLES LIKE 'character_set%';" mysql -e "SELECT @@sql_mode;" # Create Hubzilla database -mysql -e "CREATE DATABASE IF NOT EXISTS hubzilla;" -uroot; +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';" + +# Import table structure +mysql -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;" diff --git a/tests/travis/prepare_pgsql.sh b/tests/travis/prepare_pgsql.sh index dcd83f3be..63c7388cb 100755 --- a/tests/travis/prepare_pgsql.sh +++ b/tests/travis/prepare_pgsql.sh @@ -30,8 +30,15 @@ echo "Preparing for PostgreSQL ..." # Print out some PostgreSQL information psql --version # Why does this hang further execution of the job? -psql -c "SELECT VERSION();" -U postgres +psql -U postgres -c "SELECT VERSION();" # Create Hubzilla database -psql -c "DROP DATABASE IF EXISTS hubzilla;" -U postgres -psql -c "CREATE DATABASE hubzilla;" -U postgres +psql -U postgres -c "DROP DATABASE IF EXISTS hubzilla;" +psql -U postgres -c "CREATE DATABASE hubzilla;" + +# Import table structure +psql -U postgres -v ON_ERROR_STOP=1 hubzilla < ./install/schema_postgres.sql + +# Show databases and tables +psql -U postgres -l +psql -U postgres -d hubzilla -c "\dt;" -- cgit v1.2.3 From 1de1b58a087afbadb55b7f18b93fb0b502a2de3a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 11 May 2017 19:01:04 -0700 Subject: consolidate email validation checks --- tests/unit/includes/TextTest.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'tests') diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index e2c7cbb9a..25a997f7a 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -11,18 +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 $htmlbr = 'first line
-- cgit v1.2.3 From d056b13e1495b136bb138cc65c4e311b458db380 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 13 May 2017 00:16:50 +0200 Subject: :construction_worker::white_check_mark: Documentation Permissions.php. Also add some phpunit tests for this class, but there are some problems yet with mocking static functions. --- tests/unit/Access/PermissionsTest.php | 148 ++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 tests/unit/Access/PermissionsTest.php (limited to 'tests') 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 @@ +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 -- cgit v1.2.3 From 0f0e23445ab00c49a09d3167ca220ac314722cfd Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Wed, 24 May 2017 23:47:03 +0200 Subject: :hammer::white_check_mark: Add html2markdown unit tests. A tiny refactoring to make HTML 2 markdown conversion testable. Add some unit tests to check the behavior of the now used HTML2Markdown library. There are some differences compared to the old pixel418/markdownify library. --- tests/unit/includes/MarkdownTest.php | 149 +++++++++++++++++++++++++++++++++++ tests/unit/includes/TextTest.php | 18 +++++ 2 files changed, 167 insertions(+) create mode 100644 tests/unit/includes/MarkdownTest.php (limited to 'tests') 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 @@ +assertEquals($markdown, html2markdown($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 >' + ], + 'our escaped HTML entities' => [ + '&_lt_; &_gt_; &_amp_;', + '&\_lt\_; &\_gt\_; &\_amp\_;' + ], + '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' => [ + '
   line with  spaces   
', + '` line with spaces `' + ], + '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('', html2markdown('<getFunctionMock(__NAMESPACE__, "bbcode"); + $bbc->expects($this->once())->willReturn('testbold
i
  • li1
  • li2

'); + + $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..4afa2b49b 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -11,6 +11,9 @@ use Zotlabs\Tests\Unit\UnitTestCase; */ class TextTest extends UnitTestCase { + /** + * @covers ::valid_email_regex + */ public function testGoodEmail() { $this->assertTrue(valid_email_regex('ken@spaz.org')); $this->assertTrue(valid_email_regex('ken@restivo.org')); @@ -18,11 +21,17 @@ class TextTest extends UnitTestCase { $this->assertTrue(valid_email_regex('foo+nobody@hubzilla.org')); } + /** + * @covers ::valid_email_regex + */ public function testBadEmail() { $this->assertFalse(valid_email_regex('nobody!uses!these!any.more')); $this->assertFalse(valid_email_regex('foo@bar@hubzilla.org')); } + /** + * @covers ::purify_html + */ public function testPurifyHTML() { // linebreaks $htmlbr = 'first line
@@ -46,6 +55,9 @@ empty line above'; $this->assertEquals('
  • item1
', purify_html('
  • item1
')); } + /** + * @covers ::purify_html + */ public function testPurifyHTML_html() { $this->assertEquals('

ids und classes

', purify_html('

ids und classes

')); $this->assertEquals('

close missing tags

', purify_html('

close missing tags')); @@ -59,6 +71,9 @@ empty line above'; $this->assertEquals('', purify_html('')); } + /** + * @covers ::purify_html + */ public function testPurifyHTML_js() { $this->assertEquals('

', purify_html('
')); $this->assertEquals('link', purify_html('link')); @@ -66,6 +81,9 @@ empty line above'; $this->assertEquals('', purify_html('')); } + /** + * @covers ::purify_html + */ public function testPurifyHTML_css() { $this->assertEquals('

red

', purify_html('

red

')); $this->assertEquals('

invalid color

', purify_html('

invalid color

')); -- cgit v1.2.3 From 4bd825e7782338b00a91a0a0c6f882a276f095a9 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Mon, 5 Jun 2017 20:32:00 +0200 Subject: :construction_worker::white_check_mark: Add MySQL 5.7 in TravisCI. Use a Docker container to add MySQL 5.7 in TravisCI. A lot of sql_mode settings have changed with 5.7, so finnaly provide it to test against it. --- tests/travis/prepare_mysql.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'tests') 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;" -- cgit v1.2.3