فهرست منبع

[loggable] tests and other changes

Gediminas Morkevicius 14 سال پیش
والد
کامیت
f0d2efda30

+ 8 - 7
README.markdown

@@ -9,18 +9,17 @@ records being flushed in the behavioral way. List of extensions:
 - Translatable - gives you a very handy solution for translating records into diferent languages. Easy to setup, easier to use.
 - Sluggable - urlizes your specified fields into single unique slug
 - Timestampable - updates date fields on create, update and even property change.
+- Loggable - helps tracking changes and history of objects, also supports version managment.
 
 Currently these extensions support **Yaml** and **Annotation** mapping. Additional mapping drivers
 can be easy implemented using Mapping extension to handle the additional metadata mapping.
 
 ### Latest updates
 
-**2011-02-08**
+**2011-03-05**
 
-- Refactored [Tree] to support diferent strategies
-- Refactored [Tree][NestedSet] strategy to support roots
-- Changed the [Tree] repository name, relevant to strategy used
-- **Notice:** now any tree entity should have class annotation specifying the tree strategy - **@gedmo:Tree(type="nested")**
+- Merged Boussekeyt Jules pull request for Loggable extension, tweeked to support versioning
+- Added typehints for object manager and classmetadata in all extensions
 
 ### ODM MongoDB support
 
@@ -30,6 +29,7 @@ half of extensions can be used with ODM also.
 - Translatable
 - Sluggable
 - Timestampable
+- Loggable
 
 Are allready ported to support ODM MongoDB
 
@@ -51,12 +51,13 @@ To setup and run tests follow these steps:
 - run: **git submodule init**
 - run: **git submodule update**
 - go to tests directory: **cd tests**
+- run **cp phpunit.dist.xml phpunit.xml**
 - run: **phpunit**
-- optional - you can **cp phpunit.dist.xml phpunit.xml** for additional modifications
 - optional - run mongodb in background to complete all tests 
 
-### Thanks for contributions to:
+### Contributors:
 
