View source
<?php
namespace Drupal\Tests\tvi\Functional;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Core\Language\LanguageInterface;
abstract class TaxonomyViewsIntegratorTestBase extends BrowserTestBase {
use EntityReferenceTestTrait;
protected $vocabulary1;
protected $vocabulary2;
public static $modules = [
'node',
'tvi',
'tvi_test',
'views',
'views_ui',
'taxonomy',
];
protected $term1;
protected $term2;
protected $term3;
protected $term4;
protected $term5;
protected $term6;
protected $term7;
protected $term8;
protected $term9;
protected $term10;
protected $term11;
protected $term12;
public function setUp() {
parent::setUp();
$this->vocabulary1 = $this
->createVocabulary([
'name' => 'TVI Test Vocab 1',
'vid' => 'tvi_test_vocab_1',
]);
$this->vocabulary2 = $this
->createVocabulary([
'name' => 'TVI Test Vocab 2',
'vid' => 'tvi_test_vocab_2',
]);
$this->term1 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
]);
$this->term2 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
]);
$this->term3 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
]);
$this->term4 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
]);
$this->term5 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
'parent' => $this->term2
->id(),
]);
$this->term6 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
'parent' => $this->term2
->id(),
]);
$this->term7 = $this
->createTerm([
'vid' => $this->vocabulary1
->id(),
'parent' => $this->term1
->id(),
]);
$this->term8 = $this
->createTerm([
'vid' => $this->vocabulary2
->id(),
]);
$this->term9 = $this
->createTerm([
'vid' => $this->vocabulary2
->id(),
]);
$this->term10 = $this
->createTerm([
'vid' => $this->vocabulary2
->id(),
]);
$this->term11 = $this
->createTerm([
'vid' => $this->vocabulary2
->id(),
'parent' => $this->term10
->id(),
]);
$this->term12 = $this
->createTerm([
'vid' => $this->vocabulary2
->id(),
'parent' => $this->term11
->id(),
]);
$this
->createTaxonomyViewsIntegratorConfiguration();
}
protected function createVocabulary(array $settings = []) {
$settings += [
'name' => $this
->randomMachineName(),
'vid' => $this
->randomMachineName(),
];
$vocabulary = Vocabulary::create($settings);
$vocabulary
->save();
return $vocabulary;
}
protected function createTerm(array $settings = []) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$settings += [
'name' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
'format' => $format
->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
$term = Term::create($settings);
$term
->save();
return $term;
}
protected function createTaxonomyViewsIntegratorConfiguration() {
$this
->config('tvi.taxonomy_vocabulary.' . $this->vocabulary1
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_1')
->set('inherit_settings', 1)
->save();
$this
->config('tvi.taxonomy_vocabulary.' . $this->vocabulary2
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term1
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_1')
->set('inherit_settings', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term2
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_2')
->set('inherit_settings', 1)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term3
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term4
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term5
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_1')
->set('inherit_settings', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term6
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term7
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term8
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_1')
->set('inherit_settings', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term9
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term10
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_2')
->set('inherit_settings', 1)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term11
->id())
->set('enable_override', 0)
->save();
$this
->config('tvi.taxonomy_term.' . $this->term12
->id())
->set('enable_override', 1)
->set('view', 'tvi_page')
->set('view_display', 'page_1')
->set('inherit_settings', 0)
->save();
$this
->refreshVariables();
}
}