/**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => 'access-denied-page', 'page.404' => 'not-found-page']]);
     $this->aliasManager = $this->getMock('Drupal\\Core\\Path\\AliasManagerInterface');
     $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->redirectDestination->expects($this->any())->method('getAsArray')->willReturn(['destination' => 'test']);
     $this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->aliasManager, $this->kernel, $this->logger, $this->redirectDestination);
     // You can't create an exception in PHP without throwing it. Store the
     // current error_log, and disable it temporarily.
     $this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
 }
 /**
  * @covers ::getDefaultOperations
  */
 public function testGetDefaultOperationsWithAccess()
 {
     $method = new \ReflectionMethod($this->sut, 'getDefaultOperations');
     $method->setAccessible(TRUE);
     $url_canonical = new Url($this->randomMachineName());
     $url_edit_form = new Url($this->randomMachineName());
     $url_delete_form = new Url($this->randomMachineName());
     $url_update_status_form = new Url($this->randomMachineName());
     $url_capture_form = new Url($this->randomMachineName());
     $url_refund_form = new Url($this->randomMachineName());
     $url_complete = new Url($this->randomMachineName());
     $payment = $this->getMock(PaymentInterface::class);
     $map = [['view', NULL, FALSE, TRUE], ['update', NULL, FALSE, TRUE], ['delete', NULL, FALSE, TRUE], ['update_status', NULL, FALSE, TRUE], ['capture', NULL, FALSE, TRUE], ['refund', NULL, FALSE, TRUE], ['complete', NULL, FALSE, TRUE]];
     $payment->expects($this->atLeast(count($map)))->method('access')->willReturnMap($map);
     $payment->expects($this->any())->method('hasLinkTemplate')->willReturn(TRUE);
     $map = [['canonical', [], $url_canonical], ['edit-form', [], $url_edit_form], ['delete-form', [], $url_delete_form], ['update-status-form', [], $url_update_status_form], ['capture-form', [], $url_capture_form], ['refund-form', [], $url_refund_form], ['complete', [], $url_complete]];
     $payment->expects($this->atLeast(count($map)))->method('urlInfo')->willReturnMap($map);
     $destination = $this->randomMachineName();
     $this->redirectDestination->expects($this->atLeastOnce())->method('get')->willReturn($destination);
     $operations = $method->invoke($this->sut, $payment);
     ksort($operations);
     $expected_operations = ['view', 'edit', 'delete', 'update_status', 'capture', 'refund', 'complete'];
     sort($expected_operations);
     $this->assertSame($expected_operations, array_keys($operations));
     foreach ($operations as $name => $operation) {
         $this->assertInstanceof(TranslatableMarkup::class, $operation['title']);
         $this->assertInstanceof(Url::class, $operation['url']);
         if (array_key_exists('weight', $operation)) {
             $this->assertInternalType('int', $operation['weight']);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);
     $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->redirectDestination->expects($this->any())->method('getAsArray')->willReturn(['destination' => 'test']);
     $this->accessUnawareRouter = $this->getMock('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface');
     $this->accessUnawareRouter->expects($this->any())->method('match')->willReturn(['_controller' => 'mocked']);
     $this->accessManager = $this->getMock('Drupal\\Core\\Access\\AccessManagerInterface');
     $this->accessManager->expects($this->any())->method('checkNamedRoute')->willReturn(AccessResult::allowed()->addCacheTags(['foo', 'bar']));
     $this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter, $this->accessManager);
     $path_validator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface');
     $path_validator->expects($this->any())->method('getUrlIfValidWithoutAccessCheck')->willReturn(Url::fromRoute('foo', ['foo' => 'bar']));
     $container = new ContainerBuilder();
     $container->set('path.validator', $path_validator);
     \Drupal::setContainer($container);
     // You can't create an exception in PHP without throwing it. Store the
     // current error_log, and disable it temporarily.
     $this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
 }
 /**
  * @covers ::getOperations
  */
 public function testGetOperations()
 {
     $list_builder_operations = ['edit' => ['title' => 'Edit configuration'], 'delete' => ['title' => 'Delete configuration'], 'enable' => ['title' => 'Enable configuration'], 'disable' => ['title' => 'Disable configuration'], 'foo' => []];
     $destination = $this->randomMachineName();
     $this->redirectDestination->expects($this->atLeastOnce())->method('get')->willReturn($destination);
     $plugin_id = $this->randomMachineName();
     $payment_method_configuration = $this->getMock(PaymentMethodConfigurationInterface::class);
     $this->sut->expects($this->once())->method('getPaymentMethodConfiguration')->with($plugin_id)->willReturn($payment_method_configuration);
     $this->paymentMethodConfigurationListBuilder->expects($this->once())->method('getOperations')->with($payment_method_configuration)->willReturn($list_builder_operations);
     $expected_operations = $list_builder_operations;
     unset($expected_operations['foo']);
     foreach ($expected_operations as $name => $expected_operation) {
         $expected_operations[$name]['title'] = $list_builder_operations[$name]['title'];
         $expected_operations[$name]['query']['destination'] = $destination;
     }
     $this->assertEquals($expected_operations, $this->sut->getOperations($plugin_id));
 }
 /**
  * Tests a valid view without arguments pagers etc.
  */
 public function testAjaxView()
 {
     $request = new Request();
     $request->request->set('view_name', 'test_view');
     $request->request->set('view_display_id', 'page_1');
     $request->request->set('view_path', '/test-page');
     $request->request->set('_wrapper_format', 'ajax');
     $request->request->set('ajax_page_state', 'drupal.settings[]');
     $request->request->set('type', 'article');
     list($view, $executable) = $this->setupValidMocks();
     $display_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock();
     // Ensure that the pager element is not set.
     $display_handler->expects($this->never())->method('setOption');
     $display_collection = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')->disableOriginalConstructor()->getMock();
     $display_collection->expects($this->any())->method('get')->with('page_1')->will($this->returnValue($display_handler));
     $executable->displayHandlers = $display_collection;
     $this->redirectDestination->expects($this->atLeastOnce())->method('set')->with('/test-page?type=article');
     $response = $this->viewAjaxController->ajaxView($request);
     $this->assertTrue($response instanceof ViewAjaxResponse);
     $this->assertSame($response->getView(), $executable);
     $this->assertViewResultCommand($response);
 }