|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Drupal\Tests\views\Kernel\Plugin; |
| 6 | + |
| 7 | +use Drupal\views\Views; |
| 8 | +use Drupal\views_test_data\Plugin\views\join\JoinTest; |
| 9 | + |
| 10 | +/** |
| 11 | + * Tests the EntityReverse join plugin. |
| 12 | + * |
| 13 | + * @group views |
| 14 | + * @see \Drupal\views\Plugin\views\relationship\EntityReverse |
| 15 | + */ |
| 16 | +class EntityReverseJoinTest extends RelationshipJoinTestBase { |
| 17 | + |
| 18 | + /** |
| 19 | + * {@inheritdoc} |
| 20 | + */ |
| 21 | + public static $testViews = ['test_view']; |
| 22 | + |
| 23 | + /** |
| 24 | + * Tests that the EntityReverse plugin loads the correct join plugin. |
| 25 | + */ |
| 26 | + public function testJoinThroughRelationship(): void { |
| 27 | + $relationship_manager = $this->container->get('plugin.manager.views.relationship'); |
| 28 | + // Setup a simple join and test the result sql. |
| 29 | + $view = Views::getView('test_view'); |
| 30 | + $view->initDisplay(); |
| 31 | + $view->initQuery(); |
| 32 | + |
| 33 | + $configuration = [ |
| 34 | + 'id' => 'entity_reverse', |
| 35 | + 'base' => 'users_field_data', |
| 36 | + 'table' => 'users_field_data', |
| 37 | + 'field table' => 'users_field_data', |
| 38 | + 'field field' => 'uid', |
| 39 | + 'base field' => 'uid', |
| 40 | + 'field_name' => 'uid', |
| 41 | + 'join_id' => 'join_test', |
| 42 | + ]; |
| 43 | + |
| 44 | + $relationship = $relationship_manager->createInstance('entity_reverse', $configuration); |
| 45 | + $relationship->tableAlias = 'users_field_data'; |
| 46 | + $relationship->table = 'users_field_data'; |
| 47 | + $relationship->query = $view->getQuery(); |
| 48 | + $relationship->query(); |
| 49 | + $this->assertInstanceOf(JoinTest::class, $relationship->query->getTableQueue()[$relationship->alias]['join']); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments