Skip to content

Commit

Permalink
Formatting and pass tests
Browse files Browse the repository at this point in the history
Fixed formatting for previous contributor commits. Fixed failing tests
due to new commits and PHPMailer behavior changes.
  • Loading branch information
soulseekah committed Jul 29, 2014
1 parent 3b3b2b0 commit d4ce066
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
39 changes: 18 additions & 21 deletions gravityforms-digest/gravityforms-digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private function process_post_request() {
$digest_export_all_fields = ( $_POST['form_notification_digest_export_fields'] == 'specified' ) ? false : true;
$digest_export_field_list = array();

if (!$digest_export_all_fields){
foreach($form['fields'] as $field){
if($_POST['form_notification_digest_field_'.$field['id']]){
if ( !$digest_export_all_fields ) {
foreach ( $form['fields'] as $field ) {
if ( $_POST['form_notification_digest_field_' . $field['id']] ) {
$digest_export_field_list[] = $field['id'];
}
}
Expand Down Expand Up @@ -258,15 +258,15 @@ public function add_notification_settings( $out ) {
<label for="form_notification_digest_export_fields">Export:</label>
<br>
<select id="form_notification_digest_export_fields" name="form_notification_digest_export_fields" onchange="if(jQuery(this).find(':selected').val() === 'specified') {jQuery('#form_notification_digest_fieldlist_container').show('fast');} else {jQuery('#form_notification_digest_fieldlist_container').hide('fast');};">
<option value="all" <?php selected($digest_export_all_fields); ?>>All fields</option>
<option value="specified" <?php selected(!$digest_export_all_fields); ?>>Specified fields only</option>
<option value="all" <?php selected( $digest_export_all_fields ); ?>>All fields</option>
<option value="specified" <?php selected( !$digest_export_all_fields ); ?>>Specified fields only</option>
</select>
<br>

<div id="form_notification_digest_fieldlist_container" style="display:<?php echo (!$digest_export_all_fields) ? "block" : "none"?>;">
<?php foreach( $form['fields'] as $field ): ?>
<input type="checkbox" name="form_notification_digest_field_<?php echo $field['id'] ?>" id="form_notification_digest_field_<?php echo $field['id'] ?>" value="1" <?php checked( in_array($field['id'], $digest_export_field_list) ); ?> />
<label for="form_notification_digest_field_<?php echo $field['id'] ?>"><?php echo $field['label'] ?></label>
<div id="form_notification_digest_fieldlist_container" style="display: <?php echo $digest_export_all_fields ? 'none' : 'block'; ?>;">
<?php foreach ( $form['fields'] as $field ): ?>
<input type="checkbox" name="form_notification_digest_field_<?php echo $field['id']; ?>" id="form_notification_digest_field_<?php echo $field['id']; ?>" value="1" <?php checked( in_array( $field['id'], $digest_export_field_list ) ); ?> />
<label for="form_notification_digest_field_<?php echo $field['id']; ?>"><?php echo esc_html( $field['label'] ); ?></label>
<br>
<?php endforeach; ?>
</div>
Expand Down Expand Up @@ -378,12 +378,12 @@ public function send_notifications( $form_id ) {

$headers = array( 'Date Submitted' );

if ($digest_export_all_fields){
foreach( $form['fields'] as $field )
if ( $digest_export_all_fields ) {
foreach ( $form['fields'] as $field )
if ( $field['label'] ) $headers []= $field['label'];
} else{
foreach( $form['fields'] as $field )
if ( $field['label'] && in_array($field['id'], $digest_export_field_list) ) $headers []= $field['label'];
} else {
foreach ( $form['fields'] as $field )
if ( $field['label'] && in_array( $field['id'], $digest_export_field_list ) ) $headers []= $field['label'];
}

fputcsv( $csv, $headers );
Expand All @@ -404,15 +404,12 @@ public function send_notifications( $form_id ) {
else
$to = $lead->date_created;

foreach( $form['fields'] as $field ) {
foreach ( $form['fields'] as $field ) {
if ( !$field['label'] ) continue;
if ( !$digest_export_all_fields && !in_array($field['id'],$digest_export_field_list) ) continue;
if ( !$digest_export_all_fields && !in_array( $field['id'], $digest_export_field_list ) ) continue;
$raw_data = RGFormsModel::get_lead_field_value( $lead_data, $field );
if(!is_array($raw_data)){
$data []= $raw_data;
} else {
$data []= implode(', ', array_filter($raw_data));
}
if( !is_array( $raw_data ) ) $data []= $raw_data;
else $data []= implode( ', ', array_filter( $raw_data ) );
}

fputcsv( $csv, $data );
Expand Down
10 changes: 9 additions & 1 deletion tests/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function test_reschedule_existing_simple() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = '';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand All @@ -70,6 +71,7 @@ public function test_reschedule_existing_groups() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = 'sales';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand All @@ -82,6 +84,7 @@ public function test_reschedule_existing_groups() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = 'sales';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand All @@ -102,6 +105,7 @@ public function test_reschedule_existing_groups() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'hourly';
$_POST['form_notification_digest_group'] = 'sales';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand All @@ -128,6 +132,7 @@ public function test_add_simple_schedule_settings() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = '';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init();

Expand Down Expand Up @@ -156,6 +161,7 @@ public function test_email_notification_simple() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = '';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand Down Expand Up @@ -186,6 +192,7 @@ public function test_email_notification_groups() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = 'sales';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand All @@ -198,6 +205,7 @@ public function test_email_notification_groups() {
$_POST['form_notification_digest_emails'] = 'testing@digests.lo, testing2@digests.lo, out@digests.lo';
$_POST['form_notification_digest_interval'] = 'minute';
$_POST['form_notification_digest_group'] = 'sales';
$_POST['form_notification_digest_export_fields'] = 'all';

$this->digest->init(); // TODO: A better way to add

Expand Down Expand Up @@ -228,7 +236,7 @@ public function test_email_notification_groups() {
$this->assertEquals( count( $phpmailer->mock_sent ), 3 );

/* Let's take a look here... (should be in a test of its own) */
preg_match( '#filename="(.*)"#', $phpmailer->mock_sent[0]['body'], $matches );
preg_match( '#filename="?(.*\.csv)"?#', $phpmailer->mock_sent[0]['body'], $matches );
$filename = sys_get_temp_dir() . '/' . $matches[1];
$csv = fopen( $filename, 'rb' );
$this->assertEquals( fgetcsv( $csv ), array( 'Form: Test Form (#1)' ) );
Expand Down

0 comments on commit d4ce066

Please sign in to comment.