public function testEditMultipleCollections() { $collection1Data = API::createCollection("Test 1", false, $this, 'jsonData'); $collection2Name = "Test 2"; $collection2Data = API::createCollection($collection2Name, false, $this, 'jsonData'); $collection1NewName = "Test 1 Modified"; $collection2NewParentKey = API::createCollection("Test 3", false, $this, 'key'); $response = API::userPost(self::$config['userID'], "collections", json_encode([['key' => $collection1Data['key'], 'version' => $collection1Data['version'], 'name' => $collection1NewName], ['key' => $collection2Data['key'], 'version' => $collection2Data['version'], 'parentCollection' => $collection2NewParentKey]]), ["Content-Type: application/json"]); $this->assert200($response); $json = API::getJSONFromResponse($response); $this->assertCount(2, $json['success']); $response = API::getCollectionResponse($json['success']); $this->assertTotalResults(2, $response); $json = API::getJSONFromResponse($response); // POST follows PATCH behavior, so unspecified values shouldn't change $this->assertEquals($collection1NewName, $json[0]['data']['name']); $this->assertFalse($json[0]['data']['parentCollection']); $this->assertEquals($collection2Name, $json[1]['data']['name']); $this->assertEquals($collection2NewParentKey, $json[1]['data']['parentCollection']); }
public function testEditMultipleCollections() { $collection1Data = API::createCollection("Test 1", false, $this, 'jsonData'); $collection2Name = "Test 2"; $collection2Data = API::createCollection($collection2Name, false, $this, 'jsonData'); $collection1NewName = "Test 1 Modified"; $collection2NewParentKey = API::createCollection("Test 3", false, $this, 'key'); $response = API::userPost(self::$config['userID'], "collections", json_encode([['key' => $collection1Data['key'], 'version' => $collection1Data['version'], 'name' => $collection1NewName], ['key' => $collection2Data['key'], 'version' => $collection2Data['version'], 'parentCollection' => $collection2NewParentKey]]), ["Content-Type: application/json"]); $this->assert200($response); $libraryVersion = $response->getHeader("Last-Modified-Version"); $json = API::getJSONFromResponse($response); $this->assertCount(2, $json['successful']); // Deprecated $this->assertCount(2, $json['success']); // Check data in write response $this->assertEquals($json['successful'][0]['key'], $json['successful'][0]['data']['key']); $this->assertEquals($json['successful'][1]['key'], $json['successful'][1]['data']['key']); $this->assertEquals($libraryVersion, $json['successful'][0]['version']); $this->assertEquals($libraryVersion, $json['successful'][1]['version']); $this->assertEquals($libraryVersion, $json['successful'][0]['data']['version']); $this->assertEquals($libraryVersion, $json['successful'][1]['data']['version']); $this->assertEquals($collection1NewName, $json['successful'][0]['data']['name']); $this->assertEquals($collection2Name, $json['successful'][1]['data']['name']); $this->assertFalse($json['successful'][0]['data']['parentCollection']); $this->assertEquals($collection2NewParentKey, $json['successful'][1]['data']['parentCollection']); // Check in separate request, to be safe $keys = array_map(function ($o) { return $o['key']; }, $json['successful']); $response = API::getCollectionResponse($keys); $this->assertTotalResults(2, $response); $json = API::getJSONFromResponse($response); // POST follows PATCH behavior, so unspecified values shouldn't change $this->assertEquals($collection1NewName, $json[0]['data']['name']); $this->assertFalse($json[0]['data']['parentCollection']); $this->assertEquals($collection2Name, $json[1]['data']['name']); $this->assertEquals($collection2NewParentKey, $json[1]['data']['parentCollection']); }