Commit 90779e26 authored by catch's avatar catch

Issue #2876209 by Lendude: Convert \Drupal\views\Tests\ViewAjaxTest to a BrowserTestBase test

(cherry picked from commit d136825c)
parent c2b77b0c
<?php
namespace Drupal\views\Tests;
namespace Drupal\Tests\views\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
/**
......@@ -37,38 +36,24 @@ public function testAjaxView() {
$view_entry = array_keys($drupal_settings['views']['ajaxViews'])[0];
$this->assertEqual($drupal_settings['views']['ajaxViews'][$view_entry]['view_name'], 'test_ajax_view', 'The view\'s ajaxViews array entry has the correct \'view_name\' key.');
$this->assertEqual($drupal_settings['views']['ajaxViews'][$view_entry]['view_display_id'], 'page_1', 'The view\'s ajaxViews array entry has the correct \'view_display_id\' key.');
$data = [];
$data['view_name'] = 'test_ajax_view';
$data['view_display_id'] = 'test_ajax_view';
$post = [
'view_name' => 'test_ajax_view',
'view_display_id' => 'page_1',
];
$post += $this->getAjaxPageStatePostData();
$response = $this->drupalPost('views/ajax', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$data = Json::decode($response);
$this->assertTrue(isset($data[0]['settings']['views']['ajaxViews']));
// Ensure that the view insert command is part of the result.
$this->assertEqual($data[1]['command'], 'insert');
$this->assertTrue(strpos($data[1]['selector'], '.js-view-dom-id-') === 0);
$this->setRawContent($data[1]['data']);
$result = $this->xpath('//div[contains(@class, "views-row")]');
$this->assertEqual(count($result), 2, 'Ensure that two items are rendered in the HTML.');
}
/**
* Ensures that non-ajax view cannot be accessed via an ajax HTTP request.
*/
public function testNonAjaxViewViaAjax() {
$this->drupalPost('views/ajax', '', ['view_name' => 'test_ajax_view', 'view_display_id' => 'default'], ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$this->drupalPost('views/ajax', '', ['view_name' => 'test_view', 'view_display_id' => 'default'], ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(403);
$client = $this->getHttpClient();
$response = $client->request('POST', $this->buildUrl('views/ajax'), [
'form_params' => ['view_name' => 'test_ajax_view', 'view_display_id' => 'default'],
'query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax'],
]);
$this->assertEquals(200, $response->getStatusCode());
$response = $client->request('POST', $this->buildUrl('views/ajax'), [
'form_params' => ['view_name' => 'test_view', 'view_display_id' => 'default'],
'query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax'],
'http_errors' => FALSE,
]);
$this->assertEquals(403, $response->getStatusCode());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment