コード例 #1
0
$s3p4 = TestUtil::createSampleSiteProperty("VO2", "bar");
$this->em->persist($s3p1);
$this->em->persist($s3p2);
$this->em->persist($s3p3);
$this->em->persist($s3p4);
$site3->addSitePropertyDoJoin($s3p1);
$site3->addSitePropertyDoJoin($s3p2);
$site3->addSitePropertyDoJoin($s3p3);
$site3->addSitePropertyDoJoin($s3p4);
// site4
$s4p1 = TestUtil::createSampleSiteProperty("s4p1", "v1");
$s4p2 = TestUtil::createSampleSiteProperty("s4p2", "v2");
$s4p3 = TestUtil::createSampleSiteProperty("VO", "foo");
$s4p4 = TestUtil::createSampleSiteProperty("VO", "bar");
$s4p5 = TestUtil::createSampleSiteProperty("VO2", "baz");
$s4p6 = TestUtil::createSampleSiteProperty("VO2", "bing");
$this->em->persist($s4p1);
$this->em->persist($s4p2);
$this->em->persist($s4p3);
$this->em->persist($s4p4);
$this->em->persist($s4p5);
$this->em->persist($s4p6);
$site4->addSitePropertyDoJoin($s4p1);
$site4->addSitePropertyDoJoin($s4p2);
$site4->addSitePropertyDoJoin($s4p3);
$site4->addSitePropertyDoJoin($s4p4);
$site4->addSitePropertyDoJoin($s4p5);
$site4->addSitePropertyDoJoin($s4p6);
// commit
$this->em->flush();
// Assert fixture data is setup correctly in the DB.
コード例 #2
0
ファイル: ExtensionsTest.php プロジェクト: Tom-Byrne/gocdb
 /**
  * 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());
 }