### Eclipse Workspace Patch 1.0
#P faq
Index: faq.test
===================================================================
RCS file: faq.test
diff -N faq.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ faq.test	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,268 @@
+<?php
+
+// $Id: block.test,v 1.1.2.1.2.3 2009/05/27 19:13:43 boombatower Exp $
+/**
+ * @file
+ * Testing basic functionality of the FAQ module
+ */
+
+
+/**
+ * Test Taxonomy Functionality
+ */
+class TaxonomyTestCase extends DrupalWebTestCase {
+
+  protected $admin_user;
+
+  public static function getInfo() {
+    return array(
+      'name' => t('Taxonomy functionality'),
+      'description' => t('Add Taxonomy Vocabulary.'),
+      'group' => t('Taxonomy'),
+    );
+  }
+
+  function setUp() {
+    parent::setUp('taxonomy', 'faq');
+//    parent::setUp('faq');
+  }
+
+  function tearDown() {
+    parent::tearDown();
+  }
+
+  function testAddVocabulary() {
+    // Create and log in user with create FAQ permissions
+    $this->admin_user = $this->drupalCreateUser(array('administer taxonomy'));
+    $this->drupalLogin($this->admin_user);
+
+  $tax = array();
+  $tax['name'] = $this->randomName(8);	// Create taxonomy vocabulary name
+  $tax['description'] = $this->randomName(64);
+  $tax['nodes[faq]'] = '1';
+  $tax['tags'] = '1';
+  $tax['multiple'] = '1';
+  $tax['required'] = '1';
+  $this->drupalPost('admin/content/taxonomy/add/vocabulary', $tax, t('Save'));
+  $this->assertText(t('Created new vocabulary @name', array('@name' => $tax['name'])));
+  $this->assertText(t('FAQ'));
+
+  // Add term
+    $this->clickLink(t('add terms'));
+    $this->assertText(t('Add term to @name', array('@name' => $tax['name']) ));
+
+  $url = $this->getUrl();
+  $term = array();
+  $term['name'] = $this->randomName(8);	// Create taxonomy vocabulary name
+  $term['description'] = $this->randomName(64);
+  $this->drupalPost($url, $term, t('Save'));
+  $this->assertText(t('Created new term @name', array('@name' => $term['name'])));
+
+
+  }
+
+}
+
+
+/**
+ * Test FAQ functionality
+ */
+class FaqTestCase extends DrupalWebTestCase {
+
+  protected $admin_user;
+  protected $tax;
+  protected $term, $faq1, $faq2;
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('FAQ functionality'),
+      'description' => t('Add, Edit and delete FAQ nodes.'),
+      'group' => t('FAQ'),
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+
+  // Install FAQ Module
+    parent::setUp('taxonomy','faq');
+
+  }
+
+  /**
+   * Tear the whole thing down again
+   */
+  function tearDown() {
+
+    // Things to tidy up like vars and stuff
+    parent::tearDown();
+  }
+
+ /**
+   * Verify that current user has no access to page.
+   *
+   * @param $url
+   *   URL to verify.
+   */
+  function faqVerifyNoAccess($url) {
+    // Test that page returns 403 Access Denied
+    $this->drupalGet($url);
+    $this->assertResponse(403);
+  }
+
+  /**
+   * Set up the taxonomy - all vocabularies and stuff
+   * Values also stored in protected variable $tax
+   */
+  function setupTaxonomy() {
+
+    // Create and log in user with administer taxonomy permissions
+    $this->admin_user = $this->drupalCreateUser(array('administer taxonomy'));
+    $this->drupalLogin($this->admin_user);
+
+  // Create Vocabulary
+  $this->tax = array();
+  $this->tax['name'] = $this->randomName(8);	// Create taxonomy vocabulary name
+  $this->tax['description'] = $this->randomName(64);
+  $this->tax['nodes[faq]'] = '1';	// Assign vocab to FAQ node types
+  $this->tax['tags'] = '1';			// Users may create tags
+  $this->tax['multiple'] = '1';		// may have more than one tag
+  $this->tax['required'] = '1';		// but minimum 1 tag
+  $this->drupalPost('admin/content/taxonomy/add/vocabulary', $this->tax, t('Save'));
+  $this->assertText(t('Created new vocabulary @name', array('@name' => $this->tax['name'])));
+
+  $this->assertText(t('FAQ'));
+
+  // Add term
+    $this->clickLink(t('add terms'), substr_count($this->drupalGetContent(), "add terms")-1); // Click the last occurrance of the link
+    $this->assertText(t('Add term to @name', array('@name' => $this->tax['name']) ));
+
+  $url = parse_url($this->getUrl());
+  $array = split("/", $url['path']);
+  $this->tax['id'] = $array[2];
+  $this->pass(var_export($array, TRUE));
+
+  $url = $this->getUrl();
+  $this->term = array();
+  $this->term['name'] = $this->randomName(8);	// Create taxonomy vocabulary name
+  $this->term['description'] = $this->randomName(64);
+  $this->drupalPost($url, $this->term, t('Save'));
+  $this->assertText(t('Created new term @name', array('@name' => $this->term['name'])));
+
+  // Log out user creating taxonomy
+    $this->drupalLogout();
+  }
+
+  /**
+   * Test accessing the FAQ page
+   */
+
+  function testFaqAccess() {
+
+  // Verify that anonymous user has no access to the faq page
+  $this->faqVerifyNoAccess('faq');
+
+    // Create and login user
+    $normal_user = $this->drupalCreateUser();
+    $this->drupalLogin($normal_user);
+  // Verify that logged in user has no access to the faq page
+  $this->faqVerifyNoAccess('faq');
+    $this->drupalLogout();
+
+    $view_faq_user = $this->drupalCreateUser(array('view faq page'));
+    $this->drupalLogin($view_faq_user);
+
+  // Verify that the faq page is visible and available but empty
+    $this->drupalGet('faq');
+  $this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
+
+  }
+
+
+  /**
+   * Test creating a FAQ node
+   */
+
+  function testFaqCreate() {
+
+  $this->setupTaxonomy();
+
+    // Create and log in user with create FAQ permissions
+    $this->admin_user = $this->drupalCreateUser(array('create faq', 'view faq page'));
+    $this->drupalLogin($this->admin_user);
+
+  // Verify that the faq page is visible and available but empty
+    $this->drupalGet('faq');
+  $this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
+
+  // Fill in the Create FAQ node 1 form and post it
+    $this->faq1 = array();
+    $this->faq1['title'] = $this->randomName(8);
+    $this->faq1['taxonomy[tags][1]'] = $this->term['name'];		// Add existing term
+    $this->faq1['detailed_question'] = $this->randomName(16);
+    $this->faq1['body'] = $this->randomName(16);
+    $this->drupalPost('node/add/faq', $this->faq1, t('Save'));
+
+  // Check that new FAQ node has actually been created
+    $this->assertText(t('FAQ @title has been created.', array('@title' => $this->faq1['title'])));
+
+  // Fill in the Create FAQ node 2 form and post it
+    $this->faq2 = array();
+    $this->faq2['title'] = $this->randomName(8);
+    $this->faq2['taxonomy[tags][1]'] = $this->randomName(8);		// Add new term
+    $this->faq2['detailed_question'] = $this->randomName(16);
+    $this->faq2['body'] = $this->randomName(16);
+    $this->drupalPost('node/add/faq', $this->faq2, t('Save'));
+
+  // Check that new FAQ node has actually been created
+    $this->assertText(t('FAQ @title has been created.', array('@title' => $this->faq2['title'])));
+
+
+    // New user
+    $this->drupalLogout();
+
+
+  // Verify that logged in user has no access to the faq page
+  $this->faqVerifyNoAccess('faq');
+
+    // Check that the FAQ page is available and that the correct term is listed as grouping for the new FAQ node
+    $view_faq_user = $this->drupalCreateUser(array('view faq page'));
+    $this->drupalLogin($view_faq_user);
+    $this->drupalGet('faq');
+  $this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
+  $this->assertText($this->faq1['title'], t('Created FAQ node 1 available on FAQ page.'));
+  $this->assertNoText($this->faq1['taxonomy[tags][1]'], t('Term for node 1 not available on FAQ page.'));
+  $this->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
+  $this->assertNoText($this->faq2['taxonomy[tags][1]'], t('Term for node 2 not available on FAQ page.'));
+
+  // Navigate to FAQ node created on FAQ page
+    $this->clickLink(t($this->faq1['title']));
+    $this->assertText(t($this->faq1['body']));
+
+  // Enable categorisation of FAQ nodes
+    // Create and log in user with create and administer FAQ permissions
+    $this->admin_user = $this->drupalCreateUser(array('create faq', 'view faq page', 'administer faq'));
+    $this->drupalLogin($this->admin_user);
+
+  // faq_use_categories
+  $faqcfg = array();
+  $faqcfg['faq_use_categories'] = '1';	// Enable categorised FAQs
+  $this->drupalPost('admin/settings/faq/categories', $faqcfg, t('Save configuration'));
+    $this->drupalLogout();
+
+    $this->drupalLogin($view_faq_user);
+    $this->drupalGet('faq');
+  $this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
+  $this->assertText($this->faq1['title'], t('Created FAQ node 1 available on FAQ page.'));
+  $this->assertText($this->faq1['taxonomy[tags][1]'], t('Term for node 1 not available on FAQ page.'));
+  $this->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
+  $this->assertText($this->faq2['taxonomy[tags][1]'], t('Term for node 2 not available on FAQ page.'));
+
+  }
+}
+
