/**
  * {@inheritDoc}
  * 
  * @see PHPUnit_Framework_TestCase::tearDownAfterClass()
  * 
  * @uses KernelTestCase::ensureKernelShutdown()
  */
 public static function tearDownAfterClass()
 {
     parent::ensureKernelShutdown();
     static::$repository->clear();
     static::$repository = null;
     // avoid memory leaks
 }
Пример #2
0
 /**
  * Get author options
  *
  * @return array
  */
 public function getOptions()
 {
     $authors = array();
     foreach ($this->repository->findBy(array(), array('last_name' => 'asc', 'first_name' => 'asc')) as $author) {
         $authors[$author->getId()] = $author->getFullName();
     }
     return $authors;
 }
Пример #3
0
 /**
  * Perform a query
  *
  * @param string $query
  * @return array
  */
 public function find($query)
 {
     $qb = $this->repository->createQueryBuilder('p');
     $tokens = explode(' ', trim($query));
     foreach ($tokens as $p => $token) {
         $qb->orWhere($qb->expr()->like('p.headline', $qb->expr()->literal("%{$token}%")));
     }
     return $qb->getQuery()->getResult();
 }
Пример #4
0
 /**
  * @expects Exception
  */
 public function testSave()
 {
     $user = new User('uname');
     $topic = new Topic(1, 1, 'name');
     $this->em->persist($user);
     $this->em->persist($topic);
     $this->em->flush();
     $userTopic = new UserTopic($user, $topic);
     $this->em->persist($userTopic);
     $this->em->flush();
     $this->em->clear();
     $userTopics = $this->repository->findBy(array('user' => $user->getId()));
     $this->assertEquals(1, sizeof($userTopics));
     $this->assertEquals($topic->getName(), $userTopics[0]->getTopic()->getName());
 }
Пример #5
0
 public function testSave()
 {
     $user = new User();
     $user->setUsername('testname');
     $user->setEmail('email');
     $this->em->persist($user);
     $this->em->flush();
     $event = new CommunityTickerEvent();
     $this->repository->save($event, array('event' => 'test.event', 'user' => 1, 'params' => array('param1' => 'value1')));
     $this->em->flush();
     $this->em->clear();
     $this->assertEquals(1, $event->getId());
     $this->assertEquals('test.event', $event->getEvent());
     $this->assertEquals($user, $event->getUser());
     $this->assertEquals(array('param1' => 'value1'), $event->getParams());
 }
Пример #6
0
 public function testSave()
 {
     $user = new User('email');
     $this->em->persist($user);
     $this->em->flush();
     $userToken = new UserToken($user, 'test_action', 'test_token');
     $this->assertAttributeEquals('test_action', 'action', $userToken);
     $this->assertAttributeEquals('test_token', 'token', $userToken);
     $this->assertAttributeEquals($user, 'user', $userToken);
     $this->em->persist($userToken);
     $this->em->flush();
     $this->em->clear();
     $tokens = $this->repository->findAll();
     $this->assertEquals(1, sizeof($tokens));
     $token = $this->repository->find(array('user' => $user->getId(), 'action' => 'test_action', 'token' => 'test_token'));
     $this->assertNotNull($token);
 }
 /**
  * @covers Kunstmaan\PagePartBundle\EventListener\CloneListener::postDeepCloneAndSave
  */
 public function testClonePageTemplate()
 {
     $entity = $this->getMockBuilder('Kunstmaan\\PagePartBundle\\Helper\\HasPageTemplateInterface')->setMethods(array('getId', 'getPageTemplates', 'getPagePartAdminConfigurations'))->getMock();
     $entity->expects($this->any())->method('getPagePartAdminConfigurations')->will($this->returnValue(array($this->configurator)));
     $clone = clone $entity;
     $entity->expects($this->any())->method('getId')->will($this->returnValue(1));
     $clone->expects($this->any())->method('getId')->will($this->returnValue(2));
     $this->repo->expects($this->once())->method('copyPageParts')->with($this->em, $entity, $clone, 'main');
     $configuration = new PageTemplateConfiguration();
     $configuration->setId(1);
     $configuration->setPageId(1);
     $this->repo->expects($this->once())->method('findOrCreateFor')->with($this->identicalTo($entity))->will($this->returnValue($configuration));
     $newConfiguration = clone $configuration;
     $newConfiguration->setId(null);
     $newConfiguration->setPageId($clone->getId());
     $this->em->expects($this->once())->method('persist')->with($newConfiguration);
     $event = new DeepCloneAndSaveEvent($entity, $clone);
     $this->object->postDeepCloneAndSave($event);
 }
