]> git.mxchange.org Git - friendica.git/blobdiff - tests/get_tags_test.php
Merge pull request #3444 from annando/1705-mail-duplicates
[friendica.git] / tests / get_tags_test.php
index 9051923be062927da944726bdf900c1d802544d1..79dcb36a7f4c1800b6e84b89fbe73eb63712795a 100644 (file)
@@ -55,13 +55,13 @@ function q($sql) {
                        return $result; 
                }
                //second call in handle_body, name
-               if($result[0]['name']===$args[1]) {\r
-                       return $result;\r
+               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]) {\r
-               return $result;\r
+       if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
+               return $result;
        }
 }
 
@@ -88,23 +88,23 @@ function dbesc($str) {
  */
 class GetTagsTest extends PHPUnit_Framework_TestCase {
        /** the mock to use as app */
-       private $a; \r
+       private $a; 
 
        /**
         * initialize the test. That's a phpUnit function, 
         * don't change its name.
-        */\r
-       public function setUp() {\r
+        */
+       public function setUp() {
                $this->a=new MockApp(); 
        }
 
-       /**\r
-        * test with one Person tag\r
-        */\r
-       public function testGetTagsShortPerson() {\r
-               $text="hi @Mike";\r
-\r
-               $tags=get_tags($text);\r
+       /**
+        * test with one Person tag
+        */
+       public function testGetTagsShortPerson() {
+               $text="hi @Mike";
+
+               $tags=get_tags($text);
 
                $inform=''; 
                $str_tags='';
@@ -113,113 +113,125 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
                }
 
                //correct tags found?
-               $this->assertEquals(1, count($tags)); \r
+               $this->assertEquals(1, count($tags)); 
                $this->assertTrue(in_array("@Mike", $tags));
                
                //correct output from handle_tag?
                $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]", $text);\r
+               $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text);
        }
        
-       /**\r
+       /**
         * test with one Person tag. 
-        * There's a minor spelling mistake...\r
-        */\r
-       public function testGetTagsShortPersonSpelling() {\r
-               $text="hi @Mike.because";\r
-       \r
-               $tags=get_tags($text);\r
+        * There's a minor spelling mistake...
+        */
+       public function testGetTagsShortPersonSpelling() {
+               $text="hi @Mike.because";
+       
+               $tags=get_tags($text);
        
-               //correct tags found?\r
-               $this->assertEquals(1, count($tags));\r
+               //correct tags found?
+               $this->assertEquals(1, count($tags));
                $this->assertTrue(in_array("@Mike.because", $tags));
-               \r
-               $inform='';\r
-               $str_tags='';\r
-               handle_tag($this->a, $text, $inform, $str_tags, 11, $tags[0]);\r
-       \r
-               $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);\r
+               
+               $inform='';
+               $str_tags='';
+               handle_tag($this->a, $text, $inform, $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); 
+//             $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("", $inform); 
+               $this->assertEquals("", $str_tags);
+
        }
        
-       /**\r
+       /**
         * test with two Person tags. 
-        * There's a minor spelling mistake...\r
-        */\r
-       public function testGetTagsPerson2Spelling() {\r
-               $text="hi @Mike@campino@friendica.eu";\r
-       \r
-               $tags=get_tags($text);\r
+        * There's a minor spelling mistake...
+        */
+
+       public function testGetTagsPerson2Spelling() {
+               $text="hi @Mike@campino@friendica.eu";
        
-               $this->assertEquals(2, count($tags)); \r
-               $this->assertTrue(in_array("@Mike", $tags));
-               $this->assertTrue(in_array("@campino@friendica.eu", $tags));\r
-       }\r
+               $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.
-        */\r
-       public function testGetTagsShortTag() {\r
-               $text="This is a #test_case";\r
-\r
-               $tags=get_tags($text);\r
+        */
+       public function testGetTagsShortTag() {
+               $text="This is a #test_case";
+
+               $tags=get_tags($text);
 
-               $this->assertEquals(1, count($tags));\r
-               $this->assertTrue(in_array("#test_case", $tags));\r
-       }\r
+               $this->assertEquals(1, count($tags));
+               $this->assertTrue(in_array("#test_case", $tags));
+       }
 
        /**
         * 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
+        */
+       public function testGetTagsShortTagAndPerson() {
+               $text="hi @Mike This is a #test_case";
+
+               $tags=get_tags($text);
 
                $this->assertEquals(3, count($tags));
                $this->assertTrue(in_array("@Mike", $tags));
-               $this->assertTrue(in_array("@Mike This", $tags));\r
-               $this->assertTrue(in_array("#test_case", $tags));\r
+               $this->assertTrue(in_array("@Mike This", $tags));
+               $this->assertTrue(in_array("#test_case", $tags));
 
                $inform='';
                $str_tags='';
                foreach($tags as $tag) {
                        handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
                }
-               \r
+               
                $this->assertEquals("cid:15", $inform); 
-               $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?search=test%20case]test case[/url]", $str_tags);
-               $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?search=test%20case]test case[/url]", $text); 
-               \r
-       }\r
+               $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.
-        */\r
-       public function testGetTagsShortTagAndPersonSpecialChars() {\r
-               $text="hi @Mike, This is a #test_case.";\r
-\r
-               $tags=get_tags($text);\r
-\r
+        */
+       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));\r
-       }\r
+               $this->assertTrue(in_array("#test_case", $tags));
+       }
 
        /**
         * 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
+        */
+       public function testGetTagsPersonOnly() {
+               $text="@Test I saw the Theme Dev group was created.";
+
+               $tags=get_tags($text);
 
-               $this->assertEquals(2, count($tags));\r
+               $this->assertEquals(2, count($tags));
                $this->assertTrue(in_array("@Test I", $tags));
-               $this->assertTrue(in_array("@Test", $tags));\r
-       }\r
+               $this->assertTrue(in_array("@Test", $tags));
+       }
 
        /**
         * this test demonstrates strange behaviour by intval. 
@@ -243,71 +255,72 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
                //happens right now, but it shouldn't be necessary
                $this->assertTrue(in_array("@mike+15 id", $tags));
                
-               $inform='';\r
+               $inform='';
                $str_tags='';
                foreach($tags as $tag) {
                        handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
                }
                
-               $this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text);\r
-               $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);\r
-               $this->assertEquals("cid:15", $inform);
+               $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 test may produce two cid:15 entries - which is OK because duplicates are pruned before delivery
+               $this->assertContains("cid:15",$inform);
        }
        
        /**
         * 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
-
-               $this->assertEquals(5, count($tags));\r
-               $this->assertTrue(in_array("@Mike", $tags));\r
+        */
+       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));
                $this->assertTrue(in_array("#test_cases", $tags));
