public function testMerge()
 {
     $account1 = new User();
     $account2 = new User();
     $this->setId($account1, 1);
     $this->setId($account2, 2);
     $entityMetadata = new EntityMetadata(['type' => ClassUtils::getRealClass($account1)]);
     $entityData = new EntityData($entityMetadata, [$account1, $account2]);
     $entityData->setMasterEntity($account1);
     $fieldData = new FieldData($entityData, new FieldMetadata());
     $fieldData->setMode(MergeModes::NOTES_REPLACE);
     $fieldData->setSourceEntity($account2);
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock();
     $queryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf());
     $queryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([new ExtendNote()]));
     $repository = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\Repository\\ActivityListRepository')->disableOriginalConstructor()->setMethods(['getBaseAssociatedNotesQB', 'getActivityListQueryBuilderByActivityClass'])->getMock();
     $repository->expects($this->any())->method('getBaseAssociatedNotesQB')->willReturn($queryBuilder);
     $activityQueryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock();
     $activityQueryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf());
     $activityQueryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([['id' => 1, 'relatedActivityId' => 11], ['id' => 3, 'relatedActivityId' => 2]]));
     $repository->expects($this->any())->method('getActivityListQueryBuilderByActivityClass')->willReturn($activityQueryBuilder);
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['remove'])->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->willReturn($repository);
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->willReturn($entityManager);
     $this->activityListManager->expects($this->once())->method('replaceActivityTargetWithPlainQuery');
     $this->strategy->merge($fieldData);
 }
 /**
  * @param bool $withRelations
  *
  * @dataProvider testDataProvider
  */
 public function testBuildFormRegularGuesser($withRelations)
 {
     $entityName = 'Test\\Entity';
     $this->doctrineHelperMock->expects($this->once())->method('getEntityIdentifierFieldNames')->with($entityName)->willReturn(['id']);
     $fields = [['name' => 'oneField', 'type' => 'string', 'label' => 'One field'], ['name' => 'anotherField', 'type' => 'string', 'label' => 'Another field']];
     if ($withRelations) {
         $fields[] = ['name' => 'relField', 'relation_type' => 'ref-one', 'label' => 'Many to One field'];
     }
     $this->entityFieldMock->expects($this->once())->method('getFields')->willReturn($fields);
     $this->formConfigMock->expects($this->at(0))->method('getConfig')->with($entityName, 'oneField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'someField'), ['is_enabled' => false]));
     $this->formConfigMock->expects($this->at(1))->method('getConfig')->with($entityName, 'anotherField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'anotherField'), ['is_enabled' => true]));
     if ($withRelations) {
         $this->formConfigMock->expects($this->at(2))->method('getConfig')->with($entityName, 'relField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'relField'), ['is_enabled' => true]));
         $this->translatorMock->expects($this->at(0))->method('trans')->with('oro.entity.form.entity_fields')->willReturn('Fields');
         $this->translatorMock->expects($this->at(1))->method('trans')->with('oro.entity.form.entity_related')->willReturn('Relations');
     }
     $form = $this->factory->create($this->type, null, ['entity' => $entityName, 'with_relations' => $withRelations]);
     $view = $form->createView();
     $this->assertEquals('update_field_choice', $view->vars['full_name'], 'Failed asserting that field name is correct');
     $this->assertNotEmpty($view->vars['configs']['component']);
     $this->assertEquals('entity-field-choice', $view->vars['configs']['component']);
     $this->assertEquals('update_field_choice', $form->getConfig()->getType()->getName(), 'Failed asserting that correct underlying type was used');
     if ($withRelations) {
         $this->assertCount(2, $view->vars['choices'], 'Failed asserting that choices are grouped');
     } else {
         $this->assertCount(1, $view->vars['choices'], 'Failed asserting that choices exists');
         /** @var ChoiceView $choice */
         $choice = reset($view->vars['choices']);
         $this->assertEquals('Another field', $choice->label);
     }
 }
 /**
  * @dataProvider skuDataProvider
  * @param string[] $existingSku
  * @param array $testCases
  */
 public function testIncrementSku(array $existingSku, array $testCases)
 {
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with(self::PRODUCT_CLASS)->willReturn($this->getProductRepositoryMock($existingSku));
     foreach ($testCases as $expected => $sku) {
         $this->assertEquals($expected, $this->service->increment($sku));
     }
 }
Esempio n. 4
0
 protected function setUp()
 {
     $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->entityManager));
     $this->fieldHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Field\\FieldHelper')->disableOriginalConstructor()->getMock();
     $this->fixer = new EntityDetachFixer($this->doctrineHelper, $this->fieldHelper, PropertyAccess::createPropertyAccessor());
 }
Esempio n. 5
0
 /**
  * @param null|object $entity
  * @param bool        $attachmentConfigReturn
  * @param bool        $isNewRecord
  * @param bool        $isManaged
  * @param bool        $expected
  * @dataProvider configResultProvider
  */
 public function testIsAttachmentAssociationEnabled($entity, $attachmentConfigReturn, $isNewRecord, $isManaged, $expected)
 {
     $this->attachmentConfig->expects(is_object($entity) && !$isNewRecord ? $this->once() : $this->never())->method('isAttachmentAssociationEnabled')->with($entity)->willReturn($attachmentConfigReturn);
     $this->doctrineHelper->expects(is_object($entity) && $isManaged ? $this->once() : $this->never())->method('isNewEntity')->willReturn($isNewRecord);
     $this->doctrineHelper->expects(is_object($entity) ? $this->once() : $this->never())->method('isManageableEntity')->willReturn($isManaged);
     $actual = $this->filter->isAttachmentAssociationEnabled($entity);
     $this->assertEquals($expected, $actual);
 }
 /**
  * @param object $object
  * @param int $expected
  *
  * @dataProvider attributesDataProvider
  */
 public function testVote($object, $expected)
 {
     $this->doctrineHelper->expects($this->any())->method('getEntityClass')->with($object)->will($this->returnValue(get_class($object)));
     $this->voter->setClassName(get_class($object));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($object, false)->will($this->returnValue(1));
     /** @var \PHPUnit_Framework_MockObject_MockObject|TokenInterface $token */
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->assertEquals($expected, $this->voter->vote($token, $object, ['DELETE']));
 }
Esempio n. 7
0
 protected function setUp()
 {
     $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->entityManager));
     $this->detachFixer = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Writer\\EntityDetachFixer')->disableOriginalConstructor()->getMock();
     $this->contextRegistry = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry');
     $this->writer = new EntityWriter($this->doctrineHelper, $this->detachFixer, $this->contextRegistry);
 }
 /**
  * @dataProvider transformDataProvider
  *
  * @param mixed $expected
  * @param mixed $value
  */
 public function testReverseTransform($expected, $value)
 {
     if (!$expected) {
         $expected = new ArrayCollection();
     }
     $this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
         return $this->createDataObject(func_get_arg(1));
     }));
     $this->assertEquals($expected, $this->transformer->reverseTransform($value));
 }
 protected function setUp()
 {
     $this->formFactory = $this->getMockBuilder('Symfony\\Component\\Form\\FormFactory')->disableOriginalConstructor()->getMock();
     $this->aclManager = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Acl\\Persistence\\AclManager')->disableOriginalConstructor()->getMock();
     $this->privilegeRepository = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Acl\\Persistence\\AclPrivilegeRepository')->disableOriginalConstructor()->getMock();
     $this->chainMetadataProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\Metadata\\ChainMetadataProvider')->disableOriginalConstructor()->getMock();
     $this->ownershipConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $this->roleRepository = $this->getMockBuilder('\\OroB2B\\Bundle\\AccountBundle\\Entity\\Repository\\AccountUserRoleRepository')->disableOriginalConstructor()->getMock();
     $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
     $this->doctrineHelper = $this->getMockBuilder('\\Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->setConstructorArgs([$this->managerRegistry])->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->willReturn($this->roleRepository);
 }
Esempio n. 10
0
 /**
  * @dataProvider submitProvider
  *
  * @param $defaultData
  * @param $viewData
  * @param $submittedData
  * @param ArrayCollection $expected
  */
 public function testSubmit($defaultData, $viewData, $submittedData, ArrayCollection $expected)
 {
     $this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
         return $this->createDataObject(func_get_arg(1));
     }));
     $form = $this->factory->create($this->type, $defaultData, ['class' => '\\stdClass']);
     $this->assertEquals($viewData, $form->getViewData());
     $form->submit($submittedData);
     $this->assertTrue($form->isValid());
     $data = $form->getData();
     $this->assertEquals($expected, $data);
 }
 protected function setUp()
 {
     $this->product = new Product();
     $this->sourceProduct = new Product();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->productPriceRepository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock();
     $this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with($this->productPriceClass)->will($this->returnValue($this->productPriceRepository));
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->with($this->productPriceClass)->will($this->returnValue($this->objectManager));
     $this->listener = new ProductDuplicateListener();
     $this->listener->setProductPriceClass($this->productPriceClass);
     $this->listener->setDoctrineHelper($this->doctrineHelper);
 }
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->willReturnCallback(function ($message) {
         return $message . '_trans';
     });
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $accountGroupId = 1;
     $this->repository = $this->getMockBuilder('OroB2B\\Bundle\\PaymentBundle\\Entity\\Repository\\PaymentTermRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityReference')->with('OroB2BAccountBundle:AccountGroup', $accountGroupId)->willReturn(new AccountGroup());
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with(static::PAYMENT_TERM_CLASS)->willReturn($this->repository);
     $this->extension = new AccountGroupFormExtension($this->doctrineHelper, $this->translator, static::PAYMENT_TERM_CLASS);
 }
 /**
  * @param bool $isDefaultWebsiteRole
  * @param bool $hasUsers
  * @param int $expected
  *
  * @dataProvider attributesDataProvider
  */
 public function testVote($isDefaultWebsiteRole, $hasUsers, $expected)
 {
     $object = new AccountUserRole();
     $this->doctrineHelper->expects($this->any())->method('getEntityClass')->with($object)->will($this->returnValue(get_class($object)));
     $this->voter->setClassName(get_class($object));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($object, false)->will($this->returnValue(1));
     $entityRepository = $this->getMockBuilder('OroB2B\\Bundle\\CustomerBundle\\Entity\\Repository\\AccountUserRoleRepository')->disableOriginalConstructor()->getMock();
     $entityRepository->expects($this->at(0))->method('isDefaultForWebsite')->will($this->returnValue($isDefaultWebsiteRole));
     $entityRepository->expects($this->at(1))->method('hasAssignedUsers')->will($this->returnValue($hasUsers));
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with('OroB2BCustomerBundle:AccountUserRole')->will($this->returnValue($entityRepository));
     /** @var \PHPUnit_Framework_MockObject_MockObject|TokenInterface $token */
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->assertEquals($expected, $this->voter->vote($token, $object, ['DELETE']));
 }
 /**
  * @expectedException \RuntimeException
  *
  * @throws \Exception
  */
 public function testBatchUpdateException()
 {
     /** @var MassActionInterface|\PHPUnit_Framework_MockObject_MockObject $massActionMock */
     $massActionMock = $this->getMock(MassActionInterface::class);
     $entityName = 'Test\\Entity';
     $options = ActionConfiguration::create(['entityName' => $entityName]);
     $massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
     /** @var IterableResultInterface|\PHPUnit_Framework_MockObject_MockObject $massActionMock */
     $iteratorMock = $this->getIteratedResultMock();
     $data = ['mass_edit_field' => 'name', 'name' => 'something'];
     $this->doctrineHelperMock->expects($this->once())->method('getSingleEntityIdentifierFieldName')->with($entityName)->will($this->returnValue('id'));
     $this->doctrineHelperMock->expects($this->once())->method('getEntityManager')->with($entityName)->will($this->returnValue($this->getEntityManagerMock(false)));
     $this->actionRepo->batchUpdate($massActionMock, $iteratorMock, $data);
 }
 public function testPrepareContextTitleDataEvent()
 {
     $item = [];
     $item['title'] = 'title';
     $item['targetId'] = 1;
     $targetClass = Email::ENTITY_CLASS;
     $expectedItem = ['title' => 'new title', 'link' => 'link', 'targetId' => 1];
     $entity = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntity')->willReturn($entity);
     $this->router->expects($this->once())->method('generate')->willReturn('link');
     $entity->expects($this->once())->method('getSubject')->willReturn('new title');
     $event = new PrepareContextTitleEvent($item, $targetClass);
     $this->listener->prepareEmailContextTitleEvent($event);
     $this->assertEquals($expectedItem, $event->getItem());
 }
