1 | <?php |
---|
2 | /** |
---|
3 | * |
---|
4 | * @group wporg-plugin-api |
---|
5 | */ |
---|
6 | class Tests_Wporg_Plugin_API extends WP_UnitTestCase { |
---|
7 | |
---|
8 | public function setUp() { |
---|
9 | parent::setup(); |
---|
10 | } |
---|
11 | |
---|
12 | function test_wp_org_plugin_api_serialize_php() { |
---|
13 | $args = (object) array( 'slug' => 'hello-dolly' ); |
---|
14 | $request = array( 'action' => 'plugin_information', 'timeout' => 15, 'request' => serialize( $args) ); |
---|
15 | $url = 'http://api.wordpress.org/plugins/info/1.0/'; |
---|
16 | $response = wp_remote_post( $url, array( 'body' => $request ) ); |
---|
17 | $plugin_info = unserialize( $response['body'] ); |
---|
18 | |
---|
19 | $this->assertObjectHasAttribute( 'name', $plugin_info, 'Name exists' ); |
---|
20 | $this->assertObjectHasAttribute( 'slug', $plugin_info, 'Slug exits' ); |
---|
21 | $this->assertObjectHasAttribute( 'version', $plugin_info, 'Version exists' ); |
---|
22 | $this->assertObjectHasAttribute( 'author', $plugin_info, 'Author exists' ); |
---|
23 | $this->assertObjectHasAttribute( 'author_profile', $plugin_info, 'Author Profile exists' ); |
---|
24 | $this->assertObjectHasAttribute( 'contributors', $plugin_info, 'Contributors exists' ); |
---|
25 | $this->assertTrue( is_array( $plugin_info->contributors ), 'Contributors should be an array'); |
---|
26 | $this->assertObjectHasAttribute( 'requires',$plugin_info, 'Requires exists' ); |
---|
27 | $this->assertObjectHasAttribute( 'tested', $plugin_info, 'Tested exists' ); |
---|
28 | $this->assertObjectHasAttribute( 'compatibility', $plugin_info, 'Compatibility exists' ); |
---|
29 | $this->assertTrue( is_array( $plugin_info->compatibility ), 'Compatibility should be an array' ); |
---|
30 | |
---|
31 | // Ratings |
---|
32 | $this->assertObjectHasAttribute( 'ratings', $plugin_info, 'Ratings exists' ); |
---|
33 | $this->assertTrue( is_array( $plugin_info->ratings ), 'Ratings should be an array' ); |
---|
34 | $this->assertArrayHasKey( '1', $plugin_info->ratings, 'Rating should have an attribute of 1' ); |
---|
35 | $this->assertArrayHasKey( '2', $plugin_info->ratings, 'Rating should have an attribute of 2' ); |
---|
36 | $this->assertArrayHasKey( '3', $plugin_info->ratings, 'Rating should have an attribute of 3' ); |
---|
37 | $this->assertArrayHasKey( '4', $plugin_info->ratings, 'Rating should have an attribute of 4' ); |
---|
38 | $this->assertArrayHasKey( '5', $plugin_info->ratings, 'Rating should have an attribute of 5' ); |
---|
39 | $this->assertObjectHasAttribute( 'num_ratings', $plugin_info, 'Num ratings exists' ); |
---|
40 | $this->assertTrue( is_numeric( $plugin_info->num_ratings ) ); |
---|
41 | |
---|
42 | // Downloaded |
---|
43 | $this->assertObjectHasAttribute( 'downloaded', $plugin_info, 'Downloaded exists' ); |
---|
44 | $this->assertTrue( is_numeric( $plugin_info->downloaded ) ); |
---|
45 | |
---|
46 | $this->assertObjectHasAttribute( 'last_updated', $plugin_info, 'last_updated exists' ); |
---|
47 | $this->assertObjectHasAttribute( 'added', $plugin_info, 'Added exists' ); |
---|
48 | $this->assertObjectHasAttribute( 'homepage', $plugin_info, 'Homepage exists' ); |
---|
49 | $this->assertObjectHasAttribute( 'sections', $plugin_info, 'Sections Exists' ); |
---|
50 | $this->assertTrue( is_array( $plugin_info->sections ), 'Sections should be an array' ); |
---|
51 | |
---|
52 | // Download link |
---|
53 | $this->assertObjectHasAttribute( 'download_link', $plugin_info, 'Download Link exists' ); |
---|
54 | $download_url_parsed = parse_url( $plugin_info->download_link ); |
---|
55 | $this->assertEquals( $download_url_parsed['host'], 'downloads.wordpress.org' ); |
---|
56 | $this->assertStringEndsWith( $plugin_info->slug . '.' . $plugin_info->version . '.zip', $download_url_parsed['path'] , 'Download URL contains plugin slug and version' ); |
---|
57 | |
---|
58 | // Donate link |
---|
59 | $this->assertObjectHasAttribute( 'donate_link', $plugin_info, 'Donate link exists' ); |
---|
60 | |
---|
61 | // Tags should be key |
---|
62 | $this->assertObjectHasAttribute( 'tags', $plugin_info, 'Tags exists' ); |
---|
63 | $this->assertTrue( is_array( $plugin_info->tags ), 'Tags should be an array' ); |
---|
64 | } |
---|
65 | |
---|
66 | function test_wp_org_plugin_api_serialize_php_get() { |
---|
67 | $url = 'http://api.wordpress.org/plugins/info/1.0/hello-dolly'; |
---|
68 | $response = wp_remote_get( $url ); |
---|
69 | $plugin_info = unserialize( $response['body'] ); |
---|
70 | |
---|
71 | $this->assertObjectHasAttribute( 'name', $plugin_info, 'Name exists' ); |
---|
72 | $this->assertObjectHasAttribute( 'slug', $plugin_info, 'Slug exits' ); |
---|
73 | $this->assertObjectHasAttribute( 'version', $plugin_info, 'Version exists' ); |
---|
74 | $this->assertObjectHasAttribute( 'author', $plugin_info, 'Author exists' ); |
---|
75 | $this->assertObjectHasAttribute( 'author_profile', $plugin_info, 'Author Profile exists' ); |
---|
76 | $this->assertObjectHasAttribute( 'contributors', $plugin_info, 'Contributors exists' ); |
---|
77 | $this->assertTrue( is_array( $plugin_info->contributors ), 'Contributors should be an array'); |
---|
78 | $this->assertObjectHasAttribute( 'requires',$plugin_info, 'Requires exists' ); |
---|
79 | $this->assertObjectHasAttribute( 'tested', $plugin_info, 'Tested exists' ); |
---|
80 | $this->assertObjectHasAttribute( 'compatibility', $plugin_info, 'Compatibility exists' ); |
---|
81 | $this->assertTrue( is_array( $plugin_info->compatibility ), 'Compatibility should be an array' ); |
---|
82 | |
---|
83 | // Ratings |
---|
84 | $this->assertObjectHasAttribute( 'ratings', $plugin_info, 'Ratings exists' ); |
---|
85 | $this->assertTrue( is_array( $plugin_info->ratings ), 'Ratings should be an array' ); |
---|
86 | $this->assertArrayHasKey( '1', $plugin_info->ratings, 'Rating should have an attribute of 1' ); |
---|
87 | $this->assertArrayHasKey( '2', $plugin_info->ratings, 'Rating should have an attribute of 2' ); |
---|
88 | $this->assertArrayHasKey( '3', $plugin_info->ratings, 'Rating should have an attribute of 3' ); |
---|
89 | $this->assertArrayHasKey( '4', $plugin_info->ratings, 'Rating should have an attribute of 4' ); |
---|
90 | $this->assertArrayHasKey( '5', $plugin_info->ratings, 'Rating should have an attribute of 5' ); |
---|
91 | $this->assertObjectHasAttribute( 'num_ratings', $plugin_info, 'Num ratings exists' ); |
---|
92 | $this->assertTrue( is_numeric( $plugin_info->num_ratings ) ); |
---|
93 | |
---|
94 | // Downloaded |
---|
95 | $this->assertObjectHasAttribute( 'downloaded', $plugin_info, 'Downloaded exists' ); |
---|
96 | $this->assertTrue( is_numeric( $plugin_info->downloaded ) ); |
---|
97 | |
---|
98 | $this->assertObjectHasAttribute( 'last_updated', $plugin_info, 'last_updated exists' ); |
---|
99 | $this->assertObjectHasAttribute( 'added', $plugin_info, 'Added exists' ); |
---|
100 | $this->assertObjectHasAttribute( 'homepage', $plugin_info, 'Homepage exists' ); |
---|
101 | $this->assertObjectHasAttribute( 'sections', $plugin_info, 'Sections Exists' ); |
---|
102 | $this->assertTrue( is_array( $plugin_info->sections ), 'Sections should be an array' ); |
---|
103 | |
---|
104 | // Download link |
---|
105 | $this->assertObjectHasAttribute( 'download_link', $plugin_info, 'Download Link exists' ); |
---|
106 | $download_url_parsed = parse_url( $plugin_info->download_link ); |
---|
107 | $this->assertEquals( $download_url_parsed['host'], 'downloads.wordpress.org' ); |
---|
108 | $this->assertStringEndsWith( $plugin_info->slug . '.' . $plugin_info->version . '.zip', $download_url_parsed['path'] , 'Download URL contains plugin slug and version' ); |
---|
109 | |
---|
110 | // Donate link |
---|
111 | $this->assertObjectHasAttribute( 'donate_link', $plugin_info, 'Donate link exists' ); |
---|
112 | |
---|
113 | // Tags should be key |
---|
114 | $this->assertObjectHasAttribute( 'tags', $plugin_info, 'Tags exists' ); |
---|
115 | $this->assertTrue( is_array( $plugin_info->tags ), 'Tags should be an array' ); |
---|
116 | } |
---|
117 | |
---|
118 | function test_wp_org_plugin_api_json() { |
---|
119 | $url = 'http://api.wordpress.org/plugins/info/1.0/hello-dolly.json'; |
---|
120 | $response = wp_remote_get( $url ); |
---|
121 | $plugin_info = json_decode( $response['body'] ); |
---|
122 | |
---|
123 | $this->assertObjectHasAttribute( 'name', $plugin_info, 'Name exists' ); |
---|
124 | $this->assertObjectHasAttribute( 'slug', $plugin_info, 'Slug exits' ); |
---|
125 | $this->assertObjectHasAttribute( 'version', $plugin_info, 'Version exists' ); |
---|
126 | $this->assertObjectHasAttribute( 'author', $plugin_info, 'Author exists' ); |
---|
127 | $this->assertObjectHasAttribute( 'author_profile', $plugin_info, 'Author Profile exists' ); |
---|
128 | $this->assertObjectHasAttribute( 'contributors', $plugin_info, 'Contributors exists' ); |
---|
129 | $this->assertTrue( is_object( $plugin_info->contributors ), 'Contributors should be an object'); |
---|
130 | $this->assertObjectHasAttribute( 'requires',$plugin_info, 'Requires exists' ); |
---|
131 | $this->assertObjectHasAttribute( 'tested', $plugin_info, 'Tested exists' ); |
---|
132 | $this->assertObjectHasAttribute( 'compatibility', $plugin_info, 'Compatibility exists' ); |
---|
133 | $this->assertTrue( is_array( $plugin_info->compatibility ), 'Compatibility should be an object' ); |
---|
134 | |
---|
135 | // Ratings |
---|
136 | $this->assertObjectHasAttribute( 'ratings', $plugin_info, 'Ratings exists' ); |
---|
137 | $this->assertTrue( is_object( $plugin_info->ratings ), 'Ratings should be an object' ); |
---|
138 | |
---|
139 | // Num Ratings |
---|
140 | $this->assertObjectHasAttribute( 'num_ratings', $plugin_info, 'Num ratings exists' ); |
---|
141 | $this->assertTrue( is_numeric( $plugin_info->num_ratings ) ); |
---|
142 | |
---|
143 | // Downloaded |
---|
144 | $this->assertObjectHasAttribute( 'downloaded', $plugin_info, 'Downloaded exists' ); |
---|
145 | $this->assertTrue( is_numeric( $plugin_info->downloaded ) ); |
---|
146 | |
---|
147 | $this->assertObjectHasAttribute( 'last_updated', $plugin_info, 'last_updated exists' ); |
---|
148 | $this->assertObjectHasAttribute( 'added', $plugin_info, 'Added exists' ); |
---|
149 | $this->assertObjectHasAttribute( 'homepage', $plugin_info, 'Homepage exists' ); |
---|
150 | $this->assertObjectHasAttribute( 'sections', $plugin_info, 'Sections Exists' ); |
---|
151 | $this->assertTrue( is_object( $plugin_info->sections ), 'Sections should be an object' ); |
---|
152 | |
---|
153 | // Download link |
---|
154 | $this->assertObjectHasAttribute( 'download_link', $plugin_info, 'Download Link exists' ); |
---|
155 | $download_url_parsed = parse_url( $plugin_info->download_link ); |
---|
156 | $this->assertEquals( $download_url_parsed['host'], 'downloads.wordpress.org' ); |
---|
157 | $this->assertStringEndsWith( $plugin_info->slug . '.' . $plugin_info->version . '.zip', $download_url_parsed['path'] , 'Download URL contains plugin slug and version' ); |
---|
158 | |
---|
159 | // Donate link |
---|
160 | $this->assertObjectHasAttribute( 'donate_link', $plugin_info, 'Donate link exists' ); |
---|
161 | |
---|
162 | $this->assertObjectHasAttribute( 'short_description', $plugin_info, 'Short Description exists' ); |
---|
163 | |
---|
164 | // Tags should be key |
---|
165 | $this->assertObjectHasAttribute( 'tags', $plugin_info, 'Tags exists' ); |
---|
166 | $this->assertTrue( is_array( $plugin_info->tags ), 'Tags should be an array' ); |
---|
167 | } |
---|
168 | } |
---|