/**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testVisitDatasource()
 {
     $qb = new QueryBuilder($this->getTestEntityManager());
     $qb->select(['user.id', 'user.name as user_name', 'user.status as user_status'])->from('Oro\\Bundle\\QueryDesignerBundle\\Tests\\Unit\\Fixtures\\Models\\CMS\\CmsUser', 'user')->join('user.address', 'address');
     $manager = $this->getMockBuilder('Oro\\Bundle\\QueryDesignerBundle\\QueryDesigner\\Manager')->disableOriginalConstructor()->getMock();
     $manager->expects($this->any())->method('createFilter')->will($this->returnCallback(function ($name, $params) {
         return $this->createFilter($name, $params);
     }));
     $extension = new OrmDatasourceExtension(new RestrictionBuilder($manager));
     $datasource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $datasource->expects($this->once())->method('getQueryBuilder')->will($this->returnValue($qb));
     $config = DatagridConfiguration::create(['source' => ['query_config' => ['filters' => [['column' => 'user_name', 'filter' => 'string', 'filterData' => ['type' => '2', 'value' => 'test_user_name'], 'columnAlias' => 'user_name'], 'AND', [['column' => 'user_status', 'filter' => 'datetime', 'filterData' => ['type' => '2', 'value' => ['start' => '2013-11-20 10:30', 'end' => '2013-11-25 11:30']]], 'AND', [[['column' => 'address.country', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test_address_country'], 'columnAlias' => 'address_country'], 'OR', ['column' => 'address.city', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test_address_city']]], 'OR', ['column' => 'address.zip', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'address_zip']]]]]]]]);
     $extension->visitDatasource($config, $datasource);
     $result = $qb->getDQL();
     $counter = 0;
     $result = preg_replace_callback('/(:[a-z]+)(\\d+)/', function ($matches) use(&$counter) {
         return $matches[1] . ++$counter;
     }, $result);
     $this->assertEquals('SELECT user.id, user.name as user_name, user.status as user_status ' . 'FROM Oro\\Bundle\\QueryDesignerBundle\\Tests\\Unit\\Fixtures\\Models\\CMS\\CmsUser user ' . 'INNER JOIN user.address address ' . 'WHERE user_name NOT LIKE :string1 AND (' . '(user_status < :datetime2 OR user_status > :datetime3) AND ' . '(address.country LIKE :string4 OR address.city LIKE :string5 OR address.zip LIKE :string6)' . ')', $result);
 }
 /**
  * @dataProvider visitDatasourceProvider
  */
 public function testVisitDatasource($source, $expected)
 {
     $qb = new QueryBuilder($this->getTestEntityManager());
     $qb->select(['user.id', 'user.name as user_name', 'user.status as user_status'])->from('Oro\\Bundle\\QueryDesignerBundle\\Tests\\Unit\\Fixtures\\Models\\CMS\\CmsUser', 'user')->join('user.address', 'address');
     $manager = $this->getMockBuilder('Oro\\Bundle\\QueryDesignerBundle\\QueryDesigner\\Manager')->disableOriginalConstructor()->getMock();
     $manager->expects($this->any())->method('createFilter')->will($this->returnCallback(function ($name, $params) {
         return $this->createFilter($name, $params);
     }));
     $extension = new OrmDatasourceExtension(new RestrictionBuilder($manager));
     $datasource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $datasource->expects($this->once())->method('getQueryBuilder')->will($this->returnValue($qb));
     $config = DatagridConfiguration::create($source);
     $extension->visitDatasource($config, $datasource);
     $result = $qb->getDQL();
     $counter = 0;
     $result = preg_replace_callback('/(:[a-z]+)(\\d+)/', function ($matches) use(&$counter) {
         return $matches[1] . ++$counter;
     }, $result);
     $this->assertEquals($expected, $result);
 }