jenkins-bot has submitted this change and it was merged.

Change subject: Move test code to test support
......................................................................


Move test code to test support

Remove 'add a random message' feature from UI, fix description of
connectivity test.

Bug: T133712
Change-Id: I490e0ac4d2aa7691809802f5c5bc1ada9ab82504
---
M sites/all/modules/queue2civicrm/queue2civicrm.module
M sites/all/modules/queue2civicrm/tests/includes/Message.php
M sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
3 files changed, 49 insertions(+), 111 deletions(-)

Approvals:
  Awight: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/queue2civicrm/queue2civicrm.module 
b/sites/all/modules/queue2civicrm/queue2civicrm.module
index 57b9e82..d38ab90 100644
--- a/sites/all/modules/queue2civicrm/queue2civicrm.module
+++ b/sites/all/modules/queue2civicrm/queue2civicrm.module
@@ -26,18 +26,9 @@
 
   $items['admin/config/queue2civicrm/test'] = array(
     'title' => 'Test',
-    'description' => 'Run a test message through the queue.',
+    'description' => 'Test queue connectivity.',
     'access arguments' => array('administer queue2civicrm'),
     'page callback' => 'queue2civicrm_test',
-  );
-
-  $items['admin/config/queue2civicrm/insert'] = array(
-    'title' => 'Insert item',
-    'description' => 'Insert a message into the queue.',
-    'access arguments' => array('administer queue2civicrm'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('queue2civicrm_insertmq_form'),
-    'weight' => 10,
   );
 
   return $items;
@@ -308,103 +299,4 @@
         $msg = $msg + $data;
     }
     return $pending;
-}
-
-/**
- * Make the form to insert a test message into the queue
- */ 
-function queue2civicrm_insertmq_form() {
-  $message = queue2civicrm_generate_message();
-
-  $form['submit1'] = array(
-    '#value' => 'Insert into queue',
-    '#type' => 'submit'
-  );
-  
-  $form['queue'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Queue to submit to',
-    '#default_value' => variable_get( 'queue2civicrm_subscription', 
'/queue/test_donations' ),
-    '#required' => TRUE
-  );
-  
-  foreach ( $message as $key => $value ) {
-    $form[$key] = array(
-      '#type' => 'textfield',
-      '#title' => $key,
-      '#default_value' => $value
-    );
-  }
-
-  $form['submit2'] = array(
-    '#value' => 'Insert into queue',
-    '#type' => 'submit'
-  );
-
-  return $form;
-}
-
-/** 
- * Implementation of hook_form_submit
- *
- * Submits a test message to the queue
- */
-function queue2civicrm_insertmq_form_submit($form, &$form_state) {
-    $q = queue2civicrm_stomp();
-         $result = $q->enqueue( drupal_json_encode($form_state['values']), 
array('persistent' => true), $form_state['values']['queue'] );
-         $q->disconnect();
-         if (!$result) {
-      watchdog('queue2civicrm','Send to queue failed for this message: <pre>' 
. check_plain(print_r($form_state['values'], TRUE)) . '</pre>');
-      $content = 'Failed to add item to the queue.';
-      drupal_set_message($content, 'error');
-    }
-         $content = 'Success adding item to the queue!';
-         watchdog('queue2civicrm','Successfully added the following to the 
queue: <pre>' . check_plain(print_r($form_state['values'], TRUE)) . '</pre>');
-         drupal_set_message($content);
-}
-
-/**
- * Generates random data for queue and donation insertion testing
- */
-function queue2civicrm_generate_message() {
-  //language codes
-  $lang = array('en','de','fr');
-
-  $currency_codes = array('USD', 'GBP', 'EUR', 'ILS');
-  shuffle($currency_codes);
-  $currency = (mt_rand(0,1)) ? 'USD' : $currency_codes[0];
-  
-  $message = array(
-       'contribution_tracking_id' => '',
-       'optout'                 => mt_rand(0,1),
-       'anonymous'              => mt_rand(0,1),
-       'comment'                => mt_rand(),
-       'utm_source'             => mt_rand(),
-       'utm_medium'             => mt_rand(),
-       'utm_campaign'           => mt_rand(),
-       'language'               => $lang[array_rand($lang)],
-       'referrer'               => 'http://example.com/'.mt_rand(),
-       'email'                  => mt_rand() . '@example.com',
-       'first_name'             => mt_rand(),
-       'middle_name'            => mt_rand(),
-       'last_name'              => mt_rand(),
-       'street_address'         => mt_rand(),
-       'supplemental_address_1' => '',
-       'city'                   => 'San Francisco',
-       'state_province'         => 'CA',
-       'country'                => 'USA',
-       'countryID'              => 'US',
-       'postal_code'            => mt_rand(02801,99999),
-       'gateway'                => 'insert_test',
-       'gateway_txn_id'         => mt_rand(),
-       'response'               => mt_rand(),
-       'currency'               => $currency,
-       'original_currency'      => $currency_codes[0],
-       'original_gross'         => mt_rand(0,10000)/100,
-       'fee'                    => '0',
-       'gross'                  => mt_rand(0,10000)/100,
-       'net'                    => mt_rand(0,10000)/100,
-       'date'                   => date('r'), //time(),
-  );
-  return $message;
 }
diff --git a/sites/all/modules/queue2civicrm/tests/includes/Message.php 
b/sites/all/modules/queue2civicrm/tests/includes/Message.php
index 39341d0..3a68e67 100644
--- a/sites/all/modules/queue2civicrm/tests/includes/Message.php
+++ b/sites/all/modules/queue2civicrm/tests/includes/Message.php
@@ -42,6 +42,52 @@
             $this->defaults = json_decode( file_get_contents( $path ), true );
         }
     }
