Merge pull request #14278 from seamuslee001/nfc_langauge_cleanup
authorEileen McNaughton <eileen@mcnaughty.com>
Tue, 21 May 2019 07:37:51 +0000 (19:37 +1200)
committerGitHub <noreply@github.com>
Tue, 21 May 2019 07:37:51 +0000 (19:37 +1200)
[NFC] Update Language to be more user friendly when checking logs

tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContactTest.php
tests/phpunit/api/v3/MailingContactTest.php

index 4ece15ebce7a33e2e6e093f7256247fcf593dd09..fa5e5d250a689a74ee5caa914a014d315259d7fd 100644 (file)
@@ -373,14 +373,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
     $this->getConnection()->getConnection()->query("SET FOREIGN_KEY_CHECKS = 0;");
 
-    $xmlFiles = glob($fixturesDir . '/*.xml');
-    foreach ($xmlFiles as $xmlFixture) {
-      $op = new PHPUnit_Extensions_Database_Operation_Insert();
-      $dataset = $this->createXMLDataSet($xmlFixture);
-      $this->_tablesToTruncate = array_merge($this->_tablesToTruncate, $dataset->getTableNames());
-      $op->execute($this->_dbconn, $dataset);
-    }
-
     $yamlFiles = glob($fixturesDir . '/*.yaml');
     foreach ($yamlFiles as $yamlFixture) {
       $op = new PHPUnit_Extensions_Database_Operation_Insert();
index bd178c7300ad7b085076341a6fbe9ebf78277a58..d0d5ed74666761b4114fad5fd180376e3aff0730 100644 (file)
@@ -2611,19 +2611,6 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     $this->callAPISuccess('contact', 'update', $params);
   }
 
-  /**
-   * Set up helper to create a contact.
-   */
-  public function createContactFromXML() {
-    // Insert a row in civicrm_contact creating contact 17.
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_17.xml'
-      )
-    );
-  }
-
   /**
    * Test contact proximity api.
    */
index a9e00c9ea33f5230e66262ea2c3cff3cd07b6448..7ec969cac6be14da43e597fd3e7e75a07fae2d60 100644 (file)
  * @group headless
  */
 class api_v3_MailingContactTest extends CiviUnitTestCase {
-  protected $_apiversion = 3;
   protected $_entity = 'mailing';
 
   public function setUp() {
     parent::setUp();
-    $params = array(
+    $params = [
       'first_name' => 'abc1',
       'contact_type' => 'Individual',
       'last_name' => 'xyz1',
-    );
+    ];
     $this->_contact = $this->callAPISuccess("contact", "create", $params);
   }
 
   public function tearDown() {
-    $this->callAPISuccess("contact", "delete", array('id' => $this->_contact['id']));
+    $this->callAPISuccess("contact", "delete", ['id' => $this->_contact['id']]);
     parent::tearDown();
   }
 
@@ -88,10 +87,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
    * belongs in the SyntaxConformance class
    */
   public function testMailingNoContactID() {
-    $params = array(
-      'something' => 'This is not a real field',
-    );
-    $this->callAPIFailure('MailingContact', 'get', $params);
+    $this->callAPIFailure('MailingContact', 'get', ['something' => 'This is not a real field']);
   }
 
   /**
@@ -103,8 +99,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
    * belongs in the SyntaxConformance class
    */
   public function testMailingContactInvalidContactID() {
-    $params = array('contact_id' => 'This is not a number');
-    $this->callAPIFailure('MailingContact', 'get', $params);
+    $this->callAPIFailure('MailingContact', 'get', ['contact_id' => 'This is not a number']);
   }
 
   /**
@@ -134,24 +129,13 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
    * Test that the API returns a mailing properly when there is only one.
    */
   public function testMailingContactDelivered() {
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    //Create the User
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/mailing_contact.xml'
-      )
-    );
-    // Create the Mailing and connections to the user.
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/mailing_delivered.xml'
-      )
-    );
+    list($contactID, $mailingID, $eventQueueID) = $this->setupEventQueue();
+    CRM_Core_DAO::executeQuery("INSERT INTO civicrm_mailing_event_delivered (event_queue_id) VALUES(%1)", [1 => [$eventQueueID, 'Integer']]);
 
