? 918948_4_node_form_tests.patch
? 918948_5_node_form_tests.patch
Index: tests/biblio.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/biblio/tests/Attic/biblio.test,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 biblio.test
--- tests/biblio.test	13 Sep 2010 02:29:56 -0000	1.1.2.9
+++ tests/biblio.test	23 Sep 2010 18:28:20 -0000
@@ -88,3 +88,95 @@ class BiblioWebTestCase extends DrupalWe
     $this->assertEqual($count, 0, "There were $count differences between the two nodes");
   }
 }
+
+class BiblioNodeCreationTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Biblio node creation',
+      'description' => 'Create a biblio node and test saving it.',
+      'group' => 'Biblio',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('biblio');
+    $web_user = $this->drupalCreateUser(array('create biblio content'));
+    $this->drupalLogin($web_user);
+  }
+
+  /**
+   * Create a biblio node and verify its consistency in the database.
+   */
+  function testBiblioNodeCreation() {
+    // Create a node.
+    $edit = array();
+    $edit["biblio_type"] = '101';
+    $this->drupalPost('node/add/biblio', $edit, t('Next'));
+
+    // Check that the next step of the form appears.
+    $this->assertOptionSelected('edit-biblio-type', '101');
+    $this->assertFieldById('edit-title');
+    $this->assertFieldById('edit-biblio-year');
+
+    $edit = array(
+      'title' => $this->randomString(32),
+      'biblio_year' => '2009',
+      'biblio_contributors[1][0][name]' => 'Kevin Brown',
+      'biblio_contributors[1][1][name]' => 'Martin Clark',
+      'biblio_contributors[1][2][name]' => 'George Wei',
+      'biblio_keywords' => 'architecture, building, wood',
+    );
+    $this->drupalPost(NULL, $edit, t('Save'));
+
+    // Check that the Basic page has been created.
+    $this->assertRaw(t('!post %title has been created.', array('!post' => 'Biblio', '%title' => $edit["title"])), t('Biblio entry created.'));
+    $this->assertText(t('architecture, building, wood', array('!post' => 'Biblio', '%title' => $edit["title"])), t('Keywords are present on the biblio node.'));
+
+    // Check that the node exists in the database.
+    $node = $this->drupalGetNodeByTitle($edit['title']);
+    $this->assertTrue($node, t('Node found in database.'));
+  }
+}
+
+class BiblioPageViewTestCase extends BiblioWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Biblio node view and edit permissions',
+      'description' => 'Create a biblio node and test view / edit permissions.',
+      'group' => 'Biblio',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('biblio');
+  }
+
+  /**
+   * Creates a node and then an anonymous and unpermissioned user attempt to edit the node.
+   */
+  function testBiblioPageView() {
+    // Create a node to view.
+    $node = $this->createNode('101');
+    $this->assertTrue(node_load($node->nid), t('Node created.'));
+
+    // Try to edit with anonymous user.
+    $html = $this->drupalGet("node/$node->nid/edit");
+    $this->assertResponse(403);
+
+    // Create a user without permission to edit node.
+    $web_user = $this->drupalCreateUser(array('access content'));
+    $this->drupalLogin($web_user);
+
+    // Attempt to access edit page.
+    $this->drupalGet("node/$node->nid/edit");
+    $this->assertResponse(403);
+
+    // Create user with permission to edit node.
+    $web_user = $this->drupalCreateUser(array('edit any biblio content'));
+    $this->drupalLogin($web_user);
+
+    // Attempt to access edit page.
+    $this->drupalGet("node/$node->nid/edit");
+    $this->assertResponse(200);
+  }
+}
