/** * This function used as a helper function in test functions to save objects. * * @param int $numberOfObjects Number of objects you want to save. * @param callable $callback Function which takes int as a parameter. * and should return ParseObject. */ public function saveObjects($numberOfObjects, $callback) { $allObjects = []; for ($i = 0; $i < $numberOfObjects; $i++) { $allObjects[] = $callback($i); } ParseObject::saveAll($allObjects); }
private function _addTestObjects($numberOfObjects = 5) { $objects = []; for ($i = 0; $i < $numberOfObjects; $i++) { $object = new ParseObject($this->testParseClassName); $object->set('String', 'String' . $i); $objects[] = $object; } ParseObject::saveAll($objects); }
public function createEden() { $eden = []; $eden['adam'] = $this->createUser('adam'); $eden['eve'] = $this->createUser('eve'); $eden['snake'] = $this->createUser('snake'); $eden['adam']->signUp(); $eden['eve']->signUp(); $eden['snake']->signUp(); $eden['humans'] = ParseRole::createRole('humans', $this->aclPublic()); $eden['humans']->getUsers()->add($eden['adam']); $eden['humans']->getUsers()->add($eden['eve']); $eden['creatures'] = ParseRole::createRole('creatures', $this->aclPublic()); $eden['creatures']->getUsers()->add($eden['snake']); ParseObject::saveAll([$eden['humans'], $eden['creatures']]); $eden['edenkin'] = ParseRole::createRole('edenkin', $this->aclPublic()); $eden['edenkin']->getRoles()->add($eden['humans']); $eden['edenkin']->getRoles()->add($eden['creatures']); $eden['edenkin']->save(); $eden['apple'] = ParseObject::create('Things'); $eden['apple']->set('name', 'apple'); $eden['apple']->set('ACL', $this->aclPrivateTo($eden['humans'])); $eden['garden'] = ParseObject::create('Things'); $eden['garden']->set('name', 'garden'); $eden['garden']->set('ACL', $this->aclPrivateTo($eden['edenkin'])); ParseObject::saveAll([$eden['apple'], $eden['garden']]); return $eden; }
public function testCannotSaveAllWithOtherUser() { $user = new ParseUser(); $user->setUsername("asdf"); $user->setPassword("zxcv"); $user->signUp(); $otherUser = new ParseUser(); $otherUser->setUsername("hacker"); $otherUser->setPassword("password"); $otherUser->signUp(); $this->assertEquals(ParseUser::getCurrentUser(), $otherUser); $obj = ParseObject::create("TestObject"); $obj->set('user', $otherUser); $obj->save(); $item1 = ParseObject::create("TestObject"); $item1->set('num', 0); $item1->save(); $item1->set('num', 1); $item2 = ParseObject::create("TestObject"); $item2->set('num', 2); $user->setUsername('changed'); $this->setExpectedException('Parse\\ParseAggregateException', 'Errors during batch save.'); ParseObject::saveAll([$item1, $item2, $user]); }
public function createEden() { $eden = []; $eden['adam'] = $this->createUser('adam'); $eden['eve'] = $this->createUser('eve'); $eden['snake'] = $this->createUser('snake'); $eden['adam']->signUp(); $eden['eve']->signUp(); $eden['snake']->signUp(); $eden['humans'] = ParseRole::createRole("humans", $this->aclPublic()); $eden['humans']->getUsers()->add($eden['adam']); $eden['humans']->getUsers()->add($eden['eve']); $eden['creatures'] = ParseRole::createRole("creatures", $this->aclPublic()); $eden['creatures']->getUsers()->add($eden['snake']); ParseObject::saveAll([$eden['humans'], $eden['creatures']]); $eden['edenkin'] = ParseRole::createRole("edenkin", $this->aclPublic()); $eden['edenkin']->getRoles()->add($eden['humans']); $eden['edenkin']->getRoles()->add($eden['creatures']); $eden['edenkin']->save(); $eden['apple'] = ParseObject::create("Things"); $eden['apple']->set("name", "apple"); $eden['apple']->set("ACL", $this->aclPrivateTo($eden['humans'])); $eden['garden'] = ParseObject::create("Things"); $eden['garden']->set("name", "garden"); $eden['garden']->set("ACL", $this->aclPrivateTo($eden['edenkin'])); ParseObject::saveAll([$eden['apple'], $eden['garden']]); return $eden; }
public function testFetchAll() { $obj1 = ParseObject::create('TestObject'); $obj2 = ParseObject::create('TestObject'); $obj3 = ParseObject::create('TestObject'); $obj1->set('foo', 'bar'); $obj2->set('foo', 'bar'); $obj3->set('foo', 'bar'); ParseObject::saveAll([$obj1, $obj2, $obj3]); $newObj1 = ParseObject::create('TestObject', $obj1->getObjectId()); $newObj2 = ParseObject::create('TestObject', $obj2->getObjectId()); $newObj3 = ParseObject::create('TestObject', $obj3->getObjectId()); $results = ParseObject::fetchAll([$newObj1, $newObj2, $newObj3]); $this->assertEquals(3, count($results)); $this->assertEquals('bar', $results[0]->get('foo')); $this->assertEquals('bar', $results[1]->get('foo')); $this->assertEquals('bar', $results[2]->get('foo')); }
public function testACLSaveAllWithPermissions() { $alice = new ParseUser(); $alice->setUsername('alice'); $alice->setPassword('wonderland'); $alice->signUp(); $acl = ParseACL::createACLWithUser($alice); $object1 = ParseObject::create('Object'); $object1->setACL($acl); $object1->save(); $object2 = ParseObject::create('Object'); $object2->setACL($acl); $object2->save(); $this->assertTrue($object1->getACL()->getUserReadAccess($alice)); $this->assertTrue($object1->getACL()->getUserWriteAccess($alice)); $this->assertFalse($object1->getACL()->getPublicReadAccess()); $this->assertFalse($object1->getACL()->getPublicWriteAccess()); $this->assertTrue($object2->getACL()->getUserReadAccess($alice)); $this->assertTrue($object2->getACL()->getUserWriteAccess($alice)); $this->assertFalse($object2->getACL()->getPublicReadAccess()); $this->assertFalse($object2->getACL()->getPublicWriteAccess()); $object1->set('foo', 'bar'); $object2->set('foo', 'bar'); ParseObject::saveAll([$object1, $object2]); $query = new ParseQuery('Object'); $query->equalTo('foo', 'bar'); $this->assertEquals(2, count($query->find())); }
public function testFetchAll() { $obj1 = ParseObject::create("TestObject"); $obj2 = ParseObject::create("TestObject"); $obj3 = ParseObject::create("TestObject"); $obj1->set("foo", "bar"); $obj2->set("foo", "bar"); $obj3->set("foo", "bar"); ParseObject::saveAll([$obj1, $obj2, $obj3]); $newObj1 = ParseObject::create("TestObject", $obj1->getObjectId()); $newObj2 = ParseObject::create("TestObject", $obj2->getObjectId()); $newObj3 = ParseObject::create("TestObject", $obj3->getObjectId()); $results = ParseObject::fetchAll([$newObj1, $newObj2, $newObj3]); $this->assertEquals(3, count($results)); $this->assertEquals("bar", $results[0]->get("foo")); $this->assertEquals("bar", $results[1]->get("foo")); $this->assertEquals("bar", $results[2]->get("foo")); }
public function testBatchSaveExceptions() { $obj1 = ParseObject::create("TestObject"); $obj2 = ParseObject::create("TestObject"); $obj1->set("fos^^co", "hi"); $obj2->set("fo^^mo", "hi"); try { ParseObject::saveAll([$obj1, $obj2]); $this->fail("Save should have failed."); } catch (\Parse\ParseAggregateException $ex) { $errors = $ex->getErrors(); $this->assertContains("invalid field name", $errors[0]['error']); $this->assertContains("invalid field name", $errors[1]['error']); } }