Esempio n. 16
0
 protected function setUp()
 {
     $this->noteAssociationHelper = $this->getMockBuilder('Oro\\Bundle\\NoteBundle\\Tools\\NoteAssociationHelper')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('isNewEntity')->willReturnCallback(function ($entity) {
         if (method_exists($entity, 'getId')) {
             return !(bool) $entity->getId();
         }
         throw new \RuntimeException('Something wrong');
     });
     $this->doctrineHelper->expects($this->any())->method('isManageableEntity')->willReturnCallback(function ($entity) {
         return !$entity instanceof \stdClass;
     });
     $this->filter = new PlaceholderFilter($this->noteAssociationHelper, $this->doctrineHelper);
 }
 /**
  * @param array $fieldsChanges
  * @param mixed $expected
  * @param bool  $doRemove
  *
  * @dataProvider getChangesDataProvider
  */
 public function testGetChanges($fieldsChanges, $expected, $doRemove)
 {
     if ($fieldsChanges) {
         $this->repo->expects($this->any())->method('findOneBy')->with($this->isType('array'))->will($this->returnValue($fieldsChanges));
     } else {
         $newFieldsChanges = new FieldsChanges([]);
         $newFieldsChanges->setEntityClass(self::CLASS_NAME)->setEntityId(1);
         $this->doctrineHelper->expects($this->once())->method('createEntityInstance')->will($this->returnValue($newFieldsChanges));
         $this->em->expects($this->once())->method('persist')->with($this->equalTo($newFieldsChanges));
     }
     if ($doRemove) {
         $this->em->expects($this->once())->method('remove')->with($this->equalTo($fieldsChanges));
     }
     $this->assertEquals($expected, $this->manager->getChanges(new \stdClass(), $doRemove));
 }
