コード例 #1
0
ファイル: ExtensionsTest.php プロジェクト: Tom-Byrne/gocdb
 /**
  * An example test showing the creation of a service and properties and that 
  * all data is removed on deletion of a service or property
  */
 public function testServicePropertyDeletions()
 {
     print __METHOD__ . "\n";
     //Create a service
     $service = TestUtil::createSampleService("TestService");
     //Create a NGI
     $ngi = TestUtil::createSampleNGI("TestNGI");
     //Create a site
     $site = TestUtil::createSampleSite("TestSite");
     //Join service to site, and site to NGI.
     $ngi->addSiteDoJoin($site);
     $site->addServiceDoJoin($service);
     //Create service property
     $prop1 = TestUtil::createSampleServiceProperty("VO", "Atlas");
     $prop2 = TestUtil::createSampleServiceProperty("VO", "CMS");
     $prop3 = TestUtil::createSampleServiceProperty("VO", "Alice");
     $service->addServicePropertyDoJoin($prop1);
     $service->addServicePropertyDoJoin($prop2);
     $service->addServicePropertyDoJoin($prop3);
     //Persist the service & property in the entity manager
     $this->em->persist($service);
     $this->em->persist($ngi);
     $this->em->persist($site);
     $this->em->persist($prop1);
     $this->em->persist($prop2);
     $this->em->persist($prop3);
     //Commit the service to the database
     $this->em->flush();
     //Check that the service has 3 properties associated with it
     $properties = $service->getServiceProperties();
     $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->deleteServiceProperty($service, $adminUser, $prop1);
     //Check that the service now only has 2 properties
     $properties = $service->getServiceProperties();
     $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
     $servId = $service->getId();
     $result = $con->createQueryTable('results', "SELECT * FROM service_properties WHERE PARENTSERVICE_ID = '{$servId}'");
     //Assert that only 2 service properties exist in the database for this service
     $this->assertEquals(2, $result->getRowCount());
     //Now delete the service and check that it cascades the delete to remove the services associated properties
     $serviceService->deleteService($service, $adminUser, true);
     $this->em->flush();
     //Check service is gone
     $result = $con->createQueryTable('results', "SELECT * FROM Services WHERE ID = '{$servId}'");
     $this->assertEquals(0, $result->getRowCount());
     //Check properties are gone
     $result = $con->createQueryTable('results', "SELECT * FROM service_properties WHERE PARENTSERVICE_ID = '{$servId}'");
     $this->assertEquals(0, $result->getRowCount());
 }