]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/StringsTest.php
Revert "Move methods to new Util/Strings class"
[friendica.git] / tests / src / Util / StringsTest.php
1 <?php
2 /**
3  * @file tests/src/Util/StringsTest.php
4  */
5 namespace Friendica\Test\Util;
6
7 use Friendica\Util\Strings;
8 use PHPUnit\Framework\TestCase;
9
10 /**
11  * @brief Strings utility test class
12  */
13 class StringsTest extends TestCase
14 {
15     /**
16         * escape and unescape
17         */
18         public function testEscapeUnescape()
19         {
20                 $text="<tag>I want to break\n this!11!<?hard?></tag>";
21                 $xml=XML::escape($text);
22                 $retext=XML::unescape($text);
23                 $this->assertEquals($text, $retext);
24     }
25     
26         /**
27          * escape and put in a document
28          */
29         public function testEscapeDocument()
30         {
31                 $tag="<tag>I want to break</tag>";
32                 $xml=XML::escape($tag);
33                 $text='<text>'.$xml.'</text>';
34                 $xml_parser=xml_parser_create();
35                 //should be possible to parse it
36                 $values=array();
37                 $index=array();
38                 $this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index));
39                 $this->assertEquals(
40                         array('TEXT'=>array(0)),
41                         $index
42                 );
43                 $this->assertEquals(
44                         array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
45                         $values
46                 );
47                 xml_parser_free($xml_parser);
48         }
49 }