コード例 #1
0
ファイル: SiteMoveTest.php プロジェクト: Tom-Byrne/gocdb
 public function testSiteMoves()
 {
     print __METHOD__ . "\n";
     //Insert initial data
     $N1 = TestUtil::createSampleNGI("NGI1");
     $N2 = TestUtil::createSampleNGI("NGI2");
     $S1 = TestUtil::createSampleSite("Site1");
     $S2 = TestUtil::createSampleSite("Site2");
     $S3 = TestUtil::createSampleSite("Site3");
     $SE1 = TestUtil::createSampleService("SEP1");
     $dummy_user = TestUtil::createSampleUser('Test', 'User', '/Some/string');
     //Make dummy user a GOCDB admin so it can perfirm site moves etc.
     $dummy_user->setAdmin(true);
     /*
      * Current code in TestUtil does not set sites up as being owned by an an NGI by default.
      *Add them to NGI
      */
     $N1->addSiteDoJoin($S1);
     $N2->addSiteDoJoin($S2);
     $N2->addSiteDoJoin($S3);
     //Add service end point to service 1
     $S1->addServiceDoJoin($SE1);
     //Persist initial data
     $this->em->persist($N1);
     $this->em->persist($N2);
     $this->em->persist($S1);
     $this->em->persist($S2);
     $this->em->persist($S3);
     $this->em->persist($SE1);
     $this->em->persist($dummy_user);
     $this->em->flush();
     //Use DB connection to check data
     $con = $this->getConnection();
     /*
      * Check both that each NGI is present and that the ID matches the doctrine one
      */
     $N1_ID = $N1->getId();
     $sql = "SELECT 1 FROM ngis WHERE name = 'NGI1' AND ID = '{$N1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $N2_ID = $N2->getId();
     $sql = "SELECT 1 FROM ngis WHERE name = 'NGI2' AND ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     /*
      * Check each site is: present, has the right ID & parent NGI
      */
     $S1_id = $S1->getId();
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site1' AND ID = '{$S1_id}' AND NGI_ID = '{$N1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $S2_id = $S2->getId();
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site2' AND ID = '{$S2_id}' AND NGI_ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $S3_id = $S3->getId();
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site3' AND ID = '{$S3_id}' AND NGI_ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Check the SEP has correct id and Site
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP1' AND parentsite_id = '{$S1_id}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Move sites
     $serv = new org\gocdb\services\Site();
     $serv->setEntityManager($this->em);
     $serv->moveSite($S1, $N2, $dummy_user);
     $serv->moveSite($S2, $N1, $dummy_user);
     $serv->moveSite($S3, $N2, $dummy_user);
     //No change
     //flush movement
     $this->em->flush();
     //Use doctrine to check movement
     //Check correct NGI for each site
     $this->assertEquals($N2, $S1->getNgi());
     $this->assertEquals($N1, $S2->getNgi());
     $this->assertEquals($N2, $S3->getNgi());
     //Check correct sites for each NGI
     //NGI1
     $ngisites = $N1->getSites();
     foreach ($ngisites as $site) {
         $this->assertEquals($S2, $site);
     }
     //NGI2
     $ngisites = $N2->getSites();
     foreach ($ngisites as $site) {
         $this->assertTrue($site == $S1 or $site == $S3);
     }
     //check Service End Point
     $this->assertEquals($S1, $SE1->getParentSite());
     //Use database connection to check movememrnt
     $con = $this->getConnection();
     //Check NGIs are still present and their ID is unchanged
     $sql = "SELECT 1 FROM ngis WHERE name = 'NGI1' AND ID = '{$N1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $sql = "SELECT 1 FROM ngis WHERE name = 'NGI2' AND ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Check each NGI has the correct number of sites
     //NGI1
     $sql = "SELECT 1 FROM sites WHERE NGI_ID = '{$N1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //NGI2
     $sql = "SELECT 1 FROM sites WHERE NGI_ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(2, $result->getRowCount());
     //check Site IDs are unchanged and they are assigned to the correct NGI
     //Site 1
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site1' AND ID = '{$S1_id}' AND NGI_ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Site 2
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site2' AND ID = '{$S2_id}' AND NGI_ID = '{$N1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Site 3
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site3' AND ID = '{$S3_id}' AND NGI_ID = '{$N2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
 }
コード例 #2
0
//  site4 has all scopes
for ($i = 0; $i < $scopeCount; $i++) {
    $site4->addScope($scopes[$i]);
}
// Sites ****************************
// Services: all services are added to $site0
// ****************************
$service0 = TestUtil::createSampleService("Service0");
$site0->addServiceDoJoin($service0);
$service1 = TestUtil::createSampleService("Service1");
$site0->addServiceDoJoin($service1);
$service2 = TestUtil::createSampleService("Service2");
$site0->addServiceDoJoin($service2);
$service3 = TestUtil::createSampleService("Service3");
$site0->addServiceDoJoin($service3);
$service4 = TestUtil::createSampleService("Service4");
$site0->addServiceDoJoin($service4);
$this->em->persist($service0);
$this->em->persist($service1);
$this->em->persist($service2);
$this->em->persist($service3);
$this->em->persist($service4);
// Add different scopes to selected services:
// service0 has no scope
// service1 has one scope
$service0->addScope($scopes[0]);
// service2 has two scopes
$service2->addScope($scopes[0]);
$service2->addScope($scopes[1]);
// service3 has three scopes
$service3->addScope($scopes[0]);
コード例 #3
0
 /**
  * Show how Bidirectional relationships must be correctly managed in 
  * userland/application code. (See Doctrine the tutorial: 
  * "Consistency of bi-directional references on the inverse side of a 
  * relation have to be managed in userland application code. Doctrine 
  * cannot magically update your collections to be consistent."). 
  */
 public function testDowntimeEndpoint_BidirectionalJoinConsistencyManagement()
 {
     print __METHOD__ . "\n";
     // create a linked entity graph as beow:
     //
     //     se        (1 service)
     //    / | \
     // el1 el2 el3   (3 endpoints)
     //    \ | /
     //     dt1       (1 downtime)
     $se = TestUtil::createSampleService('service1');
     $el1 = TestUtil::createSampleEndpointLocation();
     $el2 = TestUtil::createSampleEndpointLocation();
     $el3 = TestUtil::createSampleEndpointLocation();
     $se->addEndpointLocationDoJoin($el1);
     $se->addEndpointLocationDoJoin($el2);
     $se->addEndpointLocationDoJoin($el3);
     $dt1 = new Downtime();
     $dt1->setDescription('downtime description');
     $dt1->setSeverity("WARNING");
     $dt1->setClassification("UNSCHEDULED");
     $dt1->addEndpointLocation($el1);
     $dt1->addEndpointLocation($el2);
     $dt1->addEndpointLocation($el3);
     // persist and flush
     $this->em->persist($se);
     $this->em->persist($el1);
     $this->em->persist($el2);
     $this->em->persist($el3);
     $this->em->persist($dt1);
     $this->em->flush();
     // Now delete the relationship between dt1 and el1 + el2 using OWNING
     // SIDE ONLY; since downtime is the OWNING side we must remove el1 + el2
     // from downtime to actually delete the relationships in the DB
     // (on the subsequent flush). Since we have only removed the relationship
     // on the downtime side, our in-mem entity model is now inconsistent !
     $dt1->getEndpointLocations()->removeElement($el1);
     //$el1->getDowntimes()->removeElement($dt1);
     $dt1->getEndpointLocations()->removeElement($el2);
     //$el2->getDowntimes()->removeElement($dt1);
     $this->em->flush();
     // Entity model in DB now looks like this:
     //     se
     //    / | \
     // el1 el2 el3
     //        /
     //     dt1      (note FKs/relationships have been removed)
     // Assert that there are still three EndpointLocations and one Downtimes in the database
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 3);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 1);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     // Assert that our in-mem entity model is now inconsistent with DB
     // when VIEWED FROM THE ENDPOINT SIDE.
     $this->assertEquals(1, count($el1->getDowntimes()));
     $this->assertEquals(1, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     // Assert that our in-mem entity model is consistent with DB
     // when VIEWED FROM THE DOWNTIME SIDE:
     // dt1 still has el3 linked (as expected) but not el1 or el2.
     // Note we use first() method to fetch first array collection entry!
     // (calling get(0) would not work as expected because the collection
     // is a map so array key values are preserved - el3 was added 3rd so it
     // preserves its zero-offset key value of 2).
     $this->assertEquals(1, count($dt1->getEndpointLocations()));
     $this->assertSame($el3, $dt1->getEndpointLocations()->first());
     $this->assertSame($el3, $dt1->getEndpointLocations()->get(2));
     // Next lines keep our in-mem inverse side consistent with DB. If we
     // didn't do this, then our first assertion on the following lines below
     // would fail! This shows that you have to keep your bi-directional
     // relationships consistent in userland/application code, doctrine
     // won't do this for you!
     $el1->getDowntimes()->removeElement($dt1);
     $el2->getDowntimes()->removeElement($dt1);
     // After updating the 'in-memory' entity model, check that el1 and el2
     // have no linked downtimes while el3 still has dt linked.
     // This mirrors what we have in the DB.
     $this->assertEquals(0, count($el1->getDowntimes()));
     $this->assertEquals(0, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     // our collection key value is still same
     $this->assertSame($el3, $dt1->getEndpointLocations()->get(2));
 }
コード例 #4
0
 * @author David Meredith 
 */
$roleType1 = TestUtil::createSampleRoleType("NAME");
$roleType2 = TestUtil::createSampleRoleType("NAME2");
$this->em->persist($roleType1);
$this->em->persist($roleType2);
// Create a user
$userWithRoles = TestUtil::createSampleUser("Test", "Testing", "/c=test");
$this->em->persist($userWithRoles);
$userId = $userWithRoles->getId();
// Create an NGI, site and services
$ngi = TestUtil::createSampleNGI("MYNGI");
$site1 = TestUtil::createSampleSite('site1');
$site2 = TestUtil::createSampleSite('site2');
$service1 = TestUtil::createSampleService('site1_service1');
$service2 = TestUtil::createSampleService('site1_service2');
$endpoint1 = TestUtil::createSampleEndpointLocation();
$downtime1 = TestUtil::createSampleDowntime();
$downtime2 = TestUtil::createSampleDowntime();
$service1->addEndpointLocationDoJoin($endpoint1);
$downtime1->addEndpointLocation($endpoint1);
$downtime2->addEndpointLocation($endpoint1);
$site1->addServiceDoJoin($service1);
$site1->addServiceDoJoin($service2);
$ngi->addSiteDoJoin($site1);
$ngi->addSiteDoJoin($site2);
$certStatusLog1 = TestUtil::createSampleCertStatusLog();
$certStatusLog2 = TestUtil::createSampleCertStatusLog();
$site2->addCertificationStatusLog($certStatusLog1);
$site2->addCertificationStatusLog($certStatusLog2);
$this->em->persist($ngi);
コード例 #5
0
 /**
  * Test the <code>$serviceDAO->removeEndpoint($endpoint)</code> method.   
  */
 public function testServiceDAORemoveEndpoint()
 {
     print __METHOD__ . "\n";
     // create a linked entity graph as beow:
     //
     //      se -----|    (1 service)
     //     / | \    |
     //  el1 el2 el3 |    (3 endpoints)
     //  |  \ | /    |
     // dt0  dt1 ----|    (1 downtime)
     $dt1 = new Downtime();
     $dt1->setDescription('downtime description');
     $dt1->setSeverity("WARNING");
     $dt1->setClassification("UNSCHEDULED");
     $dt0 = new Downtime();
     $dt0->setDescription('downtime description');
     $dt0->setSeverity("WARNING");
     $dt0->setClassification("UNSCHEDULED");
     $se = TestUtil::createSampleService('service1');
     $el1 = TestUtil::createSampleEndpointLocation();
     $el2 = TestUtil::createSampleEndpointLocation();
     $el3 = TestUtil::createSampleEndpointLocation();
     $se->addEndpointLocationDoJoin($el1);
     $se->addEndpointLocationDoJoin($el2);
     $se->addEndpointLocationDoJoin($el3);
     //$se->_addDowntime($dt1); // we don't call this in client code !
     $dt1->addEndpointLocation($el1);
     $dt1->addEndpointLocation($el2);
     $dt1->addEndpointLocation($el3);
     $dt1->addService($se);
     $dt0->addEndpointLocation($el1);
     //$dt0->addService($se); // note we don't add this relationship for purposes of the test
     // persist and flush
     $this->em->persist($se);
     $this->em->persist($el1);
     $this->em->persist($el2);
     $this->em->persist($el3);
     $this->em->persist($dt1);
     $this->em->persist($dt0);
     $this->em->flush();
     // create DAO to test
     $serviceDao = new ServiceDAO();
     $serviceDao->setEntityManager($this->em);
     // remove first endpoint causing dt0 to be orphaned
     $serviceDao->removeEndpoint($el1);
     $this->em->flush();
     // Assert expected object graph
     //     se -----|   (1 service)
     //      | \    |
     //     el2 el3 |   (2 endpoints)
     //      | /    |
     // dt0 dt1-----|   (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 2);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(1, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     $this->assertEquals(2, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(2, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
     // remove another el
     $serviceDao->removeEndpoint($el2);
     $this->em->flush();
     // Assert expected object graph in DB
     //     se -----| (1 service)
     //       \     |
     //        el3  | (1 endpoints)
     //        /    |
     // dt0 dt1-----| (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(1, count($el3->getDowntimes()));
     $this->assertEquals(1, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(1, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
     // remove another el
     $serviceDao->removeEndpoint($el3);
     $this->em->flush();
     // Assert expected object graph in DB
     //     se -----| (1 service)
     //             |
     //             | (1 endpoints)
     //             |
     // dt0 dt1-----| (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(0, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(0, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
 }
コード例 #6
0
ファイル: ServiceMoveTest.php プロジェクト: Tom-Byrne/gocdb
 public function testServiceMoves()
 {
     print __METHOD__ . "\n";
     //Insert initial data
     $S1 = TestUtil::createSamplesite("Site1");
     $S2 = TestUtil::createSamplesite("Site2");
     $SE1 = TestUtil::createSampleService("SEP1");
     $SE2 = TestUtil::createSampleService("SEP2");
     $SE3 = TestUtil::createSampleService("SEP3");
     $dummy_user = TestUtil::createSampleUser('Test', 'User', '/Some/string');
     //Make dummy user a GOCDB admin so it can perfirm site moves etc.
     $dummy_user->setAdmin(true);
     // Assign the service end points to the sites
     $S1->addServiceDoJoin($SE1);
     $S2->addServiceDoJoin($SE2);
     $S2->addServiceDoJoin($SE3);
     //Persist initial data
     $this->em->persist($S1);
     $this->em->persist($S2);
     $this->em->persist($SE1);
     $this->em->persist($SE2);
     $this->em->persist($SE3);
     $this->em->persist($dummy_user);
     $this->em->flush();
     //Use DB connection to check data
     $con = $this->getConnection();
     /*
      * Check both that each Site is present and that the ID matches the doctrine one
      */
     $S1_ID = $S1->getId();
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site1' AND ID = '{$S1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $S2_ID = $S2->getId();
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site2' AND ID = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     /*
      * Check each service endpoint is: present, has the right ID & parent Site
      */
     $SE1_id = $SE1->getId();
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP1' AND ID = '{$SE1_id}' AND PARENTSITE_ID = '{$S1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $SE2_id = $SE2->getId();
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP2' AND ID = '{$SE2_id}' AND PARENTSITE_ID = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $SE3_id = $SE3->getId();
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP3' AND ID = '{$SE3_id}' AND PARENTSITE_ID = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Move service endpoints
     $serv = new org\gocdb\services\ServiceService();
     $serv->setEntityManager($this->em);
     $serv->moveService($SE1, $S2, $dummy_user);
     $serv->moveService($SE2, $S1, $dummy_user);
     $serv->moveService($SE3, $S2, $dummy_user);
     //No change
     //flush movement
     $this->em->flush();
     //Use doctrine to check movement
     //Check correct Site for each service endpoint
     $this->assertEquals($S2, $SE1->getParentSite());
     $this->assertEquals($S1, $SE2->getParentSite());
     $this->assertEquals($S2, $SE3->getParentSite());
     //Check correct service endpoints for each Site
     //Site1
     $SiteSEPs = $S1->getServices();
     foreach ($SiteSEPs as $SEP) {
         $this->assertEquals($SE2, $SEP);
     }
     //Site2
     $SiteSEPs = $S2->getServices();
     foreach ($SiteSEPs as $SEP) {
         $this->assertTrue($SEP == $SE1 or $SEP == $SE3);
     }
     //Use database connection to check movememrnt
     $con = $this->getConnection();
     //Check Sites are still present and their ID is unchanged
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site1' AND ID = '{$S1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     $sql = "SELECT 1 FROM sites WHERE shortname = 'Site2' AND ID = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Check each Site has the correct number of service endpoints
     //Site 1
     $sql = "SELECT 1 FROM services WHERE parentsite_id = '{$S1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Site 2
     $sql = "SELECT 1 FROM services WHERE parentsite_id = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(2, $result->getRowCount());
     //check Site IDs are unchanged and they are assigned to the correct NGI
     //Site 1
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP1' AND id = '{$SE1_id}' AND parentsite_id = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Site 2
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP2' AND id = '{$SE2_id}' AND parentsite_id = '{$S1_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
     //Site 3
     $sql = "SELECT 1 FROM services WHERE hostname = 'SEP3' AND id = '{$SE3_id}' AND parentsite_id = '{$S2_ID}'";
     $result = $con->createQueryTable('', $sql);
     $this->assertEquals(1, $result->getRowCount());
 }
コード例 #7
0
 /**
  * Persist some seed data - roletypes, user, Project, NGI, sites and SEs and 
  * assert that the user has the expected number of roles that grant specific 
  * actions over the owned objects. For example, assert that the user has 'n' 
  * number of roles that allow a particular site to be edited, or 'n' number 
  * of roles that allow an NGI certification status change.  
  */
 public function testAuthorizeAction1()
 {
     print __METHOD__ . "\n";
     // Create roletypes
     $siteAdminRT = TestUtil::createSampleRoleType(RoleTypeName::SITE_ADMIN);
     $ngiManRT = TestUtil::createSampleRoleType(RoleTypeName::NGI_OPS_MAN);
     $rodRT = TestUtil::createSampleRoleType(RoleTypeName::REG_STAFF_ROD);
     $codRT = TestUtil::createSampleRoleType(RoleTypeName::COD_ADMIN);
     $this->em->persist($siteAdminRT);
     // edit site1 (but not cert status)
     $this->em->persist($ngiManRT);
     // edit owned site1/site2 and cert status
     $this->em->persist($rodRT);
     // edit owned sites 1and2 (but not cert status)
     $this->em->persist($codRT);
     // edit all sites cert status only
     // Create a user
     $u = TestUtil::createSampleUser("Test", "Testing", "/c=test");
     $this->em->persist($u);
     // Create a linked object graph
     // NGI->Site1->SE
     //   |->Site2
     $ngi = TestUtil::createSampleNGI("MYNGI");
     $this->em->persist($ngi);
     $site1 = TestUtil::createSampleSite("SITENAME");
     //$site1->setNgiDoJoin($ngi);
     $ngi->addSiteDoJoin($site1);
     $this->em->persist($site1);
     $se1 = TestUtil::createSampleService('somelabel');
     $site1->addServiceDoJoin($se1);
     $this->em->persist($se1);
     $site2_userHasNoDirectRole = TestUtil::createSampleSite("SITENAME_2");
     $ngi->addSiteDoJoin($site2_userHasNoDirectRole);
     //$site2_userHasNoDirectRole->setNgiDoJoin($ngi);
     $this->em->persist($site2_userHasNoDirectRole);
     // Create ngiManagerRole, ngiUserRole, siteAdminRole and link user and owned entities
     $ngiManagerRole = TestUtil::createSampleRole($u, $ngiManRT, $ngi, RoleStatus::GRANTED);
     $this->em->persist($ngiManagerRole);
     $rodUserRole = TestUtil::createSampleRole($u, $rodRT, $ngi, RoleStatus::GRANTED);
     $this->em->persist($rodUserRole);
     $siteAdminRole = TestUtil::createSampleRole($u, $siteAdminRT, $site1, RoleStatus::GRANTED);
     $this->em->persist($siteAdminRole);
     $this->em->flush();
     // ********MUST******** start a new connection to test transactional
     // isolation of RoleService methods.
     $em = $this->createEntityManager();
     $siteService = new org\gocdb\services\Site();
     $siteService->setEntityManager($em);
     // Assert user can edit site using 3 enabling roles
     $enablingRoles = $siteService->authorizeAction(\Action::EDIT_OBJECT, $site1, $u);
     $this->assertEquals(3, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::SITE_ADMIN, $enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::REG_STAFF_ROD, $enablingRoles));
     // Assert user can only edit cert status through his NGI_OPS_MAN role
     $enablingRoles = $siteService->authorizeAction(\Action::SITE_EDIT_CERT_STATUS, $site1, $u);
     $this->assertEquals(1, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     // Add a new project and link ngi and give user COD_ADMIN Project role (use $this->em to isolate)
     // Project->NGI->Site1->SE
     //            |->Site2
     $proj = new Project('EGI project');
     $proj->addNgi($ngi);
     //$ngi->addProject($proj); // not strictly needed
     $this->em->persist($proj);
     $codRole = TestUtil::createSampleRole($u, $codRT, $proj, RoleStatus::GRANTED);
     $this->em->persist($codRole);
     $this->em->flush();
     // Assert user now has 2 roles that enable SITE_EDIT_CERT_STATUS change action
     $enablingRoles = $siteService->authorizeAction(\Action::SITE_EDIT_CERT_STATUS, $site1, $u);
     $this->assertEquals(2, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::COD_ADMIN, $enablingRoles));
     // Assert user can edit SE using SITE_ADMIN, NGI_OPS_MAN, REG_STAFF_ROD roles (but not COD role)
     $seService = new org\gocdb\services\ServiceService();
     $seService->setEntityManager($em);
     $enablingRoles = $seService->authorizeAction(\Action::EDIT_OBJECT, $se1, $u);
     $this->assertEquals(3, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::SITE_ADMIN, $enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::REG_STAFF_ROD, $enablingRoles));
     // Assert User can only edit Site2 through his 2 indirect ngi roles
     // (user don't have any direct site level roles on this site and COD don't give edit perm)
     $enablingRoles = $siteService->authorizeAction(\Action::EDIT_OBJECT, $site2_userHasNoDirectRole, $u);
     $this->assertEquals(2, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::REG_STAFF_ROD, $enablingRoles));
     // Delete the user's Project COD role
     $this->em->remove($codRole);
     $this->em->flush();
     // Assert user can only SITE_EDIT_CERT_STATUS through 1 role for both sites
     $enablingRoles = $siteService->authorizeAction(\Action::SITE_EDIT_CERT_STATUS, $site2_userHasNoDirectRole, $u);
     $this->assertEquals(1, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     $enablingRoles = $siteService->authorizeAction(\Action::SITE_EDIT_CERT_STATUS, $site1, $u);
     $this->assertEquals(1, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::NGI_OPS_MAN, $enablingRoles));
     // Delete the user's NGI manager role
     $this->em->remove($ngiManagerRole);
     $this->em->flush();
     // Assert user can't edit site2 cert status
     $enablingRoles = $siteService->authorizeAction(\Action::SITE_EDIT_CERT_STATUS, $site2_userHasNoDirectRole, $u);
     $this->assertEquals(0, count($enablingRoles));
     // Assert user can still edit site via his ROD role
     $enablingRoles = $siteService->authorizeAction(\Action::EDIT_OBJECT, $site2_userHasNoDirectRole, $u);
     $this->assertEquals(1, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::REG_STAFF_ROD, $enablingRoles));
     // Delete the user's NGI ROD role
     $this->em->remove($rodUserRole);
     $this->em->flush();
     // User can't edit site2
     $enablingRoles = $siteService->authorizeAction(\Action::EDIT_OBJECT, $site2_userHasNoDirectRole, $u);
     $this->assertEquals(0, count($enablingRoles));
     // Assert user can still edit SITE1 through his direct site level role (this role has not been deleted)
     $enablingRoles = $siteService->authorizeAction(\Action::EDIT_OBJECT, $site1, $u);
     $this->assertEquals(1, count($enablingRoles));
     $this->assertTrue(in_array(\RoleTypeName::SITE_ADMIN, $enablingRoles));
     // Delete user's remaining Site role
     $this->em->remove($siteAdminRole);
     $this->em->flush();
     // User can't edit site1
     $enablingRoles = $siteService->authorizeAction(\Action::EDIT_OBJECT, $site1, $u);
     $this->assertEquals(0, count($enablingRoles));
 }
コード例 #8
0
ファイル: ExtensionsTest.php プロジェクト: Tom-Byrne/gocdb
 /**
  * Show the creation of an endpoint and properties and that 
  * all data is removed on deletion of an endpoint or property
  */
 public function testEndpointPropertyDeletions()
 {
     print __METHOD__ . "\n";
     $service = TestUtil::createSampleService("TestService");
     $ngi = TestUtil::createSampleNGI("TestNGI");
     $site = TestUtil::createSampleSite("TestSite");
     $endpoint = TestUtil::createSampleEndpointLocation();
     //Join service to site, and site to NGI.
     $ngi->addSiteDoJoin($site);
     $site->addServiceDoJoin($service);
     $service->addEndpointLocationDoJoin($endpoint);
     //Create properties
     $prop1 = TestUtil::createSampleEndpointProperty("VO", "Atlas");
     $prop2 = TestUtil::createSampleEndpointProperty("VO", "CMS");
     $prop3 = TestUtil::createSampleEndpointProperty("VO", "Alice");
     $endpoint->addEndpointPropertyDoJoin($prop1);
     $endpoint->addEndpointPropertyDoJoin($prop2);
     $endpoint->addEndpointPropertyDoJoin($prop3);
     //Persist in the entity manager
     $this->em->persist($service);
     $this->em->persist($ngi);
     $this->em->persist($site);
     $this->em->persist($endpoint);
     $this->em->persist($prop1);
     $this->em->persist($prop2);
     $this->em->persist($prop3);
     //Commit to the database
     $this->em->flush();
     //Check endpoint has 3 properties associated with it
     $properties = $endpoint->getEndpointProperties();
     $this->assertTrue(count($properties) == 3);
     //Create an admin user that can delete a property
     $adminUser = TestUtil::createSampleUser('my', 'admin', '/my/admin');
     $adminUser->setAdmin(TRUE);
     $this->em->persist($adminUser);
     //Delete the property from the service
     $serviceService = new org\gocdb\services\ServiceService();
     $serviceService->setEntityManager($this->em);
     $serviceService->deleteEndpointProperty($adminUser, $prop1);
     //Check that the service now only has 2 properties
     $properties = $endpoint->getEndpointProperties();
     $this->assertTrue(count($properties) == 2);
     $this->em->flush();
     //Print names of properties
     foreach ($properties as $prop) {
         print $prop->getKeyName() . "-";
         print $prop->getKeyValue() . "\n";
     }
     //Check this via the database
     $con = $this->getConnection();
     //Get service id to use in sql statements
     $endpointId = $endpoint->getId();
     $result = $con->createQueryTable('results', "SELECT * FROM endpoint_properties WHERE PARENTENDPOINT_ID = '{$endpointId}'");
     //Assert that only 2 service properties exist in the database for this service
     $this->assertEquals(2, $result->getRowCount());
     //Now delete the endpont and check that it cascade deletes
     //the endpoint's associated properties
     $serviceService->deleteEndpoint($endpoint, $adminUser);
     $this->em->flush();
     //Check endpoint is gone
     $result = $con->createQueryTable('results', "SELECT * FROM EndpointLocations WHERE ID = '{$endpointId}'");
     $this->assertEquals(0, $result->getRowCount());
     //Check properties are gone
     $result = $con->createQueryTable('results', "SELECT * FROM endpoint_properties WHERE PARENTENDPOINT_ID = '{$endpointId}'");
     $this->assertEquals(0, $result->getRowCount());
 }