(NFC) (dev/core#878) Simplify copyright header (tests/*)
[civicrm-core.git] / tests / phpunit / api / v3 / EmailTest.php
index 4299e87d33258fc3f0baecab224618b025d017c7..85c24952c4cfa5757a7e338808f9d6feada78abe 100644 (file)
@@ -1,28 +1,12 @@
 <?php
 /*
  +--------------------------------------------------------------------+
-| CiviCRM version 5                                                  |
-+--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2019                                |
-+--------------------------------------------------------------------+
-| This file is a part of CiviCRM.                                    |
-|                                                                    |
-| CiviCRM is free software; you can copy, modify, and distribute it  |
-| under the terms of the GNU Affero General Public License           |
-| Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
-|                                                                    |
-| CiviCRM is distributed in the hope that it will be useful, but     |
-| WITHOUT ANY WARRANTY; without even the implied warranty of         |
-| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
-| See the GNU Affero General Public License for more details.        |
-|                                                                    |
-| You should have received a copy of the GNU Affero General Public   |
-| License and the CiviCRM Licensing Exception along                  |
-| with this program; if not, contact CiviCRM LLC                     |
-| at info[AT]civicrm[DOT]org. If you have questions about the        |
-| GNU Affero General Public License or the licensing of CiviCRM,     |
-| see the CiviCRM license FAQ at http://civicrm.org/licensing        |
-+--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
  */
 
 /**
@@ -42,20 +26,20 @@ class api_v3_EmailTest extends CiviUnitTestCase {
 
     $this->_contactID = $this->organizationCreate(NULL);
     $this->_locationType = $this->locationTypeCreate(NULL);
-    $this->_locationType2 = $this->locationTypeCreate(array(
+    $this->_locationType2 = $this->locationTypeCreate([
       'name' => 'New Location Type 2',
       'vcard_name' => 'New Location Type 2',
       'description' => 'Another Location Type',
       'is_active' => 1,
-    ));
-    $this->_params = array(
+    ]);
+    $this->_params = [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
       'email' => 'api@a-team.com',
       'is_primary' => 1,
 
       //TODO email_type_id
-    );
+    ];
   }
 
   /**
@@ -66,30 +50,32 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $this->_apiversion = $version;
     $params = $this->_params;
     //check there are no emails to start with
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'location_type_id' => $this->_locationType->id,
-    ));
+    ]);
     $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
 
     $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count']);
     $this->assertNotNull($result['id']);
     $this->assertNotNull($result['values'][$result['id']]['id']);
-    $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+    $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
   }
 
   /**
    * If no location is specified when creating a new email, it should default to
    * the LocationType default
    *
-   * Only API v3
+   * @param int $version
+   * @dataProvider versionThreeAndFour
    */
-  public function testCreateEmailDefaultLocation() {
+  public function testCreateEmailDefaultLocation($version) {
+    $this->_apiversion = $version;
     $params = $this->_params;
     unset($params['location_type_id']);
-    $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
     $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
-    $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+    $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
   }
 
   /**
@@ -106,10 +92,10 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $email1 = $this->callAPISuccess('email', 'create', $params);
     //now we check & make sure it has been set to primary
     $expected = 1;
-    $check = $this->callAPISuccess('email', 'getcount', array(
+    $check = $this->callAPISuccess('email', 'getcount', [
       'is_primary' => 1,
       'id' => $email1['id'],
-    ),
+    ],
       $expected
     );
   }
@@ -122,10 +108,10 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $this->_apiversion = $version;
     $email1 = $this->callAPISuccess('email', 'create', $this->_params);
     $email2 = $this->callAPISuccess('email', 'create', $this->_params);
-    $check = $this->callAPISuccess('email', 'getcount', array(
+    $check = $this->callAPISuccess('email', 'getcount', [
       'is_primary' => 1,
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertEquals(1, $check);
   }
 
@@ -135,7 +121,7 @@ class api_v3_EmailTest extends CiviUnitTestCase {
    */
   public function testCreateEmailWithoutEmail($version) {
     $this->_apiversion = $version;
-    $result = $this->callAPIFailure('Email', 'Create', array('contact_id' => 4));
+    $result = $this->callAPIFailure('Email', 'Create', ['contact_id' => 4]);
     $this->assertContains('missing', $result['error_message']);
     $this->assertContains('email', $result['error_message']);
   }
@@ -149,11 +135,11 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('email', 'create', $this->_params);
     $get = $this->callAPISuccess('email', 'create', $this->_params);
     $this->assertEquals($get['count'], 1);
-    $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1));
+    $get = $this->callAPISuccess('email', 'create', $this->_params + ['debug' => 1]);
     $this->assertEquals($get['count'], 1);
