diff --git a/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block_with_context.yml b/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block_with_context.yml index 09c8e70..75ad7f2 100644 --- a/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block_with_context.yml +++ b/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block_with_context.yml @@ -265,3 +265,94 @@ display: cacheable: false max-age: -1 tags: { } + block_2: + display_plugin: block + id: block_2 + display_title: 'Block 2' + position: 2 + display_options: + display_extenders: { } + arguments: + created: + id: created + table: node_field_data + field: created + relationship: none + group_type: group + admin_label: '' + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + items_per_page: 25 + override: false + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: true + validate: + type: numeric + fail: 'not found' + validate_options: { } + entity_type: node + entity_field: created + plugin_id: date + vid: + id: vid + table: node_field_data + field: vid + relationship: none + group_type: group + admin_label: '' + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + items_per_page: 25 + override: false + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: { } + break_phrase: false + not: false + entity_type: node + entity_field: vid + plugin_id: numeric + defaults: + arguments: false + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php b/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php index e87eae0..c42754b 100644 --- a/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php +++ b/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php @@ -2,6 +2,7 @@ namespace Drupal\views\Tests\Plugin; +use Drupal\Core\Plugin\Context\ContextDefinitionInterface; use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestBase; use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait; @@ -80,7 +81,7 @@ public function testBlockContext() { // Check if context was correctly propagated to the block. $definition = $this->container->get('plugin.manager.block') ->getDefinition('views_block:test_view_block_with_context-block_1'); - $this->assertTrue($definition['context']['nid']); + $this->assertTrue($definition['context']['nid'] instanceof ContextDefinitionInterface); /** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context */ $context = $definition['context']['nid']; $this->assertEqual($context->getDataType(), 'entity:node', 'Context definition data type is correct.'); @@ -122,6 +123,24 @@ public function testBlockContext() { $this->drupalGet($this->nodes[1]->toUrl()); $this->assertText('Test view row: Second test node'); + + // Check the second block which should expose two integer contexts, one + // based on the numeric plugin and the other based on numeric validation. + $definition = $this->container->get('plugin.manager.block') + ->getDefinition('views_block:test_view_block_with_context-block_2'); + $this->assertTrue($definition['context']['created'] instanceof ContextDefinitionInterface); + /** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context */ + $context = $definition['context']['created']; + $this->assertEqual($context->getDataType(), 'integer', 'Context definition data type is correct.'); + $this->assertEqual($context->getLabel(), 'Content: Authored on', 'Context definition label is correct.'); + $this->assertFalse($context->isRequired(), 'Context is not required.'); + + $this->assertTrue($definition['context']['vid'] instanceof ContextDefinitionInterface); + /** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context */ + $context = $definition['context']['vid']; + $this->assertEqual($context->getDataType(), 'integer', 'Context definition data type is correct.'); + $this->assertEqual($context->getLabel(), 'Content: Revision ID', 'Context definition label is correct.'); + $this->assertFalse($context->isRequired(), 'Context is not required.'); } }