Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev_merge

This commit is contained in:
zotlabs 2016-10-18 16:29:36 -07:00
commit d55fcd055d
16 changed files with 321 additions and 122 deletions

View file

@ -27,8 +27,15 @@
"ext-gd" : "*",
"ext-mbstring" : "*",
"ext-xml" : "*",
"sabre/dav" : "~3.2",
"ext-openssl" : "*"
"ext-openssl" : "*",
"sabre/dav" : "~3.2"
},
"require-dev" : {
"php" : ">=5.6",
"phpunit/phpunit" : "^5.6",
"behat/behat" : "@stable",
"behat/mink-extension": "@stable",
"behat/mink-goutte-driver": "@stable"
},
"autoload" : {
"psr-4" : {
@ -36,8 +43,13 @@
"Zotlabs\\" : "Zotlabs/"
}
},
"autoload-dev" : {
"psr-4" : {
"Zotlabs\\Tests\\Unit\\" : "tests/unit"
}
},
"minimum-stability" : "stable",
"config" : {
"notify-on-install" : false
}
}
}

25
tests/README.md Normal file
View file

@ -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```

View file

@ -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: ~

View file

@ -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()
{
}
}

View file

@ -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()
{
}
}

View file

@ -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()
{
}
}

View file

@ -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"

View file

@ -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);
}
/**

View file

@ -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);
}
}

View file

@ -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"));
}
}

View file

@ -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'));
}

View file

@ -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.
}

View file

@ -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));