-               $this->assertTrue(in_array("@somebody@friendica.com", $tags));\r
-               $this->assertTrue(in_array("@somebody@friendica.com may", $tags));\r
-               $this->assertTrue(in_array("#things", $tags));\r
-       }\r
+               $this->assertTrue(in_array("@somebody@friendica.com", $tags));
+               $this->assertTrue(in_array("@somebody@friendica.com may", $tags));
+               $this->assertTrue(in_array("#things", $tags));
+       }
 
        /**
         * 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
-               \r
-               $tags=get_tags($text);\r
-\r
-               $this->assertTrue(in_array("@Mike", $tags));\r
-               $this->assertTrue(in_array("#test_cases", $tags));\r
-               $this->assertTrue(in_array("@somebody@friendica.com", $tags));\r
-               $this->assertTrue(in_array("#things", $tags));\r
-               $this->assertTrue(in_array("#pitfalls", $tags));\r
-               $this->assertTrue(in_array("#tags", $tags));\r
-               $this->assertTrue(in_array("@comment", $tags));\r
-               $this->assertTrue(in_array("@fullstops.because", $tags));\r
-               $this->assertTrue(in_array("#things", $tags));\r
-               $this->assertTrue(in_array("@Mike", $tags));\r
-               $this->assertTrue(in_array("#nice", $tags));\r
+        */
+       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
-               $this->assertFalse(in_array("@Mike@campino@friendica.eu", $tags));\r
-               $this->assertTrue(in_array("@campino@friendica.eu", $tags));
-               $this->assertTrue(in_array("@campino@friendica.eu is", $tags));\r
-       }\r
+               //right now, none of the is matched (unsupported)
+//             $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));
+       }
 
        /**
         * test with an empty string
-        */\r
-       public function testGetTagsEmpty() {\r
-               $tags=get_tags("");\r
-               $this->assertEquals(0, count($tags));\r
+        */
+       public function testGetTagsEmpty() {
+               $tags=get_tags("");
+               $this->assertEquals(0, count($tags));
        }
-}
\ No newline at end of file
+}