Beispiel #1
0
 /**
  * An example test showing the creation of a site and properties and that 
  * all data is removed on deletion of a site or property
  */
 public function testSitePropertyDeletions()
 {
     print __METHOD__ . "\n";
     //Create a site
     $site = TestUtil::createSampleSite("TestSite");
     //Create site property
     $prop1 = TestUtil::createSampleSiteProperty("VO", "Atlas");
     $prop2 = TestUtil::createSampleSiteProperty("VO", "CMS");
     $prop3 = TestUtil::createSampleSiteProperty("VO", "Alice");
     $site->addSitePropertyDoJoin($prop1);
     $site->addSitePropertyDoJoin($prop2);
     $site->addSitePropertyDoJoin($prop3);
     //Set some extra details of the site
     $site->setEmail("*****@*****.**");
     $site->setTelephone("012345678910");
     $site->setLocation("United Kingdom");
     //Persist the site & property in the entity manager
     $this->em->persist($site);
     $this->em->persist($prop1);
     $this->em->persist($prop2);
     $this->em->persist($prop3);
     //Commit the site to the database
     $this->em->flush();
     //Check that the site has 3 properties associated with it
     $properties = $site->getSiteProperties();
     $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 site
     $siteService = new org\gocdb\services\Site();
     $siteService->setEntityManager($this->em);
     $siteService->deleteSiteProperty($site, $adminUser, $prop1);
     //Check that the site now only has 2 properties
     $properties = $site->getSiteProperties();
     $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 site id to use in sql statements
     $siteId = $site->getId();
     $result = $con->createQueryTable('results', "SELECT * FROM site_properties WHERE PARENTSITE_ID = '{$siteId}'");
     //Assert that only 2 site properties exist in the database for this site
     $this->assertEquals(2, $result->getRowCount());
     //Now delete the site and check that it cascades the delete to remove the sites associated properties
     $siteService->deleteSite($site, $adminUser, false);
     $this->em->flush();
     //Check site is gone
     $result = $con->createQueryTable('results', "SELECT * FROM Sites WHERE ID = '{$siteId}'");
     $this->assertEquals(0, $result->getRowCount());
     //Check properties are gone
     $result = $con->createQueryTable('results', "SELECT * FROM site_properties WHERE PARENTSITE_ID = '{$siteId}'");
     $this->assertEquals(0, $result->getRowCount());
 }