示例#1
0
 /**
  * Testing the getRelatedObject method.
  *
  * @since 1.2.1
  */
 public function testGetRelatedObject()
 {
     $oneToOneRel = new Relation();
     $oneToOneRel->setRelatedClass('Alpha\\Model\\Person');
     $oneToOneRel->setRelatedClassField('OID');
     $oneToOneRel->setRelatedClassDisplayField('displayName');
     $oneToOneRel->setRelationType('ONE-TO-ONE');
     $oneToOneRel->setValue($this->person->getOID());
     $this->assertEquals($this->person->getDisplayName(), $oneToOneRel->getRelatedObject()->get('displayName'), 'testing the getRelatedObject method');
 }
示例#2
0
 /**
  * Testing the removeFromCache method.
  *
  * @since 1.2.1
  * @dataProvider getActiveRecordProviders
  */
 public function testRemoveFromCache($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $config = ConfigProvider::getInstance();
     $oldSetting = $config->get('cache.provider.name');
     $config->set('cache.provider.name', 'Alpha\\Util\\Cache\\CacheProviderArray');
     $this->person->save();
     $fromCache = new Person();
     $fromCache->setOID($this->person->getOID());
     $this->assertTrue($fromCache->loadFromCache(), 'testing that the item loads from the cache');
     $fromCache->removeFromCache();
     $this->assertFalse($fromCache->loadFromCache(), 'testing that the item is gone from the cache');
     $config->set('cache.provider.name', $oldSetting);
 }
示例#3
0
 /**
  * Testing the getRelatedObjects method with a ONE-TO-MANY and MANY-TO-MANY relation.
  *
  * @since 1.2.1
  */
 public function testGetRelatedObjects()
 {
     $group = new Rights();
     $group->set('name', 'unittestgroup');
     $group->save();
     $person1 = new Person();
     $person1->set('displayName', 'user1');
     $person1->set('email', '*****@*****.**');
     $person1->set('password', 'password');
     $person1->save();
     $lookup = $person1->getPropObject('rights')->getLookup();
     $lookup->setValue(array($person1->getOID(), $group->getOID()));
     $lookup->save();
     $person2 = new Person();
     $person2->set('displayName', 'user2');
     $person2->set('email', '*****@*****.**');
     $person2->set('password', 'password');
     $person2->save();
     $lookup = $person2->getPropObject('rights')->getLookup();
     $lookup->setValue(array($person2->getOID(), $group->getOID()));
     $lookup->save();
     $person2->getPropObject('rights')->setValue($group->getOID());
     $this->assertEquals(2, count($group->getPropObject('members')->getRelatedObjects('Alpha\\Model\\Rights')), 'testing the getRelatedObjects method with a MANY-TO-MANY relation');
     $this->assertTrue($group->getPropObject('members')->getRelatedObjects('Alpha\\Model\\Rights')[0] instanceof Person, 'testing the getRelatedObjects method with a MANY-TO-MANY relation');
     $article = new Article();
     $article->set('title', 'unit test');
     $article->set('description', 'unit test');
     $article->set('content', 'unit test');
     $article->set('author', 'unit test');
     $article->save();
     $comment1 = new ArticleComment();
     $comment1->set('content', 'unit test');
     $comment1->getPropObject('articleOID')->setValue($article->getOID());
     $comment1->save();
     $comment2 = new ArticleComment();
     $comment2->set('content', 'unit test');
     $comment2->getPropObject('articleOID')->setValue($article->getOID());
     $comment2->save();
     $this->assertEquals(2, count($article->getPropObject('comments')->getRelatedObjects()), 'testing the getRelatedObjects method with a ONE-TO-MANY relation');
     $this->assertTrue($article->getPropObject('comments')->getRelatedObjects()[0] instanceof ArticleComment, 'testing the getRelatedObjects method with a ONE-TO-MANY relation');
 }
示例#4
0
 /**
  * Testing the loadAllbyAttribute() method.
  *
  * @since 1.2.1
  */
 public function testLoadAllbyAttribute()
 {
     $group = new Rights();
     $group->set('name', 'unittestgroup');
     $group->save();
     $person1 = new Person();
     $person1->set('displayName', 'user1');
     $person1->set('email', '*****@*****.**');
     $person1->set('password', 'password');
     $person1->save();
     $lookup = $person1->getPropObject('rights')->getLookup();
     $lookup->setValue(array($person1->getOID(), $group->getOID()));
     $lookup->save();
     $person2 = new Person();
     $person2->set('displayName', 'user2');
     $person2->set('email', '*****@*****.**');
     $person2->set('password', 'password');
     $person2->save();
     $lookup = $person2->getPropObject('rights')->getLookup();
     $lookup->setValue(array($person2->getOID(), $group->getOID()));
     $lookup->save();
     $lookup = new RelationLookup('Alpha\\Model\\Person', 'Alpha\\Model\\Rights');
     $this->assertEquals(2, count($lookup->loadAllbyAttribute('rightID', $group->getOID())), 'testing the loadAllbyAttribute() method');
 }
示例#5
0
 /**
  * test cases to see if access rights on controllers are working as expected.
  *
  * @since 1.0
  */
 public function testRightsAccess()
 {
     $config = ConfigProvider::getInstance();
     $this->group = new Rights();
     $this->group->set('name', 'testgroup');
     $this->group->save();
     $this->person->save();
     $lookup = $this->person->getPropObject('rights')->getLookup();
     $lookup->setValue(array($this->person->getOID(), $this->group->getOID()));
     $lookup->save();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $session->set('currentUser', $this->person);
     try {
         $controller = new ImageController('testgroup');
     } catch (PHPException $e) {
         $this->fail('failed to access a controller that I have access to by rights group membership');
     }
 }