Ejemplo n.º 1
0
 public function testGetRewriteRulesNotSet()
 {
     global $wp_rewrite;
     $wp_rewrite->set_permalink_structure('');
     $wp_rewrite->flush_rules();
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/rewrite_rules/', 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals('404', $status);
 }
Ejemplo n.º 2
0
 public function testBadRoute()
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/foobar'));
     $app = new \Slim\Slim();
     $apiTest = new API_Test_v1($app);
     ob_start();
     $apiTest->app->run();
     ob_end_clean();
     $response = $apiTest->app->response();
     $this->assertObjectHasAttribute('error', json_decode($response->body()));
 }
Ejemplo n.º 3
0
 public function testGetTaxonomyEntityFilter()
 {
     add_filter('thermal_taxonomy_entity', function ($data, &$taxonomy, $state) {
         $data->test_value = $taxonomy->name;
         return $data;
     }, 10, 3);
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/taxonomies/public_taxonomy_a', 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals('200', $status);
     $this->assertObjectHasAttribute('name', $data);
     $this->assertEquals('public_taxonomy_a', $data->name);
     $this->assertObjectHasAttribute('test_value', $data);
     $this->assertEquals('public_taxonomy_a', $data->test_value);
 }
Ejemplo n.º 4
0
 public function testGetUser()
 {
     $users = $this->getTestUserData();
     $user = $users[0];
     $user['role'] = 'editor';
     $user['id'] = wp_insert_user($user);
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/users/' . $user['id'], 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals('200', $status);
     $this->assertInternalType('object', $data);
     $this->assertObjectHasAttribute('id', $data);
     $this->assertInternalType('int', $data->id);
     $this->assertEquals($user['id'], $data->id);
     $this->assertObjectHasAttribute('id_str', $data);
     $this->assertInternalType('string', $data->id_str);
     $this->assertEquals((string) $user['id'], $data->id_str);
     $this->assertObjectHasAttribute('nicename', $data);
     $this->assertInternalType('string', $data->nicename);
     $this->assertEquals($user['user_nicename'], $data->nicename);
     $this->assertObjectHasAttribute('display_name', $data);
     $this->assertInternalType('string', $data->display_name);
     $this->assertEquals($user['display_name'], $data->display_name);
     $this->assertObjectHasAttribute('user_url', $data);
     $this->assertInternalType('string', $data->user_url);
     $this->assertEquals($user['user_url'], $data->user_url);
     $this->assertObjectHasAttribute('posts_url', $data);
     $this->assertInternalType('string', $data->posts_url);
     $this->assertObjectHasAttribute('avatar', $data);
     $this->assertInternalType('array', $data->avatar);
     $this->assertObjectHasAttribute('meta', $data);
     $this->assertInternalType('object', $data->meta);
     $this->assertObjectHasAttribute('first_name', $data->meta);
     $this->assertEquals($user['first_name'], $data->meta->first_name);
     $this->assertObjectHasAttribute('last_name', $data->meta);
     $this->assertEquals($user['last_name'], $data->meta->last_name);
     $this->assertObjectHasAttribute('nickname', $data->meta);
     $this->assertEquals($user['nickname'], $data->meta->nickname);
     $this->assertObjectHasAttribute('description', $data->meta);
     $this->assertEquals($user['description'], $data->meta->description);
     $data = json_decode($body);
     //clean up
     wp_delete_user($user['id']);
 }
Ejemplo n.º 5
0
 public function testGetTermEntityFilter()
 {
     $testdata = $this->_insertTestData();
     add_filter('thermal_term_entity', function ($data, $term, $state) {
         $data->test_value = $term->term_id;
         return $data;
     }, 10, 3);
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/taxonomies/public_taxonomy_a/terms/' . $testdata['term_a']['term_id'], 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals('200', $status);
     $this->assertObjectHasAttribute('name', $data);
     $this->assertEquals('Term In Both', $data->name);
     $this->assertObjectHasAttribute('test_value', $data);
     $this->assertEquals($testdata['term_a']['term_id'], $data->test_value);
     $id = 9999999;
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/taxonomies/public_taxonomy_a/terms/' . $id, 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals('404', $status);
 }
Ejemplo n.º 6
0
 public function testGetCommentEntityFilter()
 {
     $testdata = $this->_insertTestData();
     add_filter('thermal_comment_entity', function ($data, &$comment, $state) {
         $data->test_value = $comment->comment_ID;
         return $data;
     }, 10, 3);
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/comments/' . $testdata['comment_approved_minus_10'], 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals('200', $status);
     $this->assertObjectHasAttribute('test_value', $data);
     $this->assertEquals($testdata['comment_approved_minus_10'], $data->test_value);
 }
Ejemplo n.º 7
0
 public function testGetPostGalleryInclude()
 {
     $post_content = 'Lorem Ipsum';
     $post_args = array('post_content' => $post_content);
     $post_images = array('100x200.png', '100x300.png', '100x400.png');
     $post_data = $this->_insert_post($post_args, $post_images);
     $post_id = $post_data['post_id'];
     $attachment_ids = $post_data['attachment_ids'];
     array_shift($attachment_ids);
     $this->_insert_post(array('ID' => $post_id, 'post_content' => sprintf('[gallery include="%s"]', implode(',', $attachment_ids))));
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/posts/' . $post_id, 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertEquals($attachment_ids, $data->meta->gallery[0]->ids);
 }
Ejemplo n.º 8
0
 public function testUserAvatarDisabled()
 {
     $users = $this->getTestUserData();
     $user = $users[0];
     $user['role'] = 'editor';
     $user['id'] = wp_insert_user($user);
     update_option('show_avatars', false);
     list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/users/' . $user['id'], 'QUERY_STRING' => ''));
     $data = json_decode($body);
     $this->assertObjectNotHasAttribute('avatar', $data);
 }