-    $params = array(
-      'contact_id' => 23,
+    $params = [
+      'contact_id' => $contactID,
       'type' => 'Delivered',
-    );
+    ];
 
     $result = $this->callAPISuccess('MailingContact', 'get', $params);
     $count = $this->callAPISuccess('MailingContact', 'getcount', $params);
@@ -160,40 +144,54 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
     $this->assertFalse(empty($result['values']));
     $this->assertEquals($result['values'][1]['mailing_id'], 1);
     $this->assertEquals($result['values'][1]['subject'], "Some Subject");
-    $this->assertEquals($result['values'][1]['creator_id'], 3);
-    $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1");
+    $this->assertEquals(CRM_Core_Session::getLoggedInContactID(), $result['values'][1]['creator_id']);
   }
 
   /**
-   * Test that the API returns only the "Bounced" mailings when instructed to do so.
+   * Test that the API returns only the "Bounced" mailings when instructed to
+   * do so.
+   *
+   * @throws \Exception
    */
   public function testMailingContactBounced() {
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    // Create the User.
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/mailing_contact.xml'
-      )
-    );
-    // Create the Mailing and connections to the user.
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/mailing_bounced.xml'
-      )
-    );
+    list($contactID, $mailingID, $eventQueueID) = $this->setupEventQueue();
+    CRM_Core_DAO::executeQuery("INSERT INTO civicrm_mailing_event_bounce (event_queue_id, bounce_type_id) VALUES(%1, 6)", [1 => [$eventQueueID, 'Integer']]);
 
-    $params = array(
-      'contact_id' => 23,
+    $params = [
+      'contact_id' => $contactID,
       'type' => 'Bounced',
-    );
+    ];
 
-    $result = $this->callAPISuccess('MailingContact', 'get', $params);
-    $this->assertEquals($result['count'], 1);
-    $this->assertFalse(empty($result['values']));
-    $this->assertEquals($result['values'][2]['mailing_id'], 2);
-    $this->assertEquals($result['values'][2]['subject'], "Some Subject");
-    $this->assertEquals($result['values'][2]['creator_id'], 3);
-    $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1");
+    $result = $this->callAPISuccess('MailingContact', 'get', $params)['values'];
+    $this->assertEquals(1, count($result));
+    $this->assertEquals($mailingID, $result[$mailingID]['mailing_id']);
+    $this->assertEquals('Some Subject', $result[$mailingID]['subject']);
+    $this->assertEquals(CRM_Core_Session::getLoggedInContactID(), $result[$mailingID]['creator_id'], 3);
+  }
+
+  /**
+   * @return array
+   * @throws \Exception
+   */
+  public function setupEventQueue() {
+    $contactID = $this->individualCreate(['first_name' => 'Test']);
+    $emailID = $this->callAPISuccessGetValue('Email', [
+      'return' => 'id',
+      'contact_id' => $contactID,
+    ]);
+    $this->createLoggedInUser();
+    $mailingID = $this->callAPISuccess('Mailing', 'create', [
+      'name' => 'Test Mailing',
+      'subject' => 'Some Subject',
+    ])['id'];
+    $mailingJobID = $this->callAPISuccess('MailingJob', 'create', ['mailing_id' => $mailingID])['id'];
+    $eventQueueID = $this->callAPISuccess('MailingEventQueue', 'create', [
+      'contact_id' => $contactID,
+      'mailing_id' => $mailingID,
+      'email_id' => $emailID,
+      'job_id' => $mailingJobID,
+    ])['id'];
+    return [$contactID, $mailingID, $eventQueueID];
   }
 
 }