Esempio n. 18
0
 /**
  * @param bool $supports
  * @param bool $expected
  * @param mixed $entityIndex
  * @param mixed $providerValue
  * @param mixed $expectedIndex
  * @param \PHPUnit_Framework_MockObject_MockObject|Channel $channel
  * @param int $channelId
  * @param array $categories
  *
  * @dataProvider buildDataProvider
  */
 public function testBuild($supports, $expected, $entityIndex = null, $providerValue = null, $expectedIndex = null, $channel = null, $channelId = null, array $categories = null)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|RFMProviderInterface $provider */
     $provider = $this->getMock('OroCRM\\Bundle\\AnalyticsBundle\\Builder\\RFMProviderInterface');
     $provider->expects($this->any())->method('getType')->will($this->returnValue(RFMMetricCategory::TYPE_FREQUENCY));
     $provider->expects($this->any())->method('getValue')->will($this->returnValue($providerValue));
     $provider->expects($this->any())->method('supports')->will($this->returnValue($supports));
     $this->builder->addProvider($provider);
     /** @var \PHPUnit_Framework_MockObject_MockObject|RFMAwareInterface $entity */
     $entity = $this->getMock('OroCRM\\Bundle\\AnalyticsBundle\\Model\\RFMAwareInterface');
     $entity->expects($this->any())->method('getDataChannel')->will($this->returnValue($channel));
     if ($expected) {
         $entity->expects($this->exactly(2))->method('setFrequency')->with($this->equalTo($expectedIndex));
     }
     if ($entityIndex) {
         $entity->expects($this->exactly(2))->method('getFrequency')->will($this->returnValue($entityIndex));
     }
     if ($channel) {
         $this->doctrineHelper->expects($this->exactly(2))->method('getSingleEntityIdentifier')->with($this->equalTo($channel))->will($this->returnValue($channelId));
     }
     if ($channel && is_array($categories)) {
         /** @var \PHPUnit_Framework_MockObject_MockObject|EntityRepository $repo */
         $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
         $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->will($this->returnValue($repo));
         $repo->expects($this->once())->method('findBy')->will($this->returnValue($categories));
     }
     $this->assertEquals($expected, $this->builder->build($entity));
     /** check cache, getEntityRepository should not be called anymore */
     $this->assertEquals($expected, $this->builder->build($entity));
 }
 /**
  * @param int|null $priceListId
  * @param array $priceCurrencies
  * @param array $sourceResults
  * @param ProductPrice[] $prices
  * @param array $expectedResults
  * @dataProvider onResultAfterDataProvider
  */
 public function testOnResultAfter($priceListId = null, array $priceCurrencies = [], array $sourceResults = [], array $prices = [], array $expectedResults = [])
 {
     $priceRepository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with('OroB2BPricingBundle:ProductPrice')->willReturn($priceRepository);
     $sourceResultRecords = [];
     $productIds = [];
     foreach ($sourceResults as $sourceResult) {
         $sourceResultRecords[] = new ResultRecord($sourceResult);
         $productIds[] = $sourceResult['id'];
     }
     if ($priceListId && $priceCurrencies) {
         $this->priceListRequestHandler->expects($this->any())->method('getPriceList')->willReturn($this->getPriceList($priceListId));
         $this->priceListRequestHandler->expects($this->any())->method('getPriceListSelectedCurrencies')->will($this->returnCallback(function () use($priceCurrencies) {
             return array_intersect(['USD', 'EUR'], $priceCurrencies);
         }));
         $this->priceListRequestHandler->expects($this->any())->method('getShowTierPrices')->willReturn(true);
         $priceRepository->expects($this->any())->method('findByPriceListIdAndProductIds')->with($priceListId, $productIds)->willReturn($prices);
     }
     /** @var \PHPUnit_Framework_MockObject_MockObject|DatagridInterface $datagrid */
     $datagrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $event = new OrmResultAfter($datagrid, $sourceResultRecords);
     $this->listener->onResultAfter($event);
     $actualResults = $event->getRecords();
     $this->assertSameSize($expectedResults, $actualResults);
     foreach ($expectedResults as $key => $expectedResult) {
         $actualResult = $actualResults[$key];
         foreach ($expectedResult as $name => $value) {
             $this->assertEquals($value, $actualResult->getValue($name));
         }
     }
 }
