Ejemplo n.º 1
0
 /**
  * 
  */
 public function testPersistAndDeleteUserAndGroup()
 {
     $uniqueID = \uniqid();
     $oUser = new ApplicationUser();
     $oUser->setUsername('foobar\\' . $uniqueID);
     $oUser->setEmail($uniqueID . '*****@*****.**');
     $oUser->setDisplayName($uniqueID . ' Foobar One');
     $oGroup = new WorkGroup();
     $oGroup->setName($uniqueID . ' Developer Group 2');
     $oUser->addWorkGroup($oGroup);
     $this->oEm->persist($oGroup);
     $this->oEm->flush();
     print 'User Insert ID: ' . $oUser->getId();
     print 'Group Insert ID: ' . $oGroup->getId();
     $iGroupId = $oGroup->getId();
     $iUserId = $oUser->getId();
     $this->oEm->flush();
     unset($oGroup);
     $oGroupRepo = $this->oEm->getRepository('Helpdesk\\Entity\\WorkGroup');
     $oPersistGroup = $oGroupRepo->find($iGroupId);
     $users = $oPersistGroup->getUsers();
     $this->assertInstanceOf('\\Doctrine\\ORM\\PersistentCollection', $users);
     $this->assertEquals(1, $users->count());
     $oUser->removeWorkGroup($oPersistGroup);
     $this->oEm->flush();
     unset($oPersistGroup);
     $oUserRepo = $this->oEm->getRepository('Helpdesk\\Entity\\ApplicationUser');
     $oPersistGroup2 = $oGroupRepo->find($iGroupId);
     $oFetchUser = $oUserRepo->find($iUserId);
     $groups = $oFetchUser->getWorkGroups();
     $this->assertInstanceOf('\\Doctrine\\ORM\\PersistentCollection', $groups);
     $this->assertEquals(0, $groups->count());
     //Testing constrints are setup correctly, deleting group should not remove the user
     print 'Unit of work size: ' . $this->oEm->getUnitOfWork()->size() . PHP_EOL;
     $this->oEm->remove($oPersistGroup2);
     $this->oEm->flush();
     $oPeristsUser = $oUserRepo->find($iUserId);
     $this->assertInstanceOf('\\Helpdesk\\Entity\\ApplicationUser', $oPeristsUser);
     $oRemovedGroup = $oGroupRepo->find($iGroupId);
     $this->assertNull($oRemovedGroup);
     $this->oEm->remove($oPeristsUser);
     $this->oEm->flush();
     $oRemovedUser = $oUserRepo->find($iUserId);
     $this->assertNull($oRemovedUser);
 }
Ejemplo n.º 2
0
 /**
  * @covers Helpdesk\Entity\Project::setName
  * @covers Helpdesk\Entity\Project::getName
  * @covers Helpdesk\Entity\Project::setDescription
  * @covers Helpdesk\Entity\Project::getDescription
  */
 public function testPersistAndDeleteUserAndGroup()
 {
     $uniqueID = \uniqid();
     $oUser = new ApplicationUser();
     $oUser->setUsername('foobar\\' . $uniqueID);
     $oUser->setEmail($uniqueID . '*****@*****.**');
     $oUser->setDisplayName($uniqueID . ' Foobar One');
     $oGroup = new WorkGroup();
     $oGroup->setName($uniqueID . ' Project Manager Group');
     $oUser->addWorkGroup($oGroup);
     $this->oEm->persist($oGroup);
     $this->oEm->flush();
     print 'User Insert ID: ' . $oUser->getId();
     print 'Group Insert ID: ' . $oGroup->getId();
     $iGroupId = $oGroup->getId();
     $iUserId = $oUser->getId();
     $oProject = new Project();
     $oProject->setName('Ecommerce Project');
     $oProject->setDescription('Ecommerce project for the foobar group');
     $oProject->setProjectLead($oUser);
     $this->oEm->persist($oProject);
     $this->oEm->flush();
     $this->assertNotNull($oProject->getId());
     $iProjectID = $oProject->getId();
     $oProjectRepo = $this->oEm->getRepository('Helpdesk\\Entity\\Project');
     $oPersistedProject = $oProjectRepo->find($iProjectID);
     $this->assertNotNull($oPersistedProject);
     $this->assertEquals('Ecommerce Project', $oProject->getName());
     $this->assertEquals('Ecommerce project for the foobar group', $oProject->getDescription());
     $this->oEm->remove($oProject);
     $this->oEm->flush();
     $oGroupRepo = $this->oEm->getRepository('Helpdesk\\Entity\\WorkGroup');
     $oUserRepo = $this->oEm->getRepository('Helpdesk\\Entity\\ApplicationUser');
     $oRemovedProject = $oProjectRepo->find($iProjectID);
     $this->assertNull($oRemovedProject);
     //Testing that constraints are set properly for the table associations.
     $oPersistGroup = $oGroupRepo->find($iGroupId);
     $this->assertInstanceOf('\\Helpdesk\\Entity\\WorkGroup', $oPersistGroup);
     $oPersistUser = $oUserRepo->find($iUserId);
     $this->assertInstanceOf('\\Helpdesk\\Entity\\ApplicationUser', $oPersistUser);
     //Remove the test user and group records from the database
     $this->oEm->remove($oPersistGroup);
     $this->oEm->remove($oPersistUser);
     $this->oEm->flush();
 }
