diff --git a/tests/entityreference.admin.test b/tests/entityreference.admin.test index bb33ce8..7868a42 100644 --- a/tests/entityreference.admin.test +++ b/tests/entityreference.admin.test @@ -113,11 +113,6 @@ class EntityReferenceAdminTestCase extends DrupalWebTestCase { $this->drupalPost(NULL, array(), t('Save settings')); // Check that the field appears in the overview form. - // $this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', 'Test label', t('Field was created and appears in the overview page.')); - $elements = $this->xpath('//table[@id="field-overview"]//td'); - /* @var $element SimpleXMLElement */ - foreach ($elements as $element) debug((string) $element); - $elements = $this->xpath('//table[@id="field-overview"]//td[text()="Test label"]'); $this->assertTrue($elements, 'Field was created and appears in the overview page.'); diff --git a/tests/entityreference.revisions.test b/tests/entityreference.revisions.test index 3c3f865..f470114 100644 --- a/tests/entityreference.revisions.test +++ b/tests/entityreference.revisions.test @@ -6,6 +6,18 @@ class EntityReferenceRevisionsTestCase extends DrupalWebTestCase { /** + * {@inheritdoc} + */ + protected $profile = 'testing'; + + /** + * The entityreference field instance. + * + * @var array + */ + protected $instance; + + /** * The node that is referenced. * * @var object @@ -49,39 +61,78 @@ class EntityReferenceRevisionsTestCase extends DrupalWebTestCase { 'field_name' => 'field_entityreference', 'type' => 'entityreference', ); + $field = field_create_field($field); // Create a field instance. - $field = field_create_field($field); $instance = array( 'field_name' => 'field_entityreference', 'bundle' => 'article', 'entity_type' => 'node', ); - - // Enable the taxonomy-index behavior. -// $instance['settings']['behaviors']['taxonomy-index']['status'] = TRUE; - field_create_instance($instance); + $this->instance = field_create_instance($instance); // Create two nodes. The first will be referenced in the second. - $node = (object) array( + $node = array( 'type' => 'article', 'status' => 1, 'title' => $this->randomString(), 'uid' => 1, ); - node_save($node); - $this->referenced_node = $node; + $this->referenced_node = (object) $node; + node_save($this->referenced_node); + + $node['field_entityreference'][LANGUAGE_NONE][]['target_id'] = $this->referenced_node->nid; + $this->referencing_node = (object) $node; + node_save($this->referencing_node); } /** * Test referencing a revision of an entity. */ public function testReferencingRevisions() { - debug($this->nodes); - // + // Get the original revision that was referenced. + $vid = $this->getReferencedRevisionId(); // By default the referencing of specific revisions is disabled and the // latest revision should always be referenced. + $this->createNewRevision(); + $this->assertNotEqual($vid, $vid = $this->getReferencedRevisionId(), 'When revision referencing is disabled, the latest revision is referenced.'); + + // Enable revision referencing. + $this->instance['settings']['handler_settings']['reference_revisions'] = TRUE; + field_update_instance($this->instance); + + // Check that the referenced revision stays the same when a new revision is + // made. + $this->createNewRevision(); + $this->assertEqual($vid, $this->getReferencedRevisionId(), 'When revision referencing is enabled and a new revision is created, the original revision is still referenced.'); + + // Update the referencing node. The revision is not locked, so it should + // change to the current revision. + node_save($this->referencing_node); + $this->assertNotEqual($vid, $vid = $this->getReferencedRevisionId(), 'When revision referencing is enabled and the revision is not locked, the current revision is referenced when the referencing entity is updated.'); + + // Enable revision locking. + $this->instance['settings']['handler_settings']['lock_revision'] = TRUE; + field_update_instance($this->instance); + } + + /** + * Creates a new revision of the referenced node. + */ + protected function createNewRevision() { + $this->referenced_node->revision = TRUE; + node_save($this->referenced_node); } + /** + * Returns the revision of the referenced node. + * + * @return int + * The referenced revision. + */ + protected function getReferencedRevisionId() { + $wrapper = entity_metadata_wrapper('node', $this->referencing_node); + return $wrapper->field_entityreference->vid->value(); + } }