Example #1
0
 public function testHookAlterMailer()
 {
     $test = $this;
     $mockMailer = new CRM_Utils_FakeObject(array('send' => function ($recipients, $headers, $body) use($test) {
         $test->calls['send']++;
         $test->assertEquals(array('*****@*****.**'), $recipients);
         $test->assertEquals('Subject Example', $headers['Subject']);
     }));
     CRM_Utils_Hook::singleton()->setHook('civicrm_alterMailer', function (&$mailer, $driver, $params) use($test, $mockMailer) {
         $test->calls['civicrm_alterMailer']++;
         $test->assertTrue(is_string($driver) && !empty($driver));
         $test->assertTrue(is_array($params));
         $test->assertTrue(is_callable(array($mailer, 'send')));
         $mailer = $mockMailer;
     });
     $params = array();
     $params['groupName'] = 'CRM_Core_Config_MailerTest';
     $params['from'] = 'From Example <*****@*****.**>';
     $params['toName'] = 'To Example';
     $params['toEmail'] = '*****@*****.**';
     $params['subject'] = 'Subject Example';
     $params['text'] = 'Example text';
     $params['html'] = '<p>Example HTML</p>';
     CRM_Utils_Mail::send($params);
     $this->assertEquals(1, $this->calls['civicrm_alterMailer']);
     $this->assertEquals(1, $this->calls['send']);
     // once more, just to make sure the hooks are called right #times
     CRM_Utils_Mail::send($params);
     CRM_Utils_Mail::send($params);
     $this->assertEquals(1, $this->calls['civicrm_alterMailer']);
     $this->assertEquals(3, $this->calls['send']);
 }
 /**
  *
  */
 function tearDown()
 {
     $this->_mut->stop();
     $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact'));
     CRM_Utils_Hook::singleton()->reset();
     parent::tearDown();
 }
Example #3
0
 function tearDown()
 {
     $this->quickCleanup(array('civicrm_job', 'civicrm_action_log', 'civicrm_action_schedule'));
     $this->quickCleanUpFinancialEntities();
     CRM_Utils_Hook::singleton()->reset();
     parent::tearDown();
 }
Example #4
0
 public function tearDown()
 {
     CRM_Utils_Hook::singleton()->reset();
     parent::tearDown();
     $this->callAPISuccess('system', 'flush', array());
     $this->quickCleanup(array('civicrm_domain'));
 }
Example #5
0
 public function testHookCron()
 {
     $hook = $this->getMock('stdClass', array('civicrm_cron'));
     $hook->expects($this->once())->method('civicrm_cron')->with($this->isInstanceOf('CRM_Core_JobManager'));
     CRM_Utils_Hook::singleton()->setMock($hook);
     $jobManager = new CRM_Core_JobManager();
     $jobManager->execute(FALSE);
 }
 /**
  * (non-PHPdoc)
  * @see CiviUnitTestCase::tearDown()
  */
 public function tearDown()
 {
     CRM_Utils_Hook::singleton()->reset();
     $tablesToTruncate = array('civicrm_contact', 'civicrm_group_contact', 'civicrm_group', 'civicrm_acl', 'civicrm_acl_cache', 'civicrm_acl_entity_role', 'civicrm_acl_contact_cache', 'civicrm_contribution', 'civicrm_participant', 'civicrm_uf_match');
     $this->quickCleanup($tablesToTruncate);
     $config = CRM_Core_Config::singleton();
     unset($config->userPermissionClass->permissions);
 }