-    $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1, 'action' => 'get'));
+    $get = $this->callAPISuccess('email', 'create', $this->_params + ['debug' => 1, 'action' => 'get']);
     $this->assertEquals($get['count'], 1);
-    $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+    $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
   }
 
   /**
@@ -162,28 +148,28 @@ class api_v3_EmailTest extends CiviUnitTestCase {
    */
   public function testDeleteEmail($version) {
     $this->_apiversion = $version;
-    $params = array(
+    $params = [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
       'email' => 'api@a-team.com',
       'is_primary' => 1,
 
       //TODO email_type_id
-    );
+    ];
     //check there are no emails to start with
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'location_type_id' => $this->_locationType->id,
-    ));
+    ]);
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
 
     //create one
     $create = $this->callAPISuccess('email', 'create', $params);
 
-    $result = $this->callAPIAndDocument('email', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument('email', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count']);
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'location_type_id' => $this->_locationType->id,
-    ));
+    ]);
     $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
   }
 
@@ -194,93 +180,93 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   public function testReplaceEmail($version) {
     $this->_apiversion = $version;
     // check there are no emails to start with
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
 
     // initialize email list with three emails at loc #1 and two emails at loc #2
-    $replace1Params = array(
+    $replace1Params = [
       'contact_id' => $this->_contactID,
-      'values' => array(
-        array(
+      'values' => [
+        [
           'location_type_id' => $this->_locationType->id,
           'email' => '1-1@example.com',
           'is_primary' => 1,
-        ),
-        array(
+        ],
+        [
           'location_type_id' => $this->_locationType->id,
           'email' => '1-2@example.com',
           'is_primary' => 0,
-        ),
-        array(
+        ],
+        [
           'location_type_id' => $this->_locationType->id,
           'email' => '1-3@example.com',
           'is_primary' => 0,
-        ),
-        array(
+        ],
+        [
           'location_type_id' => $this->_locationType2->id,
           'email' => '2-1@example.com',
           'is_primary' => 0,
-        ),
-        array(
+        ],
+        [
           'location_type_id' => $this->_locationType2->id,
           'email' => '2-2@example.com',
           'is_primary' => 0,
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
     $replace1 = $this->callAPIAndDocument('email', 'replace', $replace1Params, __FUNCTION__, __FILE__);
     $this->assertEquals(5, $replace1['count']);
 
     // check emails at location #1 or #2
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // replace the subset of emails in location #1, but preserve location #2
-    $replace2Params = array(
+    $replace2Params = [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
-      'values' => array(
-        array(
+      'values' => [
+        [
           'email' => '1-4@example.com',
           'is_primary' => 1,
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
     $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params);
     $this->assertEquals(1, $replace2['count']);
 
     // check emails at location #1 -- all three replaced by one
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
-    ));
+    ]);
     $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // check emails at location #2 -- preserve the original two
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType2->id,
-    ));
+    ]);
 
     $this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // replace the set of emails with an empty set
-    $replace3Params = array(
+    $replace3Params = [
       'contact_id' => $this->_contactID,
-      'values' => array(),
-    );
+      'values' => [],
+    ];
     $replace3 = $this->callAPISuccess('email', 'replace', $replace3Params);
     $this->assertEquals(0, $replace3['count']);
 
     // check emails
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
 
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertAPISuccess($get);
     $this->assertEquals(0, $get['count'], 'Incorrect email count at ' . __LINE__);
   }
@@ -292,87 +278,87 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   public function testReplaceEmailsInChain($version) {
     $this->_apiversion = $version;
     // check there are no emails to start with
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
 
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertAPISuccess($get);
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
     $description = "Demonstrates use of Replace in a nested API call.";
     $subfile = "NestedReplaceEmail";
     // initialize email list with three emails at loc #1 and two emails at loc #2
-    $getReplace1Params = array(
+    $getReplace1Params = [
 
       'id' => $this->_contactID,
-      'api.email.replace' => array(
-        'values' => array(
-          array(
+      'api.email.replace' => [
+        'values' => [
+          [
             'location_type_id' => $this->_locationType->id,
             'email' => '1-1@example.com',
             'is_primary' => 1,
-          ),
-          array(
+          ],
+          [
             'location_type_id' => $this->_locationType->id,
             'email' => '1-2@example.com',
             'is_primary' => 0,
-          ),
-          array(
+          ],
+          [
             'location_type_id' => $this->_locationType->id,
             'email' => '1-3@example.com',
             'is_primary' => 0,
-          ),
-          array(
+          ],
+          [
             'location_type_id' => $this->_locationType2->id,
             'email' => '2-1@example.com',
             'is_primary' => 0,
-          ),
-          array(
+          ],
+          [
             'location_type_id' => $this->_locationType2->id,
             'email' => '2-2@example.com',
             'is_primary' => 0,
-          ),
-        ),
-      ),
-    );
+          ],
+        ],
+      ],
+    ];
     $getReplace1 = $this->callAPIAndDocument('contact', 'get', $getReplace1Params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(5, $getReplace1['values'][$this->_contactID]['api.email.replace']['count']);
 
     // check emails at location #1 or #2
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // replace the subset of emails in location #1, but preserve location #2
-    $getReplace2Params = array(
+    $getReplace2Params = [
       'id' => $this->_contactID,
-      'api.email.replace' => array(
+      'api.email.replace' => [
         'location_type_id' => $this->_locationType->id,
-        'values' => array(
-          array(
+        'values' => [
+          [
             'email' => '1-4@example.com',
             'is_primary' => 1,
-          ),
-        ),
-      ),
-    );
+          ],
+        ],
+      ],
+    ];
     $getReplace2 = $this->callAPISuccess('contact', 'get', $getReplace2Params);
     $this->assertEquals(0, $getReplace2['values'][$this->_contactID]['api.email.replace']['is_error']);
     $this->assertEquals(1, $getReplace2['values'][$this->_contactID]['api.email.replace']['count']);
 
     // check emails at location #1 -- all three replaced by one
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
-    ));
+    ]);
 
     $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // check emails at location #2 -- preserve the original two
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType2->id,
-    ));
+    ]);
     $this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__);
   }
 
