diff --git a/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php b/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php index 60ea9b1..1f542cc 100644 --- a/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php +++ b/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php @@ -22,7 +22,11 @@ class AreaHTTPStatusCodeTest extends HandlerTestBase { * * @var array */ - public static $testViews = array('test_http_status_code'); + public static $testViews = array( + 'test_http_status_code', + 'test_http_status_code_cache_time', + 'test_http_status_code_cache_tag', + ); /** * Modules to enable. @@ -32,9 +36,24 @@ class AreaHTTPStatusCodeTest extends HandlerTestBase { public static $modules = array('node'); /** - * Tests the area handler. + * Tests caching the area handler for status codes with anonymous users. */ - public function testHTTPStatusCodeHandler() { + public function testAnonymousHTTPStatusCodeHandler() { + $this->performHTTPStatusCodeHandler(); + } + + /** + * Tests caching the area handler for status codes with a logged-in user. + */ + public function testLoginHTTPStatusCodeHandler() { + $this->drupalLogin($this->drupalCreateUser()); + $this->performHTTPStatusCodeHandler(); + } + + /** + * Tests the area handler. + */ + public function performHTTPStatusCodeHandler() { $this->drupalGet('test-http-status-code'); $this->assertResponse(200); @@ -47,6 +66,46 @@ public function testHTTPStatusCodeHandler() { // Test that the HTTP response is "I'm a teapot". $this->drupalGet('test-http-status-code'); $this->assertResponse(418); + + // Try it again, this time with a time-cached view. + $this->drupalGet('test-http-status-code-cache-time'); + $this->assertResponse(200); + + // Change the HTTP status code to 418. + $view = Views::getView('test_http_status_code_cache_time'); + $display = &$view->storage->getDisplay('default'); + $display['display_options']['empty']['http_status_code']['status_code'] = 418; + $view->save(); + + // Test that the response is not from the cache. + $this->drupalGet('test-http-status-code-cache-time'); + $this->assertResponse(418); + $this->assertEqual('MISS', $this->drupalGetHeader('x-drupal-cache')); + + // Make the same request so it should come from the cache. + $this->drupalGet('test-http-status-code-cache-time'); + $this->assertResponse(418); + $this->assertEqual('HIT', $this->drupalGetHeader('x-drupal-cache')); + + // Repeat the whole process with a tag-cached view. + $this->drupalGet('test-http-status-code-cache-tag'); + $this->assertResponse(200); + + // Change the HTTP status code to 418. + $view = Views::getView('test_http_status_code_cache_tag'); + $display = &$view->storage->getDisplay('default'); + $display['display_options']['empty']['http_status_code']['status_code'] = 418; + $view->save(); + + // Test that the response is not from the cache. + $this->drupalGet('test-http-status-code-cache-tag'); + $this->assertResponse(418); + $this->assertEqual('MISS', $this->drupalGetHeader('x-drupal-cache')); + + // Do it again for the caching. + $this->drupalGet('test-http-status-code-cache-tag'); + $this->assertResponse(418); + $this->assertEqual('HIT', $this->drupalGetHeader('x-drupal-cache')); } } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_http_status_code_cache_tag.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_http_status_code_cache_tag.yml new file mode 100644 index 0000000..dcf6ea5 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_http_status_code_cache_tag.yml @@ -0,0 +1,95 @@ +# This view is copied from views.view.test_http_status_code.yml with the +# addition of a tag-based cache. +langcode: en +status: true +dependencies: + module: + - user +id: test_http_status_code_cache_tag +label: test_http_status_code_cache_tag +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: null + display_options: + access: + type: perm + cache: + type: tag + query: + type: views_query + exposed_form: + type: basic + pager: + type: full + style: + type: default + row: + type: fields + fields: + title: + id: title + table: node_field_data + field: title + label: '' + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + plugin_id: field + entity_type: node + entity_field: title + filters: + status: + value: true + table: node_field_data + field: status + id: status + expose: + operator: '0' + group: 1 + plugin_id: boolean + entity_type: node + entity_field: status + sorts: + created: + id: created + table: node_field_data + field: created + order: DESC + entity_type: node + entity_field: created + empty: + http_status_code: + id: http_status_code + table: views + field: http_status_code + relationship: none + group_type: group + admin_label: '' + label: '' + empty: true + status_code: 200 + plugin_id: http_status_code + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: null + display_options: + path: test-http-status-code-cache-tag diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_http_status_code_cache_time.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_http_status_code_cache_time.yml new file mode 100644 index 0000000..70acf35 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_http_status_code_cache_time.yml @@ -0,0 +1,98 @@ +# This view is copied from views.view.test_http_status_code.yml with the +# addition of a time-based cache. +langcode: en +status: true +dependencies: + module: + - user +id: test_http_status_code_cache_time +label: test_http_status_code_cache_time +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: null + display_options: + access: + type: perm + cache: + type: time + options: + results_lifespan: 3600 + output_lifespan: 3600 + query: + type: views_query + exposed_form: + type: basic + pager: + type: full + style: + type: default + row: + type: fields + fields: + title: + id: title + table: node_field_data + field: title + label: '' + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + plugin_id: field + entity_type: node + entity_field: title + filters: + status: + value: true + table: node_field_data + field: status + id: status + expose: + operator: '0' + group: 1 + plugin_id: boolean + entity_type: node + entity_field: status + sorts: + created: + id: created + table: node_field_data + field: created + order: DESC + entity_type: node + entity_field: created + empty: + http_status_code: + id: http_status_code + table: views + field: http_status_code + relationship: none + group_type: group + admin_label: '' + label: '' + empty: true + status_code: 200 + plugin_id: http_status_code + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: null + display_options: + path: test-http-status-code-cache-time