function PreprocessPagerTest::setUp

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest::setUp()
  2. 10 core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest::setUp()
  3. 9 core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest::setUp()
  4. 8.9.x core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php, line 32

Class

PreprocessPagerTest
Tests pager preprocessing.

Namespace

Drupal\Tests\system\Unit\Pager

Code

protected function setUp() : void {
  parent::setUp();
  $pager_manager = $this->getMockBuilder('Drupal\\Core\\Pager\\PagerManager')
    ->disableOriginalConstructor()
    ->getMock();
  $pager = $this->getMockBuilder('Drupal\\Core\\Pager\\Pager')
    ->disableOriginalConstructor()
    ->getMock();
  $url_generator = $this->getMockBuilder('Drupal\\Core\\Routing\\UrlGenerator')
    ->disableOriginalConstructor()
    ->getMock();
  $pager->method('getTotalPages')
    ->willReturn(2);
  $pager->method('getCurrentPage')
    ->willReturn(1);
  $url_generator->method('generateFromRoute')
    ->willReturn('');
  $pager_manager->method('getPager')
    ->willReturn($pager);
  $pager_manager->method('getUpdatedParameters')
    ->willReturn('');
  $request_stack = $this->createMock(RequestStack::class);
  $request = Request::createFromGlobals();
  $request->query
    ->set(MainContentViewSubscriber::WRAPPER_FORMAT, 'drupal_modal');
  // Mocks the request stack getting the current request.
  $request_stack->expects($this->any())
    ->method('getCurrentRequest')
    ->willReturn($request);
  $this->pagerPreprocess = new PagerPreprocess($pager_manager, $request_stack);
  $container = new ContainerBuilder();
  $container->set('url_generator', $url_generator);
  \Drupal::setContainer($container);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.