private function getRole() { $rand = rand(); $cod = $rand; $xml = "<xml contenido del xml {$rand} />"; $name = "rolename{$rand}"; $text = "text is {$rand}"; $role = new Role(); $role->setCod($cod); $role->setXml($xml); $role->setName($name); $role->setText($text); return $role; }
public function testFindSeriesByPersonId() { $broadcast = new Broadcast(); $broadcast->setBroadcastTypeId(Broadcast::BROADCAST_TYPE_PUB); $broadcast->setDefaultSel(true); $this->dm->persist($broadcast); $this->dm->flush(); $series1 = $this->factoryService->createSeries(); $title1 = 'Series 1'; $series1->setTitle($title1); $series2 = $this->factoryService->createSeries(); $title2 = 'Series 2'; $series2->setTitle($title2); $series3 = $this->factoryService->createSeries(); $title3 = 'Series 3'; $series3->setTitle($title3); $this->dm->persist($series1); $this->dm->persist($series2); $this->dm->persist($series3); $personJohn = new Person(); $nameJohn = 'John Smith'; $personJohn->setName($nameJohn); $personBob = new Person(); $nameBob = 'Bob Clark'; $personBob->setName($nameBob); $personKate = new Person(); $nameKate = 'Kate Simmons'; $personKate->setName($nameKate); $this->dm->persist($personJohn); $this->dm->persist($personBob); $this->dm->persist($personKate); $roleActor = new Role(); $codActor = 'actor'; $roleActor->setCod($codActor); $rolePresenter = new Role(); $codPresenter = 'presenter'; $rolePresenter->setCod($codPresenter); $this->dm->persist($roleActor); $this->dm->persist($rolePresenter); $this->dm->flush(); $mm11 = $this->factoryService->createMultimediaObject($series1); $title11 = 'Multimedia Object 11'; $mm11->setTitle($title11); $mm11->addPersonWithRole($personJohn, $roleActor); $mm11->addPersonWithRole($personBob, $roleActor); $mm11->addPersonWithRole($personJohn, $rolePresenter); $mm12 = $this->factoryService->createMultimediaObject($series1); $title12 = 'Multimedia Object 12'; $mm12->setTitle($title12); $mm12->addPersonWithRole($personBob, $roleActor); $mm12->addPersonWithRole($personBob, $rolePresenter); $mm13 = $this->factoryService->createMultimediaObject($series1); $title13 = 'Multimedia Object 13'; $mm13->setTitle($title13); $mm13->addPersonWithRole($personKate, $roleActor); $mm21 = $this->factoryService->createMultimediaObject($series2); $title21 = 'Multimedia Object 21'; $mm21->setTitle($title21); $mm21->addPersonWithRole($personKate, $rolePresenter); $mm21->addPersonWithRole($personKate, $roleActor); $mm31 = $this->factoryService->createMultimediaObject($series3); $title31 = 'Multimedia Object 31'; $mm31->setTitle($title31); $mm31->addPersonWithRole($personJohn, $rolePresenter); $mm32 = $this->factoryService->createMultimediaObject($series3); $title32 = 'Multimedia Object 3212312'; $mm32->setTitle($title32); $mm32->addPersonWithRole($personJohn, $roleActor); $mm32->addPersonWithRole($personBob, $roleActor); $mm32->addPersonWithRole($personJohn, $rolePresenter); $this->dm->persist($mm11); $this->dm->persist($mm12); $this->dm->persist($mm13); $this->dm->persist($mm21); $this->dm->persist($mm31); $this->dm->persist($mm32); $this->dm->persist($series1); $this->dm->persist($series2); $this->dm->persist($series3); $this->dm->flush(); $seriesKate = $this->repo->findSeriesByPersonId($personKate->getId()); $this->assertEquals(2, count($seriesKate)); $this->assertEquals(array($series1, $series2), array_values($seriesKate->toArray())); $seriesJohn = $this->repo->findSeriesByPersonId($personJohn->getId()); $this->assertEquals(2, count($seriesJohn)); $this->assertEquals(array($series1, $series3), array_values($seriesJohn->toArray())); $seriesBob = $this->repo->findSeriesByPersonId($personBob->getId()); $this->assertEquals(2, count($seriesBob)); $this->assertEquals(array($series1, $series3), array_values($seriesBob->toArray())); $seriesJohnActor = $this->repo->findByPersonIdAndRoleCod($personJohn->getId(), $roleActor->getCod()); $seriesJohnPresenter = $this->repo->findByPersonIdAndRoleCod($personJohn->getId(), $rolePresenter->getCod()); $seriesBobActor = $this->repo->findByPersonIdAndRoleCod($personBob->getId(), $roleActor->getCod()); $seriesBobPresenter = $this->repo->findByPersonIdAndRoleCod($personBob->getId(), $rolePresenter->getCod()); $seriesKateActor = $this->repo->findByPersonIdAndRoleCod($personKate->getId(), $roleActor->getCod()); $seriesKatePresenter = $this->repo->findByPersonIdAndRoleCod($personKate->getId(), $rolePresenter->getCod()); $this->assertEquals(2, count($seriesJohnActor)); $this->assertTrue(in_array($series1, $seriesJohnActor->toArray())); $this->assertFalse(in_array($series2, $seriesJohnActor->toArray())); $this->assertTrue(in_array($series3, $seriesJohnActor->toArray())); $this->assertEquals(2, count($seriesJohnPresenter)); $this->assertTrue(in_array($series1, $seriesJohnPresenter->toArray())); $this->assertFalse(in_array($series2, $seriesJohnPresenter->toArray())); $this->assertTrue(in_array($series3, $seriesJohnPresenter->toArray())); $this->assertEquals(2, count($seriesBobActor)); $this->assertTrue(in_array($series1, $seriesBobActor->toArray())); $this->assertFalse(in_array($series2, $seriesBobActor->toArray())); $this->assertTrue(in_array($series3, $seriesBobActor->toArray())); $this->assertEquals(1, count($seriesBobPresenter)); $this->assertTrue(in_array($series1, $seriesBobPresenter->toArray())); $this->assertFalse(in_array($series2, $seriesBobPresenter->toArray())); $this->assertFalse(in_array($series3, $seriesBobPresenter->toArray())); $this->assertEquals(2, count($seriesKateActor)); $this->assertTrue(in_array($series1, $seriesKateActor->toArray())); $this->assertTrue(in_array($series2, $seriesKateActor->toArray())); $this->assertFalse(in_array($series3, $seriesKateActor->toArray())); $this->assertEquals(1, count($seriesKatePresenter)); $this->assertFalse(in_array($series1, $seriesKatePresenter->toArray())); $this->assertTrue(in_array($series2, $seriesKatePresenter->toArray())); $this->assertFalse(in_array($series3, $seriesKatePresenter->toArray())); }
private function createRole($name) { $cod = $name; // string (20) $rank = strlen($name); // Quick and dirty way to keep it unique $xml = '<xml content and definition of this/>'; $display = true; $text = 'Black then white are all i see in my infancy.'; $role = new Role(); $role->setCod($cod); $role->setRank($rank); $role->setXml($xml); $role->setDisplay($display); // true by default $role->setName($name); $role->setText($text); $role->increaseNumberPeopleInMultimediaObject(); $this->dm->persist($role); $this->dm->flush(); return $role; }
/** * Get people in multimedia object by role * * @param Role|EmbeddedRole $role * @param boolean $always * @return array */ public function getPeopleByRole($role = null, $always = false) { $aux = array(); if (null !== $role) { foreach ($this->people as $embeddedRole) { if ($role->getCod() == $embeddedRole->getCod()) { if ($always || $embeddedRole->getDisplay()) { foreach ($embeddedRole->getPeople() as $embeddedPerson) { $aux[] = $embeddedPerson; } } break; } } } else { foreach ($this->people as $embeddedRole) { if ($always || $embeddedRole->getDisplay()) { foreach ($embeddedRole->getPeople() as $embeddedPerson) { if (!in_array($embeddedPerson, $aux)) { $aux[] = $embeddedPerson; } } } } } return $aux; }
/** * Constructor */ public function __construct(Role $role) { if (null !== $role) { $this->id = $role->getId(); $this->cod = $role->getCod(); $this->xml = $role->getXml(); $this->display = $role->getDisplay(); $this->setI18nName($role->getI18nName()); $this->setI18nText($role->getI18nText()); } $this->people = new ArrayCollection(); }
public function testDeleteResource() { $this->createBroadcasts(); $series = $this->factory->createSeries(); $mmobj = $this->factory->createMultimediaObject($series); $this->assertEquals(3, count($this->dm->getRepository('PumukitSchemaBundle:Broadcast')->findAll())); $this->assertEquals(1, count($this->seriesRepo->findAll())); $this->assertEquals(2, count($this->mmobjRepo->findAll())); $this->factory->deleteResource($mmobj); $this->assertEquals(1, count($this->mmobjRepo->findAll())); $this->factory->deleteSeries($series); $this->assertEquals(0, count($this->seriesRepo->findAll())); $this->assertEquals(0, count($this->mmobjRepo->findAll())); $broadcasts = $this->dm->getRepository('PumukitSchemaBundle:Broadcast')->findAll(); $count = count($broadcasts); foreach ($broadcasts as $broadcast) { $this->assertEquals($count, count($this->dm->getRepository('PumukitSchemaBundle:Broadcast')->findAll())); $this->factory->deleteResource($broadcast); --$count; } $this->assertEquals(0, count($this->dm->getRepository('PumukitSchemaBundle:Broadcast')->findAll())); $role = new Role(); $role->setCod('role'); $this->dm->persist($role); $this->dm->flush(); $this->assertEquals(1, count($this->dm->getRepository('PumukitSchemaBundle:Role')->findAll())); $this->factory->deleteResource($role); $this->assertEquals(0, count($this->dm->getRepository('PumukitSchemaBundle:Role')->findAll())); }
/** * Create Role from CSV array */ private function createRoleFromCsvArray($csv_array) { $role = new Role(); $role->setCod($csv_array[1]); $role->setXml($csv_array[2]); $role->setDisplay($csv_array[3]); // NOTE Take care of csv language order! $role->setName($csv_array[4], 'es'); if (isset($csv_array[5])) { $role->setName($csv_array[5], 'gl'); } if (isset($csv_array[6])) { $role->setName($csv_array[6], 'en'); } // NOTE Take care of csv language order! if (isset($csv_array[7])) { $role->setText($csv_array[7], 'es'); } if (isset($csv_array[8])) { $role->setText($csv_array[8], 'gl'); } if (isset($csv_array[9])) { $role->setText($csv_array[9], 'en'); } $this->dm->persist($role); return $role; }
public function testNumberPeopleInMultimediaObject() { $role = new Role(); $this->assertEquals(0, $role->getNumberPeopleInMultimediaObject()); $role->increaseNumberPeopleInMultimediaObject(); $this->assertEquals(1, $role->getNumberPeopleInMultimediaObject()); $role->increaseNumberPeopleInMultimediaObject(); $role->increaseNumberPeopleInMultimediaObject(); $this->assertEquals(3, $role->getNumberPeopleInMultimediaObject()); $role->decreaseNumberPeopleInMultimediaObject(); $this->assertEquals(2, $role->getNumberPeopleInMultimediaObject()); $role->setNumberPeopleInMultimediaObject(3); $this->assertEquals(3, $role->getNumberPeopleInMultimediaObject()); }
/** * @expectedException Exception * @expectedExceptionMessage remove Person with id */ public function testDeletePerson() { $this->assertEquals(0, count($this->repo->findAll())); $person = new Person(); $person->setName('Person'); $this->dm->persist($person); $this->dm->flush(); $this->assertEquals(1, count($this->repo->findAll())); $this->personService->deletePerson($person); $this->assertEquals(0, count($this->repo->findAll())); $personBob = new Person(); $personBob->setName('Bob'); $roleActor = new Role(); $codActor = 'actor'; $roleActor->setCod($codActor); $this->dm->persist($personBob); $this->dm->persist($roleActor); $this->dm->flush(); $broadcast = new Broadcast(); $broadcast->setBroadcastTypeId(Broadcast::BROADCAST_TYPE_PUB); $broadcast->setDefaultSel(true); $this->dm->persist($broadcast); $this->dm->flush(); $series = $this->factoryService->createSeries(); $mm = $this->factoryService->createMultimediaObject($series); $mm->setTitle('Multimedia Object'); $mm->addPersonWithRole($personBob, $roleActor); $this->dm->persist($mm); $this->dm->persist($series); $this->dm->flush(); $this->assertEquals(1, count($this->repo->findAll())); $this->personService->deletePerson($personBob); $this->assertEquals(1, count($this->repo->findAll())); }