public function testconfiguration()
 {
     $config = new Configuration();
     $config->setCurrentUser($this->ZfcUserMock);
     $prefix = "prefix";
     $config->setTablePrefix($prefix);
     $suffix = "suffix";
     $config->setTableSuffix($suffix);
     $fieldName = "fieldName";
     $config->setRevisionFieldName($fieldName);
     $revisionIdFieldType = "string";
     $config->setRevisionIdFieldType($revisionIdFieldType);
     $tableName = "tableName";
     $config->setRevisionTableName($tableName);
     $revisionTypeFieldName = "string";
     $config->setRevisionTypeFieldName($revisionTypeFieldName);
     $ipaddress = $config->getIpAddress();
     $config->setAuditedEntityClasses(array('ZF2EntityAuditTest\\Entity\\Article', 'ZF2EntityAuditTest\\Entity\\Writer'));
     $config->setNote("default note");
     $this->auditManager = new Manager($config);
     $this->auditManager->registerEvents($this->em->getEventManager());
     /// creating the tables
     $this->schemaTool = $this->getSchemaTool();
     $this->schemaTool->createSchema(array($this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Article'), $this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Writer')));
     $this->assertInstanceOf("ZfcUser\\Entity\\User", $this->ZfcUserMock);
     $this->assertEquals($prefix, $config->getTablePrefix());
     $this->assertEquals($suffix, $config->getTableSuffix());
     $this->assertEquals($fieldName, $config->getRevisionFieldName());
     $this->assertEquals($tableName, $config->getRevisionTableName());
     $this->assertEquals($revisionIdFieldType, $config->getRevisionIdFieldType());
     $this->assertEquals($revisionTypeFieldName, $config->getRevisionIdFieldType());
     $this->assertEquals($ipaddress, "1.1.1.9");
 }
Beispiel #2
0
 public function getServiceConfig()
 {
     return array('factories' => array('auditConfig' => function ($sm) {
         $config = $sm->get('Config');
         $auditconfig = new Configuration();
         $auditconfig->setAuditedEntityClasses($config['zf2-entity-audit']['entities']);
         $auditconfig->setZfcUserEntityClass($config['zf2-entity-audit']['zfcuser.entity_class']);
         return $auditconfig;
     }, 'auditManager' => function ($sm) {
         $config = $sm->get('Config');
         $evm = $sm->get('doctrine.eventmanager.orm_default');
         $auditconfig = $sm->get('auditConfig');
         if ($config['zf2-entity-audit']['zfcuser.integration'] === true) {
             $auth = $sm->get('zfcuser_auth_service');
             if ($auth->hasIdentity()) {
                 $identity = $auth->getIdentity();
                 $auditconfig->setCurrentUser($identity);
             }
             /* need to handle the unauthenticated user action case, do it your own , 99% i will drop support for unauthenticated user auditing  */
         }
         $auditManager = new Manager($auditconfig);
         $evm->addEventSubscriber(new CreateSchemaListener($auditManager));
         $evm->addEventSubscriber(new LogRevisionsListener($auditManager));
         return $auditManager;
     }, 'auditReader' => function ($sm) {
         $auditManager = $sm->get('auditManager');
         $entityManager = $sm->get('doctrine.entitymanager.orm_default');
         return $auditManager->createAuditReader($entityManager);
     }));
 }
Beispiel #3
0
 public function setUp()
 {
     $this->Bootstrap = new Bootstrap();
     $this->em = $this->Bootstrap->getServiceManager()->get("doctrine.entitymanager.orm_default");
     /// echo sql logger
     //$this->em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());;
     /// let's create the default user
     $this->ZfcUserMock = $this->createUser();
     $auditConfig = new Configuration();
     $auditConfig->setCurrentUser($this->ZfcUserMock);
     $auditConfig->setAuditedEntityClasses(array('ZF2EntityAuditTest\\Entity\\Article', 'ZF2EntityAuditTest\\Entity\\Writer'));
     $auditConfig->setNote("default note");
     $this->auditManager = new Manager($auditConfig);
     $this->auditManager->registerEvents($this->em->getEventManager());
     /// creating the tables
     $this->schemaTool = $this->getSchemaTool();
     $this->schemaTool->createSchema(array($this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Article'), $this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Writer')));
 }