| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * Class Tests_Xmlrpc_Getpostcategory |
| | 5 | * test the xmlrpc_getpostcategory function |
| | 6 | */ |
| | 7 | class Tests_Xmlrpc_GetPostCategory extends WP_UnitTestCase { |
| | 8 | |
| | 9 | /** |
| | 10 | * setup |
| | 11 | * declare the default category needed in function |
| | 12 | */ |
| | 13 | function setup() { |
| | 14 | global $post_default_category; |
| | 15 | $post_default_category = 'post_default_category'; |
| | 16 | } |
| | 17 | |
| | 18 | /** |
| | 19 | * remove global |
| | 20 | */ |
| | 21 | function tearDown() { |
| | 22 | global $post_default_category; |
| | 23 | $post_default_category = null; |
| | 24 | } |
| | 25 | |
| | 26 | |
| | 27 | /** |
| | 28 | * pass null |
| | 29 | */ |
| | 30 | function test_xmlrpc_getpostcategory_null() { |
| | 31 | $this->assertEquals( 'post_default_category' , xmlrpc_getpostcategory( null ) ); |
| | 32 | } |
| | 33 | |
| | 34 | /** |
| | 35 | * pass good category in test |
| | 36 | */ |
| | 37 | function test_xmlrpc_getpostcategory_good() { |
| | 38 | |
| | 39 | $this->assertEquals( array( 'good_category' ) , xmlrpc_getpostcategory( '<category>good_category</category>' ) ); |
| | 40 | } |
| | 41 | |
| | 42 | |
| | 43 | /** |
| | 44 | * pass good category in test |
| | 45 | */ |
| | 46 | function test_xmlrpc_getpostcategorys_good() { |
| | 47 | |
| | 48 | $this->assertEquals( array( 'good_category1', 'good_category2', 'good_category3' ), xmlrpc_getpostcategory( '<category>good_category1, good_category2, good_category3</category>' ) ); |
| | 49 | } |
| | 50 | |
| | 51 | /** |
| | 52 | * pass good category in test |
| | 53 | */ |
| | 54 | function test_xmlrpc_getpostcategorys_dupicate_cat() { |
| | 55 | |
| | 56 | $this->assertEquals( array( 0 => 'good_category1', 2 => 'good_category3' ), xmlrpc_getpostcategory( '<category>good_category1, good_category1, good_category3,</category>' ) ); |
| | 57 | } |
| | 58 | |
| | 59 | /** |
| | 60 | * pass good category in lot of content |
| | 61 | */ |
| | 62 | function test_xmlrpc_getpostcategory_good_in_post_tag() { |
| | 63 | |
| | 64 | $this->assertEquals( array( 'good_category' ) , xmlrpc_getpostcategory( '<post><category>good_category</category><cat>fsdfsfsf</cat></post>' ) ); |
| | 65 | } |
| | 66 | /** |
| | 67 | * missing close |
| | 68 | */ |
| | 69 | function test_xmlrpc_getpostcategory_bad() { |
| | 70 | |
| | 71 | $this->assertEquals( 'post_default_category', xmlrpc_getpostcategory( '<category>good_category<category>ssssss' ) ); |
| | 72 | } |
| | 73 | |
| | 74 | /** |
| | 75 | * category has to be something or default is returned |
| | 76 | */ |
| | 77 | function test_xmlrpc_getpostcategory_missing() { |
| | 78 | |
| | 79 | $this->assertEquals( 'post_default_category' , xmlrpc_getpostcategory( '<category></category>' ) ); |
| | 80 | } |
| | 81 | |
| | 82 | /** |
| | 83 | * return space |
| | 84 | */ |
| | 85 | function test_xmlrpc_getpostcategory_space() { |
| | 86 | |
| | 87 | $this->assertEquals( array( '' ) , xmlrpc_getpostcategory( '<category> </category>' ) ); |
| | 88 | } |
| | 89 | |
| | 90 | /** |
| | 91 | * nest categorys tern bad string |
| | 92 | */ |
| | 93 | function test_xmlrpc_getpostcategory_category() { |
| | 94 | |
| | 95 | $this->assertEquals( array( '<category>category' ), xmlrpc_getpostcategory( '<category> <category>category</category> </category>' ) ); |
| | 96 | |
| | 97 | } |
| | 98 | |
| | 99 | /** |
| | 100 | * inluded any tag in the category |
| | 101 | */ |
| | 102 | function test_xmlrpc_getpostcategory_span() { |
| | 103 | |
| | 104 | $this->assertEquals( array( '<span>category</span>' ), xmlrpc_getpostcategory( '<category> <span>category</span> </category>' ) ); |
| | 105 | } |
| | 106 | |
| | 107 | |
| | 108 | /** |
| | 109 | * bad opening tag |
| | 110 | */ |
| | 111 | function test_xmlrpc_getpostcategory_bad_open_tag() { |
| | 112 | |
| | 113 | $this->assertEquals( 'post_default_category' , xmlrpc_getpostcategory( '<category <span>category</span> </category>' ) ); |
| | 114 | } |
| | 115 | |
| | 116 | /** |
| | 117 | * bad closing tag |
| | 118 | */ |
| | 119 | function test_xmlrpc_getpostcategory_bad_close_tag() { |
| | 120 | |
| | 121 | $this->assertEquals( 'post_default_category' , xmlrpc_getpostcategory( '<category>category</category dddddd>' ) ); |
| | 122 | } |
| | 123 | |
| | 124 | /** |
| | 125 | * dosen't find category if attribute set |
| | 126 | */ |
| | 127 | function test_xmlrpc_getpostcategory_attribute_in_tag() { |
| | 128 | |
| | 129 | $this->assertEquals( 'post_default_category' , xmlrpc_getpostcategory( '<category id="id">category</category>' ) ); |
| | 130 | } |
| | 131 | |
| | 132 | /** |
| | 133 | * find just the frist category |
| | 134 | */ |
| | 135 | function test_xmlrpc_getpostcategory_2_categorys() { |
| | 136 | |
| | 137 | $this->assertEquals( array( 'category1' ) , xmlrpc_getpostcategory( '<category>category1</category><category>category2</category>' ) ); |
| | 138 | } |
| | 139 | |
| | 140 | /** |
| | 141 | * pass cdata |
| | 142 | */ |
| | 143 | function test_xmlrpc_getpostcategory_cdata() { |
| | 144 | |
| | 145 | $this->assertEquals( array( '<![CDATA["category"]]>' ), xmlrpc_getpostcategory( '<category><![CDATA["category"]]></category>' ) ); |
| | 146 | } |
| | 147 | |
| | 148 | /** |
| | 149 | * pass cdata with tag category |
| | 150 | */ |
| | 151 | function test_xmlrpc_getpostcategory_bad_cdate() { |
| | 152 | |
| | 153 | $this->assertEquals( array( '<![CDATA["<category>category' ) , xmlrpc_getpostcategory( '<category><![CDATA["<category>category</category>"]]></category>' ) ); |
| | 154 | } |
| | 155 | } |