diff options
author | Klaus Weidenbach <Klaus.Weidenbach@gmx.net> | 2016-10-12 21:50:49 +0200 |
---|---|---|
committer | Klaus Weidenbach <Klaus.Weidenbach@gmx.net> | 2016-10-19 00:46:41 +0200 |
commit | b92e3ca3ee3f8bed1ff52311d29b4ce1e4297a83 (patch) | |
tree | fe4d742c662b65605d0b6fee8fbf3f5a9e9b66e5 /tests | |
parent | 2e1046220a70bb751c39854b881e86feb5d39149 (diff) | |
download | volse-hubzilla-b92e3ca3ee3f8bed1ff52311d29b4ce1e4297a83.tar.gz volse-hubzilla-b92e3ca3ee3f8bed1ff52311d29b4ce1e4297a83.tar.bz2 volse-hubzilla-b92e3ca3ee3f8bed1ff52311d29b4ce1e4297a83.zip |
[TASK] Restructure tests/ folder.
Move unit tests to tests/unit/. Get the old still working UnitTests
into a working state again.
Updated composer.json with required-dev packages.
Create a new folder tests/acceptance for Behat functional/acceptance
testing. Add a first Feature draft of a Behat functional test for
local login.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/README.md | 25 | ||||
-rw-r--r-- | tests/acceptance/behat.yml | 27 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/AdminContext.php | 23 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/ApiContext.php | 23 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/FeatureContext.php | 23 | ||||
-rw-r--r-- | tests/acceptance/features/login_local.feature | 18 | ||||
-rw-r--r-- | tests/unit/AntiXSSTest.php (renamed from tests/xss_filter_test.php) | 42 | ||||
-rw-r--r-- | tests/unit/AutonameTest.php (renamed from tests/autoname_test.php) | 100 | ||||
-rw-r--r-- | tests/unit/ContainsAttributeTest.php (renamed from tests/contains_attribute_test.php) | 90 | ||||
-rw-r--r-- | tests/unit/TextTest.php (renamed from tests/text_test.php) | 8 | ||||
-rw-r--r-- | tests/unit/UnitTestCase.php | 38 | ||||
-rw-r--r-- | tests/unit/UploadTest.php (renamed from tests/upload_test.php) | 8 | ||||
-rw-r--r-- | tests/unit/expand_acl_test.php (renamed from tests/expand_acl_test.php) | 0 | ||||
-rw-r--r-- | tests/unit/get_tags_test.php (renamed from tests/get_tags_test.php) | 0 | ||||
-rw-r--r-- | tests/unit/template_test.php (renamed from tests/template_test.php) | 0 |
15 files changed, 306 insertions, 119 deletions
diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..395333159 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,25 @@ +The folder tests/ contains resources for automated testing tools. + +Here you will find PHPUnit, Behat, etc. files to test the functionaly +of Hubzilla. Right now it only contains some basic tests to see if feasable +this can help improve the project. + +# Contents + +* unit/ PHPUnit tests +These are unit tests to check the smallest parts, like single functions. +It uses the tool PHPUnit https://phpunit.de/ + +* acceptance/ functional/acceptance testing +These are behavioral or so called functional/acceptance testing. They +are used to test business logic. They are written in Gherkin and use +the tool Behat http://behat.org/ + +# How to use? +You need the dev tools which are defined in the composer.json in the +require-dev configuration. +Run ```composer install``` without --no-dev to install these tools. + +To run unit tests run ```vendor/bin/phpunit tests/unit/``` + +To run acceptance tests run ```vendor/bin/behat --config tests/acceptance/behat.yml``` diff --git a/tests/acceptance/behat.yml b/tests/acceptance/behat.yml new file mode 100644 index 000000000..933571e5e --- /dev/null +++ b/tests/acceptance/behat.yml @@ -0,0 +1,27 @@ +default: + suites: + default: + paths: + - %paths.base%/features + contexts: + - Behat\MinkExtension\Context\MinkContext + admin_features: + filters: { role: admin } + contexts: + - AdminContext + api_features: + paths: + - %paths.base%/features/api + filters: + tags: "@api" + contexts: + - ApiContext + gherkin: + filters: + tags: ~@wip + extensions: + Behat\MinkExtension: + base_url: 'http://localhost' + sessions: + default: + goutte: ~ diff --git a/tests/acceptance/features/bootstrap/AdminContext.php b/tests/acceptance/features/bootstrap/AdminContext.php new file mode 100644 index 000000000..aa4dced67 --- /dev/null +++ b/tests/acceptance/features/bootstrap/AdminContext.php @@ -0,0 +1,23 @@ +<?php + +use Behat\Behat\Context\Context; +use Behat\Behat\Context\SnippetAcceptingContext; +use Behat\Gherkin\Node\PyStringNode; +use Behat\Gherkin\Node\TableNode; + +/** + * Defines application features from the specific context. + */ +class AdminContext implements Context, SnippetAcceptingContext +{ + /** + * Initializes context. + * + * Every scenario gets its own context instance. + * You can also pass arbitrary arguments to the + * context constructor through behat.yml. + */ + public function __construct() + { + } +} diff --git a/tests/acceptance/features/bootstrap/ApiContext.php b/tests/acceptance/features/bootstrap/ApiContext.php new file mode 100644 index 000000000..9b772b209 --- /dev/null +++ b/tests/acceptance/features/bootstrap/ApiContext.php @@ -0,0 +1,23 @@ +<?php + +use Behat\Behat\Context\Context; +use Behat\Behat\Context\SnippetAcceptingContext; +use Behat\Gherkin\Node\PyStringNode; +use Behat\Gherkin\Node\TableNode; + +/** + * Defines application features from the specific context. + */ +class ApiContext implements Context, SnippetAcceptingContext +{ + /** + * Initializes context. + * + * Every scenario gets its own context instance. + * You can also pass arbitrary arguments to the + * context constructor through behat.yml. + */ + public function __construct() + { + } +} diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php new file mode 100644 index 000000000..2ec02da85 --- /dev/null +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -0,0 +1,23 @@ +<?php + +use Behat\Behat\Context\Context; +use Behat\Behat\Context\SnippetAcceptingContext; +use Behat\Gherkin\Node\PyStringNode; +use Behat\Gherkin\Node\TableNode; + +/** + * Defines application features from the specific context. + */ +class FeatureContext implements Context, SnippetAcceptingContext +{ + /** + * Initializes context. + * + * Every scenario gets its own context instance. + * You can also pass arbitrary arguments to the + * context constructor through behat.yml. + */ + public function __construct() + { + } +} diff --git a/tests/acceptance/features/login_local.feature b/tests/acceptance/features/login_local.feature new file mode 100644 index 000000000..a7814b8f6 --- /dev/null +++ b/tests/acceptance/features/login_local.feature @@ -0,0 +1,18 @@ +Feature: Local login + In order to login locally + As a member + I need to successfully authenticate + + Scenario: Provide wrong credentials + Given I am on "/login" + When I fill in "id_username" with "foo" + And I fill in "id_password" with "bar" + And I press "submit" + Then I should be on "/login" + + Scenario: Provide correct credentials + Given I am on "/login" + When I fill in "id_username" with "behat" + And I fill in "id_password" with "behat" + And I press "submit" + Then I should be on "/apps" diff --git a/tests/xss_filter_test.php b/tests/unit/AntiXSSTest.php index 3fb6ac310..b45042a1e 100644 --- a/tests/xss_filter_test.php +++ b/tests/unit/AntiXSSTest.php @@ -1,13 +1,15 @@ <?php /** * tests several functions which are used to prevent xss attacks - * + * * @package test.util */ +use PHPUnit\Framework\TestCase; + require_once('include/text.php'); -class AntiXSSTest extends PHPUnit_Framework_TestCase { +class AntiXSSTest extends TestCase { /** * test, that tags are escaped @@ -27,31 +29,31 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase { */ public function testXmlify() { $text="<tag>I want to break\n this!11!<?hard?></tag>"; - $xml=xmlify($text); + $xml=xmlify($text); $retext=unxmlify($text); $this->assertEquals($text, $retext); } - - /**
- * xmlify and put in a document
- */
- public function testXmlifyDocument() {
- $tag="<tag>I want to break</tag>";
+ + /** + * xmlify and put in a document + */ + public function testXmlifyDocument() { + $tag="<tag>I want to break</tag>"; $xml=xmlify($tag); - $text='<text>'.$xml.'</text>';
- - $xml_parser=xml_parser_create(); + $text='<text>'.$xml.'</text>'; + + $xml_parser=xml_parser_create(); //should be possible to parse it - $values=array(); $index=array(); - $this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index)); - - $this->assertEquals(array('TEXT'=>array(0)), - $index); - $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
+ $values=array(); $index=array(); + $this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index)); + + $this->assertEquals(array('TEXT'=>array(0)), + $index); + $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), $values); - - xml_parser_free($xml_parser);
+ + xml_parser_free($xml_parser); } /** diff --git a/tests/autoname_test.php b/tests/unit/AutonameTest.php index 702e05bef..9f92f736f 100644 --- a/tests/autoname_test.php +++ b/tests/unit/AutonameTest.php @@ -1,76 +1,78 @@ <?php /** * this file contains tests for the autoname function - * + * * @package test.util */ +use PHPUnit\Framework\TestCase; + /** required, it is the file under test */ require_once('include/text.php'); /** * TestCase for the autoname function - * + * * @author Alexander Kampmann * @package test.util */ -class AutonameTest extends PHPUnit_Framework_TestCase { - /**
- *autonames should be random, even length
- */
- public function testAutonameEven() {
- $autoname1=autoname(10);
- $autoname2=autoname(10);
-
- $this->assertNotEquals($autoname1, $autoname2);
- }
-
- /**
- *autonames should be random, odd length
- */
- public function testAutonameOdd() {
- $autoname1=autoname(9);
- $autoname2=autoname(9);
-
- $this->assertNotEquals($autoname1, $autoname2);
- }
-
- /**
- * try to fail autonames
- */
- public function testAutonameNoLength() {
- $autoname1=autoname(0);
- $this->assertEquals(0, strlen($autoname1));
- }
- +class AutonameTest extends TestCase { + /** + *autonames should be random, even length + */ + public function testAutonameEven() { + $autoname1=autoname(10); + $autoname2=autoname(10); + + $this->assertNotEquals($autoname1, $autoname2); + } + + /** + *autonames should be random, odd length + */ + public function testAutonameOdd() { + $autoname1=autoname(9); + $autoname2=autoname(9); + + $this->assertNotEquals($autoname1, $autoname2); + } + + /** + * try to fail autonames + */ + public function testAutonameNoLength() { + $autoname1=autoname(0); + $this->assertEquals(0, strlen($autoname1)); + } + /** * try to fail it with invalid input - * + * * TODO: What's corect behaviour here? An exception? - */
- public function testAutonameNegativeLength() {
- $autoname1=autoname(-23);
- $this->assertEquals(0, strlen($autoname1));
- }
-
- // public function testAutonameMaxLength() {
- // $autoname2=autoname(PHP_INT_MAX);
- // $this->assertEquals(PHP_INT_MAX, count($autoname2));
- // }
- + */ + public function testAutonameNegativeLength() { + $autoname1=autoname(-23); + $this->assertEquals(0, strlen($autoname1)); + } + + // public function testAutonameMaxLength() { + // $autoname2=autoname(PHP_INT_MAX); + // $this->assertEquals(PHP_INT_MAX, count($autoname2)); + // } + /** * test with a length, that may be too short - */
- public function testAutonameLength1() {
- $autoname1=autoname(1);
+ */ + public function testAutonameLength1() { + $autoname1=autoname(1); $this->assertEquals(1, count($autoname1)); - - $autoname2=autoname(1);
+ + $autoname2=autoname(1); $this->assertEquals(1, count($autoname2)); // The following test is problematic, with only 26 possibilities // generating the same thing twice happens often aka // birthday paradox -// $this->assertFalse($autoname1==$autoname2);
+// $this->assertFalse($autoname1==$autoname2); } }
\ No newline at end of file diff --git a/tests/contains_attribute_test.php b/tests/unit/ContainsAttributeTest.php index b0bb06acf..0930d9837 100644 --- a/tests/contains_attribute_test.php +++ b/tests/unit/ContainsAttributeTest.php @@ -1,51 +1,53 @@ <?php -/**
- * this test tests the contains_attribute function
- *
- * @package test.util
- */
-
-/** required, it is the file under test */
-require_once('include/text.php');
-
-/**
- * TestCase for the contains_attribute function
- *
- * @author Alexander Kampmann
- * @package test.util
- */
-class ContainsAttributeTest extends PHPUnit_Framework_TestCase { - /**
- * test attribute contains
- */
- public function testAttributeContains1() {
- $testAttr="class1 notclass2 class3";
- $this->assertTrue(attribute_contains($testAttr, "class3"));
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
-
- /**
- * test attribute contains
- */
- public function testAttributeContains2() {
- $testAttr="class1 not-class2 class3";
- $this->assertTrue(attribute_contains($testAttr, "class3"));
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
- +/** + * this test tests the contains_attribute function + * + * @package test.util + */ + +use PHPUnit\Framework\TestCase; + +/** required, it is the file under test */ +require_once('include/text.php'); + +/** + * TestCase for the contains_attribute function + * + * @author Alexander Kampmann + * @package test.util + */ +class ContainsAttributeTest extends TestCase { + /** + * test attribute contains + */ + public function testAttributeContains1() { + $testAttr="class1 notclass2 class3"; + $this->assertTrue(attribute_contains($testAttr, "class3")); + $this->assertFalse(attribute_contains($testAttr, "class2")); + } + + /** + * test attribute contains + */ + public function testAttributeContains2() { + $testAttr="class1 not-class2 class3"; + $this->assertTrue(attribute_contains($testAttr, "class3")); + $this->assertFalse(attribute_contains($testAttr, "class2")); + } + /** * test with empty input - */
- public function testAttributeContainsEmpty() {
- $testAttr="";
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
- + */ + public function testAttributeContainsEmpty() { + $testAttr=""; + $this->assertFalse(attribute_contains($testAttr, "class2")); + } + /** * test input with special chars - */
- public function testAttributeContainsSpecialChars() {
- $testAttr="--... %\$ä() /(=?}";
- $this->assertFalse(attribute_contains($testAttr, "class2"));
+ */ + public function testAttributeContainsSpecialChars() { + $testAttr="--... %\$ä() /(=?}"; + $this->assertFalse(attribute_contains($testAttr, "class2")); } }
\ No newline at end of file diff --git a/tests/text_test.php b/tests/unit/TextTest.php index d1e210b68..48c04bc54 100644 --- a/tests/text_test.php +++ b/tests/unit/TextTest.php @@ -1,20 +1,22 @@ <?php /** * this file contains tests for text.php - * + * * @package test.util */ +use PHPUnit\Framework\TestCase; + /** required, it is the file under test */ require_once('include/text.php'); /** * TestCase for the texter - * + * * @author ken restivo * @package test.util */ -class TextTest extends PHPUnit_Framework_TestCase { +class TextTest extends TestCase { public function testGoodEmail() { $this->assertTrue(valid_email_regex('ken@spaz.org')); } diff --git a/tests/unit/UnitTestCase.php b/tests/unit/UnitTestCase.php new file mode 100644 index 000000000..7d706d5be --- /dev/null +++ b/tests/unit/UnitTestCase.php @@ -0,0 +1,38 @@ +<?php +/* Copyright (c) 2016 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; + +use PHPUnit\Framework\TestCase; + +/** + * @brief Base class for our Unit Tests. + * + * Empty class at the moment, but you should extend this class for unit test + * cases, so we could and for sure we will need to implement basic behaviour + * for all of our unit tests. + * + * @author Klaus Weidenbach + */ +abstract class UnitTestCase extends TestCase { + // when needed we can define functionality here which is used in UnitTests. +} diff --git a/tests/upload_test.php b/tests/unit/UploadTest.php index 031315fba..ab9d0e50a 100644 --- a/tests/upload_test.php +++ b/tests/unit/UploadTest.php @@ -1,20 +1,22 @@ <?php /** * this file contains tests for the uploader - * + * * @package test.util */ +use PHPUnit\Framework\TestCase; + /** required, it is the file under test */ require_once('include/attach.php'); /** * TestCase for the uploader - * + * * @author ken restivo * @package test.util */ -class UploadTest extends PHPUnit_Framework_TestCase { +class UploadTest extends TestCase { public function testFileNameMutipleDots() { $multidots = "foo.bar.baz.0.1.3.ogg"; $this->assertEquals("audio/ogg", z_mime_content_type($multidots)); diff --git a/tests/expand_acl_test.php b/tests/unit/expand_acl_test.php index 154bc921d..154bc921d 100644 --- a/tests/expand_acl_test.php +++ b/tests/unit/expand_acl_test.php diff --git a/tests/get_tags_test.php b/tests/unit/get_tags_test.php index 40f016747..40f016747 100644 --- a/tests/get_tags_test.php +++ b/tests/unit/get_tags_test.php diff --git a/tests/template_test.php b/tests/unit/template_test.php index 1f9f80531..1f9f80531 100644 --- a/tests/template_test.php +++ b/tests/unit/template_test.php |