Exemplo n.º 1
0
 public function testFindUser()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user1 = new CustomUser();
     $user1->setId('userId');
     $user1->setUsername('user1');
     $user1->setPassword('changeme');
     $user1->setAccount($account);
     $user2 = new User();
     $user2->setUsername('user2');
     $user2->setPassword('changeme');
     $user2->setAccount($account);
     $user3 = new User();
     $user3->setUsername('user3');
     $user3->setPassword('changeme');
     $user3->setAccount($account);
     $this->dm->persist($user1);
     $this->dm->persist($user2);
     $this->dm->persist($user3);
     $this->dm->flush();
     $this->dm->clear();
     unset($user1, $user2, $user3);
     $user = $this->dm->find('Documents\\CustomUser', 'userId');
     $this->assertNotNull($user);
     $this->assertEquals('userId', $user->getId());
     $this->assertEquals('user1', $user->getUsername());
     $this->dm->clear();
     unset($user);
     $this->assertNull($this->dm->find('Documents\\User', 'userId'));
     $this->assertNull($this->dm->find('Documents\\CustomUser', 'asd'));
 }
Exemplo n.º 2
0
 public function testPersist()
 {
     $this->dm->getConfiguration()->setDBPrefix('test_');
     $account = new Account();
     $account->setName('test');
     $this->dm->persist($account);
     $this->dm->flush();
     $this->assertTrue(!is_null($account->getId()));
     $mongo = $this->dm->getMongo()->getMongo();
     $testAccount = $mongo->test_doctrine_odm_tests->accounts->findOne(array('_id' => new \MongoId($account->getId())));
     $this->assertTrue(is_array($testAccount));
     $this->assertEquals($account->getId(), (string) $testAccount['_id']);
 }
Exemplo n.º 3
0
 public function testOneReference()
 {
     $account = new Account();
     $account->setName('Test Account');
     $user = new User();
     $user->setUsername('jwage');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->flush();
     $this->dm->clear();
     $accountId = $user->getAccount()->getId();
     $user2 = $this->dm->createQuery('Documents\\User')->where('id', $user->getId())->getSingleResult();
 }
Exemplo n.º 4
0
 public function testOneReference()
 {
     $account = new Account();
     $account->setName('Test Account');
     $user = new User();
     $user->setUsername('jwage');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->flush();
     $this->dm->clear();
     $accountId = $user->getAccount()->getId();
     $qb = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId());
     $query = $qb->getQuery();
     $user2 = $query->getSingleResult();
 }
Exemplo n.º 5
0
 public function testCascadeInsertUpdateAndRemove()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $account->setName('w00t');
     $this->dm->flush();
     $this->assertEquals('w00t', $user->getAccount()->getName());
     $this->dm->remove($user);
     $this->dm->flush();
     $this->dm->clear();
 }
Exemplo n.º 6
0
 public function testRemove()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->remove($user);
     $this->dm->flush();
     $account = $this->dm->find('Documents\\Account', $account->getId());
     $this->assertNull($account);
     $user = $this->dm->find('Documents\\User', $user->getId());
     $this->assertNull($user);
 }
Exemplo n.º 7
0
 public function testReplaceEntireGroupsArray()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon333');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $group2 = new Group('member');
     $user->addGroup(new Group('administrator'));
     $user->addGroup($group2);
     $user->addGroup(new Group('moderator'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find('Documents\\User', $user->getId());
     $this->assertNotNull($user);
     // Issue is collection must be initialized
     $groups = $user->getGroups();
     $groups[0];
     // initialize collection
     // reffectively remove two of the groups
     //$user->getGroups()->clear();
     //$user->getGroups()->add($group2);
     $user->setGroups(array($group2));
     $this->assertEquals(1, count($user->getGroups()));
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find('Documents\\User', $user->getId());
     $this->assertEquals(1, count($user->getGroups()));
 }
 public function testReplaceGroups()
 {
     $this->dm->getUnitOfWork()->setDocumentPersister('Documents\\User', new BasicDocumentPersister($this->dm, $this->classMetadata));
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $user->addGroup(new Group('administrator'));
     $user->addGroup(new Group('member'));
     $user->addGroup(new Group('moderator'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     unset($user, $account);
     $user = $this->dm->findOne('Documents\\User');
     $user->removeGroup('moderator');
     $user->removeGroup('member');
     $this->assertEquals(1, count($user->getGroups()));
     $user->addGroup(new Group('seller'));
     $user->addGroup(new Group('supplier'));
     $this->assertEquals(3, count($user->getGroups()));
     $this->dm->getUnitOfWork()->setDocumentPersister('Documents\\User', $this->persister);
     $this->persister->expects($this->once())->method('update')->with($user);
     $this->dm->getUnitOfWork()->computeChangeSets();
     $update = $this->persister->prepareUpdateData($user);
     $this->assertFalse(array_key_exists('$set', $update));
     $this->assertFalse(array_key_exists('$unset', $update));
     $this->assertTrue(array_key_exists('$pullAll', $update));
     $this->assertTrue(array_key_exists('groups', $update['$pullAll']));
     $this->assertEquals(2, count($update['$pullAll']['groups']));
     $this->assertTrue(array_key_exists('$pushAll', $update));
     $this->assertTrue(array_key_exists('groups', $update['$pushAll']));
     $this->assertEquals(2, count($update['$pushAll']['groups']));
     $this->dm->flush();
     $this->dm->clear();
     unset($user);
     $user = $this->dm->findOne('Documents\\User');
     $this->assertEquals(3, count($user->getGroups()));
 }