Exemplo n.º 1
0
 public function testConfigureOptionsWithResourceInstance()
 {
     $this->type->configureOptions($resolver = new OptionsResolver());
     $this->resourceRegistry->expects($this->never())->method('offsetGet');
     $resource = $this->createResourceMock();
     $resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($resourcePath = 'resource_path'));
     $this->assertSame(['path' => $path = 'path_value', 'options' => [], 'resource' => $resource, 'resource_path' => $resourcePath, 'type' => $type = 'resource_type'], $resolver->resolve(['path' => $path, 'resource' => $resource, 'type' => $type]));
 }
 public function testConfigureWithoutDriver()
 {
     $this->serviceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
     $resource->expects($this->once())->method('getDriver')->will($this->returnValue(null));
     $subscriber = $this->createResolveTargetSubscriberMock();
     $subscriber->expects($this->never())->method('addResolveTarget');
     $this->configurator->configure($subscriber);
 }
Exemplo n.º 3
0
 public function testConfigureOptionsWithStringResource()
 {
     $resolver = new OptionsResolver();
     $resolver->setDefined('filter');
     $this->resourceRegistry->expects($this->once())->method('offsetGet')->with($this->identicalTo($resourceName = 'resource_name'))->will($this->returnValue($resource = $this->createResourceMock()));
     $this->type->configureOptions($resolver);
     $options = ['builder_condition' => AbstractType::CONDITION_AND, 'fields_condition' => AbstractType::CONDITION_OR, 'fields' => ['field'], 'path' => null, 'filter' => $this->createFilterMock(), 'resource' => $resourceName];
     $this->assertSame(array_merge($options, ['resource' => $resource]), $resolver->resolve($options));
 }
Exemplo n.º 4
0
 public function testResourceRepository()
 {
     $entityManager = $this->createEntityManagerMock();
     $entityManager->expects($this->exactly(3))->method('getClassMetadata')->with($this->identicalTo($entityName = 'entity'))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
     $classMetadata->expects($this->exactly(3))->method('getName')->will($this->returnValue($entityName));
     $this->resourceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
     $resource->expects($this->once())->method('getModel')->will($this->returnValue($entityName));
     $classMetadata->customRepositoryClassName = $repositoryClass = Repository::class;
     $this->assertInstanceOf($repositoryClass, $repository = $this->repositoryFactory->getRepository($entityManager, $entityName));
     $this->assertSame($repository, $this->repositoryFactory->getRepository($entityManager, $entityName));
 }
Exemplo n.º 5
0
 public function testBuild()
 {
     $this->filterFormRegistry->expects($this->once())->method('offsetGet')->with($this->identicalTo($type = 'my.type'))->will($this->returnValue($formType = $this->createFormTypeMock()));
     $filter = $this->builder->build(['name' => $name = 'my.name', 'type' => $type]);
     $this->assertSame($name, $filter->getName());
     $this->assertSame($name, $filter->getLabel());
     $this->assertSame($type, $filter->getType());
     $this->assertSame(get_class($formType), $filter->getForm());
     $this->assertFalse($filter->hasFormOptions());
     $this->assertFalse($filter->hasOptions());
 }
