Esempio n. 1
0
 public function testWalkerWithSeveralAndWhereCondition()
 {
     $query = $this->em->getRepository('Test:CmsAddress')->createQueryBuilder('address')->select('address.id')->where('address.id = 1 AND address.country = \'us\'')->getQuery();
     $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Oro\\Bundle\\SecurityBundle\\ORM\\Walker\\CurrentUserWalker']);
     $query->setHint(CurrentUserWalker::HINT_SECURITY_CONTEXT, ['user' => 123, 'organization' => 456]);
     $this->assertEquals('SELECT c0_.id AS id_0' . ' FROM cms_addresses c0_' . ' WHERE c0_.id = 1 AND c0_.country = \'us\'' . ' AND c0_.user_id = 123 AND c0_.organization = 456', $query->getSQL());
 }
 public function testGetConnectionListQueryBuilder()
 {
     /** @var CalendarConnectionRepository $repo */
     $repo = $this->em->getRepository('OroCalendarBundle:CalendarConnection');
     $qb = $repo->getConnectionListQueryBuilder(1);
     $this->assertEquals('SELECT calendarConnection, connectedCalendar, owner' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\CalendarConnection calendarConnection' . ' INNER JOIN calendarConnection.calendar calendar' . ' INNER JOIN calendarConnection.connectedCalendar connectedCalendar' . ' INNER JOIN connectedCalendar.owner owner' . ' WHERE calendar.id = :id ORDER BY calendarConnection.createdAt ASC', $qb->getQuery()->getDQL());
 }
 public function testGetEventListByTimeIntervalQueryBuilderWithAdditionalFiltersAsArray()
 {
     /** @var CalendarEventRepository $repo */
     $repo = $this->em->getRepository('OroCalendarBundle:CalendarEvent');
     $qb = $repo->getEventListByTimeIntervalQueryBuilder(1, new \DateTime(), new \DateTime(), false, ['allDay' => true]);
     $this->assertEquals('SELECT c.id as calendar, e.id, e.title, e.description, e.start, e.end, e.allDay, e.createdAt, e.updatedAt' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent e' . ' INNER JOIN e.calendar c' . ' WHERE e.allDay = :allDay AND c.id = :id' . ' AND (' . '(e.start < :start AND e.end >= :start) OR ' . '(e.start <= :end AND e.end > :end) OR' . '(e.start >= :start AND e.end < :end))' . ' ORDER BY c.id, e.start ASC', $qb->getQuery()->getDQL());
     $this->assertTrue($qb->getQuery()->getParameter('allDay')->getValue());
 }
Esempio n. 4
0
 public function testGetAssociatedNotesQueryBuilderWithPaging()
 {
     /** @var NoteRepository $repo */
     $repo = $this->em->getRepository('OroNoteBundle:Note');
     $qb = $repo->getAssociatedNotesQueryBuilder('Test\\Entity', 123, 10, 50);
     $this->assertEquals('SELECT partial note.{id, message, owner, createdAt, updatedBy, updatedAt}, c, u' . ' FROM Oro\\Bundle\\NoteBundle\\Entity\\Note note' . ' INNER JOIN Test\\Entity e WITH note.entity_2929d33a = e' . ' LEFT JOIN note.owner c' . ' LEFT JOIN note.updatedBy u' . ' WHERE e.id IN(123)', $qb->getDQL());
     $this->assertEquals(450, $qb->getFirstResult());
     $this->assertEquals(50, $qb->getMaxResults());
 }
 public function testGetEmptyOutdatedFoldersByOriginQueryBuilder()
 {
     $origin = new ImapEmailOrigin();
     /** @var ImapEmailFolderRepository $repo */
     $repo = $this->em->getRepository('OroImapBundle:ImapEmailFolder');
     $qb = $repo->getEmptyOutdatedFoldersByOriginQueryBuilder($origin);
     $query = $qb->getQuery();
     $this->assertEquals('SELECT imap_folder' . ' FROM Oro\\Bundle\\ImapBundle\\Entity\\ImapEmailFolder imap_folder' . ' INNER JOIN imap_folder.folder folder' . ' LEFT JOIN folder.emailUsers emailUsers' . ' WHERE (folder.outdatedAt IS NOT NULL AND emailUsers.id IS NULL) AND folder.origin = :origin', $query->getDQL());
     $this->assertSame($origin, $query->getParameter('origin')->getValue());
 }
 public function testGetCalendarsQueryBuilder()
 {
     $organizationId = 1;
     /** @var SystemCalendarRepository $repo */
     $repo = $this->em->getRepository('OroCalendarBundle:SystemCalendar');
     $qb = $repo->getCalendarsQueryBuilder($organizationId);
     $this->assertEquals('SELECT sc' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\SystemCalendar sc' . ' WHERE sc.organization = :organizationId OR sc.public = :public', $qb->getQuery()->getDQL());
     $this->assertEquals($organizationId, $qb->getParameter('organizationId')->getValue());
     $this->assertTrue($qb->getParameter('public')->getValue());
 }
 public function testGetUserCalendarsQueryBuilder()
 {
     $organizationId = 1;
     $userId = 123;
     /** @var CalendarRepository $repo */
     $repo = $this->em->getRepository('OroCalendarBundle:Calendar');
     $qb = $repo->getUserCalendarsQueryBuilder($organizationId, $userId);
     $this->assertEquals('SELECT c' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\Calendar c' . ' WHERE c.organization = :organizationId AND c.owner = :userId', $qb->getQuery()->getDQL());
     $this->assertEquals($organizationId, $qb->getParameter('organizationId')->getValue());
     $this->assertEquals($userId, $qb->getParameter('userId')->getValue());
 }
 public function testGetTaskListByTimeIntervalQueryBuilder()
 {
     $entityClassName = 'Test\\Entity';
     $entityIds = [1, 2, 3];
     /** @var ReminderRepository $repo */
     $repo = $this->em->getRepository('OroReminderBundle:Reminder');
     $qb = $repo->findRemindersByEntitiesQueryBuilder($entityClassName, $entityIds);
     $this->assertEquals('SELECT reminder' . ' FROM Oro\\Bundle\\ReminderBundle\\Entity\\Reminder reminder' . ' WHERE reminder.relatedEntityClassName = :className AND reminder.relatedEntityId IN (:ids)', $qb->getDQL());
     $this->assertEquals($entityClassName, $qb->getParameter('className')->getValue());
     $this->assertEquals($entityIds, $qb->getParameter('ids')->getValue());
 }
 public function testGetTaskListByTimeIntervalQueryBuilderWithAlias()
 {
     $targetCalendarId = 123;
     $alias = 'test';
     /** @var CalendarPropertyRepository $repo */
     $repo = $this->em->getRepository('OroCalendarBundle:CalendarProperty');
     $qb = $repo->getConnectionsByTargetCalendarQueryBuilder($targetCalendarId, $alias);
     $this->assertEquals('SELECT connection' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\CalendarProperty connection' . ' WHERE connection.targetCalendar = :targetCalendarId AND connection.calendarAlias = :alias', $qb->getDQL());
     $this->assertEquals($targetCalendarId, $qb->getParameter('targetCalendarId')->getValue());
     $this->assertEquals($alias, $qb->getParameter('alias')->getValue());
 }
 public function testGetEmailsByMessageIdsQueryBuilder()
 {
     $origin = new ImapEmailOrigin();
     $messageIds = ['msg1', 'msg2'];
     /** @var ImapEmailRepository $repo */
     $repo = $this->em->getRepository('OroImapBundle:ImapEmail');
     $qb = $repo->getEmailsByMessageIdsQueryBuilder($origin, $messageIds);
     $query = $qb->getQuery();
     $this->assertEquals('SELECT imap_email ' . 'FROM Oro\\Bundle\\ImapBundle\\Entity\\ImapEmail imap_email ' . 'INNER JOIN imap_email.imapFolder imap_folder ' . 'INNER JOIN imap_email.email email ' . 'INNER JOIN email.emailUsers email_users ' . 'INNER JOIN email_users.folder folder ' . 'WHERE folder.origin = :origin AND email.messageId IN (:messageIds)', $query->getDQL());
     $this->assertSame($origin, $query->getParameter('origin')->getValue());
     $this->assertEquals($messageIds, $query->getParameter('messageIds')->getValue());
 }
Esempio n. 11
0
 public function testGetTaskListByTimeIntervaWithExtraFieldslQueryBuilder()
 {
     $userId = 123;
     $startDate = new \DateTime();
     $endDate = clone $startDate;
     $endDate->add(new \DateInterval('P1D'));
     $extraFields = ['status'];
     /** @var TaskRepository $repo */
     $repo = $this->em->getRepository('OroCRMTaskBundle:Task');
     $qb = $repo->getTaskListByTimeIntervalQueryBuilder($userId, $startDate, $endDate, $extraFields);
     $this->assertEquals('SELECT t.id, t.subject, t.description, t.dueDate, t.createdAt, t.updatedAt, t.status' . ' FROM OroCRM\\Bundle\\TaskBundle\\Tests\\Unit\\Fixtures\\Entity\\Task t' . ' WHERE t.owner = :assignedTo AND t.dueDate >= :start AND t.dueDate <= :end', $qb->getDQL());
     $this->assertEquals($userId, $qb->getParameter('assignedTo')->getValue());
     $this->assertEquals($startDate, $qb->getParameter('start')->getValue());
     $this->assertEquals($endDate, $qb->getParameter('end')->getValue());
 }
Esempio n. 12
0
 public function testAddFilterByTargetEntity()
 {
     $targetEntityClass = 'Oro\\Bundle\\ActivityBundle\\Tests\\Unit\\Fixtures\\Entity\\Target';
     $targetEntityId = 123;
     $qb = $this->em->getRepository('Test:Activity')->createQueryBuilder('activity')->select('activity');
     $this->manager->addFilterByTargetEntity($qb, $targetEntityClass, $targetEntityId);
     $this->assertEquals('SELECT activity' . ' FROM Oro\\Bundle\\ActivityBundle\\Tests\\Unit\\Fixtures\\Entity\\Activity activity' . ' WHERE activity.id IN(' . 'SELECT filterActivityEntity.id' . ' FROM Oro\\Bundle\\ActivityBundle\\Tests\\Unit\\Fixtures\\Entity\\Activity filterActivityEntity' . ' INNER JOIN filterActivityEntity.target_cb0fccb1 filterTargetEntity' . ' WHERE filterTargetEntity.id = :targetEntityId)', $qb->getQuery()->getDQL());
     $this->assertEquals($targetEntityId, $qb->getParameter('targetEntityId')->getValue());
 }
 public function testGetInvitedUsersByParentsQueryBuilder()
 {
     $parentEventIds = [1, 2];
     /** @var CalendarEventRepository $repo */
     $repo = $this->em->getRepository('OroCalendarBundle:CalendarEvent');
     $qb = $repo->getInvitedUsersByParentsQueryBuilder($parentEventIds);
     $this->assertEquals('SELECT IDENTITY(e.parent) AS parentEventId, e.id AS eventId, u.id AS userId' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent e' . ' INNER JOIN e.calendar c' . ' INNER JOIN c.owner u' . ' WHERE e.parent IN (:parentEventIds)', $qb->getQuery()->getDQL());
     $this->assertEquals($parentEventIds, $qb->getQuery()->getParameter('parentEventIds')->getValue());
 }