TaxonomyRelationshipTest.php in Zircon Profile 8.0
File
core/modules/taxonomy/src/Tests/Views/TaxonomyRelationshipTest.php
View source
<?php
namespace Drupal\taxonomy\Tests\Views;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
use Drupal\views\Views;
class TaxonomyRelationshipTest extends TaxonomyTestBase {
protected $terms = array();
public static $testViews = array(
'test_taxonomy_term_relationship',
);
protected function setUp() {
parent::setUp();
$this->term1
->set('parent', $this->term2
->id());
$this->term1
->save();
$this->terms[] = $this->term1;
$this->terms[] = $this->term2;
unset($this->nodes[0]->field_views_testing_tags[1]);
$this->nodes[0]
->save();
unset($this->nodes[1]->field_views_testing_tags[0]);
$this->nodes[1]
->save();
Views::viewsData()
->clear();
}
public function testTaxonomyRelationships() {
$views_data = Views::viewsData()
->get('taxonomy_index');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
$this
->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid');
$this
->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid');
$views_data = Views::viewsData()
->get('taxonomy_term_hierarchy');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
$this
->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
$this
->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data');
$this
->assertEqual($views_data['parent']['relationship']['field'], 'parent');
$this
->assertEqual($views_data['parent']['relationship']['label'], t('Parent'));
$this
->assertEqual($views_data['parent']['relationship']['id'], 'standard');
$this
->assertEqual($views_data['parent']['filter']['id'], 'numeric');
$this
->assertEqual($views_data['parent']['argument']['id'], 'taxonomy');
$view = Views::getView('test_taxonomy_term_relationship');
$this
->executeView($view);
foreach ($view->result as $index => $row) {
$this
->assertEqual($row->tid, $this->terms[$index]
->id());
$this
->assertEqual($row->_entity
->id(), $this->terms[$index]
->id());
$this
->assertTrue($row->_entity instanceof TermInterface);
if (!$index) {
$this
->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface);
$this
->assertEqual($row->_relationship_entities['parent']
->id(), $this->term2
->id());
$this
->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2
->id());
}
$this
->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface);
$this
->assertEqual($row->_relationship_entities['nid']
->id(), $this->nodes[$index]
->id());
}
}
}