Esempio n. 20
0
 /**
  * @param array $categories
  *
  * @dataProvider preSetDataProvider
  */
 public function testPreSetData(array $categories)
 {
     $channel = $this->getChannelMock(__NAMESPACE__ . '\\Stub\\RFMAwareStub');
     /** @var \PHPUnit_Framework_MockObject_MockObject|FormEvent $event */
     $event = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getData')->will($this->returnValue($channel));
     $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->will($this->returnValue($repository));
     $repository->expects($this->once())->method('findBy')->with($this->isType('array'))->will($this->returnValue($categories));
     $form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $event->expects($this->any())->method('getForm')->will($this->returnValue($form));
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->exactly(sizeof(RFMMetricCategory::$types)))->method('getEntityManager')->will($this->returnValue($em));
     $this->doctrineHelper->expects($this->exactly(sizeof(RFMMetricCategory::$types)))->method('getEntityMetadata')->will($this->returnValue($metadata));
     if ($categories) {
         $form->expects($this->exactly(4))->method('add')->withConsecutive([$this->equalTo('rfm_enabled'), $this->isType('string'), $this->isType('array')], [$this->equalTo('recency'), $this->equalTo('orocrm_analytics_rfm_category_settings'), $this->callback(function ($options) {
             $this->assertEquals($this->getCollection([$this->getCategory(RFMMetricCategory::TYPE_RECENCY)]), $options['data']);
             return true;
         })], [$this->equalTo('frequency'), $this->equalTo('orocrm_analytics_rfm_category_settings'), $this->callback(function ($options) {
             $this->assertEquals($this->getCollection([1 => $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY)]), $options['data']);
             return true;
         })], [$this->equalTo('monetary'), $this->equalTo('orocrm_analytics_rfm_category_settings'), $this->callback(function ($options) {
             $this->assertEquals($this->getCollection([]), $options['data']);
             return true;
         })]);
     }
     $this->extension->loadCategories($event);
 }
