6 require_once 'include/template_processor.php';
\r
7 require_once 'include/text.php';
8 require_once 'mod/item.php';
12 $result=array(array('id'=>15,
13 'attag'=>'', 'network'=>'dfrn',
14 'name'=>'Mike Lastname', 'alias'=>'Mike',
15 'nick'=>'Mike', 'url'=>"http://justatest.de"));
17 $args=func_get_args();
20 foreach($args as $arg) {
24 //last parameter is always (in this test) uid, so, it should be 11
25 if($args[count($args)-1]!=11) {
26 throw new Exception("q from get_tags_test was used and uid was not 11. ");
30 //first call in handle_body, id only
31 if($result[0]['id']===$args[1]) {
34 throw new Exception($str);
35 //second call in handle_body, name
36 if($result[0]['name']===$args[1]) {
\r
40 throw new Exception($str);
41 //third call in handle_body, nick or attag
42 if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
\r
45 // throw new Exception("Nothing fitted: ".$args[1].", ".$args[2]);
48 function dbesc($str) {
52 class GetTagsTest extends PHPUnit_Framework_TestCase {
\r
54 public function setUp() {
\r
56 get_include_path() . PATH_SEPARATOR
\r
57 . 'include' . PATH_SEPARATOR
\r
58 . 'library' . PATH_SEPARATOR
\r
59 . 'library/phpsec' . PATH_SEPARATOR
\r
64 * test with one Person tag
\r
66 public function testGetTagsShortPerson() {
\r
69 $tags=get_tags($text);
\r
73 handle_body($text, $inform, $str_tags, 11, $tags[0]);
75 $this->assertEquals("@Mike", $tags[0]);
76 $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text);
\r
80 * Test with one hash tag.
82 public function testGetTagsShortTag() {
\r
83 $text="This is a #test_case";
\r
85 $tags=get_tags($text);
\r
87 $this->assertEquals("#test_case", $tags[0]);
\r
91 * test with a person and a hash tag
93 public function testGetTagsShortTagAndPerson() {
\r
94 $text="hi @Mike This is a #test_case";
\r
96 $tags=get_tags($text);
\r
100 handle_body($text, $inform, $str_tags, 11, $tags[0]);
102 $this->assertEquals("hi @[url=http://justatest.de]Mike[/url] This is a #test_case", $text);
\r
103 $this->assertEquals("@Mike", $tags[0]);
\r
104 $this->assertEquals("#test_case", $tags[1]);
\r
108 * test with a person, a hash tag and some special chars.
110 public function testGetTagsShortTagAndPersonSpecialChars() {
\r
111 $text="hi @Mike, This is a #test_case.";
\r
113 $tags=get_tags($text);
\r
115 $this->assertEquals("@Mike", $tags[0]);
\r
116 $this->assertEquals("#test_case", $tags[1]);
\r
120 * Test with a person tag and text behind it.
122 public function testGetTagsPersonOnly() {
\r
123 $text="@Test I saw the Theme Dev group was created.";
\r
125 $tags=get_tags($text);
\r
127 $this->assertEquals("@Test", $tags[0]);
\r
131 * test with two persons and one special tag.
133 public function testGetTags2Persons1TagSpecialChars() {
\r
134 $text="hi @Mike, I'm just writing #test_cases, so"
\r
135 ." so @somebody@friendica.com may change #things.";
\r
137 $tags=get_tags($text);
\r
139 $this->assertEquals("@Mike", $tags[0]);
\r
140 $this->assertEquals("#test_cases", $tags[1]);
\r
141 $this->assertEquals("@somebody@friendica.com", $tags[2]);
\r
142 $this->assertEquals("#things", $tags[3]);
\r
146 * test with a long text.
148 public function testGetTags() {
\r
149 $text="hi @Mike, I'm just writing #test_cases, "
\r
150 ." so @somebody@friendica.com may change #things. Of course I "
\r
151 ."look for a lot of #pitfalls, like #tags at the end of a sentence "
\r
152 ."@comment. I hope noone forgets about @fullstops.because that might"
\r
153 ." break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "
\r
154 ."Now, add a @first_last tag. ";
\r
155 //TODO check whether this are all variants (no, auto-stuff is missing).
\r
157 $tags=get_tags($text);
\r
159 $this->assertEquals("@Mike", $tags[0]);
\r
160 $this->assertEquals("#test_cases", $tags[1]);
\r
161 $this->assertEquals("@somebody@friendica.com", $tags[2]);
\r
162 $this->assertEquals("#things", $tags[3]);
\r
163 $this->assertEquals("#pitfalls", $tags[4]);
\r
164 $this->assertEquals("#tags", $tags[5]);
\r
165 $this->assertEquals("@comment", $tags[6]);
\r
166 $this->assertEquals("@fullstops", $tags[7]);
\r
167 $this->assertEquals("#things", $tags[8]);
\r
168 $this->assertEquals("@Mike", $tags[9]);
\r
169 $this->assertEquals("@campino@friendica.eu", $tags[10]);
\r
170 $this->assertEquals("#nice", $tags[11]);
\r
171 $this->assertEquals("@first_last", $tags[12]);
\r
175 * test with an empty string
177 public function testGetTagsEmpty() {
\r
178 $tags=get_tags("");
\r
179 $this->assertEquals(0, count($tags));
\r