Mercurial > hg > isophonics-drupal-site
comparison core/modules/views/src/Tests/ViewAjaxTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\views\Tests; | |
4 | |
5 use Drupal\Component\Serialization\Json; | |
6 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; | |
7 | |
8 /** | |
9 * Tests the ajax view functionality. | |
10 * | |
11 * @group views | |
12 */ | |
13 class ViewAjaxTest extends ViewTestBase { | |
14 | |
15 /** | |
16 * Views used by this test. | |
17 * | |
18 * @var array | |
19 */ | |
20 public static $testViews = ['test_ajax_view', 'test_view']; | |
21 | |
22 protected function setUp() { | |
23 parent::setUp(); | |
24 | |
25 $this->enableViewsTestModule(); | |
26 } | |
27 | |
28 /** | |
29 * Tests an ajax view. | |
30 */ | |
31 public function testAjaxView() { | |
32 $this->drupalGet('test_ajax_view'); | |
33 | |
34 $drupal_settings = $this->getDrupalSettings(); | |
35 $this->assertTrue(isset($drupal_settings['views']['ajax_path']), 'The Ajax callback path is set in drupalSettings.'); | |
36 $this->assertEqual(count($drupal_settings['views']['ajaxViews']), 1); | |
37 $view_entry = array_keys($drupal_settings['views']['ajaxViews'])[0]; | |
38 $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.'); | |
39 $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.'); | |
40 | |
41 $data = []; | |
42 $data['view_name'] = 'test_ajax_view'; | |
43 $data['view_display_id'] = 'test_ajax_view'; | |
44 | |
45 $post = [ | |
46 'view_name' => 'test_ajax_view', | |
47 'view_display_id' => 'page_1', | |
48 ]; | |
49 $post += $this->getAjaxPageStatePostData(); | |
50 $response = $this->drupalPost('views/ajax', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | |
51 $data = Json::decode($response); | |
52 | |
53 $this->assertTrue(isset($data[0]['settings']['views']['ajaxViews'])); | |
54 | |
55 // Ensure that the view insert command is part of the result. | |
56 $this->assertEqual($data[1]['command'], 'insert'); | |
57 $this->assertTrue(strpos($data[1]['selector'], '.js-view-dom-id-') === 0); | |
58 | |
59 $this->setRawContent($data[1]['data']); | |
60 $result = $this->xpath('//div[contains(@class, "views-row")]'); | |
61 $this->assertEqual(count($result), 2, 'Ensure that two items are rendered in the HTML.'); | |
62 } | |
63 | |
64 /** | |
65 * Ensures that non-ajax view cannot be accessed via an ajax HTTP request. | |
66 */ | |
67 public function testNonAjaxViewViaAjax() { | |
68 $this->drupalPost('views/ajax', '', ['view_name' => 'test_ajax_view', 'view_display_id' => 'default'], ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | |
69 $this->assertResponse(200); | |
70 $this->drupalPost('views/ajax', '', ['view_name' => 'test_view', 'view_display_id' => 'default'], ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | |
71 $this->assertResponse(403); | |
72 } | |
73 | |
74 } |