public function testEditMany2One() { $this->assertCount(0, $this->mainlogrepo->findAll()); $art1 = new RelatedArticle(); $art1->setTitle('Title'); $art1->setContent('Content'); $art2 = new RelatedArticle(); $art2->setTitle('Title2'); $art2->setContent('Content2'); $comment = new Comment(); $comment->setSubject('Subject'); $comment->setMessage('Message'); $comment2 = new Comment(); $comment2->setSubject('Subject2'); $comment2->setMessage('Message2'); $this->em->persist($art1); $this->em->persist($art2); $this->em->persist($comment); $this->em->persist($comment2); $this->em->flush(); $this->assertCount(4, $this->mainlogrepo->findAll()); $this->assertCount(1, $this->mainlogrepo->getLogsByObject($art1)); $comment->setArticle($art1); $this->em->flush(); $logs = $this->mainlogrepo->findAll(); $this->assertCount(6, $logs); $logs = $this->mainlogrepo->getLogsByObject($art1); $this->assertCount(2, $logs); $comment->setArticle(null); $this->em->flush(); $logs = $this->mainlogrepo->findAll(); $this->assertCount(8, $logs); $logs = $this->mainlogrepo->getLogsByObject($art1); $this->assertCount(3, $logs); $parentlog = array_shift($logs); $this->assertEquals($parentlog->getAction(), LoggableListener::ACTION_REMOVE); $this->assertEquals($parentlog->getChildClass(), get_class($comment)); $this->assertEquals($parentlog->getChildId(), $comment->getId()); $this->assertEquals($parentlog->getObjectClass(), get_class($art1)); $this->assertEquals($parentlog->getObjectId(), $art1->getId()); }
public function testApplyChangeSetOne2Many() { $this->logrepo->getLoggableListener()->setUsername('testUser'); $art1 = new RelatedArticle(); $art1->setTitle('Title'); $art1->setContent('Content'); $comment = new Comment(); $comment->setSubject('Subject'); $comment->setMessage('Message'); $art1->addComment($comment); $this->em->persist($comment); $this->em->persist($art1); $this->em->flush(); $comment = new Comment(); $comment->setSubject('Subject'); $comment->setMessage('Message'); $comment->setScheduledChangeDate(new \DateTime("+ 1 second")); $art1->addComment($comment); $this->em->persist($comment); $this->assertCount(2, $art1->getComments()); $this->em->flush(); $this->assertCount(1, $art1->getComments()); $this->em->clear(); $art1 = $this->em->find(get_class($art1), $art1->getId()); $this->assertCount(1, $art1->getComments()); sleep(1); $this->changeservice->applyChanges(); $this->assertEquals(1, $this->changeservice->getProcessed()); $this->assertCount(2, $art1->getComments()); $this->em->flush(); $this->em->clear(); $art1 = $this->em->find(get_class($art1), $art1->getId()); $this->assertCount(2, $art1->getComments()); $comment = $art1->getComments()->first(); $this->assertEquals('Subject', $comment->getSubject()); $this->assertEquals('Message', $comment->getMessage()); }