Example #7
0
 public function tearDown()
 {
     CRM_Utils_Hook::singleton()->reset();
     $this->quickCleanup(array('civicrm_group'));
     $config = CRM_Core_Config::singleton();
     unset($config->userPermissionClass->permissions);
     parent::tearDown();
 }
 /**
  * (non-PHPdoc)
  * @see CiviUnitTestCase::tearDown()
  */
 function tearDown()
 {
     CRM_Utils_Hook::singleton()->reset();
     $tablesToTruncate = array('civicrm_contact');
     $this->quickCleanup($tablesToTruncate);
     $config = CRM_Core_Config::singleton();
     unset($config->userPermissionClass->permissions);
 }
 /**
  * This hook is called once for every batch before the pdf template is rendered.
  * You should use this for performance reasons when the token can be shared between chunk items (for example a contact
  * address that is the same for all files)
  *
  * You can implement this hook to add/modify template tokens
  * e.g. in your hook implementation call $template->assign('myCustomToken', 'my custom token');
  * and place a token called {$myCustomToken} in the template.
  *
  * @param object $template
  *
  * @return mixed based on op. pre-hooks return a boolean or
  * an error message which aborts the operation
  * @access public
  */
 static function pdf_shared_token(&$template, &$chunk)
 {
     if (version_compare(CRM_Utils_System::version(), '4.5', '<')) {
         return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token');
     } else {
         return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token');
     }
 }
 /**
  */
 public function tearDown()
 {
     $this->_mut->stop();
     //    $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact'));
     CRM_Utils_Hook::singleton()->reset();
     CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0;
     // DGW
     parent::tearDown();
 }
Example #11
0
File: Hook.php Project: kidaa30/yes
 /**
  * This hook data transforms data stored in accounts_data to be formatted into a standard format.
  *
  * The called hook is expected to add a key 'civicrm_formatted' to the accountsData array
  * with the data using the same field names as the relevant CiviCRM api.
  *
  * @param array $accountsData data from accounts system
  * @param string $entity entity - eg. 'AccountContact'
  * @param string $plugin plugin in use
  *
  * @return mixed
  *   Ignore value.
  */
 public static function mapAccountsData(&$accountsData, $entity, $plugin)
 {
     $codeVersion = explode('.', CRM_Utils_System::version());
     if (version_compare($codeVersion[0] . '.' . $codeVersion[1], 4.5) >= 0) {
         return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData');
     } else {
         return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData');
     }
 }
 /**
  */
 public function tearDown()
 {
     //$this->_mut->clearMessages();
     $this->_mut->stop();
     CRM_Utils_Hook::singleton()->reset();
     CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0;
     // DGW
     //$this->cleanupMailingTest();
     parent::tearDown();
 }
 private function invoke($fnSuffix, $numParams, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null, &$arg5 = null)
 {
     $hook = CRM_Utils_Hook::singleton();
     $civiVersion = CRM_Core_BAO_Domain::version();
     if (version_compare('4.4', $civiVersion, '<=')) {
         //in CiviCRM 4.4 the invoke function has 5 arguments maximum
         return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $fnSuffix);
     }
     //in CiviCRM 4.5 and later the invoke function has 6 arguments
     return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, null, $fnSuffix);
 }
 public function setUp()
 {
     parent::setUp();
     /** @var $hooks \CRM_Utils_Hook_UnitTests */
     $hooks = \CRM_Utils_Hook::singleton();
     $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
     \CRM_Case_XMLRepository::singleton(TRUE);
     \CRM_Case_XMLProcessor::flushStaticCaches();
     // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
     //. Using XML was causing breakage as id numbers were changing over time
     // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
     // state where tests could run afterwards without re-loading.
     $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_status', 'format.only_id' => 1));
     $optionValues = array('Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", 'Secure temporary housing' => 'Secure temporary housing', 'Long-term housing plan' => 'Long-term housing plan', 'ADC referral' => 'ADC referral', 'Income and benefits stabilization' => 'Income and benefits stabilization');
     foreach ($optionValues as $name => $label) {
         $activityTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => 2, 'name' => $name, 'label' => $label, 'component_id' => 7));
         // store for cleanup
         $this->optionValues[] = $activityTypes['id'];
     }
     // We used to be inconsistent about "HousingSupport" vs "housing_support".
     // Now, the rule is simply: use the "name" from "civicrm_case_type.name".
     $this->caseType = 'housing_support';
     $this->caseTypeId = 1;
     $this->tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_case_type', 'civicrm_activity_contact', 'civicrm_managed', 'civicrm_relationship', 'civicrm_relationship_type');
     $this->quickCleanup($this->tablesToTruncate);
     $this->loadAllFixtures();
     // enable the default custom templates for the case type xml files
     $this->customDirectories(array('template_path' => TRUE));
     // case is not enabled by default
     $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
     // create a logged in USER since the code references it for source_contact_id
     $this->createLoggedInUser();
     $session = CRM_Core_Session::singleton();
     $this->_loggedInUser = $session->get('userID');
     /// note that activityType options are cached by the FULL set of options you pass in
     // ie. because Activity api includes campaign in it's call cache is not flushed unless
     // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
     CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 }
 public function setUp()
 {
     parent::setUp();
     CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', array($this, 'hook_civicrm_fieldOptions'));
 }
