You are here

protected function SortableviewsAccessTest::setUp in Sortableviews 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/Access/SortableviewsAccessTest.php, line 34

Class

SortableviewsAccessTest
@coversDefaultClass \Drupal\sortableviews\Access\SortableviewsAccess @group sortableviews

Namespace

Drupal\Tests\sortableviews\Unit\Access

Code

protected function setUp() {
  $view_style = $this
    ->getMockBuilder('Drupal\\views\\Plugin\\views\\style\\StylePluginBase')
    ->disableOriginalConstructor()
    ->getMock();
  $view_style->options['weight_field'] = 'some_field';
  $entity_type = $this
    ->createMock('Drupal\\Component\\Plugin\\Definition\\PluginDefinitionInterface');
  $entity_type
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn('some_entity');
  $view_executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->getMock();
  $view_executable
    ->expects($this
    ->any())
    ->method('getBaseEntityType')
    ->willReturn($entity_type);
  $view_executable
    ->expects($this
    ->any())
    ->method('getStyle')
    ->willReturn($view_style);
  $view_entity = $this
    ->createMock('Drupal\\views\\ViewEntityInterface');
  $executable_factory = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutableFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $executable_factory
    ->expects($this
    ->any())
    ->method('get')
    ->with($view_entity)
    ->willReturn($view_executable);
  $entities = [];
  for ($aux = 1; $aux <= 2; $aux++) {
    $entity = $this
      ->createMock('Drupal\\Core\\Access\\AccessibleInterface');
    $entity
      ->expects($this
      ->any())
      ->method('access')
      ->willReturn(TRUE);
    $entities[] = $entity;
  }
  $entity_storage = $this
    ->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $entity_storage
    ->expects($this
    ->any())
    ->method('load')
    ->with('some_view')
    ->willReturn($view_entity);
  $entity_storage
    ->expects($this
    ->any())
    ->method('loadMultiple')
    ->willReturn($entities);
  $entity_manager = $this
    ->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $entity_manager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->willReturn($entity_storage);
  $this->sortableViewsAccess = new SortableviewsAccess($entity_manager, $executable_factory);
  $this->account = $this
    ->createMock('Drupal\\Core\\Session\\AccountInterface');
}