diff --git a/tests/_support/RestTester.php b/tests/_support/RestTester.php index 1d7ce6fb..972df48a 100644 --- a/tests/_support/RestTester.php +++ b/tests/_support/RestTester.php @@ -1,22 +1,11 @@ setParentId(1); + $unsavedObject->setUserOwner(1); + $unsavedObject->setUserModification(1); + $unsavedObject->setCreationDate(time()); + $unsavedObject->setKey(uniqid() . rand(10, 99)); + + $time = time(); + + $result = $this->restClient->createObjectConcrete($unsavedObject); + + $this->assertTrue($result->success, 'request not successful . ' . $result->msg); + $this->assertEquals(2, TestHelper::getObjectCount()); + + $id = $result->id; + $this->assertTrue($id > 1, 'id must be greater than 1'); + + $objectDirect = AbstractObject::getById($id); + $creationDate = $objectDirect->getCreationDate(); + + $this->assertTrue($creationDate >= $time, 'wrong creation date'); + + // as the object key is unique there must be exactly one object with that key + $list = $this->restClient->getObjectList('{ "o_key" : "' . $unsavedObject->getKey() . '"}'); + $this->assertEquals(1, count($list)); + + $fetchedObject = $this->restClient->getObjectById($id); + $this->assertInstanceOf(UserInterface::class, $fetchedObject); + } + + public function testUserGroupCreate() + { + $unsavedObject = new MembersGroup(); + $unsavedObject->setParentId(1); + $unsavedObject->setUserOwner(1); + $unsavedObject->setUserModification(1); + $unsavedObject->setCreationDate(time()); + $unsavedObject->setKey(uniqid() . rand(10, 99)); + + $time = time(); + + $result = $this->restClient->createObjectConcrete($unsavedObject); + + $this->assertTrue($result->success, 'request not successful . ' . $result->msg); + $this->assertEquals(2, TestHelper::getObjectCount()); + + $id = $result->id; + $this->assertTrue($id > 1, 'id must be greater than 1'); + + $objectDirect = AbstractObject::getById($id); + $creationDate = $objectDirect->getCreationDate(); + + $this->assertTrue($creationDate >= $time, 'wrong creation date'); + + // as the object key is unique there must be exactly one object with that key + $list = $this->restClient->getObjectList('{ "o_key" : "' . $unsavedObject->getKey() . '"}'); + $this->assertEquals(1, count($list)); + + $fetchedObject = $this->restClient->getObjectById($id); + $this->assertInstanceOf(GroupInterface::class, $fetchedObject); + } +} diff --git a/tests/bundle_tests/rest/UserTest.php b/tests/bundle_tests/rest/UserTest.php deleted file mode 100644 index 5e6b7900..00000000 --- a/tests/bundle_tests/rest/UserTest.php +++ /dev/null @@ -1,126 +0,0 @@ -restClient->getObjectList(); - - $this->assertEquals(1, count($list), 'expected 1 list item'); - $this->assertEquals('folder', $list[0]->getType(), 'expected type to be folder'); - } - - public function testObjectGet() - { - $object = $this->restClient->getObjectById(1); - - $this->assertEquals('folder', $object->getType(), 'expected type to be folder'); - $this->assertEquals(1, $object->getId(), 'wrong id'); - - $originalCount = TestHelper::getObjectCount(); - - $emptyObject = TestHelper::createEmptyObject(); - $id = $emptyObject->getId(); - - $newLocalCount = TestHelper::getObjectCount(); - $newApiCount = $this->restClient->getObjectCount(); - $expectedCount = $originalCount + 1; - - $this->assertEquals($expectedCount, $newLocalCount); - $this->assertEquals($expectedCount, $newApiCount); - - $object = $this->restClient->getObjectById($id); - - $this->assertNotNull($object, 'expected new object'); - $this->assertInstanceOf(Unittest::class, $object); - $this->assertEquals($emptyObject->getId(), $object->getId()); - $this->assertEquals($emptyObject->getFullPath(), $object->getFullPath()); - } - - public function testCreateObjectConcrete() - { - $this->assertEquals(1, TestHelper::getObjectCount()); - - $unsavedObject = TestHelper::createEmptyObject('', false); - - // object not saved, object count must still be one - $this->assertEquals(1, TestHelper::getObjectCount()); - - $time = time(); - - $result = $this->restClient->createObjectConcrete($unsavedObject); - - $this->assertTrue($result->success, 'request not successful . ' . $result->msg); - $this->assertEquals(2, TestHelper::getObjectCount()); - - $id = $result->id; - $this->assertTrue($id > 1, 'id must be greater than 1'); - - $objectDirect = AbstractObject::getById($id); - $creationDate = $objectDirect->getCreationDate(); - - $this->assertTrue($creationDate >= $time, 'wrong creation date'); - - // as the object key is unique there must be exactly one object with that key - $list = $this->restClient->getObjectList('{ "o_key" : "' . $unsavedObject->getKey() . '"}'); - $this->assertEquals(1, count($list)); - } - - public function testDelete() - { - $savedObject = TestHelper::createEmptyObject(); - - $savedObject = AbstractObject::getById($savedObject->getId()); - $this->assertNotNull($savedObject); - - $response = $this->restClient->deleteObject($savedObject->getId()); - $this->assertTrue($response->success, "request wasn't successful"); - - // this will wipe our local cache - \Pimcore::collectGarbage(); - - $savedObject = AbstractObject::getById($savedObject->getId()); - $this->assertNull($savedObject, 'object still exists'); - } - - public function testFolder() - { - // create folder but don't save it - /** @var Folder $folder */ - $folder = TestHelper::createObjectFolder('myfolder', false); - $folder->setType('folder'); - - $fitem = AbstractObject::getById($folder->getId()); - $this->assertNull($fitem); - - $response = $this->restClient->createObjectFolder($folder); - $this->assertTrue($response->success, "request wasn't successful"); - - $id = $response->id; - $this->assertTrue($id > 1, 'id not set'); - - $folderDirect = AbstractObject::getById($id); - $this->assertEquals('folder', $folderDirect->getType()); - $this->assertInstanceOf(Folder::class, $folderDirect); - - $folderRest = $this->restClient->getObjectById($id); - $this->assertEquals('folder', $folderRest->getType()); - $this->assertInstanceOf(Folder::class, $folderRest); - $this->assertTrue(TestHelper::objectsAreEqual($folderRest, $folderDirect, false), 'objects are not equal'); - - $this->restClient->deleteObject($id); - - \Pimcore::collectGarbage(); - - $folderDirect = AbstractObject::getById($id); - $this->assertNull($folderDirect, 'folder still exists'); - } -}