View source
<?php
namespace Drupal\taxonomy\Tests\Views;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
use Drupal\views\Views;
class TaxonomyTermViewTest extends TaxonomyTestBase {
public static $modules = array(
'taxonomy',
'views',
);
protected $adminUser;
protected $fieldName1;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer taxonomy',
'bypass node access',
]);
$this
->drupalLogin($this->adminUser);
$this->fieldName1 = Unicode::strtolower($this
->randomMachineName());
$handler_settings = array(
'target_bundles' => array(
$this->vocabulary
->id() => $this->vocabulary
->id(),
),
'auto_create' => TRUE,
);
$this
->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName1, array(
'type' => 'options_select',
))
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName1, array(
'type' => 'entity_reference_label',
))
->save();
}
public function testTaxonomyTermView() {
$term = $this
->createTerm();
$edit = array();
$edit['title[0][value]'] = $original_title = $this
->randomMachineName();
$edit['body[0][value]'] = $this
->randomMachineName();
$edit["{$this->fieldName1}[]"] = $term
->id();
$this
->drupalPostForm('node/add/article', $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->assertText($term
->label());
$this
->assertText($node
->label());
\Drupal::service('module_installer')
->install(array(
'language',
'content_translation',
));
$language = ConfigurableLanguage::createFromLangcode('ur');
$language
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
$roles = $this->adminUser
->getRoles(TRUE);
Role::load(reset($roles))
->grantPermission('create content translations')
->grantPermission('translate any entity')
->save();
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('router.builder')
->rebuild();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$edit['title[0][value]'] = $translated_title = $this
->randomMachineName();
$this
->drupalPostForm('node/' . $node
->id() . '/translations/add/en/ur', $edit, t('Save (this translation)'));
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->assertText($term
->label());
$this
->assertText($original_title);
$this
->assertNoText($translated_title);
$this
->drupalGet('ur/taxonomy/term/' . $term
->id());
$this
->assertText($term
->label());
$this
->assertNoText($original_title);
$this
->assertText($translated_title);
$node
->delete();
\Drupal::service('module_installer')
->uninstall([
'content_translation',
'language',
]);
$view = Views::getView('taxonomy_term');
$view
->initDisplay();
$view
->setArguments([
$term
->id(),
]);
$view
->build();
$query = $view->build_info['query'];
$tables = $query
->getTables();
$this
->assertEqual([
'node_field_data',
'taxonomy_index',
], array_keys($tables));
$condition = $query
->conditions();
unset($condition['#conjunction']);
$this
->assertEqual(1, count($condition));
Role::load(RoleInterface::ANONYMOUS_ID)
->revokePermission('access content')
->save();
$this
->drupalLogout();
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->assertResponse(403);
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/feed');
$this
->assertResponse(403);
}
}