| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Tests_Xmlrpc_Getposttitle |
| 5 | * test the xmlrpc_getposttitle function |
| 6 | */ |
| 7 | class Tests_Xmlrpc_Getposttitle extends WP_UnitTestCase { |
| 8 | |
| 9 | /** |
| 10 | * setup |
| 11 | * declare the default title needed in function |
| 12 | */ |
| 13 | function setup() { |
| 14 | global $post_default_title; |
| 15 | $post_default_title = 'post_default_title'; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * remove global |
| 20 | */ |
| 21 | function tearDown() { |
| 22 | global $post_default_title; |
| 23 | $post_default_title = null; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * pass null |
| 29 | */ |
| 30 | function test_xmlrpc_getposttitle_null() { |
| 31 | $this->assertEquals( 'post_default_title' , xmlrpc_getposttitle( null ) ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * pass good title in test |
| 36 | */ |
| 37 | function test_xmlrpc_getposttitle_good() { |
| 38 | |
| 39 | $this->assertEquals( 'good_title' , xmlrpc_getposttitle( '<title>good_title</title>' ) ); |
| 40 | } |
| 41 | /** |
| 42 | * pass good title in lot of content |
| 43 | */ |
| 44 | function test_xmlrpc_getposttitle_good_in_post_tag() { |
| 45 | |
| 46 | $this->assertEquals( 'good_title' , xmlrpc_getposttitle( '<post><title>good_title</title><cat>fsdfsfsf</cat></post>' ) ); |
| 47 | } |
| 48 | /** |
| 49 | * missing close |
| 50 | */ |
| 51 | function test_xmlrpc_getposttitle_bad() { |
| 52 | |
| 53 | $this->assertEquals( 'post_default_title', xmlrpc_getposttitle( '<title>good_title<title>ssssss' ) ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * title has to be something or default is returned |
| 58 | */ |
| 59 | function test_xmlrpc_getposttitle_missing() { |
| 60 | |
| 61 | $this->assertEquals( 'post_default_title' , xmlrpc_getposttitle( '<title></title>' ) ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * return space |
| 66 | */ |
| 67 | function test_xmlrpc_getposttitle_space() { |
| 68 | |
| 69 | $this->assertEquals( ' ' , xmlrpc_getposttitle( '<title> </title>' ) ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * nest titles tern bad string |
| 74 | */ |
| 75 | function test_xmlrpc_getposttitle_title() { |
| 76 | |
| 77 | $this->assertEquals( ' <title>title' , xmlrpc_getposttitle( '<title> <title>title</title> </title>' ) ); |
| 78 | |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * inluded any tag in the title |
| 83 | */ |
| 84 | function test_xmlrpc_getposttitle_span() { |
| 85 | |
| 86 | $this->assertEquals( ' <span>title</span> ' , xmlrpc_getposttitle( '<title> <span>title</span> </title>' ) ); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * bad opening tag |
| 92 | */ |
| 93 | function test_xmlrpc_getposttitle_bad_open_tag() { |
| 94 | |
| 95 | $this->assertEquals( 'post_default_title' , xmlrpc_getposttitle( '<title <span>title</span> </title>' ) ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * bad closing tag |
| 100 | */ |
| 101 | function test_xmlrpc_getposttitle_bad_close_tag() { |
| 102 | |
| 103 | $this->assertEquals( 'post_default_title' , xmlrpc_getposttitle( '<title>title</title dddddd>' ) ); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /** |
| 108 | * dosen't find title if attribute set |
| 109 | */ |
| 110 | function test_xmlrpc_getposttitle_attribute_in_tag() { |
| 111 | |
| 112 | $this->assertEquals( 'post_default_title' , xmlrpc_getposttitle( '<title id="id">title</title>' ) ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * find just the frist title |
| 117 | */ |
| 118 | function test_xmlrpc_getposttitle_2_titles() { |
| 119 | |
| 120 | $this->assertEquals( 'title1' , xmlrpc_getposttitle( '<title>title1</title><title>title2</title>' ) ); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * pass cdata |
| 125 | */ |
| 126 | function test_xmlrpc_getposttitle_cdata() { |
| 127 | |
| 128 | $this->assertEquals( '<![CDATA["title"]]>' , xmlrpc_getposttitle( '<title><![CDATA["title"]]></title>' ) ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * pass cdata with tag title |
| 133 | */ |
| 134 | function test_xmlrpc_getposttitle_bad_cdate() { |
| 135 | |
| 136 | $this->assertEquals( '<![CDATA["<title>title' , xmlrpc_getposttitle( '<title><![CDATA["<title>title</title>"]]></title>' ) ); |
| 137 | } |
| 138 | } |