assertFileExists($file); $post_data = ['qtiPackage' => new \CURLFile($file)]; $options = [ CURLOPT_POSTFIELDS => $post_data ]; $content = $this->curl($endpoint, CURLOPT_POST, "data", $options); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertTrue($data['success']); $this->assertTrue(isset($data['data'])); $this->assertTrue(is_array($data['data'])); $this->assertCount(1, $data['data']); $testData = reset($data['data']); $this->assertTrue(isset($testData['testId'])); $uri = $testData['testId']; $test = new \core_kernel_classes_Resource($uri); $this->assertTrue($test->exists()); $deletionCall = ROOT_URL . 'taoTests/RestTests?uri=' . urlencode($uri); $content = $this->curl($deletionCall, 'DELETE', "data"); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertTrue($data['success']); $this->assertFalse($test->exists()); // should return an error, instance no longer exists $content = $this->curl($deletionCall, 'DELETE', "data"); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertFalse($data['success']); } public function testError() { $endpoint = ROOT_URL . 'taoQtiTest/RestQtiTests'; $file = __DIR__ . '/../samples/archives/QTI 2.1/invalid/MissingItemDependency.zip'; $this->assertFileExists($file); $post_data = ['qtiPackage' => new \CURLFile($file)]; $options = [ CURLOPT_POSTFIELDS => $post_data ]; $content = $this->curl($endpoint, CURLOPT_POST, "data", $options); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertFalse($data['success']); } public function testInvalidFile() { $endpoint = ROOT_URL . 'taoQtiTest/RestQtiTests'; $post_data = [ 'qtiPackage' => new \CURLFile(__DIR__ . '/../samples/xml/compiler/meta/linear_nopreconditions_branchrules.xml') ]; $options = [ CURLOPT_POSTFIELDS => $post_data ]; $content = $this->curl($endpoint, CURLOPT_POST, "data", $options); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertFalse($data['success']); } }