function test_ls()
 {
     RemoteSyncPlugin::instance()->syncers = NULL;
     RemoteSyncPlugin::instance()->install();
     $api = new RemoteSyncApi();
     $res = $api->ls(array("type" => "post"));
     $this->assertCount(0, $res);
     $id1 = wp_insert_post(array("post_title" => "post one", "post_name" => "post-one"));
     $id2 = wp_insert_post(array("post_title" => "post two", "post_parent" => $id1, "post_name" => "post-two"));
     $id3 = wp_insert_post(array("post_title" => "post three", "post_parent" => $id2, "post_name" => "post-three"));
     $res = $api->ls(array("type" => "post"));
     $this->assertCount(3, $res);
     $this->assertEquals("post-one", $res[0]["slug"]);
     $this->assertEquals("post-two", $res[1]["slug"]);
     $this->assertEquals("post-three", $res[2]["slug"]);
     $post1 = get_post($id1);
     $post1->post_parent = NULL;
     wp_update_post($post1);
     $post2 = get_post($id2);
     $post2->post_parent = NULL;
     wp_update_post($post2);
     $post3 = get_post($id3);
     $post3->post_parent = NULL;
     wp_update_post($post3);
     $post1 = get_post($id1);
     $post1->post_parent = $id2;
     wp_update_post($post1);
     $post2 = get_post($id2);
     $post2->post_parent = $id3;
     wp_update_post($post2);
     $post3 = get_post($id3);
     $post3->post_parent = NULL;
     wp_update_post($post3);
     $res = $api->ls(array("type" => "post"));
     $this->assertCount(3, $res);
     $this->assertEquals("post-three", $res[0]["slug"]);
     $this->assertEquals("post-two", $res[1]["slug"]);
     $this->assertEquals("post-one", $res[2]["slug"]);
 }
 function test_doApiCall()
 {
     RemoteSyncPlugin::instance()->install();
     $id = wp_insert_post(array("post_title" => "hello", "post_type" => "post", "post_content" => "something", "post_name" => "the-name"));
     update_option('rs_access_key', "test");
     $api = new RemoteSyncApi();
     // test listing with the right key
     $ls_res1 = array();
     $args = array("key" => "test", "type" => "post", "version" => 2);
     $ls_res1 = $api->doApiCall("ls", $args);
     //print_r($ls_res1);
     //test listing with the wrong key
     $ls_res2 = array();
     $args = array("key" => "Wrong Key", "type" => "post");
     $ls_res2 = $api->doApiCall("ls", $args);
     //print_r($ls_res2);
     // test deleting with wrong key
     $del_res1 = array();
     $args = array("key" => "wrong key", "type" => "post", "slug" => $ls_res1[0]["slug"]);
     $del_res1 = $api->doApiCall("del", $args);
     //print_r($del_res1);
     // test deleting with right key
     $del_res1 = array();
     $args = array("key" => "test", "type" => "post", "slug" => $ls_res1[0]["slug"], "version" => 2);
     $del_res1 = $api->doApiCall("del", $args);
     //print_r($del_res1);
 }