*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
*/
// Can also be fetched via join
$email = Email::get()
- ->addSelect('contact.api_key')
+ ->addSelect('contact_id.api_key')
->addWhere('id', '=', $contact['email']['id'])
->execute()->first();
- $this->assertEquals($key, $email['contact.api_key']);
+ $this->assertEquals($key, $email['contact_id.api_key']);
$this->assertFalse($isSafe($email), "Should reveal secret details ($key): " . var_export($email, 1));
// Remove permission and we should not see the key
// Also not available via join
$email = Email::get()
- ->addSelect('contact.api_key')
+ ->addSelect('contact_id.api_key')
->addWhere('id', '=', $contact['email']['id'])
->setDebug(TRUE)
->execute();
- $this->assertContains('contact.api_key', $email->debug['undefined_fields']);
- $this->assertArrayNotHasKey('contact.api_key', $email[0]);
+ $this->assertContains('contact_id.api_key', $email->debug['undefined_fields']);
+ $this->assertArrayNotHasKey('contact_id.api_key', $email[0]);
$this->assertTrue($isSafe($email[0]), "Should NOT reveal secret details ($key): " . var_export($email[0], 1));
$result = Contact::get()
catch (\Exception $e) {
$error = $e->getMessage();
}
- $this->assertContains('key', $error);
+ $this->assertStringContainsString('key', $error);
}
public function testGetApiKeyViaJoin() {
return strpos(json_encode($mixed), $key) === FALSE;
};
- $contact = Contact::create()
- ->setCheckPermissions(FALSE)
+ $contact = Contact::create(FALSE)
->addValue('first_name', 'Api')
->addValue('last_name', 'Key0')
->addValue('api_key', $key)
->first();
$this->assertFalse($isSafe($contact), "Should reveal secret details ($key): " . var_export($contact, 1));
- Email::create()
- ->setCheckPermissions(FALSE)
+ Email::create(FALSE)
->addValue('email', 'foo@example.org')
->addValue('contact_id', $contact['id'])
->execute();
- $result = Email::get()
- ->setCheckPermissions(FALSE)
+ $result = Email::get(FALSE)
->addWhere('contact_id', '=', $contact['id'])
->addSelect('email')
- ->addSelect('contact.api_key')
+ ->addSelect('contact_id.api_key')
->execute()
->first();
$this->assertFalse($isSafe($result), "Should reveal secret details ($key): " . var_export($result, 1));
- $result = Email::get()
- ->setCheckPermissions(TRUE)
+ $result = Email::get(TRUE)
->addWhere('contact_id', '=', $contact['id'])
- ->addSelect('contact.api_key')
+ ->addSelect('contact_id.api_key')
->execute()
->first();
$this->assertTrue($isSafe($result), "Should NOT reveal secret details ($key): " . var_export($result, 1));
\CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit all contacts'];
$key = uniqid();
- $contact = Contact::create()
- ->setCheckPermissions(FALSE)
+ $contact = Contact::create(FALSE)
->addValue('first_name', 'Api')
->addValue('last_name', 'Key2')
->addValue('api_key', $key)
$error = $e->getMessage();
}
- $result = Contact::get()
- ->setCheckPermissions(FALSE)
+ $result = Contact::get(FALSE)
->addWhere('id', '=', $contact['id'])
->addSelect('api_key')
->execute()
->first();
- $this->assertContains('key', $error);
+ $this->assertStringContainsString('key', $error);
// Assert key is still the same
$this->assertEquals($result['api_key'], $key);
\CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit own api keys', 'edit all contacts'];
$key = uniqid();
- $contact = Contact::create()
- ->setCheckPermissions(FALSE)
+ $contact = Contact::create(FALSE)
->addValue('first_name', 'Api')
->addValue('last_name', 'Key3')
->addValue('api_key', $key)
$error = $e->getMessage();
}
- $this->assertContains('key', $error);
+ $this->assertStringContainsString('key', $error);
- $result = Contact::get()
- ->setCheckPermissions(FALSE)
+ $result = Contact::get(FALSE)
->addWhere('id', '=', $contact['id'])
->addSelect('api_key')
->execute()
->addValue('api_key', "MyId!")
->execute();
- $result = Contact::get()
- ->setCheckPermissions(FALSE)
+ $result = Contact::get(FALSE)
->addWhere('id', '=', $contact['id'])
->addSelect('api_key')
->execute()