Пример #8
0
 /**
  * Build where condition
  *
  * @param array $cols
  * @param string $search
  * @return Doctrine\ORM\Query\Expr
  */
 private function buildWhere(array $cols, $search)
 {
     $qb = $this->_repository->createQueryBuilder('e');
     $or = $qb->expr()->orx();
     foreach (array_keys($cols) as $i => $property) {
         if (!is_string($property)) {
             // not searchable
             continue;
         }
         $or->add($qb->expr()->like("e.{$property}", $qb->expr()->literal("%{$search}%")));
     }
     return $or;
 }
Пример #9
0
 /**
  * Build where condition
  *
  * @param array $cols
  * @param string $search
  * @return Doctrine\ORM\Query\Expr
  */
 private function buildWhere(array $cols, $params)
 {
     $qb = $this->repository->createQueryBuilder('e');
     $or = $qb->expr()->orx();
     $reflection = new \ReflectionObject(new $this->entityName());
     $search = $params['sSearch'];
     foreach (array_keys($cols) as $id => $property) {
         //column is searchable
         if ($reflection->hasProperty($property) && $params["bSearchable_{$id}"]) {
             $or->add($qb->expr()->like("e.{$property}", $qb->expr()->literal("%{$search}%")));
         }
     }
     return $or;
 }
Пример #10
0
 public function editAction()
 {
     $role = $this->_getParam('user', false) ? $this->_helper->entity->find('Newscoop\\Entity\\User', $this->_getParam('user')) : $this->_helper->entity->find('Newscoop\\Entity\\User\\Group', $this->_getParam('group'));
     if ($this->getRequest()->isPost()) {
         $values = $this->getRequest()->getPost();
         if ($this->isBlocker($values)) {
             $this->view->error = getGS("You can't deny yourself to manage \$1", $this->getResourceName($this->resource));
             return;
         }
         try {
             $this->ruleRepository->save($values, $this->_getParam('user', false));
         } catch (\Exception $e) {
             $this->view->error = $e->getMessage();
         }
         return;
     }
     $this->view->role = $role;
     $this->view->groups = $this->groups;
     $this->view->resources = $this->resources;
     $this->view->actions = $this->acl->getResources();
     $this->view->actionNames = $this->actions;
     $this->view->acl = $this->getHelper('acl')->getAcl($role);
 }
Пример #11
0
 public function editAction()
 {
     $translator = \Zend_Registry::get('container')->getService('translator');
     $role = $this->_getParam('user', false) ? $this->_helper->entity->find('Newscoop\\Entity\\User', $this->_getParam('user')) : $this->_helper->entity->find('Newscoop\\Entity\\User\\Group', $this->_getParam('group'));
     if ($this->getRequest()->isPost()) {
         $values = $this->getRequest()->getPost();
         if ($this->isBlocker($values)) {
             $this->view->error = $translator->trans("You cant deny yourself to manage \$1", array('$1' => $this->getResourceName($this->resource)), 'user_types');
             return;
         }
         try {
             $this->ruleRepository->save($values, $this->_getParam('user', false));
         } catch (\Exception $e) {
             $this->view->error = $e->getMessage();
         }
         return;
     }
     $this->view->role = $role;
     $this->view->groups = $this->groups;
     $this->view->resources = $this->resources;
     $this->view->actions = $this->acl->getResources();
     $this->view->actionNames = $this->actions;
     $this->view->acl = $this->getHelper('acl')->getAcl($role);
 }
Пример #12
0
 /**
  * Get count by a set of criteria
  *
  * @param  array $criteria
  * @return int
  */
 public function getCountBy(array $criteria = array())
 {
     return (int) $this->repository->getCountBy($criteria);
 }
 /**
  * Delete all model states.
  *
  * @param ModelInterface $model
  * @param string $processName
  */
 public function deleteAllModelStates(ModelInterface $model, $processName = null)
 {
     return $this->repository->deleteModelStates($model->getWorkflowIdentifier(), $processName);
 }
Пример #14
0
 /**
  * Retorna o nome da entity.
  *
  * @return string
  */
 public function getEntityName()
 {
     $this->repository->getEntityName();
 }
Пример #15
0
 /**
  * Normalize by fetching workflow states of each $objects.
  *
  * @param ModelState|array $objects
  * @param array            $processes
  * @param bool             $onlySuccess
  */
 public function setStates($objects, $processes = array(), $onlySuccess = false)
 {
     $this->repository->setStates($objects, $processes, $onlySuccess);
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function value($key)
 {
     return $this->repository->find($key);
 }