protected function CollectRoutesTest::setUp in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/rest/tests/src/Unit/CollectRoutesTest.php \Drupal\Tests\rest\Unit\CollectRoutesTest::setUp()
Overrides UnitTestCase::setUp
File
- core/
modules/ rest/ tests/ src/ Unit/ CollectRoutesTest.php, line 38 - Contains \Drupal\Tests\rest\Unit\CollectRoutesTest.
Class
- CollectRoutesTest
- Tests the REST export view plugin.
Namespace
Drupal\Tests\rest\UnitCode
protected function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$request = $this
->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')
->disableOriginalConstructor()
->getMock();
$this->view = $this
->getMock('\\Drupal\\views\\Entity\\View', array(
'initHandlers',
), array(
array(
'id' => 'test_view',
),
'view',
));
$view_executable = $this
->getMock('\\Drupal\\views\\ViewExecutable', array(
'initHandlers',
'getTitle',
), array(), '', FALSE);
$view_executable
->expects($this
->any())
->method('getTitle')
->willReturn('View title');
$view_executable->storage = $this->view;
$view_executable->argument = array();
$display_manager = $this
->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$container
->set('plugin.manager.views.display', $display_manager);
$access_manager = $this
->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$container
->set('plugin.manager.views.access', $access_manager);
$route_provider = $this
->getMockBuilder('\\Drupal\\Core\\Routing\\RouteProviderInterface')
->disableOriginalConstructor()
->getMock();
$container
->set('router.route_provider', $route_provider);
$state = $this
->getMock('\\Drupal\\Core\\State\\StateInterface');
$container
->set('state', $state);
$style_manager = $this
->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$container
->set('plugin.manager.views.style', $style_manager);
$container
->set('renderer', $this
->getMock('Drupal\\Core\\Render\\RendererInterface'));
\Drupal::setContainer($container);
$this->restExport = RestExport::create($container, array(), "test_routes", array());
$this->restExport->view = $view_executable;
// Initialize a display.
$this->restExport->display = array(
'id' => 'page_1',
);
// Set the style option.
$this->restExport
->setOption('style', array(
'type' => 'serializer',
));
$display_manager
->expects($this
->once())
->method('getDefinition')
->will($this
->returnValue(array(
'id' => 'test',
'provider' => 'test',
)));
$none = $this
->getMockBuilder('\\Drupal\\views\\Plugin\\views\\access\\None')
->disableOriginalConstructor()
->getMock();
$access_manager
->expects($this
->once())
->method('createInstance')
->will($this
->returnValue($none));
$style_plugin = $this
->getMock('\\Drupal\\rest\\Plugin\\views\\style\\Serializer', array(
'getFormats',
'init',
), array(), '', FALSE);
$style_plugin
->expects($this
->once())
->method('getFormats')
->will($this
->returnValue(array(
'json',
)));
$style_plugin
->expects($this
->once())
->method('init')
->with($view_executable)
->will($this
->returnValue(TRUE));
$style_manager
->expects($this
->once())
->method('createInstance')
->will($this
->returnValue($style_plugin));
$this->routes = new RouteCollection();
$this->routes
->add('test_1', new Route('/test/1'));
$this->routes
->add('view.test_view.page_1', new Route('/test/2'));
$this->view
->addDisplay('page', NULL, 'page_1');
}