public function testVisitMetadata()
 {
     $config = DatagridConfiguration::create(['options' => ['mode' => ModeExtension::MODE_CLIENT]]);
     $metadata = MetadataObject::create([]);
     $this->extension->visitMetadata($config, $metadata);
     $this->assertEquals(ModeExtension::MODE_CLIENT, $metadata->offsetGetByPath('mode'));
 }
 public function testVisitMetadata()
 {
     $config = DatagridConfiguration::create([Configuration::BASE_CONFIG_KEY => ['enable' => true]]);
     $data = MetadataObject::create([]);
     $this->extension->visitMetadata($config, $data);
     $this->assertEquals($config->offsetGet(Configuration::BASE_CONFIG_KEY), $data->offsetGet(Configuration::BASE_CONFIG_KEY));
 }
Exemple #3
0
 /**
  * Test method acceptMetadata
  */
 public function testAcceptMetadata()
 {
     $data = MetadataObject::create([]);
     $extMock = $this->getMockForAbstractClass('Oro\\Bundle\\DataGridBundle\\Extension\\ExtensionVisitorInterface');
     $extMock->expects($this->once())->method('visitMetadata')->with($this->config, $data);
     $this->acceptor->addExtension($extMock);
     $this->acceptor->acceptMetadata($data);
 }
 public function testVisitMetadata()
 {
     $metadata = MetadataObject::create([]);
     $this->extension->visitMetadata($this->config, $metadata);
     $totalsData = $metadata->offsetGet('state');
     $initialTotalsData = $metadata->offsetGet('initialState');
     $this->assertEquals($totalsData, $initialTotalsData);
     $this->assertEquals($this->config->offsetGetByPath(Configuration::TOTALS_PATH), $totalsData['totals']);
     $this->assertEquals('orodatagrid/js/totals-builder', $metadata->offsetGet('requireJSModules')[0]);
 }
 public function testVisitMetadataShouldAddGridViewsFromEvent()
 {
     $this->gridViewsExtension->setParameters(new ParameterBag());
     $data = MetadataObject::create([]);
     $config = DatagridConfiguration::create([DatagridConfiguration::NAME_KEY => 'grid']);
     $this->eventDispatcher->expects($this->once())->method('hasListeners')->with(GridViewsLoadEvent::EVENT_NAME)->will($this->returnValue(true));
     $expectedViews = ['views' => [(new View('name', ['k' => 'v'], ['k2' => 'v2']))->getMetadata()], 'permissions' => ['CREATE' => true, 'EDIT' => true, 'VIEW' => true, 'DELETE' => true, 'SHARE' => true, 'EDIT_SHARED' => true], 'gridName' => 'grid'];
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(GridViewsLoadEvent::EVENT_NAME)->will($this->returnCallback(function ($eventName, GridViewsLoadEvent $event) use($expectedViews) {
         $event->setGridViews($expectedViews);
         return $event;
     }));
     $this->assertFalse($data->offsetExists('gridViews'));
     $this->gridViewsExtension->visitMetadata($config, $data);
     $this->assertTrue($data->offsetExists('gridViews'));
     $this->assertEquals($expectedViews, $data->offsetGet('gridViews'));
 }
 /**
  * Empty implementation should be callable
  */
 public function testVisitMetadata()
 {
     $data = MetadataObject::create([]);
     $config = DatagridConfiguration::create([]);
     $this->extension->visitMetadata($config, $data);
 }
 /**
  * @param bool $isApplicable
  * @param array $state
  * @param string $scope
  * @param array $entityIds
  * @param int $entitiesLimit
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function buildDataGrid($isApplicable = false, array $state = [], $scope = EntityPaginationManager::VIEW_SCOPE, array $entityIds = [], $entitiesLimit = 0)
 {
     $metadata = ['state' => $state];
     $metadataObject = MetadataObject::create($metadata);
     $permission = EntityPaginationManager::getPermission($scope);
     $identifierField = 'id';
     $this->paginationManager->expects($this->any())->method('isDatagridApplicable')->will($this->returnValue($isApplicable));
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $queryBuilder->expects($this->any())->method('getRootEntities')->will($this->returnValue([self::ENTITY_NAME]));
     $queryBuilder->expects($this->any())->method('setFirstResult')->with(0);
     $queryBuilder->expects($this->any())->method('setMaxResults')->with($entitiesLimit);
     $entities = [];
     foreach ($entityIds as $id) {
         $entities[] = [$identifierField => $id];
     }
     $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['execute'])->getMockForAbstractClass();
     $query->expects($this->any())->method('execute')->will($this->returnValue($entities));
     $this->aclHelper->expects($this->any())->method('apply')->with($queryBuilder, $permission)->will($this->returnValue($query));
     $this->doctrineHelper->expects($this->any())->method('getEntityMetadata')->with(self::ENTITY_NAME)->will($this->returnValue(new ClassMetadata(self::ENTITY_NAME)));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifierFieldName')->with(self::ENTITY_NAME)->will($this->returnValue($identifierField));
     $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $dataSource->expects($this->any())->method('getQueryBuilder')->will($this->returnValue($queryBuilder));
     $acceptor = $this->getMock('Oro\\Bundle\\DataGridBundle\\Extension\\Acceptor');
     if ($isApplicable) {
         $acceptor->expects($this->once())->method('acceptDatasource')->with($dataSource);
     }
     $dataGrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $dataGrid->expects($this->any())->method('getMetadata')->will($this->returnValue($metadataObject));
     $dataGrid->expects($this->any())->method('getAcceptor')->will($this->returnValue($acceptor));
     $dataGrid->expects($this->any())->method('getDatasource')->will($this->returnValue($dataSource));
     $this->pager->expects($this->any())->method('setQueryBuilder')->with($queryBuilder);
     $this->pager->expects($this->any())->method('setAclPermission')->with($permission);
     $this->pager->expects($this->any())->method('computeNbResult')->will($this->returnValue(count($entityIds)));
     $this->datagridManager->expects($this->once())->method('getDatagridByRequestParams')->with(self::GRID_NAME)->will($this->returnValue($dataGrid));
     return $dataGrid;
 }