public function testConfigure()
 {
     $this->serviceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
     $resource->expects($this->once())->method('getInterfaces')->will($this->returnValue([$interface = 'interface']));
     $resource->expects($this->once())->method('getModel')->will($this->returnValue($model = 'model'));
     $subscriber = $this->createResolveTargetSubscriberMock();
     $subscriber->expects($this->once())->method('addResolveTarget')->with($this->identicalTo($interface), $this->identicalTo($model));
     $this->configurator->configure($subscriber);
 }
Example #2
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'], 'filter' => $this->createFilterMock(), 'resource' => $resourceName];
     $this->assertSame(array_merge($options, ['resource' => $resource]), $resolver->resolve($options));
 }
Example #3
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));
 }
Example #4
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());
 }
 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);
 }
Example #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('getTranslation')->will($this->returnValue($translation = $this->createResourceMock()));
     $translation->expects($this->once())->method('getModel')->will($this->returnValue($model = 'model'));
     $translatable->expects($this->once())->method('setTranslationClass')->with($this->identicalTo($model));
     $this->translatableResourceSubscriber->postLoad($event);
 }
Example #8
0
 public function testRender()
 {
     $grid = $this->createGridViewMock();
     $column = $this->createColumnMock();
     $data = 'data';
     $column->expects($this->once())->method('getType')->will($this->returnValue($type = 'type'));
     $column->expects($this->once())->method('getOptions')->will($this->returnValue($options = ['baz' => 'bat']));
     $this->columnRegistry->expects($this->exactly(2))->method('offsetGet')->will($this->returnValueMap([[$type, $columnType = $this->createColumnTypeMock()], [$parentType = 'parent_type', $parentColumnType = $this->createColumnTypeMock()]]));
     $columnType->expects($this->once())->method('getParent')->will($this->returnValue($parentType));
     $parentColumnType->expects($this->once())->method('getParent')->will($this->returnValue(null));
     $columnType->expects($this->once())->method('configureOptions')->with($this->callback(function (OptionsResolver $resolver) use($options) {
         $resolver->setDefined(array_merge(['column', 'grid'], array_keys($options)));
         return true;
     }));
     $parentColumnType->expects($this->once())->method('configureOptions')->with($this->isInstanceOf(OptionsResolver::class));
     $columnType->expects($this->once())->method('render')->with($this->identicalTo($data), $this->identicalTo(array_merge(['column' => $column, 'grid' => $grid], $options)))->will($this->returnValue($result = 'result'));
     $this->assertSame($result, $this->renderer->render($grid, $column, $data));
 }
Example #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);
 }
Example #10
0
 public function testSort()
 {
     $builder = $this->createDataSourceBuilderMock();
     $grid = $this->createGridMock();
     $data = [$sortName = 'foo' => $sortSort = 'ASC', $undefinedSort = 'bar' => 'DESC'];
     $grid->expects($this->exactly(2))->method('hasSort')->will($this->returnValueMap([[$sortName, true], [$undefinedSort, false]]));
     $grid->expects($this->once())->method('getSort')->with($this->identicalTo($sortName))->will($this->returnValue($sort = $this->createSortMock()));
     $sort->expects($this->once())->method('getType')->will($this->returnValue($type = 'type'));
     $sort->expects($this->once())->method('getOptions')->will($this->returnValue($options = ['baz' => 'bat']));
     $this->sortRegistry->expects($this->exactly(2))->method('offsetGet')->will($this->returnValueMap([[$type, $sortType = $this->createSortTypeMock()], [$parentType = 'parent_type', $parentSortType = $this->createSortTypeMock()]]));
     $sortType->expects($this->once())->method('getParent')->will($this->returnValue($parentType));
     $parentSortType->expects($this->once())->method('getParent')->will($this->returnValue(null));
     $sortType->expects($this->once())->method('configureOptions')->with($this->callback(function (OptionsResolver $resolver) use($options) {
         $resolver->setDefined(array_merge(['builder', 'sort', 'grid'], array_keys($options)));
         return true;
     }));
     $parentSortType->expects($this->once())->method('configureOptions')->with($this->isInstanceOf(OptionsResolver::class));
     $sortType->expects($this->once())->method('sort')->with($this->identicalTo($sortSort), $this->identicalTo(array_merge(['builder' => $builder, 'grid' => $grid, 'sort' => $sort], $options)))->will($this->returnValue($result = 'result'));
     $this->sorter->sort($builder, $grid, $data);
 }
 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('getManagerForClass');
     $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));
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $this->load();
     return $this->registry->getIterator();
 }
Example #14
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]));
 }
Example #15
0
 public function testBatchWithoutArray()
 {
     $this->domainManagerRegistry->expects($this->never())->method('offsetGet');
     $this->type->batch('data', []);
 }