public function testRevisionsAreReturnedInPaginator()
 {
     $sm = Bootstrap::getApplication()->getServiceManager();
     $helper = $sm->get('viewhelpermanager')->get('auditEntityOptions');
     $helper('ZFTest\\Doctrine\\Audit\\Models\\Bootstrap\\Song');
     $helper();
 }
 public function testSetJoinClass()
 {
     $serviceManager = Bootstrap::getApplication()->getServiceManager();
     $moduleOptions = clone $serviceManager->get('auditModuleOptions');
     $moduleOptions->setDefaults(array());
     $this->assertEquals($moduleOptions, $moduleOptions->addJoinClass('test', array()));
 }
 public function testGetRevisionIdentifierValue()
 {
     $serviceManager = Bootstrap::getApplication()->getServiceManager();
     $auditObjectManager = $serviceManager->get('doctrine.entitymanager.orm_zf_doctrine_audit');
     $artist = new Entity\Artist();
     $auditClass = $auditObjectManager->getRepository('ZF\\Doctrine\\Audit\\Entity\\AuditEntity')->generateClassName(get_class($artist));
     $this->assertEquals('ZF\\Doctrine\\Audit\\RevisionEntity\\ZFTest_Doctrine_Audit_Entity_Artist', $auditClass);
 }
 public function testViewHelperConfig()
 {
     $sm = Bootstrap::getApplication()->getServiceManager();
     $helper = $sm->get('viewhelpermanager')->get('auditDateTimeFormatter');
     $now = new \DateTime();
     $helper->setDateTimeFormat('U');
     $this->assertEquals($helper($now), $now->format('U'));
 }
 public function testDoesNotReturnRevisionEntity()
 {
     $sm = Bootstrap::getApplication()->getServiceManager();
     $em = \ZF\Doctrine\Audit\Module::getModuleOptions()->getEntityManager();
     $helper = $sm->get('viewhelpermanager')->get('auditCurrentRevisionEntity');
     $entity = new Album();
     $revisionEntity = $helper($entity);
     $this->assertEquals(null, $revisionEntity);
 }
 function testClearComment()
 {
     $serviceManager = Bootstrap::getApplication()->getServiceManager();
     $revisionComment = $serviceManager->get('ZF\\Doctrine\\Audit\\Service\\RevisionComment');
     $revisionComment->setComment('unittest');
     $this->assertEquals('unittest', $revisionComment->getComment());
     $revisionComment->setComment(null);
     $this->assertEquals(null, $revisionComment->getComment());
 }
 public function testGettersAndSetters()
 {
     $em = Bootstrap::getApplication()->getServiceManager()->get("doctrine.entitymanager.orm_default");
     $sm = Bootstrap::getApplication()->getServiceManager();
     $entity = new Album();
     $entity->setTitle('test 1');
     $em->persist($entity);
     $em->flush();
     $helper = $sm->get('viewhelpermanager')->get('auditCurrentRevisionEntity');
     $revisionEntity = $helper($entity);
     $this->assertEquals('INS', $revisionEntity->getRevisionType());
     $this->assertEquals($entity, $revisionEntity->getTargetEntity());
     $this->assertEquals('ZFTest\\Doctrine\\Audit\\Models\\Bootstrap\\Album', $revisionEntity->getTargetEntityClass());
 }
 public function testPaginatorCanAcceptAuditedClassName()
 {
     $sm = Bootstrap::getApplication()->getServiceManager();
     $em = \ZF\Doctrine\Audit\Module::getModuleOptions()->getEntityManager();
     $helper = $sm->get('viewhelpermanager')->get('auditRevisionEntityPaginator');
     $revisionEntities = $em->getRepository('ZF\\Doctrine\\Audit\\Entity\\RevisionEntity')->findAll();
     $count = sizeof($revisionEntities);
     $paginator = $helper($page = 0, get_class(array_shift($revisionEntities)->getTargetEntity()));
     $paginatedcount = 0;
     foreach ($paginator as $row) {
         $paginatedcount++;
     }
     $this->assertGreaterThan(0, $count);
     $this->assertEquals($count, $paginatedcount);
 }
 public function testRevisionEntityActionCanBeAccessed()
 {
     $em = Bootstrap::getApplication()->getServiceManager()->get("doctrine.entitymanager.orm_default");
     $sm = Bootstrap::getApplication()->getServiceManager();
     $entity = new Album();
     $entity->setTitle('test 1');
     $em->persist($entity);
     $em->flush();
     $helper = $sm->get('viewhelpermanager')->get('auditCurrentRevisionEntity');
     $revisionEntity = $helper($entity);
     if (!$revisionEntity) {
         die('helper did not return current revision entity');
     }
     $this->routeMatch->setParam('action', 'revision-entity');
     $this->routeMatch->setParam('controller', 'audit');
     $this->routeMatch->setParam('revisionEntityId', $revisionEntity->getId());
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->assertEquals(200, $response->getStatusCode());
 }
 public function testGetRevisionIdentifierValue()
 {
     $serviceManager = Bootstrap::getApplication()->getServiceManager();
     $objectManager = $serviceManager->get('doctrine.entitymanager.orm_default');
     $auditObjectManager = $serviceManager->get('doctrine.entitymanager.orm_zf_doctrine_audit');
     $revisionComment = $serviceManager->get('ZF\\Doctrine\\Audit\\Service\\RevisionComment');
     $artist = new Entity\Artist();
     $artist->setName('unittest');
     $objectManager->persist($artist);
     $revisionComment->setComment('Add Artist');
     $objectManager->flush();
     $artist->setName('unit-test');
     $revisionComment->setComment('Change Artist');
     $objectManager->flush();
     $revision = $auditObjectManager->getRepository('ZF\\Doctrine\\Audit\\Entity\\Revision')->findOneBy(['comment' => 'Change Artist']);
     foreach ($revision->getRevisionEntity() as $revisionEntity) {
         foreach ($revisionEntity->getRevisionEntityIdentifierValue() as $value) {
             $this->assertEquals(1, $value->getValue());
         }
     }
 }
 public function testRevisionComment()
 {
     // Inserting data insures we will have a result > 0
     $em = \ZF\Doctrine\Audit\Module::getModuleOptions()->getEntityManager();
     $service = \ZF\Doctrine\Audit\Module::getModuleOptions()->getAuditService();
     $entity = new Album();
     $entity->setTitle('Test 1');
     $service->setComment('Test service comment is persisted on revision');
     $service = \ZF\Doctrine\Audit\Module::getModuleOptions()->getAuditService();
     $this->assertEquals('Test service comment is persisted on revision', $service->getComment());
     return;
     $em->persist($entity);
     $em->flush();
     $x = $em->getRepository('ZF\\Doctrine\\Audit\\Entity\\Revision')->findAll();
     print_r($x);
     $em->persist($entity);
     $em->flush();
     $helper = Bootstrap::getApplication()->getServiceManager()->get('viewhelpermanager')->get('auditCurrentRevisionEntity');
     $lastEntityRevision = $helper($entity);
     print_r($lastEntityRevision->getRevision());
     die;
     $this->assertEquals('test 2', $lastEntityRevision->getRevision()->getComment());
 }
 public function testRevisionsAreReturnedInPaginator()
 {
     $sm = Bootstrap::getApplication()->getServiceManager();
     $em = Bootstrap::getApplication()->getServiceManager()->get("doctrine.entitymanager.orm_default");
     $helper = $sm->get('viewhelpermanager')->get('auditRevisionPaginator');
     $revisions = $em->getRepository('ZF\\Doctrine\\Audit\\Entity\\Revision')->findAll();
     $count = sizeof($revisions);
     $paginator = $helper($page = 0);
     $paginatedcount = 0;
     foreach ($paginator as $row) {
         $paginatedcount++;
     }
     $this->assertGreaterThan(0, $count);
     $this->assertEquals($count, $paginatedcount);
     // Test paginator filter
     $revision1 = array_shift($revisions);
     $paginator = $helper($page = 0, array('id' => $revision1->getId(), 'user' => null));
     $paginatedcount = 0;
     foreach ($paginator as $row) {
         $paginatedcount++;
     }
     $this->assertEquals(1, $paginatedcount);
 }
 function testAuditAutoloader()
 {
     $serviceManager = Bootstrap::getApplication()->getServiceManager();
     $auditAutoLoader = $serviceManager->get('ZF\\Doctrine\\Audit\\Loader\\AuditAutoLoader');
     $this->assertTrue($auditAutoLoader instanceof AuditAutoLoader);
 }
    }
    protected static function initAutoloader()
    {
        $vendorPath = static::findParentPath('vendor');
        if (is_readable($vendorPath . '/autoload.php')) {
            $loader = (include $vendorPath . '/autoload.php');
        } else {
            $zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));
            if (!$zf2Path) {
                throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
            }
            include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
        }
        AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array('autoregister_zf' => true, 'namespaces' => array(__NAMESPACE__ => __DIR__ . '/ZFTest'))));
    }
    protected static function findParentPath($path)
    {
        $dir = __DIR__;
        $previousDir = '.';
        while (!is_dir($dir . '/' . $path)) {
            $dir = dirname($dir);
            if ($previousDir === $dir) {
                return false;
            }
            $previousDir = $dir;
        }
        return $dir . '/' . $path;
    }
}
Bootstrap::init();