Esempio n. 21
0
 public function testSaveHandlerRouteCallback()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|Form $form */
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $entity = $this->getObject();
     $handler = $this->getMockBuilder('Oro\\Bundle\\FormBundle\\Tests\\Unit\\Form\\Stub\\HandlerStub')->getMock();
     $handler->expects($this->once())->method('process')->with($entity)->will($this->returnValue(true));
     $this->doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue(1));
     $saveAndStayRoute = ['route' => 'test_update'];
     $saveAndCloseRoute = ['route' => 'test_view'];
     $saveAndStayCallback = function () use($saveAndStayRoute) {
         return $saveAndStayRoute;
     };
     $saveAndCloseCallback = function () use($saveAndCloseRoute) {
         return $saveAndCloseRoute;
     };
     $called = false;
     $expectedForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $resultCallback = function () use(&$called, $expectedForm) {
         $called = true;
         return ['form' => $expectedForm, 'test' => 1];
     };
     $expected = $this->assertSaveData($form, $entity);
     $expected['savedId'] = 1;
     $expected['test'] = 1;
     $expected['form'] = $expectedForm;
     $result = $this->handler->handleUpdate($entity, $form, $saveAndStayCallback, $saveAndCloseCallback, 'Saved', $handler, $resultCallback);
     $this->assertTrue($called);
     $this->assertEquals($expected, $result);
 }