Example #16
0
 /**
  * Flush information about loaded modules.
  */
 public function clearModuleList()
 {
     CRM_Extension_System::singleton()->getCache()->flush();
     CRM_Utils_Hook::singleton(TRUE);
     CRM_Core_PseudoConstant::getModuleExtensions(TRUE);
     CRM_Core_Module::getAll(TRUE);
 }
 public function setUp()
 {
     parent::setUp();
     $this->useTransaction(TRUE);
     CRM_Utils_Hook::singleton()->setHook('civicrm_selectWhereClause', array($this, 'hook_civicrm_selectWhereClause'));
 }
Example #18
0
/**
 * Implementation of hook_civicrm_alterMailParams( )
 * To send headers in mail and also create activity
 */
function mte_civicrm_alterMailParams(&$params, $context = NULL)
{
    if ($context != 'civimail') {
        CRM_Core_Smarty::singleton()->assign('alterMailer', 'ignore');
    }
    if (!mte_checkSettings($context)) {
        return FALSE;
    }
    $session = CRM_Core_Session::singleton();
    $userID = $session->get('userID');
    $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
    $params['toEmail'] = trim($params['toEmail']);
    // BRES-103 Prevent silent failure when emails with whitespaces are used.
    if (!$userID) {
        $config = CRM_Core_Config::singleton();
        if (version_compare($config->civiVersion, '4.3.alpha1') < 0) {
            //FIX: source id for version less that 4.3
            $matches = array();
            preg_match('/[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b/i', $params['from'], $matches);
            if (!empty($matches)) {
                $userID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $matches[0], 'contact_id', 'email');
                if (!$userID) {
                    $userID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['toEmail'], 'contact_id', 'email');
                }
            }
        } else {
            $userID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'contact_id');
        }
    }
    if ($context == 'civimail' && CRM_Mte_BAO_Mandrill::$_mailingActivityId) {
        $activityParams = array('id' => CRM_Mte_BAO_Mandrill::$_mailingActivityId, 'target_contact_id' => mte_targetContactIds($params), 'deleteActivityTarget' => FALSE, 'version' => 3);
    } else {
        $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => array_search('Mandrill Email Sent', $activityTypes), 'subject' => CRM_Utils_Array::value('subject', $params) ? $params['subject'] : CRM_Utils_Array::value('Subject', $params), 'activity_date_time' => date('YmdHis'), 'status_id' => 2, 'priority_id' => 1, 'version' => 3, 'details' => CRM_Utils_Array::value('html', $params, $params['text']), 'target_contact_id' => mte_targetContactIds($params));
        if (!empty($params['job_id'])) {
            $jobCLassName = 'CRM_Mailing_DAO_MailingJob';
            if (version_compare('4.4alpha1', CRM_Core_Config::singleton()->civiVersion) > 0) {
                $jobCLassName = 'CRM_Mailing_DAO_Job';
            }
            $activityParams['source_record_id'] = CRM_Core_DAO::getFieldValue($jobCLassName, $params['job_id'], 'mailing_id');
        }
    }
    $result = civicrm_api('activity', 'create', $activityParams);
    if (CRM_Utils_Array::value('id', $result)) {
        $params['activityId'] = $mandrillHeader = $result['id'];
        // include verp in header incase of bulk mailing
        if ($context == 'civimail') {
            $mandrillHeader .= CRM_Core_Config::singleton()->verpSeparator . CRM_Utils_Array::value('Return-Path', $params);
        } else {
            mte_createQueue($mandrillHeader, $params['toEmail']);
            $params['mandrillHeader'] = $mandrillHeader;
        }
        $params['headers']['X-MC-Metadata'] = '{"CiviCRM_Mandrill_id": "' . $mandrillHeader . '" }';
        CRM_Core_Smarty::singleton()->assign('alterMailer', 1);
        if ($context == 'civimail' && !CRM_Mte_BAO_Mandrill::$_mailingActivityId) {
            CRM_Mte_BAO_Mandrill::$_mailingActivityId = $result['id'];
        }
        if (!method_exists(CRM_Utils_Hook::singleton(), 'alterMail')) {
            $mailer =& CRM_Core_Config::getMailer();
            mte_getmailer($mailer);
        }
    }
}
 static function afterSave($wid, &$data)
 {
     return CRM_Utils_Hook::singleton()->invoke(2, $wid, $data, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'workflow_afterSave');
 }