Ejemplo n.º 3
0
 /**
  * 
  */
 public function testCreateUpdateAndDeleteTicket()
 {
     //Create a test group and user
     $uniqueID = \uniqid();
     $oUser = new ApplicationUser();
     $oUser->setUsername('foobar\\' . $uniqueID);
     $oUser->setEmail($uniqueID . '*****@*****.**');
     $oUser->setDisplayName($uniqueID . ' Foobar One');
     $oGroup = new WorkGroup();
     $oGroup->setName($uniqueID . ' Project Manager Group');
     $oUser->addWorkGroup($oGroup);
     $oProject = new Project();
     $oProject->setName('First Line');
     $oProject->setDescription('First line helpdesk assistance.');
     $oProject->setProjectLead($oUser);
     $this->oEm->persist($oProject);
     $this->oEm->persist($oGroup);
     $this->oEm->flush();
     $iGroupId = $oGroup->getId();
     $iUserId = $oUser->getId();
     $iProjectID = $oProject->getId();
     //Create catregories and other records for the ticket
     $oTicketType = new TicketType();
     $oTicketType->setName('Bug');
     $oCategory = new Category();
     $oCategory->setName('Software');
     $oTicketCategory = new TicketCategory();
     $oTicketCategory->setName('Extended Incident');
     $oWorkFlow = new Workflow();
     $oWorkFlow->setName('Open 2');
     $this->oEm->persist($oTicketType);
     $this->oEm->persist($oCategory);
     $this->oEm->persist($oTicketCategory);
     $this->oEm->persist($oWorkFlow);
     $this->oEm->flush();
     $this->assertNotNull($oTicketType->getId());
     $this->assertNotNull($oCategory->getId());
     $this->assertNotNull($oTicketCategory->getId());
     $this->assertNotNull($oWorkFlow->getId());
     $iTicketTypeId = $oTicketType->getId();
     $iCategoryId = $oCategory->getId();
     $iTicketCategoryId = $oTicketCategory->getId();
     $iWorkFlowId = $oWorkFlow->getId();
     $oTicket = new Ticket();
     $oTicket->setCategory($oCategory);
     $oTicket->setAssignee($oUser);
     $oTicket->setDescription('FOOBAR');
     $oTicket->setProject($oProject);
     $oTicket->setReporter($oUser);
     $oTicket->setSummary('Require CSS changes pushed to development env.');
     $oTicket->setTicketKey('INC-1');
     $oTicket->setTicketCategory($oTicketCategory);
     $oTicket->setType($oTicketType);
     $oTicket->setWorkflow($oWorkFlow);
     $this->oEm->persist($oTicket);
     $this->oEm->flush();
     $this->assertNotNull($oTicket->getId());
     $iProjectId = $oTicket->getId();
     $oRepository = $this->oEm->getRepository('Helpdesk\\Entity\\Ticket');
     $oPersistTicket = $oRepository->find($iProjectId);
     $this->assertInstanceOf('\\Helpdesk\\Entity\\Ticket', $oPersistTicket);
     $this->oEm->remove($oPersistTicket);
     $this->oEm->flush();
     $oRemovedTicket = $oRepository->find($iProjectId);
     $this->assertNull($oRemovedTicket);
     $oGroupRepo = $this->oEm->getRepository('Helpdesk\\Entity\\WorkGroup');
     $oUserRepo = $this->oEm->getRepository('Helpdesk\\Entity\\ApplicationUser');
     //Testing that constraints are set properly for the table associations.
     $oPersistGroup = $oGroupRepo->find($iGroupId);
     $this->assertInstanceOf('\\Helpdesk\\Entity\\WorkGroup', $oPersistGroup);
     $oPersistUser = $oUserRepo->find($iUserId);
     $this->assertInstanceOf('\\Helpdesk\\Entity\\ApplicationUser', $oPersistUser);
     $oUpdatedCategory = $this->oEm->find('\\Helpdesk\\Entity\\Category', $iCategoryId);
     $this->assertNotNull($oUpdatedCategory);
     $this->oEm->remove($oUser);
     $this->oEm->remove($oProject);
     $this->oEm->remove($oGroup);
     $this->oEm->remove($oTicketType);
     $this->oEm->remove($oCategory);
     $this->oEm->remove($oTicketCategory);
     $this->oEm->remove($oWorkFlow);
     $this->oEm->flush();
 }