Esempio n. 22
0
 /**
  * @param bool $expected
  * @param array $channels
  * @param bool $checkExtension
  *
  * @dataProvider channelsDataProvider
  */
 public function testHasOrganizationApplicableChannels($expected, array $channels, $checkExtension = true)
 {
     $repository = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->any())->method('findBy')->with($this->arrayHasKey('organization'))->willReturn($channels);
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->will($this->returnValue($repository));
     $this->assertEquals($expected, $this->provider->hasOrganizationApplicableChannels(new Organization(), $checkExtension));
 }
 /**
  * @param object $entity
  */
 protected function assertReloadEntityCall($entity)
 {
     $class = get_class($entity);
     $id = 1;
     $this->doctrineHelper->expects($this->once())->method('getEntityClass')->with($entity)->will($this->returnValue($class));
     $this->doctrineHelper->expects($this->once())->method('getEntityIdentifier')->will($this->returnValue($id));
     $this->doctrineHelper->expects($this->once())->method('getEntity')->with($class, $id)->will($this->returnValue($entity));
 }
 /**
  * @param string     $entityName
  * @param bool       $isEntity
  * @param bool       $isException
  * @param bool       $isAlreadyConfigured
  * @param bool       $isActionEnabled
  * @param array|null $expected
  *
  * @dataProvider onBuildBeforeProvider
  */
 public function testOnBuildBefore($entityName, $isEntity, $isException, $isAlreadyConfigured, $isActionEnabled, $expected = null)
 {
     $datagrid = $this->getDatagrid($entityName, $isAlreadyConfigured);
     // prepare mocks
     if ($isException) {
         $this->classResolverMock->expects($this->once())->method('isEntity')->with($entityName)->will($this->throwException(new \ReflectionException("Not valid class")));
     } else {
         $this->classResolverMock->expects($this->once())->method('isEntity')->with($entityName)->will($this->returnValue($isEntity));
         if ($isEntity && !$isAlreadyConfigured && $isActionEnabled) {
             $this->doctrineHelperMock->expects($this->once())->method('getSingleEntityIdentifierFieldName')->will($this->returnValue('id'));
         }
         $isEmptyAndEnabled = !$isAlreadyConfigured && $isEntity;
         $this->handlerMock->expects($isEmptyAndEnabled ? $this->once() : $this->never())->method('isMassActionEnabled')->with($entityName)->will($this->returnValue($isActionEnabled));
     }
     $event = new BuildBefore($datagrid, $datagrid->getConfig());
     $this->listener->onBuildBefore($event);
     $this->assertEquals($expected, $event->getConfig()->offsetGetByPath(sprintf(GridListener::ACTION_CONFIGURATION_KEY, MassUpdateActionHandler::ACTION_NAME)), 'Failed asserting that mass action config added by listener');
 }
 /**
  * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function testUserEmptyUser()
 {
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->once())->method('getUser')->willReturn(null);
     $this->tokenStorage->expects($this->once())->method('getToken')->willReturn($token);
     $repo = $this->getMockBuilder('Oro\\Bundle\\WindowsBundle\\Entity\\Repository\\WindowsStateRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->willReturn($repo);
     $this->manager->getWindowsState(42);
 }
 public function testPrepareIdsForEmailThreadWithThreadsEvent()
 {
     $targetClass = Email::ENTITY_CLASS;
     $targetId = 1;
     $expectedResult = [2, 3];
     $email = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
     $thread = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailThread')->disableOriginalConstructor()->getMock();
     $email1 = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
     $email2 = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntity')->willReturn($email);
     $email->expects($this->exactly(2))->method('getThread')->willReturn($thread);
     $email1->expects($this->once())->method('getId')->willReturn(2);
     $email2->expects($this->once())->method('getId')->willReturn(3);
     $thread->expects($this->once())->method('getEmails')->willReturn(new ArrayCollection([$email1, $email2]));
     $event = new ActivityListPreQueryBuildEvent($targetClass, $targetId);
     $this->listener->prepareIdsForEmailThreadEvent($event);
     $this->assertEquals($expectedResult, $event->getTargetIds());
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->eventDispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->disableOriginalConstructor()->getMock();
     $this->skuIncrementor = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Duplicator\\SkuIncrementorInterface')->disableOriginalConstructor()->getMock();
     $this->attachmentManager = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Manager\\AttachmentManager')->disableOriginalConstructor()->getMock();
     $this->attachmentProvider = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Provider\\AttachmentProvider')->disableOriginalConstructor()->getMock();
     $this->productStatusRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->productStatusDisabled = $this->getMockBuilder('Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with(ExtendHelper::buildEnumValueClassName('prod_status'))->will($this->returnValue($this->productStatusRepository));
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->with($this->anything())->will($this->returnValue($this->objectManager));
     $this->objectManager->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->productStatusRepository->expects($this->once())->method('find')->with(Product::STATUS_DISABLED)->will($this->returnValue($this->productStatusDisabled));
     $this->duplicator = new ProductDuplicator($this->doctrineHelper, $this->eventDispatcher, $this->attachmentManager, $this->attachmentProvider);
     $this->duplicator->setSkuIncrementor($this->skuIncrementor);
 }
Esempio n. 28
0
 public function setUp()
 {
     $this->activityListProvider = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Provider\\ActivityListChainProvider')->disableOriginalConstructor()->getMock();
     $this->doctrine = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $this->activityListProvider->expects($this->any())->method('getTargetEntityClasses')->will($this->returnValue(['Oro\\Bundle\\ActivityListBundle\\Tests\\Unit\\Placeholder\\Fixture\\TestTarget']));
     $this->doctrineHelper = $this->getMockBuilder('\\Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->setMethods(['isNewEntity', 'isManageableEntity'])->setConstructorArgs([$this->doctrine])->getMock();
     $this->doctrineHelper->expects($this->any())->method('isNewEntity')->will($this->returnCallback(function ($entity) {
         if (method_exists($entity, 'getId')) {
             return !(bool) $entity->getId();
         }
         throw new \RuntimeException('Something wrong');
     }));
     $this->doctrineHelper->expects($this->any())->method('isManageableEntity')->willReturnCallback(function ($entity) {
         return !$entity instanceof TestNonManagedTarget;
     });
     $this->configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $this->filter = new PlaceholderFilter($this->activityListProvider, $this->doctrine, $this->doctrineHelper, $this->configManager);
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage ContainerInterface not injected
  */
 public function testWithoutContainer()
 {
     $voter = new AccountVoter($this->doctrineHelper);
     $accountUser = $this->getAccountUser(1);
     $object = $this->getObject(1);
     $this->doctrineHelper->expects($this->any())->method('getEntityClass')->with($object)->willReturn(get_class($object));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($object, false)->willReturn(1);
     $voter->setClassName(get_class($object));
     /* @var $token TokenInterface|\PHPUnit_Framework_MockObject_MockObject */
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->willReturn($accountUser);
     $voter->vote($token, $object, [AccountVoter::ATTRIBUTE_VIEW]);
 }
