function test_mock() { Curl::initMock(); Curl::mockResult("helloworld"); $curl = new Curl(); $res = $curl->exec(); $this->assertEquals($res, "helloworld"); }
function test_push() { RemoteSyncPlugin::instance()->install(); $postId = wp_insert_post(array('post_content' => 'content', 'post_name' => 'the-slug', 'post_title' => "Hello Post")); update_option("rs_remote_site_url", "http://example.com/"); Curl::mockResult(array()); Curl::mockResult(array()); Curl::mockResult(array()); $op = new RemoteSyncOperations(); $op->push(); wp_trash_post($postId); Curl::initMock(); Curl::mockResult(array(array("slug" => 'the-slug', 'revision' => "hello"))); Curl::mockResult(array()); Curl::mockResult(array()); $op = new RemoteSyncOperations(); $op->push(); }
function test_state() { update_option("rs_remote_site_url", "helloworld"); RemoteSyncPlugin::instance()->syncers = array(new SRTestSyncer("testType")); RemoteSyncPlugin::instance()->install(); $syncer = RemoteSyncPlugin::instance()->getSyncerByType("testType"); $data = $syncer->getResource("slug1"); $rev = md5(json_encode($data)); Curl::mockResult(array(array("slug" => "onlyremote", "revision" => "05a1ad082ad35cad7aac7b18e232feb3"), array("slug" => "slug1", "revision" => $rev))); $syncResources = SyncResource::findAllForType("testType", SyncResource::POPULATE_REMOTE | SyncResource::POPULATE_LOCAL); $a = array(); foreach ($syncResources as $syncResource) { $a[$syncResource->getSlug()] = $syncResource; } //echo "l: ".sizeof($syncResources); $syncResource = $syncResources[0]; $data = $syncResource->getData(); $rev = $syncResource->getLocalRevision(); $this->assertEquals($a["onlyremote"]->getState(), SyncResource::NEW_REMOTE); $this->assertEquals($a["onlylocal"]->getState(), SyncResource::NEW_LOCAL); $this->assertEquals($a["slug1"]->getState(), SyncResource::UP_TO_DATE); }