Index: job_posting.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/job_posting/job_posting.module,v retrieving revision 1.9.2.4 diff -u -r1.9.2.4 job_posting.module --- job_posting.module 23 May 2008 18:43:28 -0000 1.9.2.4 +++ job_posting.module 23 Jun 2008 21:40:46 -0000 @@ -1,4 +1,4 @@ - array( - 'name' => t('Job Posting'), - 'module' => 'job_posting', - 'description' => t('Create a job posting announcement.'), - 'has_title' => TRUE, - 'title_label' => t('Position'), - 'has_body' => TRUE, - 'body_label' => t('Description'), - 'locked' => TRUE, - ), - ); -} - -/** - * Implementation of hook_perm() - */ -function job_posting_perm() { + */ + +/** + * @file job_posting.module + * Main module file + */ + +/** + * Implementation of hook_node_info() + */ +function job_posting_node_info() { + // declare our node types return array( - 'create job posting', - 'edit job posting', + 'job_posting' => array( + 'name' => t('Job Posting'), + 'module' => 'job_posting', + 'description' => t('Create a job posting announcement.'), + 'has_title' => TRUE, + 'title_label' => t('Position'), + 'has_body' => TRUE, + 'body_label' => t('Description'), + 'locked' => TRUE, + ), + ); +} + +/** + * Implementation of hook_perm() + */ +function job_posting_perm() { + return array( + 'create job posting', + 'edit job posting', 'edit own job posting', - ); + ); } - -/** - * Implementation of hook_access() - */ -function job_posting_access($op, $node) { + +/** + * Implementation of hook_access() + */ +function job_posting_access($op, $node) { global $user; - switch ($op) { - case 'create': - return user_access('create job posting'); - case 'update': // same as delete - case 'delete': - if ((user_access('edit job posting')) || (user_access('edit own job posting') && - ($user->uid == $node->uid))) { - return TRUE; - } + switch ($op) { + case 'create': + return user_access('create job posting'); + case 'update': // same as delete + case 'delete': + if ((user_access('edit job posting')) || (user_access('edit own job posting') && + ($user->uid == $node->uid))) { + return TRUE; + } break; - } + } } /** @@ -179,11 +179,11 @@ drupal_set_message(t('Settings have been saved.')); } -/** - * Implementation of hook_form() - */ -function job_posting_form(&$node) { - $type = node_get_types('type', $node); +/** + * Implementation of hook_form() + */ +function job_posting_form(&$node) { + $type = node_get_types('type', $node); // build select options list for countries $countries = array(0 => t('--')); @@ -215,27 +215,27 @@ information needed to handle job posting display and processing.'), '#weight' => -10, ); - if ($type->has_title) { - $form['required']['title'] = array( - '#type' => 'textfield', - '#title' => check_plain($type->title_label), - '#description' => t('Provide the job title or position'), - '#required' => TRUE, - '#default_value' => $node->title, + if ($type->has_title) { + $form['required']['title'] = array( + '#type' => 'textfield', + '#title' => check_plain($type->title_label), + '#description' => t('Provide the job title or position'), + '#required' => TRUE, + '#default_value' => $node->title, '#weight' => -10, - ); - } - if ($type->has_body) { - $form['required']['body_filter']['body'] = array( - '#type' => 'textarea', - '#title' => check_plain($type->body_label), - '#description' => t('Provide detailed description for this job posting'), - '#required' => TRUE, - '#default_value' => $node->body, - '#weight' => -2, ); - $form['required']['body_filter']['filter'] = filter_form($node->format); - } + } + if ($type->has_body) { + $form['required']['body_filter']['body'] = array( + '#type' => 'textarea', + '#title' => check_plain($type->body_label), + '#description' => t('Provide detailed description for this job posting'), + '#required' => TRUE, + '#default_value' => $node->body, + '#weight' => -2, + ); + $form['required']['body_filter']['filter'] = filter_form($node->format); + } $form['required']['job_posting_email'] = array( '#type' => 'textfield', '#title' => t('Email address'), @@ -319,13 +319,13 @@ '#description' => t('The geographical location associated with this job posting.'), '#weight' => -10, ); - $form['optional']['location']['job_posting_city'] = array( - '#type' => 'textfield', - '#title' => t('City'), - '#description' => t('Provide the city location for this job posting'), - '#required' => FALSE, - '#default_value' => $node->job_posting_city, - '#weight' => -6, + $form['optional']['location']['job_posting_city'] = array( + '#type' => 'textfield', + '#title' => t('City'), + '#description' => t('Provide the city location for this job posting'), + '#required' => FALSE, + '#default_value' => $node->job_posting_city, + '#weight' => -6, ); $form['optional']['location']['job_posting_state'] = array( '#type' => 'textfield', @@ -376,7 +376,7 @@ '#default_value' => $node->job_posting_contact, '#weight' => -1, ); - return $form; + return $form; } /** @@ -422,9 +422,9 @@ } } -/** - * Implementation of hook_load() - */ +/** + * Implementation of hook_load() + */ function job_posting_load($node) { return db_fetch_object(db_query( 'SELECT nid, vid, city AS job_posting_city, state AS job_posting_state, @@ -435,12 +435,12 @@ FROM {job_posting} WHERE nid = %d', $node->nid) ); -} - -/** - * Implementation of hook_view() - */ -function job_posting_view($node, $teaser = FALSE, $page = FALSE) { +} + +/** + * Implementation of hook_view() + */ +function job_posting_view($node, $teaser = FALSE, $page = FALSE) { // add module-specific styles drupal_add_css(drupal_get_path('module', 'job_posting') .'/job-posting.css'); // do country name lookup, if required @@ -655,12 +655,12 @@ } } -/** - * Implementation of hook_insert() - */ -function job_posting_insert($node) { +/** + * Implementation of hook_insert() + */ +function job_posting_insert($node) { db_query("INSERT INTO {job_posting} - (nid, vid, city, state, cid, contact, email, employer, website, deadline, expires) + (nid, vid, city, state, cid, contact, email, employer, website, deadline, expires) VALUES (%d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d, %d)", $node->nid, $node->vid, $node->job_posting_city, $node->job_posting_state, $node->job_posting_cid, $node->job_posting_contact, $node->job_posting_email, @@ -673,21 +673,21 @@ ) ), $node->job_posting_expires - ); -} - -/** - * Implementation of hook_update() - */ -function job_posting_update($node) { - if ($node->revision) { - job_posting_insert($node); + ); +} + +/** + * Implementation of hook_update() + */ +function job_posting_update($node) { + if ($node->revision) { + job_posting_insert($node); } - else { - db_query("UPDATE {job_posting} + else { + db_query("UPDATE {job_posting} SET city = '%s', state = '%s', cid = %d, contact = '%s', email = '%s', - employer = '%s', website = '%s', deadline = %d, expires = %d - WHERE nid = %d", + employer = '%s', website = '%s', deadline = %d, expires = %d + WHERE nid = %d", $node->job_posting_city, $node->job_posting_state, $node->job_posting_cid, $node->job_posting_contact, $node->job_posting_email, $node->job_posting_employer, $node->job_posting_url, @@ -699,32 +699,32 @@ ) ), $node->job_posting_expires, - $node->nid - ); - } -} - -/** - * Implementation of hook_delete() - */ -function job_posting_delete($node) { - db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); -} - -/** - * Implementation of hook_nodeapi() - */ -function job_posting_nodeapi(&$node, $op, $teaser, $page) { - switch ($op) { - // remove row if its corresponding node gets deleted - case 'delete': - db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); - break; - // remove row if its corresponding revision gets deleted - case 'delete revision': - db_query('DELETE FROM {job_posting} WHERE vid = %d', $node->vid); - break; - } + $node->nid + ); + } +} + +/** + * Implementation of hook_delete() + */ +function job_posting_delete($node) { + db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); +} + +/** + * Implementation of hook_nodeapi() + */ +function job_posting_nodeapi(&$node, $op, $teaser, $page) { + switch ($op) { + // remove row if its corresponding node gets deleted + case 'delete': + db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); + break; + // remove row if its corresponding revision gets deleted + case 'delete revision': + db_query('DELETE FROM {job_posting} WHERE vid = %d', $node->vid); + break; + } } /** @@ -777,6 +777,16 @@ } /** +* Implementation of hook_simpletest(). +*/ +function job_posting_simpletest() { + $module_name = 'job_posting'; + $dir = drupal_get_path('module', $module_name). '/tests'; + $tests = file_scan_directory($dir, '\.test$'); + return array_keys($tests); +} + +/** * Provide paginated listing pages for all published job posting nodes * * @return string $page_content html @@ -806,8 +816,8 @@ $page_content .= theme('pager', NULL, $limit); } return theme('job_posting_list_display', $page_content); -} - +} + /** * Theme function for job posting node display * Index: tests/job_posting_module.test =================================================================== RCS file: tests/job_posting_module.test diff -N tests/job_posting_module.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/job_posting_module.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,104 @@ + t('Job setting node creation'), + 'desc' => t('Creating a node and checking its consistency in the database.'), + 'group' => t('Other'), + ); + } + + // username validation + function testPageCreation() { + /* Prepare settings */ + $this->drupalVariableSet('job_setting_options_page', array('status', 'promote')); + + /* Prepare a user to do the stuff */ + $web_user = $this->drupalCreateUserRolePerm(array('edit own job posting', 'create job posting')); + $web_user->mail = $web_user->name .'@example.com'; + + $this->drupalLoginUser($web_user); + + $edit = array(); + + + $edit['title'] = '!SimpleTest test node! ' . $this->randomName(10); + $edit['job_posting_email'] = $this->randomName(10) .'@example.com'; + $edit['job_posting_expires'] = TRUE; + $edit['job-posting-deadline-date-month'] = '12'; + $edit['job-posting-deadline-date-day'] = '1'; + $edit['job-posting-deadline-date-year'] = '2009'; + $edit['job-posting-deadline-hour'] = '0'; + + $edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32); + $this->drupalPostRequest('node/add/job-posting', $edit, 'Submit'); + + $this->assertWantedRaw(t('Your %post has been created.', array ('%post' => 'Job Posting')), 'Job Posting added'); + + $node = node_load(array('title' => $edit['title'])); + $this->assertNotNull($node, 'Node found in database. %s'); + } + +} + +class JobPostingModuleTestApplication extends DrupalTestCase { + + function get_info() { + return array( + 'name' => t('Applying for a job'), + 'desc' => t('Submitting an application on a created job.'), + 'group' => t('Other'), + ); + } + + // username validation + function testPageCreation() { + /* Prepare settings */ + $this->drupalVariableSet('job_setting_options_page', array('status', 'promote')); + + /* Prepare a user to do the stuff */ + $web_user = $this->drupalCreateUserRolePerm(array('edit own job posting', 'create job posting')); + $web_user->mail = $web_user->name .'@example.com'; + $this->drupalLoginUser($web_user); + + $edit = array(); + + + $edit['title'] = '!SimpleTest test node! ' . $this->randomName(10); + $edit['job_posting_email'] = $this->randomName(10) .'@example.com'; + $edit['job_posting_expires'] = TRUE; + $edit['job-posting-deadline-date-month'] = '12'; + $edit['job-posting-deadline-date-day'] = '1'; + $edit['job-posting-deadline-date-year'] = '2009'; + $edit['job-posting-deadline-hour'] = '0'; + + $edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32); + + $this->drupalPostRequest('node/add/job-posting', $edit, 'Submit'); + + $this->assertWantedRaw(t('Your %post has been created.', array ('%post' => 'Job Posting')), 'Job Posting added'); + + $node = node_load(array('title' => $edit['title'])); + $this->assertNotNull($node, 'Node found in database. %s'); + + $nid = $node->nid; + + /* Prepare a second user to apply for a job */ + $web_user2 = $this->drupalCreateUserRolePerm(array('edit own job posting', 'create job posting')); + $this->drupalLoginUser($web_user2); + + $edit2 = array(); + + $edit2['job-posting-coverletter'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32); + + $this->drupalPostRequest("job/application/node/$nid", $edit2, 'Send'); + + $this->assertWantedRaw(t('Your application has been submitted. Thank you.', array ()), 'Application submitted'); + } + +} + +?>