Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/374903 )

Change subject: Add unit tests for Thank You mailer
......................................................................

Add unit tests for Thank You mailer

Change-Id: If2046ab1ab6632eb9cfa4bb36d28b24b22d21bab
---
M phpunit.xml
A sites/all/modules/thank_you/tests/phpunit/ThankYouTest.php
2 files changed, 99 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/03/374903/1

diff --git a/phpunit.xml b/phpunit.xml
index 2f3e236..06e7423 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -21,6 +21,9 @@
       <testsuite name="recurring_globalcollect tests">
         <directory>sites/all/modules/recurring_globalcollect/tests</directory>
       </testsuite>
+      <testsuite name="thank_you tests">
+        <directory>sites/all/modules/thank_you/tests/phpunit</directory>
+      </testsuite>
       <testsuite name="wmf_audit tests">
         <directory>sites/all/modules/wmf_audit/tests</directory>
       </testsuite>
diff --git a/sites/all/modules/thank_you/tests/phpunit/ThankYouTest.php 
b/sites/all/modules/thank_you/tests/phpunit/ThankYouTest.php
new file mode 100644
index 0000000..2425364
--- /dev/null
+++ b/sites/all/modules/thank_you/tests/phpunit/ThankYouTest.php
@@ -0,0 +1,96 @@
+<?php
+
+use wmf_communication\TestMailer;
+
+/**
+ * @group ThankYou
+ */
+class ThankYouTest extends BaseWmfDrupalPhpUnitTestCase {
+
+       /**
+        * Id of the contribution created in the setup function.
+        *
+        * @var int
+        */
+       protected $contribution_id;
+       protected $contact_id;
+       protected $old_civimail;
+       protected $old_civimail_rate;
+       protected $message;
+
+       public function setUp() {
+               if ( !defined( 'WMF_UNSUB_SALT' ) ) {
+                       define( 'WMF_UNSUB_SALT', 'abc123' );
+               }
+               parent::setUp();
+               civicrm_initialize();
+               TestMailer::setup();
+               $this->message = array(
+                       'city' => 'Somerville',
+                       'country' => 'US',
+                       'currency' => 'USD',
+                       'date' => '2012-05-01 00:00:00',
+                       'email' => 'generousdo...@example.org',
+                       'first_name' => 'Test',
+                       'last_name' => 'Es',
+                       'language' => 'en',
+                       'gateway' => 'test_gateway',
+                       'gateway_txn_id' => mt_rand(),
+                       'gross' => '1.23',
+                       'payment_method' => 'cc',
+                       'postal_code' => '02144',
+                       'state_province' => 'MA',
+                       'street_address' => '1 Davis Square',
+               );
+               $this->old_civimail = variable_get( 
'thank_you_add_civimail_records', 'false' );
+               $this->old_civimail_rate = variable_get( 
'thank_you_civimail_rate', 1.0 );
+
+               $contribution = wmf_civicrm_contribution_message_import( 
$this->message );
+
+               $this->contact_id = $contribution['contact_id'];
+               $this->contribution_id = $contribution['id'];
+       }
+
+       public function tearDown() {
+               parent::cleanUpContact( $this->contact_id );
+               variable_set( 'thank_you_add_civimail_records', 
$this->old_civimail );
+               variable_get( 'thank_you_civimail_rate', 
$this->old_civimail_rate );
+               parent::tearDown();
+       }
+
+       public function testSendThankYou() {
+               variable_set( 'thank_you_add_civimail_records', 'false' );
+               $result = thank_you_for_contribution( $this->contribution_id );
+               $this->assertTrue( $result );
+               $this->assertEquals( 1, TestMailer::countMailings() );
+               $sent = TestMailer::getMailing( 0 );
+               $this->assertEquals( $this->message['email'], 
$sent['to_address'] );
+               $this->assertEquals(
+                       "{$this->message['first_name']} 
{$this->message['last_name']}",
+                       $sent['to_name']
+               );
+               $expectedBounce = 'bounce-' .
+                       str_replace( '@', '=', $this->message['email'] ) .
+                       '@donate.wikimedia.org';
+               $this->assertEquals( $expectedBounce, $sent['reply_to'] );
+               $this->assertRegExp( '/\$ 1.23/', $sent['html'] );
+       }
+
+       public function testSendThankYouAddCiviMailActivity() {
+               variable_set( 'thank_you_add_civimail_records', 'true' );
+               variable_set( 'thank_you_civimail_rate', 1.0 );
+               $result = thank_you_for_contribution( $this->contribution_id );
+               $this->assertTrue( $result );
+               $activity = civicrm_api3( 'Activity', 'getSingle', array(
+                       'contact_id' => $this->contact_id,
+                       'activity_type_id' => CRM_Core_PseudoConstant::getKey(
+                               'CRM_Activity_BAO_Activity',
+                               'activity_type_id',
+                               'Email'
+                       )
+               ) );
+               $this->assertEquals( 1, TestMailer::countMailings() );
+               $sent = TestMailer::getMailing( 0 );
+               $this->assertEquals( $activity['details'], $sent['html'] );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If2046ab1ab6632eb9cfa4bb36d28b24b22d21bab
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to