Exemplo n.º 6
0
 public function testHandle()
 {
     $grid = $this->createGridMock();
     $grid->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock()));
     $grid->expects($this->once())->method('getOptions')->will($this->returnValue($options = ['foo' => 'bar']));
     $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $this->repositoryRegistry->expects($this->once())->method('offsetGet')->with($this->identicalTo($name))->will($this->returnValue($repository = $this->createRepositoryMock()));
     $repository->expects($this->once())->method('createDataSourceBuilder')->with($this->identicalTo($options))->will($this->returnValue($builder = $this->createDataSourceBuilderMock()));
     $this->filterer->expects($this->once())->method('filter')->with($this->identicalTo($builder), $this->identicalTo($grid), $this->identicalTo($filters = ['filter']));
     $this->sorter->expects($this->once())->method('sort')->with($this->identicalTo($builder), $this->identicalTo($grid), $this->identicalTo($sorting = ['sort']));
     $this->slicer->expects($this->once())->method('slice')->with($this->identicalTo($builder), $this->identicalTo($grid), $this->identicalTo($slicing = ['slice']));
     $this->gridViewFactory->expects($this->once())->method('create')->with($this->identicalTo($grid), $this->identicalTo($builder))->will($this->returnValue($view = $this->createGridViewMock()));
     $this->assertSame($view, $this->handler->handle($grid, $filters, $sorting, $slicing));
 }
 public function testPostLoadWithTranslatable()
 {
     $event = $this->createLifecycleEventArgsMock();
     $event->expects($this->once())->method('getEntity')->will($this->returnValue($translatable = $this->createTranslatableMock()));
     $this->localeContext->expects($this->once())->method('getLocales')->will($this->returnValue($locales = ['fr']));
     $translatable->expects($this->once())->method('setLocales')->with($this->identicalTo($locales));
     $this->localeContext->expects($this->once())->method('getFallbackLocale')->will($this->returnValue($fallbackLocale = 'en'));
     $translatable->expects($this->once())->method('setFallbackLocale')->with($this->identicalTo($fallbackLocale));
     $this->resourceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
     $resource->expects($this->once())->method('getModel')->will($this->returnValue(get_class($translatable)));
     $resource->expects($this->once())->method('getRelation')->with($this->identicalTo('translation'))->will($this->returnValue($translation = $this->createResourceMock()));
     $translation->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $this->factoryRegistry->expects($this->once())->method('offsetGet')->with($this->identicalTo($name))->will($this->returnValue($translationFactory = $this->createFactoryMock()));
     $translatable->expects($this->once())->method('setTranslationFactory')->with($this->identicalTo($translationFactory));
     $this->translatableResourceSubscriber->postLoad($event);
 }
Exemplo n.º 8
0
 public function testRender()
 {
     $grid = $this->createGridViewMock();
     $action = $this->createActionMock();
     $data = 'data';
     $action->expects($this->once())->method('getType')->will($this->returnValue($type = 'type'));
     $action->expects($this->once())->method('getOptions')->will($this->returnValue($options = ['baz' => 'bat']));
     $this->actionRegistry->expects($this->exactly(2))->method('offsetGet')->will($this->returnValueMap([[$type, $actionType = $this->createActionTypeMock()], [$parentType = 'parent_type', $parentActionType = $this->createActionTypeMock()]]));
     $actionType->expects($this->once())->method('getParent')->will($this->returnValue($parentType));
     $parentActionType->expects($this->once())->method('getParent')->will($this->returnValue(null));
     $actionType->expects($this->once())->method('configureOptions')->with($this->callback(function (OptionsResolver $resolver) use($options) {
         $resolver->setDefined(array_merge(['action', 'grid'], array_keys($options)));
         return true;
     }));
     $parentActionType->expects($this->once())->method('configureOptions')->with($this->isInstanceOf(OptionsResolver::class));
     $actionType->expects($this->once())->method('render')->with($this->identicalTo($data), $this->identicalTo(array_merge(['action' => $action, 'grid' => $grid], $options)))->will($this->returnValue($result = 'result'));
     $this->assertSame($result, $this->renderer->render($grid, $action, $data));
 }
Exemplo n.º 9
0
 public function testBatch()
 {
     $grid = $this->createGridMock();
     $batch = 'delete';
     $data = ['data'];
     $grid->expects($this->once())->method('getBatch')->with($this->identicalTo($batch))->will($this->returnValue($gridBatch = $this->createBatchMock()));
     $gridBatch->expects($this->once())->method('getType')->will($this->returnValue($type = 'type'));
     $gridBatch->expects($this->once())->method('getOptions')->will($this->returnValue($options = ['foo' => 'bar']));
     $this->batchRegistry->expects($this->exactly(2))->method('offsetGet')->will($this->returnValueMap([[$type, $batchType = $this->createBatchTypeMock()], [$parentType = 'parent_type', $parentBatchType = $this->createBatchTypeMock()]]));
     $batchType->expects($this->once())->method('getParent')->will($this->returnValue($parentType));
     $parentBatchType->expects($this->once())->method('getParent')->will($this->returnValue(null));
     $batchType->expects($this->once())->method('configureOptions')->with($this->callback(function (OptionsResolver $resolver) use($options) {
         $resolver->setDefined(array_merge(['batch', 'grid'], array_keys($options)));
         return true;
     }));
     $parentBatchType->expects($this->once())->method('configureOptions')->with($this->isInstanceOf(OptionsResolver::class));
     $batchType->expects($this->once())->method('batch')->with($this->identicalTo($data), $this->identicalTo(array_merge(['batch' => $gridBatch, 'grid' => $grid], $options)));
     $this->batcher->batch($grid, $batch, $data);
 }
