? references_1045420.patch
Index: node_reference/node_reference.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/references/node_reference/node_reference.info,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 node_reference.info
--- node_reference/node_reference.info	30 Jan 2011 16:14:17 -0000	1.1.2.3
+++ node_reference/node_reference.info	30 Jan 2011 17:39:27 -0000
@@ -5,3 +5,4 @@ package = Fields
 core = 7.x
 dependencies[] = field
 dependencies[] = options
+files[] = node_reference.test
Index: node_reference/node_reference.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/references/node_reference/Attic/node_reference.test,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 node_reference.test
--- node_reference/node_reference.test	14 Jan 2011 20:18:28 -0000	1.1.2.1
+++ node_reference/node_reference.test	30 Jan 2011 17:39:27 -0000
@@ -1,6 +1,76 @@
 <?php
-// $Id: node_reference.test,v 1.1.2.1 2011/01/14 20:18:28 fgm Exp $
+// $Id$
 /**
  * @file
- * Placeholder for the development of node_reference tests
- */
\ No newline at end of file
+ * Initial node_reference tests
+ */
+
+/**
+ * Unit tests for referenceability of node types in entity forms.
+ */
+class Node_Reference_Test extends FieldTestCase {
+  public static function getInfo() {
+    return array(
+      'name'        => 'Node reference',
+      'description' => 'Make sure nodes are referenceable in entity forms.',
+      'group'       => 'References',
+    );
+  }
+
+  function setUp() {
+    parent::setUp(array('node_reference', 'field_test'));
+
+    $this->field_name = 'test_node_reference';
+    $this->field = array(
+      'field_name'  => $this->field_name,
+      'type'        => 'node_reference',
+      'cardinality' => 1,
+      'settings'    => array(
+        'referenceable_types' => node_type_get_names(),
+      ),
+    );
+    $this->field = field_create_field($this->field);
+    $this->instance = array(
+      'field_name'  => $this->field_name,
+      'entity_type' => 'test_entity',
+      'bundle'      => 'test_bundle',
+      'widget'      => array(
+        'type'        => 'options_buttons',
+      ),
+    );
+
+    $this->instance = field_create_instance($this->instance);
+  }
+
+  function testReferenceableNodeTypes() {
+    $langcode = LANGUAGE_NONE;
+    $nodes = array();
+    foreach (node_type_get_names() as $type_name => $type_title) {
+      $nodes[$type_name] = $this->drupalCreateNode(array(
+        'type'  => $type_name,
+        'title' => $this->randomName(8),
+        // 'body'  => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
+      ));
+      $this->pass(t('Created %type node %nid: %title', array(
+        '%type'  => $type_name,
+        '%nid'   => $nodes[$type_name]->nid,
+        '%title' => $nodes[$type_name]->title,
+      )), 'destination creation');
+    }
+
+    // All referenceable types should appear
+    $entity = field_test_create_stub_entity();
+    $form = drupal_get_form('field_test_entity_form', $entity);
+    $options = $form[$this->field_name][$langcode]['#options'];
+    // debug($options);
+    $this->assertTrue(isset($options['_none']), t('Empty choice offered for reference'), 'form');
+    unset($options['_none']);
+    foreach ($nodes as $node) {
+      $this->assertTrue(isset($options[$node->nid]),
+        t('Node of type @type is referenceable', array('@type' => $node->type)),
+        'form');
+      unset($options[$node->nid]);
+    }
+    $this->assertTrue(empty($options), t('No extra choice is referenceable'), 'form');
+  }
+}
