Chris@0: installEntitySchema('user'); Chris@0: $this->installEntitySchema('node'); Chris@0: $this->installEntitySchema('taxonomy_term'); Chris@0: $this->installSchema('node', 'node_access'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that the taxonomy index work correctly with pending revisions. Chris@0: */ Chris@0: public function testTaxonomyIndexWithPendingRevision() { Chris@0: \Drupal::configFactory()->getEditable('taxonomy.settings')->set('maintain_index_table', TRUE)->save(); Chris@0: Chris@0: Vocabulary::create([ Chris@0: 'name' => 'test', Chris@0: 'vid' => 'test', Chris@0: ])->save(); Chris@0: $term = Term::create([ Chris@0: 'name' => 'term1', Chris@0: 'vid' => 'test', Chris@0: ]); Chris@0: $term->save(); Chris@0: $term2 = Term::create([ Chris@0: 'name' => 'term2', Chris@0: 'vid' => 'test', Chris@0: ]); Chris@0: $term2->save(); Chris@0: Chris@0: NodeType::create([ Chris@0: 'type' => 'page', Chris@0: ])->save(); Chris@0: Chris@0: FieldStorageConfig::create([ Chris@0: 'entity_type' => 'node', Chris@0: 'field_name' => 'field_tags', Chris@0: 'type' => 'entity_reference', Chris@0: 'settings' => [ Chris@0: 'target_type' => 'taxonomy_term', Chris@0: ], Chris@0: ])->save(); Chris@0: Chris@0: FieldConfig::create([ Chris@0: 'field_name' => 'field_tags', Chris@0: 'entity_type' => 'node', Chris@0: 'bundle' => 'page', Chris@0: ])->save(); Chris@0: $node = Node::create([ Chris@0: 'type' => 'page', Chris@0: 'title' => 'test_title', Chris@0: 'field_tags' => [$term->id()], Chris@0: ]); Chris@0: $node->save(); Chris@0: Chris@0: $taxonomy_index = $this->getTaxonomyIndex(); Chris@0: $this->assertEquals($term->id(), $taxonomy_index[$node->id()]->tid); Chris@0: Chris@0: // Normal new revision. Chris@0: $node->setNewRevision(TRUE); Chris@0: $node->isDefaultRevision(TRUE); Chris@0: $node->field_tags->target_id = $term2->id(); Chris@0: $node->save(); Chris@0: Chris@0: $taxonomy_index = $this->getTaxonomyIndex(); Chris@0: $this->assertEquals($term2->id(), $taxonomy_index[$node->id()]->tid); Chris@0: Chris@0: // Check that saving a pending revision does not affect the taxonomy index. Chris@0: $node->setNewRevision(TRUE); Chris@0: $node->isDefaultRevision(FALSE); Chris@0: $node->field_tags->target_id = $term->id(); Chris@0: $node->save(); Chris@0: Chris@0: $taxonomy_index = $this->getTaxonomyIndex(); Chris@0: $this->assertEquals($term2->id(), $taxonomy_index[$node->id()]->tid); Chris@0: Chris@0: // Check that making the previously created pending revision the default Chris@0: // revision updates the taxonomy index correctly. Chris@0: $node->isDefaultRevision(TRUE); Chris@0: $node->save(); Chris@0: Chris@0: $taxonomy_index = $this->getTaxonomyIndex(); Chris@0: $this->assertEquals($term->id(), $taxonomy_index[$node->id()]->tid); Chris@0: } Chris@0: Chris@0: protected function getTaxonomyIndex() { Chris@0: return \Drupal::database()->select('taxonomy_index') Chris@0: ->fields('taxonomy_index') Chris@0: ->execute() Chris@0: ->fetchAllAssoc('nid'); Chris@0: } Chris@0: Chris@0: }