Exemplo n.º 10
0
 public function testFilter()
 {
     $builder = $this->createDataSourceBuilderMock();
     $grid = $this->createGridMock();
     $data = [$filterName = 'foo' => $filterSort = 'ASC', $undefinedFilter = 'bar' => 'DESC'];
     $grid->expects($this->exactly(2))->method('hasFilter')->will($this->returnValueMap([[$filterName, true], [$undefinedFilter, false]]));
     $grid->expects($this->once())->method('getFilter')->with($this->identicalTo($filterName))->will($this->returnValue($filter = $this->createFilterMock()));
     $filter->expects($this->once())->method('getType')->will($this->returnValue($type = 'type'));
     $filter->expects($this->once())->method('getOptions')->will($this->returnValue($options = ['baz' => 'bat']));
     $this->filterRegistry->expects($this->exactly(2))->method('offsetGet')->will($this->returnValueMap([[$type, $filterType = $this->createFilterTypeMock()], [$parentType = 'parent_type', $parentFilterType = $this->createFilterTypeMock()]]));
     $filterType->expects($this->once())->method('getParent')->will($this->returnValue($parentType));
     $parentFilterType->expects($this->once())->method('getParent')->will($this->returnValue(null));
     $filterType->expects($this->once())->method('configureOptions')->with($this->callback(function (OptionsResolver $resolver) use($options) {
         $resolver->setDefined(array_merge(['builder', 'filter', 'grid'], array_keys($options)));
         return true;
     }));
     $parentFilterType->expects($this->once())->method('configureOptions')->with($this->isInstanceOf(OptionsResolver::class));
     $filterType->expects($this->once())->method('filter')->with($this->identicalTo($filterSort), $this->identicalTo(array_merge(['filter' => $filter, 'grid' => $grid, 'builder' => $builder], $options)))->will($this->returnValue($result = 'result'));
     $this->filterer->filter($builder, $grid, $data);
 }
Exemplo n.º 11
0
 public function testLoadClassMetadataWithoutResource()
 {
     $event = $this->createLoadClassMetadataEventArgsMock();
     $event->expects($this->once())->method('getClassMetadata')->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
     $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($model = 'model'));
     $this->serviceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([])));
     $classMetadata->expects($this->never())->method('setCustomRepositoryClass');
     $classMetadata->isMappedSuperclass = true;
     $this->resourceSubscriber->loadClassMetadata($event);
     $this->assertTrue($classMetadata->isMappedSuperclass);
 }
Exemplo n.º 12
0
 public function testEventWithInvalidForm()
 {
     $initEvent = $this->createFormEventMock();
     $initEvent->expects($this->once())->method('getData')->will($this->returnValue($initCollection = $this->createCollectionMock()));
     $manageEvent = $this->createFormEventMock();
     $manageEvent->expects($this->once())->method('getForm')->will($this->returnValue($form = $this->createFormMock()));
     $form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->managerRegistry->expects($this->never())->method('offsetGet');
     $this->subscriber->init($initEvent);
     $this->subscriber->manage($manageEvent);
 }
 public function testTranslatableRepository()
 {
     $documentManager = $this->createDocumentManagerMock();
     $documentManager->expects($this->once())->method('getClassMetadata')->with($this->identicalTo($documentName = 'document'))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
     $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($documentName));
     $this->resourceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
     $resource->expects($this->once())->method('getModel')->will($this->returnValue($documentName));
     $documentManager->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->createUnitOfWorkMock()));
     $classMetadata->customRepositoryClassName = $repositoryClass = TranslatableRepository::class;
     $this->assertInstanceOf($repositoryClass, $repository = $this->repositoryFactory->getRepository($documentManager, $documentName));
     $this->assertSame($repository, $this->repositoryFactory->getRepository($documentManager, $documentName));
 }
Exemplo n.º 14
0
 public function testBatchWithoutArray()
 {
     $this->domainManagerRegistry->expects($this->never())->method('offsetGet');
     $this->type->batch('data', []);
 }
Exemplo n.º 15
0
 public function testConfigureOptionsWithStringResource()
 {
     $this->type->configureOptions($resolver = new OptionsResolver());
     $this->resourceRegistry->expects($this->once())->method('offsetGet')->with($this->identicalTo($name = 'name'))->will($this->returnValue($resource = $this->createResourceMock()));
     $this->assertSame(['field' => $field = 'field', 'resource' => $resource], $resolver->resolve(['field' => $field, 'resource' => $name]));
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $this->load();
     return $this->registry->getIterator();
 }