+- Boussekeyt Jules [gordonslondon](http://github.com/gordonslondon)
 - Christophe Coevoet [stof](http://github.com/stof)
 - Kudryashov Konstantin [everzet](http://github.com/everzet)
 - Klein Florian [docteurklein](http://github.com/docteurklein)

+ 5 - 1
tests/Gedmo/Loggable/Fixture/Document/Article.php

@@ -12,11 +12,15 @@ class Article
     private $id;
 
     /**
-     * @gedmo:Sluggable
      * @String
      */
     private $title;
 
+    public function __toString()
+    {
+        return $this->title;
+    }
+
     public function getId()
     {
         return $this->id;

+ 37 - 7
tests/Gedmo/Loggable/Fixture/Document/Comment.php

@@ -4,7 +4,7 @@ namespace Loggable\Fixture\Document;
 
 /**
  * @Document
- * @gedmo:Loggable(actions={"create", "delete"})
+ * @gedmo:Loggable(logEntryClass="Loggable\Fixture\Document\Log\Comment")
  */
 class Comment
 {
@@ -16,20 +16,50 @@ class Comment
     /**
      * @String
      */
-    private $title;
+    private $subject;
+
+    /**
+     * @String
+     */
+    private $message;
+    
+    /**
+     * @ReferenceOne(targetDocument="RelatedArticle", inversedBy="comments")
+     */
+    private $article;
+
+    public function setArticle($article)
+    {
+        $this->article = $article;
+    }
+    
+    public function getArticle()
+    {
+        return $this->article;
+    }
 
     public function getId()
     {
         return $this->id;
     }
+    
+    public function setSubject($subject)
+    {
+        $this->subject = $subject;
+    }
+
+    public function getSubject()
+    {
+        return $this->subject;
+    }
 
-    public function setTitle($title)
+    public function setMessage($message)
     {
-        $this->title = $title;
+        $this->message = $message;
     }
 
-    public function getTitle()
+    public function getMessage()
     {
-        return $this->title;
+        return $this->message;
     }
-}
+}

+ 16 - 0
tests/Gedmo/Loggable/Fixture/Document/Log/Comment.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace Loggable\Fixture\Document\Log;
+
+use Gedmo\Loggable\Document\AbstractLogEntry;
+
+/**
+ * @Document(
+ *     collection="test_comment_log_entries", 
+ *     repositoryClass="Gedmo\Loggable\Document\Repository\LogEntryRepository"
+ * )
+ */
+class Comment extends AbstractLogEntry
+{
+    
+}

+ 66 - 0
tests/Gedmo/Loggable/Fixture/Document/RelatedArticle.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace Loggable\Fixture\Document;
+
+/**
+ * @Document
+ * @gedmo:Loggable
+ */
+class RelatedArticle
+{
+    /** 
+     * @Id
+     */
+    private $id;
+
+    /**
+     * @String
+     */
+    private $title;
+
+    /**
+     * @String
+     */
+    private $content;
+    
+    /**
+     * @ReferenceMany(targetDocument="Comment", mappedBy="article")
+     */
+    private $comments;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function addComment(Comment $comment)
+    {
+        $comment->setArticle($this);
+        $this->comments[] = $comment;
+    }
+
+    public function getComments()
+    {
+        return $this->comments;
+    }
+    
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+
+    public function setContent($content)
+    {
+        $this->content = $content;
+    }
+
+    public function getContent()
+    {
+        return $this->content;
+    }
+}

+ 41 - 11
tests/Gedmo/Loggable/Fixture/Entity/Comment.php

@@ -4,34 +4,64 @@ namespace Loggable\Fixture\Entity;
 
 /**
  * @Entity
- * @gedmo:Loggable(actions={"create", "update"})
+ * @gedmo:Loggable(logEntryClass="Loggable\Fixture\Entity\Log\Comment")
  */
 class Comment
 {
-    /**
-     * @Column(name="id", type="integer")
-     * @Id
-     * @GeneratedValue(strategy="IDENTITY")
+    /** 
+     * @Id 
+     * @GeneratedValue 
+     * @Column(type="integer") 
      */
     private $id;
 
     /**
-     * @Column(name="title", type="string", length=8)
+     * @Column(length=128)
+     */
+    private $subject;
+
+    /**
+     * @Column(type="text")
      */
-    private $title;
+    private $message;
+    
+    /**
+     * @ManyToOne(targetEntity="RelatedArticle", inversedBy="comments")
+     */
+    private $article;
+
+    public function setArticle($article)
+    {
+        $this->article = $article;
+    }
+    
+    public function getArticle()
+    {
+        return $this->article;
+    }
 
     public function getId()
     {
         return $this->id;
     }
+    
+    public function setSubject($subject)
+    {
+        $this->subject = $subject;
+    }
+
+    public function getSubject()
+    {
+        return $this->subject;
+    }
 
-    public function setTitle($title)
+    public function setMessage($message)
     {
-        $this->title = $title;
+        $this->message = $message;
     }
 
-    public function getTitle()
+    public function getMessage()
     {
-        return $this->title;
+        return $this->message;
     }
 }

+ 14 - 0
tests/Gedmo/Loggable/Fixture/Entity/Log/Comment.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace Loggable\Fixture\Entity\Log;
+
+use Gedmo\Loggable\Entity\AbstractLogEntry;
+
+/**
+ * @Table(name="test_comment_log_entries")
+ * @Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository")
+ */
+class Comment extends AbstractLogEntry
+{
+    
+}

+ 68 - 0
tests/Gedmo/Loggable/Fixture/Entity/RelatedArticle.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace Loggable\Fixture\Entity;
+
+/**
+ * @Entity
+ * @gedmo:Loggable
+ */
+class RelatedArticle
+{
+    /** 
+     * @Id 
+     * @GeneratedValue 
+     * @Column(type="integer") 
+     */
+    private $id;
+
+    /**
+     * @Column(length=128)
+     */
+    private $title;
+
+    /**
+     * @Column(type="text")
+     */
+    private $content;
+    
+    /**
+     * @OneToMany(targetEntity="Comment", mappedBy="article")
+     */
+    private $comments;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function addComment(Comment $comment)
+    {
+        $comment->setArticle($this);
+        $this->comments[] = $comment;
+    }
+
+    public function getComments()
+    {
+        return $this->comments;
+    }
+    
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+
+    public function setContent($content)
+    {
+        $this->content = $content;
+    }
+
+    public function getContent()
+    {
+        return $this->content;
+    }
+}

+ 105 - 78
tests/Gedmo/Loggable/LoggableDocumentTest.php

@@ -3,6 +3,7 @@
 namespace Gedmo\Loggable;
 
 use Loggable\Fixture\Document\Article,
+    Loggable\Fixture\Document\RelatedArticle,
     Loggable\Fixture\Document\Comment;
 
 /**
@@ -19,6 +20,8 @@ class LoggableDocumentTest extends \PHPUnit_Framework_TestCase
 {
     const TEST_CLASS_ARTICLE = 'Loggable\Fixture\Document\Article';
     const TEST_CLASS_COMMENT = 'Loggable\Fixture\Document\Comment';
+    const TEST_CLASS_RELATED_ARTICLE = 'Loggable\Fixture\Document\RelatedArticle';
+    const TEST_CLASS_LOG_COMMENT = 'Loggable\Fixture\Document\Log\Comment';
 
     /**
      * @var DocumentManager
@@ -26,7 +29,7 @@ class LoggableDocumentTest extends \PHPUnit_Framework_TestCase
     private $dm;
 
     public function setUp()
-    {
+    {        
         $config = new \Doctrine\ODM\MongoDB\Configuration();
         $config->setProxyDir(__DIR__ . '/Proxy');
         $config->setProxyNamespace('Gedmo\Loggable\Proxies');
@@ -34,10 +37,12 @@ class LoggableDocumentTest extends \PHPUnit_Framework_TestCase
         $config->setHydratorNamespace('Hydrator');
         $config->setDefaultDB('gedmo_loggable_tests');
 
+
         $config->setLoggerCallable(function(array $log) {
             print_r($log);
         });
 
+
         $reader = new \Doctrine\Common\Annotations\AnnotationReader();
         $reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
         $config->setMetadataDriverImpl(
@@ -46,7 +51,7 @@ class LoggableDocumentTest extends \PHPUnit_Framework_TestCase
 
         $evm = new \Doctrine\Common\EventManager();
         $loggableListener = new ODM\MongoDB\LoggableListener();
-        $loggableListener::setUser('jules');
+        $loggableListener->setUsername('jules');
         $evm->addEventSubscriber($loggableListener);
 
         if (!class_exists('Mongo')) {
@@ -59,108 +64,130 @@ class LoggableDocumentTest extends \PHPUnit_Framework_TestCase
                 $config,
                 $evm
             );
+            
+            // if previous test failed, also checks connection
+            $this->clear();
         } catch (\MongoException $e) {
             $this->markTestSkipped('Doctrine MongoDB ODM connection problem.');
         }
     }
 
-    protected function tearDown()
+    public function testLogGeneration()
     {
-        $this->clearLogs();
-    }
+        $logRepo = $this->dm->getRepository('Gedmo\Loggable\Document\LogEntry');
+        $articleRepo = $this->dm->getRepository(self::TEST_CLASS_ARTICLE);
+        $this->assertEquals(0, count($logRepo->findAll()));
 
-    public function testLoggableAllActions()
-    {
         $art0 = new Article();
-
-        // action create
-
-        $art0->setTitle('My Title');
+        $art0->setTitle('Title');
+        
         $this->dm->persist($art0);
         $this->dm->flush();
 
-        $logs = $this->getLogs();
-        $this->assertEquals(1, count($logs), 'a log is created');
-        $log = $logs->getSingleResult();
-
+        $log = $logRepo->findOneByObjectId($art0->getId());
+        
         $this->assertNotEquals(null, $log);
-        $this->assertTrue($log instanceof Document\HistoryLog, 'a log instance of Document\HistoryLog');
-
         $this->assertEquals('create', $log->getAction());
         $this->assertEquals(get_class($art0), $log->getObjectClass());
-        $this->assertEquals($art0->getId(), $log->getForeignKey());
-        $this->assertEquals('jules', $log->getUser());
-
-        $this->clearLogs();
-
-        // action update
-
-        $art0->setTitle('Another Title');
-        $this->dm->persist($art0);
+        $this->assertEquals('jules', $log->getUsername());
+        $this->assertEquals(1, $log->getVersion());
+        $data = $log->getData();
+        $this->assertEquals(1, count($data));
+        $this->assertArrayHasKey('title', $data);
+        $this->assertEquals($data['title'], 'Title');
+        
+        // test update
+        $article = $articleRepo->findOneByTitle('Title');
+        $article->setTitle('New');
+        $this->dm->persist($article);
         $this->dm->flush();
-
-        $logs = $this->getLogs();
-        $this->assertEquals(1, count($logs), 'a log is created');
-        $log = $logs->getSingleResult();
-        $this->assertNotEquals(null, $log);
-        $this->assertTrue($log instanceof Document\HistoryLog, 'a log instance of Document\HistoryLog');
-
+        $this->dm->clear();
+        
+        $log = $logRepo->findOneBy(array('version' => 2, 'objectId' => $article->getId()));
         $this->assertEquals('update', $log->getAction());
-        $this->assertEquals(get_class($art0), $log->getObjectClass());
-        $this->assertEquals($art0->getId(), $log->getForeignKey());
-        $this->assertEquals('jules', $log->getUser());
-
-        $this->clearLogs();
-
-        // action delete
-
-        $articleId = $art0->getId();
-        $this->dm->remove($art0);
+        
+        // test delete
+        $article = $articleRepo->findOneByTitle('New');
+        $this->dm->remove($article);
         $this->dm->flush();
-
-        $logs = $this->getLogs();
-        $this->assertEquals(1, count($logs), 'a log is created');
-        $log = $logs->getSingleResult();
-        $this->assertNotEquals(null, $log);
-        $this->assertTrue($log instanceof Document\HistoryLog, 'a log instance of Document\HistoryLog');
-
-        $this->assertEquals('delete', $log->getAction());
-        $this->assertEquals(get_class($art0), $log->getObjectClass());
-        $this->assertEquals($articleId, $log->getForeignKey());
-        $this->assertEquals('jules', $log->getUser());
+        $this->dm->clear();
+        
+        $log = $logRepo->findOneBy(array('version' => 3, 'objectId' => $article->getId()));
+        $this->assertEquals('remove', $log->getAction());
+        $this->assertEquals(null, $log->getData());
     }
-
-    public function testLoggableNotAllowedAction()
+    
+    public function testVersionControl()
     {
-        $comment = new Comment();
-        $comment->setTitle('My Title');
-
+        $this->populate();
+        $commentLogRepo = $this->dm->getRepository(self::TEST_CLASS_LOG_COMMENT);
+        $commentRepo = $this->dm->getRepository(self::TEST_CLASS_COMMENT);
+        
+        $comment = $commentRepo->findOneByMessage('m-v5');
+        $commentId = $comment->getId();
+        $this->assertEquals('m-v5', $comment->getMessage());
+        $this->assertEquals('s-v3', $comment->getSubject());
+        $this->assertEquals('a2-t-v1', $comment->getArticle()->getTitle());
+        
+        // test revert
+        $commentLogRepo->revert($comment, 3);
+        $this->assertEquals('s-v3', $comment->getSubject());
+        $this->assertEquals('m-v2', $comment->getMessage());
+        $this->assertEquals('a1-t-v1', $comment->getArticle()->getTitle());
         $this->dm->persist($comment);
         $this->dm->flush();
-        $this->assertEquals(1, $this->getLogs()->count());
-        $this->clearLogs();
 
-        $comment->setTitle('Another Title');
-        $this->dm->persist($comment);
-        $this->dm->flush();
-        $this->assertEquals(0, $this->getLogs()->count());
+        // test get log entries
+        $logEntries = $commentLogRepo->getLogEntries($comment);
+        $this->assertEquals(6, count($logEntries));
+        $latest = array_shift($logEntries);
+        $this->assertEquals('update', $latest->getAction());
     }
-
-    private function getLogs()
+    
+    private function populate()
     {
-        return $this->dm->createQueryBuilder('Gedmo\Loggable\Document\HistoryLog')
-            ->select()
-            ->getQuery()
-            ->execute()
-        ;
+        $article = new RelatedArticle;
+        $article->setTitle('a1-t-v1');
+        $article->setContent('a1-c-v1');
+        
+        $comment = new Comment;
+        $comment->setArticle($article);
+        $comment->setMessage('m-v1');
+        $comment->setSubject('s-v1');
+        
+        $this->dm->persist($article);
+        $this->dm->persist($comment);
+        $this->dm->flush();
+        
+        $comment->setMessage('m-v2');
+        $this->dm->persist($comment);
+        $this->dm->flush();
+        
+        $comment->setSubject('s-v3');
+        $this->dm->persist($comment);
+        $this->dm->flush();
+        
+        $article2 = new RelatedArticle;
+        $article2->setTitle('a2-t-v1');
+        $article2->setContent('a2-c-v1');
+        
+        $comment->setArticle($article2);
+        $this->dm->persist($article2);
+        $this->dm->persist($comment);
+        $this->dm->flush();
+        
+        $comment->setMessage('m-v5');
+        $this->dm->persist($comment);
+        $this->dm->flush();
+        $this->dm->clear();
     }
 
-    private function clearLogs()
+    private function clear()
     {
-        $this->dm->createQueryBuilder('Gedmo\Loggable\Document\HistoryLog')
-            ->remove()
-            ->getQuery()
-            ->execute()
-        ;
+        $this->dm->getDocumentCollection('Gedmo\Loggable\Document\LogEntry')->drop();
+        $this->dm->getDocumentCollection(self::TEST_CLASS_ARTICLE)->drop();
+        $this->dm->getDocumentCollection(self::TEST_CLASS_RELATED_ARTICLE)->drop();
+        $this->dm->getDocumentCollection(self::TEST_CLASS_COMMENT)->drop();
+        $this->dm->getDocumentCollection(self::TEST_CLASS_LOG_COMMENT)->drop();
     }
 }

+ 97 - 81
tests/Gedmo/Loggable/LoggableEntityTest.php

@@ -4,8 +4,9 @@ namespace Gedmo\Loggable;
 
 use Doctrine\Common\Util\Debug,
     Loggable\Fixture\Entity\Article,
+    Loggable\Fixture\Entity\RelatedArticle,
     Loggable\Fixture\Entity\Comment;
-
+    
 /**
  * These are tests for loggable behavior
  *
@@ -18,6 +19,8 @@ class LoggableEntityTest extends \PHPUnit_Framework_TestCase
 {
     const TEST_ENTITY_CLASS_ARTICLE = 'Loggable\Fixture\Entity\Article';
     const TEST_ENTITY_CLASS_COMMENT = 'Loggable\Fixture\Entity\Comment';
+    const TEST_ENTITY_CLASS_RELATED_ARTICLE = 'Loggable\Fixture\Entity\RelatedArticle';
+    const TEST_ENTITY_CLASS_LOG_COMMENT = 'Loggable\Fixture\Entity\Log\Comment';
 
     private $articleId;
     private $LoggableListener;
@@ -40,8 +43,8 @@ class LoggableEntityTest extends \PHPUnit_Framework_TestCase
         //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
 
         $evm = new \Doctrine\Common\EventManager();
-        $this->LoggableListener = new ORM\LoggableListener();
-        $this->LoggableListener->setUser('jules');
+        $this->LoggableListener = new LoggableListener();
+        $this->LoggableListener->setUsername('jules');
         $evm->addEventSubscriber($this->LoggableListener);
         $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
 
@@ -50,106 +53,119 @@ class LoggableEntityTest extends \PHPUnit_Framework_TestCase
         $schemaTool->createSchema(array(
             $this->em->getClassMetadata(self::TEST_ENTITY_CLASS_ARTICLE),
             $this->em->getClassMetadata(self::TEST_ENTITY_CLASS_COMMENT),
-            $this->em->getClassMetadata('Gedmo\Loggable\Entity\HistoryLog'),
+            $this->em->getClassMetadata('Gedmo\Loggable\Entity\LogEntry'),
+            $this->em->getClassMetadata(self::TEST_ENTITY_CLASS_LOG_COMMENT),
+            $this->em->getClassMetadata(self::TEST_ENTITY_CLASS_RELATED_ARTICLE)
         ));
     }
 
-    protected function tearDown()
+    public function testLoggable()
     {
-        $this->clearLogs();
-    }
+        $logRepo = $this->em->getRepository('Gedmo\Loggable\Entity\LogEntry');
+        $articleRepo = $this->em->getRepository(self::TEST_ENTITY_CLASS_ARTICLE);
+        $this->assertEquals(0, count($logRepo->findAll()));
 
-    public function testLoggableAllActions()
-    {
         $art0 = new Article();
-
-        // action create
-
-        $art0->setTitle('My Title');
+        $art0->setTitle('Title');
+        
         $this->em->persist($art0);
         $this->em->flush();
 
-        $logs = $this->getLogs();
-        $this->assertEquals(1, count($logs), 'a log is created');
-        $log = $logs[0];
+        $log = $logRepo->findOneByObjectId($art0->getId());
+        
         $this->assertNotEquals(null, $log);
-        $this->assertTrue($log instanceof Entity\HistoryLog, 'a log instance of Entity\HistoryLog');
-
         $this->assertEquals('create', $log->getAction());
         $this->assertEquals(get_class($art0), $log->getObjectClass());
-        $this->assertEquals($art0->getId(), $log->getForeignKey());
-        $this->assertEquals('jules', $log->getUser());
-
-        $this->clearLogs();
-
-        // action update
-
-        $art0->setTitle('Another Title');
-        $this->em->persist($art0);
+        $this->assertEquals('jules', $log->getUsername());
+        $this->assertEquals(1, $log->getVersion());
+        $data = $log->getData();
+        $this->assertEquals(1, count($data));
+        $this->assertArrayHasKey('title', $data);
+        $this->assertEquals($data['title'], 'Title');
+        
+        // test update
+        $article = $articleRepo->findOneByTitle('Title');
+        
+        $article->setTitle('New');
+        $this->em->persist($article);
         $this->em->flush();
-
-        $logs = $this->getLogs();
-        $this->assertEquals(1, count($logs), 'a log is created');
-        $log = $logs[0];
-        $this->assertNotEquals(null, $log);
-        $this->assertTrue($log instanceof Entity\HistoryLog, 'a log instance of Entity\HistoryLog');
-
+        $this->em->clear();
+        
+        $log = $logRepo->findOneBy(array('version' => 2, 'objectId' => $article->getId()));
         $this->assertEquals('update', $log->getAction());
-        $this->assertEquals(get_class($art0), $log->getObjectClass());
-        $this->assertEquals($art0->getId(), $log->getForeignKey());
-        $this->assertEquals('jules', $log->getUser());
-
-        $this->clearLogs();
-
-        // action delete
-
-        $articleId = $art0->getId();
-        $this->em->remove($art0);
+        
+        // test delete
+        $article = $articleRepo->findOneByTitle('New');
+        $this->em->remove($article);
         $this->em->flush();
-
-        $logs = $this->getLogs();
-        $this->assertEquals(1, count($logs), 'a log is created');
-        $log = $logs[0];
-        $this->assertNotEquals(null, $log);
-        $this->assertTrue($log instanceof Entity\HistoryLog, 'a log instance of Entity\HistoryLog');
-
-        $this->assertEquals('delete', $log->getAction());
-        $this->assertEquals(get_class($art0), $log->getObjectClass());
-        $this->assertEquals($articleId, $log->getForeignKey());
-        $this->assertEquals('jules', $log->getUser());
+        $this->em->clear();
+        
+        $log = $logRepo->findOneBy(array('version' => 3, 'objectId' => 1));
+        $this->assertEquals('remove', $log->getAction());
+        $this->assertEquals(null, $log->getData());
     }
 
-    public function testLoggableNotAllowedAction()
+    public function testVersionControl()
     {
-        $comment = new Comment();
-        $comment->setTitle('My Title');
-
+        $this->populate();
+        $commentLogRepo = $this->em->getRepository(self::TEST_ENTITY_CLASS_LOG_COMMENT);
+        $commentRepo = $this->em->getRepository(self::TEST_ENTITY_CLASS_COMMENT);
+        
+        $comment = $commentRepo->find(1);
+        $this->assertEquals('m-v5', $comment->getMessage());
+        $this->assertEquals('s-v3', $comment->getSubject());
+        $this->assertEquals(2, $comment->getArticle()->getId());
+        
+        // test revert
+        $commentLogRepo->revert($comment, 3);
+        $this->assertEquals('s-v3', $comment->getSubject());
+        $this->assertEquals('m-v2', $comment->getMessage());
+        $this->assertEquals(1, $comment->getArticle()->getId());
         $this->em->persist($comment);
         $this->em->flush();
-        $this->assertEquals(1, count($this->getLogs()));
-        $this->clearLogs();
         
-        $this->em->remove($comment);
-        $this->em->flush();
-        $this->assertEquals(0, count($this->getLogs()));
+        // test get log entries
+        $logEntries = $commentLogRepo->getLogEntries($comment);
+        $this->assertEquals(6, count($logEntries));
+        $latest = $logEntries[0];
+        $this->assertEquals('update', $latest->getAction());
     }
-
-    private function getLogs()
+    
+    private function populate()
     {
-        return $this->em->createQueryBuilder()
-            ->select('log')
-            ->from('Gedmo\Loggable\Entity\HistoryLog', 'log')
-            ->getQuery()
-            ->execute(array())
-        ;
-    }
-
-    private function clearLogs()
-    {
-        $this->em->createQueryBuilder()
-            ->delete('Gedmo\Loggable\Entity\HistoryLog', 'log')
-            ->getQuery()
-            ->execute()
-        ;
+        $article = new RelatedArticle;
+        $article->setTitle('a1-t-v1');
+        $article->setContent('a1-c-v1');
+        
+        $comment = new Comment;
+        $comment->setArticle($article);
+        $comment->setMessage('m-v1');
+        $comment->setSubject('s-v1');
+        
+        $this->em->persist($article);
+        $this->em->persist($comment);
+        $this->em->flush();
+        
+        $comment->setMessage('m-v2');
+        $this->em->persist($comment);
+        $this->em->flush();
+        
+        $comment->setSubject('s-v3');
+        $this->em->persist($comment);
+        $this->em->flush();
+        
+        $article2 = new RelatedArticle;
+        $article2->setTitle('a2-t-v1');
+        $article2->setContent('a2-c-v1');
+        
+        $comment->setArticle($article2);
+        $this->em->persist($article2);
+        $this->em->persist($comment);
+        $this->em->flush();
+        
+        $comment->setMessage('m-v5');
+        $this->em->persist($comment);
+        $this->em->flush();
+        $this->em->clear();
     }
 }

+ 3 - 0
tests/phpunit.dist.xml

@@ -16,5 +16,8 @@
         <testsuite name="Mapping Extension">
             <directory suffix=".php">./Gedmo/Mapping/</directory>
         </testsuite>
+        <testsuite name="Loggable Extension">
+            <directory suffix=".php">./Gedmo/Loggable/</directory>
+        </testsuite>
     </testsuites>
 </phpunit>

+ 1 - 1
vendor/doctrine-common

@@ -1 +1 @@
-Subproject commit 602de4d6d8813e567c8e5333d85bda28b4583ffc
+Subproject commit 440e0504921f7464b1852c1364d7bc7d0119cbc3

+ 1 - 1
vendor/doctrine-dbal

@@ -1 +1 @@
-Subproject commit 92c680ac979438b555ccc2f50ed3d758cebdced6
+Subproject commit 547eaaff9f74557c5fbaa0141ff685c917b19286

+ 1 - 1
vendor/doctrine-mongodb

@@ -1 +1 @@
-Subproject commit a467d22d6ccbcae42aa89f4cdf6d35ea957b5ff9
+Subproject commit 4488aadb38d2fc24d0e82db928aa5e8e6a372d22

+ 1 - 1
vendor/doctrine-mongodb-odm

@@ -1 +1 @@
-Subproject commit afa17ea761d19a45571bf4295d02e50db3776455
+Subproject commit c2ff02c2b4ca23b0601923a0aecc9b21e4dba435

+ 1 - 1
vendor/doctrine-orm

@@ -1 +1 @@
-Subproject commit 4ecb582c7638ec8ade2ab9a9694e97f2d5428cee
+Subproject commit 521705a0f23d3efeb7d165b11631b437e2503dda