Exemplo n.º 1
0
 public function setUp()
 {
     $this->entityManagerMock = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->eventDispatcherMock = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->columnFactoryMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\ColumnFactoryInterface');
     $columnTypeIdMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface');
     $columnTypeNameMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface');
     $columnTypeTestMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface');
     $that = $this;
     $this->columnFactoryMock->expects($this->any())->method('create')->with($this->logicalOr($this->equalTo('id'), $this->equalTo('name'), $this->equalTo('test')))->will($this->returnCallback(function ($name, $type, $options) use($that, $columnTypeIdMock, $columnTypeNameMock, $columnTypeTestMock) {
         $options['name'] = $name;
         switch ($name) {
             case 'id':
                 return new ColumnBuilder($columnTypeIdMock, $that->getResolvedOptions(array_merge($options, array('params' => array('id'), 'allow_sort' => false))));
             case 'name':
                 return new ColumnBuilder($columnTypeNameMock, $that->getResolvedOptions(array_merge($options, array('params' => array('name'), 'allow_sort' => array('name', 'id'), 'allow_filter' => true))));
             default:
                 return new ColumnBuilder($columnTypeTestMock, $that->getResolvedOptions(array_merge($options, array('params' => array('w' => 'x'), 'allow_sort' => array('y'), 'allow_filter' => array('z')))));
         }
     }));
     $this->queryResult = new QueryResult(self::$rows, count(self::$rows));
     $this->dataProvider = $this->getMock('EMC\\TableBundle\\Provider\\DataProviderInterface');
     $this->dataProvider->expects($this->any())->method('find')->will($this->returnValue($this->queryResult));
     $options = array('data_provider' => $this->dataProvider);
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $this->fooType = new Type\FooType($queryBuilder);
     $optionsResolver = new OptionsResolver();
     $this->fooType->setDefaultOptions($optionsResolver, $this->defaultOptions);
     $this->resolvedOptions = $optionsResolver->resolve($options);
     $this->resolvedOptions['_tid'] = 'test';
     $this->resolvedOptions['_passed_options'] = array();
     $this->resolvedOptions['_query'] = array('page' => 1, 'sort' => 0, 'limit' => 10, 'filter' => null);
     $this->builder = new TableBuilder($this->entityManagerMock, $this->eventDispatcherMock, $this->columnFactoryMock, $this->fooType, $this->defaultColumnOptions, null, $this->resolvedOptions);
 }
Exemplo n.º 2
0
 public function setDefaultOptions(OptionsResolverInterface $resolver, array $defaultOptions)
 {
     return $this->type->setDefaultOptions($resolver, $defaultOptions);
 }
Exemplo n.º 3
0
 /**
  * Resolve table type options
  * @param \EMC\TableBundle\Table\Type\TableTypeInterface $type
  * @param array $data
  * @param array $options
  * @param array $params
  * @return array
  */
 private function resolveOptions(TableTypeInterface $type, array $data = null, array $options = array(), array $params = array())
 {
     if (null !== $data && !array_key_exists('data', $options)) {
         $options['data'] = $data;
     }
     $_options = $options;
     if (count($params) > 0) {
         $options['params'] = $params;
     }
     $resolver = $type->getOptionsResolver();
     $type->setDefaultOptions($resolver, $this->defaultOptions);
     $options = $resolver->resolve($options);
     $availableExport = array();
     foreach ($options['export'] as $export) {
         $availableExport[$export] = $this->exportRegistry->get($export);
     }
     unset($options['export']);
     $options['export'] = $availableExport;
     $options['_tid'] = $this->generateTableId($type, $_options);
     $options['_passed_options'] = $_options;
     $options['_query'] = array('page' => 1, 'sort' => $options['default_sorts'], 'limit' => $options['limit'], 'filter' => null);
     return $options;
 }