123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- <?php
- class FaqTestCase extends DrupalWebTestCase {
- protected $admin_user, $faq_user;
- protected $taxonomy;
- protected $term, $faq1, $faq2;
-
- public static function getInfo() {
- return array(
- 'name' => t('FAQ functionality'),
- 'description' => t('Base class. No tests here.'),
- 'group' => t('Frequently Asked Questions'),
- );
- }
-
- function setUp() {
-
- parent::setUp('taxonomy', 'faq');
-
- $this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'administer faq', 'administer faq order', 'administer blocks'));
- $this->drupalLogin($this->admin_user);
- $this->faq_user = $this->drupalCreateUser(array('create faq content', 'edit any faq content', 'delete any faq content', 'view faq page', 'access content'));
-
- $this->setupTaxonomy();
-
- $this->drupalPost('admin/config/content/faq/categories', array('faq_use_categories' => '1'), t('Save configuration'));
-
- $roles = $this->faq_user->roles;
- end($roles);
-
- $this->drupalLogout();
- }
-
- function tearDown() {
-
- parent::tearDown();
- }
-
- protected static function randomNumber($length = 8) {
- $str = '';
- for ($i = 0; $i < $length; $i++) {
- $str .= chr(mt_rand(48, 57));
- }
- return $str;
- }
-
- function faqVerifyNoAccess($url) {
-
- $this->drupalGet($url);
- $this->assertResponse(403);
- }
-
- function setupTaxonomy() {
-
- $this->vocabulary = $vocabulary = new stdClass();
- $vocabulary->name = $this->randomName(8);
- $vocabulary->description = $this->randomName(64);
- $vocabulary->machine_name = drupal_strtolower($this->randomName());
- $vocabulary->help = '';
- $vocabulary->nodes = array('faq' => 'faq');
- $vocabulary->weight = mt_rand(0, 10);
- taxonomy_vocabulary_save($vocabulary);
- $field = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($field);
- $this->instance = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'bundle' => 'faq',
- 'entity_type' => 'node',
- 'widget' => array(
- 'type' => 'taxonomy_autocomplete',
- ),
- 'display' => array(
- 'default' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
-
-
- $this->term = $term = new stdClass();
- $term->name = $this->randomName(8);
- $term->description = $this->randomName(64);
-
- $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField();
- $term->vid = $vocabulary->vid;
- taxonomy_term_save($term);
- }
-
- }
- class FaqAccessTestClass extends FaqTestCase {
-
- public static function getInfo() {
- return array(
- 'name' => t('Access to FAQ pages'),
- 'description' => t('Access to pages by anonymous user and logged in user with rights.'),
- 'group' => t('Frequently Asked Questions'),
- );
- }
- function testFaqAccess() {
-
- $this->faqVerifyNoAccess('faq-page');
-
- $normal_user = $this->drupalCreateUser();
- $this->drupalLogin($normal_user);
-
- $this->faqVerifyNoAccess('faq-page');
- $this->drupalLogout();
- $view_faq_user = $this->drupalCreateUser(array('view faq page'));
- $this->drupalLogin($view_faq_user);
-
- $this->drupalGet('faq-page');
- $this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
- }
- }
- class CreateFaqTestCase extends FaqTestCase {
-
- public static function getInfo() {
- return array(
- 'name' => t('Create FAQ node'),
- 'description' => t('Add, edit and delete FAQ nodes when FAQ module is enabled.'),
- 'group' => t('Frequently Asked Questions'),
- );
- }
-
- function testFaqCreate() {
-
- $this->drupalLogin($this->admin_user);
-
- $this->drupalGet('admin/config/content/faq/questions');
-
- $this->drupalPost('admin/config/content/faq/questions', array('faq_question_long_form' => '1', 'faq_qa_mark' => '1'), t('Save configuration'));
- $this->drupalPost('admin/config/content/faq/questions', array('faq_question_length' => 'both'), t('Save configuration'));
- $this->afaq_user = $this->drupalCreateUser(array('create faq content', 'view faq page'));
- $this->drupalLogin($this->afaq_user);
-
- $this->drupalGet('faq-page');
- $this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
-
- $langcode = LANGUAGE_NONE;
- $this->faq1 = array();
- $this->faq1['title'] = 'faq1_'. $this->randomName(8);
- $this->faq1[$this->instance['field_name'] . '[' . $langcode .']'] = $this->term->name;
- $this->faq1["field_detailed_question[$langcode][0][value]"] = $this->randomName(16);
- $this->faq1["body[$langcode][0][value]"] = $this->randomName(16);
- $this->drupalPost('node/add/faq', $this->faq1, t('Save'));
-
- $this->assertText(t('FAQ @title has been created.', array('@title' => $this->faq1['title'])));
-
- $this->drupalGet('taxonomy/term/' . $this->term->tid);
- $this->assertText(t('@title', array('@title' => $this->faq1['title'])));
-
- $this->faq2 = array();
- $this->faq2['title'] = 'faq2_'. $this->randomName(8);
- $this->faq2[$this->instance['field_name'] . '[' . $langcode .']'] = $this->randomName(8);
- $this->faq2["field_detailed_question[$langcode][0][value]"] = $this->randomName(16);
- $this->faq2["body[$langcode][0][value]"] = $this->randomName(16);
- $this->drupalPost('node/add/faq', $this->faq2, t('Save'));
-
- $this->assertText(t('FAQ @title has been created.', array('@title' => $this->faq2['title'])));
-
- $this->drupalLogout();
-
- $this->faqVerifyNoAccess('faq-page');
-
- $view_faq_user = $this->drupalCreateUser(array('view faq page'));
- $this->drupalLogin($view_faq_user);
- $this->drupalGet('faq-page');
- $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[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 1 available on FAQ page.'));
- $this->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
- $this->assertText($this->faq2[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 2 available on FAQ page.'));
-
- $this->clickLink(t($this->faq1['title']));
- $this->assertText(t($this->faq1["field_detailed_question[$langcode][0][value]"]), t('Detailed question visible'));
- $this->assertText(t($this->faq1["body[$langcode][0][value]"]), t('Answer visible'));
-
-
- $this->admin_user = $this->drupalCreateUser(array('create faq content', 'view faq page', 'administer faq'));
- $this->drupalLogin($this->admin_user);
-
- $faqcfg = array();
- $faqcfg['faq_use_categories'] = '1';
- $this->drupalPost('admin/config/content/faq/categories', $faqcfg, t('Save configuration'));
- $this->drupalLogout();
- $this->drupalLogin($view_faq_user);
- $this->drupalGet('faq-page');
- $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[$this->instance['field_name'] . '[' . $langcode .']'], 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[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 2 not available on FAQ page.'));
-
- }
- }
- class CRAUDFaqTestCase extends FaqTestCase {
-
- public static function getInfo() {
- return array(
- 'name' => t('CRUD Question'),
- 'description' => t('Create, read, update and delete a question'),
- 'group' => t('Frequently Asked Questions'),
- );
- }
-
- public function testFaqCreate() {
-
- $this->faqVerifyNoAccess('faq-page');
-
- $this->drupalLogin($this->faq_user);
-
- $edit = array();
- $edit['title'] = $this->randomName(8);
- $edit[$this->instance['field_name'] . '['. LANGUAGE_NONE .']'] = $this->randomName(8);
- $edit['field_detailed_question['. LANGUAGE_NONE .'][0][value]'] = $this->randomName(64);
- $edit['body['. LANGUAGE_NONE .'][0][value]'] = $this->randomString(264);
- $this->drupalPost('node/add/faq', $edit, t('Save'));
- $this->assertText(t('FAQ @title has been created.', array('@title' => $edit['title'])));
-
- $node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertTrue($node->status);
- $this->drupalLogout();
-
-
- $this->drupalGet('node/' . $node->nid . '/edit');
-
-
- $faq_view_user = $this->drupalCreateUser(array('view faq page'));
- $this->drupalLogin($faq_view_user);
-
- $this->drupalGet('faq-page');
- $this->assertText($edit['title']);
- $this->drupalGet('node/' . $node->nid);
-
-
- $this->drupalLogin($this->faq_user);
- $edit2['title'] = 'title-' . $this->randomName(8);
- $edit2['body['. LANGUAGE_NONE .'][0][value]'] = 'body-' . $this->randomName(64);
- $this->drupalPost('node/' . $node->nid . '/edit', $edit2, t('Save'));
- $this->assertText(t('FAQ @title has been updated.', array('@title' => $edit2['title'])));
- $this->assertText($edit2['title'], 'Title has changed');
- $this->assertText($edit2['body['. LANGUAGE_NONE .'][0][value]'], 'Body has changed');
-
-
- $this->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
-
- $this->drupalLogin($this->admin_user);
- $this->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
- $this->assertText(t('Are you sure you want to delete @title?', array('@title' => $edit2['title'])));
- $this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
- $this->assertText(t('FAQ @title has been deleted.', array('@title' => $edit2['title'])));
- }
- }
|