aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2023-11-25 17:12:28 +0100
committerMario <mario@mariovavti.com>2023-11-25 17:12:28 +0100
commit0fd8e02a884a2b040dca62ab5d9674db5f6a070b (patch)
tree586ee43f32f6f14368c09026f21dcd3244ea24b6 /tests
parent82e704ec5b107823c09f1387e9091adee53a4c2d (diff)
parent55c4bfb67009c598f25b1a8189604bfffa73dfbb (diff)
downloadvolse-hubzilla-8.8.tar.gz
volse-hubzilla-8.8.tar.bz2
volse-hubzilla-8.8.zip
Merge branch '8.8RC'8.8
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Access/AccessListTest.php85
-rw-r--r--tests/unit/AntiXSSTest.php62
-rw-r--r--tests/unit/AutonameTest.php17
-rw-r--r--tests/unit/ContainsAttributeTest.php17
-rw-r--r--tests/unit/GetTagsTest.php (renamed from tests/unit/get_tags_test.php)376
5 files changed, 271 insertions, 286 deletions
diff --git a/tests/unit/Access/AccessListTest.php b/tests/unit/Access/AccessListTest.php
index 3c8d3e859..635f09930 100644
--- a/tests/unit/Access/AccessListTest.php
+++ b/tests/unit/Access/AccessListTest.php
@@ -34,10 +34,9 @@ use Zotlabs\Access\AccessList;
class AccessListTest extends UnitTestCase {
/**
- * @brief Expected result for most tests.
- * @var array
+ * Expected result for most tests.
*/
- protected $expectedResult = [
+ protected array $expectedResult = [
'allow_cid' => '<acid><acid2>',
'allow_gid' => '<agid>',
'deny_cid' => '',
@@ -61,31 +60,42 @@ class AccessListTest extends UnitTestCase {
}
/**
- * @expectedException PHPUnit\Framework\Error\Error
+ * AccessList constructor should throw an exception if input is not
+ * an array.
*/
-/*
- public function testPHPErrorOnInvalidConstructor() {
+ public function testConstructorThrowsOnInvalidInputType() {
+ $this->expectException("TypeError");
$accessList = new AccessList('invalid');
- // Causes: "Illegal string offset 'channel_allow_cid'"
}
-*/
- public function testDefaultGetExplicit() {
+
+ /**
+ * AccessList constructor should throw an exception on
+ * invalid input.
+ */
+ public function testConstructorThrowsOnMissingKeysInArray() {
+ $this->expectException("Exception");
+ $this->expectExceptionMessage("Invalid AccessList object");
+ $accessList = new AccessList(['something_else' => 'should_this_fail?']);
+ }
+
+ /**
+ * Test that the defaults are as expected when constructed with
+ * an empty array.
+ */
+ public function testDefaults() {
$accessList = new AccessList([]);
$this->assertFalse($accessList->get_explicit());
- }
+ $this->assertFalse($accessList->is_private());
- public function testDefaultGet() {
- $arr = [
+ $expected = [
'allow_cid' => '',
'allow_gid' => '',
'deny_cid' => '',
'deny_gid' => ''
];
- $accessList = new AccessList([]);
-
- $this->assertEquals($arr, $accessList->get());
+ $this->assertEquals($expected, $accessList->get());
}
public function testSet() {
@@ -111,19 +121,27 @@ class AccessListTest extends UnitTestCase {
}
/**
- * @expectedException PHPUnit\Framework\Error\Error
+ * The set method should throw an exception if input is not an array.
*/
-/*
- public function testPHPErrorOnInvalidSet() {
+ public function testSetThrowsOnInvalidInputType() {
+ $this->expectException('TypeError');
$accessList = new AccessList([]);
$accessList->set('invalid');
- // Causes: "Illegal string offset 'allow_cid'"
}
-*/
+
+ public function testSetThrowsOnMissingKeysInArray() {
+ $this->expectException('Exception');
+ $this->expectExceptionMessage('Invalid AccessList object');
+
+ $accessList = new AccessList([]);
+ $accessList->set(['something_else' => 'should_this_fail?']);
+ }
/**
- * set_from_array() calls some other functions, too which are not yet unit tested.
+ * The set_from_array() function calls some other functions, too which are
+ * not yet unit tested.
+ *
* @uses ::perms2str
* @uses ::sanitise_acl
* @uses ::notags
@@ -158,12 +176,11 @@ class AccessListTest extends UnitTestCase {
}
/**
+ * The AccessList should be private if any of the fields are set,
+ *
* @dataProvider isprivateProvider
*/
public function testIsPrivate($channel) {
- $accessListPublic = new AccessList([]);
- $this->assertFalse($accessListPublic->is_private());
-
$accessListPrivate = new AccessList($channel);
$this->assertTrue($accessListPrivate->is_private());
}
@@ -176,12 +193,30 @@ class AccessListTest extends UnitTestCase {
'channel_deny_cid' => '<dcid>',
'channel_deny_gid' => '<dgid>'
]],
- 'only one set' => [[
+ 'only allow_cid set' => [[
'channel_allow_cid' => '<acid>',
'channel_allow_gid' => '',
'channel_deny_cid' => '',
'channel_deny_gid' => ''
]],
+ 'only allow_gid set' => [[
+ 'channel_allow_cid' => '',
+ 'channel_allow_gid' => '<agid>',
+ 'channel_deny_cid' => '',
+ 'channel_deny_gid' => ''
+ ]],
+ 'only deny_cid set' => [[
+ 'channel_allow_cid' => '',
+ 'channel_allow_gid' => '',
+ 'channel_deny_cid' => '<dcid>',
+ 'channel_deny_gid' => ''
+ ]],
+ 'only deny_gid set' => [[
+ 'channel_allow_cid' => '',
+ 'channel_allow_gid' => '',
+ 'channel_deny_cid' => '',
+ 'channel_deny_gid' => '<dgid>'
+ ]],
'acid+null' => [[
'channel_allow_cid' => '<acid>',
'channel_allow_gid' => null,
diff --git a/tests/unit/AntiXSSTest.php b/tests/unit/AntiXSSTest.php
index 09642726f..1de9d54cd 100644
--- a/tests/unit/AntiXSSTest.php
+++ b/tests/unit/AntiXSSTest.php
@@ -1,18 +1,16 @@
<?php
/**
- * tests several functions which are used to prevent xss attacks
+ * 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 TestCase {
/**
- * test, that tags are escaped
+ * Test, that tags are escaped
*/
public function testEscapeTags() {
$invalidstring='<submit type="button" onclick="alert(\'failed!\');" />';
@@ -24,28 +22,30 @@ class AntiXSSTest extends TestCase {
$this->assertEquals("&lt;submit type=&quot;button&quot; onclick=&quot;alert('failed!');&quot; /&gt;", $escapedString);
}
- /**
- * @dataProvider urlTestProvider
- */
- public function testEscapeURL($url, $expected) : void {
- $this->assertEquals($expected, escape_url($url));
- }
+ /**
+ * Test escaping URL's to make them safe for use in html and attributes.
+ *
+ * @dataProvider urlTestProvider
+ */
+ public function testEscapeURL($url, $expected) : void {
+ $this->assertEquals($expected, escape_url($url));
+ }
- public function urlTestProvider() : array {
- return [
- [
- "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'><script>alert('boom')</script>",
- "https://example.com/settings/calendar/?f=&amp;rpath=https://example.com/cdav/calendar&apos;&gt;&lt;script&gt;alert(&apos;boom&apos;)&lt;/script&gt;"
- ],
- [
- "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='",
- "settings/calendar/?f=&amp;rpath=https://example.com&apos;+accesskey=x+onclick=alert(/boom/);a=&apos;"
- ],
- ];
- }
+ public function urlTestProvider() : array {
+ return [
+ [
+ "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'><script>alert('boom')</script>",
+ "https://example.com/settings/calendar/?f=&amp;rpath=https://example.com/cdav/calendar&apos;&gt;&lt;script&gt;alert(&apos;boom&apos;)&lt;/script&gt;"
+ ],
+ [
+ "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='",
+ "settings/calendar/?f=&amp;rpath=https://example.com&apos;+accesskey=x+onclick=alert(/boom/);a=&apos;"
+ ],
+ ];
+ }
/**
- *xmlify and unxmlify
+ * Test xmlify and unxmlify
*/
public function testXmlify() {
$text="<tag>I want to break\n this!11!<?hard?></tag>";
@@ -56,7 +56,7 @@ class AntiXSSTest extends TestCase {
}
/**
- * xmlify and put in a document
+ * Test xmlify and put in a document
*/
public function testXmlifyDocument() {
$tag="<tag>I want to break</tag>";
@@ -65,7 +65,9 @@ class AntiXSSTest extends TestCase {
$xml_parser=xml_parser_create();
//should be possible to parse it
- $values=array(); $index=array();
+ $values=array();
+ $index=array();
+
$this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index));
$this->assertEquals(array('TEXT'=>array(0)),
@@ -76,16 +78,6 @@ class AntiXSSTest extends TestCase {
xml_parser_free($xml_parser);
}
- /**
- * test hex2bin and reverse
- */
- public function testHex2Bin() {
- $this->assertEquals(-3, hex2bin(bin2hex(-3)));
- $this->assertEquals(0, hex2bin(bin2hex(0)));
- $this->assertEquals(12, hex2bin(bin2hex(12)));
- $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));
- }
-
//function qp, quick and dirty??
//get_mentions
//get_contact_block, bis Zeile 538
diff --git a/tests/unit/AutonameTest.php b/tests/unit/AutonameTest.php
index 566fe6149..b79a600c5 100644
--- a/tests/unit/AutonameTest.php
+++ b/tests/unit/AutonameTest.php
@@ -1,24 +1,21 @@
<?php
/**
- * this file contains tests for the autoname function
+ * 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
+ * @author Alexander Kampmann
* @package test.util
*/
class AutonameTest extends TestCase {
/**
- *autonames should be random, even length
+ * Autonames should be random, even length
*/
public function testAutonameEven() {
$autoname1=autoname(10);
@@ -28,7 +25,7 @@ class AutonameTest extends TestCase {
}
/**
- *autonames should be random, odd length
+ * Autonames should be random, odd length
*/
public function testAutonameOdd() {
$autoname1=autoname(9);
@@ -38,7 +35,7 @@ class AutonameTest extends TestCase {
}
/**
- * try to fail autonames
+ * Try to fail autonames
*/
public function testAutonameNoLength() {
$autoname1=autoname(0);
@@ -46,7 +43,7 @@ class AutonameTest extends TestCase {
}
/**
- * try to fail it with invalid input
+ * Try to fail it with invalid input
*
* TODO: What's corect behaviour here? An exception?
*/
@@ -61,7 +58,7 @@ class AutonameTest extends TestCase {
// }
/**
- * test with a length, that may be too short
+ * Test with a length, that may be too short
* length is maximum - autoname can return something shorter.
*/
public function testAutonameLength1() {
diff --git a/tests/unit/ContainsAttributeTest.php b/tests/unit/ContainsAttributeTest.php
index 0930d9837..db9618826 100644
--- a/tests/unit/ContainsAttributeTest.php
+++ b/tests/unit/ContainsAttributeTest.php
@@ -1,24 +1,21 @@
<?php
/**
- * this test tests the contains_attribute function
+ * 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
+ * @author Alexander Kampmann
* @package test.util
*/
class ContainsAttributeTest extends TestCase {
/**
- * test attribute contains
+ * Test attribute contains
*/
public function testAttributeContains1() {
$testAttr="class1 notclass2 class3";
@@ -27,7 +24,7 @@ class ContainsAttributeTest extends TestCase {
}
/**
- * test attribute contains
+ * Test attribute contains
*/
public function testAttributeContains2() {
$testAttr="class1 not-class2 class3";
@@ -36,7 +33,7 @@ class ContainsAttributeTest extends TestCase {
}
/**
- * test with empty input
+ * Test with empty input
*/
public function testAttributeContainsEmpty() {
$testAttr="";
@@ -44,10 +41,10 @@ class ContainsAttributeTest extends TestCase {
}
/**
- * test input with special chars
+ * Test input with special chars
*/
public function testAttributeContainsSpecialChars() {
$testAttr="--... %\$รค() /(=?}";
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/get_tags_test.php b/tests/unit/GetTagsTest.php
index bdffd8311..418d32c47 100644
--- a/tests/unit/get_tags_test.php
+++ b/tests/unit/GetTagsTest.php
@@ -1,110 +1,104 @@
<?php
/**
* This file contains the tests for get_tags and the tag handling in item.php
- *
+ *
* @package test.util
*/
/**
- * required, because it contains the get_tags() function
- */
-require_once 'include/text.php';
-/**
- * required, because it contains the tag handling
- */
-require_once 'mod/item.php';
-
-/**
* A class which can be used as replacement for an app if
- * only get_baseurl is used.
- *
- * @author Alexander Kampmann
+ * only get_baseurl is used.
+ *
+ * @author Alexander Kampmann
* @package test.util
*/
class MockApp {
function get_baseurl() {
- return "baseurl";
+ return "baseurl";
}
-};
+}
/**
- * the test should not rely on a database,
- * so this is a replacement for the database access method q.
- *
- * It simulates the user with uid 11 has one contact, named Mike Lastname.
- *
+ * The test should not rely on a database,
+ * so this is a replacement for the database access method q.
+ *
+ * It simulates the user with uid 11 has one contact, named Mike Lastname.
+ *
* @param string $sql
*/
function q($sql) {
- $result=array(array('id'=>15,
- 'attag'=>'', 'network'=>'dfrn',
- 'name'=>'Mike Lastname', 'alias'=>'Mike',
- 'nick'=>'Mike', 'url'=>"http://justatest.de"));
-
- $args=func_get_args();
+ $result=array(array('id'=>15,
+ 'attag'=>'', 'network'=>'dfrn',
+ 'name'=>'Mike Lastname', 'alias'=>'Mike',
+ 'nick'=>'Mike', 'url'=>"http://justatest.de"));
+
+ $args=func_get_args();
//last parameter is always (in this test) uid, so, it should be 11
if($args[count($args)-1]!=11) {
- return;
+ return;
}
-
-
+
+
if(3==count($args)) {
//first call in handle_body, id only
if($result[0]['id']==$args[1]) {
- return $result;
+ return $result;
}
//second call in handle_body, name
- if($result[0]['name']===$args[1]) {
- return $result;
+ if($result[0]['name']===$args[1]) {
+ return $result;
}
}
//third call in handle_body, nick or attag
- if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
- return $result;
+ if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
+ return $result;
}
}
/**
- * replacement for dbesc.
+ * Replacement for dbesc.
* I don't want to test dbesc here, so
- * I just return the input. It won't be a problem, because
- * the test does not use a real database.
- *
+ * I just return the input. It won't be a problem, because
+ * the test does not use a real database.
+ *
* DON'T USE HAT FUNCTION OUTSIDE A TEST!
- *
+ *
* @param string $str
+ *
* @return input
*/
function dbesc($str) {
- return $str;
+ return $str;
}
/**
- * TestCase for tag handling.
- *
- * @author alexander
+ * TestCase for tag handling.
+ *
+ * @author alexander
* @package test.util
*/
-class GetTagsTest extends PHPUnit_Framework_TestCase {
- /** the mock to use as app */
- private $a;
+class GetTagsTest extends Zotlabs\Tests\Unit\UnitTestCase {
+ /**
+ * The mock to use as app
+ */
+ private $a;
/**
- * initialize the test. That's a phpUnit function,
+ * Initialize the test. That's a phpUnit function,
* don't change its name.
- */
- public function setUp() {
- $this->a=new MockApp();
+ */
+ public function setUp() : void {
+ $this->a = new MockApp();
}
- /**
- * test with one Person tag
- */
- public function testGetTagsShortPerson() {
- $text="hi @Mike";
-
- $tags=get_tags($text);
+ /**
+ * Test with one Person tag
+ */
+ public function testGetTagsShortPerson() {
+ $text="hi @Mike";
+
+ $tags=get_tags($text);
$str_tags='';
foreach($tags as $tag) {
@@ -112,206 +106,176 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
}
//correct tags found?
- $this->assertEquals(1, count($tags));
+ $this->assertEquals(1, count($tags));
$this->assertTrue(in_array("@Mike", $tags));
-
+
//correct output from handle_tag?
- $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
- $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text);
+ //$this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
+ //$this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text);
}
-
- /**
- * test with one Person tag.
- * There's a minor spelling mistake...
- */
- public function testGetTagsShortPersonSpelling() {
- $text="hi @Mike.because";
-
- $tags=get_tags($text);
-
- //correct tags found?
- $this->assertEquals(1, count($tags));
+
+ /**
+ * Test with one Person tag.
+ * There's a minor spelling mistake...
+ */
+ public function testGetTagsShortPersonSpelling() {
+ $text="hi @Mike.because";
+
+ $tags=get_tags($text);
+
+ //correct tags found?
+ $this->assertEquals(1, count($tags));
$this->assertTrue(in_array("@Mike.because", $tags));
-
- $str_tags='';
- handle_tag($text, $str_tags, 11, $tags[0]);
-
+
+ $str_tags='';
+ handle_tag($text, $str_tags, 11, $tags[0]);
+
// (mike) - This is a tricky case.
// we support mentions as in @mike@example.com - which contains a period.
// This shouldn't match anything unless you have a contact named "Mike.because".
// We may need another test for "@Mike. because" - which should return the contact
- // as we ignore trailing periods in tags.
-
-// $this->assertEquals("cid:15", $inform);
+ // as we ignore trailing periods in tags.
+
+// $this->assertEquals("cid:15", $inform);
// $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
-// $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url].because", $text);
+// $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url].because", $text);
$this->assertEquals("", $str_tags);
}
-
- /**
- * test with two Person tags.
- * There's a minor spelling mistake...
- */
-
- public function testGetTagsPerson2Spelling() {
- $text="hi @Mike@campino@friendica.eu";
-
- $tags=get_tags($text);
-
-// This construct is not supported. Results are indeterminate
-// $this->assertEquals(2, count($tags));
-// $this->assertTrue(in_array("@Mike", $tags));
-// $this->assertTrue(in_array("@campino@friendica.eu", $tags));
- }
/**
* Test with one hash tag.
- */
- public function testGetTagsShortTag() {
- $text="This is a #test_case";
-
- $tags=get_tags($text);
+ */
+ public function testGetTagsShortTag() {
+ $text="This is a #test_case";
+
+ $tags=get_tags($text);
- $this->assertEquals(1, count($tags));
- $this->assertTrue(in_array("#test_case", $tags));
- }
+ $this->assertEquals(1, count($tags));
+ $this->assertTrue(in_array("#test_case", $tags));
+ }
/**
- * test with a person and a hash tag
- */
- public function testGetTagsShortTagAndPerson() {
- $text="hi @Mike This is a #test_case";
-
- $tags=get_tags($text);
-
- $this->assertEquals(3, count($tags));
+ * Test with a person and a hash tag
+ */
+ public function testGetTagsShortTagAndPerson() {
+ $text="hi @Mike This is a #test_case";
+
+ $tags=get_tags($text);
+
+ $this->assertEquals(2, count($tags));
$this->assertTrue(in_array("@Mike", $tags));
- $this->assertTrue(in_array("@Mike This", $tags));
- $this->assertTrue(in_array("#test_case", $tags));
+ $this->assertTrue(in_array("#test_case", $tags));
$str_tags='';
foreach($tags as $tag) {
handle_tag($text, $str_tags, 11, $tag);
}
-
- $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?tag=test%20case]test case[/url]", $str_tags);
- $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?tag=test%20case]test case[/url]", $text);
-
- }
+
+ //$this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?tag=test%20case]test case[/url]", $str_tags);
+ //$this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?tag=test%20case]test case[/url]", $text);
+
+ }
/**
- * test with a person, a hash tag and some special chars.
- */
- public function testGetTagsShortTagAndPersonSpecialChars() {
- $text="hi @Mike, This is a #test_case.";
-
- $tags=get_tags($text);
-
+ * Test with a person, a hash tag and some special chars.
+ */
+ public function testGetTagsShortTagAndPersonSpecialChars() {
+ $text="hi @Mike, This is a #test_case.";
+
+ $tags=get_tags($text);
+
$this->assertEquals(2, count($tags));
$this->assertTrue(in_array("@Mike", $tags));
- $this->assertTrue(in_array("#test_case", $tags));
- }
+ $this->assertTrue(in_array("#test_case", $tags));
+ }
/**
* Test with a person tag and text behind it.
- */
- public function testGetTagsPersonOnly() {
- $text="@Test I saw the Theme Dev group was created.";
-
- $tags=get_tags($text);
+ */
+ public function testGetTagsPersonOnly() {
+ $text="@Test I saw the Theme Dev group was created.";
- $this->assertEquals(2, count($tags));
- $this->assertTrue(in_array("@Test I", $tags));
- $this->assertTrue(in_array("@Test", $tags));
- }
+ $tags=get_tags($text);
- /**
- * this test demonstrates strange behaviour by intval.
- * It makes the next test fail.
- */
- public function testIntval() {
- $this->assertEquals(15, intval("15 it"));
+ $this->assertEquals(1, count($tags));
+ $this->assertTrue(in_array("@Test", $tags));
}
-
+
/**
- * test a tag with an id in it
+ * Test a tag with an id in it
*/
public function testIdTag() {
- $text="Test with @mike+15 id tag";
-
- $tags=get_tags($text);
-
- $this->assertEquals(2, count($tags));
+ $text="Test with @mike+15 id tag";
+
+ $tags=get_tags($text);
+
+ $this->assertEquals(1, count($tags));
$this->assertTrue(in_array("@mike+15", $tags));
-
- //happens right now, but it shouldn't be necessary
- $this->assertTrue(in_array("@mike+15 id", $tags));
-
+
$str_tags='';
foreach($tags as $tag) {
handle_tag($text, $str_tags, 11, $tag);
}
-
- $this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text);
- $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
+
+ //$this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text);
+ //$this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
}
-
+
/**
- * test with two persons and one special tag.
- */
- public function testGetTags2Persons1TagSpecialChars() {
- $text="hi @Mike, I'm just writing #test_cases, so"
- ." so @somebody@friendica.com may change #things.";
-
- $tags=get_tags($text);
-
- $this->assertEquals(5, count($tags));
- $this->assertTrue(in_array("@Mike", $tags));
+ * Test with two persons and one special tag.
+ */
+ public function testGetTags2Persons1TagSpecialChars() {
+ $text="hi @Mike, I'm just writing #test_cases, so"
+ . " so @somebody@friendica.com may change #things.";
+
+ $tags=get_tags($text);
+
+ $this->assertEquals(4, count($tags));
+ $this->assertTrue(in_array("@Mike", $tags));
$this->assertTrue(in_array("#test_cases", $tags));
- $this->assertTrue(in_array("@somebody@friendica.com", $tags));
- $this->assertTrue(in_array("@somebody@friendica.com may", $tags));
- $this->assertTrue(in_array("#things", $tags));
- }
+ $this->assertTrue(in_array("@somebody@friendica.com", $tags));
+ $this->assertTrue(in_array("#things", $tags));
+ }
/**
- * test with a long text.
- */
- public function testGetTags() {
- $text="hi @Mike, I'm just writing #test_cases, "
- ." so @somebody@friendica.com may change #things. Of course I "
- ."look for a lot of #pitfalls, like #tags at the end of a sentence "
- ."@comment. I hope noone forgets about @fullstops.because that might"
- ." break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "
- ."Now, add a @first_last tag. ";
-
- $tags=get_tags($text);
-
- $this->assertTrue(in_array("@Mike", $tags));
- $this->assertTrue(in_array("#test_cases", $tags));
- $this->assertTrue(in_array("@somebody@friendica.com", $tags));
- $this->assertTrue(in_array("#things", $tags));
- $this->assertTrue(in_array("#pitfalls", $tags));
- $this->assertTrue(in_array("#tags", $tags));
- $this->assertTrue(in_array("@comment", $tags));
- $this->assertTrue(in_array("@fullstops.because", $tags));
- $this->assertTrue(in_array("#things", $tags));
- $this->assertTrue(in_array("@Mike", $tags));
- $this->assertTrue(in_array("#nice", $tags));
+ * Test with a long text.
+ */
+ public function testGetTags() {
+ $text="hi @Mike, I'm just writing #test_cases, "
+ . " so @somebody@friendica.com may change #things. Of course I "
+ . "look for a lot of #pitfalls, like #tags at the end of a sentence "
+ . "@comment. I hope noone forgets about @fullstops.because that might"
+ . " break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "
+ . "Now, add a @first_last tag. ";
+
+ $tags=get_tags($text);
+
+ $this->assertTrue(in_array("@Mike", $tags));
+ $this->assertTrue(in_array("#test_cases", $tags));
+ $this->assertTrue(in_array("@somebody@friendica.com", $tags));
+ $this->assertTrue(in_array("#things", $tags));
+ $this->assertTrue(in_array("#pitfalls", $tags));
+ $this->assertTrue(in_array("#tags", $tags));
+ $this->assertTrue(in_array("@comment", $tags));
+ $this->assertTrue(in_array("@fullstops.because", $tags));
+ $this->assertTrue(in_array("#things", $tags));
+ $this->assertTrue(in_array("@Mike", $tags));
+ $this->assertTrue(in_array("#nice", $tags));
$this->assertTrue(in_array("@first_last", $tags));
-
+
//right now, none of the is matched (unsupported)
-// $this->assertFalse(in_array("@Mike@campino@friendica.eu", $tags));
+// $this->assertFalse(in_array("@Mike@campino@friendica.eu", $tags));
// $this->assertTrue(in_array("@campino@friendica.eu", $tags));
-// $this->assertTrue(in_array("@campino@friendica.eu is", $tags));
- }
+// $this->assertTrue(in_array("@campino@friendica.eu is", $tags));
+ }
/**
- * test with an empty string
- */
- public function testGetTagsEmpty() {
- $tags=get_tags("");
- $this->assertEquals(0, count($tags));
+ * Test with an empty string
+ */
+ public function testGetTagsEmpty() {
+ $tags=get_tags("");
+ $this->assertEquals(0, count($tags));
}
-} \ No newline at end of file
+}