@@ -383,23 +369,23 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   public function testReplaceEmailWithId($version) {
     $this->_apiversion = $version;
     // check there are no emails to start with
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
-    ));
+    ]);
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
 
     // initialize email address
-    $replace1Params = array(
+    $replace1Params = [
       'contact_id' => $this->_contactID,
-      'values' => array(
-        array(
+      'values' => [
+        [
           'location_type_id' => $this->_locationType->id,
           'email' => '1-1@example.com',
           'is_primary' => 1,
           'on_hold' => 1,
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
     $replace1 = $this->callAPISuccess('email', 'replace', $replace1Params);
     $this->assertEquals(1, $replace1['count']);
 
@@ -407,23 +393,23 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $emailID = array_shift($keys);
 
     // update the email address, but preserve any other fields
-    $replace2Params = array(
+    $replace2Params = [
       'contact_id' => $this->_contactID,
-      'values' => array(
-        array(
+      'values' => [
+        [
           'id' => $emailID,
           'email' => '1-2@example.com',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
     $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params);
     $this->assertEquals(1, $replace2['count']);
 
     // ensure the 'email' was updated while other fields were preserved
-    $get = $this->callAPISuccess('email', 'get', array(
+    $get = $this->callAPISuccess('email', 'get', [
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
-    ));
+    ]);
 
     $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
     $this->assertEquals(1, $get['values'][$emailID]['is_primary']);
@@ -432,13 +418,13 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   }
 
   public function testEmailOnHold() {
-    $params = array();
-    $params_change = array();
-    $params = array(
+    $params = [];
+    $params_change = [];
+    $params = [
       'contact_id' => $this->_contactID,
       'email' => 'api@a-team.com',
       'on_hold' => '2',
-    );
+    ];
     $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count']);
     $this->assertNotNull($result['id']);
@@ -448,21 +434,21 @@ class api_v3_EmailTest extends CiviUnitTestCase {
 
     // set on_hold is '0'
     // if isMultipleBulkMail is active, the value in On-hold select is string
-    $params_change = array(
+    $params_change = [
       'id' => $result['id'],
       'contact_id' => $this->_contactID,
       'email' => 'api@a-team.com',
       'is_primary' => 1,
       'on_hold' => '0',
-    );
-    $result_change = $this->callAPISuccess('email', 'create', $params_change + array('action' => 'get'));
+    ];
+    $result_change = $this->callAPISuccess('email', 'create', $params_change + ['action' => 'get']);
     $this->assertEquals(1, $result_change['count']);
     $this->assertEquals($result['id'], $result_change['id']);
     $this->assertEmpty($result_change['values'][$result_change['id']]['on_hold']);
     $this->assertEquals(date('Y-m-d H:i'), date('Y-m-d H:i', strtotime($result_change['values'][$result_change['id']]['reset_date'])));
     $this->assertEmpty($result_change['values'][$result_change['id']]['hold_date']);
 
-    $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+    $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
   }
 
 }