4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace api\v
4\Utils
;
24 use api\v
4\UnitTestCase
;
25 use Civi\Api4\Utils\SelectUtil
;
30 class SelectUtilTest
extends UnitTestCase
{
32 private $emailFieldNames = [
46 'contact.display_name',
49 'contact.phone.phone',
50 'contact.phone.phone_type_id',
53 public function getSelectExamples() {
56 ['any', ['*', 'one', 'two'], TRUE],
57 ['one', ['one', 'two'], TRUE],
58 ['one', ['o*', 'two'], TRUE],
59 ['one', ['*o', 'two'], FALSE],
60 ['zoo', ['one', 'two'], FALSE],
61 ['one.id', ['one.id', 'two'], TRUE],
62 ['one.id', ['one.*', 'two'], TRUE],
67 * @dataProvider getSelectExamples
68 * @param string $field
69 * @param array $selects
70 * @param bool $expected
72 public function testIsFieldSelected($field, $selects, $expected) {
73 $this->assertEquals($expected, SelectUtil
::isFieldSelected($field, $selects));
76 public function getMatchingExamples() {
78 [array_slice($this->emailFieldNames
, 0, 12), '*'],
81 [['contact_id', 'location_type_id'], '*_id'],
82 [['contact_id', 'location_type_id'], '*o*_id'],
83 [['contact_id'], 'con*_id'],
84 [['is_primary', 'is_billing', 'is_bulkmail'], 'is_*'],
85 [['is_billing', 'is_bulkmail'], 'is_*l*'],
86 [['contact.id', 'contact.display_name', 'contact.sort_name'], 'contact.*'],
87 [['contact.display_name', 'contact.sort_name'], 'contact.*_name'],
88 [['contact.phone.id', 'contact.phone.phone', 'contact.phone.phone_type_id'], 'contact.phone.*'],
89 [['contact.phone.phone', 'contact.phone.phone_type_id'], 'contact.phone.phone*'],
94 * @dataProvider getMatchingExamples
98 public function testGetMatchingFields($expected, $pattern) {
99 $this->assertEquals($expected, SelectUtil
::getMatchingFields($pattern, $this->emailFieldNames
));