Esempio n. 30
0
 /**
  * @param array $column
  * @param array $expected
  * @param bool $invokes
  *
  * @dataProvider setParametersDataProvider
  */
 public function testRelationGuess($column, $expected, $invokes)
 {
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->will($this->returnValue($em));
     $em->expects($this->any())->method('getClassMetadata')->willReturn($metadata);
     if ($invokes) {
         $metadata->expects($this->any())->method('hasAssociation')->willReturn(true);
         $metadata->expects($this->once())->method('getAssociationMapping')->willReturn(['type' => 8]);
         $metadata->expects($this->once())->method('getSingleIdentifierFieldName')->willReturn('key');
         $metadata->expects($this->once())->method('getFieldNames')->willReturn(['test']);
         $metadata->expects($this->once())->method('getTypeOfField')->willReturn('string');
         $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->setMethods(['getResult'])->disableOriginalConstructor()->getMock();
         $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
         $this->aclHelper->expects($this->any())->method('apply')->willReturn($qb);
         $em->expects($this->any())->method('getRepository')->willReturn($repo);
         $repo->expects($this->any())->method('createQueryBuilder')->willReturn($qb);
         $qb->expects($this->once())->method('getResult')->willReturn([['key' => 'a1', 'test' => 'A1'], ['key' => 'a2', 'test' => 'A2']]);
     }
     $guessed = $this->guesser->guessColumnOptions('test', 'test', $column);
     $this->assertEquals($expected, $guessed);
 }