// Preview and verify the terms appear but are not created.
$this->submitForm($edit, 'Preview'); foreach($termsas$term){ $this->assertSession()->pageTextContains($term); } $tree = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->loadTree($this->vocabulary->id()); $this->assertEmpty($tree, 'The terms are not created on preview.');
// Save, creating the terms.
$this->drupalGet('node/add/article'); $this->submitForm($edit, 'Save'); $this->assertSession()->pageTextContains('Article ' . $edit['title[0][value]'] . ' has been created.');
// Verify that the creation message contains a link to a node.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
/**
* Tests loading the workspace tree when there are no workspaces available.
*/ publicfunctiontestEmptyWorkspaceTree(){ $tree = \Drupal::service('workspaces.repository')->loadTree(); $this->assertSame([], $tree); }
/**
* {@inheritdoc}
*/ publicfunctionload(){ // Get all the workspace entities and sort them in tree order.
$workspace_tree = $this->workspaceRepository->loadTree(); $entities = array_replace($workspace_tree, $this->storage->loadMultiple()); foreach($entitiesas$id => $entity){ $entity->_depth = $workspace_tree[$id]['depth']; }
$this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree"); $term = $this->treeData[$vid][$tid]; $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree"); }
// Terms from previous and next pages are shown if the term tree would have
// been cut in the middle. Keep track of how many extra terms we show on
// each page of terms.
$back_step = NULL; $forward_step = 0;
// An array of the terms to be displayed on this page.
$current_page = [];
$delta = 0; $term_deltas = []; $tree = $this->storageController->loadTree($taxonomy_vocabulary->id(), 0, NULL, TRUE); $tree_index = 0; $complete_tree = NULL; do{ // In case this tree is completely empty.
if(empty($tree[$tree_index])){ break; } $delta++; // Count entries before the current page.
if($page&&($page * $page_increment) > $before_entries && !isset($back_step)){ $before_entries++;
/**
* Tests the forum node pager for nodes with multiple grants per realm.
*/ publicfunctiontestForumPager(){ // Look up the forums vocabulary ID.
$vid = $this->config('forum.settings')->get('vocabulary'); $this->assertNotEmpty($vid, 'Forum navigation vocabulary ID is set.');
// Look up the general discussion term.
$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid, 0, 1); $tid = reset($tree)->tid; $this->assertNotEmpty($tid, 'General discussion term is found in the forum vocabulary.');
$this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree"); $term = $this->treeData[$vid][$tid]; // PostgreSQL, MySQL and SQLite may not return the parent terms in the same
// order so sort before testing.
sort($parent_ids);
/**
* {@inheritdoc}
*/ publicfunctiongetReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0){ // Get all the workspace entities and sort them in tree order.
$storage = $this->entityTypeManager->getStorage('workspace'); $workspace_tree = $this->workspaceRepository->loadTree(); $entities = array_replace($workspace_tree, $storage->loadMultiple());
// If we need to restrict the list of workspaces by searching only a part of
// their label ($match) or by a number of results ($limit), the workspace
// tree would be mangled because it wouldn't contain all the tree items.
if($match || $limit){ $options = parent::getReferenceableEntities($match, $match_operator, $limit); } else{ $options = []; foreach($entitiesas$entity){
// Ensure that workspaces that have descendants can not be deleted.
foreach($entitiesas$entity){ if(!empty($workspace_tree[$entity->id()]['descendants'])){ thrownew \InvalidArgumentException("The {$entity->label()} workspace can not be deleted because it has child workspaces."); } } }