+
+    /**
+     * Generates random data for queue and donation insertion testing
+     */
+    public static function generateRandom() {
+        //language codes
+        $lang = array( 'en', 'de', 'fr' );
+
+        $currency_codes = array( 'USD', 'GBP', 'EUR', 'ILS' );
+        shuffle( $currency_codes );
+        $currency = ( mt_rand( 0, 1 ) ) ? 'USD' : $currency_codes[0];
+
+        $message = array(
+            'contribution_tracking_id' => '',
+            'optout' => mt_rand( 0, 1 ),
+            'anonymous' => mt_rand( 0, 1 ),
+            'comment' => mt_rand(),
+            'utm_source' => mt_rand(),
+            'utm_medium' => mt_rand(),
+            'utm_campaign' => mt_rand(),
+            'language' => $lang[array_rand( $lang )],
+            'referrer' => 'http://example.com/' . mt_rand(),
+            'email' => mt_rand() . '@example.com',
+            'first_name' => mt_rand(),
+            'middle_name' => mt_rand(),
+            'last_name' => mt_rand(),
+            'street_address' => mt_rand(),
+            'supplemental_address_1' => '',
+            'city' => 'San Francisco',
+            'state_province' => 'CA',
+            'country' => 'USA',
+            'countryID' => 'US',
+            'postal_code' => mt_rand( 2801, 99999 ),
+            'gateway' => 'insert_test',
+            'gateway_txn_id' => mt_rand(),
+            'response' => mt_rand(),
+            'currency' => $currency,
+            'original_currency' => $currency_codes[0],
+            'original_gross' => mt_rand( 0, 10000 ) / 100,
+            'fee' => '0',
+            'gross' => mt_rand( 0, 10000 ) / 100,
+            'net' => mt_rand( 0, 10000 ) / 100,
+            'date' => date( 'r' ), //time(),
+        );
+        return $message;
+    }
 }
 
 class TransactionMessage extends Message {
diff --git a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php 
b/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
index 6693c36..cd845fe 100644
--- a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
+++ b/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
@@ -21,7 +21,7 @@
         $this->emptyQueue();
         //queue2civicrm_insertmq_form_submit($form, &$form_state) 
$form_state['values'] appears to be where all the $key=>$value form pairs live.
         ////Just fake it out. :p queue2civicrm_generate_message() will do 
nicely.
-        $message = queue2civicrm_generate_message();
+        $message = Message::generateRandom();
         //I think we want gateway_txn_id and contribution_tracking_id to match 
much the same way we did before.
         $message['gateway_txn_id'] = "civiTest";
         $message['contribution_tracking_id'] = $message['gateway_txn_id'];
@@ -147,7 +147,7 @@
 
         $messages_in = array();
         for ($i=0; $i<10; ++$i){
-            $message = queue2civicrm_generate_message();
+            $message = Message::generateRandom();
             unset($message['contribution_tracking_id']);
             $message['gateway'] = 'CiviTest' . $i;
             $message['gateway_txn_id'] = time();

-- 
To view, visit https://gerrit.wikimedia.org/r/287653
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I490e0ac4d2aa7691809802f5c5bc1ada9ab82504
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to