Example #20
0
 static function setParams(&$params)
 {
     return CRM_Utils_Hook::singleton()->invoke(1, $params, self::$null, self::$null, self::$null, self::$null, self::$null, 'civicrm_speakciviParams');
 }
Example #21
0
 /**
  * Get a list of boot services.
  *
  * These are services which must be setup *before* the container can operate.
  *
  * @param bool $loadFromDB
  * @throws \CRM_Core_Exception
  */
 public static function boot($loadFromDB)
 {
     // Array(string $serviceId => object $serviceInstance).
     $bootServices = array();
     \Civi::$statics[__CLASS__]['boot'] =& $bootServices;
     $bootServices['runtime'] = $runtime = new \CRM_Core_Config_Runtime();
     $runtime->initialize($loadFromDB);
     $bootServices['paths'] = new \Civi\Core\Paths();
     $class = $runtime->userFrameworkClass;
     $bootServices['userSystem'] = $userSystem = new $class();
     $userSystem->initialize();
     $userPermissionClass = 'CRM_Core_Permission_' . $runtime->userFramework;
     $bootServices['userPermissionClass'] = new $userPermissionClass();
     $bootServices['cache.settings'] = \CRM_Utils_Cache::create(array('name' => 'settings', 'type' => array('*memory*', 'SqlGroup', 'ArrayCache')));
     $bootServices['settings_manager'] = new \Civi\Core\SettingsManager($bootServices['cache.settings']);
     $bootServices['lockManager'] = self::createLockManager();
     if ($loadFromDB && $runtime->dsn) {
         \CRM_Core_DAO::init($runtime->dsn);
         \CRM_Utils_Hook::singleton(TRUE);
         \CRM_Extension_System::singleton(TRUE);
         \CRM_Extension_System::singleton(TRUE)->getClassLoader()->register();
         $runtime->includeCustomPath();
         $c = new self();
         $container = $c->loadContainer();
         foreach ($bootServices as $name => $obj) {
             $container->set($name, $obj);
         }
         \Civi::$statics[__CLASS__]['container'] = $container;
     }
 }
Example #22
0
 /**
  * Find any hook functions in $test and register them.
  *
  * @param \Civi\Test\HookInterface $test
  */
 protected function registerHooks(HookInterface $test)
 {
     if (CIVICRM_UF !== 'UnitTests') {
         // This is not ideal -- it's just a side-effect of how hooks and E2E tests work.
         // We can temporarily subscribe to hooks in-process, but for other processes, it gets messy.
         throw new \RuntimeException('CiviHookTestInterface requires CIVICRM_UF=UnitTests');
     }
     \CRM_Utils_Hook::singleton()->reset();
     /** @var \CRM_Utils_Hook_UnitTests $hooks */
     $hooks = \CRM_Utils_Hook::singleton();
     foreach ($this->findTestHooks($test) as $hook => $func) {
         $hooks->setHook($hook, array($test, $func));
     }
 }
