public function testSetJoinClass() { $serviceManager = Bootstrap::getApplication()->getServiceManager(); $moduleOptions = clone $serviceManager->get('auditModuleOptions'); $moduleOptions->setDefaults(array()); $this->assertEquals($moduleOptions, $moduleOptions->addJoinClass('test', array())); }
public function testRevisionsAreReturnedInPaginator() { $sm = Bootstrap::getApplication()->getServiceManager(); $helper = $sm->get('viewhelpermanager')->get('auditEntityOptions'); $helper('SoliantEntityAuditTest\\Models\\Bootstrap\\Song'); $helper(); }
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 = \SoliantEntityAudit\Module::getModuleOptions()->getEntityManager(); $helper = $sm->get('viewhelpermanager')->get('auditCurrentRevisionEntity'); $entity = new Album(); $revisionEntity = $helper($entity); $this->assertEquals(null, $revisionEntity); }
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('SoliantEntityAuditTest\\Models\\Bootstrap\\Album', $revisionEntity->getTargetEntityClass()); }
public function testPaginatorCanAcceptAuditedClassName() { $sm = Bootstrap::getApplication()->getServiceManager(); $em = \SoliantEntityAudit\Module::getModuleOptions()->getEntityManager(); $helper = $sm->get('viewhelpermanager')->get('auditRevisionEntityPaginator'); $revisionEntities = $em->getRepository('SoliantEntityAudit\\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 testRevisionComment() { // Inserting data insures we will have a result > 0 $em = \SoliantEntityAudit\Module::getModuleOptions()->getEntityManager(); $service = \SoliantEntityAudit\Module::getModuleOptions()->getAuditService(); $entity = new Album(); $entity->setTitle('Test 1'); $service->setComment('Test service comment is persisted on revision'); $service = \SoliantEntityAudit\Module::getModuleOptions()->getAuditService(); $this->assertEquals('Test service comment is persisted on revision', $service->getComment()); return; $em->persist($entity); $em->flush(); $x = $em->getRepository('SoliantEntityAudit\\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('SoliantEntityAudit\\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); }
} 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__ . '/' . __NAMESPACE__)))); } 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();