示例#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);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function store(TableTypeInterface $type, array $data = null, array $options = array())
 {
     if (!isset($options['_tid']) || !isset($options['_passed_options'])) {
         throw new \RuntimeException();
     }
     $tables = $this->session->get('tables');
     $tid = $options['_tid'];
     $options = $options['_passed_options'];
     $ressolvedType = null;
     if ($type instanceof TableDecoratorInterface) {
         $ressolvedType = $type->getType();
     } else {
         $ressolvedType = $type;
     }
     $tables[$tid] = array('class' => get_class($ressolvedType), 'data' => $data, 'options' => $options);
     $this->session->set('tables', $tables);
 }
 public function setUp()
 {
     $this->decoratorMock = $this->getMock('EMC\\TableBundle\\Table\\Type\\Decorator\\TableDecoratorInterface');
     $this->tableTypeMock = $this->getMock('EMC\\TableBundle\\Table\\Type\\TableTypeInterface');
     $this->columnTypeMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface');
     $this->columnMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\ColumnInterface');
     $this->columnMock->expects($this->any())->method('getType')->will($this->returnValue($this->columnTypeMock));
     $expectedView = array('a' => 1, 'b' => '2');
     $this->expectedView = $expectedView;
     $this->tableTypeMock->expects($this->any())->method('buildHeaderCellView')->willReturnCallback(function (&$view, $column) use($expectedView) {
         $view = $expectedView;
     });
     $this->tableTypeMock->expects($this->any())->method('buildBodyCellView')->willReturnCallback(function (&$view, $column) use($expectedView) {
         $view = $expectedView;
     });
     $this->tableMock = $this->getMock('EMC\\TableBundle\\Table\\TableInterface');
     $this->tableMock->method('getType')->will($this->returnValue($this->tableTypeMock));
     $this->queryConfig = new QueryConfig();
     $this->queryConfig->setLimit(5)->setSelect(array('t.a', 't.b', 't.c'))->setPage(2)->setOrderBy(array('t.d' => true, 't.e' => false))->addParameter('query', '%xxx%')->getConstraints()->add('LOWER(t.a) LIKE :query')->add('LOWER(t.c) LIKE :query');
 }
示例#4
0
 public function getQueryResult(TableInterface $table)
 {
     if (is_array($this->data)) {
         return new QueryResult($this->data, 0);
     } else {
         $queryBuilder = $this->type->getQueryBuilder($this->entityManager, $this->options['params']);
         /* @var $dataProvider \EMC\TableBundle\Provider\DataProviderInterface */
         $dataProvider = $this->options['data_provider'];
         $queryConfig = $this->getQueryConfig($table);
         if (!$queryConfig->isValid()) {
             return null;
         }
         return $dataProvider->find($queryBuilder, $queryConfig);
     }
     return null;
 }
示例#5
0
 public function resolveParams(array $params, array $data, $preserveKeys = false, $default = array())
 {
     return $this->type->resolveParams($params, $data, $preserveKeys, $default);
 }
示例#6
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;
 }
示例#7
0
文件: Table.php 项目: cwd/TableBundle
 /**
  * {@inheritdoc}
  */
 public function getView()
 {
     $view = new TableView();
     $this->type->buildView($view, $this);
     return $view;
 }
示例#8
0
 public function testRestore()
 {
     $builder = $this->factory->restore($this->fooType->getId());
     $expected = $this->factory->create(new Type\FooType());
     $this->assertEquals($expected, $builder);
 }