Skip to content

Commit

Permalink
Add basic tests for job details in emails
Browse files Browse the repository at this point in the history
  • Loading branch information
jom committed Apr 11, 2018
1 parent 8e851a1 commit 6f65ca7
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public function setUp() {
defined( 'PHPUNIT_WPJM_TESTSUITE' ) || define( 'PHPUNIT_WPJM_TESTSUITE', true );
parent::setUp();
reset_phpmailer_instance();
update_option( 'job_manager_enable_categories', 1 );
update_option( 'job_manager_enable_types', 1 );
add_theme_support( 'job-manager-templates' );
unregister_post_type( 'job_listing' );
$post_type_instance = WP_Job_Manager_Post_Types::instance();
$post_type_instance->register_post_types();
WP_Job_Manager_Email_Notifications::_clear_deferred_notifications();
}

Expand Down Expand Up @@ -188,6 +194,28 @@ public function test_get_template_file_name_rich() {
$this->assertEquals( "emails/{$template_name}.php", WP_Job_Manager_Email_Notifications::get_template_file_name( $template_name, false ) );
}

/**
* @covers WP_Job_Manager_Email_Notifications::output_job_details()
* @covers WP_Job_Manager_Email_Notifications::get_job_detail_fields()
*/
public function test_output_job_details() {
add_filter( 'job_manager_email_notifications', array( $this, 'inject_email_config_valid_email' ) );
$emails = WP_Job_Manager_Email_Notifications::get_email_notifications( false );
remove_filter( 'job_manager_email_notifications', array( $this, 'inject_email_config_valid_email' ) );
$email = $emails['valid-email'];
$job = $this->get_valid_job();

ob_start();
WP_Job_Manager_Email_Notifications::output_job_details( $job, $email, true, true );
$content = ob_get_clean();
$this->assertContains( 'Job title: ' . $job->post_title, $content );
$this->assertContains( 'Location: ' . $job->_job_location, $content );
$this->assertContains( 'Job type: Full Time', $content );
$this->assertContains( 'Job category: Weird', $content );
$this->assertContains( 'Company name: ' . $job->_company_name, $content );
$this->assertContains( 'Company website: ' . $job->_company_website, $content );
}

/**
* Helper Methods
*/
Expand All @@ -211,6 +239,25 @@ public function inject_email_config_valid_email( $emails ) {
return $emails;
}

protected function get_valid_job() {
$full_time_term = wp_create_term( 'Full Time', 'job_listing_type' );
$weird_cat_term = wp_create_term( 'Weird', 'job_listing_category' );
$job_args = array(
'post_title' => 'Job Post-' . md5( microtime( true ) ),
'post_content' => 'Job Description-' . md5( microtime( true ) ),
'meta_input' => array(
'_job_location' => 'Job Location-' . md5( microtime( true ) ),
'_company_name' => 'Company-' . md5( microtime( true ) ),
'_company_website' => 'http://' . md5( microtime( true ) ) .'.com',
),
'tax_input' => array(
'job_listing_type' => $full_time_term['term_id'],
'job_listing_category' => $weird_cat_term['term_id'],
),
);
return get_post( $this->factory->job_listing->create( $job_args ) );
}

/**
* @param array $core_email_class
*/
Expand Down

0 comments on commit 6f65ca7

Please sign in to comment.