]> git.mxchange.org Git - friendica.git/blob - tests/get_tags_test.php
splitted test cases.
[friendica.git] / tests / get_tags_test.php
1 <?php
2 /**
3  * @package test.util
4  */
5
6 require_once 'include/template_processor.php';\r
7 require_once 'include/text.php';
8 require_once 'mod/item.php';
9
10 function q($sql) {
11         return array(array('id'=>15, 'network'=>'stat', 'alias'=>'Mike', 'nick'=>'Mike', 'url'=>"http://justatest.de"));
12
13 }
14 function dbesc($str) {
15         echo $str; 
16 }
17
18 class GetTagsTest extends PHPUnit_Framework_TestCase {\r
19 \r
20         public function setUp() {\r
21                 set_include_path(\r
22                                 get_include_path() . PATH_SEPARATOR\r
23                                 . 'include' . PATH_SEPARATOR\r
24                                 . 'library' . PATH_SEPARATOR\r
25                                 . 'library/phpsec' . PATH_SEPARATOR\r
26                                 . '.' );\r
27         }
28
29         /**\r
30          * test with one Person tag\r
31          */\r
32         public function testGetTagsShortPerson() {\r
33                 $text="hi @Mike";\r
34 \r
35                 $tags=get_tags($text);\r
36
37                 $inform=''; 
38                 $str_tags='';
39                 handle_body($text, $inform, $str_tags, 11, $tags[0]);
40 \r
41                 $this->assertEquals("@Mike", $tags[0]);
42                 $this->assertEquals($text, "hi @[url=http://justatest.de]Mike[/url]");\r
43         }\r
44
45         /**
46          * Test with one hash tag.
47          */\r
48         public function testGetTagsShortTag() {\r
49                 $text="This is a #test_case";\r
50 \r
51                 $tags=get_tags($text);\r
52 \r
53                 $this->assertEquals("#test_case", $tags[0]);\r
54         }\r
55
56         /**
57          * test with a person and a hash tag
58          */\r
59         public function testGetTagsShortTagAndPerson() {\r
60                 $text="hi @Mike This is a #test_case";\r
61 \r
62                 $tags=get_tags($text);\r
63
64                 $inform='';\r
65                 $str_tags='';\r
66                 handle_body($text, $inform, $str_tags, 11, $tags[0]);
67                 
68                 $this->assertEquals("hi @[url=http://justatest.de]Mike[/url] This is a #test_case", $text); \r
69                 $this->assertEquals("@Mike", $tags[0]);\r
70                 $this->assertEquals("#test_case", $tags[1]);\r
71         }\r
72
73         /**
74          * test with a person, a hash tag and some special chars.
75          */\r
76         public function testGetTagsShortTagAndPersonSpecialChars() {\r
77                 $text="hi @Mike, This is a #test_case.";\r
78 \r
79                 $tags=get_tags($text);\r
80 \r
81                 $this->assertEquals("@Mike", $tags[0]);\r
82                 $this->assertEquals("#test_case", $tags[1]);\r
83         }\r
84
85         /**
86          * Test with a person tag and text behind it.
87          */\r
88         public function testGetTagsPersonOnly() {\r
89                 $text="@Test I saw the Theme Dev group was created.";\r
90 \r
91                 $tags=get_tags($text);\r
92 \r
93                 $this->assertEquals("@Test", $tags[0]);\r
94         }\r
95
96         /**
97          * test with two persons and one special tag.
98          */\r
99         public function testGetTags2Persons1TagSpecialChars() {\r
100                 $text="hi @Mike, I'm just writing #test_cases, so"\r
101                 ." so @somebody@friendica.com may change #things.";\r
102 \r
103                 $tags=get_tags($text);\r
104 \r
105                 $this->assertEquals("@Mike", $tags[0]);\r
106                 $this->assertEquals("#test_cases", $tags[1]);\r
107                 $this->assertEquals("@somebody@friendica.com", $tags[2]);\r
108                 $this->assertEquals("#things", $tags[3]);\r
109         }\r
110
111         /**
112          * test with a long text.
113          */\r
114         public function testGetTags() {\r
115                 $text="hi @Mike, I'm just writing #test_cases, "\r
116                 ." so @somebody@friendica.com may change #things. Of course I "\r
117                 ."look for a lot of #pitfalls, like #tags at the end of a sentence "\r
118                 ."@comment. I hope noone forgets about @fullstops.because that might"\r
119                 ." break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "\r
120                 ."Now, add a @first_last tag. ";\r
121                 //TODO check whether this are all variants (no, auto-stuff is missing).\r
122 \r
123                 $tags=get_tags($text);\r
124 \r
125                 $this->assertEquals("@Mike", $tags[0]);\r
126                 $this->assertEquals("#test_cases", $tags[1]);\r
127                 $this->assertEquals("@somebody@friendica.com", $tags[2]);\r
128                 $this->assertEquals("#things", $tags[3]);\r
129                 $this->assertEquals("#pitfalls", $tags[4]);\r
130                 $this->assertEquals("#tags", $tags[5]);\r
131                 $this->assertEquals("@comment", $tags[6]);\r
132                 $this->assertEquals("@fullstops", $tags[7]);\r
133                 $this->assertEquals("#things", $tags[8]);\r
134                 $this->assertEquals("@Mike", $tags[9]);\r
135                 $this->assertEquals("@campino@friendica.eu", $tags[10]);\r
136                 $this->assertEquals("#nice", $tags[11]);\r
137                 $this->assertEquals("@first_last", $tags[12]);\r
138         }\r
139
140         /**
141          * test with an empty string
142          */\r
143         public function testGetTagsEmpty() {\r
144                 $tags=get_tags("");\r
145                 $this->assertEquals(0, count($tags));\r
146         }
147 }