Example #23
0
 /**
  * Get a list of boot services.
  *
  * These are services which must be setup *before* the container can operate.
  *
  * @param bool $loadFromDB
  * @throws \CRM_Core_Exception
  */
 public static function boot($loadFromDB)
 {
     $bootServices = array();
     \Civi::$statics[__CLASS__]['boot'] =& $bootServices;
     $bootServices['runtime'] = array('class' => 'CRM_Core_Config_Runtime', 'obj' => $runtime = new \CRM_Core_Config_Runtime());
     $runtime->initialize($loadFromDB);
     if ($loadFromDB && $runtime->dsn) {
         \CRM_Core_DAO::init($runtime->dsn);
     }
     $bootServices['paths'] = array('class' => 'Civi\\Core\\Paths', 'obj' => new \Civi\Core\Paths());
     $class = $runtime->userFrameworkClass;
     $bootServices['userSystem'] = array('class' => 'CRM_Utils_Cache_Interface', 'obj' => $userSystem = new $class());
     $userSystem->initialize();
     $userPermissionClass = 'CRM_Core_Permission_' . $runtime->userFramework;
     $bootServices['userPermissionClass'] = array('class' => 'CRM_Core_Permission_Base', 'obj' => new $userPermissionClass());
     $bootServices['cache.settings'] = array('class' => 'CRM_Utils_Cache_Interface', 'obj' => \CRM_Utils_Cache::create(array('name' => 'settings', 'type' => array('*memory*', 'SqlGroup', 'ArrayCache'))));
     $bootServices['settings_manager'] = array('class' => 'Civi\\Core\\SettingsManager', 'obj' => new \Civi\Core\SettingsManager($bootServices['cache.settings']['obj']));
     $bootServices['lockManager'] = array('class' => 'Civi\\Core\\Lock\\LockManager', 'obj' => self::createLockManager());
     if ($loadFromDB && $runtime->dsn) {
         \CRM_Utils_Hook::singleton(TRUE);
         \CRM_Extension_System::singleton(TRUE);
         $c = new self();
         \Civi::$statics[__CLASS__]['container'] = $c->loadContainer();
     }
 }
Example #24
0
 /**
  * Temporarily alter the settings-metadata to add a mock setting.
  *
  * WARNING: The setting metadata will disappear on the next cache-clear.
  *
  * @param $extras
  * @return void
  */
 public function setMockSettingsMetaData($extras)
 {
     Civi::service('settings_manager')->flush();
     CRM_Utils_Hook::singleton()->setHook('civicrm_alterSettingsMetaData', function (&$metadata, $domainId, $profile) use($extras) {
         $metadata = array_merge($metadata, $extras);
     });
     $fields = $this->callAPISuccess('setting', 'getfields', array());
     foreach ($extras as $key => $spec) {
         $this->assertNotEmpty($spec['title']);
         $this->assertEquals($spec['title'], $fields['values'][$key]['title']);
     }
 }
 protected function tearDown()
 {
     CRM_Utils_Hook::singleton()->reset();
     CRM_Core_DAO_AllCoreTables::init(1);
     parent::tearDown();
 }
Example #26
0
 /**
  * Clean up after each test.
  */
 public function tearDown()
 {
     $this->quickCleanUpFinancialEntities();
     CRM_Utils_Hook::singleton()->reset();
 }
 /**
  * hook_civicrm_conditionalFields is used to specify which extensions have
  * show/hide condition definitions supported by this extension
  *
  * @param array $enableForExtensions An array of extensions implementing
  *    conditional fields, e.g.,
  *        $enableForExtensions[] = 'org.xyz.eventregistration'
  * @return null The return value is ignored
  */
 public static function conditionalFields(array &$enableForExtensions)
 {
     return CRM_Utils_Hook::singleton()->invoke(1, $enableForExtensions, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, 'civicrm_conditionalFields');
 }
Example #28
0
 function tearDown()
 {
     $this->quickCleanup(array('civicrm_job'));
     CRM_Utils_Hook::singleton()->reset();
     parent::tearDown();
 }
 static function campaign_kpis($campaign_id, &$kpi_list, $level)
 {
     return CRM_Utils_Hook::singleton()->invoke(3, $campaign_id, $kpi_list, $level, self::$null, self::$null, self::$null, 'civicrm_campaign_kpis');
 }
 /**
  * Hook that allows 3rd party extensions alter the permissions
  * for a given user/file/action combo
  *
  *
  * @param $op
  *  The Action being requested
  * @param $file
  *  The File this action is being taken on
  * @param $user
  *  The user this file belongs to
  *
  * @return mixed
  *  (Bool) False for expressly deny operation
  *  (Bool) True for expressly allow this operation
  *  Null for fallback on built in permissions
  */
 public static function checkPermissions($op, $file, $user)
 {
     $valid = null;
     CRM_Utils_Hook::singleton()->invoke(4, $op, $file, $user, $valid, self::$_nullObject, self::$_nullObject, 'Securefiles_alterFilePermissions');
     return $valid;
 }