コード例 #1
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());
 }