public static function waitForUpload($sessionID, $response, $context, $allowError = false) { $xml = Sync::getXMLFromResponse($response); if (isset($xml->uploaded) || isset($xml->error) && $allowError) { return $xml; } $context->assertTrue(isset($xml->queued)); $max = 5; do { $wait = (int) $xml->queued['wait']; sleep($wait / 1000); $response = Sync::uploadStatus($sessionID, $allowError); $xml = Sync::getXMLFromResponse($response); $max--; } while (isset($xml->queued) && $max > 0); if (!$max) { $context->fail("Upload did not finish after {$max} attempts"); } if (!$allowError) { $context->assertTrue(isset($xml->uploaded)); } return $xml; }
/** * @depends testSyncEmpty */ public function testSync() { $response = $this->updated(); $xml = Sync::getXMLFromResponse($response); // Upload $data = file_get_contents("data/sync1upload.xml"); $data = str_replace('libraryID=""', 'libraryID="' . self::$config['libraryID'] . '"', $data); $response = $this->updated(); $xml = Sync::getXMLFromResponse($response); $updateKey = (string) $xml['updateKey']; $response = $this->upload($updateKey, $data); $xml = Sync::getXMLFromResponse($response); $this->assertTrue(isset($xml->queued)); $max = 5; do { $wait = (int) $xml->queued['wait']; sleep($wait / 1000); $response = $this->uploadstatus(); $xml = Sync::getXMLFromResponse($response); $max--; } while (isset($xml->queued) && $max > 0); if (!$max) { $this->fail("Upload did not finish after {$max} attempts"); } $this->assertTrue(isset($xml->uploaded)); // Download $response = $this->updated(); $xml = Sync::getXMLFromResponse($response); $max = 5; do { $wait = (int) $xml->locked['wait']; sleep($wait / 1000); $response = $this->updated(); $xml = Sync::getXMLFromResponse($response); //var_dump($response->getBody()); $max--; } while (isset($xml->locked) && $max > 0); if (!$max) { $this->fail("Download did not finish after {$max} attempts"); } $xml = Sync::getXMLFromResponse($response); unset($xml->updated->groups); $xml['timestamp'] = ""; $xml['updateKey'] = ""; $xml['earliest'] = ""; $this->assertXmlStringEqualsXmlFile("data/sync1download.xml", $xml->asXML()); }