+<?php
+/**
+ * @package test.util
+ */
+
+require_once 'include/template_processor.php';\r
+require_once 'include/text.php';
+require_once 'mod/item.php';
+
+function q($sql) {
+ return array(array('id'=>15, 'network'=>'stat', 'alias'=>'Mike', 'nick'=>'Mike', 'url'=>"http://justatest.de"));
+
+}
+function dbesc($str) {
+ echo $str;
+}
+
+class GetTagsTest extends PHPUnit_Framework_TestCase {\r
+\r
+ public function setUp() {\r
+ set_include_path(\r
+ get_include_path() . PATH_SEPARATOR\r
+ . 'include' . PATH_SEPARATOR\r
+ . 'library' . PATH_SEPARATOR\r
+ . 'library/phpsec' . PATH_SEPARATOR\r
+ . '.' );\r
+ }
+
+ /**\r
+ * test with one Person tag\r
+ */\r
+ public function testGetTagsShortPerson() {\r
+ $text="hi @Mike";\r
+\r
+ $tags=get_tags($text);\r
+
+ $inform='';
+ $str_tags='';
+ handle_body($text, $inform, $str_tags, 11, $tags[0]);
+\r
+ $this->assertEquals("@Mike", $tags[0]);
+ $this->assertEquals($text, "hi @[url=http://justatest.de]Mike[/url]");\r
+ }\r
+
+ /**
+ * Test with one hash tag.
+ */\r
+ public function testGetTagsShortTag() {\r
+ $text="This is a #test_case";\r
+\r
+ $tags=get_tags($text);\r
+\r
+ $this->assertEquals("#test_case", $tags[0]);\r
+ }\r
+
+ /**
+ * test with a person and a hash tag
+ */\r
+ public function testGetTagsShortTagAndPerson() {\r
+ $text="hi @Mike This is a #test_case";\r
+\r
+ $tags=get_tags($text);\r
+
+ $inform='';\r
+ $str_tags='';\r
+ handle_body($text, $inform, $str_tags, 11, $tags[0]);
+
+ $this->assertEquals("hi @[url=http://justatest.de]Mike[/url] This is a #test_case", $text); \r
+ $this->assertEquals("@Mike", $tags[0]);\r
+ $this->assertEquals("#test_case", $tags[1]);\r
+ }\r
+
+ /**
+ * test with a person, a hash tag and some special chars.
+ */\r
+ public function testGetTagsShortTagAndPersonSpecialChars() {\r
+ $text="hi @Mike, This is a #test_case.";\r
+\r
+ $tags=get_tags($text);\r
+\r
+ $this->assertEquals("@Mike", $tags[0]);\r
+ $this->assertEquals("#test_case", $tags[1]);\r
+ }\r
+
+ /**
+ * Test with a person tag and text behind it.
+ */\r
+ public function testGetTagsPersonOnly() {\r
+ $text="@Test I saw the Theme Dev group was created.";\r
+\r
+ $tags=get_tags($text);\r
+\r
+ $this->assertEquals("@Test", $tags[0]);\r
+ }\r
+
+ /**
+ * test with two persons and one special tag.
+ */\r
+ public function testGetTags2Persons1TagSpecialChars() {\r
+ $text="hi @Mike, I'm just writing #test_cases, so"\r
+ ." so @somebody@friendica.com may change #things.";\r
+\r
+ $tags=get_tags($text);\r
+\r
+ $this->assertEquals("@Mike", $tags[0]);\r
+ $this->assertEquals("#test_cases", $tags[1]);\r
+ $this->assertEquals("@somebody@friendica.com", $tags[2]);\r
+ $this->assertEquals("#things", $tags[3]);\r
+ }\r
+
+ /**
+ * test with a long text.
+ */\r
+ public function testGetTags() {\r
+ $text="hi @Mike, I'm just writing #test_cases, "\r
+ ." so @somebody@friendica.com may change #things. Of course I "\r
+ ."look for a lot of #pitfalls, like #tags at the end of a sentence "\r
+ ."@comment. I hope noone forgets about @fullstops.because that might"\r
+ ." break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "\r
+ ."Now, add a @first_last tag. ";\r
+ //TODO check whether this are all variants (no, auto-stuff is missing).\r
+\r
+ $tags=get_tags($text);\r
+\r
+ $this->assertEquals("@Mike", $tags[0]);\r
+ $this->assertEquals("#test_cases", $tags[1]);\r
+ $this->assertEquals("@somebody@friendica.com", $tags[2]);\r
+ $this->assertEquals("#things", $tags[3]);\r
+ $this->assertEquals("#pitfalls", $tags[4]);\r
+ $this->assertEquals("#tags", $tags[5]);\r
+ $this->assertEquals("@comment", $tags[6]);\r
+ $this->assertEquals("@fullstops", $tags[7]);\r
+ $this->assertEquals("#things", $tags[8]);\r
+ $this->assertEquals("@Mike", $tags[9]);\r
+ $this->assertEquals("@campino@friendica.eu", $tags[10]);\r
+ $this->assertEquals("#nice", $tags[11]);\r
+ $this->assertEquals("@first_last", $tags[12]);\r
+ }\r
+
+ /**
+ * test with an empty string
+ */\r
+ public function testGetTagsEmpty() {\r
+ $tags=get_tags("");\r
+ $this->assertEquals(0, count($tags));\r
+ }
+}
\ No newline at end of file