From 9099cab32034e86e611f8e52c4a633494e26eac5 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 22 Jul 2019 17:33:36 -0400 Subject: [PATCH] Autoformat /tests directory with php short array syntax --- tests/phpunit/CRM/ACL/ListTest.php | 100 +- .../CRM/Activity/ActionMappingTest.php | 100 +- .../Activity/BAO/ActivityAssignmentTest.php | 2 +- .../CRM/Activity/BAO/ActivityTargetTest.php | 2 +- .../phpunit/CRM/Activity/BAO/ActivityTest.php | 324 ++-- .../CRM/Activity/Form/ActivityTest.php | 28 +- tests/phpunit/CRM/Batch/BAO/BatchTest.php | 8 +- tests/phpunit/CRM/Batch/Form/EntryTest.php | 110 +- tests/phpunit/CRM/Bridge/OG/DrupalTest.php | 24 +- tests/phpunit/CRM/Case/BAO/CaseTest.php | 20 +- .../phpunit/CRM/Case/BAO/CaseTypeForkTest.php | 44 +- tests/phpunit/CRM/Case/BAO/CaseTypeTest.php | 150 +- tests/phpunit/CRM/Case/BAO/QueryTest.php | 20 +- tests/phpunit/CRM/Case/PseudoConstantTest.php | 4 +- tests/phpunit/CRM/Case/XMLRepositoryTest.php | 42 +- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 428 ++--- .../CRM/Contact/BAO/GroupContactCacheTest.php | 160 +- .../CRM/Contact/BAO/GroupContactTest.php | 176 +- tests/phpunit/CRM/Contact/BAO/GroupTest.php | 58 +- .../CRM/Contact/BAO/IndividualTest.php | 26 +- .../CRM/Contact/BAO/QueryStateNameTest.php | 12 +- .../CRM/Contact/BAO/QueryTestDataProvider.php | 106 +- .../CRM/Contact/BAO/RelationshipTest.php | 40 +- .../CRM/Contact/BAO/SavedSearchTest.php | 214 +-- .../Form/Search/Custom/FullTextTest.php | 20 +- .../Contact/Form/Search/Custom/GroupTest.php | 30 +- .../Search/Custom/GroupTestDataProvider.php | 224 +-- .../Contact/Form/Search/Custom/SampleTest.php | 24 +- .../Search/Custom/SampleTestDataProvider.php | 52 +- .../CRM/Contact/Form/Task/EmailCommonTest.php | 28 +- .../Contact/Form/Task/PrintDocumentTest.php | 22 +- .../Contact/Import/Form/DataSourceTest.php | 4 +- .../CRM/Contact/Import/Form/MapFieldTest.php | 78 +- .../CRM/Contact/Import/Parser/ContactTest.php | 178 +- tests/phpunit/CRM/Contact/Page/AjaxTest.php | 196 +- .../CRM/Contact/Page/DedupeExceptionTest.php | 4 +- .../View/UserDashboard/GroupContactTest.php | 68 +- .../Contribute/ActionMapping/ByTypeTest.php | 126 +- .../Contribute/BAO/ContributionPageTest.php | 28 +- .../Contribute/BAO/ContributionRecurTest.php | 16 +- .../CRM/Contribute/BAO/ContributionTest.php | 526 +++--- .../Contribute/BAO/ContributionTypeTest.php | 28 +- .../CRM/Contribute/BAO/ProductTest.php | 24 +- .../Contribute/Form/AdditionalPaymentTest.php | 104 +- .../Form/Contribution/ConfirmTest.php | 38 +- .../Contribute/Form/Contribution/MainTest.php | 60 +- .../Form/Contribution/ThankYouTest.php | 12 +- .../CRM/Contribute/Form/ContributionTest.php | 536 +++--- .../CRM/Contribute/Form/SearchTest.php | 132 +- .../CRM/Contribute/Form/Task/InvoiceTest.php | 24 +- .../Form/Task/PDFLetterCommonTest.php | 78 +- .../CRM/Contribute/Form/Task/StatusTest.php | 12 +- .../phpunit/CRM/Contribute/Form/TaskTest.php | 16 +- .../Import/Parser/ContributionTest.php | 24 +- .../phpunit/CRM/Contribute/Page/AjaxTest.php | 60 +- .../CRM/Contribute/Selector/SearchTest.php | 4 +- .../CRM/Core/BAO/ActionScheduleTest.php | 1226 ++++++------ tests/phpunit/CRM/Core/BAO/AddressTest.php | 120 +- tests/phpunit/CRM/Core/BAO/CacheTest.php | 2 +- .../CRM/Core/BAO/ConfigSettingTest.php | 4 +- .../phpunit/CRM/Core/BAO/CustomGroupTest.php | 152 +- .../phpunit/CRM/Core/BAO/CustomQueryTest.php | 62 +- .../Core/BAO/CustomValueTableMultipleTest.php | 68 +- .../Core/BAO/CustomValueTableSetGetTest.php | 64 +- .../CRM/Core/BAO/CustomValueTableTest.php | 98 +- .../phpunit/CRM/Core/BAO/CustomValueTest.php | 30 +- tests/phpunit/CRM/Core/BAO/DashboardTest.php | 8 +- tests/phpunit/CRM/Core/BAO/EmailTest.php | 44 +- .../CRM/Core/BAO/FinancialTrxnTest.php | 86 +- tests/phpunit/CRM/Core/BAO/IMTest.php | 12 +- tests/phpunit/CRM/Core/BAO/LocationTest.php | 256 +-- .../CRM/Core/BAO/MessageTemplateTest.php | 113 +- tests/phpunit/CRM/Core/BAO/NavigationTest.php | 100 +- tests/phpunit/CRM/Core/BAO/OpenIDTest.php | 24 +- .../phpunit/CRM/Core/BAO/OptionGroupTest.php | 12 +- .../phpunit/CRM/Core/BAO/OptionValueTest.php | 16 +- tests/phpunit/CRM/Core/BAO/PhoneTest.php | 20 +- .../CRM/Core/BAO/PrevNextCacheTest.php | 12 +- .../CRM/Core/BAO/RecurringEntityTest.php | 101 +- .../CRM/Core/BAO/SchemaHandlerTest.php | 96 +- tests/phpunit/CRM/Core/BAO/SettingTest.php | 30 +- tests/phpunit/CRM/Core/BAO/UFFieldTest.php | 48 +- .../CRM/Core/CodeGen/FreshnessTest.php | 4 +- .../CRM/Core/CommunityMessagesTest.php | 128 +- tests/phpunit/CRM/Core/ComposerConfigTest.php | 6 +- tests/phpunit/CRM/Core/Config/MailerTest.php | 14 +- .../CRM/Core/DAO/AllCoreTablesTest.php | 118 +- tests/phpunit/CRM/Core/DAOConformanceTest.php | 4 +- tests/phpunit/CRM/Core/DAOTest.php | 202 +- tests/phpunit/CRM/Core/FieldOptionsTest.php | 66 +- tests/phpunit/CRM/Core/I18n/SchemaTest.php | 10 +- tests/phpunit/CRM/Core/InnoDBIndexerTest.php | 58 +- .../phpunit/CRM/Core/ManagedEntitiesTest.php | 114 +- tests/phpunit/CRM/Core/MenuTest.php | 56 +- tests/phpunit/CRM/Core/OptionGroupTest.php | 16 +- tests/phpunit/CRM/Core/Page/AJAXTest.php | 66 +- tests/phpunit/CRM/Core/Page/HookTest.php | 28 +- tests/phpunit/CRM/Core/Page/RedirectTest.php | 18 +- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 122 +- .../CRM/Core/Payment/AuthorizeNetTest.php | 44 +- .../phpunit/CRM/Core/Payment/BaseIPNTest.php | 126 +- .../CRM/Core/Payment/PayPalIPNTest.php | 86 +- .../CRM/Core/Payment/PayPalProIPNTest.php | 68 +- tests/phpunit/CRM/Core/PaymentTest.php | 4 +- .../phpunit/CRM/Core/Permission/BaseTest.php | 22 +- .../CRM/Core/Permission/GenericTest.php | 10 +- .../CRM/Core/Permission/JoomlaTest.php | 18 +- tests/phpunit/CRM/Core/PseudoConstantTest.php | 1122 +++++------ tests/phpunit/CRM/Core/RegionTest.php | 106 +- .../CRM/Core/Resources/StringsTest.php | 4 +- tests/phpunit/CRM/Core/ResourcesTest.php | 92 +- .../CRM/Core/Smarty/plugins/CrmScopeTest.php | 26 +- tests/phpunit/CRM/Core/TransactionTest.php | 162 +- tests/phpunit/CRM/Custom/Page/AJAXTest.php | 30 +- tests/phpunit/CRM/Dedupe/DedupeFinderTest.php | 102 +- .../CRM/Event/BAO/EventPermissionsTest.php | 8 +- .../CRM/Event/BAO/ParticipantStatusTest.php | 24 +- .../Event/Form/Registration/ConfirmTest.php | 114 +- .../Form/Registration/RegistrationTest.php | 14 +- tests/phpunit/CRM/Event/Form/SearchTest.php | 20 +- tests/phpunit/CRM/Extension/BrowserTest.php | 12 +- .../CRM/Extension/Container/BasicTest.php | 16 +- .../Extension/Container/CollectionTest.php | 48 +- .../CRM/Extension/Container/StaticTest.php | 18 +- tests/phpunit/CRM/Extension/InfoTest.php | 4 +- .../CRM/Extension/Manager/ModuleTest.php | 78 +- .../CRM/Extension/Manager/PaymentTest.php | 34 +- .../CRM/Extension/Manager/ReportTest.php | 16 +- .../CRM/Extension/Manager/SearchTest.php | 16 +- tests/phpunit/CRM/Extension/ManagerTest.php | 124 +- tests/phpunit/CRM/Extension/MapperTest.php | 28 +- .../Financial/BAO/FinancialAccountTest.php | 108 +- .../CRM/Financial/BAO/FinancialItemTest.php | 72 +- .../BAO/FinancialTypeAccountTest.php | 30 +- .../CRM/Financial/BAO/FinancialTypeTest.php | 118 +- .../Financial/BAO/PaymentProcessorTest.php | 12 +- .../BAO/PaymentProcessorTypeTest.php | 26 +- .../CRM/Financial/Form/PaymentEditTest.php | 44 +- .../Financial/Page/AjaxBatchSummaryTest.php | 4 +- tests/phpunit/CRM/Financial/Page/AjaxTest.php | 4 +- tests/phpunit/CRM/Group/Page/AjaxTest.php | 92 +- .../phpunit/CRM/Import/DataSource/CsvTest.php | 10 +- tests/phpunit/CRM/Logging/LoggingTest.php | 12 +- tests/phpunit/CRM/Logging/SchemaTest.php | 8 +- tests/phpunit/CRM/Mailing/BAO/MailingTest.php | 242 +-- tests/phpunit/CRM/Mailing/BAO/QueryTest.php | 6 +- .../CRM/Mailing/BAO/QueryTestDataProvider.php | 156 +- tests/phpunit/CRM/Mailing/BAO/SpoolTest.php | 14 +- .../CRM/Mailing/BaseMailingSystemTest.php | 106 +- .../phpunit/CRM/Mailing/MailingSystemTest.php | 4 +- tests/phpunit/CRM/Mailing/TokensTest.php | 60 +- .../CRM/Member/BAO/MembershipLogTest.php | 34 +- .../CRM/Member/BAO/MembershipStatusTest.php | 42 +- .../phpunit/CRM/Member/BAO/MembershipTest.php | 206 +- .../CRM/Member/BAO/MembershipTypeTest.php | 108 +- tests/phpunit/CRM/Member/BAO/QueryTest.php | 36 +- .../CRM/Member/Form/MembershipRenewalTest.php | 186 +- .../CRM/Member/Form/MembershipTest.php | 468 ++--- .../Member/Form/Task/PDFLetterCommonTest.php | 24 +- .../Member/Import/Parser/MembershipTest.php | 78 +- tests/phpunit/CRM/PCP/BAO/PCPTest.php | 6 +- .../CRM/Pledge/BAO/PledgeBlockTest.php | 34 +- .../CRM/Pledge/BAO/PledgePaymentTest.php | 90 +- tests/phpunit/CRM/Pledge/BAO/PledgeTest.php | 32 +- tests/phpunit/CRM/Pledge/Form/SearchTest.php | 10 +- tests/phpunit/CRM/Price/BAO/PriceSetTest.php | 66 +- tests/phpunit/CRM/Price/Form/FieldTest.php | 20 +- tests/phpunit/CRM/Queue/Queue/SqlTest.php | 44 +- tests/phpunit/CRM/Queue/QueueTest.php | 74 +- tests/phpunit/CRM/Queue/RunnerTest.php | 116 +- .../phpunit/CRM/Report/Form/ActivityTest.php | 70 +- .../CRM/Report/Form/ContactSummaryTest.php | 4 +- .../CRM/Report/Form/Contribute/DetailTest.php | 48 +- .../phpunit/CRM/Report/Form/TestCaseTest.php | 66 +- tests/phpunit/CRM/Report/FormTest.php | 8 +- tests/phpunit/CRM/SMS/BAO/ProviderTest.php | 28 +- tests/phpunit/CRM/SMS/ProviderTest.php | 20 +- .../phpunit/CRM/UF/Page/ProfileEditorTest.php | 2 +- .../phpunit/CRM/Utils/API/MatchOptionTest.php | 174 +- .../CRM/Utils/API/ReloadOptionTest.php | 46 +- tests/phpunit/CRM/Utils/AddressTest.php | 12 +- tests/phpunit/CRM/Utils/ArrayTest.php | 186 +- tests/phpunit/CRM/Utils/AutoCleanTest.php | 4 +- .../phpunit/CRM/Utils/Cache/SqlGroupTest.php | 38 +- tests/phpunit/CRM/Utils/DateTest.php | 8 +- .../phpunit/CRM/Utils/DeprecatedUtilsTest.php | 8 +- tests/phpunit/CRM/Utils/FileTest.php | 24 +- tests/phpunit/CRM/Utils/GlobalStackTest.php | 8 +- tests/phpunit/CRM/Utils/HTMLTest.php | 104 +- tests/phpunit/CRM/Utils/HookTest.php | 20 +- tests/phpunit/CRM/Utils/HtmlToTextTest.php | 14 +- tests/phpunit/CRM/Utils/HttpClientTest.php | 12 +- tests/phpunit/CRM/Utils/ICalendarTest.php | 10 +- tests/phpunit/CRM/Utils/JSTest.php | 130 +- .../CRM/Utils/Mail/EmailProcessorTest.php | 44 +- tests/phpunit/CRM/Utils/MailTest.php | 28 +- .../CRM/Utils/Migrate/ImportExportTest.php | 92 +- tests/phpunit/CRM/Utils/MoneyTest.php | 16 +- tests/phpunit/CRM/Utils/NumberTest.php | 22 +- .../phpunit/CRM/Utils/QueryFormatterTest.php | 158 +- tests/phpunit/CRM/Utils/RestTest.php | 20 +- tests/phpunit/CRM/Utils/RuleTest.php | 90 +- tests/phpunit/CRM/Utils/SQL/DeleteTest.php | 10 +- tests/phpunit/CRM/Utils/SQL/InsertTest.php | 18 +- tests/phpunit/CRM/Utils/SQL/SelectTest.php | 98 +- tests/phpunit/CRM/Utils/SignerTest.php | 102 +- tests/phpunit/CRM/Utils/StringTest.php | 206 +- tests/phpunit/CRM/Utils/SystemTest.php | 6 +- tests/phpunit/CRM/Utils/TimeTest.php | 16 +- tests/phpunit/CRM/Utils/TokenTest.php | 44 +- tests/phpunit/CRM/Utils/TypeTest.php | 168 +- tests/phpunit/CRM/Utils/ZipTest.php | 56 +- tests/phpunit/CRM/Utils/versionCheckTest.php | 164 +- tests/phpunit/Civi/API/KernelTest.php | 38 +- tests/phpunit/Civi/API/RequestTest.php | 56 +- .../Subscriber/DynamicFKAuthorizationTest.php | 106 +- .../Subscriber/TransactionSubscriberTest.php | 66 +- .../Subscriber/WhitelistSubscriberTest.php | 316 ++-- .../ActionSchedule/AbstractMappingTest.php | 34 +- tests/phpunit/Civi/Angular/ChangeSetTest.php | 14 +- tests/phpunit/Civi/Angular/ManagerTest.php | 32 +- .../Civi/Angular/PartialSyntaxTest.php | 32 +- .../Civi/CCase/SequenceListenerTest.php | 36 +- .../Civi/Core/CiviEventInspectorTest.php | 2 +- tests/phpunit/Civi/Core/CiviFacadeTest.php | 2 +- .../Civi/Core/Event/GenericHookEventTest.php | 30 +- tests/phpunit/Civi/Core/ResolverTest.php | 2 +- tests/phpunit/Civi/Core/SettingsBagTest.php | 2 +- .../phpunit/Civi/Core/SettingsManagerTest.php | 22 +- tests/phpunit/Civi/Test/ExampleHookTest.php | 4 +- .../Civi/Test/ExampleTransactionalTest.php | 6 +- .../phpunit/Civi/Token/TokenProcessorTest.php | 104 +- tests/phpunit/api/v3/ACLCachingTest.php | 12 +- tests/phpunit/api/v3/APITest.php | 38 +- tests/phpunit/api/v3/APIWrapperTest.php | 6 +- tests/phpunit/api/v3/ActionScheduleTest.php | 12 +- tests/phpunit/api/v3/ActivityCaseTest.php | 42 +- tests/phpunit/api/v3/ActivityContactTest.php | 24 +- tests/phpunit/api/v3/ActivityTest.php | 432 ++--- tests/phpunit/api/v3/ActivityTypeTest.php | 18 +- tests/phpunit/api/v3/AddressTest.php | 144 +- tests/phpunit/api/v3/AttachmentTest.php | 288 +-- tests/phpunit/api/v3/BatchTest.php | 22 +- tests/phpunit/api/v3/CRM11793Test.php | 4 +- tests/phpunit/api/v3/CampaignTest.php | 10 +- tests/phpunit/api/v3/CaseContactTest.php | 16 +- tests/phpunit/api/v3/CaseTest.php | 434 ++--- tests/phpunit/api/v3/CaseTypeTest.php | 108 +- tests/phpunit/api/v3/ConstantTest.php | 24 +- tests/phpunit/api/v3/ContactTypeTest.php | 140 +- tests/phpunit/api/v3/ContributionPageTest.php | 746 ++++---- .../phpunit/api/v3/ContributionRecurTest.php | 20 +- tests/phpunit/api/v3/ContributionSoftTest.php | 112 +- tests/phpunit/api/v3/ContributionTest.php | 1668 ++++++++--------- tests/phpunit/api/v3/CountryTest.php | 24 +- tests/phpunit/api/v3/CustomApiTest.php | 18 +- tests/phpunit/api/v3/CustomGroupTest.php | 90 +- tests/phpunit/api/v3/CustomSearchTest.php | 18 +- .../api/v3/CustomValueContactTypeTest.php | 88 +- tests/phpunit/api/v3/CustomValueTest.php | 212 +-- tests/phpunit/api/v3/DashboardContactTest.php | 12 +- tests/phpunit/api/v3/DashboardTest.php | 18 +- tests/phpunit/api/v3/DomainTest.php | 50 +- tests/phpunit/api/v3/EmailTest.php | 224 +-- tests/phpunit/api/v3/EntityBatchTest.php | 12 +- tests/phpunit/api/v3/EntityJoinTest.php | 10 +- tests/phpunit/api/v3/EntityTagACLTest.php | 58 +- tests/phpunit/api/v3/EntityTagTest.php | 108 +- tests/phpunit/api/v3/EventTest.php | 270 +-- tests/phpunit/api/v3/ExtensionTest.php | 24 +- tests/phpunit/api/v3/FinancialTypeACLTest.php | 70 +- tests/phpunit/api/v3/GrantTest.php | 48 +- tests/phpunit/api/v3/GroupContactTest.php | 118 +- .../phpunit/api/v3/GroupOrganizationTest.php | 50 +- .../phpunit/api/v3/JobProcessMailingTest.php | 180 +- .../phpunit/api/v3/JobTestCustomDataTest.php | 208 +- tests/phpunit/api/v3/LineItemTest.php | 26 +- tests/phpunit/api/v3/LoggingTest.php | 184 +- tests/phpunit/api/v3/MailingABTest.php | 98 +- tests/phpunit/api/v3/MailingContactTest.php | 12 +- tests/phpunit/api/v3/MailingGroupTest.php | 36 +- tests/phpunit/api/v3/MailingTest.php | 446 ++--- tests/phpunit/api/v3/MappingFieldTest.php | 14 +- tests/phpunit/api/v3/MappingTest.php | 14 +- .../phpunit/api/v3/MembershipPaymentTest.php | 26 +- tests/phpunit/api/v3/MembershipStatusTest.php | 48 +- tests/phpunit/api/v3/MembershipTest.php | 502 ++--- tests/phpunit/api/v3/MembershipTypeTest.php | 132 +- tests/phpunit/api/v3/MessageTemplateTest.php | 51 +- tests/phpunit/api/v3/MultilingualTest.php | 42 +- tests/phpunit/api/v3/NavigationTest.php | 24 +- tests/phpunit/api/v3/NoteTest.php | 60 +- tests/phpunit/api/v3/OpenIDTest.php | 14 +- tests/phpunit/api/v3/OptionValueTest.php | 194 +- tests/phpunit/api/v3/OrderTest.php | 270 +-- .../phpunit/api/v3/ParticipantPaymentTest.php | 146 +- .../api/v3/ParticipantStatusTypeTest.php | 12 +- tests/phpunit/api/v3/ParticipantTest.php | 248 +-- tests/phpunit/api/v3/PaymentProcessorTest.php | 30 +- .../api/v3/PaymentProcessorTypeTest.php | 50 +- tests/phpunit/api/v3/PaymentTokenTest.php | 10 +- tests/phpunit/api/v3/PcpTest.php | 18 +- tests/phpunit/api/v3/PhoneTest.php | 34 +- tests/phpunit/api/v3/PledgePaymentTest.php | 124 +- tests/phpunit/api/v3/PledgeTest.php | 164 +- tests/phpunit/api/v3/PriceFieldTest.php | 56 +- tests/phpunit/api/v3/PriceFieldValueTest.php | 86 +- tests/phpunit/api/v3/PriceSetTest.php | 46 +- tests/phpunit/api/v3/ProductTest.php | 8 +- tests/phpunit/api/v3/RelationshipTest.php | 434 ++--- tests/phpunit/api/v3/RelationshipTypeTest.php | 60 +- tests/phpunit/api/v3/ReportTemplateTest.php | 364 ++-- tests/phpunit/api/v3/SavedSearchTest.php | 28 +- tests/phpunit/api/v3/SelectQueryTest.php | 30 +- tests/phpunit/api/v3/SettingTest.php | 208 +- tests/phpunit/api/v3/StateProvinceTest.php | 24 +- tests/phpunit/api/v3/StatusPreferenceTest.php | 18 +- tests/phpunit/api/v3/SurveyRespondantTest.php | 10 +- tests/phpunit/api/v3/SurveyTest.php | 18 +- .../phpunit/api/v3/SyntaxConformanceTest.php | 564 +++--- tests/phpunit/api/v3/SystemCheckTest.php | 56 +- tests/phpunit/api/v3/SystemTest.php | 20 +- tests/phpunit/api/v3/TagTest.php | 50 +- .../api/v3/TaxContributionPageTest.php | 158 +- tests/phpunit/api/v3/UFGroupTest.php | 30 +- tests/phpunit/api/v3/UFJoinTest.php | 46 +- tests/phpunit/api/v3/UFMatchTest.php | 50 +- tests/phpunit/api/v3/UserTest.php | 6 +- tests/phpunit/api/v3/UtilsTest.php | 188 +- tests/phpunit/api/v3/ValidateTest.php | 32 +- tests/phpunit/api/v3/WebsiteTest.php | 26 +- .../api/v3/custom_api/MailingProviderData.php | 38 +- .../api/v3/Contact/ExampleAction2.php | 2 +- .../api/v3/Generic/ExampleAction1.php | 2 +- .../api/v3/Generic/ExampleAction2.php | 2 +- .../v3/dataset/resolver/api/v3/TestEntity.php | 2 +- .../phpunit/api/v3/settings/test.setting.php | 24 +- 337 files changed, 14739 insertions(+), 14718 deletions(-) diff --git a/tests/phpunit/CRM/ACL/ListTest.php b/tests/phpunit/CRM/ACL/ListTest.php index c9b78c76ef..c435ffca4c 100644 --- a/tests/phpunit/CRM/ACL/ListTest.php +++ b/tests/phpunit/CRM/ACL/ListTest.php @@ -17,7 +17,7 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { parent::setUp(); // $this->quickCleanup(array('civicrm_acl_contact_cache'), TRUE); $this->useTransaction(TRUE); - $this->allowedContactsACL = array(); + $this->allowedContactsACL = []; } /** @@ -35,19 +35,19 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'"); // test WITH explicit permission - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts']; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::VIEW); sort($result); $this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'"); // test WITH EDIT permissions (should imply VIEW) - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts']; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::VIEW); sort($result); $this->assertEquals($result, $contacts, "Contacts should be viewable when 'edit all contacts'"); // test WITHOUT permission - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); sort($result); $this->assertEmpty($result, "Contacts should NOT be viewable when 'view all contacts' is not set"); @@ -61,13 +61,13 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $contacts = $this->createScenarioPlain(); // test WITH explicit permission - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts']; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::EDIT); sort($result); $this->assertEquals($result, $contacts, "Contacts should be viewable when 'edit all contacts'"); // test WITHOUT permission - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); sort($result); $this->assertEmpty($result, "Contacts should NOT be viewable when 'edit all contacts' is not set"); @@ -82,12 +82,12 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // delete one contact $deleted_contact_id = $contacts[2]; - $this->callAPISuccess('Contact', 'create', array('id' => $deleted_contact_id, 'contact_is_deleted' => 1)); - $deleted_contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $deleted_contact_id)); + $this->callAPISuccess('Contact', 'create', ['id' => $deleted_contact_id, 'contact_is_deleted' => 1]); + $deleted_contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $deleted_contact_id]); $this->assertEquals($deleted_contact['contact_is_deleted'], 1, "Contact should've been deleted"); // test WITH explicit permission - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts', 'view all contacts'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts', 'view all contacts']; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::EDIT); sort($result); $this->assertNotContains($deleted_contact_id, $result, "Deleted contacts should be excluded"); @@ -106,8 +106,8 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // remove all permissions $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array(); - $permissions_to_check = array(CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit'); + $config->userPermissionClass->permissions = []; + $permissions_to_check = [CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit']; // run this for SIMPLE relations $config->secondDegRelPermissions = FALSE; @@ -182,13 +182,13 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $contacts = $this->createScenarioPlain(); // set custom hook - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause')); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']); // run simple test - $permissions_to_check = array(CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit'); + $permissions_to_check = [CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit']; - $this->allowedContactsACL = array($contacts[0], $contacts[1], $contacts[4]); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); + $this->allowedContactsACL = [$contacts[0], $contacts[1], $contacts[4]]; + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); sort($result); @@ -206,14 +206,14 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $contacts = $this->createScenarioRelations(); // set custom hook - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause')); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']); $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array(); + $config->userPermissionClass->permissions = []; $config->secondDegRelPermissions = TRUE; - $this->allowedContactsACL = array($contacts[0], $contacts[1], $contacts[4]); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); + $this->allowedContactsACL = [$contacts[0], $contacts[1], $contacts[4]]; + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); sort($result); @@ -232,15 +232,15 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $contact_index = array_flip($contacts); // set custom hook - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause')); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']); $config = CRM_Core_Config::singleton(); - $this->allowedContactsACL = array($contacts[0], $contacts[1], $contacts[4]); + $this->allowedContactsACL = [$contacts[0], $contacts[1], $contacts[4]]; $config->secondDegRelPermissions = TRUE; // test configurations - $permissions_to_check = array(CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit'); - $user_permission_options = array(/*ALL*/ NULL, /*NONE*/ array(), array('view all contacts'), array('edit all contacts'), array('view all contacts', 'edit all contacts')); + $permissions_to_check = [CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit']; + $user_permission_options = [/*ALL*/ NULL, /*NONE*/ [], ['view all contacts'], ['edit all contacts'], ['view all contacts', 'edit all contacts']]; // run all combinations of those foreach ($permissions_to_check as $permission_to_check => $permission_label) { @@ -294,17 +294,17 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $this->assertNotEmpty($user_id); // create test contacts - $bush_sr_id = $this->individualCreate(array('first_name' => 'George', 'middle_name' => 'H. W.', 'last_name' => 'Bush')); - $bush_jr_id = $this->individualCreate(array('first_name' => 'George', 'middle_name' => 'W.', 'last_name' => 'Bush')); - $bush_laura_id = $this->individualCreate(array('first_name' => 'Laura Lane', 'last_name' => 'Bush')); - $bush_brbra_id = $this->individualCreate(array('first_name' => 'Barbara', 'last_name' => 'Bush')); - $bush_brother_id = $this->individualCreate(array('first_name' => 'Brother', 'last_name' => 'Bush')); - $bush_nephew_id = $this->individualCreate(array('first_name' => 'Nephew', 'last_name' => 'Bush')); - $bush_nephew2_id = $this->individualCreate(array('first_name' => 'Nephew2', 'last_name' => 'Bush')); - $bush_otherbro_id = $this->individualCreate(array('first_name' => 'Other Brother', 'last_name' => 'Bush')); - $bush_otherneph_id = $this->individualCreate(array('first_name' => 'Other Nephew', 'last_name' => 'Bush')); - - $contacts = array($user_id, $bush_sr_id, $bush_jr_id, $bush_laura_id, $bush_brbra_id, $bush_brother_id, $bush_nephew_id, $bush_nephew2_id, $bush_otherbro_id, $bush_otherneph_id); + $bush_sr_id = $this->individualCreate(['first_name' => 'George', 'middle_name' => 'H. W.', 'last_name' => 'Bush']); + $bush_jr_id = $this->individualCreate(['first_name' => 'George', 'middle_name' => 'W.', 'last_name' => 'Bush']); + $bush_laura_id = $this->individualCreate(['first_name' => 'Laura Lane', 'last_name' => 'Bush']); + $bush_brbra_id = $this->individualCreate(['first_name' => 'Barbara', 'last_name' => 'Bush']); + $bush_brother_id = $this->individualCreate(['first_name' => 'Brother', 'last_name' => 'Bush']); + $bush_nephew_id = $this->individualCreate(['first_name' => 'Nephew', 'last_name' => 'Bush']); + $bush_nephew2_id = $this->individualCreate(['first_name' => 'Nephew2', 'last_name' => 'Bush']); + $bush_otherbro_id = $this->individualCreate(['first_name' => 'Other Brother', 'last_name' => 'Bush']); + $bush_otherneph_id = $this->individualCreate(['first_name' => 'Other Nephew', 'last_name' => 'Bush']); + + $contacts = [$user_id, $bush_sr_id, $bush_jr_id, $bush_laura_id, $bush_brbra_id, $bush_brother_id, $bush_nephew_id, $bush_nephew2_id, $bush_otherbro_id, $bush_otherneph_id]; sort($contacts); return $contacts; } @@ -316,34 +316,34 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { $contacts = $this->createScenarioPlain(); // create some relationships - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // CHILD OF 'relationship_type_id' => 1, 'contact_id_a' => $contacts[1], 'contact_id_b' => $contacts[0], 'is_permission_b_a' => 1, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // CHILD OF 'relationship_type_id' => 1, 'contact_id_a' => $contacts[2], 'contact_id_b' => $contacts[1], 'is_permission_b_a' => 1, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // CHILD OF 'relationship_type_id' => 1, 'contact_id_a' => $contacts[4], 'contact_id_b' => $contacts[2], 'is_permission_b_a' => 1, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // SIBLING OF 'relationship_type_id' => 4, 'contact_id_a' => $contacts[5], @@ -351,9 +351,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // View 'is_permission_b_a' => 2, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // CHILD OF 'relationship_type_id' => 1, 'contact_id_a' => $contacts[6], @@ -361,9 +361,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // Edit 'is_permission_b_a' => 1, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // CHILD OF 'relationship_type_id' => 1, 'contact_id_a' => $contacts[7], @@ -371,9 +371,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // View 'is_permission_b_a' => 2, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // SIBLING OF 'relationship_type_id' => 4, 'contact_id_a' => $contacts[0], @@ -381,9 +381,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // edit (as a_b) 'is_permission_a_b' => 1, 'is_active' => 1, - )); + ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // CHILD OF 'relationship_type_id' => 1, 'contact_id_a' => $contacts[9], @@ -391,7 +391,7 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { // view 'is_permission_b_a' => 2, 'is_active' => 1, - )); + ]); return $contacts; } diff --git a/tests/phpunit/CRM/Activity/ActionMappingTest.php b/tests/phpunit/CRM/Activity/ActionMappingTest.php index d28dd4284f..12110efbb6 100644 --- a/tests/phpunit/CRM/Activity/ActionMappingTest.php +++ b/tests/phpunit/CRM/Activity/ActionMappingTest.php @@ -57,19 +57,19 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin * - subject: regex */ public function createTestCases() { - $cs = array(); + $cs = []; - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', 'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource', - array( - array( + [ + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('alice@example.org'), + 'to' => ['alice@example.org'], 'subject' => '/Hello, Alice.*via subject/', - ), - ), - ); + ], + ], + ]; // FIXME: CRM-19415: This test should pass... // $cs[] = array( @@ -85,61 +85,61 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin // ), // ); - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', 'addAliceMeeting addBobPhoneCall scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource', - array( - array( + [ + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('alice@example.org'), + 'to' => ['alice@example.org'], 'subject' => '/Hello, Alice.*via subject/', - ), - ), - ); + ], + ], + ]; - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', 'addAliceMeeting addBobPhoneCall scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource', - array( - array( + [ + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('alice@example.org'), + 'to' => ['alice@example.org'], 'subject' => '/Hello, Alice.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - ), - ); + ], + ], + ]; - $cs[] = array( + $cs[] = [ '2015-02-02 00:00:00', 'addAliceMeeting addBobPhoneCall scheduleForPhoneCall startWeekBefore repeatTwoWeeksAfter useHelloFirstName recipientIsActivitySource', - array( - array( + [ + [ 'time' => '2015-01-26 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-02 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-09 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-16 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - ), - ); + ], + ], + ]; return $cs; } @@ -148,28 +148,28 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin * Create an activity record for Alice with type "Meeting". */ public function addAliceMeeting() { - $this->callAPISuccess('Activity', 'create', array( + $this->callAPISuccess('Activity', 'create', [ 'source_contact_id' => $this->contacts['alice']['id'], 'activity_type_id' => 'Meeting', 'subject' => 'Subject for Alice', 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate)), 'status_id' => 2, - 'assignee_contact_id' => array($this->contacts['carol']['id']), - )); + 'assignee_contact_id' => [$this->contacts['carol']['id']], + ]); } /** * Create a contribution record for Bob with type "Donation". */ public function addBobPhoneCall() { - $this->callAPISuccess('Activity', 'create', array( + $this->callAPISuccess('Activity', 'create', [ 'source_contact_id' => $this->contacts['bob']['id'], 'activity_type_id' => 'Phone Call', 'subject' => 'Subject for Bob', 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate)), 'status_id' => 2, - 'assignee_contact_id' => array($this->contacts['carol']['id']), - )); + 'assignee_contact_id' => [$this->contacts['carol']['id']], + ]); } /** @@ -179,8 +179,8 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin $actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id'); $this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID; $this->schedule->start_action_date = 'receive_date'; - $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(array_search('Meeting', $actTypes))); - $this->schedule->entity_status = CRM_Utils_Array::implodePadded(array(2)); + $this->schedule->entity_value = CRM_Utils_Array::implodePadded([array_search('Meeting', $actTypes)]); + $this->schedule->entity_status = CRM_Utils_Array::implodePadded([2]); } /** @@ -190,7 +190,7 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin $actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id'); $this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID; $this->schedule->start_action_date = 'receive_date'; - $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(array_search('Phone Call', $actTypes))); + $this->schedule->entity_value = CRM_Utils_Array::implodePadded([array_search('Phone Call', $actTypes)]); $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL); } diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityAssignmentTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityAssignmentTest.php index ccf88dab76..691ddbbfff 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityAssignmentTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityAssignmentTest.php @@ -113,7 +113,7 @@ class CRM_Activity_BAO_ActivityAssignmentTest extends CiviUnitTestCase { */ public function testGetAssigneeNamesOneId() { $activity = $this->activityCreate(); - $assignees = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity['id'])); + $assignees = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames([$activity['id']]); $this->assertEquals(count($assignees), 1, '1 assignee names retrieved'); } diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php index 09330c5fbd..6d6aa5c749 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php @@ -52,7 +52,7 @@ class CRM_Activity_BAO_ActivityTargetTest extends CiviUnitTestCase { public function testRetrieveTargetIdsByActivityIdZeroID() { $this->activityCreate(); $target = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId(0); - $this->assertSame($target, array(), 'No targets returned'); + $this->assertSame($target, [], 'No targets returned'); } public function testRetrieveTargetIdsByActivityIdOneID() { diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 770188f08b..6b84cd7a3b 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -11,7 +11,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->prepareForACLs(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts', 'access CiviCRM'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts', 'access CiviCRM']; $this->setupForSmsTests(); } @@ -19,13 +19,13 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { * Clean up after tests. */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_activity', 'civicrm_activity_contact', 'civicrm_uf_match', 'civicrm_campaign', 'civicrm_email', - ); + ]; $this->quickCleanup($tablesToTruncate); $this->cleanUpAfterACLs(); $this->setupForSmsTests(TRUE); @@ -38,11 +38,11 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { public function testCreate() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - ); + ]; CRM_Activity_BAO_Activity::create($params); @@ -51,12 +51,12 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ); // Now call create() to modify an existing Activity. - $params = array( + $params = [ 'id' => $activityId, 'source_contact_id' => $contactId, 'subject' => 'Scheduling Interview', 'activity_type_id' => 3, - ); + ]; CRM_Activity_BAO_Activity::create($params); @@ -76,19 +76,19 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { */ public function testGetContactActivity() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'first_name' => 'liz', 'last_name' => 'hurleey', - ); + ]; $targetContactId = $this->individualCreate($params); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - 'target_contact_id' => array($targetContactId), + 'target_contact_id' => [$targetContactId], 'activity_date_time' => date('Ymd'), - ); + ]; $this->callAPISuccess('Activity', 'create', $params); @@ -114,19 +114,19 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { */ public function testRetrieve() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'first_name' => 'liz', 'last_name' => 'hurleey', - ); + ]; $targetContactId = $this->individualCreate($params); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - 'target_contact_id' => array($targetContactId), + 'target_contact_id' => [$targetContactId], 'activity_date_time' => date('Ymd'), - ); + ]; CRM_Activity_BAO_Activity::create($params); @@ -139,7 +139,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'Database check for created activity target.' ); - $defaults = array(); + $defaults = []; $activity = CRM_Activity_BAO_Activity::retrieve($params, $defaults); $this->assertEquals($activity->subject, 'Scheduling Meeting', 'Verify activity subject is correct.'); @@ -160,28 +160,28 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { */ public function testTargetContactNotavaliable() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'first_name' => 'liz', 'last_name' => 'hurleey', - ); + ]; $targetContactId = $this->individualCreate($params); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - 'target_contact_id' => array($targetContactId), + 'target_contact_id' => [$targetContactId], 'activity_date_time' => date('Ymd'), - ); + ]; CRM_Activity_BAO_Activity::create($params); // set custom hook - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause')); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; - $this->allowedContactsACL = array($contactId); + $this->allowedContactsACL = [$contactId]; // get logged in user $user_id = $this->createLoggedInUser(); @@ -204,20 +204,20 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { */ public function testDeleteActivity() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'first_name' => 'liz', 'last_name' => 'hurleey', - ); + ]; $targetContactId = $this->individualCreate($params); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'source_record_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - 'target_contact_id' => array($targetContactId), + 'target_contact_id' => [$targetContactId], 'activity_date_time' => date('Ymd'), - ); + ]; CRM_Activity_BAO_Activity::create($params); @@ -229,12 +229,12 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'id', 'contact_id', 'Database check for created activity target.' ); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'source_record_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - ); + ]; CRM_Activity_BAO_Activity::deleteActivity($params); @@ -252,19 +252,19 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { */ public function testDeleteActivityTarget() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'first_name' => 'liz', 'last_name' => 'hurleey', - ); + ]; $targetContactId = $this->individualCreate($params); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - 'target_contact_id' => array($targetContactId), + 'target_contact_id' => [$targetContactId], 'activity_date_time' => date('Ymd'), - ); + ]; CRM_Activity_BAO_Activity::create($params); @@ -294,19 +294,19 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { */ public function testDeleteActivityAssignment() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'first_name' => 'liz', 'last_name' => 'hurleey', - ); + ]; $assigneeContactId = $this->individualCreate($params); - $params = array( + $params = [ 'source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, - 'assignee_contact_id' => array($assigneeContactId), + 'assignee_contact_id' => [$assigneeContactId], 'activity_date_time' => date('Ymd'), - ); + ]; CRM_Activity_BAO_Activity::create($params); @@ -344,7 +344,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { public function testGetActivitiesCountforNonAdminDashboard() { $this->createTestActivities(); - $params = array( + $params = [ 'contact_id' => 9, 'admin' => FALSE, 'caseId' => NULL, @@ -355,7 +355,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ); + ]; //since we are loading activities from dataset, we know total number of activities for this contact // 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities @@ -368,7 +368,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { public function testGetActivitiesCountforContactSummary() { $this->createTestActivities(); - $params = array( + $params = [ 'contact_id' => 9, 'admin' => FALSE, 'caseId' => NULL, @@ -377,7 +377,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ); + ]; //since we are loading activities from dataset, we know total number of activities for this contact // 5 activities, Contact Summary should show all activities @@ -393,15 +393,15 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->createLoggedInUser(); global $_GET; - $_GET = array( + $_GET = [ 'cid' => 9, 'context' => 'activity', 'activity_type_id' => 1, 'is_unit_test' => 1, - ); - $expectedFilters = array( + ]; + $expectedFilters = [ 'activity_type_filter_id' => 1, - ); + ]; list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity(); //Assert whether filters are correctly set. @@ -427,7 +427,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { public function testGetActivitiesCountforContactSummaryWithNoActivities() { $this->createTestActivities(); - $params = array( + $params = [ 'contact_id' => 17, 'admin' => FALSE, 'caseId' => NULL, @@ -436,7 +436,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ); + ]; //since we are loading activities from dataset, we know total number of activities for this contact // this contact does not have any activity @@ -454,7 +454,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { //since we are loading activities from dataset, we know total number of activities // with no contact ID and there should be 8 schedule activities shown on dashboard $count = 8; - foreach (array($activitiesNew) as $activities) { + foreach ([$activitiesNew] as $activities) { $this->assertEquals($count, count($activities)); foreach ($activities as $key => $value) { @@ -469,9 +469,9 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { * Test getActivities BAO method. */ public function testGetActivitiesForAdminDashboardNoViewContacts() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; $this->setUpForActivityDashboardTests(); - foreach (array(CRM_Activity_BAO_Activity::getActivities($this->_params)) as $activities) { + foreach ([CRM_Activity_BAO_Activity::getActivities($this->_params)] as $activities) { // Skipped until we get back to the upgraded version properly. $this->assertEquals(0, count($activities)); } @@ -481,9 +481,9 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { * Test getActivities BAO method. */ public function testGetActivitiesForAdminDashboardAclLimitedViewContacts() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); - $this->allowedContacts = array(1, 3, 4, 5); - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereMultipleContacts')); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; + $this->allowedContacts = [1, 3, 4, 5]; + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereMultipleContacts']); $this->setUpForActivityDashboardTests(); $this->assertEquals(7, count(CRM_Activity_BAO_Activity::getActivities($this->_params))); } @@ -495,7 +495,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->createTestActivities(); $contactID = 9; - $params = array( + $params = [ 'contact_id' => $contactID, 'admin' => FALSE, 'caseId' => NULL, @@ -506,9 +506,9 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ); + ]; - foreach (array(CRM_Activity_BAO_Activity::getActivities($params)) as $activities) { + foreach ([CRM_Activity_BAO_Activity::getActivities($params)] as $activities) { //since we are loading activities from dataset, we know total number of activities for this contact // 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities $count = 2; @@ -535,21 +535,21 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { public function testTargetCountforContactSummary() { $targetCount = 5; $contactId = $this->individualCreate(); - $targetContactIDs = array(); + $targetContactIDs = []; for ($i = 0; $i < $targetCount; $i++) { - $targetContactIDs[] = $this->individualCreate(array(), $i); + $targetContactIDs[] = $this->individualCreate([], $i); } // Create activities with 5 target contacts. - $activityParams = array( + $activityParams = [ 'source_contact_id' => $contactId, 'target_contact_id' => $targetContactIDs, - ); + ]; $this->activityCreate($activityParams); - $params = array( + $params = [ 'contact_id' => $contactId, 'context' => 'activity', - ); + ]; $activities = CRM_Activity_BAO_Activity::getActivities($params); //verify target count $this->assertEquals($targetCount, $activities[1]['target_contact_count']); @@ -589,7 +589,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->createTestActivities(); $contactID = 9; - $params = array( + $params = [ 'contact_id' => $contactID, 'admin' => FALSE, 'caseId' => NULL, @@ -597,7 +597,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'activity_type_id' => NULL, 'offset' => 0, 'rowCount' => 0, - ); + ]; //since we are loading activities from dataset, we know total number of activities for this contact // 5 activities, Contact Summary should show all activities @@ -644,9 +644,9 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->createTestActivities(); // parameters for different test cases, check each array key for the specific test-case - $testCases = array( - 'with-no-activity' => array( - 'params' => array( + $testCases = [ + 'with-no-activity' => [ + 'params' => [ 'contact_id' => 17, 'admin' => FALSE, 'caseId' => NULL, @@ -655,10 +655,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'with-activity' => array( - 'params' => array( + ], + ], + 'with-activity' => [ + 'params' => [ 'contact_id' => 1, 'admin' => FALSE, 'caseId' => NULL, @@ -667,10 +667,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'with-activity_type' => array( - 'params' => array( + ], + ], + 'with-activity_type' => [ + 'params' => [ 'contact_id' => 3, 'admin' => FALSE, 'caseId' => NULL, @@ -679,22 +679,22 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'exclude-all-activity_type' => array( - 'params' => array( + ], + ], + 'exclude-all-activity_type' => [ + 'params' => [ 'contact_id' => 3, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'home', - 'activity_type_exclude_id' => array(1, 2), + 'activity_type_exclude_id' => [1, 2], 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'sort-by-subject' => array( - 'params' => array( + ], + ], + 'sort-by-subject' => [ + 'params' => [ 'contact_id' => 1, 'admin' => FALSE, 'caseId' => NULL, @@ -703,15 +703,15 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => 'subject DESC', - ), - ), - ); + ], + ], + ]; foreach ($testCases as $caseName => $testCase) { $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']); $activitiesNew = CRM_Activity_BAO_Activity::getActivities($testCase['params']); - foreach (array($activitiesNew) as $activities) { + foreach ([$activitiesNew] as $activities) { //$this->assertEquals($activityCount, CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params'])); if ($caseName == 'with-no-activity') { $this->assertEquals(0, count($activities)); @@ -746,11 +746,11 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->assertEquals(3, count($activities)); $this->assertEquals(3, $activityCount); // activities should be order by 'subject DESC' - $subjectOrder = array( + $subjectOrder = [ 'subject 8', 'subject 7', 'subject 1', - ); + ]; $count = 0; foreach ($activities as $activity) { $this->assertEquals($subjectOrder[$count], $activity['subject']); @@ -769,10 +769,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->createTestActivities(); // activity IDs catagorised by date - $lastWeekActivities = array(1, 2, 3); - $todayActivities = array(4, 5, 6, 7); - $lastTwoMonthsActivities = array(8, 9, 10, 11); - $lastOrNextYearActivities = array(12, 13, 14, 15, 16); + $lastWeekActivities = [1, 2, 3]; + $todayActivities = [4, 5, 6, 7]; + $lastTwoMonthsActivities = [8, 9, 10, 11]; + $lastOrNextYearActivities = [12, 13, 14, 15, 16]; // date values later used to set activity date value $lastWeekDate = date('YmdHis', strtotime('1 week ago')); @@ -794,16 +794,16 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { elseif (in_array($i, $todayActivities)) { $date = $today; } - $this->callAPISuccess('Activity', 'create', array( + $this->callAPISuccess('Activity', 'create', [ 'id' => $i, 'activity_date_time' => $date, - )); + ]); } // parameters for different test cases, check each array key for the specific test-case - $testCases = array( - 'todays-activity' => array( - 'params' => array( + $testCases = [ + 'todays-activity' => [ + 'params' => [ 'contact_id' => 1, 'admin' => TRUE, 'caseId' => NULL, @@ -813,10 +813,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'todays-activity-filtered-by-range' => array( - 'params' => array( + ], + ], + 'todays-activity-filtered-by-range' => [ + 'params' => [ 'contact_id' => 1, 'admin' => TRUE, 'caseId' => NULL, @@ -827,10 +827,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'last-week-activity' => array( - 'params' => array( + ], + ], + 'last-week-activity' => [ + 'params' => [ 'contact_id' => 1, 'admin' => TRUE, 'caseId' => NULL, @@ -840,10 +840,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'this-quarter-activity' => array( - 'params' => array( + ], + ], + 'this-quarter-activity' => [ + 'params' => [ 'contact_id' => 1, 'admin' => TRUE, 'caseId' => NULL, @@ -853,10 +853,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - 'activity-of-all-statuses' => array( - 'params' => array( + ], + ], + 'activity-of-all-statuses' => [ + 'params' => [ 'contact_id' => 1, 'admin' => TRUE, 'caseId' => NULL, @@ -866,9 +866,9 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ), - ), - ); + ], + ], + ]; foreach ($testCases as $caseName => $testCase) { CRM_Utils_Date::convertFormDateToApiFormat($testCase['params'], 'activity_date_time', FALSE); @@ -971,22 +971,22 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { // Case 1: assert the 'From' Email Address of source Actvity Contact ID // create activity with source contact ID which has email address $assigneeContactId = $this->individualCreate(); - $sourceContactParams = array( + $sourceContactParams = [ 'first_name' => 'liz', 'last_name' => 'hurleey', 'email' => substr(sha1(rand()), 0, 7) . '@testemail.com', - ); + ]; $sourceContactID = $this->individualCreate($sourceContactParams); $sourceDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactID, 'display_name'); // create an activity using API - $params = array( + $params = [ 'source_contact_id' => $sourceContactID, 'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4), 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'), - 'assignee_contact_id' => array($assigneeContactId), + 'assignee_contact_id' => [$assigneeContactId], 'activity_date_time' => date('Ymd'), - ); + ]; $activity = $this->callAPISuccess('Activity', 'create', $params); // Check that from address is in "Source-Display-Name " @@ -996,19 +996,19 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { // Case 2: System Default From Address // but first erase the email address of existing source contact ID - $withoutEmailParams = array( + $withoutEmailParams = [ 'email' => '', - ); + ]; $sourceContactID = $this->individualCreate($withoutEmailParams); - $params = array( + $params = [ 'source_contact_id' => $sourceContactID, 'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4), 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'), 'activity_date_time' => date('Ymd'), - ); + ]; $activity = $this->callAPISuccess('Activity', 'create', $params); // fetch domain info - $domainInfo = $this->callAPISuccess('Domain', 'getsingle', array('id' => CRM_Core_Config::domainID())); + $domainInfo = $this->callAPISuccess('Domain', 'getsingle', ['id' => CRM_Core_Config::domainID()]); $formAddress = CRM_Case_BAO_Case::getReceiptFrom($activity['id']); if (!empty($domainInfo['from_email'])) { @@ -1030,7 +1030,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { protected function setUpForActivityDashboardTests() { $this->createTestActivities(); - $this->_params = array( + $this->_params = [ 'contact_id' => NULL, 'admin' => TRUE, 'caseId' => NULL, @@ -1041,7 +1041,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'offset' => 0, 'rowCount' => 0, 'sort' => NULL, - ); + ]; } public function testSendEmailBasic() { @@ -1052,8 +1052,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $session = CRM_Core_Session::singleton(); $loggedInUser = $session->get('userID'); - $contact = $this->civicrm_api('contact', 'getsingle', array('id' => $contactId, 'version' => $this->_apiversion)); - $contactDetailsIntersectKeys = array( + $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion]); + $contactDetailsIntersectKeys = [ 'contact_id' => '', 'sort_name' => '', 'display_name' => '', @@ -1062,10 +1062,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'is_deceased' => '', 'email' => '', 'on_hold' => '', - ); - $contactDetails = array( + ]; + $contactDetails = [ array_intersect_key($contact, $contactDetailsIntersectKeys), - ); + ]; $subject = __FUNCTION__ . ' subject'; $html = __FUNCTION__ . ' html'; @@ -1082,7 +1082,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $from = __FUNCTION__ . '@example.com' ); - $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activity_id, 'version' => $this->_apiversion)); + $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion]); $details = "-ALTERNATIVE ITEM 0- $html -ALTERNATIVE ITEM 1- @@ -1102,8 +1102,8 @@ $text $session = CRM_Core_Session::singleton(); $loggedInUser = $session->get('userID'); - $contact = $this->civicrm_api('contact', 'getsingle', array('id' => $contactId, 'version' => $this->_apiversion)); - $contactDetailsIntersectKeys = array( + $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion]); + $contactDetailsIntersectKeys = [ 'contact_id' => '', 'sort_name' => '', 'display_name' => '', @@ -1112,16 +1112,16 @@ $text 'is_deceased' => '', 'email' => '', 'on_hold' => '', - ); - $contactDetails = array( + ]; + $contactDetails = [ array_intersect_key($contact, $contactDetailsIntersectKeys), - ); + ]; // Create a campaign. - $result = $this->civicrm_api('Campaign', 'create', array( + $result = $this->civicrm_api('Campaign', 'create', [ 'version' => $this->_apiversion, 'title' => __FUNCTION__ . ' campaign', - )); + ]); $campaign_id = $result['id']; $subject = __FUNCTION__ . ' subject'; @@ -1145,7 +1145,7 @@ $text NULL, $campaign_id ); - $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activity_id, 'version' => $this->_apiversion)); + $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion]); $this->assertEquals($activity['campaign_id'], $campaign_id, 'Activity campaign_id does not match.'); } @@ -1156,7 +1156,7 @@ $text public function testSendSMSWithoutPermission() { $dummy = NULL; $session = CRM_Core_Session::singleton(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; CRM_Activity_BAO_Activity::sendSMS( $dummy, @@ -1169,7 +1169,7 @@ $text public function testSendSmsNoPhoneNumber() { list($sent, $activityId, $success) = $this->createSendSmsTest(0); - $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion)); + $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]); $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS'); $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'); @@ -1184,7 +1184,7 @@ $text public function testSendSmsFixedPhoneNumber() { list($sent, $activityId, $success) = $this->createSendSmsTest(1); - $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion)); + $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]); $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS'); $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'); @@ -1199,7 +1199,7 @@ $text public function testSendSmsMobilePhoneNumber() { list($sent, $activityId, $success) = $this->createSendSmsTest(2); - $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion)); + $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]); $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS'); $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'); @@ -1241,7 +1241,7 @@ $text * @param array $additionalContactParams additional contact creation params */ public function createSendSmsTest($phoneType = 0, $passPhoneTypeInContactDetails = FALSE, $additionalContactParams = []) { - $provider = civicrm_api3('SmsProvider', 'create', array( + $provider = civicrm_api3('SmsProvider', 'create', [ 'name' => "CiviTestSMSProvider", 'api_type' => "1", "username" => "1", @@ -1252,7 +1252,7 @@ $text "is_default" => "1", "is_active" => "1", "domain_id" => "1", - )); + ]); $smsProviderParams['provider_id'] = $provider['id']; @@ -1280,7 +1280,7 @@ $text $this->_testSmsContactId = $this->createLoggedInUser(); // Give user permission to 'send SMS' - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'send SMS'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'send SMS']; // Create a phone number switch ($phoneType) { @@ -1290,11 +1290,11 @@ $text case 2: // Create a mobile phone number - $phone = civicrm_api3('Phone', 'create', array( + $phone = civicrm_api3('Phone', 'create', [ 'contact_id' => $contactId, 'phone' => 123456, 'phone_type_id' => "Mobile", - )); + ]); if ($passPhoneTypeInContactDetails) { $contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone']; $contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id']; @@ -1303,11 +1303,11 @@ $text case 1: // Create a fixed phone number - $phone = civicrm_api3('Phone', 'create', array( + $phone = civicrm_api3('Phone', 'create', [ 'contact_id' => $contactId, 'phone' => 654321, 'phone_type_id' => "Phone", - )); + ]); if ($passPhoneTypeInContactDetails) { $contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone']; $contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id']; @@ -1324,7 +1324,7 @@ $text $sourceContactId ); - return array($sent, $activityId, $success); + return [$sent, $activityId, $success]; } protected function createTestActivities() { diff --git a/tests/phpunit/CRM/Activity/Form/ActivityTest.php b/tests/phpunit/CRM/Activity/Form/ActivityTest.php index e0c58cc280..8242774779 100644 --- a/tests/phpunit/CRM/Activity/Form/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/Form/ActivityTest.php @@ -8,16 +8,16 @@ class CRM_Activity_Form_ActivityTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->assignee1 = $this->individualCreate(array( + $this->assignee1 = $this->individualCreate([ 'first_name' => 'testassignee1', 'last_name' => 'testassignee1', 'email' => 'testassignee1@gmail.com', - )); - $this->assignee2 = $this->individualCreate(array( + ]); + $this->assignee2 = $this->individualCreate([ 'first_name' => 'testassignee2', 'last_name' => 'testassignee2', 'email' => 'testassignee2@gmail.com', - )); + ]); $this->target = $this->individualCreate(); $this->source = $this->individualCreate(); } @@ -25,33 +25,33 @@ class CRM_Activity_Form_ActivityTest extends CiviUnitTestCase { public function testActivityCreate() { Civi::settings()->set('activity_assignee_notification', TRUE); //Reset filter to none. - Civi::settings()->set('do_not_notify_assignees_for', array()); + Civi::settings()->set('do_not_notify_assignees_for', []); $mut = new CiviMailUtils($this, TRUE); $mut->clearMessages(); $form = new CRM_Activity_Form_Activity(); $activityTypeId = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Meeting'); - $params = array( + $params = [ 'source_contact_id' => $this->source, - 'assignee_contact_id' => array($this->assignee1), - 'target_contact_id' => array($this->target), - 'followup_assignee_contact_id' => array(), + 'assignee_contact_id' => [$this->assignee1], + 'target_contact_id' => [$this->target], + 'followup_assignee_contact_id' => [], 'activity_type_id' => $activityTypeId, - ); + ]; $activityRef = new ReflectionClass('CRM_Activity_Form_Activity'); $method = $activityRef->getMethod('processActivity'); $method->setAccessible(TRUE); - $method->invokeArgs($form, array(&$params)); + $method->invokeArgs($form, [&$params]); $msg = $mut->getMostRecentEmail(); $this->assertNotEmpty($msg); $mut->clearMessages(); //Block Meeting notification. - Civi::settings()->set('do_not_notify_assignees_for', array($activityTypeId)); - $params['assignee_contact_id'] = array($this->assignee2); - $method->invokeArgs($form, array(&$params)); + Civi::settings()->set('do_not_notify_assignees_for', [$activityTypeId]); + $params['assignee_contact_id'] = [$this->assignee2]; + $method->invokeArgs($form, [&$params]); $msg = $mut->getMostRecentEmail(); $this->assertEmpty($msg); } diff --git a/tests/phpunit/CRM/Batch/BAO/BatchTest.php b/tests/phpunit/CRM/Batch/BAO/BatchTest.php index 1e7b4664e9..c6b57a81d6 100644 --- a/tests/phpunit/CRM/Batch/BAO/BatchTest.php +++ b/tests/phpunit/CRM/Batch/BAO/BatchTest.php @@ -47,7 +47,7 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { // create two contributions: one check and one credit card - $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe')); + $contactId = $this->individualCreate(['first_name' => 'John', 'last_name' => 'Doe']); $this->contributionCreate([ 'contact_id' => $contactId, 'total_amount' => 1, @@ -83,13 +83,13 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { //create an empty batch to use for the search, and run the search - $batchParams = array('title' => 'Test Batch'); + $batchParams = ['title' => 'Test Batch']; $batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open'); $batch = CRM_Batch_BAO_Batch::create($batchParams); $entityId = $batch->id; - $returnvalues = array( + $returnvalues = [ 'civicrm_financial_trxn.payment_instrument_id as payment_method', - ); + ]; $notPresent = TRUE; $params['contribution_payment_instrument_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index 1bd225198d..47b0336f19 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -76,17 +76,17 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $params = array( + $params = [ 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', 'name_a_b' => 'Test Employee of', 'name_b_a' => 'Test Employer of', - ); + ]; $this->_relationshipTypeId = $this->relationshipTypeCreate($params); $this->_orgContactID = $this->organizationCreate(); $this->_financialTypeId = 1; $this->_membershipTypeName = 'Mickey Mouse Club Member'; - $params = array( + $params = [ 'name' => $this->_membershipTypeName, 'description' => NULL, 'minimum_fee' => 1500, @@ -101,12 +101,12 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'fixed_period_start_day' => 101, 'fixed_period_rollover_day' => 1231, 'domain_id' => CRM_Core_Config::domainID(), - ); + ]; $membershipType = $this->callAPISuccess('membership_type', 'create', $params); $this->_membershipTypeID = $membershipType['id']; $this->_orgContactID2 = $this->organizationCreate(); - $params = array( + $params = [ 'name' => 'General', 'duration_unit' => 'year', 'duration_interval' => 1, @@ -117,13 +117,13 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'is_active' => 1, 'sequential' => 1, 'visibility' => 'Public', - ); + ]; $membershipType2 = $this->callAPISuccess('membership_type', 'create', $params); $this->_membershipTypeID2 = $membershipType2['id']; $this->_membershipStatusID = $this->membershipStatusCreate('test status'); $this->_contactID = $this->individualCreate(); - $contact2Params = array( + $contact2Params = [ 'first_name' => 'Anthonita', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -131,10 +131,10 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'b@c.com', 'contact_type' => 'Individual', - ); + ]; $this->_contactID2 = $this->individualCreate($contact2Params); - $this->_contactID3 = $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com')); - $this->_contactID4 = $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com')); + $this->_contactID3 = $this->individualCreate(['first_name' => 'bobby', 'email' => 'c@d.com']); + $this->_contactID4 = $this->individualCreate(['first_name' => 'bobbynita', 'email' => 'c@de.com']); $session = CRM_Core_Session::singleton(); $session->set('dateTypes', 1); @@ -149,10 +149,10 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { public function tearDown() { $this->quickCleanUpFinancialEntities(); $this->relationshipTypeDelete($this->_relationshipTypeId); - if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID))) { - $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); + if ($this->callAPISuccessGetCount('membership', ['id' => $this->_membershipTypeID])) { + $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); } - if ($this->callAPISuccessGetCount('MembershipStatus', array('id' => $this->_membershipStatusID))) { + if ($this->callAPISuccessGetCount('MembershipStatus', ['id' => $this->_membershipStatusID])) { $this->membershipStatusDelete($this->_membershipStatusID); } $this->contactDelete($this->_contactID); @@ -176,7 +176,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { $params = $this->getMembershipData(); $this->assertTrue($form->testProcessMembership($params)); - $result = $this->callAPISuccess('membership', 'get', array()); + $result = $this->callAPISuccess('membership', 'get', []); $this->assertEquals(3, $result['count']); //check start dates #1 should default to 1 Jan this year, #2 should be as entered $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']); @@ -191,14 +191,14 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']); $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']); $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']); - $result = $this->callAPISuccess('contribution', 'get', array('return' => array('total_amount', 'trxn_id'))); + $result = $this->callAPISuccess('contribution', 'get', ['return' => ['total_amount', 'trxn_id']]); $this->assertEquals(3, $result['count']); foreach ($result['values'] as $key => $contribution) { - $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array( + $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', [ 'contribution_id' => $contribution['id'], 'return' => 'line_total', - )), $contribution['total_amount']); + ]), $contribution['total_amount']); $this->assertEquals(1500, $contribution['total_amount']); $this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']); } @@ -217,14 +217,14 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { $form = new CRM_Batch_Form_Entry(); $params = $this->getContributionData(); $this->assertTrue($form->testProcessContribution($params)); - $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount')); + $result = $this->callAPISuccess('contribution', 'get', ['return' => 'total_amount']); $this->assertEquals(2, $result['count']); foreach ($result['values'] as $contribution) { - $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array( + $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', [ 'contribution_id' => $contribution['id'], 'return' => 'line_total', - )), $contribution['total_amount']); + ]), $contribution['total_amount']); } } @@ -233,34 +233,34 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { */ public function testMembershipRenewalDates() { $form = new CRM_Batch_Form_Entry(); - foreach (array($this->_contactID, $this->_contactID2) as $contactID) { - $membershipParams = array( + foreach ([$this->_contactID, $this->_contactID2] as $contactID) { + $membershipParams = [ 'membership_type_id' => $this->_membershipTypeID2, 'contact_id' => $contactID, 'start_date' => "01/01/2015", 'join_date' => "01/01/2010", 'end_date' => "12/31/2015", - ); + ]; $this->contactMembershipCreate($membershipParams); } $params = $this->getMembershipData(); //ensure membership renewal - $params['member_option'] = array( + $params['member_option'] = [ 1 => 2, 2 => 2, - ); - $params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2); + ]; + $params['field'][1]['membership_type'] = [0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2]; $params['field'][1]['receive_date'] = date('Y-m-d'); // explicitly specify start and end dates - $params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2); + $params['field'][2]['membership_type'] = [0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2]; $params['field'][2]['membership_start_date'] = "2016-04-01"; $params['field'][2]['membership_end_date'] = "2017-03-31"; $params['field'][2]['receive_date'] = "2016-04-01"; $this->assertTrue($form->testProcessMembership($params)); - $result = $this->callAPISuccess('membership', 'get', array()); + $result = $this->callAPISuccess('membership', 'get', []); // renewal dates should be from current if start_date and end_date is passed as NULL $this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']); @@ -278,17 +278,17 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { */ public function getMembershipData() { - return array( + return [ 'batch_id' => 4, - 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL), - 'primary_contact_id' => array( + 'primary_profiles' => [1 => NULL, 2 => NULL, 3 => NULL], + 'primary_contact_id' => [ 1 => $this->_contactID, 2 => $this->_contactID2, 3 => $this->_contactID3, - ), - 'field' => array( - 1 => array( - 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID), + ], + 'field' => [ + 1 => [ + 'membership_type' => [0 => $this->_orgContactID, 1 => $this->_membershipTypeID], 'join_date' => '2013-07-22', 'membership_start_date' => NULL, 'membership_end_date' => NULL, @@ -301,9 +301,9 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'trxn_id' => 'TX101', 'check_number' => NULL, 'contribution_status_id' => 1, - ), - 2 => array( - 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID), + ], + 2 => [ + 'membership_type' => [0 => $this->_orgContactID, 1 => $this->_membershipTypeID], 'join_date' => '2013-07-03', 'membership_start_date' => '2013-02-03', 'membership_end_date' => NULL, @@ -316,10 +316,10 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'trxn_id' => 'TX102', 'check_number' => NULL, 'contribution_status_id' => 1, - ), + ], // no join date, coded end date - 3 => array( - 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID), + 3 => [ + 'membership_type' => [0 => $this->_orgContactID, 1 => $this->_membershipTypeID], 'join_date' => NULL, 'membership_start_date' => NULL, 'membership_end_date' => '2013-12-01', @@ -332,12 +332,12 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'trxn_id' => 'TX103', 'check_number' => NULL, 'contribution_status_id' => 1, - ), + ], - ), + ], 'actualBatchTotal' => 0, - ); + ]; } /** @@ -346,16 +346,16 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { * @return array */ public function getContributionData($thousandSeparator = '.') { - return array( + return [ //'batch_id' => 4, - 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL), - 'primary_contact_id' => array( + 'primary_profiles' => [1 => NULL, 2 => NULL, 3 => NULL], + 'primary_contact_id' => [ 1 => $this->_contactID, 2 => $this->_contactID2, 3 => $this->_contactID3, - ), - 'field' => array( - 1 => array( + ], + 'field' => [ + 1 => [ 'financial_type' => 1, 'total_amount' => $this->formatMoneyInput(1500.15), 'receive_date' => '2013-07-24', @@ -363,8 +363,8 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'payment_instrument' => 1, 'check_number' => NULL, 'contribution_status_id' => 1, - ), - 2 => array( + ], + 2 => [ 'financial_type' => 1, 'total_amount' => $this->formatMoneyInput(1500.15), 'receive_date' => '2013-07-24', @@ -372,11 +372,11 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { 'payment_instrument' => 1, 'check_number' => NULL, 'contribution_status_id' => 1, - ), - ), + ], + ], 'actualBatchTotal' => $this->formatMoneyInput(3000.30), - ); + ]; } } diff --git a/tests/phpunit/CRM/Bridge/OG/DrupalTest.php b/tests/phpunit/CRM/Bridge/OG/DrupalTest.php index fdbda50049..02cb1722c5 100644 --- a/tests/phpunit/CRM/Bridge/OG/DrupalTest.php +++ b/tests/phpunit/CRM/Bridge/OG/DrupalTest.php @@ -46,26 +46,26 @@ class CRM_Bridge_OG_DrupalTest extends CiviUnitTestCase { * Test that one (ane only one) role (option value) is deleted by the updateCiviACLRole function */ public function testACLRoleDeleteFunctionality() { - $optionGroup = civicrm_api('OptionGroup', 'Get', array( + $optionGroup = civicrm_api('OptionGroup', 'Get', [ 'version' => 3, 'name' => 'acl_role', 'api.OptionValue.Create' => - array( - array( + [ + [ 'label' => 'OG', 'value' => 5, 'description' => 'OG Sync Group ACL :1967:', - ), - array( + ], + [ 'label' => 'OG2', 'value' => 6, 'description' => 'OG Sync Group ACL :1969:', - ), - ), - )); - $getOptionGroupParams = array('version' => 3, 'option_group_id' => $optionGroup['id']); + ], + ], + ]); + $getOptionGroupParams = ['version' => 3, 'option_group_id' => $optionGroup['id']]; $originalCount = civicrm_api('OptionValue', 'GetCount', $getOptionGroupParams); - $params = array('source' => 'OG Sync Group ACL :1969:'); + $params = ['source' => 'OG Sync Group ACL :1969:']; // this is the function we are testing CRM_Bridge_OG_Drupal::updateCiviACLRole($params, 'delete'); @@ -75,8 +75,8 @@ class CRM_Bridge_OG_DrupalTest extends CiviUnitTestCase { $this->assertEquals(1, $originalCount - $newCount); //clean up - civicrm_api('OptionValue', 'Get', array('version' => 3, 'label' => 'OG', 'api.option_value.delete')); - civicrm_api('OptionValue', 'Get', array('version' => 3, 'label' => 'OG2', 'api.option_value.delete')); + civicrm_api('OptionValue', 'Get', ['version' => 3, 'label' => 'OG', 'api.option_value.delete']); + civicrm_api('OptionValue', 'Get', ['version' => 3, 'label' => 'OG2', 'api.option_value.delete']); } } diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index c9a24392a9..0130809430 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -9,7 +9,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->tablesToTruncate = array( + $this->tablesToTruncate = [ 'civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', @@ -22,7 +22,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { 'civicrm_managed', 'civicrm_relationship', 'civicrm_relationship_type', - ); + ]; $this->quickCleanup($this->tablesToTruncate); @@ -59,10 +59,10 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { } public function testAddCaseToContact() { - $params = array( + $params = [ 'case_id' => 1, 'contact_id' => 17, - ); + ]; CRM_Case_BAO_CaseContact::create($params); $recent = CRM_Utils_Recent::get(); @@ -80,7 +80,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { // backwards compatibility - but it's more typical that the creator is a different person than the client $loggedInUser = $clientId; } - $caseParams = array( + $caseParams = [ 'activity_subject' => 'Case Subject', 'client_id' => $clientId, 'case_type_id' => 1, @@ -91,7 +91,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { 'start_date_time' => date("YmdHis"), 'medium_id' => 2, 'activity_details' => '', - ); + ]; $form = new CRM_Case_Form_Case(); $caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone"); return $caseObj; @@ -110,13 +110,13 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { 'contact_type_b' => 'Individual', ]); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ 'contact_id_a' => $contactIdA, 'contact_id_b' => $contactIdB, 'relationship_type_id' => $relationshipType, 'case_id' => $caseId, 'is_active' => $isActive, - )); + ]); } /** @@ -128,7 +128,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { */ private function assertCasesOfUser($loggedInUser, $caseId, $caseCount) { $summary = CRM_Case_BAO_Case::getCasesSummary(FALSE); - $upcomingCases = CRM_Case_BAO_Case::getCases(FALSE, array(), 'dashboard', TRUE); + $upcomingCases = CRM_Case_BAO_Case::getCases(FALSE, [], 'dashboard', TRUE); $caseRoles = CRM_Case_BAO_Case::getCaseRoles($loggedInUser, $caseId); $this->assertEquals($caseCount, $upcomingCases, 'Upcoming case count must be ' . $caseCount); @@ -167,7 +167,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { public function testRetrieveCaseIdsByContactId() { $caseIds = CRM_Case_BAO_Case::retrieveCaseIdsByContactId(3, FALSE, 'housing_support'); - $this->assertEquals(array(1), $caseIds); + $this->assertEquals([1], $caseIds); } /** diff --git a/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php b/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php index 4fce36f37a..493094e204 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php @@ -53,24 +53,24 @@ class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase { $this->assertTrue(CRM_Case_BAO_CaseType::isForkable($caseTypeId)); $this->assertFalse(CRM_Case_BAO_CaseType::isForked($caseTypeId)); - $this->callAPISuccess('CaseType', 'create', array( + $this->callAPISuccess('CaseType', 'create', [ 'id' => $caseTypeId, - 'definition' => array( - 'activityTypes' => array( - array('name' => 'First act'), - array('name' => 'Second act'), - ), - ), - )); + 'definition' => [ + 'activityTypes' => [ + ['name' => 'First act'], + ['name' => 'Second act'], + ], + ], + ]); $this->assertTrue(CRM_Case_BAO_CaseType::isForkable($caseTypeId)); $this->assertTrue(CRM_Case_BAO_CaseType::isForked($caseTypeId)); $this->assertDBNotNull('CRM_Case_BAO_CaseType', $caseTypeId, 'definition', 'id', "Should not have DB-based definition"); - $this->callAPISuccess('CaseType', 'create', array( + $this->callAPISuccess('CaseType', 'create', [ 'id' => $caseTypeId, 'definition' => 'null', - )); + ]); $this->assertDBNull('CRM_Case_BAO_CaseType', $caseTypeId, 'definition', 'id', "Should not have DB-based definition"); $this->assertTrue(CRM_Case_BAO_CaseType::isForkable($caseTypeId)); @@ -88,15 +88,15 @@ class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase { $this->assertFalse(CRM_Case_BAO_CaseType::isForkable($caseTypeId)); $this->assertFalse(CRM_Case_BAO_CaseType::isForked($caseTypeId)); - $this->callAPISuccess('CaseType', 'create', array( + $this->callAPISuccess('CaseType', 'create', [ 'id' => $caseTypeId, - 'definition' => array( - 'activityTypes' => array( - array('name' => 'First act'), - array('name' => 'Second act'), - ), - ), - )); + 'definition' => [ + 'activityTypes' => [ + ['name' => 'First act'], + ['name' => 'Second act'], + ], + ], + ]); $this->assertFalse(CRM_Case_BAO_CaseType::isForkable($caseTypeId)); $this->assertFalse(CRM_Case_BAO_CaseType::isForked($caseTypeId)); @@ -108,16 +108,16 @@ class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase { * @see \CRM_Utils_Hook::caseTypes */ public function hook_caseTypes(&$caseTypes) { - $caseTypes['ForkableCaseType'] = array( + $caseTypes['ForkableCaseType'] = [ 'module' => 'civicrm', 'name' => 'ForkableCaseType', 'file' => __DIR__ . '/ForkableCaseType.xml', - ); - $caseTypes['UnforkableCaseType'] = array( + ]; + $caseTypes['UnforkableCaseType'] = [ 'module' => 'civicrm', 'name' => 'UnforkableCaseType', 'file' => __DIR__ . '/UnforkableCaseType.xml', - ); + ]; } } diff --git a/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php b/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php index 413c4acb3c..30a4974b7b 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php @@ -13,118 +13,118 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase { * @return array */ public function definitionProvider() { - $fixtures['empty-defn'] = array( - 'json' => json_encode(array()), + $fixtures['empty-defn'] = [ + 'json' => json_encode([]), 'xml' => file_get_contents(__DIR__ . '/xml/empty-defn.xml'), - ); + ]; - $fixtures['empty-lists'] = array( - 'json' => json_encode(array( - 'activitySets' => array(), - 'activityTypes' => array(), - 'caseRoles' => array(), - 'timelineActivityTypes' => array(), - )), + $fixtures['empty-lists'] = [ + 'json' => json_encode([ + 'activitySets' => [], + 'activityTypes' => [], + 'caseRoles' => [], + 'timelineActivityTypes' => [], + ]), 'xml' => file_get_contents(__DIR__ . '/xml/empty-lists.xml'), - ); + ]; - $fixtures['one-item-in-each'] = array( - 'json' => json_encode(array( - 'activityTypes' => array( - array('name' => 'First act (foréign éxamplé, &c)'), - ), - 'activitySets' => array( - array( + $fixtures['one-item-in-each'] = [ + 'json' => json_encode([ + 'activityTypes' => [ + ['name' => 'First act (foréign éxamplé, &c)'], + ], + 'activitySets' => [ + [ 'name' => 'set1', 'label' => 'Label 1', 'timeline' => 1, - 'activityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - ), - ), - ), - 'timelineActivityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - ), - 'caseRoles' => array( - array('name' => 'First role', 'creator' => 1, 'manager' => 1), - ), - )), + 'activityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + ], + ], + ], + 'timelineActivityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + ], + 'caseRoles' => [ + ['name' => 'First role', 'creator' => 1, 'manager' => 1], + ], + ]), 'xml' => file_get_contents(__DIR__ . '/xml/one-item-in-each.xml'), - ); + ]; - $fixtures['two-items-in-each'] = array( - 'json' => json_encode(array( - 'activityTypes' => array( - array('name' => 'First act'), - array('name' => 'Second act'), - ), - 'activitySets' => array( - array( + $fixtures['two-items-in-each'] = [ + 'json' => json_encode([ + 'activityTypes' => [ + ['name' => 'First act'], + ['name' => 'Second act'], + ], + 'activitySets' => [ + [ 'name' => 'set1', 'label' => 'Label 1', 'timeline' => 1, - 'activityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - array( + 'activityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + [ 'name' => 'Meeting', 'reference_activity' => 'Open Case', 'reference_offset' => 1, 'reference_select' => 'newest', - ), - ), - ), - array( + ], + ], + ], + [ 'name' => 'set2', 'label' => 'Label 2', 'sequence' => 1, - 'activityTypes' => array( - array('name' => 'First act'), - array('name' => 'Second act'), - ), - ), - ), - 'timelineActivityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - array( + 'activityTypes' => [ + ['name' => 'First act'], + ['name' => 'Second act'], + ], + ], + ], + 'timelineActivityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + [ 'name' => 'Meeting', 'reference_activity' => 'Open Case', 'reference_offset' => 1, 'reference_select' => 'newest', - ), - ), - 'caseRoles' => array( - array('name' => 'First role', 'creator' => 1, 'manager' => 1), - array('name' => 'Second role'), - ), - )), + ], + ], + 'caseRoles' => [ + ['name' => 'First role', 'creator' => 1, 'manager' => 1], + ['name' => 'Second role'], + ], + ]), 'xml' => file_get_contents(__DIR__ . '/xml/two-items-in-each.xml'), - ); + ]; - $fixtures['forkable-0'] = array( - 'json' => json_encode(array( + $fixtures['forkable-0'] = [ + 'json' => json_encode([ 'forkable' => 0, - )), + ]), 'xml' => file_get_contents(__DIR__ . '/xml/forkable-0.xml'), - ); + ]; - $fixtures['forkable-1'] = array( - 'json' => json_encode(array( + $fixtures['forkable-1'] = [ + 'json' => json_encode([ 'forkable' => 1, - )), + ]), 'xml' => file_get_contents(__DIR__ . '/xml/forkable-1.xml'), - ); + ]; - $cases = array(); - foreach (array( + $cases = []; + foreach ([ 'empty-defn', 'empty-lists', 'one-item-in-each', 'two-items-in-each', 'forkable-0', 'forkable-1', - ) as $key) { - $cases[] = array($key, $fixtures[$key]['json'], $fixtures[$key]['xml']); + ] as $key) { + $cases[] = [$key, $fixtures[$key]['json'], $fixtures[$key]['xml']]; } return $cases; } diff --git a/tests/phpunit/CRM/Case/BAO/QueryTest.php b/tests/phpunit/CRM/Case/BAO/QueryTest.php index 713cf7c92a..1a4cc92cd6 100644 --- a/tests/phpunit/CRM/Case/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Case/BAO/QueryTest.php @@ -33,37 +33,37 @@ class CRM_Case_BAO_QueryTest extends CiviUnitTestCase { * - case_activity_medium_id */ public function testWhereClauseSingle() { - $params = array( - 0 => array( + $params = [ + 0 => [ 0 => 'case_recent_activity_type', 1 => '=', 2 => 6, 3 => 1, 4 => 0, - ), - 1 => array( + ], + 1 => [ 0 => 'case_activity_status_id', 1 => '=', 2 => 1, 3 => 1, 4 => 0, - ), - 2 => array( + ], + 2 => [ 0 => 'case_activity_medium_id', 1 => '=', 2 => 1, 3 => 1, 4 => 0, - ), - ); + ], + ]; $queryObj = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CASE); $this->assertEquals( - array( + [ 0 => 'Activity Type = Contribution', 1 => 'Activity Type = Scheduled', 2 => 'Activity Medium = In Person', - ), + ], $queryObj->_qill[1] ); } diff --git a/tests/phpunit/CRM/Case/PseudoConstantTest.php b/tests/phpunit/CRM/Case/PseudoConstantTest.php index 2913abe08e..8a2997cb83 100644 --- a/tests/phpunit/CRM/Case/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Case/PseudoConstantTest.php @@ -10,10 +10,10 @@ class CRM_Case_PseudoConstantTest extends CiviCaseTestCase { public function testCaseType() { CRM_Core_PseudoConstant::flush(); $caseTypes = CRM_Case_PseudoConstant::caseType(); - $expectedTypes = array( + $expectedTypes = [ 1 => 'Housing Support', 2 => 'Adult Day Care Referral', - ); + ]; $this->assertEquals($expectedTypes, $caseTypes); } diff --git a/tests/phpunit/CRM/Case/XMLRepositoryTest.php b/tests/phpunit/CRM/Case/XMLRepositoryTest.php index 2f2de17ef8..fe6e4c5e3a 100644 --- a/tests/phpunit/CRM/Case/XMLRepositoryTest.php +++ b/tests/phpunit/CRM/Case/XMLRepositoryTest.php @@ -5,7 +5,7 @@ * @group headless */ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { - protected $fixtures = array(); + protected $fixtures = []; protected function setUp() { parent::setUp(); @@ -98,45 +98,45 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { public function testGetAllDeclaredActivityTypes() { $repo = new CRM_Case_XMLRepository( - array('CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'), - array( + ['CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'], + [ 'CaseTypeWithTwoActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoActivityTypes']), 'CaseTypeWithThreeActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeActivityTypes']), /* healthful noise: */ 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), - ) + ] ); // omitted: 'Single Activity Type' - $expected = array('First Activity Type', 'Second Activity Type', 'Third Activity Type'); + $expected = ['First Activity Type', 'Second Activity Type', 'Third Activity Type']; $actual = $repo->getAllDeclaredActivityTypes(); $this->assertEquals($expected, $actual); } public function testGetAllDeclaredRelationshipTypes() { $repo = new CRM_Case_XMLRepository( - array('CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'), - array( + ['CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'], + [ 'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']), 'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']), /* healthful noise: */ 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), - ) + ] ); // omitted: 'Single Role' - $expected = array('First Role', 'Second Role', 'Third Role'); + $expected = ['First Role', 'Second Role', 'Third Role']; $actual = $repo->getAllDeclaredRelationshipTypes(); $this->assertEquals($expected, $actual); } public function testGetActivityReferenceCount_1() { $repo = new CRM_Case_XMLRepository( - array('CaseTypeWithSingleActivityType'), - array( + ['CaseTypeWithSingleActivityType'], + [ 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), /* healthful noise: */ 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), - ) + ] ); $this->assertEquals(1, $repo->getActivityReferenceCount('Single Activity Type')); @@ -147,13 +147,13 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { public function testGetActivityReferenceCount_23() { $repo = new CRM_Case_XMLRepository( - array('CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'), - array( + ['CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'], + [ 'CaseTypeWithTwoActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoActivityTypes']), 'CaseTypeWithThreeActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeActivityTypes']), /* noise: */ 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), - ) + ] ); $this->assertEquals(0, $repo->getActivityReferenceCount('Single Activity Type')); @@ -164,12 +164,12 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { public function testGetRoleReferenceCount_1() { $repo = new CRM_Case_XMLRepository( - array('CaseTypeWithSingleRole', 'CaseTypeWithSingleActivityType'), - array( + ['CaseTypeWithSingleRole', 'CaseTypeWithSingleActivityType'], + [ 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), /* healthful noise: */ 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), - ) + ] ); $this->assertEquals(1, $repo->getRelationshipReferenceCount('Single Role')); @@ -180,13 +180,13 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { public function testGetRoleReferenceCount_23() { $repo = new CRM_Case_XMLRepository( - array('CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'), - array( + ['CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'], + [ 'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']), 'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']), /* healthful noise: */ 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), - ) + ] ); $this->assertEquals(0, $repo->getRelationshipReferenceCount('Single Role')); diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index 2556b203e2..8dd1f6e96b 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -19,7 +19,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { * test with empty params. */ public function testAddWithEmptyParams() { - $params = array(); + $params = []; $contact = CRM_Contact_BAO_Contact::add($params); // Now check Contact object. @@ -34,11 +34,11 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { public function testAddWithNames() { $firstName = 'Shane'; $lastName = 'Whatson'; - $params = array( + $params = [ 'first_name' => $firstName, 'last_name' => $lastName, 'contact_type' => 'Individual', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); @@ -51,11 +51,11 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { // Update and change first name and last name, using add( ). $firstName = 'Jane'; - $params = array( + $params = [ 'first_name' => $firstName, 'contact_type' => 'Individual', 'contact_id' => $contactId, - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); @@ -113,7 +113,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contact->preferred_communication_method ); - $checkPrefComm = array(); + $checkPrefComm = []; foreach ($dbPrefComm as $key => $value) { if ($value) { $checkPrefComm[$value] = 1; @@ -121,7 +121,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { } $this->assertAttributesEquals($checkPrefComm, $prefComm); - $updateParams = array( + $updateParams = [ 'contact_type' => 'Individual', 'first_name' => 'Jane', 'middle_name' => 'abc', @@ -132,32 +132,32 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'job_title' => 'software Developer', 'gender_id' => 1, 'is_deceased' => 1, - 'website' => array( - 1 => array( + 'website' => [ + 1 => [ 'website_type_id' => 1, 'url' => 'http://docs.civicrm.org', - ), - ), + ], + ], 'contact_source' => 'test update contact', 'external_identifier' => 111111111, 'preferred_mail_format' => 'Both', 'is_opt_out' => 0, 'deceased_date' => '1981-03-03', 'birth_date' => '1951-04-04', - 'privacy' => array( + 'privacy' => [ 'do_not_phone' => 0, 'do_not_email' => 0, 'do_not_mail' => 0, 'do_not_trade' => 0, - ), - 'preferred_communication_method' => array( + ], + 'preferred_communication_method' => [ '1' => 0, '2' => 1, '3' => 0, '4' => 1, '5' => 0, - ), - ); + ], + ]; $prefComm = $updateParams['preferred_communication_method']; $updateParams['contact_id'] = $contactId; @@ -199,7 +199,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contact->preferred_communication_method ); - $checkPrefComm = array(); + $checkPrefComm = []; foreach ($dbPrefComm as $key => $value) { if ($value) { $checkPrefComm[$value] = 1; @@ -216,11 +216,11 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { public function testAddWithAllContactTypes() { $firstName = 'Bill'; $lastName = 'Adams'; - $params = array( + $params = [ 'first_name' => $firstName, 'last_name' => $lastName, 'contact_type' => 'Individual', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($firstName, $contact->first_name, 'Check for first name creation.'); @@ -230,11 +230,11 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //update and change first name and last name, using create() $firstName = 'Joan'; - $params = array( + $params = [ 'first_name' => $firstName, 'contact_type' => 'Individual', 'contact_id' => $contactId, - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($firstName, $contact->first_name, 'Check for updated first name.'); @@ -242,41 +242,41 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->contactDelete($contactId); $householdName = 'Adams house'; - $params = array( + $params = [ 'household_name' => $householdName, 'contact_type' => 'Household', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($householdName, $contact->sort_name, 'Check for created household.'); $contactId = $contact->id; //update and change name of household, using create $householdName = 'Joans home'; - $params = array( + $params = [ 'household_name' => $householdName, 'contact_type' => 'Household', 'contact_id' => $contactId, - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($householdName, $contact->sort_name, 'Check for updated household.'); $this->contactDelete($contactId); $organizationName = 'My Organization'; - $params = array( + $params = [ 'organization_name' => $organizationName, 'contact_type' => 'Organization', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($organizationName, $contact->sort_name, 'Check for created organization.'); $contactId = $contact->id; //update and change name of organization, using create $organizationName = 'Your Changed Organization'; - $params = array( + $params = [ 'organization_name' => $organizationName, 'contact_type' => 'Organization', 'contact_id' => $contactId, - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($organizationName, $contact->sort_name, 'Check for updated organization.'); $this->contactDelete($contactId); @@ -288,10 +288,10 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { * Test with missing params. */ public function testCreateWithEmptyParams() { - $params = array( + $params = [ 'first_name' => 'Bill', 'last_name' => 'Adams', - ); + ]; $contact = CRM_Contact_BAO_Contact::create($params); //Now check Contact object @@ -322,12 +322,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($params['contact_type'], $contact->contact_type, 'Check for contact type creation.'); //Now check DB for Address - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => CRM_Utils_Array::value('street_address', $params['address'][1]), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', $params['address'][1] @@ -346,59 +346,59 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { ), 'geo_code_1' => CRM_Utils_Array::value('geo_code_1', $params['address'][1]), 'geo_code_2' => CRM_Utils_Array::value('geo_code_2', $params['address'][1]), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //Now check DB for Email - $compareParams = array('email' => CRM_Utils_Array::value('email', $params['email'][1])); + $compareParams = ['email' => CRM_Utils_Array::value('email', $params['email'][1])]; $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); //Now check DB for openid - $compareParams = array('openid' => CRM_Utils_Array::value('openid', $params['openid'][1])); + $compareParams = ['openid' => CRM_Utils_Array::value('openid', $params['openid'][1])]; $this->assertDBCompareValues('CRM_Core_DAO_OpenID', $searchParams, $compareParams); //Now check DB for IM - $compareParams = array( + $compareParams = [ 'name' => CRM_Utils_Array::value('name', $params['im'][1]), 'provider_id' => CRM_Utils_Array::value('provider_id', $params['im'][1]), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); //Now check DB for Phone - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, 'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][1]), - ); - $compareParams = array('phone' => CRM_Utils_Array::value('phone', $params['phone'][1])); + ]; + $compareParams = ['phone' => CRM_Utils_Array::value('phone', $params['phone'][1])]; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for Mobile - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2]), - ); - $compareParams = array('phone' => CRM_Utils_Array::value('phone', $params['phone'][2])); + ]; + $compareParams = ['phone' => CRM_Utils_Array::value('phone', $params['phone'][2])]; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for Note - $searchParams = array( + $searchParams = [ 'entity_id' => $contactId, 'entity_table' => 'civicrm_contact', - ); - $compareParams = array('note' => $params['note']); + ]; + $compareParams = ['note' => $params['note']]; $this->assertDBCompareValues('CRM_Core_DAO_Note', $searchParams, $compareParams); //update the contact. - $updateParams = array( + $updateParams = [ 'first_name' => 'John', 'last_name' => 'Doe', 'contact_type' => 'Individual', 'note' => 'new test note', - ); - $updateParams['address'][1] = array( + ]; + $updateParams['address'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'street_address' => 'Oberoi Garden', @@ -411,24 +411,24 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'state_province_id' => 1004, 'geo_code_1' => '31.694842', 'geo_code_2' => '-106.29998', - ); - $updateParams['email'][1] = array( + ]; + $updateParams['email'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'email' => 'john.doe@example.org', - ); + ]; - $updateParams['phone'][1] = array( + $updateParams['phone'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'phone_type_id' => 1, 'phone' => '02115245336', - ); - $updateParams['phone'][2] = array( + ]; + $updateParams['phone'][2] = [ 'location_type_id' => 1, 'phone_type_id' => 2, 'phone' => '9766323895', - ); + ]; $updateParams['contact_id'] = $contactId; //create the contact with given params. @@ -444,12 +444,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($updateParams['contact_type'], $contact->contact_type, 'Check for contact type creation.'); //Now check DB for updated Address - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => 'Oberoi Garden', 'supplemental_address_1' => 'A-wing:3037', 'supplemental_address_2' => 'Andhery', @@ -460,30 +460,30 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'state_province_id' => 1004, 'geo_code_1' => '31.694842', 'geo_code_2' => '-106.29998', - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //Now check DB for updated Email - $compareParams = array('email' => 'john.doe@example.org'); + $compareParams = ['email' => 'john.doe@example.org']; $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); //Now check DB for updated Phone - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, 'phone_type_id' => 1, - ); - $compareParams = array('phone' => '02115245336'); + ]; + $compareParams = ['phone' => '02115245336']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for updated Mobile - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => 2, - ); - $compareParams = array('phone' => '9766323895'); + ]; + $compareParams = ['phone' => '9766323895']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); // As we are not updating note. // Now check DB for New Note. @@ -496,7 +496,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { // Cleanup DB by deleting the contact. $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact', 'civicrm_note')); + $this->quickCleanup(['civicrm_contact', 'civicrm_note']); } /** @@ -505,19 +505,19 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { * Test all pseudoConstant, stateProvince, country. */ public function testResolveDefaults() { - $params = array( + $params = [ 'prefix_id' => 3, 'suffix_id' => 2, 'gender_id' => 2, 'birth_date' => '1983-12-13', - ); + ]; - $params['address'][1] = array( + $params['address'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'country_id' => 1228, 'state_province_id' => 1004, - ); + ]; // @todo - we are testing this with $reverse = FALSE but it is never called that way! CRM_Contact_BAO_Contact::resolveDefaults($params); @@ -551,10 +551,10 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); $contactId = $contact->id; //create the organization contact with the given params. - $orgParams = array( + $orgParams = [ 'organization_name' => 'Test Organization ' . substr(sha1(rand()), 0, 4), 'contact_type' => 'Organization', - ); + ]; $orgContact = CRM_Contact_BAO_Contact::add($orgParams); $this->assertInstanceOf('CRM_Contact_DAO_Contact', $orgContact, 'Check for created object'); @@ -562,8 +562,8 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contactId, $orgContact->id); //retrieve the contact values from database. - $values = array(); - $searchParams = array('contact_id' => $contactId); + $values = []; + $searchParams = ['contact_id' => $contactId]; $retrieveContact = CRM_Contact_BAO_Contact::retrieve($searchParams, $values); //Now check $retrieveContact is object of contact DAO.. @@ -632,7 +632,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //cleanup DB by deleting the contact $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact')); + $this->quickCleanup(['civicrm_contact']); } /** @@ -642,16 +642,16 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $contactParams = $this->contactParams(); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', 'custom_group_id' => $customGroup['id'], - ); + ]; $customField = CRM_Core_BAO_CustomField::create($fields); - $contactParams['custom'] = array( - $customField->id => array( - -1 => array( + $contactParams['custom'] = [ + $customField->id => [ + -1 => [ 'value' => 'Test custom value', 'type' => 'String', 'custom_field_id' => $customField->id, @@ -659,9 +659,9 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField->column_name, 'file_id' => NULL, - ), - ), - ); + ], + ], + ]; //create contact $contact = CRM_Contact_BAO_Contact::create($contactParams); @@ -699,10 +699,10 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { ); // Check that the custom field value is no longer present - $params = array( + $params = [ 'entityID' => $contactId, 'custom_' . $customField->id => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals(CRM_Utils_Array::value("custom_" . $customField->id, $values), '', 'Verify that the data value is empty for contact ' . $contactId @@ -713,7 +713,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertDBNull('CRM_Contact_DAO_Contact', $contactId, 'id', 'sort_name', 'Database check, contact deleted successfully.' ); - $this->quickCleanup(array('civicrm_contact', 'civicrm_note')); + $this->quickCleanup(['civicrm_contact', 'civicrm_note']); $this->customGroupDelete($customGroup['id']); } @@ -724,19 +724,19 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $fields = CRM_Contact_BAO_Contact::exportableFields('Individual'); //current employer field for individual - $fields['organization_name'] = array( + $fields['organization_name'] = [ 'name' => 'organization_name', 'where' => 'civicrm_organization.organization_name', 'title' => 'Current Employer', - ); + ]; //get the common params $contactParams = $this->contactParams(); - $unsetParams = array('location', 'privacy'); + $unsetParams = ['location', 'privacy']; foreach ($unsetParams as $param) { unset($contactParams[$param]); } - $profileParams = array( + $profileParams = [ 'organization_name' => 'Yahoo', 'gender_id' => '2', 'prefix_id' => '3', @@ -768,12 +768,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'user_unique_id' => '123456789', 'is_bulkmail' => '1', 'world_region' => 'India', - 'tag' => array( + 'tag' => [ '3' => '1', '4' => '1', '1' => '1', - ), - ); + ], + ]; $createParams = array_merge($contactParams, $profileParams); //create the contact using create profile contact. @@ -823,7 +823,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'preferred_communication_method', 'id', TRUE) ); - $checkPrefComm = array(); + $checkPrefComm = []; foreach ($dbPrefComm as $key => $value) { if ($value) { $checkPrefComm[$value] = 1; @@ -832,12 +832,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertAttributesEquals($checkPrefComm, $params['preferred_communication_method']); //Now check DB for Address - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => CRM_Utils_Array::value('street_address-Primary', $profileParams), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1-Primary', $profileParams), 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2-Primary', $profileParams), @@ -848,42 +848,42 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'state_province_id' => CRM_Utils_Array::value('state_province-Primary', $profileParams), 'geo_code_1' => CRM_Utils_Array::value('geo_code_1-Primary', $profileParams), 'geo_code_2' => CRM_Utils_Array::value('geo_code_2-Primary', $profileParams), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //Now check DB for Email - $compareParams = array('email' => CRM_Utils_Array::value('email-Primary', $profileParams)); + $compareParams = ['email' => CRM_Utils_Array::value('email-Primary', $profileParams)]; $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); //Now check DB for IM - $compareParams = array( + $compareParams = [ 'name' => CRM_Utils_Array::value('im-Primary', $profileParams), 'provider_id' => CRM_Utils_Array::value('im-Primary-provider_id', $profileParams), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); //Now check DB for Phone - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-1', $profileParams)); + ]; + $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-1', $profileParams)]; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for Mobile - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2]), - ); - $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-2', $profileParams)); + ]; + $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-2', $profileParams)]; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //get the value of relationship - $values = array(); - $searchParams = array('contact_id' => $contactId); + $values = []; + $searchParams = ['contact_id' => $contactId]; $relationship = CRM_Contact_BAO_Relationship::getValues($searchParams, $values); //Now check values of Relationship Count. $this->assertEquals(0, $values['relationship']['totalCount'], 'Check for total relationship count'); @@ -905,7 +905,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertAttributesEquals($profileParams['tag'], $tagIds); //update Contact mode - $updateCParams = array( + $updateCParams = [ 'first_name' => 'john', 'last_name' => 'doe', 'contact_type' => 'Individual', @@ -916,12 +916,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'job_title' => 'software Developer', 'gender_id' => 1, 'is_deceased' => 1, - 'website' => array( - 1 => array( + 'website' => [ + 1 => [ 'website_type_id' => 1, 'url' => 'http://civicrmUpdate.org', - ), - ), + ], + ], 'contact_source' => 'test contact', 'external_identifier' => 111222333, 'preferred_mail_format' => 'Both', @@ -930,20 +930,20 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'image_URL' => 'http://imageupdate.com', 'deceased_date' => '1981-10-10', 'birth_date' => '1951-11-11', - 'privacy' => array( + 'privacy' => [ 'do_not_phone' => 1, 'do_not_email' => 1, - ), - 'preferred_communication_method' => array( + ], + 'preferred_communication_method' => [ '1' => 0, '2' => 1, '3' => 0, '4' => 1, '5' => 0, - ), - ); + ], + ]; - $updatePfParams = array( + $updatePfParams = [ 'organization_name' => 'Google', 'city-Primary' => 'Mumbai', 'contact_type' => 'Individual', @@ -972,11 +972,11 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'user_unique_id' => '1122334455', 'is_bulkmail' => '1', 'world_region' => 'India', - 'tag' => array( + 'tag' => [ '2' => '1', '5' => '1', - ), - ); + ], + ]; $createParams = array_merge($updateCParams, $updatePfParams); @@ -1029,7 +1029,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'preferred_communication_method', 'id', TRUE) ); - $checkPrefComm = array(); + $checkPrefComm = []; foreach ($dbPrefComm as $key => $value) { if ($value) { $checkPrefComm[$value] = 1; @@ -1038,12 +1038,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertAttributesEquals($checkPrefComm, $updateCParams['preferred_communication_method']); //Now check DB for Address - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => CRM_Utils_Array::value('street_address-Primary', $updatePfParams), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1-Primary', $updatePfParams), 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2-Primary', $updatePfParams), @@ -1054,41 +1054,41 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'state_province_id' => CRM_Utils_Array::value('state_province-Primary', $updatePfParams), 'geo_code_1' => CRM_Utils_Array::value('geo_code_1-Primary', $updatePfParams), 'geo_code_2' => CRM_Utils_Array::value('geo_code_2-Primary', $updatePfParams), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //Now check DB for Email - $compareParams = array('email' => CRM_Utils_Array::value('email-Primary', $updatePfParams)); + $compareParams = ['email' => CRM_Utils_Array::value('email-Primary', $updatePfParams)]; $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); //Now check DB for IM - $compareParams = array( + $compareParams = [ 'name' => CRM_Utils_Array::value('im-Primary', $updatePfParams), 'provider_id' => CRM_Utils_Array::value('im-Primary-provider_id', $updatePfParams), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); //Now check DB for Phone - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-1', $updatePfParams)); + ]; + $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-1', $updatePfParams)]; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for Mobile - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2]), - ); - $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-2', $updatePfParams)); + ]; + $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-2', $updatePfParams)]; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //get the value of relationship - $values = array(); - $searchParams = array('contact_id' => $contactId); + $values = []; + $searchParams = ['contact_id' => $contactId]; $relationship = CRM_Contact_BAO_Relationship::getValues($searchParams, $values); //Now check values of Relationship Count. $this->assertEquals(0, $values['relationship']['totalCount'], 'Check for total relationship count'); @@ -1125,17 +1125,17 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //get the contact details $contactDetails = CRM_Contact_BAO_Contact::getContactDetails($contactId); - $compareParams = array( + $compareParams = [ $params['first_name'] . ' ' . $params['last_name'], CRM_Utils_Array::value('email', $params['email'][1]), (bool ) $params['privacy']['do_not_email'], - ); + ]; //Now check the contact details $this->assertAttributesEquals($compareParams, $contactDetails); //cleanup DB by deleting the contact $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact')); + $this->quickCleanup(['civicrm_contact']); } /** @@ -1183,7 +1183,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //cleanup DB by deleting the contact $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact')); + $this->quickCleanup(['civicrm_contact']); } /** @@ -1228,7 +1228,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //cleanup DB by deleting the contact $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact')); + $this->quickCleanup(['civicrm_contact']); } /** @@ -1247,7 +1247,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //cleanup DB by deleting the contact $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact')); + $this->quickCleanup(['civicrm_contact']); } /** @@ -1274,7 +1274,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //cleanup DB by deleting the contact $this->contactDelete($contactId); - $this->quickCleanup(array('civicrm_contact')); + $this->quickCleanup(['civicrm_contact']); } /** @@ -1311,7 +1311,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { */ private function contactParams() { - $params = array( + $params = [ 'first_name' => 'john', 'last_name' => 'smith', 'contact_type' => 'Individual', @@ -1322,12 +1322,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'job_title' => 'software engg', 'gender_id' => 2, 'is_deceased' => 1, - 'website' => array( - 1 => array( + 'website' => [ + 1 => [ 'website_type_id' => 1, 'url' => 'http://civicrm.org', - ), - ), + ], + ], 'contact_source' => 'test contact', 'external_identifier' => 123456789, 'preferred_mail_format' => 'Both', @@ -1336,23 +1336,23 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'image_URL' => 'http://image.com', 'deceased_date' => '1991-07-07', 'birth_date' => '1961-06-06', - 'privacy' => array( + 'privacy' => [ 'do_not_phone' => 1, 'do_not_email' => 1, 'do_not_mail' => 1, 'do_not_trade' => 1, - ), - 'preferred_communication_method' => array( + ], + 'preferred_communication_method' => [ '1' => 1, '2' => 0, '3' => 1, '4' => 0, '5' => 1, - ), - ); + ], + ]; - $params['address'] = array(); - $params['address'][1] = array( + $params['address'] = []; + $params['address'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'street_address' => 'Saint Helier St', @@ -1365,42 +1365,42 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', - ); + ]; - $params['email'] = array(); - $params['email'][1] = array( + $params['email'] = []; + $params['email'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'email' => 'john.smith@example.org', - ); + ]; - $params['phone'] = array(); - $params['phone'][1] = array( + $params['phone'] = []; + $params['phone'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'phone_type_id' => 1, 'phone' => '303443689', - ); - $params['phone'][2] = array( + ]; + $params['phone'][2] = [ 'location_type_id' => 1, 'phone_type_id' => 2, 'phone' => '9833910234', - ); + ]; - $params['openid'] = array(); - $params['openid'][1] = array( + $params['openid'] = []; + $params['openid'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'openid' => 'http://civicrm.org/', - ); + ]; - $params['im'] = array(); - $params['im'][1] = array( + $params['im'] = []; + $params['im'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, 'name' => 'john.smith', 'provider_id' => 1, - ); + ]; return $params; } @@ -1410,17 +1410,17 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { */ public function testTimestampContact() { $test = $this; - $this->_testTimestamps(array( + $this->_testTimestamps([ 'UPDATE' => function ($contactId) use ($test) { - $params = array( + $params = [ 'first_name' => 'Testing', 'contact_type' => 'Individual', 'contact_id' => $contactId, - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $test->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); }, - )); + ]); } /** @@ -1428,33 +1428,33 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { */ public function testTimestampsEmail() { $test = $this; - $this->_testTimestamps(array( + $this->_testTimestamps([ 'INSERT' => function ($contactId) use ($test) { - $params = array( + $params = [ 'email' => 'ex-1@example.com', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Email::add($params); $test->assertDBQuery('ex-1@example.com', 'SELECT email FROM civicrm_email WHERE contact_id = %1 ORDER BY id DESC LIMIT 1', - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, 'UPDATE' => function ($contactId) use ($test) { CRM_Core_DAO::executeQuery( 'UPDATE civicrm_email SET email = "ex-2@example.com" WHERE contact_id = %1', - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, 'DELETE' => function ($contactId) use ($test) { CRM_Core_DAO::executeQuery( 'DELETE FROM civicrm_email WHERE contact_id = %1', - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, - )); + ]); } /** @@ -1462,33 +1462,33 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { */ public function testTimestampsPhone() { $test = $this; - $this->_testTimestamps(array( + $this->_testTimestamps([ 'INSERT' => function ($contactId) use ($test) { - $params = array( + $params = [ 'phone' => '202-555-1000', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Phone::add($params); $test->assertDBQuery('202-555-1000', 'SELECT phone FROM civicrm_phone WHERE contact_id = %1 ORDER BY id DESC LIMIT 1', - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, 'UPDATE' => function ($contactId) use ($test) { CRM_Core_DAO::executeQuery( 'UPDATE civicrm_phone SET phone = "202-555-2000" WHERE contact_id = %1', - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, 'DELETE' => function ($contactId) use ($test) { CRM_Core_DAO::executeQuery( 'DELETE FROM civicrm_phone WHERE contact_id = %1', - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, - )); + ]); } /** @@ -1499,35 +1499,35 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { public function testTimestampsCustom() { $customGroup = $this->customGroupCreate(); $customGroup = $customGroup['values'][$customGroup['id']]; - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'String', 'html_type' => 'Text', - ); + ]; $customField = $this->customFieldCreate($fields); $customField = $customField['values'][$customField['id']]; $test = $this; - $this->_testTimestamps(array( + $this->_testTimestamps([ 'INSERT' => function ($contactId) use ($test, $customGroup, $customField) { - civicrm_api3('contact', 'create', array( + civicrm_api3('contact', 'create', [ 'contact_id' => $contactId, 'custom_' . $customField['id'] => 'test-1', - )); + ]); }, 'UPDATE' => function ($contactId) use ($test, $customGroup, $customField) { CRM_Core_DAO::executeQuery( "UPDATE {$customGroup['table_name']} SET {$customField['column_name']} = 'test-2' WHERE entity_id = %1", - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, 'DELETE' => function ($contactId) use ($test, $customGroup, $customField) { CRM_Core_DAO::executeQuery( "DELETE FROM {$customGroup['table_name']} WHERE entity_id = %1", - array(1 => array($contactId, 'Integer')) + [1 => [$contactId, 'Integer']] ); }, - )); - $this->quickCleanup(array('civicrm_contact'), TRUE); + ]); + $this->quickCleanup(['civicrm_contact'], TRUE); } /** @@ -1572,18 +1572,18 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { public function testUpdateProfileLocationLeak() { // create a simple contact with address and phone that share the same location type $defaults = $this->contactParams(); - $params = array( + $params = [ 'first_name' => $defaults['first_name'], 'last_name' => $defaults['last_name'], 'contact_type' => 'Individual', - 'address' => array(1 => $defaults['address'][1]), - 'phone' => array(1 => $defaults['phone'][1]), - ); + 'address' => [1 => $defaults['address'][1]], + 'phone' => [1 => $defaults['phone'][1]], + ]; $contact = CRM_Contact_BAO_Contact::create($params); $contactId = $contact->id; // now, update using a profile with phone, email, address... that share the same location type - $updatePfParams = array( + $updatePfParams = [ 'first_name' => $params['first_name'], 'last_name' => $params['first_name'], 'street_address-Primary' => $params['address'][1]['street_address'], @@ -1591,7 +1591,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'country-Primary' => $params['address'][1]['country_id'], 'phone-Primary-1' => $params['phone'][1]['phone'], 'phone_ext-Primary-1' => '345', - ); + ]; //create the contact using create profile contact. $fields = CRM_Contact_BAO_Contact::exportableFields('Individual'); @@ -1609,14 +1609,14 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($params['phone'][1]['phone'], $phone['phone']); //check the values in DB. - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => CRM_Utils_Array::value('street_address-Primary', $updatePfParams), - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //cleanup DB by deleting the contact diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php index b8af15bcba..ef36a5b36b 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php @@ -40,31 +40,31 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { list($group, $living, $deceased) = $this->setupSmartGroup(); // Add $n1 to $g - $this->callAPISuccess('group_contact', 'create', array( + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $living[0]->id, 'group_id' => $group->id, - )); + ]); CRM_Contact_BAO_GroupContactCache::load($group, TRUE); $this->assertCacheMatches( - array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id, $living[0]->id), + [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id, $living[0]->id], $group->id ); // Remove $y1 from $g - $this->callAPISuccess('group_contact', 'create', array( + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $deceased[0]->id, 'group_id' => $group->id, 'status' => 'Removed', - )); + ]); CRM_Contact_BAO_GroupContactCache::load($group, TRUE); $this->assertCacheMatches( - array( + [ $deceased[1]->id, $deceased[2]->id, $living[0]->id, - ), + ], $group->id ); } @@ -74,67 +74,67 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testRemoveFromParentSmartGroup() { // Create smart group $parent - $params = array( + $params = [ 'name' => 'Deceased Contacts', 'title' => 'Deceased Contacts', 'is_active' => 1, - 'formValues' => array('is_deceased' => 1), - ); + 'formValues' => ['is_deceased' => 1], + ]; $parent = CRM_Contact_BAO_Group::createSmartGroup($params); - $this->registerTestObjects(array($parent)); + $this->registerTestObjects([$parent]); // Create group $child in $parent - $params = array( + $params = [ 'name' => 'Child Group', 'title' => 'Child Group', 'is_active' => 1, - 'parents' => array($parent->id => 1), - ); + 'parents' => [$parent->id => 1], + ]; $child = CRM_Contact_BAO_Group::create($params); - $this->registerTestObjects(array($child)); + $this->registerTestObjects([$child]); // Create $c1, $c2, $c3 - $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3); + $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3); // Add $c1, $c2, $c3 to $child foreach ($deceased as $contact) { - $this->callAPISuccess('group_contact', 'create', array( + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $contact->id, 'group_id' => $child->id, - )); + ]); } CRM_Contact_BAO_GroupContactCache::load($parent, TRUE); $this->assertCacheMatches( - array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), + [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id], $parent->id ); // Remove $c1 from $parent - $this->callAPISuccess('group_contact', 'create', array( + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $deceased[0]->id, 'group_id' => $parent->id, 'status' => 'Removed', - )); + ]); // Assert $c1 not in $parent CRM_Contact_BAO_GroupContactCache::load($parent, TRUE); $this->assertCacheMatches( - array( + [ $deceased[1]->id, $deceased[2]->id, - ), + ], $parent->id ); // Assert $c1 still in $child $this->assertDBQuery(1, 'select count(*) from civicrm_group_contact where group_id=%1 and contact_id=%2 and status=%3', - array( - 1 => array($child->id, 'Integer'), - 2 => array($deceased[0]->id, 'Integer'), - 3 => array('Added', 'String'), - ) + [ + 1 => [$child->id, 'Integer'], + 2 => [$deceased[0]->id, 'Integer'], + 3 => ['Added', 'String'], + ] ); } @@ -147,9 +147,9 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function assertCacheMatches($expectedContactIds, $groupId) { $sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1'; - $params = array(1 => array($groupId, 'Integer')); + $params = [1 => [$groupId, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($sql, $params); - $actualContactIds = array(); + $actualContactIds = []; while ($dao->fetch()) { $actualContactIds[] = $dao->contact_id; } @@ -164,9 +164,9 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testOpportunisticRefreshCacheNoChangeIfNotExpired() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); $this->assertCacheMatches( - array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), + [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id], $group->id ); CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); @@ -179,7 +179,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testOpportunisticRefreshChangeIfCacheDateFieldStale() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); CRM_Core_DAO::executeQuery('UPDATE civicrm_group SET cache_date = DATE_SUB(NOW(), INTERVAL 7 MINUTE) WHERE id = ' . $group->id); $group->find(TRUE); Civi::$statics['CRM_Contact_BAO_GroupContactCache']['is_refresh_init'] = FALSE; @@ -194,12 +194,12 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testOpportunisticRefreshNoChangeWithDeterministicSetting() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic')); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); $this->makeCacheStale($group); CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); $this->assertCacheNotRefreshed($deceased, $group); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']); } /** @@ -207,12 +207,12 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testDeterministicRefreshChangeWithDeterministicSetting() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic')); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); $this->makeCacheStale($group); CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); $this->assertCacheRefreshed($group); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']); } /** @@ -220,11 +220,11 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testDeterministicRefreshChangeDoesNotTouchNonExpired() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic')); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); $this->assertCacheNotRefreshed($deceased, $group); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']); } /** @@ -234,8 +234,8 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testDeterministicRefreshChangeWithOpportunisticSetting() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); $this->makeCacheStale($group); CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); $this->assertCacheRefreshed($group); @@ -246,10 +246,10 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ public function testJobWrapper() { list($group, $living, $deceased) = $this->setupSmartGroup(); - $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); - $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); + $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']); + $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]); $this->makeCacheStale($group); - $this->callAPISuccess('Job', 'group_cache_flush', array()); + $this->callAPISuccess('Job', 'group_cache_flush', []); $this->assertCacheRefreshed($group); } @@ -266,7 +266,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { * This method is called before a test is executed. */ protected function setUp() { - $this->_testObjects = array(); + $this->_testObjects = []; parent::setUp(); } @@ -292,13 +292,13 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { * * @return array|NULL|object */ - public function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE) { + public function createTestObject($daoName, $params = [], $numObjects = 1, $createOnly = FALSE) { $objects = CRM_Core_DAO::createTestObject($daoName, $params, $numObjects, $createOnly); if (is_array($objects)) { $this->registerTestObjects($objects); } else { - $this->registerTestObjects(array($objects)); + $this->registerTestObjects([$objects]); } return $objects; } @@ -328,10 +328,10 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { public function deleteTestObjects() { foreach ($this->_testObjects as $daoName => $daoIds) { foreach ($daoIds as $daoId) { - CRM_Core_DAO::deleteTestObjects($daoName, array('id' => $daoId)); + CRM_Core_DAO::deleteTestObjects($daoName, ['id' => $daoId]); } } - $this->_testObjects = array(); + $this->_testObjects = []; } /** @@ -340,18 +340,18 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { * @return array */ protected function setupSmartGroup() { - $params = array( + $params = [ 'name' => 'Deceased Contacts', 'title' => 'Deceased Contacts', 'is_active' => 1, - 'formValues' => array('is_deceased' => 1), - ); + 'formValues' => ['is_deceased' => 1], + ]; $group = CRM_Contact_BAO_Group::createSmartGroup($params); - $this->registerTestObjects(array($group)); + $this->registerTestObjects([$group]); // Create contacts $y1, $y2, $y3 which do match $g; create $n1, $n2, $n3 which do not match $g - $living = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 0), 3); - $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3); + $living = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 0], 3); + $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3); $this->assertEquals(3, count($deceased)); $this->assertEquals(3, count($living)); @@ -359,11 +359,11 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { CRM_Contact_BAO_GroupContactCache::load($group, TRUE); $group->find(TRUE); $this->assertCacheMatches( - array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), + [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id], $group->id ); // Reload the group so we have the cache_date & refresh_date. - return array($group, $living, $deceased); + return [$group, $living, $deceased]; } /** @@ -374,10 +374,10 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ protected function assertCacheNotRefreshed($deceased, $group) { $this->assertCacheMatches( - array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), + [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id], $group->id ); - $afterGroup = $this->callAPISuccessGetSingle('Group', array('id' => $group->id)); + $afterGroup = $this->callAPISuccessGetSingle('Group', ['id' => $group->id]); $this->assertEquals($group->cache_date, $afterGroup['cache_date']); } @@ -400,11 +400,11 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { */ protected function assertCacheRefreshed($group) { $this->assertCacheMatches( - array(), + [], $group->id ); - $afterGroup = $this->callAPISuccessGetSingle('Group', array('id' => $group->id)); + $afterGroup = $this->callAPISuccessGetSingle('Group', ['id' => $group->id]); $this->assertTrue(empty($afterGroup['cache_date']), 'refresh date should not be set as the cache is not built'); $this->assertTrue(empty($afterGroup['refresh_date']), 'refresh date should not be set as the cache is not built'); } @@ -413,24 +413,24 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { * Test Smart group search */ public function testSmartGroupSearchBuilder() { - $returnProperties = array( + $returnProperties = [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'group' => 1, - ); + ]; list($group, $living, $deceased) = $this->setupSmartGroup(); - $params = array( + $params = [ 'name' => 'Living Contacts', 'title' => 'Living Contacts', 'is_active' => 1, - 'formValues' => array('is_deceased' => 0), - ); + 'formValues' => ['is_deceased' => 0], + ]; $group2 = CRM_Contact_BAO_Group::createSmartGroup($params); //Filter on smart group with =, !=, IN and NOT IN operator. - $params = array(array('group', '=', $group2->id, 1, 0)); + $params = [['group', '=', $group2->id, 1, 0]]; $query = new CRM_Contact_BAO_Query( $params, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, @@ -446,7 +446,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id = {$group2->id}"); - $params = array(array('group', '!=', $group->id, 1, 0)); + $params = [['group', '!=', $group->id, 1, 0]]; $query = new CRM_Contact_BAO_Query( $params, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, @@ -459,7 +459,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id != {$group->id}"); - $params = array(array('group', 'IN', array($group->id, $group2->id), 1, 0)); + $params = [['group', 'IN', [$group->id, $group2->id], 1, 0]]; $query = new CRM_Contact_BAO_Query( $params, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, @@ -471,7 +471,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id IN ({$group->id}, {$group2->id})"); - $params = array(array('group', 'NOT IN', array($group->id), 1, 0)); + $params = [['group', 'NOT IN', [$group->id], 1, 0]]; $query = new CRM_Contact_BAO_Query( $params, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, @@ -487,24 +487,24 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { } public function testMultipleGroupWhereClause() { - $returnProperties = array( + $returnProperties = [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'group' => 1, - ); + ]; list($group, $living, $deceased) = $this->setupSmartGroup(); - $params = array( + $params = [ 'name' => 'Living Contacts', 'title' => 'Living Contacts', 'is_active' => 1, - 'formValues' => array('is_deceased' => 0), - ); + 'formValues' => ['is_deceased' => 0], + ]; $group2 = CRM_Contact_BAO_Group::createSmartGroup($params); //Filter on smart group with =, !=, IN and NOT IN operator. - $params = array(array('group', '=', $group2->id, 1, 0), array('group', '=', $group->id, 1, 0)); + $params = [['group', '=', $group2->id, 1, 0], ['group', '=', $group->id, 1, 0]]; $query = new CRM_Contact_BAO_Query( $params, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, @@ -539,7 +539,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { FALSE, FALSE, FALSE, TRUE, FALSE )); - $expectedContactIds = array(); + $expectedContactIds = []; $groupDAO = CRM_Core_DAO::executeQuery("SELECT contact_id FROM civicrm_group_contact_cache WHERE {$groupWhereClause}"); while ($groupDAO->fetch()) { $expectedContactIds[] = $groupDAO->contact_id; diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php index 8002a15b60..ef50508744 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php @@ -96,102 +96,102 @@ class CRM_Contact_BAO_GroupContactTest extends CiviUnitTestCase { */ public function testContactSearchByParentGroup() { // create a parent group - $parentGroup = $this->callAPISuccess('Group', 'create', array( + $parentGroup = $this->callAPISuccess('Group', 'create', [ 'title' => 'Parent Group', 'description' => 'Parent Group', 'visibility' => 'User and User Admin Only', 'is_active' => 1, - )); + ]); // create a child group - $childGroup = $this->callAPISuccess('Group', 'create', array( + $childGroup = $this->callAPISuccess('Group', 'create', [ 'title' => 'Child Group', 'description' => 'Child Group', 'visibility' => 'User and User Admin Only', 'parents' => $parentGroup['id'], 'is_active' => 1, - )); + ]); // create smart group based on saved criteria Gender = Male - $batch = $this->callAPISuccess('SavedSearch', 'create', array( + $batch = $this->callAPISuccess('SavedSearch', 'create', [ 'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}', - )); + ]); // Create contact with Gender - Male - $childSmartGroupContact = $this->individualCreate(array( + $childSmartGroupContact = $this->individualCreate([ 'gender_id' => "Male", 'first_name' => 'C', - ), 1); + ], 1); // then create smart group - $childSmartGroup = $this->callAPISuccess('Group', 'create', array( + $childSmartGroup = $this->callAPISuccess('Group', 'create', [ 'title' => 'Child Smart Group', 'description' => 'Child Smart Group', 'visibility' => 'User and User Admin Only', 'saved_search_id' => $batch['id'], 'is_active' => 1, 'parents' => $parentGroup['id'], - )); + ]); - $this->callAPISuccess('Group', 'create', array( + $this->callAPISuccess('Group', 'create', [ 'id' => $parentGroup['id'], - 'children' => implode(',', array($childGroup['id'], $childSmartGroup['id'])), - )); + 'children' => implode(',', [$childGroup['id'], $childSmartGroup['id']]), + ]); // Create a contact within parent group - $parentContactParams = array( + $parentContactParams = [ 'first_name' => 'Parent1 Fname', 'last_name' => 'Parent1 Lname', - 'group' => array($parentGroup['id'] => 1), - ); + 'group' => [$parentGroup['id'] => 1], + ]; $parentContact = $this->individualCreate($parentContactParams); // create a contact within child dgroup - $childContactParams = array( + $childContactParams = [ 'first_name' => 'Child1 Fname', 'last_name' => 'Child2 Lname', 'group' => [$childGroup['id'] => 1], - ); + ]; $childContact = $this->individualCreate($childContactParams); // Check if searching by parent group returns both parent and child group contacts - $result = $this->callAPISuccess('contact', 'get', array( + $result = $this->callAPISuccess('contact', 'get', [ 'group' => $parentGroup['id'], - )); - $validContactIds = array($parentContact, $childContact); - $resultContactIds = array(); + ]); + $validContactIds = [$parentContact, $childContact]; + $resultContactIds = []; foreach ($result['values'] as $k => $v) { $resultContactIds[] = $v['contact_id']; } $this->assertEquals(3, count($resultContactIds), 'Check the count of returned values'); - $this->assertEquals(array(), array_diff($validContactIds, $resultContactIds), 'Check that the difference between two arrays should be blank array'); + $this->assertEquals([], array_diff($validContactIds, $resultContactIds), 'Check that the difference between two arrays should be blank array'); // Check if searching by child group returns just child group contacts - $result = $this->callAPISuccess('contact', 'get', array( + $result = $this->callAPISuccess('contact', 'get', [ 'group' => $childGroup['id'], - )); - $validChildContactIds = array($childContact); - $resultChildContactIds = array(); + ]); + $validChildContactIds = [$childContact]; + $resultChildContactIds = []; foreach ($result['values'] as $k => $v) { $resultChildContactIds[] = $v['contact_id']; } $this->assertEquals(1, count($resultChildContactIds), 'Check the count of returned values'); - $this->assertEquals(array(), array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array'); + $this->assertEquals([], array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array'); // Check if searching by smart child group returns just smart child group contacts - $result = $this->callAPISuccess('contact', 'get', array( + $result = $this->callAPISuccess('contact', 'get', [ 'group' => $childSmartGroup['id'], - )); - $validChildContactIds = array($childSmartGroupContact); - $resultChildContactIds = array(); + ]); + $validChildContactIds = [$childSmartGroupContact]; + $resultChildContactIds = []; foreach ($result['values'] as $k => $v) { $resultChildContactIds[] = $v['contact_id']; } $this->assertEquals(1, count($resultChildContactIds), 'Check the count of returned values'); - $this->assertEquals(array(), array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array'); + $this->assertEquals([], array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array'); //cleanup - $this->callAPISuccess('Contact', 'delete', array('id' => $parentContact)); - $this->callAPISuccess('Contact', 'delete', array('id' => $childContact)); - $this->callAPISuccess('Contact', 'delete', array('id' => $childSmartGroupContact)); + $this->callAPISuccess('Contact', 'delete', ['id' => $parentContact]); + $this->callAPISuccess('Contact', 'delete', ['id' => $childContact]); + $this->callAPISuccess('Contact', 'delete', ['id' => $childSmartGroupContact]); } /** @@ -199,65 +199,65 @@ class CRM_Contact_BAO_GroupContactTest extends CiviUnitTestCase { */ public function testContactCombineGroupSearch() { // create regular group based - $regularGroup = $this->callAPISuccess('Group', 'create', array( + $regularGroup = $this->callAPISuccess('Group', 'create', [ 'title' => 'Regular Group', 'description' => 'Regular Group', 'visibility' => 'User and User Admin Only', 'is_active' => 1, - )); + ]); // Create contact with Gender - Male - $contact1 = $this->individualCreate(array( + $contact1 = $this->individualCreate([ 'gender_id' => "Male", 'first_name' => 'A', - )); + ]); // Create contact with Gender - Male and in regular group - $contact2 = $this->individualCreate(array( - 'group' => array($regularGroup['id'] => 1), + $contact2 = $this->individualCreate([ + 'group' => [$regularGroup['id'] => 1], 'gender_id' => "Male", 'first_name' => 'B', - ), 1); + ], 1); // Create contact with Gender - Female and in regular group - $contact3 = $this->individualCreate(array( - 'group' => array($regularGroup['id'] => 1), + $contact3 = $this->individualCreate([ + 'group' => [$regularGroup['id'] => 1], 'gender_id' => "Female", 'first_name' => 'C', - ), 1); + ], 1); // create smart group based on saved criteria Gender = Male - $batch = $this->callAPISuccess('SavedSearch', 'create', array( + $batch = $this->callAPISuccess('SavedSearch', 'create', [ 'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}', - )); - $smartGroup = $this->callAPISuccess('Group', 'create', array( + ]); + $smartGroup = $this->callAPISuccess('Group', 'create', [ 'title' => 'Smart Group', 'description' => 'Smart Group', 'visibility' => 'User and User Admin Only', 'saved_search_id' => $batch['id'], 'is_active' => 1, - )); + ]); - $useCases = array( + $useCases = [ //Case 1: Find all contacts in regular group - array( - 'form_value' => array('group' => $regularGroup['id']), + [ + 'form_value' => ['group' => $regularGroup['id']], 'expected_count' => 2, - 'expected_contact' => array($contact2, $contact3), - ), + 'expected_contact' => [$contact2, $contact3], + ], //Case 2: Find all contacts in smart group - array( - 'form_value' => array('group' => $smartGroup['id']), + [ + 'form_value' => ['group' => $smartGroup['id']], 'expected_count' => 2, - 'expected_contact' => array($contact1, $contact2), - ), + 'expected_contact' => [$contact1, $contact2], + ], //Case 3: Find all contacts in regular group and smart group - array( - 'form_value' => array('group' => array('IN' => array($regularGroup['id'], $smartGroup['id']))), + [ + 'form_value' => ['group' => ['IN' => [$regularGroup['id'], $smartGroup['id']]]], 'expected_count' => 3, - 'expected_contact' => array($contact1, $contact2, $contact3), - ), - ); + 'expected_contact' => [$contact1, $contact2, $contact3], + ], + ]; foreach ($useCases as $case) { $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($case['form_value'])); list($select, $from, $where, $having) = $query->query(); @@ -279,53 +279,53 @@ class CRM_Contact_BAO_GroupContactTest extends CiviUnitTestCase { $accessControlGT = array_search('Access Control', $groupTypes); // create group with group type - Mailing list - $group1 = $this->callAPISuccess('Group', 'create', array( + $group1 = $this->callAPISuccess('Group', 'create', [ 'title' => 'Group 1', 'visibility' => 'User and User Admin Only', 'is_active' => 1, 'group_type' => $mailingListGT, - )); + ]); // create group with group type - Access Control - $group2 = $this->callAPISuccess('Group', 'create', array( + $group2 = $this->callAPISuccess('Group', 'create', [ 'title' => 'Group 2', 'visibility' => 'User and User Admin Only', 'is_active' => 1, 'group_type' => $accessControlGT, - )); + ]); // create contact in 'Group 1' - $contact1 = $this->individualCreate(array( - 'group' => array($group1['id'] => 1), + $contact1 = $this->individualCreate([ + 'group' => [$group1['id'] => 1], 'first_name' => 'A', - )); + ]); // create contact in 'Group 2' - $contact2 = $this->individualCreate(array( - 'group' => array($group2['id'] => 1), + $contact2 = $this->individualCreate([ + 'group' => [$group2['id'] => 1], 'first_name' => 'B', - ), 1); + ], 1); - $useCases = array( + $useCases = [ //Case 1: Find contacts in group type - Mailing List - array( - 'form_value' => array('group_type' => array($mailingListGT)), + [ + 'form_value' => ['group_type' => [$mailingListGT]], 'expected_count' => 1, - 'expected_contact' => array($contact1), - ), + 'expected_contact' => [$contact1], + ], //Case 2: Find contacts in group type - Access Control - array( - 'form_value' => array('group_type' => array($accessControlGT)), + [ + 'form_value' => ['group_type' => [$accessControlGT]], 'expected_count' => 1, - 'expected_contact' => array($contact2), - ), + 'expected_contact' => [$contact2], + ], //Case 3: Find contacts in group type - Mailing List or Access List - array( - 'form_value' => array('group_type' => array($mailingListGT, $accessControlGT)), + [ + 'form_value' => ['group_type' => [$mailingListGT, $accessControlGT]], 'expected_count' => 2, - 'expected_contact' => array($contact1, $contact2), - ), - ); + 'expected_contact' => [$contact1, $contact2], + ], + ]; foreach ($useCases as $case) { $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($case['form_value'])); diff --git a/tests/phpunit/CRM/Contact/BAO/GroupTest.php b/tests/phpunit/CRM/Contact/BAO/GroupTest.php index b37d5ddb36..65f96fe7a6 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupTest.php @@ -48,7 +48,7 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { * This method is called after a test is executed. */ protected function tearDown() { - $this->quickCleanup(array('civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search')); + $this->quickCleanup(['civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search']); } /** @@ -56,18 +56,18 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { */ public function testAddSimple() { - $checkParams = $params = array( + $checkParams = $params = [ 'title' => 'Group Uno', 'description' => 'Group One', 'visibility' => 'User and User Admin Only', 'is_active' => 1, - ); + ]; $group = CRM_Contact_BAO_Group::create($params); $this->assertDBCompareValues( 'CRM_Contact_DAO_Group', - array('id' => $group->id), + ['id' => $group->id], $checkParams ); } @@ -81,39 +81,39 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { // 1. Create two parent group A and B and disable B // 2. Create a child group C // 3. Ensure that Group C is present in the group hierarchy - $params = array( + $params = [ 'name' => uniqid(), 'title' => 'Parent Group A', 'description' => 'Parent Group One', 'visibility' => 'User and User Admin Only', 'is_active' => 1, - ); + ]; $group1 = CRM_Contact_BAO_Group::create($params); - $params = array_merge($params, array( + $params = array_merge($params, [ 'name' => uniqid(), 'title' => 'Parent Group B', 'description' => 'Parent Group Two', // disable 'is_active' => 0, - )); + ]); $group2 = CRM_Contact_BAO_Group::create($params); - $params = array_merge($params, array( + $params = array_merge($params, [ 'name' => uniqid(), 'title' => 'Child Group C', 'description' => 'Child Group C', - 'parents' => array( + 'parents' => [ $group1->id => 1, $group2->id => 1, - ), - )); + ], + ]); $group3 = CRM_Contact_BAO_Group::create($params); - $params = array( + $params = [ $group1->id => 1, $group3->id => 1, - ); + ]; $groupsHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($params, NULL, '  ', TRUE); // check if child group is present in the tree with formatted group title prepended with spacer '  ' $this->assertEquals('  Child Group C', $groupsHierarchy[$group3->id]); @@ -130,20 +130,20 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { */ public function testAddSmart() { - $checkParams = $params = array( + $checkParams = $params = [ 'title' => 'Group Dos', 'description' => 'Group Two', 'visibility' => 'User and User Admin Only', 'is_active' => 1, - 'formValues' => array('sort_name' => 'Adams'), - ); + 'formValues' => ['sort_name' => 'Adams'], + ]; $group = CRM_Contact_BAO_Group::createSmartGroup($params); unset($checkParams['formValues']); $this->assertDBCompareValues( 'CRM_Contact_DAO_Group', - array('id' => $group->id), + ['id' => $group->id], $checkParams ); } @@ -157,7 +157,7 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { $this->loadSavedSearches(); $results = CRM_Core_DAO::singleValueQuery('SELECT GROUP_CONCAT(id) FROM civicrm_group WHERE saved_search_id IS NOT NULL'); - return array(explode(',', $results)); + return [explode(',', $results)]; } /** @@ -204,35 +204,35 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { * Ensure that when updating a group with a linked organisation record even tho that record's id doesn't match the group id no db error is produced */ public function testGroupUpdateWithOrganization() { - $params = array( + $params = [ 'name' => uniqid(), 'title' => 'Group A', 'description' => 'Group One', 'visibility' => 'User and User Admin Only', 'is_active' => 1, - ); + ]; $group1 = CRM_Contact_BAO_Group::create($params); $domain1 = $this->callAPISuccess('Domain', 'get', ['id' => 1]); - $params2 = array( + $params2 = [ 'name' => uniqid(), 'title' => 'Group B', 'description' => 'Group Two', 'visibility' => 'User and User Admin Only', 'is_active' => 1, 'organization_id' => $domain1['values'][1]['contact_id'], - ); + ]; $group2 = CRM_Contact_BAO_Group::create($params2); $domain2 = $this->callAPISuccess('Domain', 'get', ['id' => 2]); - $params3 = array( + $params3 = [ 'name' => uniqid(), 'title' => 'Group C', 'description' => 'Group Three', 'visibility' => 'User and User Admin Only', 'is_active' => 1, 'organization_id' => $domain2['values'][2]['contact_id'], - ); + ]; $group3 = CRM_Contact_BAO_Group::create($params3); $params2['id'] = $group2->id; $testUpdate = CRM_Contact_BAO_Group::create($params2); @@ -243,12 +243,12 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { */ public function testHiddenSmartGroup() { $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', 'custom_group_id' => $customGroup['id'], - ); + ]; $customFieldID = CRM_Core_BAO_CustomField::create($fields)->id; $contactID = $this->individualCreate(['custom_' . $customFieldID => 'abc']); @@ -263,12 +263,12 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase { list($smartGroupID, $savedSearchID) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams); $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id']; - $this->callAPISuccess('MailingGroup', 'create', array( + $this->callAPISuccess('MailingGroup', 'create', [ 'mailing_id' => $mailingID, 'group_type' => 'Include', 'entity_table' => 'civicrm_group', 'entity_id' => $smartGroupID, - )); + ]); CRM_Mailing_BAO_Mailing::getRecipients($mailingID); $recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailingID]); diff --git a/tests/phpunit/CRM/Contact/BAO/IndividualTest.php b/tests/phpunit/CRM/Contact/BAO/IndividualTest.php index 9d70a7e2ae..0307ef1390 100644 --- a/tests/phpunit/CRM/Contact/BAO/IndividualTest.php +++ b/tests/phpunit/CRM/Contact/BAO/IndividualTest.php @@ -12,11 +12,11 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { * See CRM-19123: Merging contacts: blank date fields write as 1970 */ public function testFormatNullDates() { - $params = array( + $params = [ 'contact_type' => 'Individual', 'birth_date' => 'null', 'deceased_date' => 'null', - ); + ]; $contact = new CRM_Contact_DAO_Contact(); CRM_Contact_BAO_Individual::format($params, $contact); @@ -31,13 +31,13 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { */ public function testFormatDisplayName() { - $params = array( + $params = [ 'contact_type' => 'Individual', 'first_name' => 'Ben', 'last_name' => 'Lee', 'individual_prefix' => 'Mr.', 'individual_suffix' => 'Jr.', - ); + ]; $contact = new CRM_Contact_DAO_Contact(); @@ -54,7 +54,7 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { */ public function testFormatDisplayNamePrefixesById() { - $params = array( + $params = [ 'contact_type' => 'Individual', 'first_name' => 'Ben', 'last_name' => 'Lee', @@ -62,7 +62,7 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { 'prefix_id' => 4, // and the doctor is a senior 'suffix_id' => 2, - ); + ]; $contact = new CRM_Contact_DAO_Contact(); @@ -78,11 +78,11 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { */ public function testFormatDisplayNameNoIndividual() { - $params = array( + $params = [ 'contact_type' => 'Organization', 'first_name' => 'Ben', 'last_name' => 'Lee', - ); + ]; $contact = new CRM_Contact_DAO_Contact(); @@ -96,14 +96,14 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { */ public function testFormatDisplayNameOnlyEmail() { - $email['1'] = array('email' => "bleu01@example.com"); - $email['2'] = array('email' => "bleu02@example.com", 'is_primary' => 1); - $email['3'] = array('email' => "bleu03@example.com"); + $email['1'] = ['email' => "bleu01@example.com"]; + $email['2'] = ['email' => "bleu02@example.com", 'is_primary' => 1]; + $email['3'] = ['email' => "bleu03@example.com"]; - $params = array( + $params = [ 'contact_type' => 'Individual', 'email' => $email , - ); + ]; $contact = new CRM_Contact_DAO_Contact(); diff --git a/tests/phpunit/CRM/Contact/BAO/QueryStateNameTest.php b/tests/phpunit/CRM/Contact/BAO/QueryStateNameTest.php index ba16c35814..65e75f5f91 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryStateNameTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryStateNameTest.php @@ -15,21 +15,21 @@ class CRM_Contact_BAO_QueryStateNameTest extends CiviUnitTestCase { public function testStateName() { $state_name = 'Norfolk'; $state_abbreviation = 'NFK'; - $create_params = array( + $create_params = [ 'contact_type' => 'Individual', 'first_name' => 'John', 'last_name' => 'Doe', - 'api.Address.create' => array( + 'api.Address.create' => [ 'location_type_id' => 'Home', 'state_province_id' => $state_name, - ), - ); + ], + ]; $create_res = civicrm_api3('Contact', 'Create', $create_params); - $get_params = array( + $get_params = [ 'id' => $create_res['id'], 'sequential' => 1, - ); + ]; $get_res = civicrm_api3('Contact', 'get', $get_params); $this->assertEquals($state_name, $get_res['values'][0]['state_province_name']); // Lock in that state_provice should equal that of the abbreviation. diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php b/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php index a25441ffba..a193317701 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php @@ -50,11 +50,11 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { * IDs should be selected when the form values are applied to the * database in dataset.xml */ - private $dataset = array( + private $dataset = [ // Include static group 3 - array( - 'fv' => array('group' => '3'), - 'id' => array( + [ + 'fv' => ['group' => '3'], + 'id' => [ '17', '18', '19', @@ -63,12 +63,12 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '22', '23', '24', - ), - ), + ], + ], // Include static group 5 - array( - 'fv' => array('group' => '5'), - 'id' => array( + [ + 'fv' => ['group' => '5'], + 'id' => [ '13', '14', '15', @@ -77,12 +77,12 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '22', '23', '24', - ), - ), + ], + ], // Include static groups 3 and 5 - array( - 'fv' => array('group' => array('3', '5')), - 'id' => array( + [ + 'fv' => ['group' => ['3', '5']], + 'id' => [ '13', '14', '15', @@ -95,12 +95,12 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '22', '23', '24', - ), - ), + ], + ], // Include static groups 3 and 5 in legacy format - array( - 'fv' => array('group' => array('3' => 1, '5' => 1)), - 'id' => array( + [ + 'fv' => ['group' => ['3' => 1, '5' => 1]], + 'id' => [ '13', '14', '15', @@ -113,12 +113,12 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '22', '23', '24', - ), - ), + ], + ], // Include tag 7 - array( - 'fv' => array('tag' => '7'), - 'id' => array( + [ + 'fv' => ['tag' => '7'], + 'id' => [ '11', '12', '15', @@ -127,12 +127,12 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '20', '23', '24', - ), - ), + ], + ], // Include tag 9 - array( - 'fv' => array('tag' => array('9' => 1)), - 'id' => array( + [ + 'fv' => ['tag' => ['9' => 1]], + 'id' => [ '10', '12', '14', @@ -141,12 +141,12 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '20', '22', '24', - ), - ), + ], + ], // Include tags 7 and 9 - array( - 'fv' => array('tag' => array('7', '9')), - 'id' => array( + [ + 'fv' => ['tag' => ['7', '9']], + 'id' => [ '10', '11', '12', @@ -159,24 +159,24 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '22', '23', '24', - ), - ), + ], + ], // gender_id 1 = 'Female' - array( - 'fv' => array('gender_id' => 1), - 'id' => array('9', '20', '22'), - ), + [ + 'fv' => ['gender_id' => 1], + 'id' => ['9', '20', '22'], + ], // prefix_id 2 = 'Ms.' - array( - 'fv' => array('prefix_id' => 2), - 'id' => array('10', '13'), - ), + [ + 'fv' => ['prefix_id' => 2], + 'id' => ['10', '13'], + ], // suffix_id 6 = 'V' - array( - 'fv' => array('suffix_id' => 6), - 'id' => array('16', '19', '20', '21'), - ), - ); + [ + 'fv' => ['suffix_id' => 6], + 'id' => ['16', '19', '20', '21'], + ], + ]; public function _construct() { $this->i = 0; @@ -192,15 +192,15 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { public function current() { $count = count($this->dataset[$this->i]['id']); $ids = $this->dataset[$this->i]['id']; - $full = array(); + $full = []; foreach ($this->dataset[$this->i]['id'] as $key => $value) { - $full[] = array( + $full[] = [ 'contact_id' => $value, 'contact_type' => 'Individual', 'sort_name' => "Test Contact $value", - ); + ]; } - return array($this->dataset[$this->i]['fv'], $count, $ids, $full); + return [$this->dataset[$this->i]['fv'], $count, $ids, $full]; } /** diff --git a/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php b/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php index 4ad1e34123..382f404f96 100644 --- a/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php +++ b/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php @@ -155,54 +155,54 @@ class CRM_Contact_BAO_RelationshipTest extends CiviUnitTestCase { } public function getRelationshipTypeDuplicates() { - $relationshipTypeList = array( + $relationshipTypeList = [ '1_a_b' => 'duplicate one', '1_b_a' => 'duplicate one', '2_a_b' => 'two a', '2_b_a' => 'two b', - ); - $data = array( - array( + ]; + $data = [ + [ $relationshipTypeList, 'a_b', - array( + [ '1_a_b' => 'duplicate one', '2_a_b' => 'two a', '2_b_a' => 'two b', - ), + ], 'With suffix a_b', - ), - array( + ], + [ $relationshipTypeList, 'b_a', - array( + [ '1_b_a' => 'duplicate one', '2_a_b' => 'two a', '2_b_a' => 'two b', - ), + ], 'With suffix b_a', - ), - array( + ], + [ $relationshipTypeList, NULL, - array( + [ '1_a_b' => 'duplicate one', '2_a_b' => 'two a', '2_b_a' => 'two b', - ), + ], 'With suffix NULL', - ), - array( + ], + [ $relationshipTypeList, NULL, - array( + [ '1_a_b' => 'duplicate one', '2_a_b' => 'two a', '2_b_a' => 'two b', - ), + ], 'With suffix "" (empty string)', - ), - ); + ], + ]; return $data; } diff --git a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php index 9289e8fddb..52965533db 100644 --- a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php +++ b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php @@ -48,12 +48,12 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { * This method is called after a test is executed. */ protected function tearDown() { - $this->quickCleanup(array( + $this->quickCleanup([ 'civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search', - )); + ]); } /** @@ -62,14 +62,14 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { public function testDefaultValues() { $sg = new CRM_Contact_Form_Search_Advanced(); $sg->controller = new CRM_Core_Controller(); - $sg->_formValues = array( + $sg->_formValues = [ 'group_search_selected' => 'group', - 'privacy_options' => array('do_not_email'), + 'privacy_options' => ['do_not_email'], 'privacy_operator' => 'OR', 'privacy_toggle' => 2, 'operator' => 'AND', 'component_mode' => 1, - ); + ]; CRM_Core_DAO::executeQuery( "INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($sg->_formValues) . "')" ); @@ -91,7 +91,7 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { "INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($formValues) . "')" ); $result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()')); - $this->assertEquals(array('membership_type_id', 'membership_status_id'), array_keys($result)); + $this->assertEquals(['membership_type_id', 'membership_status_id'], array_keys($result)); foreach ($result as $key => $value) { $this->assertEquals($expectedResult, $value, 'failure on set ' . $searchDescription); } @@ -104,7 +104,7 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { */ public function testDateRange() { $savedSearch = new CRM_Contact_BAO_SavedSearch(); - $formValues = array( + $formValues = [ 'hidden_basic' => 1, 'group_search_selected' => 'group', 'component_mode' => 1, @@ -115,24 +115,24 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { 'participant_register_date_high' => '01/01/2018', 'radio_ts' => 'ts_all', 'title' => 'bah bah bah', - ); + ]; - $queryParams = array( - 0 => array( + $queryParams = [ + 0 => [ 0 => 'participant_register_date_low', 1 => '=', 2 => '01/01/2009', 3 => 0, 4 => 0, - ), - 1 => array( + ], + 1 => [ 0 => 'participant_register_date_high', 1 => '=', 2 => '01/01/2018', 3 => 0, 4 => 0, - ), - ); + ], + ]; CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues); CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues); @@ -151,26 +151,26 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { public function testSkippedElements() { $relTypeID = $this->relationshipTypeCreate(); $savedSearch = new CRM_Contact_BAO_SavedSearch(); - $formValues = array( + $formValues = [ 'operator' => 'AND', 'title' => 'testsmart', 'radio_ts' => 'ts_all', 'component_mode' => CRM_Contact_BAO_Query::MODE_CONTACTS, 'display_relationship_type' => "{$relTypeID}_a_b", 'uf_group_id' => 1, - ); - $queryParams = array(); + ]; + $queryParams = []; CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues); $savedSearch->form_values = serialize($queryParams); $savedSearch->save(); $result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()')); - $expectedResult = array( + $expectedResult = [ 'operator' => 'AND', 'component_mode' => CRM_Contact_BAO_Query::MODE_CONTACTS, 'display_relationship_type' => "{$relTypeID}_a_b", 'uf_group_id' => 1, - ); + ]; $this->checkArrayEquals($result, $expectedResult); } @@ -180,14 +180,14 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { */ public function testRelativeDateValues() { $savedSearch = new CRM_Contact_BAO_SavedSearch(); - $formValues = array( + $formValues = [ 'operator' => 'AND', 'event_relative' => 'this.month', 'participant_relative' => 'today', 'participant_test' => 0, 'title' => 'testsmart', 'radio_ts' => 'ts_all', - ); + ]; $queryParams = []; CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues); CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues); @@ -213,8 +213,8 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { */ public function testCustomFieldRelativeDates() { // Create a custom field. - $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'relative_date_test_group')); - $params = array( + $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'relative_date_test_group']); + $params = [ 'custom_group_id' => $customGroup['id'], 'name' => 'test_datefield', 'label' => 'Date Field for Testing', @@ -226,31 +226,31 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { 'is_searchable' => 1, 'date_format' => 'mm/dd/yy', 'is_active' => 1, - ); + ]; $customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__); $id = $customField['id']; - $queryParams = array( - 0 => array( + $queryParams = [ + 0 => [ 0 => "custom_${id}_low", 1 => '=', 2 => '20170425000000', - ), - 1 => array( + ], + 1 => [ 0 => "custom_${id}_high", 1 => '=', 2 => '20170501235959', - ), - ); - $formValues = array( + ], + ]; + $formValues = [ "custom_${id}_relative" => 'ending.week', - ); + ]; CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues); // Since custom_13 doesn't have the word 'date' in it, the key is // set to 0, rather than the field name. $this->assertArrayNotHasKey('relative_dates', $queryParams, 'Relative date in custom field smart group creation failed.'); $dropCustomValueTables = TRUE; - $this->quickCleanup(array('civicrm_saved_search'), $dropCustomValueTables); + $this->quickCleanup(['civicrm_saved_search'], $dropCustomValueTables); } /** @@ -259,10 +259,10 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { * @return array */ public function getSavedSearches() { - $return = array(); + $return = []; $searches = $this->getSearches(); foreach ($searches as $key => $search) { - $return[] = array($search['form_values'], $search['expected'], $key); + $return[] = [$search['form_values'], $search['expected'], $key]; } return $return; } @@ -275,78 +275,78 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { * @return array */ public function getSearches() { - return array( - 'checkbox_format_1_first' => array( - 'form_values' => array( - 'member_membership_type_id' => array(1 => 1, 2 => 1), - 'member_status_id' => array(1 => 1, 2 => 1), - ), - 'expected' => array(1, 2), - ), - 'checkbox_format_1_later' => array( - 'form_values' => array( - 'member_membership_type_id' => array(2 => 1, 1 => 1), - 'member_status_id' => array(2 => 1, 1 => 1), - ), - 'expected' => array(2, 1), - ), - 'checkbox_format_single_use_1' => array( - 'form_values' => array( - 'member_membership_type_id' => array(1 => 1), - 'member_status_id' => array(1 => 1), - ), - 'expected' => array(1), - ), - 'checkbox_format_single_not_1' => array( - 'form_values' => array( - 'member_membership_type_id' => array(2 => 1), - 'member_status_id' => array(2 => 1), - ), - 'expected' => array(2), - ), - 'array_format' => array( - 'form_values' => array( - 'member_membership_type_id' => array(1, 2), - 'member_status_id' => array(1, 2), - ), - 'expected' => array(1, 2), - ), - 'array_format_1_later' => array( - 'form_values' => array( - 'member_membership_type_id' => array(2, 1), - 'member_status_id' => array(2, 1), - ), - 'expected' => array(2, 1), - ), - 'array_format_single_use_1' => array( - 'form_values' => array( - 'member_membership_type_id' => array(1), - 'member_status_id' => array(1), - ), - 'expected' => array(1), - ), - 'array_format_single_not_1' => array( - 'form_values' => array( - 'member_membership_type_id' => array(2), - 'member_status_id' => array(2), - ), - 'expected' => array(2), - ), - 'IN_format_single_not_1' => array( - 'form_values' => array( - 'membership_type_id' => array('IN' => array(2)), - 'membership_status_id' => array('IN' => array(2)), - ), - 'expected' => array(2), - ), - 'IN_format_1_later' => array( - 'form_values' => array( - 'membership_type_id' => array('IN' => array(2, 1)), - 'membership_status_id' => array('IN' => array(2, 1)), - ), - 'expected' => array(2, 1), - ), - ); + return [ + 'checkbox_format_1_first' => [ + 'form_values' => [ + 'member_membership_type_id' => [1 => 1, 2 => 1], + 'member_status_id' => [1 => 1, 2 => 1], + ], + 'expected' => [1, 2], + ], + 'checkbox_format_1_later' => [ + 'form_values' => [ + 'member_membership_type_id' => [2 => 1, 1 => 1], + 'member_status_id' => [2 => 1, 1 => 1], + ], + 'expected' => [2, 1], + ], + 'checkbox_format_single_use_1' => [ + 'form_values' => [ + 'member_membership_type_id' => [1 => 1], + 'member_status_id' => [1 => 1], + ], + 'expected' => [1], + ], + 'checkbox_format_single_not_1' => [ + 'form_values' => [ + 'member_membership_type_id' => [2 => 1], + 'member_status_id' => [2 => 1], + ], + 'expected' => [2], + ], + 'array_format' => [ + 'form_values' => [ + 'member_membership_type_id' => [1, 2], + 'member_status_id' => [1, 2], + ], + 'expected' => [1, 2], + ], + 'array_format_1_later' => [ + 'form_values' => [ + 'member_membership_type_id' => [2, 1], + 'member_status_id' => [2, 1], + ], + 'expected' => [2, 1], + ], + 'array_format_single_use_1' => [ + 'form_values' => [ + 'member_membership_type_id' => [1], + 'member_status_id' => [1], + ], + 'expected' => [1], + ], + 'array_format_single_not_1' => [ + 'form_values' => [ + 'member_membership_type_id' => [2], + 'member_status_id' => [2], + ], + 'expected' => [2], + ], + 'IN_format_single_not_1' => [ + 'form_values' => [ + 'membership_type_id' => ['IN' => [2]], + 'membership_status_id' => ['IN' => [2]], + ], + 'expected' => [2], + ], + 'IN_format_1_later' => [ + 'form_values' => [ + 'membership_type_id' => ['IN' => [2, 1]], + 'membership_status_id' => ['IN' => [2, 1]], + ], + 'expected' => [2, 1], + ], + ]; } } diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/FullTextTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/FullTextTest.php index 4bff5fb7f9..d13b710dbc 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/FullTextTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/FullTextTest.php @@ -29,9 +29,9 @@ class CRM_Contact_Form_Search_Custom_FullTextTest extends CiviUnitTestCase { /** * @var array */ - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_acl_contact_cache', - ); + ]; /** * Test ACL contacts are filtered properly. @@ -42,26 +42,26 @@ class CRM_Contact_Form_Search_Custom_FullTextTest extends CiviUnitTestCase { $userId = $this->createLoggedInUser(); // remove all permissions $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array(); + $config->userPermissionClass->permissions = []; for ($i = 1; $i <= 10; $i++) { - $contactId = $this->individualCreate(array(), $i); + $contactId = $this->individualCreate([], $i); if ($i <= 5) { - $queryParams = array( - 1 => array($userId, 'Integer'), - 2 => array($contactId, 'Integer'), - ); + $queryParams = [ + 1 => [$userId, 'Integer'], + 2 => [$contactId, 'Integer'], + ]; CRM_Core_DAO::executeQuery("INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation ) VALUES(%1, %2, 'View')", $queryParams); } $contactIDs[$i] = $contactId; } - $formValues = array('component_mode' => 1, 'operator' => 1, 'is_unit_test' => 1); + $formValues = ['component_mode' => 1, 'operator' => 1, 'is_unit_test' => 1]; $fullText = new CRM_Contact_Form_Search_Custom_FullText($formValues); $fullText->initialize(); //Assert that ACL contacts are filtered. - $queryParams = array(1 => array($userId, 'Integer')); + $queryParams = [1 => [$userId, 'Integer']]; $whereClause = "WHERE NOT EXISTS (SELECT c.contact_id FROM civicrm_acl_contact_cache c WHERE c.user_id = %1 AND t.contact_id = c.contact_id )"; diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php index bd10b66d8a..e9b66a8e81 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php @@ -55,7 +55,7 @@ * @group headless */ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_group_contact', 'civicrm_group', 'civicrm_saved_search', @@ -64,7 +64,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { 'civicrm_contact', 'civicrm_option_value', 'civicrm_option_group', - ); + ]; /** * @return CRM_Contact_Form_Search_Custom_GroupTestDataProvider @@ -126,13 +126,13 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { $sql = $obj->all(); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); - $all = array(); + $all = []; while ($dao->fetch()) { - $all[] = array( + $all[] = [ 'contact_id' => $dao->contact_id, 'contact_type' => $dao->contact_type, 'sort_name' => $dao->sort_name, - ); + ]; } asort($all); $this->assertEquals($full, $all); @@ -157,7 +157,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); - $contacts = array(); + $contacts = []; while ($dao->fetch()) { $contacts[$dao->contact_id] = 1; } @@ -171,7 +171,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * It returns an array of translated name => keys */ public function testColumns() { - $formValues = array(); + $formValues = []; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $columns = $obj->columns(); $this->assertTrue(is_array($columns)); @@ -193,7 +193,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * It returns NULL */ public function testSummary() { - $formValues = array(); + $formValues = []; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $this->assertNull($obj->summary()); } @@ -203,7 +203,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * Returns the path to the file as a string */ public function testTemplateFile() { - $formValues = array(); + $formValues = []; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $fileName = $obj->templateFile(); $this->assertTrue(is_string($fileName)); @@ -216,10 +216,10 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * With no arguments it returns '(1)' */ public function testWhereNoArgs() { - $formValues = array( + $formValues = [ CRM_Core_Form::CB_PREFIX . '17' => TRUE, CRM_Core_Form::CB_PREFIX . '23' => TRUE, - ); + ]; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $this->assertEquals(' (1) ', $obj->where()); } @@ -229,10 +229,10 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * With false argument it returns '(1)' */ public function testWhereFalse() { - $formValues = array( + $formValues = [ CRM_Core_Form::CB_PREFIX . '17' => TRUE, CRM_Core_Form::CB_PREFIX . '23' => TRUE, - ); + ]; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $this->assertEquals(' (1) ', $obj->where(FALSE), 'In line ' . __LINE__ @@ -244,10 +244,10 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * With true argument it returns list of contact IDs */ public function testWhereTrue() { - $formValues = array( + $formValues = [ CRM_Core_Form::CB_PREFIX . '17' => TRUE, CRM_Core_Form::CB_PREFIX . '23' => TRUE, - ); + ]; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $this->assertEquals(' (1) AND contact_a.id IN ( 17, 23 )', $obj->where(TRUE), 'In line ' . __LINE__ diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTestDataProvider.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTestDataProvider.php index 8ce25c7a5c..9ae26807c1 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTestDataProvider.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTestDataProvider.php @@ -49,11 +49,11 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { * IDs should be selected when the form values are applied to the * database in dataset.xml */ - private $dataset = array( + private $dataset = [ // Exclude static group 3 - array( - 'fv' => array('excludeGroups' => array('3')), - 'id' => array( + [ + 'fv' => ['excludeGroups' => ['3']], + 'id' => [ '9', '10', '11', @@ -63,12 +63,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '15', '16', '26', - ), - ), + ], + ], // Include static group 3 - array( - 'fv' => array('includeGroups' => array('3')), - 'id' => array( + [ + 'fv' => ['includeGroups' => ['3']], + 'id' => [ '17', '18', '19', @@ -79,12 +79,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '24', '27', '28', - ), - ), + ], + ], // Include static group 5 - array( - 'fv' => array('includeGroups' => array('5')), - 'id' => array( + [ + 'fv' => ['includeGroups' => ['5']], + 'id' => [ '13', '14', '15', @@ -93,12 +93,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '22', '23', '24', - ), - ), + ], + ], // Include static groups 3 and 5 - array( - 'fv' => array('includeGroups' => array('3', '5')), - 'id' => array( + [ + 'fv' => ['includeGroups' => ['3', '5']], + 'id' => [ '13', '14', '15', @@ -113,20 +113,20 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '24', '27', '28', - ), - ), + ], + ], // Include static group 3, exclude static group 5 - array( - 'fv' => array( - 'includeGroups' => array('3'), - 'excludeGroups' => array('5'), - ), - 'id' => array('17', '18', '19', '20', '27', '28'), - ), + [ + 'fv' => [ + 'includeGroups' => ['3'], + 'excludeGroups' => ['5'], + ], + 'id' => ['17', '18', '19', '20', '27', '28'], + ], // Exclude tag 7 - array( - 'fv' => array('excludeTags' => array('7')), - 'id' => array( + [ + 'fv' => ['excludeTags' => ['7']], + 'id' => [ '9', '10', '13', @@ -136,12 +136,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '21', '22', '27', - ), - ), + ], + ], // Include tag 7 - array( - 'fv' => array('includeTags' => array('7')), - 'id' => array( + [ + 'fv' => ['includeTags' => ['7']], + 'id' => [ '11', '12', '15', @@ -152,12 +152,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '24', '26', '28', - ), - ), + ], + ], // Include tag 9 - array( - 'fv' => array('includeTags' => array('9')), - 'id' => array( + [ + 'fv' => ['includeTags' => ['9']], + 'id' => [ '10', '12', '14', @@ -166,12 +166,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '20', '22', '24', - ), - ), + ], + ], // Include tags 7 and 9 - array( - 'fv' => array('includeTags' => array('7', '9')), - 'id' => array( + [ + 'fv' => ['includeTags' => ['7', '9']], + 'id' => [ '10', '11', '12', @@ -186,24 +186,24 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '24', '26', '28', - ), - ), + ], + ], // Include tag 7, exclude tag 9 - array( - 'fv' => array( - 'includeTags' => array('7'), - 'excludeTags' => array('9'), - ), - 'id' => array('11', '15', '19', '23', '26', '28'), - ), + [ + 'fv' => [ + 'includeTags' => ['7'], + 'excludeTags' => ['9'], + ], + 'id' => ['11', '15', '19', '23', '26', '28'], + ], // Include static group 3, include tag 7 (either) - array( - 'fv' => array( - 'includeGroups' => array('3'), - 'includeTags' => array('7'), + [ + 'fv' => [ + 'includeGroups' => ['3'], + 'includeTags' => ['7'], 'andOr' => 0, - ), - 'id' => array( + ], + 'id' => [ '11', '12', '15', @@ -219,40 +219,40 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '26', '27', '28', - ), - ), + ], + ], // Include static group 3, include tag 7 (both) - array( - 'fv' => array( - 'includeGroups' => array('3'), - 'includeTags' => array('7'), + [ + 'fv' => [ + 'includeGroups' => ['3'], + 'includeTags' => ['7'], 'andOr' => 1, - ), - 'id' => array('19', '20', '23', '24', '28'), - ), + ], + 'id' => ['19', '20', '23', '24', '28'], + ], // Include static group 3, exclude tag 7 - array( - 'fv' => array( - 'includeGroups' => array('3'), - 'excludeTags' => array('7'), - ), - 'id' => array('17', '18', '21', '22', '27'), - ), + [ + 'fv' => [ + 'includeGroups' => ['3'], + 'excludeTags' => ['7'], + ], + 'id' => ['17', '18', '21', '22', '27'], + ], // Include tag 9, exclude static group 5 - array( - 'fv' => array( - 'includeTags' => array('9'), - 'excludeGroups' => array('5'), - ), - 'id' => array('10', '12', '18', '20'), - ), + [ + 'fv' => [ + 'includeTags' => ['9'], + 'excludeGroups' => ['5'], + ], + 'id' => ['10', '12', '18', '20'], + ], // Exclude tag 9, exclude static group 5 - array( - 'fv' => array( - 'excludeTags' => array('9'), - 'excludeGroups' => array('5'), - ), - 'id' => array( + [ + 'fv' => [ + 'excludeTags' => ['9'], + 'excludeGroups' => ['5'], + ], + 'id' => [ '9', '11', '17', @@ -260,12 +260,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '26', '27', '28', - ), - ), + ], + ], // Include smart group 6 - array( - 'fv' => array('includeGroups' => array('6')), - 'id' => array( + [ + 'fv' => ['includeGroups' => ['6']], + 'id' => [ '9', '10', '11', @@ -275,12 +275,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '15', '16', '26', - ), - ), + ], + ], // Include smart group 4 - array( - 'fv' => array('includeGroups' => array('4')), - 'id' => array( + [ + 'fv' => ['includeGroups' => ['4']], + 'id' => [ '17', '18', '19', @@ -291,12 +291,12 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '24', '27', '28', - ), - ), + ], + ], // Include smart group 4 and static group 5 - array( - 'fv' => array('includeGroups' => array('4', '5')), - 'id' => array( + [ + 'fv' => ['includeGroups' => ['4', '5']], + 'id' => [ '13', '14', '15', @@ -311,9 +311,9 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { '24', '27', '28', - ), - ), - ); + ], + ], + ]; public function _construct() { $this->i = 0; @@ -329,15 +329,15 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator { public function current() { $count = count($this->dataset[$this->i]['id']); $ids = $this->dataset[$this->i]['id']; - $full = array(); + $full = []; foreach ($this->dataset[$this->i]['id'] as $key => $value) { - $full[] = array( + $full[] = [ 'contact_id' => $value, 'contact_type' => 'Individual', 'sort_name' => "Test Contact $value", - ); + ]; } - return array($this->dataset[$this->i]['fv'], $count, $ids, $full); + return [$this->dataset[$this->i]['fv'], $count, $ids, $full]; } /** diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php index cedcff81e5..1131ade708 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php @@ -52,13 +52,13 @@ * @group headless */ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_address', 'civicrm_saved_search', 'civicrm_contact', 'civicrm_option_value', 'civicrm_option_group', - ); + ]; /** * @return CRM_Contact_Form_Search_Custom_SamplTestDataProvider @@ -112,13 +112,13 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { $sql = $obj->all(0, 0, 'contact_id'); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); - $all = array(); + $all = []; while ($dao->fetch()) { - $all[] = array( + $all[] = [ 'contact_id' => $dao->contact_id, 'contact_type' => $dao->contact_type, 'household_name' => $dao->sort_name, - ); + ]; } asort($all); $this->assertEquals($full, $all); @@ -142,7 +142,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); - $contacts = array(); + $contacts = []; while ($dao->fetch()) { $contacts[$dao->contact_id] = 1; } @@ -156,7 +156,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { * It returns an array of translated name => keys */ public function testColumns() { - $formValues = array(); + $formValues = []; $obj = new CRM_Contact_Form_Search_Custom_Sample($formValues); $columns = $obj->columns(); $this->assertTrue(is_array($columns)); @@ -178,7 +178,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { * It returns NULL */ public function testSummary() { - $formValues = array(); + $formValues = []; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $this->assertNull($obj->summary()); } @@ -188,7 +188,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { * Returns the path to the file as a string */ public function testTemplateFile() { - $formValues = array(); + $formValues = []; $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); $fileName = $obj->templateFile(); $this->assertTrue(is_string($fileName)); @@ -205,8 +205,8 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml'); - $dataset[1] = array('id' => array(12)); - $dataset[2] = array('id' => array(10, 11)); + $dataset[1] = ['id' => [12]]; + $dataset[2] = ['id' => [10, 11]]; $ssdao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_saved_search"); while ($ssdao->fetch()) { @@ -215,7 +215,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); - $contacts = array(); + $contacts = []; while ($dao->fetch()) { $contacts[] = $dao->contact_id; } diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php index d3fa7eecee..79edef1c77 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php @@ -45,40 +45,40 @@ class CRM_Contact_Form_Search_Custom_SampleTestDataProvider implements Iterator * IDs should be selected when the form values are applied to the * database in dataset.xml */ - private $dataset = array( + private $dataset = [ // Search by Household name: 'Household 9' - array( - 'fv' => array('household_name' => 'Household 9'), - 'id' => array( + [ + 'fv' => ['household_name' => 'Household 9'], + 'id' => [ '9', - ), - ), + ], + ], // Search by Household name: 'Household' - array( - 'fv' => array('household_name' => 'Household'), - 'id' => array( + [ + 'fv' => ['household_name' => 'Household'], + 'id' => [ '9', '10', '11', '12', - ), - ), + ], + ], // Search by State: California - array( - 'fv' => array('state_province_id' => '1004'), - 'id' => array( + [ + 'fv' => ['state_province_id' => '1004'], + 'id' => [ '10', '11', - ), - ), + ], + ], // Search by State: New York - array( - 'fv' => array('state_province_id' => '1031'), - 'id' => array( + [ + 'fv' => ['state_province_id' => '1031'], + 'id' => [ '12', - ), - ), - ); + ], + ], + ]; public function _construct() { $this->i = 0; @@ -94,15 +94,15 @@ class CRM_Contact_Form_Search_Custom_SampleTestDataProvider implements Iterator public function current() { $count = count($this->dataset[$this->i]['id']); $ids = $this->dataset[$this->i]['id']; - $full = array(); + $full = []; foreach ($this->dataset[$this->i]['id'] as $key => $value) { - $full[] = array( + $full[] = [ 'contact_id' => $value, 'contact_type' => 'Household', 'household_name' => "Household $value", - ); + ]; } - return array($this->dataset[$this->i]['fv'], $count, $ids, $full); + return [$this->dataset[$this->i]['fv'], $count, $ids, $full]; } /** diff --git a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php index e55974b5d5..24514ca535 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php @@ -32,14 +32,14 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); - $this->_contactIds = array( - $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')), - $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')), - ); - $this->_optionValue = $this->callApiSuccess('optionValue', 'create', array( + $this->_contactIds = [ + $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']), + $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']), + ]; + $this->_optionValue = $this->callApiSuccess('optionValue', 'create', [ 'label' => '"Seamus Lee" ', 'option_group_id' => 'from_email_address', - )); + ]); } /** @@ -48,9 +48,9 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { public function testDomainEmailGeneration() { $emails = CRM_Core_BAO_Email::domainEmails(); $this->assertNotEmpty($emails); - $optionValue = $this->callAPISuccess('OptionValue', 'Get', array( + $optionValue = $this->callAPISuccess('OptionValue', 'Get', [ 'id' => $this->_optionValue['id'], - )); + ]); $this->assertTrue(array_key_exists('"Seamus Lee" ', $emails)); $this->assertEquals('"Seamus Lee" ', $optionValue['values'][$this->_optionValue['id']]['label']); } @@ -64,9 +64,9 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { $form->controller = new CRM_Core_Controller(); for ($i = 0; $i < 27; $i++) { $email = 'spy' . $i . '@secretsquirrels.com'; - $contactID = $this->individualCreate(array('email' => $email)); + $contactID = $this->individualCreate(['email' => $email]); $form->_contactIds[$contactID] = $contactID; - $form->_toContactEmails[$this->callAPISuccessGetValue('Email', array('return' => 'id', 'email' => $email))] = $email; + $form->_toContactEmails[$this->callAPISuccessGetValue('Email', ['return' => 'id', 'email' => $email])] = $email; } $loggedInEmail = $this->callAPISuccess('Email', 'create', [ 'email' => 'mickey@mouse.com', @@ -77,17 +77,17 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { 'signature_html' => '

This is a test Signature

', ]); $form->_allContactIds = $form->_toContactIds = $form->_contactIds; - $form->_emails = array($loggedInEmail['id'] => 'mickey@mouse.com'); - $form->_fromEmails = array($loggedInEmail['id'] => 'mickey@mouse.com'); + $form->_emails = [$loggedInEmail['id'] => 'mickey@mouse.com']; + $form->_fromEmails = [$loggedInEmail['id'] => 'mickey@mouse.com']; CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($form); CRM_Contact_Form_Task_EmailCommon::buildQuickForm($form); CRM_Contact_Form_Task_EmailCommon::submit($form, array_merge($form->_defaultValues, [ 'from_email_address' => $loggedInEmail['id'], 'subject' => 'Really interesting stuff', ])); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'This is a test Signature', - )); + ]); $mut->stop(); Civi::settings()->set('allow_mail_from_logged_in_contact', 0); } diff --git a/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php b/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php index 3d8e65cd5c..d04fc9e053 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php @@ -37,10 +37,10 @@ class CRM_Contact_Form_Task_PrintDocumentTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); - $this->_contactIds = array( - $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')), - $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')), - ); + $this->_contactIds = [ + $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']), + $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']), + ]; $this->_docTypes = CRM_Core_SelectValues::documentApplicationType(); } @@ -48,13 +48,13 @@ class CRM_Contact_Form_Task_PrintDocumentTest extends CiviUnitTestCase { * Test the documents got token replaced rightfully. */ public function testPrintDocument() { - foreach (array('docx', 'odt') as $docType) { - $formValues = array( - 'document_file' => array( + foreach (['docx', 'odt'] as $docType) { + $formValues = [ + 'document_file' => [ 'name' => __DIR__ . "/sample_documents/Template.$docType", 'type' => $this->_docTypes[$docType], - ), - ); + ], + ]; $this->_testDocumentContent($formValues, $docType); } } @@ -66,13 +66,13 @@ class CRM_Contact_Form_Task_PrintDocumentTest extends CiviUnitTestCase { * @param array $type */ public function _testDocumentContent($formValues, $type) { - $html = array(); + $html = []; $form = new CRM_Contact_Form_Task_PDFLetterCommon(); list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues); list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']); foreach ($this->_contactIds as $item => $contactId) { - $params = array('contact_id' => $contactId); + $params = ['contact_id' => $contactId]; list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, diff --git a/tests/phpunit/CRM/Contact/Import/Form/DataSourceTest.php b/tests/phpunit/CRM/Contact/Import/Form/DataSourceTest.php index 5eaaf73c16..43cd5b913d 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/DataSourceTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/DataSourceTest.php @@ -44,10 +44,10 @@ class CRM_Contact_Import_Form_DataSourceTest extends CiviUnitTestCase { * (Added in conjunction with fixed noting on mapping assignment). */ public function testBuildForm() { - $this->callAPISuccess('Mapping', 'create', array('name' => 'Well dressed ducks', 'mapping_type_id' => 'Import Contact')); + $this->callAPISuccess('Mapping', 'create', ['name' => 'Well dressed ducks', 'mapping_type_id' => 'Import Contact']); $form = $this->getFormObject('CRM_Contact_Import_Form_DataSource'); $form->buildQuickForm(); - $this->assertEquals(array(1 => 'Well dressed ducks'), CRM_Core_Smarty::singleton()->get_template_vars('savedMapping')); + $this->assertEquals([1 => 'Well dressed ducks'], CRM_Core_Smarty::singleton()->get_template_vars('savedMapping')); } } diff --git a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php index 933f2d4cf0..27b9b2f2fc 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php @@ -49,11 +49,11 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { * @param array $mapper * @param array $expecteds */ - public function testSubmit($params, $mapper, $expecteds = array()) { + public function testSubmit($params, $mapper, $expecteds = []) { CRM_Core_DAO::executeQuery("CREATE TABLE IF NOT EXISTS civicrm_import_job_xxx (`nada` text, `first_name` text, `last_name` text, `address` text) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); $form = $this->getFormObject('CRM_Contact_Import_Form_MapField'); $form->set('contactType', CRM_Import_Parser::CONTACT_INDIVIDUAL); - $form->_columnNames = array('nada', 'first_name', 'last_name', 'address'); + $form->_columnNames = ['nada', 'first_name', 'last_name', 'address']; $form->set('importTableName', 'civicrm_import_job_xxx'); $form->preProcess(); $form->submit($params, $mapper); @@ -61,7 +61,7 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { CRM_Core_DAO::executeQuery("DROP TABLE civicrm_import_job_xxx"); if (!empty($expecteds)) { foreach ($expecteds as $expected) { - $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], array('sequential' => 1))); + $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], ['sequential' => 1])); $this->assertEquals($expected['count'], $result['count']); if (isset($expected['result'])) { foreach ($expected['result'] as $key => $expectedValues) { @@ -72,7 +72,7 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { } } } - $this->quickCleanup(array('civicrm_mapping', 'civicrm_mapping_field')); + $this->quickCleanup(['civicrm_mapping', 'civicrm_mapping_field']); } /** @@ -81,48 +81,48 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { * @return array */ public function getSubmitData() { - return array( - 'basic_data' => array( - array( + return [ + 'basic_data' => [ + [ 'saveMappingName' => '', 'saveMappingDesc' => '', - ), - array( - 0 => array(0 => 'do_not_import'), - 1 => array(0 => 'first_name'), - 2 => array(0 => 'last_name'), - 3 => array(0 => 'street_address', 1 => 2), - ), - ), - 'save_mapping' => array( - array( + ], + [ + 0 => [0 => 'do_not_import'], + 1 => [0 => 'first_name'], + 2 => [0 => 'last_name'], + 3 => [0 => 'street_address', 1 => 2], + ], + ], + 'save_mapping' => [ + [ 'saveMappingName' => 'new mapping', 'saveMappingDesc' => 'save it', 'saveMapping' => 1, - ), - array( - 0 => array(0 => 'do_not_import'), - 1 => array(0 => 'first_name'), - 2 => array(0 => 'last_name'), - 3 => array(0 => 'street_address', 1 => 2), - ), - array( - array('entity' => 'mapping', 'count' => 1, 'values' => array('name' => 'new mapping')), - array( + ], + [ + 0 => [0 => 'do_not_import'], + 1 => [0 => 'first_name'], + 2 => [0 => 'last_name'], + 3 => [0 => 'street_address', 1 => 2], + ], + [ + ['entity' => 'mapping', 'count' => 1, 'values' => ['name' => 'new mapping']], + [ 'entity' => 'mapping_field', 'count' => 4, - 'values' => array(), - 'result' => array( - 0 => array('name' => '- do not import -'), - 1 => array('name' => 'First Name'), - 2 => array('name' => 'Last Name'), - 3 => array('name' => 'Street Address', 'location_type_id' => 2), - ), - ), - ), - ), - ); + 'values' => [], + 'result' => [ + 0 => ['name' => '- do not import -'], + 1 => ['name' => 'First Name'], + 2 => ['name' => 'Last Name'], + 3 => ['name' => 'Street Address', 'location_type_id' => 2], + ], + ], + ], + ], + ]; } /** @@ -137,7 +137,7 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { public function getFormObject($class, $formValues = [], $pageName = '') { $form = parent::getFormObject($class); $contactFields = CRM_Contact_BAO_Contact::importableFields(); - $fields = array(); + $fields = []; foreach ($contactFields as $name => $field) { $fields[$name] = $field['title']; } diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 783015fd97..d9f4c18c29 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -52,15 +52,15 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \Exception */ public function testImportParserWtihEmployeeOfRelationship() { - $this->organizationCreate(array( + $this->organizationCreate([ "organization_name" => "Agileware", "legal_name" => "Agileware", - )); - $contactImportValues = array( + ]); + $contactImportValues = [ "first_name" => "Alok", "last_name" => "Patel", "Employee of" => "Agileware", - ); + ]; $fields = array_keys($contactImportValues); $values = array_values($contactImportValues); @@ -69,30 +69,30 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $parser->init(); $this->mapRelationshipFields($fields, $parser->getAllFields()); - $parser = new CRM_Contact_Import_Parser_Contact($fields, [], [], [], array( + $parser = new CRM_Contact_Import_Parser_Contact($fields, [], [], [], [ NULL, NULL, $fields[2], - ), array( + ], [ NULL, NULL, "Organization", - ), array( + ], [ NULL, NULL, "organization_name", - ), [], [], [], [], []); + ], [], [], [], [], []); $parser->_contactType = 'Individual'; $parser->_onDuplicate = CRM_Import_Parser::DUPLICATE_UPDATE; $parser->init(); $this->assertEquals(CRM_Import_Parser::VALID, $parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), 'Return code from parser import was not as expected'); - $this->callAPISuccess("Contact", "get", array( + $this->callAPISuccess("Contact", "get", [ "first_name" => "Alok", "last_name" => "Patel", "organization_name" => "Agileware", - )); + ]); } /** @@ -101,17 +101,17 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \Exception */ public function testImportParserWtihDeletedContactExternalIdentifier() { - $contactId = $this->individualCreate(array( + $contactId = $this->individualCreate([ "external_identifier" => "ext-1", - )); + ]); CRM_Contact_BAO_Contact::deleteContact($contactId); - list($originalValues, $result) = $this->setUpBaseContact(array( + list($originalValues, $result) = $this->setUpBaseContact([ 'external_identifier' => 'ext-1', - )); + ]); $originalValues['nick_name'] = 'Old Bill'; $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; - $this->assertEquals('ext-1', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'external_identifier'))); + $this->assertEquals('ext-1', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'external_identifier'])); $this->callAPISuccessGetSingle('Contact', $originalValues); } @@ -127,7 +127,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $originalValues['nick_name'] = 'Old Bill'; $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; - $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name'))); + $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name'])); $this->callAPISuccessGetSingle('Contact', $originalValues); } @@ -139,7 +139,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \Exception */ public function testImportParserWithUpdateWithExternalIdentifier() { - list($originalValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows')); + list($originalValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']); $this->assertEquals($result['id'], CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', 'windows', 'id', 'external_identifier', TRUE)); $this->assertEquals('windows', $result['external_identifier']); @@ -148,7 +148,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; - $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name'))); + $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name'])); $this->callAPISuccessGetSingle('Contact', $originalValues); } @@ -173,7 +173,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; - $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name'))); + $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name'])); $this->callAPISuccessGetSingle('Contact', $originalValues); } @@ -187,10 +187,10 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \Exception */ public function testImportParserWithUpdateWithContactID() { - list($originalValues, $result) = $this->setUpBaseContact(array( + list($originalValues, $result) = $this->setUpBaseContact([ 'external_identifier' => '', 'email' => NULL, - )); + ]); $updateValues = ['id' => $result['id'], 'email' => 'bill@example.com']; // This is some deep weirdness - this sets a flag for updatingBlankLocinfo - allowing input to be blanked // (which IS a good thing but it's pretty weird & all to do with legacy profile stuff). @@ -212,7 +212,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $originalValues['external_identifier'] = 'windows'; $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; - $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name'))); + $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name'])); $this->callAPISuccessGetSingle('Contact', $originalValues); } @@ -222,13 +222,13 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \Exception */ public function testImportParserWithUpdateWithChangedExternalIdentifier() { - list($contactValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows')); + list($contactValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']); $contact_id = $result['id']; $contactValues['nick_name'] = 'Old Bill'; $contactValues['external_identifier'] = 'android'; $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $contactValues['id'] = $contact_id; - $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $contact_id, 'return' => 'nick_name'))); + $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $contact_id, 'return' => 'nick_name'])); $this->callAPISuccessGetSingle('Contact', $contactValues); } @@ -243,15 +243,15 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $contactValues['external_identifier'] = 'android'; $contactValues['street_address'] = 'Big Mansion'; $contactValues['phone'] = '911'; - $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 2, 6 => 2)); - $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion')); + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 2, 6 => 2]); + $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']); $this->assertEquals(2, $address['location_type_id']); - $phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '911')); + $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '911']); $this->assertEquals(2, $phone['location_type_id']); $contact = $this->callAPISuccessGetSingle('Contact', $contactValues); - $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id'])); + $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]); } /** @@ -265,18 +265,18 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $contactValues['external_identifier'] = 'android'; $contactValues['street_address'] = 'Big Mansion'; $contactValues['phone'] = 12334; - $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary')); - $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion')); + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary']); + $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']); $this->assertEquals(1, $address['location_type_id']); $this->assertEquals(1, $address['is_primary']); - $phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '12334')); + $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '12334']); $this->assertEquals(1, $phone['location_type_id']); - $this->callAPISuccessGetSingle('Email', array('email' => 'bill.gates@microsoft.com')); + $this->callAPISuccessGetSingle('Email', ['email' => 'bill.gates@microsoft.com']); $contact = $this->callAPISuccessGetSingle('Contact', $contactValues); - $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id'])); + $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]); } /** @@ -290,7 +290,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $contactValues['external_identifier'] = 'android'; $contactValues['street_address'] = 'Big Mansion'; $contactValues['custom_' . $ids['custom_field_id']] = 'Update'; - $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary')); + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary']); $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion', 'return' => 'custom_' . $ids['custom_field_id']]); $this->assertEquals('Update', $address['custom_' . $ids['custom_field_id']]); } @@ -310,7 +310,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->assertEquals('1910-12-17', $contact['birth_date']); $this->assertEquals('2010-12-17', $contact['deceased_date']); $this->assertEquals(1, $contact['is_deceased']); - $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id'])); + $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]); } /** @@ -329,9 +329,9 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $contactValues['phone_2'] = 4444; $fields[] = 'street_address'; $fields[] = 'phone'; - $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 3, 8 => 3), $fields); - $contact = $this->callAPISuccessGetSingle('Contact', array('external_identifier' => 'android')); - $address = $this->callAPISuccess('Address', 'get', array('contact_id' => $contact['id'], 'sequential' => 1)); + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 3, 8 => 3], $fields); + $contact = $this->callAPISuccessGetSingle('Contact', ['external_identifier' => 'android']); + $address = $this->callAPISuccess('Address', 'get', ['contact_id' => $contact['id'], 'sequential' => 1]); $this->assertEquals(3, $address['values'][0]['location_type_id']); $this->assertEquals(0, $address['values'][0]['is_primary']); @@ -341,7 +341,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->assertEquals(1, $address['values'][1]['is_primary']); $this->assertEquals('Big Mansion', $address['values'][1]['street_address']); - $phone = $this->callAPISuccess('Phone', 'get', array('contact_id' => $contact['id'], 'sequential' => 1)); + $phone = $this->callAPISuccess('Phone', 'get', ['contact_id' => $contact['id'], 'sequential' => 1]); $this->assertEquals(1, $phone['values'][0]['location_type_id']); $this->assertEquals(1, $phone['values'][0]['is_primary']); $this->assertEquals(12334, $phone['values'][0]['phone']); @@ -349,7 +349,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->assertEquals(0, $phone['values'][1]['is_primary']); $this->assertEquals(4444, $phone['values'][1]['phone']); - $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id'])); + $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]); } /** @@ -368,9 +368,9 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $contactValues['phone_2'] = 4444; $fields[] = 'street_address'; $fields[] = 'phone'; - $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 3, 6 => 3, 7 => 'Primary', 8 => 'Primary'), $fields); - $contact = $this->callAPISuccessGetSingle('Contact', array('external_identifier' => 'android')); - $address = $this->callAPISuccess('Address', 'get', array('contact_id' => $contact['id'], 'sequential' => 1))['values']; + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 3, 6 => 3, 7 => 'Primary', 8 => 'Primary'], $fields); + $contact = $this->callAPISuccessGetSingle('Contact', ['external_identifier' => 'android']); + $address = $this->callAPISuccess('Address', 'get', ['contact_id' => $contact['id'], 'sequential' => 1])['values']; $this->assertEquals(1, $address[1]['location_type_id']); $this->assertEquals(1, $address[1]['is_primary']); @@ -388,7 +388,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->assertEquals(1, $phone[0]['is_primary']); $this->assertEquals(4444, $phone[0]['phone']); - $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id'])); + $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]); } /** @@ -397,21 +397,21 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \Exception */ public function testImportPrimaryAddressUpdate() { - list($contactValues) = $this->setUpBaseContact(array('external_identifier' => 'android')); + list($contactValues) = $this->setUpBaseContact(['external_identifier' => 'android']); $contactValues['email'] = 'melinda.gates@microsoft.com'; $contactValues['phone'] = '98765'; $contactValues['external_identifier'] = 'android'; $contactValues['street_address'] = 'Big Mansion'; $contactValues['city'] = 'Big City'; - $contactID = $this->callAPISuccessGetValue('Contact', array('external_identifier' => 'android', 'return' => 'id')); - $originalAddress = $this->callAPISuccess('Address', 'create', array('location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID)); - $originalPhone = $this->callAPISuccess('phone', 'create', array('location_type_id' => 2, 'phone' => '1234', 'contact_id' => $contactID)); - $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 'Primary')); + $contactID = $this->callAPISuccessGetValue('Contact', ['external_identifier' => 'android', 'return' => 'id']); + $originalAddress = $this->callAPISuccess('Address', 'create', ['location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID]); + $originalPhone = $this->callAPISuccess('phone', 'create', ['location_type_id' => 2, 'phone' => '1234', 'contact_id' => $contactID]); + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 'Primary']); $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '98765']); $this->assertEquals(2, $phone['location_type_id']); $this->assertEquals($originalPhone['id'], $phone['id']); $email = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $contactID]); - $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion')); + $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']); $this->assertEquals(2, $address['location_type_id']); $this->assertEquals($originalAddress['id'], $address['id']); $this->assertEquals('Big City', $address['city']); @@ -422,17 +422,17 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * Test the determination of whether a custom field is valid. */ public function testCustomFieldValidation() { - $errorMessage = array(); - $customGroup = $this->customGroupCreate(array( + $errorMessage = []; + $customGroup = $this->customGroupCreate([ 'extends' => 'Contact', 'title' => 'ABC', - )); - $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', array('html_type' => 'Multi-Select')); - $params = array( + ]); + $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', ['html_type' => 'Multi-Select']); + $params = [ 'custom_' . $customField['id'] => 'Label1|Label2', - ); + ]; CRM_Contact_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage); - $this->assertEquals(array(), $errorMessage); + $this->assertEquals([], $errorMessage); } /** @@ -444,40 +444,40 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { public function testImportFill() { // Create a custom field group for testing. $custom_group_name = 'importFillGroup'; - $results = $this->callAPISuccess('customGroup', 'get', array('title' => $custom_group_name)); + $results = $this->callAPISuccess('customGroup', 'get', ['title' => $custom_group_name]); if ($results['count'] == 0) { - $api_params = array( + $api_params = [ 'title' => $custom_group_name, 'extends' => 'Individual', 'is_active' => TRUE, - ); + ]; $customGroup = $this->callAPISuccess('customGroup', 'create', $api_params); } // Add two custom fields. - $api_params = array( + $api_params = [ 'custom_group_id' => $customGroup['id'], 'label' => 'importFillField1', 'html_type' => 'Select', 'data_type' => 'String', - 'option_values' => array( + 'option_values' => [ 'foo' => 'Foo', 'bar' => 'Bar', - ), - ); + ], + ]; $result = $this->callAPISuccess('custom_field', 'create', $api_params); $customField1 = $result['id']; - $api_params = array( + $api_params = [ 'custom_group_id' => $customGroup['id'], 'label' => 'importFillField2', 'html_type' => 'Select', 'data_type' => 'String', - 'option_values' => array( + 'option_values' => [ 'baz' => 'Baz', 'boo' => 'Boo', - ), - ); + ], + ]; $result = $this->callAPISuccess('custom_field', 'create', $api_params); $customField2 = $result['id']; @@ -495,42 +495,42 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { // Create contact with both one known core field and one custom // field filled in. - $api_params = array( + $api_params = [ 'contact_type' => 'Individual', 'email' => $original_email, 'gender' => $original_gender, 'custom_' . $customField1 => $original_custom1, - ); + ]; $result = $this->callAPISuccess('contact', 'create', $api_params); $contact_id = $result['id']; // Run an import. - $import = array( + $import = [ 'email' => $original_email, 'gender_id' => $import_gender, 'custom_' . $customField1 => $import_custom1, 'job_title' => $import_job_title, 'custom_' . $customField2 => $import_custom2, - ); + ]; $this->runImport($import, CRM_Import_Parser::DUPLICATE_FILL, CRM_Import_Parser::VALID); - $expected = array( + $expected = [ 'gender' => $original_gender, 'custom_' . $customField1 => $original_custom1, 'job_title' => $import_job_title, 'custom_' . $customField2 => $import_custom2, - ); + ]; - $params = array( + $params = [ 'id' => $contact_id, - 'return' => array( + 'return' => [ 'gender', 'custom_' . $customField1, 'job_title', 'custom_' . $customField2, - ), - ); + ], + ]; $result = civicrm_api3('Contact', 'get', $params); $values = array_pop($result['values']); foreach ($expected as $field => $expected_value) { @@ -555,19 +555,19 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { public function testImportAmbiguousStateCountry() { $this->callAPISuccess('Setting', 'create', ['defaultContactCountry' => 1228]); $countries = CRM_Core_PseudoConstant::country(FALSE, FALSE); - $this->callAPISuccess('Setting', 'create', array('countryLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)))); - $this->callAPISuccess('Setting', 'create', array('provinceLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)))); - $mapper = array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL); + $this->callAPISuccess('Setting', 'create', ['countryLimit' => [array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)]]); + $this->callAPISuccess('Setting', 'create', ['provinceLimit' => [array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)]]); + $mapper = [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL]; list($contactValues) = $this->setUpBaseContact(); $fields = array_keys($contactValues); - $addressValues = array( + $addressValues = [ 'street_address' => 'PO Box 2716', 'city' => 'Midway', 'state_province' => 'UT', 'postal_code' => 84049, 'country' => 'United States', - ); - $locationTypes = $this->callAPISuccess('Address', 'getoptions', array('field' => 'location_type_id')); + ]; + $locationTypes = $this->callAPISuccess('Address', 'getoptions', ['field' => 'location_type_id']); $locationTypes = $locationTypes['values']; foreach ($addressValues as $field => $value) { $contactValues['home_' . $field] = $value; @@ -580,7 +580,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $contactValues['work_country'] = ''; $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, $mapper, $fields); - $addresses = $this->callAPISuccess('Address', 'get', array('contact_id' => array('>' => 2), 'sequential' => 1)); + $addresses = $this->callAPISuccess('Address', 'get', ['contact_id' => ['>' => 2], 'sequential' => 1]); $this->assertEquals(2, $addresses['count']); $this->assertEquals(array_search('United States', $countries), $addresses['values'][0]['country_id']); $this->assertEquals(array_search('United States', $countries), $addresses['values'][1]['country_id']); @@ -633,16 +633,16 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @return array * @throws \Exception */ - protected function setUpBaseContact($params = array()) { - $originalValues = array_merge(array( + protected function setUpBaseContact($params = []) { + $originalValues = array_merge([ 'first_name' => 'Bill', 'last_name' => 'Gates', 'email' => 'bill.gates@microsoft.com', 'nick_name' => 'Billy-boy', - ), $params); + ], $params); $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $result = $this->callAPISuccessGetSingle('Contact', $originalValues); - return array($originalValues, $result); + return [$originalValues, $result]; } } diff --git a/tests/phpunit/CRM/Contact/Page/AjaxTest.php b/tests/phpunit/CRM/Contact/Page/AjaxTest.php index bbcfbd22b8..be18ecdf30 100644 --- a/tests/phpunit/CRM/Contact/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Contact/Page/AjaxTest.php @@ -31,19 +31,19 @@ class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase { public function testGetDedupes() { $_REQUEST['gid'] = 1; $_REQUEST['rgid'] = 1; - $_REQUEST['columns'] = array( - array( - 'search' => array( - 'value' => array( + $_REQUEST['columns'] = [ + [ + 'search' => [ + 'value' => [ 'src' => 'first_name', - ), - ), + ], + ], 'data' => 'src', - ), - ); + ], + ]; $_REQUEST['is_unit_test'] = TRUE; $result = CRM_Contact_Page_AJAX::getDedupes(); - $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result); + $this->assertEquals(['data' => [], 'recordsTotal' => 0, 'recordsFiltered' => 0], $result); } /** @@ -67,167 +67,167 @@ class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['rgid'] = 1; $_REQUEST['snippet'] = 4; $_REQUEST['draw'] = 3; - $_REQUEST['columns'] = array( - 0 => array( + $_REQUEST['columns'] = [ + 0 => [ 'data' => 'is_selected_input', 'name' => '', 'searchable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 1 => array( + 1 => [ 'data' => 'src_image', 'name' => '', 'searchable' => TRUE, 'orderable' => FALSE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 2 => array( + 2 => [ 'data' => 'src', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 3 => array( + 3 => [ 'data' => 'dst_image', 'name' => '', 'searchable' => TRUE, 'orderable' => FALSE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 4 => array( + 4 => [ 'data' => 'dst', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 5 => array( + 5 => [ 'data' => 'src_email', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 6 => array( + 6 => [ 'data' => 'dst_email', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 7 => array( + 7 => [ 'data' => 'src_street', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 8 => array( + 8 => [ 'data' => 'dst_street', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 9 => array( + 9 => [ 'data' => 'src_postcode', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => 123, 'regex' => FALSE, - ), - ), + ], + ], - 10 => array( + 10 => [ 'data' => 'dst_postcode', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 11 => array( + 11 => [ 'data' => 'conflicts', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 12 => array( + 12 => [ 'data' => 'weight', 'name' => '', 'searchable' => TRUE, 'orderable' => TRUE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), + ], + ], - 13 => array( + 13 => [ 'data' => 'actions', 'name' => '', 'searchable' => TRUE, 'orderable' => FALSE, - 'search' => array( + 'search' => [ 'value' => '', 'regex' => FALSE, - ), - ), - ); + ], + ], + ]; $_REQUEST['start'] = 0; $_REQUEST['length'] = 10; - $_REQUEST['search'] = array( + $_REQUEST['search'] = [ 'value' => '', 'regex' => FALSE, - ); + ]; $_REQUEST['_'] = 1466478641007; $_REQUEST['Drupal_toolbar_collapsed'] = 0; @@ -237,59 +237,59 @@ class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['is_unit_test'] = TRUE; $result = CRM_Contact_Page_AJAX::getDedupes(); - $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result); + $this->assertEquals(['data' => [], 'recordsTotal' => 0, 'recordsFiltered' => 0], $result); } /** * CRM-20621 : Test to check usage count of Tag tree */ public function testGetTagTree() { - $contacts = array(); + $contacts = []; // create three contacts for ($i = 0; $i < 3; $i++) { $contacts[] = $this->individualCreate(); } // Create Tag called as 'Parent Tag' - $parentTag = $this->tagCreate(array( + $parentTag = $this->tagCreate([ 'name' => 'Parent Tag', 'used_for' => 'civicrm_contact', - )); + ]); //assign first contact to parent tag - $params = array( + $params = [ 'entity_id' => $contacts[0], 'entity_table' => 'civicrm_contact', 'tag_id' => $parentTag['id'], - ); + ]; // TODO: EntityTag.create API is not working CRM_Core_BAO_EntityTag::add($params); // Create child Tag of $parentTag - $childTag1 = $this->tagCreate(array( + $childTag1 = $this->tagCreate([ 'name' => 'Child Tag Level 1', 'parent_id' => $parentTag['id'], 'used_for' => 'civicrm_contact', - )); + ]); //assign contact to this level 1 child tag - $params = array( + $params = [ 'entity_id' => $contacts[1], 'entity_table' => 'civicrm_contact', 'tag_id' => $childTag1['id'], - ); + ]; CRM_Core_BAO_EntityTag::add($params); // Create child Tag of $childTag1 - $childTag2 = $this->tagCreate(array( + $childTag2 = $this->tagCreate([ 'name' => 'Child Tag Level 2', 'parent_id' => $childTag1['id'], 'used_for' => 'civicrm_contact', - )); + ]); //assign contact to this level 2 child tag - $params = array( + $params = [ 'entity_id' => $contacts[2], 'entity_table' => 'civicrm_contact', 'tag_id' => $childTag2['id'], - ); + ]; CRM_Core_BAO_EntityTag::add($params); // CASE I : check the usage count of parent tag which need to be 1 @@ -319,23 +319,23 @@ class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase { unset($_GET['parent_id']); $_GET['str'] = 'Level'; $tagIDs = CRM_Admin_Page_AJAX::getTagTree(); - $expectedTagIDs = array($parentTag['id'], $childTag1['id'], $childTag2['id']); + $expectedTagIDs = [$parentTag['id'], $childTag1['id'], $childTag2['id']]; $this->checkArrayEquals($tagIDs, $expectedTagIDs); // CASE 4 : check the tag IDs returned on searching with 'Level 1' // which needs to array('parent tag id', 'level 1 child tag id') $_GET['str'] = 'Level 1'; $tagIDs = CRM_Admin_Page_AJAX::getTagTree(); - $expectedTagIDs = array($parentTag['id'], $childTag1['id']); + $expectedTagIDs = [$parentTag['id'], $childTag1['id']]; $this->checkArrayEquals($tagIDs, $expectedTagIDs); //cleanup foreach ($contacts as $id) { - $this->callAPISuccess('Contact', 'delete', array('id' => $id)); + $this->callAPISuccess('Contact', 'delete', ['id' => $id]); } - $this->callAPISuccess('Tag', 'delete', array('id' => $childTag2['id'])); - $this->callAPISuccess('Tag', 'delete', array('id' => $childTag1['id'])); - $this->callAPISuccess('Tag', 'delete', array('id' => $parentTag['id'])); + $this->callAPISuccess('Tag', 'delete', ['id' => $childTag2['id']]); + $this->callAPISuccess('Tag', 'delete', ['id' => $childTag1['id']]); + $this->callAPISuccess('Tag', 'delete', ['id' => $parentTag['id']]); } /** @@ -344,25 +344,25 @@ class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase { public function testContactReference() { //create group $groupId1 = $this->groupCreate(); - $groupId2 = $this->groupCreate(array( + $groupId2 = $this->groupCreate([ 'name' => 'Test Group 2', 'domain_id' => 1, 'title' => 'New Test Group2 Created', 'description' => 'New Test Group2 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only', - )); + ]); - $contactIds = array(); - foreach (array($groupId1, $groupId2) as $groupId) { + $contactIds = []; + foreach ([$groupId1, $groupId2] as $groupId) { $this->groupContactCreate($groupId); $contactIds = array_merge($contactIds, CRM_Contact_BAO_Group::getGroupContacts($groupId)); } $contactIds = CRM_Utils_Array::collect('contact_id', $contactIds); // create custom group with contact reference field - $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group')); - $params = array( + $customGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'select_test_group']); + $params = [ 'custom_group_id' => $customGroup['id'], 'name' => 'Worker_Lookup', 'label' => 'Worker Lookup', @@ -373,13 +373,13 @@ class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase { 'weight' => 4, 'is_searchable' => 1, 'is_active' => 1, - ); + ]; $customField = $this->callAPISuccess('custom_field', 'create', $params); - $_GET = array( + $_GET = [ 'id' => $customField['id'], 'is_unit_test' => TRUE, - ); + ]; $contactList = CRM_Contact_Page_AJAX::contactReference(); $contactList = CRM_Utils_Array::collect('id', $contactList); diff --git a/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php b/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php index c67b49bcf4..28ab4297fc 100644 --- a/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php +++ b/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php @@ -59,14 +59,14 @@ class CRM_Contact_Page_DedupeExceptionTest extends CiviUnitTestCase { ]); $page = new CRM_Contact_Page_DedupeException(); $totalitems = civicrm_api3('Exception', "getcount", []); - $params = array( + $params = [ 'total' => $totalitems, 'rowCount' => CRM_Utils_Pager::ROWCOUNT, 'status' => ts('Dedupe Exceptions %%StatusMessage%%'), 'buttonBottom' => 'PagerBottomButton', 'buttonTop' => 'PagerTopButton', 'pageID' => $page->get(CRM_Utils_Pager::PAGE_ID), - ); + ]; $page->_pager = new CRM_Utils_Pager($params); $exceptions = $page->getExceptions(); $expectedArray = [ diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashboard/GroupContactTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashboard/GroupContactTest.php index 90e27f4cbb..9c3acf9b12 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashboard/GroupContactTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashboard/GroupContactTest.php @@ -57,60 +57,60 @@ class CRM_Contact_Page_View_UserDashboard_GroupContactTest extends CiviUnitTestC public function testBrowseDisplaysCorrectListOfAddedGroups() { // create admin-only non-smart group $adminStdGroupTitle = 'The Admin-only Std Group'; - $adminStdGroup = $this->callAPISuccess('Group', 'create', array( + $adminStdGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $adminStdGroupTitle, 'visibility' => 'User and User Admin Only', 'is_active' => 1, - )); + ]); // create public non-smart group $publicStdGroupTitle = 'The Public Std Group'; - $publicStdGroup = $this->callAPISuccess('Group', 'create', array( + $publicStdGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $publicStdGroupTitle, 'visibility' => 'Public Pages', 'is_active' => 1, - )); + ]); // Prepare to create smart groups based on saved criteria Gender = Male. // Start by creating the saved search. - $savedSearch = $this->callAPISuccess('SavedSearch', 'create', array( + $savedSearch = $this->callAPISuccess('SavedSearch', 'create', [ 'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}', - )); + ]); // Create contact with Gender - Male - $savedSearchContact = $this->individualCreate(array( + $savedSearchContact = $this->individualCreate([ 'gender_id' => "Male", 'first_name' => 'C', - ), 1); + ], 1); // Create admin-only smart group for this saved search. $adminSmartGroupTitle = 'The Admin-only Smart Group'; - $adminSmartGroup = $this->callAPISuccess('Group', 'create', array( + $adminSmartGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $adminSmartGroupTitle, 'visibility' => 'User and User Admin Only', 'saved_search_id' => $savedSearch['id'], 'is_active' => 1, - )); + ]); // Create public smart group for this saved search. $publicSmartGroupTitle = 'The Public Smart Group'; - $publicSmartGroup = $this->callAPISuccess('Group', 'create', array( + $publicSmartGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $publicSmartGroupTitle, 'visibility' => 'Public Pages', 'saved_search_id' => $savedSearch['id'], 'is_active' => 1, - )); + ]); // Get logged in user contact ID. $user_id = $this->createLoggedInUser(); $_REQUEST['id'] = $user_id; // Add current user to the test groups. - $publicSmartGroup = $this->callAPISuccess('Contact', 'create', array( + $publicSmartGroup = $this->callAPISuccess('Contact', 'create', [ 'id' => $user_id, - 'group' => array( + 'group' => [ $adminStdGroup['id'] => 1, $adminSmartGroup['id'] => 1, $publicStdGroup['id'] => 1, $publicSmartGroup['id'] => 1, - ), - )); + ], + ]); // Run the contact dashboard and assert that only the public groups appear // in the variables. @@ -133,52 +133,52 @@ class CRM_Contact_Page_View_UserDashboard_GroupContactTest extends CiviUnitTestC // create admin-only non-smart group $adminStdGroupTitle = 'The Admin-only Std Group' . uniqid(); - $adminStdGroup = $this->callAPISuccess('Group', 'create', array( + $adminStdGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $adminStdGroupTitle, 'visibility' => 'User and User Admin Only', 'is_active' => 1, - )); + ]); // create public non-smart group $publicStdGroupTitle = 'The Public Std Group' . uniqid(); - $publicStdGroup = $this->callAPISuccess('Group', 'create', array( + $publicStdGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $publicStdGroupTitle, 'visibility' => 'Public Pages', 'is_active' => 1, - )); + ]); // create second public non-smart group $publicStdGroupTitle2 = 'The 2nd Public Std Group' . uniqid(); - $publicStdGroup2 = $this->callAPISuccess('Group', 'create', array( + $publicStdGroup2 = $this->callAPISuccess('Group', 'create', [ 'title' => $publicStdGroupTitle2, 'visibility' => 'Public Pages', 'is_active' => 1, - )); + ]); // Prepare to create smart groups based on saved criteria Gender = Male. // Start by creating the saved search. - $savedSearch = $this->callAPISuccess('SavedSearch', 'create', array( + $savedSearch = $this->callAPISuccess('SavedSearch', 'create', [ 'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}', - )); + ]); // Create contact with Gender - Male - $savedSearchContact = $this->individualCreate(array( + $savedSearchContact = $this->individualCreate([ 'gender_id' => "Male", 'first_name' => 'C', - ), 1); + ], 1); // Create admin-only smart group for this saved search. $adminSmartGroupTitle = 'The Admin-only Smart Group' . uniqid(); - $adminSmartGroup = $this->callAPISuccess('Group', 'create', array( + $adminSmartGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $adminSmartGroupTitle, 'visibility' => 'User and User Admin Only', 'saved_search_id' => $savedSearch['id'], 'is_active' => 1, - )); + ]); // Create public smart group for this saved search. $publicSmartGroupTitle = 'The Public Smart Group' . uniqid(); - $publicSmartGroup = $this->callAPISuccess('Group', 'create', array( + $publicSmartGroup = $this->callAPISuccess('Group', 'create', [ 'title' => $publicSmartGroupTitle, 'visibility' => 'Public Pages', 'saved_search_id' => $savedSearch['id'], 'is_active' => 1, - )); + ]); // Get logged in user contact ID. $user_id = $this->createLoggedInUser(); @@ -197,15 +197,15 @@ class CRM_Contact_Page_View_UserDashboard_GroupContactTest extends CiviUnitTestC $this->assertNotContains($adminStdGroupTitle, $group_id_field_html, "Group '$adminStdGroupTitle' should not be in listed available groups, but is."); // Add current user to the test groups. - $publicSmartGroup = $this->callAPISuccess('Contact', 'create', array( + $publicSmartGroup = $this->callAPISuccess('Contact', 'create', [ 'id' => $user_id, - 'group' => array( + 'group' => [ $adminStdGroup['id'] => 1, $adminSmartGroup['id'] => 1, $publicStdGroup['id'] => 1, $publicSmartGroup['id'] => 1, - ), - )); + ], + ]); // Run the contact dashboard and assert that none of the groups appear // in select list of available groups. diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index dc8b4ac9d3..a21720b1b8 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -52,7 +52,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr * - subject: regex */ public function createTestCases() { - $cs = array(); + $cs = []; // FIXME: CRM-19415: The right email content goes out, but it appears that the dates are incorrect. // $cs[] = array( @@ -73,92 +73,92 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr // ), // ); - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientBob', - array(), - ); + [], + ]; - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientAlice', - array( - array( + [ + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('alice@example.org'), + 'to' => ['alice@example.org'], 'subject' => '/Hello, Alice.*via subject/', - ), - ), - ); + ], + ], + ]; - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', // 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstName', 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstNameStatus', - array( - array( + [ + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('alice@example.org'), + 'to' => ['alice@example.org'], 'subject' => '/Hello, Alice. @Completed.*via subject/', - ), - ), - ); + ], + ], + ]; - $cs[] = array( + $cs[] = [ '2015-02-01 00:00:00', 'addAliceDues addBobDonation scheduleForAny startOnTime useHelloFirstName', - array( - array( + [ + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('alice@example.org'), + 'to' => ['alice@example.org'], 'subject' => '/Hello, Alice.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-01 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - ), - ); + ], + ], + ]; - $cs[] = array( + $cs[] = [ '2015-02-02 00:00:00', 'addAliceDues addBobDonation scheduleForDonation startWeekBefore repeatTwoWeeksAfter useHelloFirstName', - array( - array( + [ + [ 'time' => '2015-01-26 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-02 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-09 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - array( + ], + [ 'time' => '2015-02-16 00:00:00', - 'to' => array('bob@example.org'), + 'to' => ['bob@example.org'], 'subject' => '/Hello, Bob.*via subject/', - ), - ), - ); + ], + ], + ]; - $cs[] = array( + $cs[] = [ '2015-02-03 00:00:00', 'addAliceDues addBobDonation scheduleForSoftCreditor startWeekAfter useHelloFirstName', - array( - array( + [ + [ 'time' => '2015-02-10 00:00:00', - 'to' => array('carol@example.org'), + 'to' => ['carol@example.org'], 'subject' => '/Hello, Carol.*via subject/', - ), - ), - ); + ], + ], + ]; return $cs; } @@ -167,7 +167,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr * Create a contribution record for Alice with type "Member Dues". */ public function addAliceDues() { - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $this->contacts['alice']['id'], 'receive_date' => date('Ymd', strtotime($this->targetDate)), 'total_amount' => '100', @@ -177,21 +177,21 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr 'net_amount' => '95', 'source' => 'SSF', 'contribution_status_id' => 1, - 'soft_credit' => array( - '1' => array( + 'soft_credit' => [ + '1' => [ 'contact_id' => $this->contacts['carol']['id'], 'amount' => 50, 'soft_credit_type_id' => 3, - ), - ), - )); + ], + ], + ]); } /** * Create a contribution record for Bob with type "Donation". */ public function addBobDonation() { - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $this->contacts['bob']['id'], 'receive_date' => date('Ymd', strtotime($this->targetDate)), 'total_amount' => '150', @@ -201,7 +201,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr 'net_amount' => '145', 'source' => 'SSF', 'contribution_status_id' => 2, - )); + ]); } /** @@ -210,8 +210,8 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr public function scheduleForDues() { $this->schedule->mapping_id = CRM_Contribute_ActionMapping_ByType::MAPPING_ID; $this->schedule->start_action_date = 'receive_date'; - $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(1)); - $this->schedule->entity_status = CRM_Utils_Array::implodePadded(array(1)); + $this->schedule->entity_value = CRM_Utils_Array::implodePadded([1]); + $this->schedule->entity_status = CRM_Utils_Array::implodePadded([1]); } /** @@ -220,7 +220,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr public function scheduleForDonation() { $this->schedule->mapping_id = CRM_Contribute_ActionMapping_ByType::MAPPING_ID; $this->schedule->start_action_date = 'receive_date'; - $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(2)); + $this->schedule->entity_value = CRM_Utils_Array::implodePadded([2]); $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL); } @@ -244,7 +244,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL); $this->schedule->limit_to = 1; $this->schedule->recipient = 'soft_credit_type'; - $this->schedule->recipient_listing = CRM_Utils_Array::implodePadded(array(3)); + $this->schedule->recipient_listing = CRM_Utils_Array::implodePadded([3]); } public function useHelloFirstNameStatus() { diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php index 3b6244b6de..fdfa401e4e 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php @@ -44,7 +44,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { */ public function testCreate() { - $params = array( + $params = [ 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e', 'title' => 'Test Contribution Page', 'financial_type_id' => $this->_financialTypeID, @@ -61,13 +61,13 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { 'end_date' => '19700101000000', 'end_date_time' => '', 'is_credit_card_only' => '', - ); + ]; $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params); $this->assertNotNull($contributionpage->id); $this->assertType('int', $contributionpage->id); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionpage->id)); + $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]); } /** @@ -75,18 +75,18 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { */ public function testsetIsActive() { - $params = array( + $params = [ 'title' => 'Test Contribution Page', 'financial_type_id' => $this->_financialTypeID, 'is_active' => 1, - ); + ]; $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params); $id = $contributionpage->id; $is_active = 1; $pageActive = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active); $this->assertEquals($pageActive, TRUE, 'Verify financial types record deletion.'); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionpage->id)); + $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]); } /** @@ -94,29 +94,29 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { */ public function testSetValues() { - $params = array( + $params = [ 'title' => 'Test Contribution Page', 'financial_type_id' => $this->_financialTypeID, 'is_active' => 1, - ); + ]; $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $id = $contributionPage->id; - $values = array(); + $values = []; CRM_Contribute_BAO_ContributionPage::setValues($id, $values); $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.'); $this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.'); $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.'); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionPage->id)); + $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]); } /** * Test copy() method */ public function testcopy() { - $params = array( + $params = [ 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e', 'title' => 'Test Contribution Page', 'financial_type_id' => $this->_financialTypeID, @@ -133,14 +133,14 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { 'end_date' => '19700101000000', 'end_date_time' => '', 'is_credit_card_only' => '', - ); + ]; $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id); $this->assertEquals($copyContributionPage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.'); $this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.'); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionPage->id)); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $copyContributionPage->id)); + $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]); + $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]); } } diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php index 5d82d4c0b8..0b120f16f4 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php @@ -30,12 +30,12 @@ * @group headless */ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { - protected $_params = array(); + protected $_params = []; public function setUp() { parent::setUp(); $this->_ids['payment_processor'] = $this->paymentProcessorCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->individualCreate(), 'amount' => 3.00, 'frequency_unit' => 'week', @@ -62,11 +62,11 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'payment_instrument_id' => 1, 'campaign_id' => NULL, - ); + ]; } public function teardown() { - $this->quickCleanup(array('civicrm_contribution_recur', 'civicrm_payment_processor')); + $this->quickCleanup(['civicrm_contribution_recur', 'civicrm_payment_processor']); } /** @@ -99,7 +99,7 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { */ public function testSupportFinancialTypeChange() { $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params); - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'contribution_recur_id' => $contributionRecur['id'], 'total_amount' => '3.00', 'financial_type_id' => 1, @@ -108,7 +108,7 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { 'contact_id' => $this->individualCreate(), 'contribution_status_id' => 1, 'receive_date' => 'yesterday', - )); + ]); $this->assertTrue(CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($contributionRecur['id'])); } @@ -119,10 +119,10 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { $createParams = $this->_params; $createParams['currency'] = 'XAU'; $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $createParams); - $editParams = array( + $editParams = [ 'id' => $contributionRecur['id'], 'end_date' => '+ 4 weeks', - ); + ]; $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $editParams); $dao = new CRM_Contribute_BAO_ContributionRecur(); $dao->id = $contributionRecur['id']; diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 33fb1b85b6..540f6fe9db 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -48,7 +48,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { public function testCreate() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -65,7 +65,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0]; @@ -90,20 +90,20 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $contactId = $this->individualCreate(); //create custom data - $customGroup = $this->customGroupCreate(array('extends' => 'Contribution')); + $customGroup = $this->customGroupCreate(['extends' => 'Contribution']); $customGroupID = $customGroup['id']; $customGroup = $customGroup['values'][$customGroupID]; - $fields = array( + $fields = [ 'label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', 'is_active' => 1, 'custom_group_id' => $customGroupID, - ); + ]; $customField = CRM_Core_BAO_CustomField::create($fields); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -121,11 +121,11 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', 'thankyou_date' => '20080522', 'skipCleanMoney' => TRUE, - ); + ]; - $params['custom'] = array( - $customField->id => array( - -1 => array( + $params['custom'] = [ + $customField->id => [ + -1 => [ 'value' => 'Test custom value', 'type' => 'String', 'custom_field_id' => $customField->id, @@ -133,17 +133,17 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'table_name' => $customGroup['table_name'], 'column_name' => $customField->column_name, 'file_id' => NULL, - ), - ), - ); + ], + ], + ]; $contribution = CRM_Contribute_BAO_Contribution::create($params); // Check that the custom field value is saved - $customValueParams = array( + $customValueParams = [ 'entityID' => $contribution->id, 'custom_' . $customField->id => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($customValueParams); $this->assertEquals('Test custom value', $values['custom_' . $customField->id], 'Check the custom field value'); @@ -156,13 +156,13 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { */ public function testContributionCountDisabledFinancialType() { $contactId = $this->individualCreate(); - $financialType = array( + $financialType = [ 'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7), 'is_reserved' => 0, 'is_active' => 0, - ); + ]; $finType = $this->callAPISuccess('financial_type', 'create', $financialType); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => $finType['id'], @@ -179,9 +179,9 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'trxn_id' => '22ereerwww322323', 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', 'thankyou_date' => '20080522', - ); + ]; $this->callAPISuccess('Contribution', 'create', $params); - $this->callAPISuccess('financial_type', 'create', array('is_active' => 0, 'id' => $finType['id'])); + $this->callAPISuccess('financial_type', 'create', ['is_active' => 0, 'id' => $finType['id']]); $contributionCount = CRM_Contribute_BAO_Contribution::contributionCount($contactId); $this->assertEquals(1, $contributionCount); } @@ -192,7 +192,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { public function testDeleteContribution() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -210,7 +210,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '33ed39c9e9ee6ef6031621ce0eafe6da70', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0]; @@ -237,13 +237,13 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $honoreeProfileId = $ufGroupDAO->id; } - $params = array( + $params = [ 'prefix_id' => 3, 'first_name' => $firstName, 'last_name' => $lastName, 'email-1' => $email, - ); - $softParam = array('soft_credit_type_id' => 1); + ]; + $softParam = ['soft_credit_type_id' => 1]; $null = []; $honoreeContactId = CRM_Contact_BAO_Contact::createProfileContact($params, $null, @@ -255,9 +255,9 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { ); //create contribution on behalf of honary. - $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe')); + $contactId = $this->individualCreate(['first_name' => 'John', 'last_name' => 'Doe']); - $param = array( + $param = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 4, @@ -265,7 +265,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'receive_date' => date('Ymd'), 'total_amount' => 66, 'sequential' => 1, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0]; $id = $contribution['id']; @@ -282,8 +282,8 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { ); //get honorary information $getHonorContact = CRM_Contribute_BAO_Contribution::getHonorContacts($honoreeContactId); - $this->assertEquals(array( - $id => array( + $this->assertEquals([ + $id => [ 'honor_type' => 'In Honor of', 'honorId' => $contactId, 'display_name' => 'Mr. John Doe II', @@ -293,8 +293,8 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'source' => NULL, 'receive_date' => date('Y-m-d 00:00:00'), 'contribution_status' => 'Completed', - ), - ), $getHonorContact); + ], + ], $getHonorContact); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $honoreeContactId, 'first_name', 'id', $firstName, 'Database check for created honor contact record.' @@ -361,7 +361,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { * Test that financial type data is not added to the annual query if acls not enabled. */ public function testAnnualQueryWithFinancialHook() { - $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'aclIdNoZero')); + $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'aclIdNoZero']); $sql = CRM_Contribute_BAO_Contribution::getAnnualQuery([1, 2, 3]); $this->assertContains('SUM(total_amount) as amount,', $sql); $this->assertContains('WHERE b.contact_id IN (1,2,3)', $sql); @@ -389,11 +389,11 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { * sortName(); */ public function testsortName() { - $params = array( + $params = [ 'first_name' => 'Shane', 'last_name' => 'Whatson', 'contact_type' => 'Individual', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); @@ -401,7 +401,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); $contactId = $contact->id; - $param = array( + $param = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -419,7 +419,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '22ed39c9e9ee621ce0eafe6da70', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0]; @@ -440,7 +440,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { public function testAddPremium() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'name' => 'TEST Premium', 'sku' => 111, 'imageOption' => 'noImage', @@ -449,12 +449,12 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'cost' => 90.00, 'min_contribution' => 100, 'is_active' => 1, - ); + ]; $premium = CRM_Contribute_BAO_Product::create($params); $this->assertEquals('TEST Premium', $premium->name, 'Check for premium name.'); - $contributionParams = array( + $contributionParams = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -472,19 +472,19 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '98ed34f7u9hh672ce0eafe8fb92', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams)['values'][0]; $this->assertEquals($contributionParams['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.'); $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.'); //parameter for adding premium to contribution - $data = array( + $data = [ 'product_id' => $premium->id, 'contribution_id' => $contribution['id'], 'product_option' => NULL, 'quantity' => 1, - ); + ]; $contributionProduct = CRM_Contribute_BAO_Contribution::addPremium($data); $this->assertEquals($contributionProduct->product_id, $premium->id, 'Check for Product id .'); @@ -503,7 +503,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { public function testcheckDuplicateIds() { $contactId = $this->individualCreate(); - $param = array( + $param = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -521,17 +521,17 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '93ed39a9e9hd621bs0eafe3da82', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0]; $this->assertEquals($param['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.'); $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.'); - $data = array( + $data = [ 'id' => $contribution['id'], 'trxn_id' => $contribution['trxn_id'], 'invoice_id' => $contribution['invoice_id'], - ); + ]; $contributionID = CRM_Contribute_BAO_Contribution::checkDuplicateIds($data); $this->assertEquals($contributionID, $contribution['id'], 'Check for duplicate transcation id .'); } @@ -544,7 +544,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { public function testCreateCreditNoteId() { $contactId = $this->individualCreate(); - $param = array( + $param = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -562,7 +562,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '93ed39a9e9hd621bs0eafe3da82', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId(); $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0]; @@ -599,11 +599,11 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.'); $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.'); - $trxnArray = array( + $trxnArray = [ 'trxn_id' => $params['trxn_id'], 'is_payment' => 1, - ); - $defaults = array(); + ]; + $defaults = []; $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults); $this->assertEquals(1, $financialTrxn->N, 'Mismatch count for is payment flag.'); //update contribution amount @@ -613,11 +613,11 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .'); $this->assertEquals($params['total_amount'], $contribution['total_amount'], 'Check for Amount updation.'); - $trxnArray = array( + $trxnArray = [ 'trxn_id' => $params['trxn_id'], 'is_payment' => 1, - ); - $defaults = array(); + ]; + $defaults = []; $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults); $this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.'); $trxnArray['is_payment'] = 0; @@ -631,7 +631,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { public function testIsPaymentFlagForPending() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -649,18 +649,18 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { 'invoice_id' => '86ed39c9e9yy6ef6541621ce0eafe7eb81', 'thankyou_date' => '20080522', 'sequential' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0]; $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transaction id creation.'); $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.'); - $trxnArray = array( + $trxnArray = [ 'trxn_id' => $params['trxn_id'], 'is_payment' => 0, - ); - $defaults = array(); + ]; + $defaults = []; $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults); $this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.'); $trxnArray['is_payment'] = 1; @@ -674,11 +674,11 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .'); $this->assertEquals($params['contribution_status_id'], $contribution['contribution_status_id'], 'Check for status updation.'); - $trxnArray = array( + $trxnArray = [ 'trxn_id' => $params['trxn_id'], 'is_payment' => 1, - ); - $defaults = array(); + ]; + $defaults = []; $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults); $this->assertEquals(1, $financialTrxn->N, 'Mismatch count for is payment flag.'); $trxnArray['is_payment'] = 0; @@ -704,11 +704,11 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { INNER JOIN civicrm_entity_financial_trxn eft1 ON (eft1.financial_trxn_id = eft.financial_trxn_id AND eft1.entity_table = 'civicrm_financial_item') WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; - $queryParams[1] = array($contribution->id, 'Integer'); - $queryParams[2] = array($toFinancialAccount, 'Integer'); + $queryParams[1] = [$contribution->id, 'Integer']; + $queryParams[2] = [$toFinancialAccount, 'Integer']; $dao = CRM_Core_DAO::executeQuery($query, $queryParams); - $amounts = array(100.00, 50.00); + $amounts = [100.00, 50.00]; while ($dao->fetch()) { $this->assertEquals(150.00, $dao->total_amount, 'Mismatch of total amount paid.'); $this->assertEquals($dao->amount, array_pop($amounts), 'Mismatch of amount proportionally assigned to financial item'); @@ -720,10 +720,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; */ public function testAssignProportionalLineItems() { list($lineItems, $contribution) = $this->addParticipantWithContribution(); - $params = array( + $params = [ 'contribution_id' => $contribution->id, 'total_amount' => 150.00, - ); + ]; $trxn = new CRM_Financial_DAO_FinancialTrxn(); $trxn->orderBy('id DESC'); $trxn->find(TRUE); @@ -754,43 +754,43 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset' ); - $paramsField = array( + $paramsField = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', - 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_value' => array('1' => 100, '2' => 200), - 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_weight' => array('1' => 1, '2' => 2), - 'option_amount' => array('1' => 100, '2' => 200), + 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_value' => ['1' => 100, '2' => 200], + 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_weight' => ['1' => 1, '2' => 2], + 'option_amount' => ['1' => 100, '2' => 200], 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, - 'is_active' => array('1' => 1, '2' => 1), + 'is_active' => ['1' => 1, '2' => 1], 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'), - ); + ]; $priceField = CRM_Price_BAO_PriceField::create($paramsField); - $eventParams = array( + $eventParams = [ 'id' => $this->_eventId, 'financial_type_id' => 4, 'is_monetary' => 1, - ); + ]; CRM_Event_BAO_Event::create($eventParams); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId); - $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); - $participantParams = array( + $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]); + $participantParams = [ 'financial_type_id' => 4, 'event_id' => $this->_eventId, 'role_id' => 1, 'status_id' => 14, 'fee_currency' => 'USD', 'contact_id' => $this->_contactId, - ); + ]; $participant = CRM_Event_BAO_Participant::add($participantParams); - $contributionParams = array( + $contributionParams = [ 'total_amount' => 150, 'currency' => 'USD', 'contact_id' => $this->_contactId, @@ -801,10 +801,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'contribution_mode' => 'participant', 'participant_id' => $participant->id, 'sequential' => TRUE, - ); + ]; foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[1][$key] = array( + $lineItems[1][$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -813,37 +813,37 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id'], - ); + ]; } $contributionParams['line_item'] = $lineItems; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams)['values'][0]; - $paymentParticipant = array( + $paymentParticipant = [ 'participant_id' => $participant->id, 'contribution_id' => $contribution['id'], - ); + ]; CRM_Event_BAO_ParticipantPayment::create($paymentParticipant); $contributionObject = new CRM_Contribute_BAO_Contribution(); $contributionObject->id = $contribution['id']; $contributionObject->find(TRUE); - return array($lineItems, $contributionObject); + return [$lineItems, $contributionObject]; } /** * checkLineItems() check if total amount matches the sum of line total */ public function testcheckLineItems() { - $params = array( + $params = [ 'contact_id' => 202, 'receive_date' => '2010-01-20', 'total_amount' => 100, 'financial_type_id' => 3, - 'line_items' => array( - array( - 'line_item' => array( - array( + 'line_items' => [ + [ + 'line_item' => [ + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 16, @@ -851,8 +851,8 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'qty' => 1, 'unit_price' => 100, 'line_total' => 100, - ), - array( + ], + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 17, @@ -861,12 +861,12 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'unit_price' => 200, 'line_total' => 200, 'financial_type_id' => 1, - ), - ), - 'params' => array(), - ), - ), - ); + ], + ], + 'params' => [], + ], + ], + ]; try { CRM_Contribute_BAO_Contribution::checkLineItems($params); @@ -890,15 +890,15 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; * floating point values. */ public function testCheckLineItemsWithFloatingPointValues() { - $params = array( + $params = [ 'contact_id' => 202, 'receive_date' => date('Y-m-d'), 'total_amount' => 16.67, 'financial_type_id' => 3, - 'line_items' => array( - array( - 'line_item' => array( - array( + 'line_items' => [ + [ + 'line_item' => [ + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 16, @@ -906,8 +906,8 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'qty' => 1, 'unit_price' => 14.85, 'line_total' => 14.85, - ), - array( + ], + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 17, @@ -916,8 +916,8 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'unit_price' => 1.66, 'line_total' => 1.66, 'financial_type_id' => 1, - ), - array( + ], + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 17, @@ -926,12 +926,12 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'unit_price' => 0.16, 'line_total' => 0.16, 'financial_type_id' => 1, - ), - ), - 'params' => array(), - ), - ), - ); + ], + ], + 'params' => [], + ], + ], + ]; $foundException = FALSE; @@ -950,9 +950,9 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; */ public function testActivityCreate() { $contactId = $this->individualCreate(); - $defaults = array(); + $defaults = []; - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -967,7 +967,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81', 'thankyou_date' => '20160519', 'sequential' => 1, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0]; @@ -975,10 +975,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.'); // Check amount in activity. - $activityParams = array( + $activityParams = [ 'source_record_id' => $contribution['id'], 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Contribution'), - ); + ]; // @todo use api instead. $activity = CRM_Activity_BAO_Activity::retrieve($activityParams, $defaults); @@ -1005,27 +1005,27 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; */ public function testAllowUpdateRevenueRecognitionDate() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => '2010-01-20', 'total_amount' => 100, 'financial_type_id' => 4, - ); + ]; $order = $this->callAPISuccess('order', 'create', $params); $allowUpdate = CRM_Contribute_BAO_Contribution::allowUpdateRevenueRecognitionDate($order['id']); $this->assertTrue($allowUpdate); $event = $this->eventCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => '2010-01-20', 'total_amount' => 300, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), 'contribution_status_id' => 'Completed', - ); + ]; $priceFields = $this->createPriceSet('event', $event['id']); foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[$key] = array( + $lineItems[$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -1035,35 +1035,35 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id'], 'entity_table' => 'civicrm_participant', - ); + ]; } - $params['line_items'][] = array( + $params['line_items'][] = [ 'line_item' => $lineItems, - 'params' => array( + 'params' => [ 'contact_id' => $contactId, 'event_id' => $event['id'], 'status_id' => 1, 'role_id' => 1, 'register_date' => '2007-07-21 00:00:00', 'source' => 'Online Event Registration: API Testing', - ), - ); + ], + ]; $order = $this->callAPISuccess('order', 'create', $params); $allowUpdate = CRM_Contribute_BAO_Contribution::allowUpdateRevenueRecognitionDate($order['id']); $this->assertFalse($allowUpdate); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => '2010-01-20', 'total_amount' => 200, 'financial_type_id' => $this->getFinancialTypeId('Member Dues'), 'contribution_status_id' => 'Completed', - ); + ]; $membershipType = $this->membershipTypeCreate(); $priceFields = $this->createPriceSet(); - $lineItems = array(); + $lineItems = []; foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[$key] = array( + $lineItems[$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -1074,11 +1074,11 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'financial_type_id' => $priceField['financial_type_id'], 'entity_table' => 'civicrm_membership', 'membership_type_id' => $membershipType, - ); + ]; } - $params['line_items'][] = array( - 'line_item' => array(array_pop($lineItems)), - 'params' => array( + $params['line_items'][] = [ + 'line_item' => [array_pop($lineItems)], + 'params' => [ 'contact_id' => $contactId, 'membership_type_id' => $membershipType, 'join_date' => '2006-01-21', @@ -1087,8 +1087,8 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'source' => 'Payment', 'is_override' => 1, 'status_id' => 1, - ), - ); + ], + ]; $order = $this->callAPISuccess('order', 'create', $params); $allowUpdate = CRM_Contribute_BAO_Contribution::allowUpdateRevenueRecognitionDate($order['id']); $this->assertFalse($allowUpdate); @@ -1098,65 +1098,65 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; * Test calculateFinancialItemAmount(). */ public function testcalculateFinancialItemAmount() { - $testParams = array( - array( - 'params' => array(), - 'amountParams' => array( + $testParams = [ + [ + 'params' => [], + 'amountParams' => [ 'line_total' => 100, 'previous_line_total' => 300, 'diff' => 1, - ), + ], 'context' => 'changedAmount', 'expectedItemAmount' => -200, - ), - array( - 'params' => array(), - 'amountParams' => array( + ], + [ + 'params' => [], + 'amountParams' => [ 'line_total' => 100, 'previous_line_total' => 100, 'diff' => -1, - ), + ], // Most contexts are ignored. Removing refs to change payment instrument so placeholder. 'context' => 'not null', 'expectedItemAmount' => -100, - ), - array( - 'params' => array( + ], + [ + 'params' => [ 'is_quick_config' => TRUE, 'total_amount' => 110, 'tax_amount' => 10, - ), - 'amountParams' => array( + ], + 'amountParams' => [ 'item_amount' => 100, - ), + ], 'context' => 'changedAmount', 'expectedItemAmount' => 100, - ), - array( - 'params' => array( + ], + [ + 'params' => [ 'is_quick_config' => TRUE, 'total_amount' => 110, 'tax_amount' => 10, - ), - 'amountParams' => array( + ], + 'amountParams' => [ 'item_amount' => NULL, - ), + ], 'context' => 'changedAmount', 'expectedItemAmount' => 110, - ), - array( - 'params' => array( + ], + [ + 'params' => [ 'is_quick_config' => TRUE, 'total_amount' => 110, 'tax_amount' => 10, - ), - 'amountParams' => array( + ], + 'amountParams' => [ 'item_amount' => NULL, - ), + ], 'context' => NULL, 'expectedItemAmount' => 100, - ), - ); + ], + ]; foreach ($testParams as $params) { $itemAmount = CRM_Contribute_BAO_Contribution::calculateFinancialItemAmount($params['params'], $params['amountParams'], $params['context']); $this->assertEquals($itemAmount, $params['expectedItemAmount'], 'Invalid Financial Item amount.'); @@ -1169,7 +1169,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; public function testCommaSeparatorAmount() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -1180,16 +1180,16 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'total_amount' => '20000.00', 'partial_payment_total' => '20,000.00', 'partial_amount_to_pay' => '8,000.00', - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('total_amount'), - ) + 'return' => ['total_amount'], + ] ); $this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid Tax amount.'); } @@ -1201,7 +1201,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->enableTaxAndInvoicing(); $financialType = $this->createFinancialType(); $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']); - $expectedResult = array($financialAccount->financial_account_id => $financialAccount->financial_account_id); + $expectedResult = [$financialAccount->financial_account_id => $financialAccount->financial_account_id]; $financialType = $this->createFinancialType(); $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']); $expectedResult[$financialAccount->financial_account_id] = $financialAccount->financial_account_id; @@ -1220,30 +1220,30 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; public function testCreateProportionalEntry($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); list($contribution, $financialAccount) = $this->createContributionWithTax(); - $params = array( + $params = [ 'total_amount' => 55, 'to_financial_account_id' => $financialAccount->financial_account_id, 'payment_instrument_id' => 1, 'trxn_date' => date('Ymd'), 'status_id' => 1, 'entity_id' => $contribution['id'], - ); + ]; $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); - $entityParams = array( + $entityParams = [ 'contribution_total_amount' => $contribution['total_amount'], 'trxn_total_amount' => 55, 'line_item_amount' => 100, - ); + ]; $previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']); - $eftParams = array( + $eftParams = [ 'entity_table' => 'civicrm_financial_item', 'entity_id' => $previousLineItem['id'], 'financial_trxn_id' => (string) $financialTrxn['id'], - ); + ]; CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams); - $trxnTestArray = array_merge($eftParams, array( + $trxnTestArray = array_merge($eftParams, [ 'amount' => '50.00', - )); + ]); $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray); } @@ -1257,31 +1257,31 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; */ public function testCreateProportionalEntryZeroAmount($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); - list($contribution, $financialAccount) = $this->createContributionWithTax(array('total_amount' => 0)); - $params = array( + list($contribution, $financialAccount) = $this->createContributionWithTax(['total_amount' => 0]); + $params = [ 'total_amount' => 0, 'to_financial_account_id' => $financialAccount->financial_account_id, 'payment_instrument_id' => 1, 'trxn_date' => date('Ymd'), 'status_id' => 1, 'entity_id' => $contribution['id'], - ); + ]; $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); - $entityParams = array( + $entityParams = [ 'contribution_total_amount' => $contribution['total_amount'], 'trxn_total_amount' => 0, 'line_item_amount' => 0, - ); + ]; $previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']); - $eftParams = array( + $eftParams = [ 'entity_table' => 'civicrm_financial_item', 'entity_id' => $previousLineItem['id'], 'financial_trxn_id' => (string) $financialTrxn['id'], - ); + ]; CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams); - $trxnTestArray = array_merge($eftParams, array( + $trxnTestArray = array_merge($eftParams, [ 'amount' => '0.00', - )); + ]); $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray); } @@ -1336,19 +1336,19 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; */ public function testProportionallyAssignedForPIChange() { list($contribution, $financialAccount) = $this->createContributionWithTax(); - $params = array( + $params = [ 'id' => $contribution['id'], 'payment_instrument_id' => 3, - ); + ]; $this->callAPISuccess('Contribution', 'create', $params); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); - $eftParams = array( + $eftParams = [ 'entity_table' => 'civicrm_financial_item', 'financial_trxn_id' => $lastFinancialTrxnId['financialTrxnId'], - ); + ]; $entityFinancialTrxn = $this->callAPISuccess('EntityFinancialTrxn', 'Get', $eftParams); $this->assertEquals($entityFinancialTrxn['count'], 2, 'Invalid count.'); - $testAmount = array(10, 100); + $testAmount = [10, 100]; foreach ($entityFinancialTrxn['values'] as $value) { $this->assertEquals($value['amount'], array_pop($testAmount), 'Invalid amount stored in civicrm_entity_financial_trxn.'); } @@ -1357,7 +1357,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; /** * Function to create contribution with tax. */ - public function createContributionWithTax($params = array(), $isCompleted = TRUE) { + public function createContributionWithTax($params = [], $isCompleted = TRUE) { if (!isset($params['total_amount'])) { $params['total_amount'] = 100; } @@ -1367,27 +1367,27 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => $params['total_amount'], 'financial_type_id' => $financialType['id'], 'contact_id' => $contactId, 'contribution_status_id' => $isCompleted ? 1 : 2, 'price_set_id' => 0, - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contact_id' => $contactId, - 'return' => array('tax_amount', 'total_amount'), - ) + 'return' => ['tax_amount', 'total_amount'], + ] ); - return array($contribution, $financialAccount); + return [$contribution, $financialAccount]; } /** * Test processOnBehalfOrganization() function. */ public function testProcessOnBehalfOrganization() { - $orgInfo = array( + $orgInfo = [ 'phone' => '11111111', 'email' => 'testorg@gmail.com', 'street_address' => 'test Street', @@ -1395,32 +1395,32 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'state_province' => 'AA', 'postal_code' => '222222', 'country' => 'United States', - ); + ]; $contactID = $this->individualCreate(); - $orgId = $this->organizationCreate(array('organization_name' => 'testorg1')); - $orgCount = $this->callAPISuccessGetCount('Contact', array( + $orgId = $this->organizationCreate(['organization_name' => 'testorg1']); + $orgCount = $this->callAPISuccessGetCount('Contact', [ 'contact_type' => "Organization", 'organization_name' => "testorg1", - )); + ]); $this->assertEquals($orgCount, 1); - $values = $params = array(); - $behalfOrganization = array( + $values = $params = []; + $behalfOrganization = [ 'organization_name' => 'testorg1', - 'phone' => array( - 1 => array( + 'phone' => [ + 1 => [ 'phone' => $orgInfo['phone'], 'is_primary' => 1, - ), - ), - 'email' => array( - 1 => array( + ], + ], + 'email' => [ + 1 => [ 'email' => $orgInfo['email'], 'is_primary' => 1, - ), - ), - 'address' => array( - 3 => array( + ], + ], + 'address' => [ + 3 => [ 'street_address' => $orgInfo['street_address'], 'city' => $orgInfo['city'], 'location_type_id' => 3, @@ -1428,10 +1428,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'country' => 'US', 'state_province' => 'AA', 'is_primary' => 1, - ), - ), - ); - $fields = array( + ], + ], + ]; + $fields = [ 'organization_name' => 1, 'phone-3-1' => 1, 'email-3' => 1, @@ -1440,14 +1440,14 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'postal_code-3' => 1, 'country-3' => 1, 'state_province-3' => 1, - ); + ]; CRM_Contribute_Form_Contribution_Confirm::processOnBehalfOrganization($behalfOrganization, $contactID, $values, $params, $fields); //Check whether new organisation is not created. - $result = $this->callAPISuccess('Contact', 'get', array( + $result = $this->callAPISuccess('Contact', 'get', [ 'contact_type' => "Organization", 'organization_name' => "testorg1", - )); + ]); $this->assertEquals($result['count'], 1); //Assert all org values are updated. @@ -1456,7 +1456,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; } //Check if alert is assigned to params if more than 1 dupe exists. - $orgId = $this->organizationCreate(array('organization_name' => 'testorg1', 'email' => 'testorg@gmail.com')); + $orgId = $this->organizationCreate(['organization_name' => 'testorg1', 'email' => 'testorg@gmail.com']); CRM_Contribute_Form_Contribution_Confirm::processOnBehalfOrganization($behalfOrganization, $contactID, $values, $params, $fields); $this->assertEquals($params['onbehalf_dupe_alert'], 1); } @@ -1469,7 +1469,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $customGroup = $this->customGroupCreate(['extends' => 'Contribution', 'title' => 'contribution stuff']); $customField = $this->customFieldOptionValueCreate($customGroup, 'myCustomField'); $contactId1 = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId1, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -1479,10 +1479,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'source' => 'SSF', 'contribution_status_id' => 2, "custom_{$customField['id']}" => 'value1', - ); + ]; $contribution1 = $this->contributionCreate($params); $contactId2 = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId2, 'receive_date' => '20150511', 'total_amount' => 200.00, @@ -1492,9 +1492,9 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'source' => 'ABC', 'contribution_status_id' => 1, "custom_{$customField['id']}" => 'value2', - ); + ]; $contribution2 = $this->contributionCreate($params); - $ids = array($contribution1, $contribution2); + $ids = [$contribution1, $contribution2]; $subject = "This is a test for contribution ID: {contribution.contribution_id}"; $text = "Contribution Amount: {contribution.total_amount}"; @@ -1530,7 +1530,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; public function testContributionWithDeferredRevenue() { $contactId = $this->individualCreate(); Civi::settings()->set('deferred_revenue_enabled', TRUE); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -1540,44 +1540,44 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'source' => 'SSF', 'contribution_status_id' => 'Completed', 'revenue_recognition_date' => date('Ymd', strtotime("+3 month")), - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccessGetCount('EntityFinancialTrxn', array( + $this->callAPISuccessGetCount('EntityFinancialTrxn', [ 'entity_table' => "civicrm_contribution", 'entity_id' => $contribution['id'], - ), 2); + ], 2); - $checkAgainst = array( + $checkAgainst = [ 'financial_trxn_id.to_financial_account_id.name' => 'Deferred Revenue - Event Fee', 'financial_trxn_id.from_financial_account_id.name' => 'Event Fee', 'financial_trxn_id' => '2', - ); - $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array( - 'return' => array( + ]; + $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', [ + 'return' => [ "financial_trxn_id.from_financial_account_id.name", "financial_trxn_id.to_financial_account_id.name", "financial_trxn_id", - ), + ], 'entity_table' => "civicrm_contribution", 'entity_id' => $contribution['id'], 'financial_trxn_id.is_payment' => 0, - ), $checkAgainst); + ], $checkAgainst); - $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array( + $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', [ 'entity_table' => "civicrm_financial_item", 'financial_trxn_id' => $result['financial_trxn_id'], - 'return' => array('entity_id'), - )); + 'return' => ['entity_id'], + ]); - $checkAgainst = array( + $checkAgainst = [ 'financial_account_id.name' => 'Deferred Revenue - Event Fee', 'id' => $result['entity_id'], - ); - $result = $this->callAPISuccessGetSingle('FinancialItem', array( + ]; + $result = $this->callAPISuccessGetSingle('FinancialItem', [ 'id' => $result['entity_id'], - 'return' => array("financial_account_id.name"), - ), $checkAgainst); + 'return' => ["financial_account_id.name"], + ], $checkAgainst); } /** @@ -1587,13 +1587,13 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; public function testChangingFinancialTypeWithoutTax() { $ids = $values = []; $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => date('YmdHis'), 'total_amount' => 100.00, 'financial_type_id' => 'Donation', 'contribution_status_id' => 'Completed', - ); + ]; /* first test the scenario when sending an email */ $contributionId = $this->callAPISuccess( 'contribution', @@ -1682,24 +1682,24 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; * CRM-21424 Check if the receipt update is set after composing the receipt message */ public function testSendMailUpdateReceiptDate() { - $ids = $values = array(); + $ids = $values = []; $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => '20120511', 'total_amount' => 100.00, 'financial_type_id' => 'Donation', 'source' => 'SSF', 'contribution_status_id' => 'Completed', - ); + ]; /* first test the scenario when sending an email */ $contribution = $this->callAPISuccess('contribution', 'create', $params); $contributionId = $contribution['id']; $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null'); - $input = array('receipt_update' => 0); + $input = ['receipt_update' => 0]; CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values); $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null'); - $input = array('receipt_update' => 1); + $input = ['receipt_update' => 1]; CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values); $this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set'); @@ -1707,11 +1707,11 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $contribution = $this->callAPISuccess('contribution', 'create', $params); $contributionId = $contribution['id']; $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null'); - $input = array('receipt_update' => 0); + $input = ['receipt_update' => 0]; /* setting the lasast parameter (returnmessagetext) to TRUE is done by the download of the pdf */ CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values, TRUE); $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null'); - $input = array('receipt_update' => 1); + $input = ['receipt_update' => 1]; CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values, TRUE); $this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set'); } diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTypeTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTypeTest.php index 9c9abeca0d..fa4238bd9c 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTypeTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTypeTest.php @@ -44,12 +44,12 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase { * Check method add() */ public function testAdd() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids); $result = $this->assertDBNotNull('CRM_Financial_BAO_FinancialType', $contributionType->id, @@ -64,15 +64,15 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase { * Check method retrive() */ public function testRetrieve() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids); - $defaults = array(); + $defaults = []; $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals($result->name, 'Donations', 'Verify financial type name.'); @@ -82,12 +82,12 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase { * Check method setIsActive() */ public function testSetIsActive() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids); $result = CRM_Financial_BAO_FinancialType::setIsActive($contributionType->id, 0); $this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.'); @@ -103,16 +103,16 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase { * Check method del() */ public function testdel() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids); CRM_Financial_BAO_FinancialType::del($contributionType->id); - $params = array('id' => $contributionType->id); + $params = ['id' => $contributionType->id]; $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); } diff --git a/tests/phpunit/CRM/Contribute/BAO/ProductTest.php b/tests/phpunit/CRM/Contribute/BAO/ProductTest.php index 986fa75707..dd9a98929f 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ProductTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ProductTest.php @@ -39,7 +39,7 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { * Check method add() */ public function testAdd() { - $params = array( + $params = [ 'name' => 'Test Product', 'sku' => 'TP-10', 'imageOption' => 'noImage', @@ -47,7 +47,7 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { 'cost' => 5, 'min_contribution' => 5, 'is_active' => 1, - ); + ]; $product = CRM_Contribute_BAO_Product::create($params); $result = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id, @@ -62,7 +62,7 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { * Check method retrieve( ) */ public function testRetrieve() { - $params = array( + $params = [ 'name' => 'Test Product', 'sku' => 'TP-10', 'imageOption' => 'noImage', @@ -70,11 +70,11 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { 'cost' => 5, 'min_contribution' => 5, 'is_active' => 1, - ); + ]; $product = CRM_Contribute_BAO_Product::create($params); - $params = array('id' => $product->id); - $default = array(); + $params = ['id' => $product->id]; + $default = []; $result = CRM_Contribute_BAO_Product::retrieve($params, $default); $this->assertEquals(empty($result), FALSE, 'Verify products record.'); } @@ -83,7 +83,7 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { * Check method setIsActive( ) */ public function testSetIsActive() { - $params = array( + $params = [ 'name' => 'Test Product', 'sku' => 'TP-10', 'imageOption' => 'noImage', @@ -91,7 +91,7 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { 'cost' => 5, 'min_contribution' => 5, 'is_active' => 1, - ); + ]; $product = CRM_Contribute_BAO_Product::create($params); CRM_Contribute_BAO_Product::setIsActive($product->id, 0); @@ -108,7 +108,7 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { * Check method del( ) */ public function testDel() { - $params = array( + $params = [ 'name' => 'Test Product', 'sku' => 'TP-10', 'imageOption' => 'noImage', @@ -116,13 +116,13 @@ class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { 'cost' => 5, 'min_contribution' => 5, 'is_active' => 1, - ); + ]; $product = CRM_Contribute_BAO_Product::create($params); CRM_Contribute_BAO_Product::del($product->id); - $params = array('id' => $product->id); - $defaults = array(); + $params = ['id' => $product->id]; + $defaults = []; $retrievedProduct = CRM_Contribute_BAO_Product::retrieve($params, $defaults); $this->assertEquals(empty($retrievedProduct), TRUE, 'Verify product record deletion.'); diff --git a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php index efedd30dfd..48973291f8 100644 --- a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php @@ -60,14 +60,14 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { * * @var array */ - protected $_processorParams = array(); + protected $_processorParams = []; /** * Payment instrument mapping. * * @var array */ - protected $paymentInstruments = array(); + protected $paymentInstruments = []; /** * Dummy payment processor. @@ -91,13 +91,13 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->createLoggedInUser(); $this->_individualId = $this->individualCreate(); - $this->_params = array( + $this->_params = [ 'total_amount' => 100, 'currency' => 'USD', 'contact_id' => $this->_individualId, 'financial_type_id' => 1, - ); - $this->_processorParams = array( + ]; + $this->_processorParams = [ 'domain_id' => 1, 'name' => 'Dummy', 'payment_processor_type_id' => 10, @@ -107,9 +107,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'url_site' => 'http://dummy.com', 'url_recur' => 'http://dummy.com', 'billing_mode' => 1, - ); + ]; - $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); $this->paymentInstruments = $instruments['values']; $this->paymentProcessor = $this->dummyProcessorCreate(); @@ -135,7 +135,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount by using Credit Card $this->submitPayment(70, 'live', TRUE); - $this->checkResults(array(30, 70), 2); + $this->checkResults([30, 70], 2); $mut->assertSubjects(['Payment Receipt -']); $mut->checkMailLog([ 'Dear Anthony,', @@ -162,7 +162,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount $this->submitPayment(70); - $this->checkResults(array(30, 70), 2); + $this->checkResults([30, 70], 2); } /** @@ -173,12 +173,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount $this->submitPayment(50); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); // pay additional amount $this->submitPayment(20); - $this->checkResults(array(30, 50, 20), 3); + $this->checkResults([30, 50, 20], 3); $activities = $this->callAPISuccess('Activity', 'get', [ 'source_record_id' => $this->_contributionId, 'activity_type_id' => 'Payment', @@ -211,13 +211,13 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount $this->submitPayment(50, NULL, TRUE); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); // pay additional amount by using credit card $this->submitPayment(20, 'live'); - $this->checkResults(array(30, 50, 20), 3); - $mut->assertSubjects(array('Payment Receipt -')); + $this->checkResults([30, 50, 20], 3); + $mut->assertSubjects(['Payment Receipt -']); $mut->checkMailLog([ 'Dear Anthony,', 'A payment has been received', @@ -243,7 +243,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount by using Credit Card $this->submitPayment(100, 'live'); - $this->checkResults(array(100), 1); + $this->checkResults([100], 1); } /** @@ -254,12 +254,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount $this->submitPayment(70); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); // pay additional amount $this->submitPayment(30); - $this->checkResults(array(30, 70), 2); + $this->checkResults([30, 70], 2); } /** @@ -270,15 +270,15 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $membership = $this->createPendingMembershipAndRecordContribution($this->_contributionId); // pay additional amount $this->submitPayment(100); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); - $contributionMembership = $this->callAPISuccessGetSingle('Membership', array('id' => $membership["id"])); - $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', array('id' => $contributionMembership["status_id"])); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); + $contributionMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership["id"]]); + $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['id' => $contributionMembership["status_id"]]); $this->assertEquals('New', $membershipStatus['name']); } private function createPendingMembershipAndRecordContribution($contributionId) { $this->_individualId = $this->individualCreate(); - $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array( + $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [ 'domain_id' => 1, 'name' => "AnnualFixed", 'member_of_contact_id' => 1, @@ -289,22 +289,22 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'fixed_period_rollover_day' => "1231", 'relationship_type_id' => 20, 'financial_type_id' => 2, - )); + ]); $membershipStatuses = CRM_Member_PseudoConstant::membershipStatus(); $pendingStatusId = array_search('Pending', $membershipStatuses); - $membership = $this->callAPISuccess('Membership', 'create', array( + $membership = $this->callAPISuccess('Membership', 'create', [ 'contact_id' => $this->_individualId, 'membership_type_id' => $membershipTypeAnnualFixed['id'], - )); + ]); // Updating Membership status to Pending - $membership = $this->callAPISuccess('Membership', 'create', array( + $membership = $this->callAPISuccess('Membership', 'create', [ 'id' => $membership["id"], 'status_id' => $pendingStatusId, - )); - $membershipPayment = $this->callAPISuccess('MembershipPayment', 'create', array( + ]); + $membershipPayment = $this->callAPISuccess('MembershipPayment', 'create', [ 'membership_id' => $membership["id"], 'contribution_id' => $contributionId, - )); + ]); return $membership; } @@ -316,19 +316,19 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount $this->submitPayment(40); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); $this->submitPayment(20); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); $this->submitPayment(30); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); $this->submitPayment(10); - $this->checkResults(array(40, 20, 30, 10), 4); + $this->checkResults([40, 20, 30, 10], 4); } /** @@ -339,19 +339,19 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { // pay additional amount $this->submitPayment(50); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); $this->submitPayment(20, 'live'); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); $this->submitPayment(20); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertEquals('Partially paid', $contribution['contribution_status']); $this->submitPayment(10, 'live'); - $this->checkResults(array(50, 20, 20, 10), 4); + $this->checkResults([50, 20, 20, 10], 4); } /** @@ -362,20 +362,20 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { */ public function createContribution($typeofContribution = 'Pending') { if ($typeofContribution == 'Partially paid') { - $contributionParams = array_merge($this->_params, array( + $contributionParams = array_merge($this->_params, [ 'partial_payment_total' => 100.00, 'partial_amount_to_pay' => 30, 'contribution_status_id' => 1, - )); + ]); } elseif ($typeofContribution == 'Pending') { - $contributionParams = array_merge($this->_params, array( + $contributionParams = array_merge($this->_params, [ 'contribution_status_id' => 2, 'is_pay_later' => 1, - )); + ]); } $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contribution['id'])); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]); $this->assertNotEmpty($contribution); $this->assertEquals($typeofContribution, $contribution['contribution_status']); $this->_contributionId = $contribution['id']; @@ -393,7 +393,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { public function submitPayment($amount, $mode = NULL, $isEmailReceipt = FALSE) { $form = new CRM_Contribute_Form_AdditionalPayment(); - $submitParams = array( + $submitParams = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_individualId, 'total_amount' => $amount, @@ -405,12 +405,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'payment_processor_id' => 0, 'is_email_receipt' => $isEmailReceipt, 'from_email_address' => 'site@something.com', - ); + ]; if ($mode) { - $submitParams += array( + $submitParams += [ 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025], 'credit_card_number' => '411111111111111', 'cvv2' => 234, 'credit_card_type' => 'Visa', @@ -418,13 +418,13 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'billing_state_province_id-5' => 1059, 'billing_postal_code-5' => 1321312, 'billing_country_id-5' => 1228, - ); + ]; } else { - $submitParams += array( + $submitParams += [ 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'check_number' => 'check-12345', - ); + ]; } $form->cid = $this->_individualId; $form->testSubmit($submitParams, $mode); @@ -440,16 +440,16 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { * */ public function checkResults($amounts, $count) { - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); $this->assertNotEmpty($contribution); $this->assertEquals('Completed', $contribution['contribution_status']); - $this->callAPISuccessGetCount('EntityFinancialTrxn', array( + $this->callAPISuccessGetCount('EntityFinancialTrxn', [ 'entity_table' => "civicrm_contribution", 'entity_id' => $this->_contributionId, 'financial_trxn_id.is_payment' => 1, - 'financial_trxn_id.total_amount' => array('IN' => $amounts), - ), $count); + 'financial_trxn_id.total_amount' => ['IN' => $amounts], + ], $count); } } diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php index bbcd88f6f5..e519040d8e 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -46,10 +46,10 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { */ public function testPaynowPayment() { $contactID = $this->individualCreate(); - $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy')); + $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']); // create a contribution page which is later used to make pay-later contribution - $result = $this->callAPISuccess('ContributionPage', 'create', array( + $result = $this->callAPISuccess('ContributionPage', 'create', [ 'title' => 'Test Contribution Page', 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), 'currency' => 'USD', @@ -59,10 +59,10 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { 'is_allow_other_amount' => 1, 'min_amount' => 20, 'max_amount' => 2000, - )); + ]); $contributionPageID1 = $result['id']; // create pending contribution - $contribution = $this->callAPISuccess('Contribution', 'create', array( + $contribution = $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $contactID, 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), 'currency' => 'USD', @@ -70,10 +70,10 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), 'contribution_page_id' => $contributionPageID1, 'source' => 'backoffice pending contribution', - )); + ]); // create a contribution page which is later used to make online payment for pending contribution - $result = $this->callAPISuccess('ContributionPage', 'create', array( + $result = $this->callAPISuccess('ContributionPage', 'create', [ 'title' => 'Test Contribution Page', 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), 'currency' => 'USD', @@ -83,27 +83,27 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { 'is_allow_other_amount' => 1, 'min_amount' => 10, 'max_amount' => 1000, - )); + ]); $form = new CRM_Contribute_Form_Contribution_Confirm(); $contributionPageID2 = $result['id']; $form->_id = $contributionPageID2; $form->_values = $result['values'][$contributionPageID2]; - $form->_paymentProcessor = array( + $form->_paymentProcessor = [ 'id' => $paymentProcessorID, 'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM, 'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID), 'is_recur' => FALSE, 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit card'), - ); - $form->_params = array( + ]; + $form->_params = [ 'qfKey' => 'donotcare', 'contribution_id' => $contribution['id'], 'credit_card_number' => 4111111111111111, 'cvv2' => 234, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 2, 'Y' => 2021, - ), + ], 'credit_card_type' => 'Visa', 'email-5' => 'test@test.com', 'total_amount' => 100.00, @@ -118,7 +118,7 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { 'is_quick_config' => 1, 'description' => $contribution['values'][$contribution['id']]['source'], 'skipLineItem' => 0, - ); + ]; $processConfirmResult = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $form->_params, @@ -132,21 +132,21 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { // Based on the processed contribution, complete transaction which update the contribution status based on payment result. if (!empty($processConfirmResult['contribution'])) { - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $processConfirmResult['contribution']->id, 'trxn_date' => date('Y-m-d'), 'payment_processor_id' => $paymentProcessorID, - )); + ]); } - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'id' => $form->_params['contribution_id'], - 'return' => array( + 'return' => [ 'contribution_page_id', 'contribution_status', 'contribution_source', - ), - )); + ], + ]); // check that contribution page ID isn't changed $this->assertEquals($contributionPageID1, $contribution['contribution_page_id']); diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php index f1d69b0654..0d9be8fa1f 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php @@ -45,11 +45,11 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { * Test that the membership is set to recurring if the membership type is always autorenew. */ public function testSetRecurFunction() { - $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 2, 'minimum_fee' => 80)); + $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 2, 'minimum_fee' => 80]); $form = $this->getContributionForm(); - $form->testSubmit(array( + $form->testSubmit([ 'selectMembership' => $membershipTypeID, - )); + ]); $this->assertEquals(1, $form->_params['is_recur']); } @@ -57,12 +57,12 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { * Test that the membership is set to recurring if the membership type is always autorenew. */ public function testSetRecurFunctionOptionalYes() { - $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 1, 'minimum_fee' => 80)); + $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 1, 'minimum_fee' => 80]); $form = $this->getContributionForm(); - $form->testSubmit(array( + $form->testSubmit([ 'selectMembership' => $membershipTypeID, 'is_recur' => 1, - )); + ]); $this->assertEquals(1, $form->_params['is_recur']); } @@ -70,12 +70,12 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { * Test that the membership is set to recurring if the membership type is always autorenew. */ public function testSetRecurFunctionOptionalNo() { - $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 1, 'minimum_fee' => 80)); + $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 1, 'minimum_fee' => 80]); $form = $this->getContributionForm(); - $form->testSubmit(array( + $form->testSubmit([ 'selectMembership' => $membershipTypeID, 'is_recur' => 0, - )); + ]); $this->assertEquals(0, $form->_params['is_recur']); } @@ -83,11 +83,11 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { * Test that the membership is set to recurring if the membership type is always autorenew. */ public function testSetRecurFunctionNotAvailable() { - $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 0, 'minimum_fee' => 80)); + $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 0, 'minimum_fee' => 80]); $form = $this->getContributionForm(); - $form->testSubmit(array( + $form->testSubmit([ 'selectMembership' => $membershipTypeID, - )); + ]); $this->assertArrayNotHasKey('is_recur', $form->_params); } @@ -100,19 +100,19 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { $form = new CRM_Contribute_Form_Contribution_Main(); $form->_values['is_monetary'] = 1; $form->_values['is_pay_later'] = 0; - $form->_priceSetId = $this->callAPISuccessGetValue('PriceSet', array( + $form->_priceSetId = $this->callAPISuccessGetValue('PriceSet', [ 'name' => 'default_membership_type_amount', 'return' => 'id', - )); - $priceFields = $this->callAPISuccess('PriceField', 'get', array('id' => $form->_priceSetId)); + ]); + $priceFields = $this->callAPISuccess('PriceField', 'get', ['id' => $form->_priceSetId]); $form->_priceSet['fields'] = $priceFields['values']; - $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy')); - $form->_paymentProcessor = array( + $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']); + $form->_paymentProcessor = [ 'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM, 'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID), 'is_recur' => TRUE, - ); - $form->_values = array( + ]; + $form->_values = [ 'title' => "Test Contribution Page", 'financial_type_id' => 1, 'currency' => 'NZD', @@ -121,7 +121,7 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { 'is_monetary' => TRUE, 'pay_later_text' => 'Front up', 'pay_later_receipt' => 'Ta', - ); + ]; return $form; } @@ -130,7 +130,7 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { */ public function testExpiredPriceSet() { $form = $this->getContributionForm(); - $priceSetParams1 = array( + $priceSetParams1 = [ 'name' => 'priceset', 'title' => 'Priceset with Multiple Terms', 'is_active' => 1, @@ -138,24 +138,24 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { 'financial_type_id' => 2, 'is_quick_config' => 1, 'is_reserved' => 1, - ); + ]; $priceSet = $this->callAPISuccess('price_set', 'create', $priceSetParams1); $form->_priceSetId = $priceSet['id']; $form->controller = new CRM_Core_Controller(); $form->set('priceSetId', $form->_priceSetId); - $params = array( + $params = [ 'price_set_id' => $form->_priceSetId, 'name' => 'testvalidpf', 'label' => 'test valid pf', 'html_type' => 'Radio', 'is_enter_qty' => 1, 'is_active' => 1, - ); + ]; $priceField1 = $this->callAPISuccess('PriceField', 'create', $params); //Create expired price field. - $params = array( + $params = [ 'price_set_id' => $form->_priceSetId, 'name' => 'testexpiredpf', 'label' => 'test expired pf', @@ -163,14 +163,14 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { 'is_enter_qty' => 1, 'is_active' => 1, 'expire_on' => date('Y-m-d', strtotime("-1 days")), - ); + ]; $priceField2 = $this->callAPISuccess('PriceField', 'create', $params); //Create price options. $membershipOrgId = $this->organizationCreate(NULL); - $memtype = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId)); - foreach (array($priceField1, $priceField2) as $priceField) { - $priceFieldValueParams = array( + $memtype = $this->membershipTypeCreate(['member_of_contact_id' => $membershipOrgId]); + foreach ([$priceField1, $priceField2] as $priceField) { + $priceFieldValueParams = [ 'price_field_id' => $priceField['id'], 'name' => 'rye grass', 'membership_type_id' => $memtype, @@ -178,7 +178,7 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { 'amount' => 1, 'membership_num_terms' => 2, 'financial_type_id' => 1, - ); + ]; $this->callAPISuccess('PriceFieldValue', 'create', $priceFieldValueParams); } diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php index efe98b0f32..c4bfa47465 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php @@ -45,7 +45,7 @@ class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase { * Test that correct contribution status is fetched for both live and test contributions. */ public function testLiveAndTestContributionStatus() { - $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy')); + $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']); $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE); $form->buildQuickForm(); @@ -83,7 +83,7 @@ class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase { private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) { $pageContribution = $this->getPageContribution((($withPendingContribution) ? 2 : 1), $isTestContribution); $form = $this->getThankYouForm(); - $form->_lineItem = array(); + $form->_lineItem = []; $form->_params['contributionID'] = $pageContribution['contribution_id']; $form->_params['invoiceID'] = $pageContribution['invoice_id']; @@ -106,17 +106,17 @@ class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase { $individualId = $this->individualCreate(); $invoiceId = rand(100000, 999999); - $contributionId = $this->contributionCreate(array( + $contributionId = $this->contributionCreate([ 'contact_id' => $individualId, 'invoice_id' => $invoiceId, 'contribution_status_id' => $contributionStatus, 'is_test' => ($isTest) ? 1 : 0, - )); + ]); - return array( + return [ 'contribution_id' => $contributionId, 'invoice_id' => $invoiceId, - ); + ]; } /** diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 629b9d9229..44c958ec06 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -40,8 +40,8 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { protected $_apiversion; protected $_entity = 'Contribution'; protected $_params; - protected $_ids = array(); - protected $_pageParams = array(); + protected $_ids = []; + protected $_pageParams = []; protected $_userId; /** @@ -49,7 +49,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { * * @var array */ - protected $_processorParams = array(); + protected $_processorParams = []; /** * ID of created event. @@ -63,14 +63,14 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { * * @var array */ - protected $paymentInstruments = array(); + protected $paymentInstruments = []; /** * Products. * * @var array */ - protected $products = array(); + protected $products = []; /** * Dummy payment processor. @@ -95,7 +95,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $this->_userId = $this->createLoggedInUser(); $this->_individualId = $this->individualCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -105,8 +105,8 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'net_amount' => 95.00, 'source' => 'SSF', 'contribution_status_id' => 1, - ); - $this->_processorParams = array( + ]; + $this->_processorParams = [ 'domain_id' => 1, 'name' => 'Dummy', 'payment_processor_type_id' => 10, @@ -116,14 +116,14 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'url_site' => 'http://dummy.com', 'url_recur' => 'http://dummy.com', 'billing_mode' => 1, - ); + ]; - $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); $this->paymentInstruments = $instruments['values']; - $product1 = $this->callAPISuccess('product', 'create', array( + $product1 = $this->callAPISuccess('product', 'create', [ 'name' => 'Smurf', 'options' => 'brainy smurf, clumsy smurf, papa smurf', - )); + ]); $this->products[] = $product1['values'][$product1['id']]; $this->paymentProcessor = $this->dummyProcessorCreate(); @@ -136,7 +136,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address')); + $this->quickCleanup(['civicrm_note', 'civicrm_uf_match', 'civicrm_address']); } /** @@ -149,14 +149,14 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { public function testSubmit($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => $this->formatMoneyInput(1234), 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, - ), CRM_Core_Action::ADD); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); + ], CRM_Core_Action::ADD); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); $this->assertEmpty($contribution['amount_level']); $this->assertEquals(1234, $contribution['total_amount']); $this->assertEquals(1234, $contribution['net_amount']); @@ -167,17 +167,17 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function testSubmitCreditCard() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'contribution_status_id' => 1, - ), CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array( + ], CRM_Core_Action::ADD); + $this->callAPISuccessGetCount('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 'Completed', - ), 1); + ], 1); } /** @@ -187,21 +187,21 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $mut->clearMessages(); $form = new CRM_Contribute_Form_Contribution(); - $paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0)); + $paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0]); $form->_mode = 'Live'; $error = FALSE; try { - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'contribution_status_id' => 1, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -223,25 +223,25 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'payment_processor_id' => $paymentProcessorID, 'currency' => 'USD', 'source' => 'bob sled race', - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); } catch (Civi\Payment\Exception\PaymentProcessorException $e) { $error = TRUE; } - $contribution = $this->callAPISuccess('Contribution', 'get', array( + $contribution = $this->callAPISuccess('Contribution', 'get', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => $error ? 'Failed' : 'Completed', - 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( + 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ 'return' => 'payment_instrument_id', 'id' => $paymentProcessorID, - )), - )); + ]), + ]); $this->assertEquals(1, $contribution["count"], "Contribution count should be one."); $this->assertTrue(!empty($contribution["values"][$contribution["id"]]["receipt_date"]), "Receipt date should not be blank."); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]); $this->assertTrue(empty($contact['source'])); if (!$error) { $msgs = $mut->getAllMessages(); @@ -260,17 +260,17 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $form = new CRM_Contribute_Form_Contribution(); $form->_mode = 'Live'; - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'contribution_status_id' => 1, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -292,17 +292,17 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'payment_processor_id' => $this->paymentProcessorID, 'currency' => 'USD', 'source' => 'bob sled race', - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array( + $this->callAPISuccessGetCount('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 'Completed', - 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( + 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ 'return' => 'payment_instrument_id', 'id' => $this->paymentProcessorID, - )), - ), 1); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); + ]), + ], 1); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]); $this->assertTrue(empty($contact['source'])); $msgs = $mut->getAllMessages(); $this->assertEquals(1, count($msgs)); @@ -319,17 +319,17 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $form->_mode = 'Live'; $error = FALSE; try { - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 60, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'contribution_status_id' => 1, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -351,21 +351,21 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'payment_processor_id' => $this->paymentProcessorID, 'currency' => 'USD', 'source' => 'bob sled race', - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); } catch (Civi\Payment\Exception\PaymentProcessorException $e) { $error = TRUE; } - $this->callAPISuccessGetCount('Contribution', array( + $this->callAPISuccessGetCount('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => $error ? 'Failed' : 'Completed', - 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( + 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ 'return' => 'payment_instrument_id', 'id' => $this->paymentProcessorID, - )), - ), 1); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); + ]), + ], 1); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]); $this->assertTrue(empty($contact['source'])); $mut->assertMailLogEmpty(); $mut->stop(); @@ -376,9 +376,9 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function testSubmitCreditCardFee() { $form = new CRM_Contribute_Form_Contribution(); - $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08)); + $this->paymentProcessor->setDoDirectPaymentResult(['is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08]); $form->_mode = 'Live'; - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, @@ -386,10 +386,10 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'contribution_status_id' => 1, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -410,12 +410,12 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'payment_processor_id' => $this->paymentProcessorID, 'currency' => 'USD', 'source' => '', - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 'Completed', - )); + ]); $this->assertEquals('50', $contribution['total_amount']); $this->assertEquals(.08, $contribution['fee_amount']); $this->assertEquals(49.92, $contribution['net_amount']); @@ -429,7 +429,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { public function testSubmitCreditCardFullyDeductible() { $form = new CRM_Contribute_Form_Contribution(); $form->_mode = 'Live'; - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, @@ -437,10 +437,10 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'contribution_status_id' => 1, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -461,12 +461,12 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'payment_processor_id' => $this->paymentProcessorID, 'currency' => 'USD', 'source' => '', - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 'Completed', - )); + ]); $this->assertEquals('50', $contribution['total_amount']); $this->assertEquals(0, $contribution['non_deductible_amount']); } @@ -485,32 +485,32 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function testSubmitCreditCardInvalid() { $form = new CRM_Contribute_Form_Contribution(); - $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 1)); + $this->paymentProcessor->setDoDirectPaymentResult(['is_error' => 1]); try { - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2012], 'credit_card_number' => '411111111111111', - ), CRM_Core_Action::ADD, 'live'); + ], CRM_Core_Action::ADD, 'live'); } catch (\Civi\Payment\Exception\PaymentProcessorException $e) { - $this->callAPISuccessGetCount('Contribution', array( + $this->callAPISuccessGetCount('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 'Failed', - ), 1); - $lineItem = $this->callAPISuccessGetSingle('line_item', array()); + ], 1); + $lineItem = $this->callAPISuccessGetSingle('line_item', []); $this->assertEquals('50.00', $lineItem['unit_price']); $this->assertEquals('50.00', $lineItem['line_total']); $this->assertEquals(1, $lineItem['qty']); $this->assertEquals(1, $lineItem['financial_type_id']); - $financialItem = $this->callAPISuccessGetSingle('financial_item', array( + $financialItem = $this->callAPISuccessGetSingle('financial_item', [ 'civicrm_line_item' => $lineItem['id'], 'entity_id' => $lineItem['id'], - )); + ]); $this->assertEquals('50.00', $financialItem['amount']); $this->assertEquals(3, $financialItem['status_id']); return; @@ -523,23 +523,23 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function testSubmitCreditCardWithBillingAddress() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025], 'credit_card_number' => '411111111111111', 'billing_city-5' => 'Vancouver', - ), CRM_Core_Action::ADD, 'live'); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); + ], CRM_Core_Action::ADD, 'live'); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'address_id']); $this->assertNotEmpty($contribution['address_id']); // CRM-18490 : There is a unwanted test leakage due to below getsingle Api as it only fails in Jenkin // for now we are only fetching address on based on Address ID (removed filter location_type_id and city) - $this->callAPISuccessGetSingle('Address', array( + $this->callAPISuccessGetSingle('Address', [ 'id' => $contribution['address_id'], - )); + ]); } /** @@ -549,7 +549,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { public function testSubmitCreditCardWithRecur() { $form = new CRM_Contribute_Form_Contribution(); $receiveDate = date('Y-m-d H:i:s', strtotime('+1 month')); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'is_recur' => 1, @@ -560,11 +560,11 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025], 'credit_card_number' => '411111111111111', 'billing_city-5' => 'Vancouver', - ), CRM_Core_Action::ADD, 'live'); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'receive_date')); + ], CRM_Core_Action::ADD, 'live'); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'receive_date']); $this->assertEquals($contribution['receive_date'], $receiveDate); } @@ -573,21 +573,21 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function testSubmitCreditCardWithNoBillingAddress() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025], 'credit_card_number' => '411111111111111', - ), CRM_Core_Action::ADD, 'live'); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); + ], CRM_Core_Action::ADD, 'live'); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'address_id']); $this->assertEmpty($contribution['address_id']); - $this->callAPISuccessGetCount('Address', array( + $this->callAPISuccessGetCount('Address', [ 'city' => 'Vancouver', 'location_type_id' => 5, - ), 0); + ], 0); } /** @@ -596,18 +596,18 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { public function testSubmitEmailReceipt() { $form = new CRM_Contribute_Form_Contribution(); $mut = new CiviMailUtils($this, TRUE); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'is_email_receipt' => TRUE, 'from_email_address' => 'test@test.com', 'contribution_status_id' => 1, - ), CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); - $mut->checkMailLog(array( + ], CRM_Core_Action::ADD); + $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1); + $mut->checkMailLog([ '

Please print this receipt for your records.

', - )); + ]); $mut->stop(); } @@ -621,19 +621,19 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'contact_id' => $this->_userId, 'email' => 'testLoggedIn@example.com', ]); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'is_email_receipt' => TRUE, 'from_email_address' => $email['id'], 'contribution_status_id' => 1, - ), CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); - $mut->checkMailLog(array( + ], CRM_Core_Action::ADD); + $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1); + $mut->checkMailLog([ '

Please print this receipt for your records.

', '', - )); + ]); $mut->stop(); } @@ -642,12 +642,12 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function testEmailReceiptOnPayLater() { $donationFT = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name'); - $paramsSet = array( + $paramsSet = [ 'title' => 'Price Set' . substr(sha1(rand()), 0, 4), 'is_active' => TRUE, 'financial_type_id' => $donationFT, 'extends' => 2, - ); + ]; $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); @@ -657,27 +657,27 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset' ); - $paramsField = array( + $paramsField = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', - 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_value' => array('1' => 100, '2' => 200), - 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_weight' => array('1' => 1, '2' => 2), - 'option_amount' => array('1' => 100, '2' => 200), + 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_value' => ['1' => 100, '2' => 200], + 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_weight' => ['1' => 1, '2' => 2], + 'option_amount' => ['1' => 100, '2' => 200], 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, - 'is_active' => array('1' => 1, '2' => 1), + 'is_active' => ['1' => 1, '2' => 1], 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => $donationFT, - ); + ]; $priceField = CRM_Price_BAO_PriceField::create($paramsField); - $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); + $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]); - $params = array( + $params = [ 'total_amount' => 100, 'financial_type_id' => $donationFT, 'contact_id' => $this->_individualId, @@ -685,11 +685,11 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'from_email_address' => 'test@test.com', 'price_set_id' => $priceSetId, 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), - ); + ]; foreach ($priceFieldValue['values'] as $id => $price) { if ($price['amount'] == 100) { - $params['price_' . $priceField->id] = array($id => 1); + $params['price_' . $priceField->id] = [$id => 1]; } } $form = new CRM_Contribute_Form_Contribution(); @@ -697,14 +697,14 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); $form->testSubmit($params, CRM_Core_Action::ADD); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Financial Type: Donation --------------------------------------------------------- Item Qty Each Total ---------------------------------------------------------- Price Field - Price Field 1 1 $ 100.00 $ 100.00 ', - )); + ]); $mut->stop(); } @@ -712,7 +712,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 * Test that a contribution is assigned against a pledge. */ public function testUpdatePledge() { - $pledge = $this->callAPISuccess('pledge', 'create', array( + $pledge = $this->callAPISuccess('pledge', 'create', [ 'contact_id' => $this->_individualId, 'pledge_create_date' => date('Ymd'), 'start_date' => date('Ymd'), @@ -725,22 +725,22 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'frequency_day' => 15, 'installments' => 2, 'sequential' => 1, - )); - $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array( + ]); + $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', [ 'pledge_id' => $pledge['id'], - 'options' => array('limit' => 1), + 'options' => ['limit' => 1], 'return' => 'id', - )); + ]); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'pledge_payment_id' => $pledgePaymentID, 'contribution_status_id' => 1, - ), CRM_Core_Action::ADD); - $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID)); + ], CRM_Core_Action::ADD); + $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', ['id' => $pledgePaymentID]); $this->assertNotEmpty($pledgePayment['contribution_id']); $this->assertEquals($pledgePayment['actual_amount'], 50); $this->assertEquals(1, $pledgePayment['status_id']); @@ -752,24 +752,24 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 public function testPremiumUpdate() { $form = new CRM_Contribute_Form_Contribution(); $mut = new CiviMailUtils($this, TRUE); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, - 'product_name' => array($this->products[0]['id'], 1), + 'product_name' => [$this->products[0]['id'], 1], 'fulfilled_date' => '', 'is_email_receipt' => TRUE, 'from_email_address' => 'test@test.com', - ), CRM_Core_Action::ADD); - $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); + ], CRM_Core_Action::ADD); + $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', []); $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Premium Information', 'Smurf', 'clumsy smurf', - )); + ]); $mut->stop(); } @@ -779,27 +779,27 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 public function testPremiumUpdateCreditCard() { $form = new CRM_Contribute_Form_Contribution(); $mut = new CiviMailUtils($this, TRUE); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, - 'product_name' => array($this->products[0]['id'], 1), + 'product_name' => [$this->products[0]['id'], 1], 'fulfilled_date' => '', 'is_email_receipt' => TRUE, 'from_email_address' => 'test@test.com', 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2026), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2026], 'credit_card_number' => '411111111111111', - ), CRM_Core_Action::ADD, 'live'); - $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); + ], CRM_Core_Action::ADD, 'live'); + $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', []); $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Premium Information', 'Smurf', 'clumsy smurf', - )); + ]); $mut->stop(); } @@ -808,16 +808,16 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 */ public function testSubmitWithNote() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'note' => 'Super cool and interesting stuff', - ), CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); - $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); + ], CRM_Core_Action::ADD); + $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1); + $note = $this->callAPISuccessGetSingle('note', ['entity_table' => 'civicrm_contribution']); $this->assertEquals($note['note'], 'Super cool and interesting stuff'); } @@ -827,17 +827,17 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 public function testSubmitWithNoteCreditCard() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'note' => 'Super cool and interesting stuff', - ) + $this->getCreditCardParams(), + ] + $this->getCreditCardParams(), CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); - $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); + $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1); + $note = $this->callAPISuccessGetSingle('note', ['entity_table' => 'civicrm_contribution']); $this->assertEquals($note['note'], 'Super cool and interesting stuff'); } @@ -850,19 +850,19 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 */ public function testEnterNegativeContribution() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => -5, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, - ), + ], CRM_Core_Action::ADD); - $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); + $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, - )); + ]); $this->assertEquals(-5, $contribution['total_amount']); } @@ -877,16 +877,16 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->setCurrencySeparators($thousandSeparator); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => $this->formatMoneyInput(6100.10), 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'price_set_id' => 0, - ), CRM_Core_Action::ADD); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); - $form->testSubmit(array( + ], CRM_Core_Action::ADD); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); + $form->testSubmit([ 'total_amount' => $this->formatMoneyInput(5200.20), 'net_amount' => $this->formatMoneyInput(5200.20), 'financial_type_id' => 1, @@ -895,16 +895,16 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'contribution_status_id' => 1, 'price_set_id' => 0, 'id' => $contribution['id'], - ), CRM_Core_Action::UPDATE); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); + ], CRM_Core_Action::UPDATE); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); $this->assertEquals(5200.20, $contribution['total_amount'], 2); - $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE)); + $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', ['sequential' => TRUE]); $this->assertEquals(2, $financialTransactions['count']); $this->assertEquals(6100.10, $financialTransactions['values'][0]['total_amount']); $this->assertEquals(-899.90, $financialTransactions['values'][1]['total_amount']); $this->assertEquals(-899.90, $financialTransactions['values'][1]['net_amount']); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array()); + $lineItem = $this->callAPISuccessGetSingle('LineItem', []); $this->assertEquals(5200.20, $lineItem['line_total']); } @@ -919,7 +919,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->setCurrencySeparators($thousandSeparator); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 1200.55, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, @@ -927,9 +927,9 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'check_number' => '123AX', 'contribution_status_id' => 1, 'price_set_id' => 0, - ), CRM_Core_Action::ADD); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); - $form->testSubmit(array( + ], CRM_Core_Action::ADD); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); + $form->testSubmit([ 'total_amount' => 1200.55, 'net_amount' => 1200.55, 'financial_type_id' => 1, @@ -940,11 +940,11 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'contribution_status_id' => 1, 'price_set_id' => 0, 'id' => $contribution['id'], - ), CRM_Core_Action::UPDATE); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); + ], CRM_Core_Action::UPDATE); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); $this->assertEquals(1200.55, $contribution['total_amount']); - $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE)); + $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', ['sequential' => TRUE]); $this->assertEquals(3, $financialTransactions['count']); list($oldTrxn, $reversedTrxn, $latestTrxn) = $financialTransactions['values']; @@ -960,7 +960,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->assertEquals(1200.55, $latestTrxn['total_amount']); $this->assertEquals('1011', $latestTrxn['pan_truncation']); $this->assertEquals(array_search('Credit Card', $this->paymentInstruments), $latestTrxn['payment_instrument_id']); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array()); + $lineItem = $this->callAPISuccessGetSingle('LineItem', []); } /** @@ -970,11 +970,11 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 * Credit card specific parameters. */ protected function getCreditCardParams() { - return array( + return [ 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2012], 'credit_card_number' => '411111111111111', - ); + ]; } /** @@ -984,7 +984,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 // create a partially paid contribution by using back-office form $form = new CRM_Contribute_Form_Contribution(); $form->testSubmit( - array( + [ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, @@ -992,15 +992,15 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'check_number' => substr(sha1(rand()), 0, 7), 'billing_city-5' => 'Vancouver', 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'), - ), CRM_Core_Action::ADD + ], CRM_Core_Action::ADD ); - $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + $contribution = $this->callAPISuccessGetSingle('Contribution', []); $this->assertNotEmpty($contribution); $this->assertEquals('Partially paid', $contribution['contribution_status']); // pay additional amount by using Credit Card $form = new CRM_Contribute_Form_AdditionalPayment(); - $form->testSubmit(array( + $form->testSubmit([ 'contribution_id' => $contribution['id'], 'contact_id' => $this->_individualId, 'total_amount' => 50, @@ -1009,7 +1009,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessorID, - 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025], 'credit_card_number' => '411111111111111', 'cvv2' => 234, 'credit_card_type' => 'Visa', @@ -1018,8 +1018,8 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'billing_postal_code-5' => 1321312, 'billing_country_id-5' => 1228, 'trxn_date' => '2017-04-11 13:05:11', - ), 'live'); - $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + ], 'live'); + $contribution = $this->callAPISuccessGetSingle('Contribution', []); $this->assertNotEmpty($contribution); $this->assertEquals('Completed', $contribution['contribution_status']); } @@ -1037,40 +1037,40 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => $this->formatMoneyInput(1000.00), 'financial_type_id' => $this->_financialTypeId, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'price_set_id' => 0, - ), + ], CRM_Core_Action::ADD ); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contact_id' => $this->_individualId, - 'return' => array('tax_amount', 'total_amount'), - ) + 'return' => ['tax_amount', 'total_amount'], + ] ); $this->assertEquals(1100, $contribution['total_amount']); $this->assertEquals(100, $contribution['tax_amount']); - $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); - $this->callAPISuccessGetCount('FinancialItem', array(), 2); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'])); + $this->callAPISuccessGetCount('FinancialTrxn', [], 1); + $this->callAPISuccessGetCount('FinancialItem', [], 2); + $lineItem = $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id']]); $this->assertEquals(1000, $lineItem['line_total']); $this->assertEquals(100, $lineItem['tax_amount']); // CRM-20423: Upon simple submit of 'Edit Contribution' form ensure that total amount is same - $form->testSubmit(array( + $form->testSubmit([ 'id' => $contribution['id'], 'financial_type_id' => 3, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, - ), CRM_Core_Action::UPDATE); + ], CRM_Core_Action::UPDATE); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); // Check if total amount is unchanged $this->assertEquals(1100, $contribution['total_amount']); } @@ -1083,30 +1083,30 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 100, 'financial_type_id' => 3, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'price_set_id' => 0, - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contact_id' => $this->_individualId, - 'return' => array('tax_amount', 'total_amount'), - ) + 'return' => ['tax_amount', 'total_amount'], + ] ); $this->assertEquals(100, $contribution['total_amount']); $this->assertEquals(NULL, $contribution['tax_amount']); - $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); - $this->callAPISuccessGetCount('FinancialItem', array(), 1); + $this->callAPISuccessGetCount('FinancialTrxn', [], 1); + $this->callAPISuccessGetCount('FinancialItem', [], 1); $lineItem = $this->callAPISuccessGetSingle( 'LineItem', - array( + [ 'contribution_id' => $contribution['id'], - 'return' => array('line_total', 'tax_amount'), - ) + 'return' => ['line_total', 'tax_amount'], + ] ); $this->assertEquals(100, $lineItem['line_total']); $this->assertTrue(empty($lineItem['tax_amount'])); @@ -1132,7 +1132,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $mut = new CiviMailUtils($this, TRUE); // Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same: - $form->testSubmit(array( + $form->testSubmit([ 'id' => $contribution['id'], 'tax_amount' => $contribution['tax_amount'], 'financial_type_id' => $contribution['financial_type_id'], @@ -1143,28 +1143,28 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'contribution_status_id' => 1, 'is_email_receipt' => 1, 'from_email_address' => 'demo@example.com', - ), CRM_Core_Action::UPDATE); + ], CRM_Core_Action::UPDATE); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contribution_id' => 1, - 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'), - ) + 'return' => ['tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'], + ] ); $this->assertEquals(11000, $contribution['total_amount']); $this->assertEquals(1000, $contribution['tax_amount']); $this->assertEquals(11000, $contribution['net_amount']); - $strings = array( + $strings = [ 'Total Tax Amount : $ ' . $this->formatMoneyInput(1000.00), 'Total Amount : $ ' . $this->formatMoneyInput(11000.00), 'Date Received: April 21st, 2015', 'Paid By: Check', 'Check Number: 12345', - ); + ]; $mut->checkMailLog($strings); - $this->callAPISuccessGetCount('FinancialTrxn', array(), 3); - $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1)); + $this->callAPISuccessGetCount('FinancialTrxn', [], 3); + $items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1]); $this->assertEquals(2, $items['count']); $this->assertEquals('Contribution Amount', $items['values'][0]['description']); $this->assertEquals('Sales Tax', $items['values'][1]['description']); @@ -1190,7 +1190,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $mut = new CiviMailUtils($this, TRUE); // Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same: - $form->testSubmit(array( + $form->testSubmit([ 'id' => $contribution['id'], 'total_amount' => $this->formatMoneyInput(20000), 'tax_amount' => $this->formatMoneyInput(2000), @@ -1202,28 +1202,28 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'contribution_status_id' => 1, 'is_email_receipt' => 1, 'from_email_address' => 'demo@example.com', - ), CRM_Core_Action::UPDATE); + ], CRM_Core_Action::UPDATE); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contribution_id' => 1, - 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'), - ) + 'return' => ['tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'], + ] ); $this->assertEquals(22000, $contribution['total_amount']); $this->assertEquals(2000, $contribution['tax_amount']); $this->assertEquals(22000, $contribution['net_amount']); - $strings = array( + $strings = [ 'Total Tax Amount : $ ' . $this->formatMoneyInput(2000), 'Total Amount : $ ' . $this->formatMoneyInput(22000.00), 'Date Received: April 21st, 2015', 'Paid By: Check', 'Check Number: 12345', - ); + ]; $mut->checkMailLog($strings); - $this->callAPISuccessGetCount('FinancialTrxn', array(), 4); - $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1)); + $this->callAPISuccessGetCount('FinancialTrxn', [], 4); + $items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1]); $this->assertEquals(4, $items['count']); $this->assertEquals('Contribution Amount', $items['values'][0]['description']); $this->assertEquals('Sales Tax', $items['values'][1]['description']); @@ -1246,7 +1246,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 protected function doInitialSubmit() { $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => $this->formatMoneyInput(10000), 'financial_type_id' => $this->_financialTypeId, 'receive_date' => '2015-04-21 00:00:00', @@ -1254,24 +1254,24 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'price_set_id' => 0, - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contribution_id' => 1, - 'return' => array( + 'return' => [ 'tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id', - ), - ) + ], + ] ); $this->assertEquals(11000, $contribution['total_amount']); $this->assertEquals(1000, $contribution['tax_amount']); $this->assertEquals(11000, $contribution['net_amount']); - return array($form, $contribution); + return [$form, $contribution]; } /** @@ -1280,7 +1280,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 public function testCardTypeAndPanTruncation() { $form = new CRM_Contribute_Form_Contribution(); $form->testSubmit( - array( + [ 'total_amount' => 100, 'financial_type_id' => 3, 'contact_id' => $this->_individualId, @@ -1289,22 +1289,22 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'credit_card_type' => 'Visa', 'pan_truncation' => 4567, 'price_set_id' => 0, - ), + ], CRM_Core_Action::ADD ); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contact_id' => $this->_individualId, - 'return' => array('id'), - ) + 'return' => ['id'], + ] ); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id.label', 'pan_truncation'), - ) + 'return' => ['card_type_id.label', 'pan_truncation'], + ] ); $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567); @@ -1315,7 +1315,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 */ public function testContributionBasePreProcess() { //Create contribution page with only pay later enabled. - $params = array( + $params = [ 'title' => "Test Contribution Page", 'financial_type_id' => 1, 'currency' => 'NZD', @@ -1326,7 +1326,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'is_email_receipt' => TRUE, 'receipt_from_email' => 'yourconscience@donate.com', 'receipt_from_name' => 'Ego Freud', - ); + ]; $page1 = $this->callAPISuccess("contribution_page", 'create', $params); @@ -1367,17 +1367,17 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $form = new CRM_Contribute_Form_Contribution(); $form->_mode = 'Live'; $form->testSubmit( - array( + [ 'total_amount' => 50, 'financial_type_id' => 1, 'contact_id' => $this->_individualId, 'credit_card_number' => 4444333322221111, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => date('Y', strtotime('+5 years')), - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -1398,17 +1398,17 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'payment_processor_id' => $this->paymentProcessorID, 'currency' => 'USD', 'source' => 'bob sled race', - ), + ], CRM_Core_Action::ADD ); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals($visaID, $financialTrxn['card_type_id']); $this->assertEquals(1111, $financialTrxn['pan_truncation']); @@ -1423,7 +1423,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $contactID2 = $this->organizationCreate(); // create membership types - $membershipTypeOne = civicrm_api3('membership_type', 'create', array( + $membershipTypeOne = civicrm_api3('membership_type', 'create', [ 'domain_id' => 1, 'name' => "One", 'member_of_contact_id' => $contactID1, @@ -1437,9 +1437,9 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'weight' => 50, 'is_active' => 1, 'visibility' => "Public", - )); + ]); - $membershipTypeTwo = civicrm_api3('membership_type', 'create', array( + $membershipTypeTwo = civicrm_api3('membership_type', 'create', [ 'domain_id' => 1, 'name' => "Two", 'member_of_contact_id' => $contactID2, @@ -1453,15 +1453,15 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'weight' => 51, 'is_active' => 1, 'visibility' => "Public", - )); + ]); //create custom Fields - $membershipCustomFieldsGroup = civicrm_api3('CustomGroup', 'create', array( + $membershipCustomFieldsGroup = civicrm_api3('CustomGroup', 'create', [ 'title' => "Custom Fields on Membership", 'extends' => "Membership", - )); + ]); - $membershipCustomField = civicrm_api3('CustomField', 'create', array( + $membershipCustomField = civicrm_api3('CustomField', 'create', [ "custom_group_id" => $membershipCustomFieldsGroup['id'], "name" => "my_membership_custom_field", "label" => "Membership Custom Field", @@ -1470,10 +1470,10 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 "is_active" => "1", "is_view" => "0", "text_length" => "255", - )); + ]); // create profile - $membershipCustomFieldsProfile = civicrm_api3('UFGroup', 'create', array( + $membershipCustomFieldsProfile = civicrm_api3('UFGroup', 'create', [ "is_active" => "1", "group_type" => "Membership,Individual", "title" => "Membership Custom Fields", @@ -1482,10 +1482,10 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 "is_edit_link" => "0", "is_uf_link" => "0", "is_update_dupe" => "0", - )); + ]); // add custom fields to profile - $membershipCustomFieldsProfileFields = civicrm_api3('UFField', 'create', array( + $membershipCustomFieldsProfileFields = civicrm_api3('UFField', 'create', [ "uf_group_id" => $membershipCustomFieldsProfile['id'], "field_name" => "custom_" . $membershipCustomField['id'], "is_active" => "1", @@ -1494,9 +1494,9 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 "is_searchable" => "0", "label" => "custom text field on membership", "field_type" => "Membership", - )); + ]); - $contribPage = civicrm_api3('ContributionPage', 'create', array( + $contribPage = civicrm_api3('ContributionPage', 'create', [ "title" => "Membership", "financial_type_id" => 1, 'financial_account_id' => 1, @@ -1521,21 +1521,21 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'is_allow_other_amount' => 1, 'min_amount' => 10, 'max_amount' => 1000, - )); + ]); $contribPage1 = $contribPage['id']; //create price set with two options for the two different memberships - $priceSet = civicrm_api3('PriceSet', 'create', array( + $priceSet = civicrm_api3('PriceSet', 'create', [ 'title' => "Two Membership Type Checkbox", 'extends' => "CiviMember", 'is_active' => 1, "financial_type_id" => "1", "is_quick_config" => "0", "is_reserved" => "0", - "entity" => array("civicrm_contribution_page" => array($contribPage1)), - )); + "entity" => ["civicrm_contribution_page" => [$contribPage1]], + ]); - $priceField = civicrm_api3('PriceField', 'create', array( + $priceField = civicrm_api3('PriceField', 'create', [ "price_set_id" => $priceSet['id'], "name" => "mt", "label" => "Membership Types", @@ -1547,9 +1547,9 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 "is_active" => "1", "is_required" => "0", "visibility_id" => "1", - )); + ]); - $priceFieldOption1 = civicrm_api3('PriceFieldValue', 'create', array( + $priceFieldOption1 = civicrm_api3('PriceFieldValue', 'create', [ "price_field_id" => $priceField['id'], "name" => "membership_type_one", "label" => "Membership Type One", @@ -1562,9 +1562,9 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 "financial_type_id" => "1", "non_deductible_amount" => "0.00", "contribution_type_id" => "2", - )); + ]); - $priceFieldOption2 = civicrm_api3('PriceFieldValue', 'create', array( + $priceFieldOption2 = civicrm_api3('PriceFieldValue', 'create', [ "price_field_id" => $priceField['id'], "name" => "membership_type_two", "label" => "Membership Type Two", @@ -1577,26 +1577,26 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 "financial_type_id" => "1", "non_deductible_amount" => "0.00", "contribution_type_id" => "2", - )); + ]); // assign profile with custom fields to contribution page - $profile = civicrm_api3('UFJoin', 'create', array( + $profile = civicrm_api3('UFJoin', 'create', [ 'module' => "CiviContribute", 'weight' => "1", 'uf_group_id' => $membershipCustomFieldsProfile['id'], "entity_table" => "civicrm_contribution_page", "entity_id" => $contribPage1, - )); + ]); $form = new CRM_Contribute_Form_Contribution_Confirm(); - $form->_params = array( + $form->_params = [ 'id' => $contribPage1, "qfKey" => "donotcare", "custom_{$membershipCustomField['id']}" => "Hello", "email-5" => "admin@example.com", "priceSetId" => $priceSet['id'], 'price_set_id' => $priceSet['id'], - "price_" . $priceField['id'] => array($priceFieldOption1['id'] => 1, $priceFieldOption2['id'] => 1), + "price_" . $priceField['id'] => [$priceFieldOption1['id'] => 1, $priceFieldOption2['id'] => 1], "invoiceID" => "9a6f7b49358dc31c3604e463b225c5be", "email" => "admin@example.com", "currencyID" => "USD", @@ -1608,18 +1608,18 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 'tax_amount' => 0.00, 'is_pay_later' => 1, 'is_quick_config' => 1, - ); + ]; $form->submit($form->_params); - $membership1 = civicrm_api3('Membership', 'getsingle', array( + $membership1 = civicrm_api3('Membership', 'getsingle', [ 'contact_id' => $contactID, 'membership_type_id' => $membershipTypeOne['id'], - )); + ]); $this->assertEquals("Hello", $membership1["custom_{$membershipCustomField['id']}"]); - $membership2 = civicrm_api3('Membership', 'getsingle', array( + $membership2 = civicrm_api3('Membership', 'getsingle', [ 'contact_id' => $contactID, 'membership_type_id' => $membershipTypeTwo['id'], - )); + ]); $this->assertEquals("Hello", $membership2["custom_{$membershipCustomField['id']}"]); } diff --git a/tests/phpunit/CRM/Contribute/Form/SearchTest.php b/tests/phpunit/CRM/Contribute/Form/SearchTest.php index bb7547e76b..1d9c3a0411 100644 --- a/tests/phpunit/CRM/Contribute/Form/SearchTest.php +++ b/tests/phpunit/CRM/Contribute/Form/SearchTest.php @@ -117,7 +117,7 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { $form->testProcessContribution($batchEntry); // fetch created contributions - $entities = $this->callAPISuccess('EntityBatch', 'get', array('batch_id' => $batchID)); + $entities = $this->callAPISuccess('EntityBatch', 'get', ['batch_id' => $batchID]); $ids = []; foreach ($entities['values'] as $value) { $ids[] = $value['entity_id']; @@ -127,29 +127,29 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { $useCases = [ // Case 1: Search for ONLY those contributions which are created from batch [ - 'form_value' => array('contribution_batch_id' => 'IS NOT NULL'), + 'form_value' => ['contribution_batch_id' => 'IS NOT NULL'], 'expected_count' => 2, - 'expected_contribution' => array($batchContriID1, $batchContriID2), + 'expected_contribution' => [$batchContriID1, $batchContriID2], 'expected_qill' => 'Batch Name Not Null', ], // Case 2: Search for ONLY those contributions which are NOT created from batch [ - 'form_value' => array('contribution_batch_id' => 'IS NULL'), + 'form_value' => ['contribution_batch_id' => 'IS NULL'], 'expected_count' => 1, - 'expected_contribution' => array($nonBatchContriID), + 'expected_contribution' => [$nonBatchContriID], 'expected_qill' => 'Batch Name Is Null', ], // Case 3: Search for ONLY those contributions which are created from batch ID - $batchID [ - 'form_value' => array('contribution_batch_id' => $batchID), + 'form_value' => ['contribution_batch_id' => $batchID], 'expected_count' => 2, - 'expected_contribution' => array($batchContriID1, $batchContriID2), + 'expected_contribution' => [$batchContriID1, $batchContriID2], 'expected_qill' => 'Batch Name = ' . $batchTitle, ], ]; foreach ($useCases as $case) { $fv = $case['form_value']; - CRM_Contact_BAO_Query::processSpecialFormValue($fv, array('contribution_batch_id')); + CRM_Contact_BAO_Query::processSpecialFormValue($fv, ['contribution_batch_id']); $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv)); list($select, $from, $where) = $query->query(); @@ -173,85 +173,85 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { */ public function testCardTypeFilter() { $this->quickCleanup($this->_tablesToTruncate); - $contactID1 = $this->individualCreate(array(), 1); - $contactID2 = $this->individualCreate(array(), 2); - $Contribution1 = $this->callAPISuccess('Contribution', 'create', array( + $contactID1 = $this->individualCreate([], 1); + $contactID2 = $this->individualCreate([], 2); + $Contribution1 = $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => 1, 'total_amount' => 100, 'receive_date' => date('Ymd'), 'payment_instrument' => 1, 'contribution_status_id' => 1, 'contact_id' => $contactID1, - )); - $params = array( + ]); + $params = [ 'to_financial_account_id' => 1, 'status_id' => 1, 'contribution_id' => $Contribution1['id'], 'payment_instrument_id' => 1, 'card_type_id' => 1, 'total_amount' => 100, - ); + ]; CRM_Core_BAO_FinancialTrxn::create($params); - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => 1, 'total_amount' => 150, 'receive_date' => date('Ymd'), 'payment_instrument' => 1, 'contribution_status_id' => 1, 'contact_id' => $contactID1, - )); - $Contribution3 = $this->callAPISuccess('Contribution', 'create', array( + ]); + $Contribution3 = $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => 1, 'total_amount' => 200, 'receive_date' => date('Ymd'), 'payment_instrument' => 1, 'contribution_status_id' => 1, 'contact_id' => $contactID2, - )); - $params = array( + ]); + $params = [ 'to_financial_account_id' => 1, 'status_id' => 1, 'contribution_id' => $Contribution3['id'], 'payment_instrument_id' => 1, 'card_type_id' => 2, 'total_amount' => 200, - ); + ]; CRM_Core_BAO_FinancialTrxn::create($params); - $useCases = array( + $useCases = [ // Case 1: Search for ONLY those contributions which have card type - array( - 'form_value' => array('financial_trxn_card_type_id' => 'IS NOT NULL'), + [ + 'form_value' => ['financial_trxn_card_type_id' => 'IS NOT NULL'], 'expected_count' => 2, - 'expected_contribution' => array($Contribution1['id'], $Contribution3['id']), + 'expected_contribution' => [$Contribution1['id'], $Contribution3['id']], 'expected_qill' => 'Card Type Not Null', - ), + ], // Case 2: Search for ONLY those contributions which have Card Type as Visa - array( - 'form_value' => array('financial_trxn_card_type_id' => array(1)), + [ + 'form_value' => ['financial_trxn_card_type_id' => [1]], 'expected_count' => 1, - 'expected_contribution' => array($Contribution1['id']), + 'expected_contribution' => [$Contribution1['id']], 'expected_qill' => 'Card Type In Visa', - ), + ], // Case 3: Search for ONLY those contributions which have Card Type as Amex - array( - 'form_value' => array('financial_trxn_card_type_id' => array(3)), + [ + 'form_value' => ['financial_trxn_card_type_id' => [3]], 'expected_count' => 0, - 'expected_contribution' => array(), + 'expected_contribution' => [], 'expected_qill' => 'Card Type In Amex', - ), + ], // Case 4: Search for ONLY those contributions which have Card Type as Visa or MasterCard - array( - 'form_value' => array('financial_trxn_card_type_id' => array(1, 2)), + [ + 'form_value' => ['financial_trxn_card_type_id' => [1, 2]], 'expected_count' => 2, - 'expected_contribution' => array($Contribution1['id'], $Contribution3['id']), + 'expected_contribution' => [$Contribution1['id'], $Contribution3['id']], 'expected_qill' => 'Card Type In Visa, MasterCard', - ), - ); + ], + ]; foreach ($useCases as $case) { $fv = $case['form_value']; - CRM_Contact_BAO_Query::processSpecialFormValue($fv, array('financial_trxn_card_type_id')); + CRM_Contact_BAO_Query::processSpecialFormValue($fv, ['financial_trxn_card_type_id']); $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv)); list($select, $from, $where) = $query->query(); @@ -275,17 +275,17 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { */ public function testCardNumberFilter() { $this->quickCleanup($this->_tablesToTruncate); - $contactID1 = $this->individualCreate(array(), 1); - $contactID2 = $this->individualCreate(array(), 2); - $Contribution1 = $this->callAPISuccess('Contribution', 'create', array( + $contactID1 = $this->individualCreate([], 1); + $contactID2 = $this->individualCreate([], 2); + $Contribution1 = $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => 1, 'total_amount' => 100, 'receive_date' => date('Ymd'), 'payment_instrument' => 1, 'contribution_status_id' => 1, 'contact_id' => $contactID1, - )); - $params = array( + ]); + $params = [ 'to_financial_account_id' => 1, 'status_id' => 1, 'contribution_id' => $Contribution1['id'], @@ -293,25 +293,25 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { 'card_type_id' => 1, 'total_amount' => 100, 'pan_truncation' => 1234, - ); + ]; CRM_Core_BAO_FinancialTrxn::create($params); - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => 1, 'total_amount' => 150, 'receive_date' => date('Ymd'), 'payment_instrument' => 1, 'contribution_status_id' => 1, 'contact_id' => $contactID1, - )); - $Contribution3 = $this->callAPISuccess('Contribution', 'create', array( + ]); + $Contribution3 = $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => 1, 'total_amount' => 200, 'receive_date' => date('Ymd'), 'payment_instrument' => 1, 'contribution_status_id' => 1, 'contact_id' => $contactID2, - )); - $params = array( + ]); + $params = [ 'to_financial_account_id' => 1, 'status_id' => 1, 'contribution_id' => $Contribution3['id'], @@ -319,36 +319,36 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { 'card_type_id' => 2, 'total_amount' => 200, 'pan_truncation' => 5678, - ); + ]; CRM_Core_BAO_FinancialTrxn::create($params); - $useCases = array( + $useCases = [ // Case 1: Search for ONLY those contributions which have card number - array( - 'form_value' => array('financial_trxn_pan_truncation' => 'IS NOT NULL'), + [ + 'form_value' => ['financial_trxn_pan_truncation' => 'IS NOT NULL'], 'expected_count' => 2, - 'expected_contribution' => array($Contribution1['id'], $Contribution3['id']), + 'expected_contribution' => [$Contribution1['id'], $Contribution3['id']], 'expected_qill' => 'Card Number Not Null', - ), + ], // Case 2: Search for ONLY those contributions which have Card Number as 1234 - array( - 'form_value' => array('financial_trxn_pan_truncation' => 1234), + [ + 'form_value' => ['financial_trxn_pan_truncation' => 1234], 'expected_count' => 1, - 'expected_contribution' => array($Contribution1['id']), + 'expected_contribution' => [$Contribution1['id']], 'expected_qill' => 'Card Number Like %1234%', - ), + ], // Case 3: Search for ONLY those contributions which have Card Number as 8888 - array( - 'form_value' => array('financial_trxn_pan_truncation' => 8888), + [ + 'form_value' => ['financial_trxn_pan_truncation' => 8888], 'expected_count' => 0, - 'expected_contribution' => array(), + 'expected_contribution' => [], 'expected_qill' => 'Card Number Like %8888%', - ), - ); + ], + ]; foreach ($useCases as $case) { $fv = $case['form_value']; - CRM_Contact_BAO_Query::processSpecialFormValue($fv, array('financial_trxn_pan_truncation')); + CRM_Contact_BAO_Query::processSpecialFormValue($fv, ['financial_trxn_pan_truncation']); $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv)); list($select, $from, $where) = $query->query(); diff --git a/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php b/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php index 745dd9f4b3..dedc0a997c 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php @@ -49,18 +49,18 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { * invoice pdf for pending and completed contributions */ public function testInvoiceForDueDate() { - $contactIds = array(); - $params = array( + $contactIds = []; + $params = [ 'output' => 'pdf_invoice', 'forPage' => 1, - ); + ]; $this->_individualId = $this->individualCreate(); - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'total_amount' => 100, 'financial_type_id' => 'Donation', - ); + ]; $result = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contributionParams['contribution_status_id'] = 2; @@ -68,15 +68,15 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contribution3 = $this->callAPISuccess('Contribution', 'create', $contributionParams); - $this->callAPISuccess('Payment', 'create', array('total_amount' => 8, 'contribution_id' => $contribution3['id'])); + $this->callAPISuccess('Payment', 'create', ['total_amount' => 8, 'contribution_id' => $contribution3['id']]); - $this->callAPISuccess('Contribution', 'create', array('id' => $contribution3['id'], 'is_pay_later' => 0)); + $this->callAPISuccess('Contribution', 'create', ['id' => $contribution3['id'], 'is_pay_later' => 0]); - $contributionIDs = array( - array($result['id']), - array($contribution['id']), - array($contribution3['id']), - ); + $contributionIDs = [ + [$result['id']], + [$contribution['id']], + [$contribution3['id']], + ]; $contactIds[] = $this->_individualId; foreach ($contributionIDs as $contributionID) { diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index b7eada9d98..0a696981e2 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -51,7 +51,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); - $this->_individualId = $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')); + $this->_individualId = $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']); $this->_docTypes = CRM_Core_SelectValues::documentApplicationType(); } @@ -60,7 +60,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_uf_match')); + $this->quickCleanup(['civicrm_uf_match']); CRM_Utils_Hook::singleton()->reset(); } @@ -70,45 +70,45 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { public function testBuildContributionArray() { $this->_individualId = $this->individualCreate(); - $customGroup = $this->callAPISuccess('CustomGroup', 'create', array( + $customGroup = $this->callAPISuccess('CustomGroup', 'create', [ 'title' => 'Test Custom Set for Contribution', 'extends' => 'Contribution', 'is_active' => TRUE, - )); - $params = array( + ]); + $params = [ 'custom_group_id' => $customGroup['id'], 'label' => 'Text field', 'html_type' => 'Text', 'data_type' => 'String', 'weight' => 1, 'is_active' => 1, - ); + ]; $customField = $this->callAPISuccess('CustomField', 'create', $params); $customFieldKey = 'custom_' . $customField['id']; $campaignTitle = 'Test Campaign ' . substr(sha1(rand()), 0, 7); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'total_amount' => 6, - 'campaign_id' => $this->campaignCreate(array('title' => $campaignTitle), FALSE), + 'campaign_id' => $this->campaignCreate(['title' => $campaignTitle], FALSE), 'financial_type_id' => 'Donation', $customFieldKey => 'Text_' . substr(sha1(rand()), 0, 7), - ); - $contributionIDs = $returnProperties = array(); + ]; + $contributionIDs = $returnProperties = []; $result = $this->callAPISuccess('Contribution', 'create', $params); $contributionIDs[] = $result['id']; - $this->hookClass->setHook('civicrm_tokenValues', array($this, 'hookTokenValues')); + $this->hookClass->setHook('civicrm_tokenValues', [$this, 'hookTokenValues']); // assume that there are two token {contribution.financial_type} and // {contribution.custom_N} in message content - $messageToken = array( - 'contribution' => array( + $messageToken = [ + 'contribution' => [ 'financial_type', 'payment_instrument', 'campaign', $customFieldKey, - ), - ); + ], + ]; list($contributions, $contacts) = CRM_Contribute_Form_Task_PDFLetterCommon::buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE); @@ -146,36 +146,36 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { public function testPostProcess() { $this->createLoggedInUser(); $this->_individualId = $this->individualCreate(); - foreach (array('docx', 'odt') as $docType) { - $formValues = array( + foreach (['docx', 'odt'] as $docType) { + $formValues = [ 'is_unit_test' => TRUE, 'group_by' => NULL, - 'document_file' => array( + 'document_file' => [ 'name' => __DIR__ . "/sample_documents/Template.$docType", 'type' => $this->_docTypes[$docType], - ), - ); + ], + ]; - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'total_amount' => 100, 'financial_type_id' => 'Donation', - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contributionId = $contribution['id']; $form = new CRM_Contribute_Form_Task_PDFLetter(); - $form->setContributionIds(array($contributionId)); + $form->setContributionIds([$contributionId]); $format = Civi::settings()->get('dateformatFull'); $date = CRM_Utils_Date::getToday(); $displayDate = CRM_Utils_Date::customFormat($date, $format); $html = CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($form, $formValues); - $expectedValues = array( + $expectedValues = [ 'Hello Anthony Collins', '$ 100.00', $displayDate, 'Donation', - ); + ]; foreach ($expectedValues as $val) { $this->assertTrue(strpos($html[$contributionId], $val) !== 0); @@ -191,43 +191,43 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { */ public function testPostProcessGroupByContact() { $this->createLoggedInUser(); - $this->hookClass->setHook('civicrm_tokenValues', array($this, 'hook_aggregateTokenValues')); - $this->hookClass->setHook('civicrm_tokens', array($this, 'hook_tokens')); + $this->hookClass->setHook('civicrm_tokenValues', [$this, 'hook_aggregateTokenValues']); + $this->hookClass->setHook('civicrm_tokens', [$this, 'hook_tokens']); $this->mut = new CiviMailUtils($this, TRUE); $this->_individualId = $this->individualCreate(); $this->_individualId2 = $this->individualCreate(); $htmlMessage = "{aggregate.rendered_token}"; - $formValues = array( + $formValues = [ 'is_unit_test' => TRUE, 'group_by' => 'contact_id', 'html_message' => $htmlMessage, 'email_options' => 'both', 'subject' => 'Testy test test', 'from' => 'info@example.com', - ); + ]; - $contributionIDs = array(); - $contribution = $this->callAPISuccess('Contribution', 'create', array( + $contributionIDs = []; + $contribution = $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $this->_individualId, 'total_amount' => 100, 'financial_type_id' => 'Donation', 'receive_date' => '2016-12-25', - )); + ]); $contributionIDs[] = $contribution['id']; - $contribution = $this->callAPISuccess('Contribution', 'create', array( + $contribution = $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $this->_individualId2, 'total_amount' => 10, 'financial_type_id' => 'Donation', 'receive_date' => '2016-12-25', - )); + ]); $contributionIDs[] = $contribution['id']; - $contribution = $this->callAPISuccess('Contribution', 'create', array( + $contribution = $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $this->_individualId2, 'total_amount' => 1, 'financial_type_id' => 'Donation', 'receive_date' => '2016-12-25', - )); + ]); $contributionIDs[] = $contribution['id']; $form = new CRM_Contribute_Form_Task_PDFLetter(); @@ -295,7 +295,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { ", $html[2]); - $activities = $this->callAPISuccess('Activity', 'get', array('activity_type_id' => 'Print PDF Letter', 'sequential' => 1)); + $activities = $this->callAPISuccess('Activity', 'get', ['activity_type_id' => 'Print PDF Letter', 'sequential' => 1]); $this->assertEquals(2, $activities['count']); $this->assertEquals($html[1], $activities['values'][0]['details']); $this->assertEquals($html[2], $activities['values'][1]['details']); @@ -311,7 +311,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { */ public function hook_tokens(&$tokens) { $this->hookTokensCalled++; - $tokens['aggregate'] = array('rendered_token' => 'rendered_token'); + $tokens['aggregate'] = ['rendered_token' => 'rendered_token']; } /** @@ -365,7 +365,7 @@ value=$contact_aggregate+$contribution.total_amount} * @param array $tokens * @param null $context */ - public function hook_aggregateTokenValues(&$values, $contactIDs, $job = NULL, $tokens = array(), $context = NULL) { + public function hook_aggregateTokenValues(&$values, $contactIDs, $job = NULL, $tokens = [], $context = NULL) { foreach ($contactIDs as $contactID) { CRM_Core_Smarty::singleton()->assign('messageContactID', $contactID); $values[$contactID]['aggregate.rendered_token'] = CRM_Core_Smarty::singleton() diff --git a/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php b/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php index 498efed17d..e7520a0b8e 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php @@ -48,30 +48,30 @@ class CRM_Contribute_Form_Task_StatusTest extends CiviUnitTestCase { $form = new CRM_Contribute_Form_Task_Status(); // create a pending contribution - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'total_amount' => 100, 'financial_type_id' => 'Donation', 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contributionId = $contribution['id']; - $form->setContributionIds(array($contributionId)); + $form->setContributionIds([$contributionId]); $form->buildQuickForm(); - $params = array( + $params = [ "contribution_status_id" => 1, "trxn_id_{$contributionId}" => NULL, "check_number_{$contributionId}" => NULL, "fee_amount_{$contributionId}" => 0, "trxn_date_{$contributionId}" => date('m/d/Y'), "payment_instrument_id_{$contributionId}" => 4, - ); + ]; CRM_Contribute_Form_Task_Status::processForm($form, $params); - $contribution = $this->callAPISuccess('Contribution', 'get', array('id' => $contributionId)); + $contribution = $this->callAPISuccess('Contribution', 'get', ['id' => $contributionId]); $updatedContribution = $contribution['values'][1]; $this->assertEquals('', $updatedContribution['contribution_source']); diff --git a/tests/phpunit/CRM/Contribute/Form/TaskTest.php b/tests/phpunit/CRM/Contribute/Form/TaskTest.php index 5cd4cdec9c..b0492e2045 100644 --- a/tests/phpunit/CRM/Contribute/Form/TaskTest.php +++ b/tests/phpunit/CRM/Contribute/Form/TaskTest.php @@ -45,30 +45,30 @@ class CRM_Contribute_Form_TaskTest extends CiviUnitTestCase { * executes without any error after sorting the search result. */ public function testPreProcessCommonAfterSorting() { - $fields = array( + $fields = [ 'source' => 'contribution_source', 'status' => 'contribution_status', 'financialTypes' => 'financial_type', - ); - $financialTypes = array('Member Dues', 'Event Fee', 'Donation'); - $status = array('Completed', 'Partially paid', 'Pending'); - $source = array('test source text', 'check source text', 'source text'); + ]; + $financialTypes = ['Member Dues', 'Event Fee', 'Donation']; + $status = ['Completed', 'Partially paid', 'Pending']; + $source = ['test source text', 'check source text', 'source text']; $this->_individualId = $this->individualCreate(); for ($i = 0; $i < 3; $i++) { - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'total_amount' => 100, 'source' => $source[$i], 'financial_type_id' => $financialTypes[$i], 'contribution_status_id' => $status[$i], - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contributionIds[] = $contribution['id']; } // Generate expected sorted array. - $expectedValues = array(); + $expectedValues = []; foreach ($fields as $key => $fld) { $sortedFields = array_combine($$key, $contributionIds); ksort($sortedFields); diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index ed21e72e2e..44dd252fb1 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -10,7 +10,7 @@ * @group headless */ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { - protected $_tablesToTruncate = array(); + protected $_tablesToTruncate = []; /** * Setup function. @@ -32,33 +32,33 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { */ public function testImportParserWithSoftCreditsByExternalIdentifier($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); - $contact1Params = array( + $contact1Params = [ 'first_name' => 'Contact', 'last_name' => 'One', 'external_identifier' => 'ext-1', 'contact_type' => 'Individual', - ); - $contact2Params = array( + ]; + $contact2Params = [ 'first_name' => 'Contact', 'last_name' => 'Two', 'external_identifier' => 'ext-2', 'contact_type' => 'Individual', - ); + ]; $contact1Id = $this->individualCreate($contact1Params); $contact2Id = $this->individualCreate($contact2Params); - $values = array( + $values = [ "total_amount" => $this->formatMoneyInput(1230.99), "financial_type" => "Donation", "external_identifier" => "ext-1", "soft_credit" => "ext-2", - ); - $mapperSoftCredit = array(NULL, NULL, NULL, "external_identifier"); - $mapperSoftCreditType = array(NULL, NULL, NULL, "1"); + ]; + $mapperSoftCredit = [NULL, NULL, NULL, "external_identifier"]; + $mapperSoftCreditType = [NULL, NULL, NULL, "1"]; $this->runImport($values, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Contribute_Import_Parser::SOFT_CREDIT, $mapperSoftCredit, NULL, $mapperSoftCreditType); - $params = array( + $params = [ "contact_id" => $contact1Id, - ); - $values = array(); + ]; + $values = []; $contributionsOfMainContact = CRM_Contribute_BAO_Contribution::retrieve($params, $values, $values); $this->assertEquals(1230.99, $contributionsOfMainContact->total_amount); $this->assertEquals(1230.99, $contributionsOfMainContact->net_amount); diff --git a/tests/phpunit/CRM/Contribute/Page/AjaxTest.php b/tests/phpunit/CRM/Contribute/Page/AjaxTest.php index ff19b9eb99..bb2178d849 100644 --- a/tests/phpunit/CRM/Contribute/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Contribute/Page/AjaxTest.php @@ -31,30 +31,30 @@ */ class CRM_Contribute_Page_AjaxTest extends CiviUnitTestCase { - protected $_params = array(); + protected $_params = []; public function setUp() { parent::setUp(); - $this->_fields = array('amount', 'sct_label'); + $this->_fields = ['amount', 'sct_label']; - $this->_params = array( + $this->_params = [ 'page' => 1, 'rp' => 50, 'offset' => 0, 'rowCount' => 50, 'sort' => NULL, 'is_unit_test' => TRUE, - ); - $softContactParams = array( + ]; + $softContactParams = [ 'first_name' => 'soft', 'last_name' => 'Contact', - ); + ]; $this->_softContactId = $this->individualCreate($softContactParams); //create three sample contacts - foreach (array(0, 1, 2) as $seq) { - $this->_primaryContacts[] = $this->individualCreate(array(), $seq); + foreach ([0, 1, 2] as $seq) { + $this->_primaryContacts[] = $this->individualCreate([], $seq); } } @@ -62,48 +62,48 @@ class CRM_Contribute_Page_AjaxTest extends CiviUnitTestCase { * Test retrieve Soft Contribution through AJAX */ public function testGetSoftContributionSelector() { - $softTypes = array(3, 2, 5); - $amounts = array('100', '600', '150'); + $softTypes = [3, 2, 5]; + $amounts = ['100', '600', '150']; // create sample soft contribution for contact foreach ($this->_primaryContacts as $seq => $contactId) { - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $contactId, 'receive_date' => date('Ymd'), 'total_amount' => $amounts[$seq], 'financial_type_id' => 1, 'non_deductible_amount' => '10', 'contribution_status_id' => 1, - 'soft_credit' => array( - '1' => array( + 'soft_credit' => [ + '1' => [ 'contact_id' => $this->_softContactId, 'amount' => $amounts[$seq], 'soft_credit_type_id' => $softTypes[$seq], - ), - ), - )); + ], + ], + ]); } $_GET = array_merge($this->_params, - array( + [ 'cid' => $this->_softContactId, 'context' => 'contribution', - ) + ] ); $softCreditList = CRM_Contribute_Page_AJAX::getSoftContributionRows(); foreach ($this->_fields as $columnName) { - $_GET['columns'][] = array( + $_GET['columns'][] = [ 'data' => $columnName, - ); + ]; } // get the results in descending order - $_GET['order'] = array( - '0' => array( + $_GET['order'] = [ + '0' => [ 'column' => 0, 'dir' => 'desc', - ), - ); + ], + ]; $amountSortedList = CRM_Contribute_Page_AJAX::getSoftContributionRows(); $this->assertEquals(3, $softCreditList['recordsTotal']); @@ -131,7 +131,7 @@ class CRM_Contribute_Page_AjaxTest extends CiviUnitTestCase { */ public function testGetSoftContributionForMembership() { //Check soft credit for membership - $memParams = array( + $memParams = [ 'contribution_contact_id' => $this->_primaryContacts[0], 'contact_id' => $this->_softContactId, 'contribution_status_id' => 1, @@ -139,17 +139,17 @@ class CRM_Contribute_Page_AjaxTest extends CiviUnitTestCase { 'status_id' => 1, 'total_amount' => 100, 'receive_date' => '2018-06-08', - 'soft_credit' => array( + 'soft_credit' => [ 'soft_credit_type_id' => 11, 'contact_id' => $this->_softContactId, - ), - ); + ], + ]; $_GET = array_merge($this->_params, - array( + [ 'cid' => $this->_softContactId, 'context' => 'membership', 'entityID' => $this->contactMembershipCreate($memParams), - ) + ] ); $softCreditList = CRM_Contribute_Page_AJAX::getSoftContributionRows(); diff --git a/tests/phpunit/CRM/Contribute/Selector/SearchTest.php b/tests/phpunit/CRM/Contribute/Selector/SearchTest.php index d9abb3e2e3..56455b28ae 100644 --- a/tests/phpunit/CRM/Contribute/Selector/SearchTest.php +++ b/tests/phpunit/CRM/Contribute/Selector/SearchTest.php @@ -36,7 +36,7 @@ class CRM_Contribute_Selector_SearchTest extends CiviUnitTestCase { * CRM-20866 - Soft credit appearance inconsistent in contribution search */ public function testSoftCreditFieldsSelected() { - $queryParams = array(array('contribution_or_softcredits', '=', 'both_related', 0, 0)); + $queryParams = [['contribution_or_softcredits', '=', 'both_related', 0, 0]]; $searchSelector = new CRM_Contribute_Selector_Search($queryParams, CRM_Core_Action::VIEW); list($select, $from, $where, $having) = $searchSelector->getQuery()->query(); @@ -47,7 +47,7 @@ class CRM_Contribute_Selector_SearchTest extends CiviUnitTestCase { * CRM-20866 - Soft credit appearance inconsistent in contribution search */ public function testSoftCreditFieldNotSelected() { - $queryParams = array(array('contribution_or_softcredits', '=', 'only_contribs', 0, 0)); + $queryParams = [['contribution_or_softcredits', '=', 'only_contribs', 0, 0]]; $searchSelector = new CRM_Contribute_Selector_Search($queryParams, CRM_Core_Action::VIEW); list($select, $from, $where, $having) = $searchSelector->getQuery()->query(); diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index 4365f21e4c..0e5af472a5 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -46,84 +46,84 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->mut = new CiviMailUtils($this, TRUE); - $this->fixtures['rolling_membership_type'] = array( + $this->fixtures['rolling_membership_type'] = [ 'period_type' => 'rolling', 'duration_unit' => 'month', 'duration_interval' => '3', 'is_active' => 1, 'domain_id' => 1, 'financial_type_id' => 2, - ); + ]; - $this->fixtures['rolling_membership'] = array( - 'membership_type_id' => array( + $this->fixtures['rolling_membership'] = [ + 'membership_type_id' => [ 'period_type' => 'rolling', 'duration_unit' => 'month', 'duration_interval' => '3', 'is_active' => 1, - ), + ], 'join_date' => '20120315', 'start_date' => '20120315', 'end_date' => '20120615', 'is_override' => 0, - ); + ]; - $this->fixtures['rolling_membership_past'] = array( - 'membership_type_id' => array( + $this->fixtures['rolling_membership_past'] = [ + 'membership_type_id' => [ 'period_type' => 'rolling', 'duration_unit' => 'month', 'duration_interval' => '3', 'is_active' => 1, - ), + ], 'join_date' => '20100310', 'start_date' => '20100310', 'end_date' => '20100610', 'is_override' => 'NULL', - ); - $this->fixtures['participant'] = array( - 'event_id' => array( + ]; + $this->fixtures['participant'] = [ + 'event_id' => [ 'is_active' => 1, 'is_template' => 0, 'title' => 'Example Event', 'start_date' => '20120315', 'end_date' => '20120615', - ), + ], // Attendee. 'role_id' => '1', // No-show. 'status_id' => '8', - ); + ]; - $this->fixtures['phonecall'] = array( + $this->fixtures['phonecall'] = [ 'status_id' => 1, 'activity_type_id' => 2, 'activity_date_time' => '20120615100000', 'is_current_revision' => 1, 'is_deleted' => 0, - ); - $this->fixtures['contact'] = array( + ]; + $this->fixtures['contact'] = [ 'is_deceased' => 0, 'contact_type' => 'Individual', 'email' => 'test-member@example.com', 'gender_id' => 'Female', 'first_name' => 'Churmondleia', 'last_name' => 'Ōtākou', - ); - $this->fixtures['contact_2'] = array( + ]; + $this->fixtures['contact_2'] = [ 'is_deceased' => 0, 'contact_type' => 'Individual', 'email' => 'test-contact-2@example.com', 'gender_id' => 'Male', 'first_name' => 'Fabble', 'last_name' => 'Fi', - ); - $this->fixtures['contact_birthdate'] = array( + ]; + $this->fixtures['contact_birthdate'] = [ 'is_deceased' => 0, 'contact_type' => 'Individual', 'email' => 'test-bday@example.com', 'birth_date' => '20050707', - ); - $this->fixtures['sched_activity_1day'] = array( + ]; + $this->fixtures['sched_activity_1day'] = [ 'name' => 'One_Day_Phone_Call_Notice', 'title' => 'One Day Phone Call Notice', 'limit_to' => '1', @@ -152,8 +152,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => '1-Day (non-repeating) (about {activity.activity_type})', - ); - $this->fixtures['sched_activity_1day_r'] = array( + ]; + $this->fixtures['sched_activity_1day_r'] = [ 'name' => 'One_Day_Phone_Call_Notice_R', 'title' => 'One Day Phone Call Notice R', 'limit_to' => 1, @@ -182,8 +182,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => '1-Day (repeating) (about {activity.activity_type})', - ); - $this->fixtures['sched_activity_1day_r_on_abs_date'] = array( + ]; + $this->fixtures['sched_activity_1day_r_on_abs_date'] = [ 'name' => 'One_Day_Phone_Call_Notice_R', 'title' => 'One Day Phone Call Notice R', 'limit_to' => 1, @@ -212,8 +212,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '', 'start_action_unit' => '', 'subject' => '1-Day (repeating) (about {activity.activity_type})', - ); - $this->fixtures['sched_eventname_1day_on_abs_date'] = array( + ]; + $this->fixtures['sched_eventname_1day_on_abs_date'] = [ 'name' => 'sched_eventname_1day_on_abs_date', 'title' => 'sched_eventname_1day_on_abs_date', 'limit_to' => 1, @@ -242,8 +242,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => NULL, 'start_action_unit' => NULL, 'subject' => 'sched_eventname_1day_on_abs_date', - ); - $this->fixtures['sched_membership_join_2week'] = array( + ]; + $this->fixtures['sched_membership_join_2week'] = [ 'name' => 'sched_membership_join_2week', 'title' => 'sched_membership_join_2week', 'absolute_date' => '', @@ -271,8 +271,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '2', 'start_action_unit' => 'week', 'subject' => 'subject sched_membership_join_2week (joined {membership.join_date})', - ); - $this->fixtures['sched_membership_start_1week'] = array( + ]; + $this->fixtures['sched_membership_start_1week'] = [ 'name' => 'sched_membership_start_1week', 'title' => 'sched_membership_start_1week', 'absolute_date' => '', @@ -300,8 +300,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'week', 'subject' => 'subject sched_membership_start_1week (joined {membership.start_date})', - ); - $this->fixtures['sched_membership_end_2week'] = array( + ]; + $this->fixtures['sched_membership_end_2week'] = [ 'name' => 'sched_membership_end_2week', 'title' => 'sched_membership_end_2week', 'absolute_date' => '', @@ -329,8 +329,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '2', 'start_action_unit' => 'week', 'subject' => 'subject sched_membership_end_2week', - ); - $this->fixtures['sched_on_membership_end_date'] = array( + ]; + $this->fixtures['sched_on_membership_end_date'] = [ 'name' => 'sched_on_membership_end_date', 'title' => 'sched_on_membership_end_date', 'body_html' => '

Your membership expired today

', @@ -343,8 +343,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '0', 'start_action_unit' => 'hour', 'subject' => 'subject send reminder on membership_end_date', - ); - $this->fixtures['sched_after_1day_membership_end_date'] = array( + ]; + $this->fixtures['sched_after_1day_membership_end_date'] = [ 'name' => 'sched_after_1day_membership_end_date', 'title' => 'sched_after_1day_membership_end_date', 'body_html' => '

Your membership expired yesterday

', @@ -357,9 +357,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject send reminder on membership_end_date', - ); + ]; - $this->fixtures['sched_membership_end_2month'] = array( + $this->fixtures['sched_membership_end_2month'] = [ 'name' => 'sched_membership_end_2month', 'title' => 'sched_membership_end_2month', 'absolute_date' => '', @@ -387,9 +387,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '2', 'start_action_unit' => 'month', 'subject' => 'subject sched_membership_end_2month', - ); + ]; - $this->fixtures['sched_membership_absolute_date'] = array( + $this->fixtures['sched_membership_absolute_date'] = [ 'name' => 'sched_membership_absolute_date', 'title' => 'sched_membership_absolute_date', 'absolute_date' => CRM_Utils_Date::processDate('20120614100000'), @@ -417,9 +417,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '', 'start_action_unit' => '', 'subject' => 'subject sched_membership_absolute_date', - ); + ]; - $this->fixtures['sched_contact_bday_yesterday'] = array( + $this->fixtures['sched_contact_bday_yesterday'] = [ 'name' => 'sched_contact_bday_yesterday', 'title' => 'sched_contact_bday_yesterday', 'absolute_date' => '', @@ -447,9 +447,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject sched_contact_bday_yesterday', - ); + ]; - $this->fixtures['sched_contact_bday_anniv'] = array( + $this->fixtures['sched_contact_bday_anniv'] = [ 'name' => 'sched_contact_bday_anniv', 'title' => 'sched_contact_bday_anniv', 'absolute_date' => '', @@ -477,9 +477,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject sched_contact_bday_anniv', - ); + ]; - $this->fixtures['sched_contact_grad_tomorrow'] = array( + $this->fixtures['sched_contact_grad_tomorrow'] = [ 'name' => 'sched_contact_grad_tomorrow', 'title' => 'sched_contact_grad_tomorrow', 'absolute_date' => '', @@ -506,9 +506,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject sched_contact_grad_tomorrow', - ); + ]; - $this->fixtures['sched_contact_grad_anniv'] = array( + $this->fixtures['sched_contact_grad_anniv'] = [ 'name' => 'sched_contact_grad_anniv', 'title' => 'sched_contact_grad_anniv', 'absolute_date' => '', @@ -535,9 +535,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'week', 'subject' => 'subject sched_contact_grad_anniv', - ); + ]; - $this->fixtures['sched_contact_created_yesterday'] = array( + $this->fixtures['sched_contact_created_yesterday'] = [ 'name' => 'sched_contact_created_yesterday', 'title' => 'sched_contact_created_yesterday', 'absolute_date' => '', @@ -565,9 +565,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject sched_contact_created_yesterday', - ); + ]; - $this->fixtures['sched_contact_mod_anniv'] = array( + $this->fixtures['sched_contact_mod_anniv'] = [ 'name' => 'sched_contact_mod_anniv', 'title' => 'sched_contact_mod_anniv', 'absolute_date' => '', @@ -595,9 +595,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject sched_contact_mod_anniv', - ); + ]; - $this->fixtures['sched_eventtype_start_1week_before'] = array( + $this->fixtures['sched_eventtype_start_1week_before'] = [ 'name' => 'sched_eventtype_start_1week_before', 'title' => 'sched_eventtype_start_1week_before', 'absolute_date' => '', @@ -628,8 +628,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'week', 'subject' => 'subject sched_eventtype_start_1week_before ({event.title})', - ); - $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'] = array( + ]; + $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'] = [ 'name' => 'sched_eventtype_end_2month_repeat_twice_2_weeks', 'title' => 'sched_eventtype_end_2month_repeat_twice_2_weeks', 'absolute_date' => '', @@ -660,9 +660,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '2', 'start_action_unit' => 'month', 'subject' => 'subject sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}', - ); + ]; - $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = array( + $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = [ 'name' => 'sched_membership_end_2month', 'title' => 'sched_membership_end_2month', 'absolute_date' => '', @@ -690,8 +690,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '2', 'start_action_unit' => 'month', 'subject' => 'subject sched_membership_end_2month', - ); - $this->fixtures['sched_membership_end_limit_to_none'] = array( + ]; + $this->fixtures['sched_membership_end_limit_to_none'] = [ 'name' => 'limit to none', 'title' => 'limit to none', 'absolute_date' => '', @@ -720,8 +720,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '2', 'start_action_unit' => 'month', 'subject' => 'limit to none', - ); - $this->fixtures['sched_on_membership_end_date_repeat_interval'] = array( + ]; + $this->fixtures['sched_on_membership_end_date_repeat_interval'] = [ 'name' => 'sched_on_membership_end_date', 'title' => 'sched_on_membership_end_date', 'body_html' => '

Your membership expired 1 unit ago

', @@ -737,9 +737,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '0', 'start_action_unit' => 'hour', 'subject' => 'subject send reminder every unit after membership_end_date', - ); + ]; - $customGroup = $this->callAPISuccess('CustomGroup', 'create', array( + $customGroup = $this->callAPISuccess('CustomGroup', 'create', [ 'title' => ts('Test Contact Custom group'), 'name' => 'test_contact_cg', 'extends' => 'Contact', @@ -747,19 +747,19 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'is_active' => 1, 'collapse_adv_display' => 0, 'collapse_display' => 0, - )); - $customField = $this->callAPISuccess('CustomField', 'create', array( + ]); + $customField = $this->callAPISuccess('CustomField', 'create', [ 'label' => 'Test Text', 'data_type' => 'String', 'html_type' => 'Text', 'custom_group_id' => $customGroup['id'], - )); - $this->fixtures['contact_custom_token'] = array( + ]); + $this->fixtures['contact_custom_token'] = [ 'id' => $customField['id'], 'token' => sprintf('{contact.custom_%s}', $customField['id']), 'name' => sprintf('custom_%s', $customField['id']), 'value' => 'text ' . substr(sha1(rand()), 0, 7), - ); + ]; $this->_setUp(); } @@ -774,26 +774,26 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->mut->clearMessages(); $this->mut->stop(); unset($this->mut); - $this->quickCleanup(array( + $this->quickCleanup([ 'civicrm_action_schedule', 'civicrm_action_log', 'civicrm_membership', 'civicrm_participant', 'civicrm_event', 'civicrm_email', - )); - $this->callAPISuccess('CustomField', 'delete', array('id' => $this->fixtures['contact_custom_token']['id'])); - $this->callAPISuccess('CustomGroup', 'delete', array( + ]); + $this->callAPISuccess('CustomField', 'delete', ['id' => $this->fixtures['contact_custom_token']['id']]); + $this->callAPISuccess('CustomGroup', 'delete', [ 'id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'test_contact_cg', 'id', 'name'), - )); + ]); $this->_tearDown(); } public function mailerExamples() { - $cases = array(); + $cases = []; // Some tokens - short as subject has 128char limit in DB. - $someTokensTmpl = implode(';;', array( + $someTokensTmpl = implode(';;', [ // basic contact token '{contact.display_name}', // funny legacy contact token @@ -804,77 +804,77 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { '{domain.name}', // action-scheduler token '{activity.activity_type}', - )); + ]); // Further tokens can be tested in the body text/html. - $manyTokensTmpl = implode(';;', array( + $manyTokensTmpl = implode(';;', [ $someTokensTmpl, '{contact.email_greeting}', $this->fixture['contact_custom_token']['token'], - )); + ]); // Note: The behavior of domain-tokens on a scheduled reminder is undefined. All we // can really do is check that it has something. $someTokensExpected = 'Churmondleia Ōtākou;;Female;;Female;;[a-zA-Z0-9 ]+;;Phone Call'; $manyTokensExpected = sprintf('%s;;Dear Churmondleia;;%s', $someTokensExpected, $this->fixture['contact_custom_token']['value']); // In this example, we use a lot of tokens cutting across multiple components. - $cases[0] = array( + $cases[0] = [ // Schedule definition. - array( + [ 'subject' => "subj $someTokensTmpl", 'body_html' => "html $manyTokensTmpl", 'body_text' => "text $manyTokensTmpl", - ), + ], // Assertions (regex). - array( + [ 'from_name' => "/^FIXME\$/", 'from_email' => "/^info@EXAMPLE.ORG\$/", 'subject' => "/^subj $someTokensExpected\$/", 'body_html' => "/^html $manyTokensExpected\$/", 'body_text' => "/^text $manyTokensExpected\$/", - ), - ); + ], + ]; // In this example, we customize the from address. - $cases[1] = array( + $cases[1] = [ // Schedule definition. - array( + [ 'from_name' => 'Bob', 'from_email' => 'bob@example.org', - ), + ], // Assertions (regex). - array( + [ 'from_name' => "/^Bob\$/", 'from_email' => "/^bob@example.org\$/", - ), - ); + ], + ]; // In this example, we autoconvert HTML to text - $cases[2] = array( + $cases[2] = [ // Schedule definition. - array( + [ 'body_html' => '

Hello & stuff.

', 'body_text' => '', - ), + ], // Assertions (regex). - array( + [ 'body_html' => '/^' . preg_quote('

Hello & stuff.

', '/') . '/', 'body_text' => '/^' . preg_quote('Hello & stuff.', '/') . '/', - ), - ); + ], + ]; // In this example, we autoconvert HTML to text - $cases[3] = array( + $cases[3] = [ // Schedule definition. - array( + [ 'body_html' => '', 'body_text' => 'Hello world', - ), + ], // Assertions (regex). - array( + [ 'body_html' => '/^--UNDEFINED--$/', 'body_text' => '/^Hello world$/', - ), - ); + ], + ]; return $cases; } @@ -903,9 +903,9 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($activity->id)); $contact = $this->callAPISuccess('contact', 'create', array_merge( $this->fixtures['contact'], - array( + [ $this->fixtures['contact_custom_token']['name'] => $this->fixtures['contact_custom_token']['value'], - ) + ] )); $activity->save(); @@ -916,12 +916,12 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $activityContact->save(); CRM_Utils_Time::setTime('2012-06-14 15:00:00'); - $this->callAPISuccess('job', 'send_reminder', array()); - $this->mut->assertRecipients(array(array('test-member@example.com'))); + $this->callAPISuccess('job', 'send_reminder', []); + $this->mut->assertRecipients([['test-member@example.com']]); foreach ($this->mut->getAllMessages('ezc') as $message) { /** @var ezcMail $message */ - $messageArray = array(); + $messageArray = []; $messageArray['subject'] = $message->subject; $messageArray['from_name'] = $message->from->name; $messageArray['from_email'] = $message->from->email; @@ -940,7 +940,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { foreach ($patterns as $field => $pattern) { $this->assertRegExp($pattern, $messageArray[$field], - "Check that '$field'' matches regex. " . print_r(array('expected' => $patterns, 'actual' => $messageArray), 1)); + "Check that '$field'' matches regex. " . print_r(['expected' => $patterns, 'actual' => $messageArray], 1)); } } $this->mut->clearMessages(); @@ -962,25 +962,25 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source); $activityContact->save(); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 24-hour mark, no email 'time' => '2012-06-14 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // After the 24-hour mark, an email 'time' => '2012-06-14 15:00:00', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('1-Day (non-repeating) (about Phone Call)'), - ), - array( + 'recipients' => [['test-member@example.com']], + 'subjects' => ['1-Day (non-repeating) (about Phone Call)'], + ], + [ // Run cron again; message already sent 'time' => '', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $activityDAO = new CRM_Activity_DAO_Activity(); $activityDAO->source_record_id = $activity->id; @@ -1006,32 +1006,32 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source); $activityContact->save(); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 24-hour mark, no email 'time' => '012-06-14 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // After the 24-hour mark, an email 'time' => '2012-06-14 15:00:00', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('1-Day (repeating) (about Phone Call)'), - ), - array( + 'recipients' => [['test-member@example.com']], + 'subjects' => ['1-Day (repeating) (about Phone Call)'], + ], + [ // Run cron 4 hours later; first message already sent 'time' => '2012-06-14 20:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // Run cron 6 hours later; send second message. 'time' => '2012-06-14 21:00:01', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('1-Day (repeating) (about Phone Call)'), - ), - )); + 'recipients' => [['test-member@example.com']], + 'subjects' => ['1-Day (repeating) (about Phone Call)'], + ], + ]); } public function testActivityDateTimeMatchRepeatableScheduleOnAbsDate() { @@ -1049,66 +1049,66 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source); $activityContact->save(); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 24-hour mark, no email 'time' => '2012-06-13 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // On absolute date set on 2012-06-14 'time' => '2012-06-14 00:00:00', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('1-Day (repeating) (about Phone Call)'), - ), - array( + 'recipients' => [['test-member@example.com']], + 'subjects' => ['1-Day (repeating) (about Phone Call)'], + ], + [ // Run cron 4 hours later; first message already sent 'time' => '2012-06-14 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // Run cron 6 hours later; send second message. 'time' => '2012-06-14 06:00:01', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('1-Day (repeating) (about Phone Call)'), - ), - )); + 'recipients' => [['test-member@example.com']], + 'subjects' => ['1-Day (repeating) (about Phone Call)'], + ], + ]); } public function testEventNameWithAbsoluteDateAndNothingElse() { - $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 1))); - $this->callAPISuccess('Email', 'create', array( + $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], ['status_id' => 1])); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $participant->contact_id, 'email' => 'test-event@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id))); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id])); $actionSchedule = $this->fixtures['sched_eventname_1day_on_abs_date']; $actionSchedule['entity_value'] = $participant->event_id; $this->callAPISuccess('action_schedule', 'create', $actionSchedule); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 24-hour mark, no email 'time' => '2012-06-13 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // On absolute date set on 2012-06-14 'time' => '2012-06-14 00:00:00', - 'recipients' => array(array('test-event@example.com')), - 'subjects' => array('sched_eventname_1day_on_abs_date'), - ), - array( + 'recipients' => [['test-event@example.com']], + 'subjects' => ['sched_eventname_1day_on_abs_date'], + ], + [ // Run cron 4 hours later; first message already sent 'time' => '2012-06-14 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - )); + 'recipients' => [], + 'subjects' => [], + ], + ]); } /** @@ -1122,36 +1122,36 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { * an email should be sent. */ public function testMembershipDateMatch() { - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 1))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 1])); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'test-member@example.com', 'location_type_id' => 1, 'is_primary' => 1, - )); + ]); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $actionSchedule = $this->fixtures['sched_membership_join_2week']; $actionSchedule['entity_value'] = $membership->membership_type_id; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); // start_date=2012-03-15 ; schedule is 2 weeks after join_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email. 'time' => '2012-03-28 01:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // After the 2-week mark, send an email. 'time' => '2012-03-29 01:00:00', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('subject sched_membership_join_2week (joined March 15th, 2012)'), - ), - )); + 'recipients' => [['test-member@example.com']], + 'subjects' => ['subject sched_membership_join_2week (joined March 15th, 2012)'], + ], + ]); $actionSchedule = $this->fixtures['sched_membership_start_1week']; $actionSchedule['entity_value'] = $membership->membership_type_id; @@ -1159,20 +1159,20 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($actionScheduleDao->id)); // start_date=2012-03-15 ; schedule is 1 weeks after start_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email. 'time' => '2012-03-21 01:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // After the 2-week mark, send an email. 'time' => '2012-03-22 01:00:00', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('subject sched_membership_start_1week (joined March 15th, 2012)'), - ), - )); + 'recipients' => [['test-member@example.com']], + 'subjects' => ['subject sched_membership_start_1week (joined March 15th, 2012)'], + ], + ]); } /** @@ -1180,31 +1180,31 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testScheduleReminderWithParentGroup() { // Contact A with birth-date at '07-07-2005' and gender - Male, later got added in smart group - $contactID1 = $this->individualCreate(array('birth_date' => '20050707', 'gender_id' => 1, 'email' => 'abc@test.com')); + $contactID1 = $this->individualCreate(['birth_date' => '20050707', 'gender_id' => 1, 'email' => 'abc@test.com']); // Contact B with birth-date at '07-07-2005', later got added in regular group - $contactID2 = $this->individualCreate(array('birth_date' => '20050707', 'email' => 'def@test.com'), 1); + $contactID2 = $this->individualCreate(['birth_date' => '20050707', 'email' => 'def@test.com'], 1); // Contact C with birth-date at '07-07-2005', but not included in any group - $contactID3 = $this->individualCreate(array('birth_date' => '20050707', 'email' => 'ghi@test.com'), 2); + $contactID3 = $this->individualCreate(['birth_date' => '20050707', 'email' => 'ghi@test.com'], 2); // create regular group and add Contact B to it $groupID = $this->groupCreate(); - $this->callAPISuccess('GroupContact', 'Create', array( + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID2, - )); + ]); // create smart group which will contain all Male contacts - $smartGroupParams = array('formValues' => array('gender_id' => 1)); + $smartGroupParams = ['formValues' => ['gender_id' => 1]]; $smartGroupID = $this->smartGroupCreate( $smartGroupParams, - array( + [ 'name' => 'new_smart_group', 'title' => 'New Smart Group', - 'parents' => array($groupID => 1), - ) + 'parents' => [$groupID => 1], + ] ); - $actionScheduleParams = array( + $actionScheduleParams = [ 'name' => 'sched_contact_bday_yesterday', 'title' => 'sched_contact_bday_yesterday', 'absolute_date' => '', @@ -1233,31 +1233,31 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => 'subject sched_contact_bday_yesterday', - ); + ]; // Create schedule reminder where parent group ($groupID) is selectd to limit recipients, // which contain a individual contact - $contactID2 and is parent to smart group. $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionScheduleParams); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On the birthday, no email. 'time' => '2005-07-07 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // The next day, send an email. 'time' => '2005-07-08 20:00:00', - 'recipients' => array( - array( + 'recipients' => [ + [ 'def@test.com', - ), - array( + ], + [ 'abc@test.com', - ), - ), - ), - )); + ], + ], + ], + ]); $this->groupDelete($smartGroupID); $this->groupDelete($groupID); } @@ -1271,14 +1271,14 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { public function testMembershipJoinDateNonMatch() { $membership = $this->createTestObject('CRM_Member_DAO_Membership', $this->fixtures['rolling_membership']); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'location_type_id' => 1, 'email' => 'test-member@example.com', - )); + ]); // Add an alternative membership type, and only send messages for that type - $extraMembershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', array()); + $extraMembershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', []); $this->assertTrue(is_numeric($extraMembershipType->id)); $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures['sched_membership_join_2week']); $this->assertTrue(is_numeric($actionScheduleDao->id)); @@ -1286,13 +1286,13 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionScheduleDao->save(); // start_date=2012-03-15 ; schedule is 2 weeks after start_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // After the 2-week mark, don't send email because we have different membership type. 'time' => '2012-03-29 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } /** @@ -1300,58 +1300,58 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testMembershipEndDateRepeat() { // creates membership with end_date = 20120615 - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); - $result = $this->callAPISuccess('Email', 'create', array( + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2])); + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'test-member@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks']; $actionSchedule['entity_value'] = $membership->membership_type_id; $this->callAPISuccess('action_schedule', 'create', $actionSchedule); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // After the 1-month mark, no email 'time' => '2012-07-15 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-month mark, send an email. 'time' => '2012-08-15 01:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - array( + 'recipients' => [['test-member@example.com']], + ], + [ // 4 weeks after first email send first repeat 'time' => '2012-09-12 01:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - array( + 'recipients' => [['test-member@example.com']], + ], + [ // 1 week after first repeat send nothing // There was a bug where the first repeat went out and then // it would keep going out every cron run. This is to check that's // not happening. 'time' => '2012-09-19 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // 4 weeks after first repeat send second repeat 'time' => '2012-10-10 01:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - array( + 'recipients' => [['test-member@example.com']], + ], + [ // 4 months after membership end, send nothing 'time' => '2012-10-15 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // 5 months after membership end, send nothing 'time' => '2012-11-15 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } /** @@ -1363,34 +1363,34 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testMembershipEndDateRepeatChangedEndDate_CRM_15376() { // creates membership with end_date = 20120615 - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); - $this->callAPISuccess('Email', 'create', array( + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2])); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'test-member@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks']; $actionSchedule['entity_value'] = $membership->membership_type_id; $this->callAPISuccess('action_schedule', 'create', $actionSchedule); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // After the 2-week mark, send an email. 'time' => '2012-08-15 01:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - )); + 'recipients' => [['test-member@example.com']], + ], + ]); // Extend membership - reminder should NOT go out. - $this->callAPISuccess('membership', 'create', array('id' => $membership->id, 'end_date' => '2014-01-01')); - $this->assertCronRuns(array( - array( + $this->callAPISuccess('membership', 'create', ['id' => $membership->id, 'end_date' => '2014-01-01']); + $this->assertCronRuns([ + [ // After the 2-week mark, send an email. 'time' => '2012-09-12 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } /** @@ -1401,13 +1401,13 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testMembershipEndDateMatch() { // creates membership with end_date = 20120615 - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2])); $this->assertTrue(is_numeric($membership->id)); - $this->callAPISuccess('Email', 'create', array( + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'test-member@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $actionSchedule = $this->fixtures['sched_membership_end_2week']; $actionSchedule['entity_value'] = $membership->membership_type_id; @@ -1415,23 +1415,23 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($actionScheduleDao->id)); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email. 'time' => '2012-05-31 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week mark, send an email. 'time' => '2012-06-01 01:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - array( + 'recipients' => [['test-member@example.com']], + ], + [ // After the email is sent, another one is not sent 'time' => '2012-06-01 02:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); // Now suppose user has renewed for rolling membership after 3 months, so upcoming assertion is written // to ensure that new reminder is sent 2 week before the new end_date i.e. '2012-09-15' @@ -1440,64 +1440,64 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { //change the email id of chosen membership contact to assert //recipient of not the previously sent mail but the new one - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'is_primary' => 1, 'contact_id' => $membership->contact_id, 'email' => 'member2@example.com', - )); + ]); $this->assertAPISuccess($result); // end_date=2012-09-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email 'time' => '2012-08-31 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week mark, send an email 'time' => '2012-09-01 01:00:00', - 'recipients' => array(array('member2@example.com')), - ), - array( + 'recipients' => [['member2@example.com']], + ], + [ // After the email is sent, another one is not sent 'time' => '2012-09-01 02:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); $membership->end_date = '2012-12-15'; $membership->save(); // end_date=2012-12-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email 'time' => '2012-11-30 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week mark, send an email 'time' => '2012-12-01 01:00:00', - 'recipients' => array(array('member2@example.com')), - ), - array( + 'recipients' => [['member2@example.com']], + ], + [ // After the email is sent, another one is not sent 'time' => '2012-12-01 02:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } public function createMembershipAndContact($contactFixture, $membershipTypeId) { $result = $this->callAPISuccess('contact', 'create', $contactFixture); $contact = $result['values'][$result['id']]; - $params = array( + $params = [ 'status_id' => 2, 'contact_id' => $contact['id'], 'membership_type_id' => $membershipTypeId, 'owner_membership_id' => 'NULL', - ); + ]; $params = array_merge($this->fixtures['rolling_membership'], $params); $membership = $this->createTestObject('CRM_Member_DAO_Membership', $params); $this->assertTrue(is_numeric($membership->id)); @@ -1521,26 +1521,26 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($actionScheduleDao->id)); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email. 'time' => '2012-05-31 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week mark, send emails. 'time' => '2012-06-01 01:00:00', - 'recipients' => array( - array('test-member@example.com'), - array('test-contact-2@example.com'), - ), - ), - array( + 'recipients' => [ + ['test-member@example.com'], + ['test-contact-2@example.com'], + ], + ], + [ // After the email is sent, another one is not sent 'time' => '2012-06-01 02:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); // Now suppose user has renewed for rolling membership after 3 months, so upcoming assertion is written // to ensure that new reminder is sent 2 week before the new end_date i.e. '2012-09-15' @@ -1550,26 +1550,26 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $membershipTwo->save(); // end_date=2012-09-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email 'time' => '2012-08-31 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week mark, send an email 'time' => '2012-09-01 01:00:00', - 'recipients' => array( - array('test-member@example.com'), - array('test-contact-2@example.com'), - ), - ), - array( + 'recipients' => [ + ['test-member@example.com'], + ['test-contact-2@example.com'], + ], + ], + [ // After the email is sent, another one is not sent 'time' => '2012-06-01 02:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } /** @@ -1580,13 +1580,13 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testMembershipEndDateNoMatch() { // creates membership with end_date = 20120615 - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 3))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 3])); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'test-member@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $actionSchedule = $this->fixtures['sched_membership_end_2month']; $actionSchedule['entity_value'] = $membership->membership_type_id; @@ -1594,18 +1594,18 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($actionScheduleDao->id)); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email. 'time' => '2012-05-31 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week mark, no email 'time' => '2013-05-01 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } public function testContactBirthDateNoAnniv() { @@ -1614,18 +1614,18 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionSchedule = $this->fixtures['sched_contact_bday_yesterday']; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On the birthday, no email. 'time' => '2005-07-07 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // The next day, send an email. 'time' => '2005-07-08 20:00:00', - 'recipients' => array(array('test-bday@example.com')), - ), - )); + 'recipients' => [['test-bday@example.com']], + ], + ]); } public function testContactBirthDateAnniversary() { @@ -1634,36 +1634,36 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionSchedule = $this->fixtures['sched_contact_bday_anniv']; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On some random day, no email. 'time' => '2014-03-07 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // On the eve of their 9th birthday, send an email. 'time' => '2014-07-06 20:00:00', - 'recipients' => array(array('test-bday@example.com')), - ), - )); + 'recipients' => [['test-bday@example.com']], + ], + ]); } public function testContactCustomDateNoAnniv() { - $group = array( + $group = [ 'title' => 'Test_Group', 'name' => 'test_group', - 'extends' => array('Individual'), + 'extends' => ['Individual'], 'style' => 'Inline', 'is_multiple' => FALSE, 'is_active' => 1, - ); + ]; $createGroup = $this->callAPISuccess('custom_group', 'create', $group); - $field = array( + $field = [ 'label' => 'Graduation', 'data_type' => 'Date', 'html_type' => 'Select Date', 'custom_group_id' => $createGroup['id'], - ); + ]; $createField = $this->callAPISuccess('custom_field', 'create', $field); $contactParams = $this->fixtures['contact']; $contactParams["custom_{$createField['id']}"] = '2013-12-16'; @@ -1673,19 +1673,19 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionSchedule['entity_value'] = "custom_{$createField['id']}"; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On some random day, no email. 'time' => '2014-03-07 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // On the eve of their graduation, send an email. 'time' => '2013-12-15 20:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - )); - $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id'])); + 'recipients' => [['test-member@example.com']], + ], + ]); + $this->callAPISuccess('custom_group', 'delete', ['id' => $createGroup['id']]); } public function testContactCreatedNoAnniv() { @@ -1694,39 +1694,39 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionSchedule = $this->fixtures['sched_contact_created_yesterday']; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On the date created, no email. 'time' => $contact['values'][$contact['id']]['created_date'], - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // The next day, send an email. 'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['created_date'] . ' +1 day')), - 'recipients' => array(array('test-bday@example.com')), - ), - )); + 'recipients' => [['test-bday@example.com']], + ], + ]); } public function testContactModifiedAnniversary() { $contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']); $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; - $modifiedDate = $this->callAPISuccess('Contact', 'getvalue', array('id' => $contact['id'], 'return' => 'modified_date')); + $modifiedDate = $this->callAPISuccess('Contact', 'getvalue', ['id' => $contact['id'], 'return' => 'modified_date']); $actionSchedule = $this->fixtures['sched_contact_mod_anniv']; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On some random day, no email. 'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['modified_date'] . ' -60 days')), - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // On the eve of 3 years after they were modified, send an email. 'time' => date('Y-m-d H:i:s', strtotime($modifiedDate . ' +3 years -1 day')), - 'recipients' => array(array('test-bday@example.com')), - ), - )); + 'recipients' => [['test-bday@example.com']], + ], + ]); } /** @@ -1734,15 +1734,15 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testMembershipLimitToNone() { // creates membership with end_date = 20120615 - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2])); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'member@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); - $this->callAPISuccess('contact', 'create', array('email' => 'b@c.com', 'contact_type' => 'Individual')); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); + $this->callAPISuccess('contact', 'create', ['email' => 'b@c.com', 'contact_type' => 'Individual']); $this->assertAPISuccess($result); @@ -1752,26 +1752,26 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($actionScheduleDao->id)); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 2-week mark, no email. 'time' => '2012-05-31 01:00:00', // 'time' => '2012-06-01 01:00:00', // FIXME: Is this the right boundary? - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } public function testMembership_referenceDate() { - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2])); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'member@example.com', - )); + ]); - $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $this->assertAPISuccess($result); $actionSchedule = $this->fixtures['sched_membership_join_2week']; @@ -1780,18 +1780,18 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($actionScheduleDao->id)); // start_date=2012-03-15 ; schedule is 2 weeks after start_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // After the 2-week mark, send an email 'time' => '2012-03-29 01:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // After the 2-week 1day mark, don't send an email 'time' => '2012-03-30 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); //check if reference date is set to membership's join date //as per the action_start_date chosen for current schedule reminder @@ -1803,36 +1803,36 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $membership->join_date = '2012-03-29'; $membership->save(); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // After the 13 days of the changed join date 2012-03-29, don't send an email 'time' => '2012-04-11 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-week of the changed join date 2012-03-29, send an email 'time' => '2012-04-12 01:00:00', - 'recipients' => array(array('member@example.com')), - ), - )); - $this->assertCronRuns(array( - array( + 'recipients' => [['member@example.com']], + ], + ]); + $this->assertCronRuns([ + [ // It should not re-send on the same day 'time' => '2012-04-12 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } public function testMembershipOnMultipleReminder() { - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2])); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'member@example.com', - )); - $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + ]); + $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $this->assertAPISuccess($result); // Send email 2 weeks before end_date @@ -1842,44 +1842,44 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { // Send email 1 day after end_date/grace period $actionScheduleAfter = $this->fixtures['sched_after_1day_membership_end_date']; $actionScheduleBefore['entity_value'] = $actionScheduleOn['entity_value'] = $actionScheduleAfter['entity_value'] = $membership->membership_type_id; - foreach (array('actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter') as $value) { + foreach (['actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter'] as $value) { $$value = CRM_Core_BAO_ActionSchedule::add($$value); $this->assertTrue(is_numeric($$value->id)); } $this->assertCronRuns( - array( - array( + [ + [ // 1day 2weeks before membership end date(MED), don't send mail 'time' => '2012-05-31 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // 2 weeks before MED, send an email 'time' => '2012-06-01 01:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // 1day before MED, don't send mail 'time' => '2012-06-14 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // On MED, send an email 'time' => '2012-06-15 00:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // After 1day of MED, send an email 'time' => '2012-06-16 01:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // After 1day 1min of MED, don't send an email 'time' => '2012-06-17 00:01:00', - 'recipients' => array(), - ), - ) + 'recipients' => [], + ], + ] ); // Assert the timestamp as of when the emails of respective three reminders as configured @@ -1908,58 +1908,58 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $membership->end_date = '2012-06-20'; $membership->save(); - $result = $this->callAPISuccess('Contact', 'get', array('id' => $membership->contact_id)); + $result = $this->callAPISuccess('Contact', 'get', ['id' => $membership->contact_id]); $this->assertCronRuns( - array( - array( + [ + [ // 1day 2weeks before membership end date(MED), don't send mail 'time' => '2012-06-05 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // 2 weeks before MED, send an email 'time' => '2012-06-06 01:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // 1day before MED, don't send mail 'time' => '2012-06-19 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // On MED, send an email 'time' => '2012-06-20 00:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // After 1day of MED, send an email 'time' => '2012-06-21 01:00:00', - 'recipients' => array(array('member@example.com')), - ), - array( + 'recipients' => [['member@example.com']], + ], + [ // After 1day 1min of MED, don't send an email 'time' => '2012-07-21 00:01:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } public function testContactCustomDate_Anniv() { - $group = array( + $group = [ 'title' => 'Test_Group now', 'name' => 'test_group_now', - 'extends' => array('Individual'), + 'extends' => ['Individual'], 'style' => 'Inline', 'is_multiple' => FALSE, 'is_active' => 1, - ); + ]; $createGroup = $this->callAPISuccess('custom_group', 'create', $group); - $field = array( + $field = [ 'label' => 'Graduation', 'data_type' => 'Date', 'html_type' => 'Select Date', 'custom_group_id' => $createGroup['id'], - ); + ]; $createField = $this->callAPISuccess('custom_field', 'create', $field); $contactParams = $this->fixtures['contact']; @@ -1970,19 +1970,19 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionSchedule['entity_value'] = "custom_{$createField['id']}"; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // On some random day, no email. 'time' => '2014-03-07 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // A week after their 5th anniversary of graduation, send an email. 'time' => '2018-12-23 20:00:00', - 'recipients' => array(array('test-member@example.com')), - ), - )); - $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id'])); + 'recipients' => [['test-member@example.com']], + ], + ]); + $this->callAPISuccess('custom_group', 'delete', ['id' => $createGroup['id']]); } /** @@ -1990,19 +1990,19 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testEventTypeRegistrationDate() { //Create contact - $contactParams = array( + $contactParams = [ 'email' => 'test-event@example.com', - ); + ]; $contact = $this->individualCreate($contactParams); //Add it as a participant to an event ending registration - 7 days from now. - $params = array( + $params = [ 'start_date' => date('Ymd', strtotime('-5 day')), 'end_date' => date('Ymd', strtotime('+7 day')), 'registration_start_date' => date('Ymd', strtotime('-5 day')), 'registration_end_date' => date('Ymd', strtotime('+7 day')), - ); + ]; $event = $this->eventCreate($params); - $this->participantCreate(array('contact_id' => $contact, 'event_id' => $event['id'])); + $this->participantCreate(['contact_id' => $contact, 'event_id' => $event['id']]); //Create a scheduled reminder to send email 7 days before registration date. $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before']; @@ -2010,52 +2010,52 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $actionSchedule['start_action_unit'] = 'day'; $actionSchedule['start_action_date'] = 'registration_end_date'; $actionSchedule['entity_value'] = $event['values'][$event['id']]['event_type_id']; - $actionSchedule['entity_status'] = $this->callAPISuccessGetValue('ParticipantStatusType', array( + $actionSchedule['entity_status'] = $this->callAPISuccessGetValue('ParticipantStatusType', [ 'return' => "id", 'name' => "Attended", - )); + ]); $actionSched = $this->callAPISuccess('action_schedule', 'create', $actionSchedule); //Run the cron and verify if an email was sent. - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ 'time' => date('Y-m-d'), - 'recipients' => array(array('test-event@example.com')), - ), - )); + 'recipients' => [['test-event@example.com']], + ], + ]); //Create contact 2 - $contactParams = array( + $contactParams = [ 'email' => 'test-event2@example.com', - ); + ]; $contact2 = $this->individualCreate($contactParams); //Create an event with registration end date = 2 week from now. $params['end_date'] = date('Ymd', strtotime('+2 week')); $params['registration_end_date'] = date('Ymd', strtotime('+2 week')); $event2 = $this->eventCreate($params); - $this->participantCreate(array('contact_id' => $contact2, 'event_id' => $event2['id'])); + $this->participantCreate(['contact_id' => $contact2, 'event_id' => $event2['id']]); //Assert there is no reminder sent to the contact. - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ 'time' => date('Y-m-d'), - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); //Modify the sched reminder to be sent 2 week from registration end date. - $this->callAPISuccess('action_schedule', 'create', array( + $this->callAPISuccess('action_schedule', 'create', [ 'id' => $actionSched['id'], 'start_action_offset' => 2, 'start_action_unit' => 'week', - )); + ]); //Contact should receive the reminder now. - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ 'time' => date('Y-m-d'), - 'recipients' => array(array('test-event2@example.com')), - ), - )); + 'recipients' => [['test-event2@example.com']], + ], + ]); } /** @@ -2063,12 +2063,12 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { */ public function testEventTypeStartDate() { // Create event+participant with start_date = 20120315, end_date = 20120615. - $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 2))); - $this->callAPISuccess('Email', 'create', array( + $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], ['status_id' => 2])); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $participant->contact_id, 'email' => 'test-event@example.com', - )); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id))); + ]); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id])); $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before']; $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id'); @@ -2077,70 +2077,70 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { //echo "CREATED\n"; ob_flush(); sleep(20); // end_date=2012-06-15 ; schedule is 2 weeks before end_date - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // 2 weeks before 'time' => '2012-03-02 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // 1 week before 'time' => '2012-03-08 01:00:00', - 'recipients' => array(array('test-event@example.com')), - ), - array( + 'recipients' => [['test-event@example.com']], + ], + [ // And then nothing else 'time' => '2012-03-16 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } public function testEventTypeEndDateRepeat() { // Create event+participant with start_date = 20120315, end_date = 20120615. - $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 2))); - $this->callAPISuccess('Email', 'create', array( + $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], ['status_id' => 2])); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $participant->contact_id, 'email' => 'test-event@example.com', - )); - $c = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id))); + ]); + $c = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id])); $actionSchedule = $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks']; $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id'); $this->callAPISuccess('action_schedule', 'create', $actionSchedule); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Almost 2 months. 'time' => '2012-08-13 01:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After the 2-month mark, send an email. 'time' => '2012-08-16 01:00:00', - 'recipients' => array(array('test-event@example.com')), - ), - array( + 'recipients' => [['test-event@example.com']], + ], + [ // After 2 months and 1 week, don't repeat yet. 'time' => '2012-08-23 02:00:00', - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ // After 2 months and 2 weeks 'time' => '2012-08-30 02:00:00', - 'recipients' => array(array('test-event@example.com')), - ), - array( + 'recipients' => [['test-event@example.com']], + ], + [ // After 2 months and 4 week 'time' => '2012-09-13 02:00:00', - 'recipients' => array(array('test-event@example.com')), - ), - array( + 'recipients' => [['test-event@example.com']], + ], + [ // After 2 months and 6 weeks 'time' => '2012-09-27 01:00:00', - 'recipients' => array(), - ), - )); + 'recipients' => [], + ], + ]); } // TODO // function testMembershipEndDate_NonMatch() { } @@ -2160,7 +2160,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { public function assertCronRuns($cronRuns) { foreach ($cronRuns as $cronRun) { CRM_Utils_Time::setTime($cronRun['time']); - $this->callAPISuccess('job', 'send_reminder', array()); + $this->callAPISuccess('job', 'send_reminder', []); $this->mut->assertRecipients($cronRun['recipients']); if (array_key_exists('subjects', $cronRun)) { $this->mut->assertSubjects($cronRun['subjects']); @@ -2180,7 +2180,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { * This method is called before a test is executed. */ protected function _setUp() { - $this->_testObjects = array(); + $this->_testObjects = []; } /** @@ -2206,13 +2206,13 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { * * @return array|NULL|object */ - public function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE) { + public function createTestObject($daoName, $params = [], $numObjects = 1, $createOnly = FALSE) { $objects = CRM_Core_DAO::createTestObject($daoName, $params, $numObjects, $createOnly); if (is_array($objects)) { $this->registerTestObjects($objects); } else { - $this->registerTestObjects(array($objects)); + $this->registerTestObjects([$objects]); } return $objects; } @@ -2239,10 +2239,10 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { // and the "automatic/secondary records" foreach ($this->_testObjects as $daoName => $daoIds) { foreach ($daoIds as $daoId) { - CRM_Core_DAO::deleteTestObjects($daoName, array('id' => $daoId)); + CRM_Core_DAO::deleteTestObjects($daoName, ['id' => $daoId]); } } - $this->_testObjects = array(); + $this->_testObjects = []; } /** @@ -2250,33 +2250,33 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { * CRM-17028 */ public function testRepetitionFrequencyUnit() { - $membershipTypeParams = array( + $membershipTypeParams = [ 'duration_interval' => '1', 'duration_unit' => 'year', 'is_active' => 1, 'period_type' => 'rolling', - ); + ]; $membershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', $membershipTypeParams); - $interval_units = array('hour', 'day', 'week', 'month', 'year'); + $interval_units = ['hour', 'day', 'week', 'month', 'year']; foreach ($interval_units as $interval_unit) { $membershipEndDate = DateTime::createFromFormat('Y-m-d H:i:s', "2013-03-15 00:00:00"); - $contactParams = array( + $contactParams = [ 'contact_type' => 'Individual', 'first_name' => 'Test', 'last_name' => "Interval $interval_unit", 'is_deceased' => 0, - ); + ]; $contact = $this->createTestObject('CRM_Contact_DAO_Contact', $contactParams); $this->assertTrue(is_numeric($contact->id)); - $emailParams = array( + $emailParams = [ 'contact_id' => $contact->id, 'is_primary' => 1, 'email' => "test-member-{$interval_unit}@example.com", 'location_type_id' => 1, - ); + ]; $email = $this->createTestObject('CRM_Core_DAO_Email', $emailParams); $this->assertTrue(is_numeric($email->id)); - $membershipParams = array( + $membershipParams = [ 'membership_type_id' => $membershipType->id, 'contact_id' => $contact->id, 'join_date' => '20120315', @@ -2284,7 +2284,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'end_date' => '20130315', 'is_override' => 0, 'status_id' => 2, - ); + ]; $membershipParams['status-id'] = 1; $membership = $this->createTestObject('CRM_Member_DAO_Membership', $membershipParams); $actionScheduleParams = $this->fixtures['sched_on_membership_end_date_repeat_interval']; @@ -2296,24 +2296,24 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $beforeEndDate = $this->createModifiedDateTime($membershipEndDate, '-1 day'); $beforeFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+1 $interval_unit"); $afterFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+2 $interval_unit"); - $cronRuns = array( - array( + $cronRuns = [ + [ 'time' => $beforeEndDate->format('Y-m-d H:i:s'), - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ 'time' => $membershipEndDate->format('Y-m-d H:i:s'), - 'recipients' => array(array("test-member-{$interval_unit}@example.com")), - ), - array( + 'recipients' => [["test-member-{$interval_unit}@example.com"]], + ], + [ 'time' => $beforeFirstUnit->format('Y-m-d H:i:s'), - 'recipients' => array(), - ), - array( + 'recipients' => [], + ], + [ 'time' => $afterFirstUnit->format('Y-m-d H:i:s'), - 'recipients' => array(array("test-member-{$interval_unit}@example.com")), - ), - ); + 'recipients' => [["test-member-{$interval_unit}@example.com"]], + ], + ]; $this->assertCronRuns($cronRuns); $actionSchedule->delete(); $membership->delete(); @@ -2444,41 +2444,41 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { } public function testMembershipScheduleWithAbsoluteDate() { - $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 1))); + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 1])); $this->assertTrue(is_numeric($membership->id)); - $result = $this->callAPISuccess('Email', 'create', array( + $result = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $membership->contact_id, 'email' => 'test-member@example.com', 'location_type_id' => 1, 'is_primary' => 1, - )); + ]); - $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id])); $actionSchedule = $this->fixtures['sched_membership_absolute_date']; $actionSchedule['entity_value'] = $membership->membership_type_id; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); - $this->assertCronRuns(array( - array( + $this->assertCronRuns([ + [ // Before the 24-hour mark, no email 'time' => '2012-06-13 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - array( + 'recipients' => [], + 'subjects' => [], + ], + [ // On absolute date set on 2012-06-14 'time' => '2012-06-14 00:00:00', - 'recipients' => array(array('test-member@example.com')), - 'subjects' => array('subject sched_membership_absolute_date'), - ), - array( + 'recipients' => [['test-member@example.com']], + 'subjects' => ['subject sched_membership_absolute_date'], + ], + [ // Run cron 4 hours later; first message already sent 'time' => '2012-06-14 04:00:00', - 'recipients' => array(), - 'subjects' => array(), - ), - )); + 'recipients' => [], + 'subjects' => [], + ], + ]); } } diff --git a/tests/phpunit/CRM/Core/BAO/AddressTest.php b/tests/phpunit/CRM/Core/BAO/AddressTest.php index 44130a7786..110a0a5f40 100644 --- a/tests/phpunit/CRM/Core/BAO/AddressTest.php +++ b/tests/phpunit/CRM/Core/BAO/AddressTest.php @@ -34,7 +34,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->quickCleanup(array('civicrm_contact', 'civicrm_address')); + $this->quickCleanup(['civicrm_contact', 'civicrm_address']); } /** @@ -43,8 +43,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { public function testCreate() { $contactId = $this->individualCreate(); - $params = array(); - $params['address']['1'] = array( + $params = []; + $params['address']['1'] = [ 'street_address' => 'Oberoi Garden', 'supplemental_address_1' => 'Attn: Accounting', 'supplemental_address_2' => 'Powai', @@ -58,7 +58,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'location_type_id' => '1', 'is_primary' => '1', 'is_billing' => '0', - ); + ]; $params['contact_id'] = $contactId; @@ -71,8 +71,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { // Now call add() to modify an existing address - $params = array(); - $params['address']['1'] = array( + $params = []; + $params['address']['1'] = [ 'id' => $addressId, 'street_address' => '120 Terminal Road', 'supplemental_address_1' => 'A-wing:3037', @@ -87,7 +87,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'location_type_id' => '1', 'is_primary' => '1', 'is_billing' => '0', - ); + ]; $params['contact_id'] = $contactId; $block = CRM_Core_BAO_Address::create($params, $fixAddress, $entity = NULL); @@ -107,7 +107,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { public function testAdd() { $contactId = $this->individualCreate(); - $fixParams = array( + $fixParams = [ 'street_address' => 'E 906N Pine Pl W', 'supplemental_address_1' => 'Editorial Dept', 'supplemental_address_2' => '', @@ -123,7 +123,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'is_primary' => '1', 'is_billing' => '0', 'contact_id' => $contactId, - ); + ]; $addAddress = CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); @@ -147,7 +147,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { public function testallAddress() { $contactId = $this->individualCreate(); - $fixParams = array( + $fixParams = [ 'street_address' => 'E 906N Pine Pl W', 'supplemental_address_1' => 'Editorial Dept', 'supplemental_address_2' => '', @@ -163,14 +163,14 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'is_primary' => '1', 'is_billing' => '0', 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created contact address.' ); - $fixParams = array( + $fixParams = [ 'street_address' => 'SW 719B Beech Dr NW', 'supplemental_address_1' => 'C/o OPDC', 'supplemental_address_2' => '', @@ -186,7 +186,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'is_primary' => '', 'is_billing' => '1', 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); @@ -207,7 +207,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { public function testnullallAddress() { $contactId = $this->individualCreate(); - $fixParams = array( + $fixParams = [ 'street_address' => 'E 906N Pine Pl W', 'supplemental_address_1' => 'Editorial Dept', 'supplemental_address_2' => '', @@ -223,7 +223,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'is_primary' => '1', 'is_billing' => '0', 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); @@ -246,8 +246,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { public function testGetValues() { $contactId = $this->individualCreate(); - $params = array(); - $params['address']['1'] = array( + $params = []; + $params['address']['1'] = [ 'street_address' => 'Oberoi Garden', 'supplemental_address_1' => 'Attn: Accounting', 'supplemental_address_2' => 'Powai', @@ -261,7 +261,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'location_type_id' => '1', 'is_primary' => '1', 'is_billing' => '0', - ); + ]; $params['contact_id'] = $contactId; @@ -273,7 +273,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { 'Database check for created address.' ); - $entityBlock = array('contact_id' => $contactId); + $entityBlock = ['contact_id' => $contactId]; $address = CRM_Core_BAO_Address::getValues($entityBlock); $this->assertEquals($address[1]['id'], $addressId); $this->assertEquals($address[1]['contact_id'], $contactId); @@ -313,11 +313,11 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $contactId = $this->individualCreate(); $street_address = "54 Excelsior Ave."; - $params = array( + $params = [ 'contact_id' => $contactId, 'street_address' => $street_address, 'location_type_id' => 1, - ); + ]; $result = civicrm_api3('Address', 'create', $params); $value = array_pop($result['values']); @@ -410,11 +410,11 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { } public function supportedAddressParsingLocales() { - return array( - array('en_US'), - array('en_CA'), - array('fr_CA'), - ); + return [ + ['en_US'], + ['en_CA'], + ['fr_CA'], + ]; } /** @@ -435,11 +435,11 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { } public function sampleOFUnsupportedAddressParsingLocales() { - return array( - array('en_GB'), - array('af_ZA'), - array('da_DK'), - ); + return [ + ['en_GB'], + ['af_ZA'], + ['da_DK'], + ]; } /** @@ -453,43 +453,43 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { * Also, Contact C's address' master_id should be Contact A's address id. */ public function testSharedAddressChaining1() { - $contactIdA = $this->individualCreate(array(), 0); - $contactIdB = $this->individualCreate(array(), 1); - $contactIdC = $this->individualCreate(array(), 2); + $contactIdA = $this->individualCreate([], 0); + $contactIdB = $this->individualCreate([], 1); + $contactIdC = $this->individualCreate([], 2); - $addressParamsA = array( + $addressParamsA = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'contact_id' => $contactIdA, - ); + ]; $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); - $addressParamsB = array( + $addressParamsB = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'master_id' => $addAddressA->id, 'contact_id' => $contactIdB, - ); + ]; $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE); - $addressParamsC = array( + $addressParamsC = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'master_id' => $addAddressB->id, 'contact_id' => $contactIdC, - ); + ]; $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE); - $updatedAddressParamsA = array( + $updatedAddressParamsA = [ 'id' => $addAddressA->id, 'street_address' => '1313 New Address Lane', 'location_type_id' => '1', 'is_primary' => '1', 'contact_id' => $contactIdA, - ); + ]; $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE); // CRM-21214 - Has Address C been updated with Address A's new values? @@ -513,52 +513,52 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { * Also, Contact C's address' master_id should be Contact B's address id. */ public function testSharedAddressChaining2() { - $contactIdA = $this->individualCreate(array(), 0); - $contactIdB = $this->individualCreate(array(), 1); - $contactIdC = $this->individualCreate(array(), 2); + $contactIdA = $this->individualCreate([], 0); + $contactIdB = $this->individualCreate([], 1); + $contactIdC = $this->individualCreate([], 2); - $addressParamsA = array( + $addressParamsA = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'contact_id' => $contactIdA, - ); + ]; $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); - $addressParamsB = array( + $addressParamsB = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'contact_id' => $contactIdB, - ); + ]; $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE); - $addressParamsC = array( + $addressParamsC = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'master_id' => $addAddressA->id, 'contact_id' => $contactIdC, - ); + ]; $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE); - $updatedAddressParamsA = array( + $updatedAddressParamsA = [ 'id' => $addAddressA->id, 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'master_id' => $addAddressB->id, 'contact_id' => $contactIdA, - ); + ]; $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE); - $updatedAddressParamsB = array( + $updatedAddressParamsB = [ 'id' => $addAddressB->id, 'street_address' => '1313 New Address Lane', 'location_type_id' => '1', 'is_primary' => '1', 'contact_id' => $contactIdB, - ); + ]; $updatedAddressB = CRM_Core_BAO_Address::add($updatedAddressParamsB, FALSE); // CRM-21214 - Has Address C been updated with Address B's new values? @@ -579,24 +579,24 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { * An error should be given, and master_id should remain the same. */ public function testSharedAddressChaining3() { - $contactIdA = $this->individualCreate(array(), 0); + $contactIdA = $this->individualCreate([], 0); - $addressParamsA = array( + $addressParamsA = [ 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'contact_id' => $contactIdA, - ); + ]; $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); - $updatedAddressParamsA = array( + $updatedAddressParamsA = [ 'id' => $addAddressA->id, 'street_address' => '123 Fake St.', 'location_type_id' => '1', 'is_primary' => '1', 'master_id' => $addAddressA->id, 'contact_id' => $contactIdA, - ); + ]; $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE); // CRM-21214 - AdressA shouldn't be master of itself. diff --git a/tests/phpunit/CRM/Core/BAO/CacheTest.php b/tests/phpunit/CRM/Core/BAO/CacheTest.php index 23326e9f8e..dbe69ee1dd 100644 --- a/tests/phpunit/CRM/Core/BAO/CacheTest.php +++ b/tests/phpunit/CRM/Core/BAO/CacheTest.php @@ -65,7 +65,7 @@ class CRM_Core_BAO_CacheTest extends CiviUnitTestCase { $ex = []; - $ex[] = [array('abc' => 'def')]; + $ex[] = [['abc' => 'def']]; $ex[] = [0]; $ex[] = ['hello world']; $ex[] = ['Scarabée']; diff --git a/tests/phpunit/CRM/Core/BAO/ConfigSettingTest.php b/tests/phpunit/CRM/Core/BAO/ConfigSettingTest.php index 38ad72fd97..292abc1df1 100644 --- a/tests/phpunit/CRM/Core/BAO/ConfigSettingTest.php +++ b/tests/phpunit/CRM/Core/BAO/ConfigSettingTest.php @@ -32,7 +32,7 @@ class CRM_Core_BAO_ConfigSettingTest extends CiviUnitTestCase { public function testToggleComponent() { - $origNames = array(); + $origNames = []; foreach (CRM_Core_Component::getEnabledComponents() as $c) { $origNames[] = $c->name; } @@ -41,7 +41,7 @@ class CRM_Core_BAO_ConfigSettingTest extends CiviUnitTestCase { $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__); - $newNames = array(); + $newNames = []; foreach (CRM_Core_Component::getEnabledComponents() as $c) { $newNames[] = $c->name; } diff --git a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php index cc6b539615..c6c9bc4c7b 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php @@ -40,7 +40,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testGetTree() { $customGroup = $this->CustomGroupCreate(); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); $result = CRM_Core_BAO_CustomGroup::getTree('Individual', NULL, $customGroup['id']); $this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); @@ -53,21 +53,21 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * inconsistency. */ public function testGetTreeContactSubType() { - $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization')); - $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank'))); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); - $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank')); + $contactType = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']); + $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank']]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); + $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Big_Bank']); $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); $result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big_Bank' . CRM_Core_DAO::VALUE_SEPARATOR); $this->assertEquals($result1, $result); $result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, 'Big_Bank'); $this->assertEquals($result1, $result); try { - CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Small Kind Bank')); + CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Small Kind Bank']); } catch (CRM_Core_Exception $e) { $this->customGroupDelete($customGroup['id']); - $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id'])); + $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]); return; } $this->fail('There is no such thing as a small kind bank'); @@ -77,56 +77,56 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test calling getTree for a custom field extending a renamed contact type. */ public function testGetTreeContactSubTypeForNameChangedContactType() { - $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization')); + $contactType = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']); CRM_Core_DAO::executeQuery('UPDATE civicrm_contact_type SET label = "boo" WHERE name = "Organization"'); - $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank'))); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); - $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank')); + $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank']]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); + $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Big_Bank']); $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); - $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id'])); + $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]); } /** * Test calling getTree for a custom field extending a disabled contact type. */ public function testGetTreeContactSubTypeForDisabledChangedContactType() { - $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization')); - $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank'))); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); - $this->callAPISuccess('ContactType', 'create', array('id' => $contactType['id'], 'is_active' => 0)); - $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank')); + $contactType = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']); + $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank']]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); + $this->callAPISuccess('ContactType', 'create', ['id' => $contactType['id'], 'is_active' => 0]); + $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Big_Bank']); $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); - $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id'])); + $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]); } /** * Test calling GetTree for a custom field extending multiple subTypes. */ public function testGetTreetContactSubTypeForMultipleSubTypes() { - $contactType1 = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization')); - $contactType2 = $this->callAPISuccess('ContactType', 'create', array('name' => 'Small Bank', 'label' => 'smallee', 'parent_id' => 'Organization')); - $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank', 'Small_Bank'))); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); + $contactType1 = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']); + $contactType2 = $this->callAPISuccess('ContactType', 'create', ['name' => 'Small Bank', 'label' => 'smallee', 'parent_id' => 'Organization']); + $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank', 'Small_Bank']]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big_Bank' . CRM_Core_DAO::VALUE_SEPARATOR . 'Small_Bank' . CRM_Core_DAO::VALUE_SEPARATOR); $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); - $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType1['id'])); - $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType2['id'])); + $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType1['id']]); + $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType2['id']]); } /** * Test calling GetTree for a custom field that extends a non numerical Event Type. */ public function testGetTreeEventSubTypeAlphabetical() { - $eventType = $this->callAPISuccess('OptionValue', 'Create', array('option_group_id' => 'event_type', 'value' => 'meeting', 'label' => 'Meeting')); - $customGroup = $this->CustomGroupCreate(array('extends' => 'Event', 'extends_entity_column_value' => array('Meeting'))); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); + $eventType = $this->callAPISuccess('OptionValue', 'Create', ['option_group_id' => 'event_type', 'value' => 'meeting', 'label' => 'Meeting']); + $customGroup = $this->CustomGroupCreate(['extends' => 'Event', 'extends_entity_column_value' => ['Meeting']]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); $result1 = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'meeting' . CRM_Core_DAO::VALUE_SEPARATOR); $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); - $this->callAPISuccess('OptionValue', 'delete', array('id' => $eventType['id'])); + $this->callAPISuccess('OptionValue', 'delete', ['id' => $eventType['id']]); } /** @@ -139,11 +139,11 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { $sep = CRM_Core_DAO::VALUE_SEPARATOR; $this->campaignCreate(); $this->campaignCreate(); - $customGroup = $this->CustomGroupCreate(array( + $customGroup = $this->CustomGroupCreate([ 'extends' => 'Campaign', 'extends_entity_column_value' => "{$sep}1{$sep}2{$sep}", - )); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); + ]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); $result1 = CRM_Core_BAO_CustomGroup::getTree('Campaign', NULL, NULL, NULL, '12'); $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); @@ -153,8 +153,8 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test calling getTree with contact subtype data. */ public function testGetTreeActivitySubType() { - $customGroup = $this->CustomGroupCreate(array('extends' => 'Activity', 'extends_entity_column_value' => 1)); - $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); + $customGroup = $this->CustomGroupCreate(['extends' => 'Activity', 'extends_entity_column_value' => 1]); + $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]); $result = CRM_Core_BAO_CustomGroup::getTree('Activity', NULL, NULL, NULL, 1); $this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']); $this->customGroupDelete($customGroup['id']); @@ -164,7 +164,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test retrieve() with Empty Params. */ public function testRetrieveEmptyParams() { - $params = array(); + $params = []; $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults); $this->assertNull($customGroup, 'Check that no custom Group is retreived'); } @@ -173,7 +173,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test retrieve() with Inalid Params */ public function testRetrieveInvalidParams() { - $params = array('id' => 99); + $params = ['id' => 99]; $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults); $this->assertNull($customGroup, 'Check that no custom Group is retreived'); } @@ -183,7 +183,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testRetrieve() { $customGroupTitle = 'Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'My_Custom_Group', 'style' => 'Tab', @@ -193,7 +193,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'is_active' => 1, 'collapse_display' => 1, 'weight' => 2, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); @@ -205,13 +205,13 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testSetIsActive() { $customGroupTitle = 'My Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 0, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; @@ -233,7 +233,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test getGroupDetail() with Empty Params */ public function testGetGroupDetailEmptyParams() { - $customGroupId = array(); + $customGroupId = []; $customGroup = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId); $this->assertTrue(empty($customGroup), 'Check that no custom Group details is retreived'); } @@ -252,7 +252,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testGetGroupDetail() { $customGroupTitle = 'My Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'My_Custom_Group', 'extends' => 'Individual', @@ -260,12 +260,12 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; - $fieldParams = array( + $fieldParams = [ 'custom_group_id' => $customGroupId, 'label' => 'Test Custom Field', 'html_type' => 'Text', @@ -273,7 +273,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1, - ); + ]; $customField = $this->customFieldCreate($fieldParams); $customFieldId = $customField['id']; @@ -313,13 +313,13 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testGetTitle() { $customGroupTitle = 'Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 0, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; @@ -338,13 +338,13 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testDeleteGroup() { $customGroupTitle = 'My Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $groupObject = new CRM_Core_BAO_CustomGroup(); @@ -364,14 +364,14 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test createTable() */ public function testCreateTable() { - $groupParams = array( + $groupParams = [ 'title' => 'My Custom Group', 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 1, 'version' => 3, - ); + ]; $customGroupBAO = new CRM_Core_BAO_CustomGroup(); $customGroupBAO->copyValues($groupParams); @@ -398,7 +398,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test checkCustomField() */ public function testCheckCustomField() { - $groupParams = array( + $groupParams = [ 'title' => 'My Custom Group', 'name' => 'my_custom_group', 'extends' => 'Individual', @@ -406,14 +406,14 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $this->assertNotNull($customGroup['id'], 'pre-requisite group not created successfully'); $customGroupId = $customGroup['id']; $customFieldLabel = 'Test Custom Field'; - $fieldParams = array( + $fieldParams = [ 'custom_group_id' => $customGroupId, 'label' => $customFieldLabel, 'html_type' => 'Text', @@ -421,7 +421,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1, - ); + ]; $customField = $this->customFieldCreate($fieldParams); $customField = $customField['values'][$customField['id']]; @@ -435,11 +435,11 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { $this->assertEquals($customFieldLabel, $dbCustomFieldLabel); //check the custom field type. - $params = array('Individual'); + $params = ['Individual']; $usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params); $this->assertEquals(FALSE, $usedFor); - $params = array('Contribution', 'Membership', 'Participant'); + $params = ['Contribution', 'Membership', 'Participant']; $usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params); $this->assertEquals(TRUE, $usedFor); @@ -459,14 +459,14 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { public function testGetActiveGroups() { $contactId = $this->individualCreate(); $customGroupTitle = 'Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'test_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'weight' => 10, 'is_active' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $activeGroup = CRM_Core_BAO_CustomGroup::getActiveGroups('Individual', 'civicrm/contact/view/cd', $contactId); @@ -487,10 +487,10 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test create() */ public function testCreate() { - $params = array( + $params = [ 'title' => 'Test_Group_1', 'name' => 'test_group_1', - 'extends' => array(0 => 'Individual', 1 => array()), + 'extends' => [0 => 'Individual', 1 => []], 'weight' => 4, 'collapse_display' => 1, 'style' => 'Inline', @@ -498,7 +498,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, 'version' => 3, - ); + ]; $customGroup = CRM_Core_BAO_CustomGroup::create($params); $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'title', 'id', @@ -519,18 +519,18 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test create() given a table_name */ public function testCreateTableName() { - $params = array( + $params = [ 'title' => 'Test_Group_2', 'name' => 'test_group_2', 'table_name' => 'test_otherTableName', - 'extends' => array(0 => 'Individual', 1 => array()), + 'extends' => [0 => 'Individual', 1 => []], 'weight' => 4, 'collapse_display' => 1, 'style' => 'Inline', 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - ); + ]; $customGroup = CRM_Core_BAO_CustomGroup::create($params); $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'title', 'id', @@ -551,14 +551,14 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testIsGroupEmpty() { $customGroupTitle = 'Test Custom Group'; - $groupParams = array( + $groupParams = [ 'title' => $customGroupTitle, 'name' => 'test_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'weight' => 10, 'is_active' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; @@ -572,7 +572,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test getGroupTitles() with Invalid Params() */ public function testGetGroupTitlesWithInvalidParams() { - $params = array(99); + $params = [99]; $groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params); $this->assertTrue(empty($groupTitles), 'Check that no titles are received'); } @@ -581,18 +581,18 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { * Test getGroupTitles() */ public function testGetGroupTitles() { - $groupParams = array( + $groupParams = [ 'title' => 'Test Group', 'name' => 'test_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'weight' => 10, 'is_active' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); - $fieldParams = array( + $fieldParams = [ 'label' => 'Custom Field', 'html_type' => 'Text', 'data_type' => 'String', @@ -600,12 +600,12 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'is_searchable' => 0, 'is_active' => 1, 'custom_group_id' => $customGroup['id'], - ); + ]; $customField = $this->customFieldCreate($fieldParams); $customFieldId = $customField['id']; - $params = array($customFieldId); + $params = [$customFieldId]; $groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params); @@ -618,18 +618,18 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { */ public function testExtractGetParamsReturnsDates() { // Create a custom group to contain the custom field. - $groupParams = array( + $groupParams = [ 'title' => 'My Custom Group', 'name' => 'my_custom_group', 'extends' => 'Individual', 'is_active' => 1, 'collapse_display' => 1, - ); + ]; $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; // Create teh custom field. - $fieldParams = array( + $fieldParams = [ 'custom_group_id' => $customGroupId, 'label' => 'My Custom Date Field', 'html_type' => 'Select Date', @@ -638,7 +638,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { 'is_searchable' => 0, 'is_active' => 1, 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fieldParams); $customFieldId = $customField['id']; diff --git a/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php b/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php index a5fd1cc115..649969971a 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php @@ -14,9 +14,9 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { * @throws \Exception */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); parent::tearDown(); } @@ -26,19 +26,19 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { */ public function testSearchCustomDataDateRelative() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest'); - $dateCustomField = $this->customFieldCreate(array( + $dateCustomField = $this->customFieldCreate([ 'custom_group_id' => $ids['custom_group_id'], 'label' => 'date field', 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => NULL, - )); + ]); $dateCustomFieldName = 'custom_' . $dateCustomField['id']; - $formValues = array( + $formValues = [ $dateCustomFieldName . '_relative' => 'this.year', $dateCustomFieldName . '_from' => '', $dateCustomFieldName . '_to' => '', - ); + ]; // Assigning the relevant form value to be within a custom key is normally done in // build field params. It would be better if it were all done in convertFormValues // but for now we just imitate it. @@ -90,21 +90,21 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { */ public function testSearchCustomDataDateFromTo() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest'); - $dateCustomField = $this->customFieldCreate(array( + $dateCustomField = $this->customFieldCreate([ 'custom_group_id' => $ids['custom_group_id'], 'label' => 'date field', 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => NULL, - )); + ]); $dateCustomFieldName = 'custom_' . $dateCustomField['id']; // Assigning the relevant form value to be within a custom key is normally done in // build field params. It would be better if it were all done in convertFormValues // but for now we just imitate it. - $formValues = array( + $formValues = [ $dateCustomFieldName . '_from' => '2014-06-06', $dateCustomFieldName . '_to' => '2015-06-06', - ); + ]; $params[$dateCustomField['id']] = CRM_Contact_BAO_Query::convertFormValues($formValues); $queryObj = new CRM_Core_BAO_CustomQuery($params); @@ -125,20 +125,20 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { */ public function testSearchCustomDataFromTo() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest'); - $datas = array( + $datas = [ 'Int' => 2, 'Float' => 12.123, 'Money' => 91.21, - ); + ]; foreach ($datas as $type => $data) { $customField = $this->customFieldCreate( - array( + [ 'custom_group_id' => $ids['custom_group_id'], 'label' => "$type field", 'data_type' => $type, 'html_type' => 'Text', 'default_value' => NULL, - ) + ] ); $customFieldName = 'custom_' . $customField['id']; // Assigning the relevant form value to be within a custom key is normally done in @@ -146,12 +146,12 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { // but for now we just imitate it. $from = $data - 1; $to = $data; - $formValues = array( + $formValues = [ $customFieldName . '_from' => $from, $customFieldName . '_to' => $to, - ); + ]; - $params = array($customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)); + $params = [$customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)]; $queryObj = new CRM_Core_BAO_CustomQuery($params); $queryObj->Query(); $this->assertEquals( @@ -167,22 +167,22 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { */ public function testSearchCustomDataFromAndTo() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest'); - $datas = array( + $datas = [ 'Date' => '2015-06-06', 'Int' => 2, 'Float' => 12.123, 'Money' => 91.21, - ); + ]; foreach ($datas as $type => $data) { $isDate = ($type === 'Date'); $customField = $this->customFieldCreate( - array( + [ 'custom_group_id' => $ids['custom_group_id'], 'label' => "$type field", 'data_type' => $type, 'html_type' => ($isDate) ? 'Select Date' : 'Text', 'default_value' => NULL, - ) + ] ); $customFieldName = 'custom_' . $customField['id']; @@ -194,11 +194,11 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { // but for now we just imitate it. //Scenrio 2 : TO date filter - $formValues = array( + $formValues = [ $customFieldName . '_to' => $data, - ); + ]; - $params = array($customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)); + $params = [$customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)]; $queryObj = new CRM_Core_BAO_CustomQuery($params); $queryObj->Query(); $wierdStringThatMeansGreaterEquals = chr(226) . chr(137) . chr(164); @@ -212,11 +212,11 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { ); //Scenrio 2 : FROM date filter - $formValues = array( + $formValues = [ $customFieldName . '_from' => $data, - ); + ]; - $params = array($customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)); + $params = [$customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)]; $queryObj = new CRM_Core_BAO_CustomQuery($params); $queryObj->Query(); $wierdStringThatMeansLessThanEquals = chr(226) . chr(137) . chr(165); @@ -238,19 +238,19 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { */ public function testSearchCustomDataDateEquals() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest'); - $dateCustomField = $this->customFieldCreate(array( + $dateCustomField = $this->customFieldCreate([ 'custom_group_id' => $ids['custom_group_id'], 'label' => 'date field', 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => NULL, - )); + ]); $dateCustomFieldName = 'custom_' . $dateCustomField['id']; - $this->individualCreate(array($dateCustomFieldName => "2015-01-01")); + $this->individualCreate([$dateCustomFieldName => "2015-01-01"]); // Assigning the relevant form value to be within a custom key is normally done in // build field params. It would be better if it were all done in convertFormValues // but for now we just imitate it. - $formValues = array($dateCustomFieldName => '2015-06-06'); + $formValues = [$dateCustomFieldName => '2015-06-06']; $params[$dateCustomField['id']] = CRM_Contact_BAO_Query::convertFormValues($formValues); $queryObj = new CRM_Core_BAO_CustomQuery($params); $queryObj->Query(); diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php index ad6e0d86bd..bd60364d02 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php @@ -12,40 +12,40 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { public function testCustomGroupMultipleSingle() { $contactID = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); - $fields = array( + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); + $fields = [ 'custom_group_id' => $customGroup['id'], 'dataType' => 'String', 'htmlType' => 'Text', - ); + ]; $customField = $this->customFieldCreate($fields); - $params = array( + $params = [ 'entityID' => $contactID, "custom_{$customField['id']}_-1" => 'First String', - ); + ]; CRM_Core_BAO_CustomValueTable::setValues($params); - $newParams = array( + $newParams = [ 'entityID' => $contactID, "custom_{$customField['id']}" => 1, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); $this->assertEquals($params["custom_{$customField['id']}_-1"], $result["custom_{$customField['id']}_1"]); $this->assertEquals($params['entityID'], $result['entityID']); - $updateParams = array( + $updateParams = [ 'id' => 1, 'entityID' => $contactID, "custom_{$customField['id']}" => 2, - ); + ]; CRM_Core_BAO_CustomValueTable::setValues($updateParams); - $criteria = array( + $criteria = [ 'id' => 1, 'entityID' => $contactID, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::getValues($criteria); $this->assertEquals(2, $result["custom_{$customField['id']}_1"]); @@ -56,25 +56,25 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { public function testCustomGroupMultipleDouble() { $contactID = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); - $fields = array( + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); + $fields = [ 'custom_group_id' => $customGroup['id'], 'dataType' => 'String', 'htmlType' => 'Text', - ); + ]; $customField = $this->customFieldCreate($fields); - $params = array( + $params = [ 'entityID' => $contactID, "custom_{$customField['id']}_-1" => 'First String', "custom_{$customField['id']}_-2" => 'Second String', - ); + ]; CRM_Core_BAO_CustomValueTable::setValues($params); - $newParams = array( + $newParams = [ 'entityID' => $contactID, "custom_{$customField['id']}" => 1, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); $this->assertEquals($params["custom_{$customField['id']}_-1"], $result["custom_{$customField['id']}_1"]); @@ -88,33 +88,33 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { public function testCustomGroupMultipleUpdate() { $contactID = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); - $fields = array( + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); + $fields = [ 'custom_group_id' => $customGroup['id'], 'dataType' => 'String', 'htmlType' => 'Text', - ); + ]; $customField = $this->customFieldCreate($fields); - $params = array( + $params = [ 'entityID' => $contactID, "custom_{$customField['id']}_-1" => 'First String', "custom_{$customField['id']}_-2" => 'Second String', "custom_{$customField['id']}_-3" => 'Third String', - ); + ]; CRM_Core_BAO_CustomValueTable::setValues($params); - $newParams = array( + $newParams = [ 'entityID' => $contactID, "custom_{$customField['id']}_1" => 'Updated First String', "custom_{$customField['id']}_3" => 'Updated Third String', - ); + ]; CRM_Core_BAO_CustomValueTable::setValues($newParams); - $getParams = array( + $getParams = [ 'entityID' => $contactID, "custom_{$customField['id']}" => 1, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::getValues($getParams); $this->assertEquals($newParams["custom_{$customField['id']}_1"], $result["custom_{$customField['id']}_1"]); @@ -129,24 +129,24 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { public function testCustomGroupMultipleOldFormat() { $contactID = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); - $fields = array( + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); + $fields = [ 'custom_group_id' => $customGroup['id'], 'dataType' => 'String', 'htmlType' => 'Text', - ); + ]; $customField = $this->customFieldCreate($fields); - $params = array( + $params = [ 'entityID' => $contactID, "custom_{$customField['id']}" => 'First String', - ); + ]; CRM_Core_BAO_CustomValueTable::setValues($params); - $newParams = array( + $newParams = [ 'entityID' => $contactID, "custom_{$customField['id']}" => 1, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); $this->assertEquals($params["custom_{$customField['id']}"], $result["custom_{$customField['id']}_1"]); diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php index 3673e6dd83..1e9d7fa84b 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php @@ -14,43 +14,43 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { * Test setValues() and GetValues() methods with custom Date field */ public function testSetGetValuesDate() { - $params = array(); + $params = []; $contactID = $this->individualCreate(); //create Custom Group - $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); //create Custom Field of data type Date - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); // Retrieve the field ID for sample custom field 'test_Date' - $params = array('label' => 'test_Date'); - $field = array(); + $params = ['label' => 'test_Date']; + $field = []; CRM_Core_BAO_CustomField::retrieve($params, $field); $fieldID = $customField['id']; // Set test_Date to a valid date value $date = '20080608000000'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $date, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the date value is stored - $values = array(); - $params = array( + $values = []; + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); @@ -61,10 +61,10 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Now set test_Date to an invalid date value and try to reset $badDate = '20080631000000'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $badDate, - ); + ]; CRM_Core_TemporaryErrorScope::useException(); $message = NULL; @@ -79,10 +79,10 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad date is passed'); - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['custom_' . $fieldID . '_1'], CRM_Utils_Date::mysqlToIso($date), @@ -90,17 +90,17 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { ); // Test setting test_Date to null - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => NULL, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::setValues($params); // Check that the date value is empty - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); @@ -116,20 +116,20 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { public function testSetGetValuesYesNoRadio() { $contactID = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); //create Custom Field of type YesNo(Boolean) Radio - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'Boolean', 'html_type' => 'Radio', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); // Retrieve the field ID for sample custom field 'test_Boolean' - $params = array('label' => 'test_Boolean'); - $field = array(); + $params = ['label' => 'test_Boolean']; + $field = []; //get field Id CRM_Core_BAO_CustomField::retrieve($params, $field); @@ -138,19 +138,19 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // valid boolean value '1' for Boolean Radio $yesNo = '1'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $yesNo, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the YesNo radio value is stored - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); @@ -160,10 +160,10 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Now set YesNo radio to an invalid boolean value and try to reset $badYesNo = '20'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $badYesNo, - ); + ]; CRM_Core_TemporaryErrorScope::useException(); $message = NULL; @@ -178,10 +178,10 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed'); - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php index 7256b4931d..580df3134d 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php @@ -14,20 +14,20 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { * Test store function for country. */ public function testStoreCountry() { - $params = array(); + $params = []; $contactID = $this->individualCreate(); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'Country', 'html_type' => 'Select Country', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); - $params[] = array( - $customField['id'] => array( + $params[] = [ + $customField['id'] => [ 'value' => 1228, 'type' => 'Country', 'custom_field_id' => $customField['id'], @@ -35,8 +35,8 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => '', - ), - ); + ], + ]; CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); @@ -50,19 +50,19 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { */ public function testStoreFile() { $contactID = $this->individualCreate(); - $file = $this->callAPISuccess('File', 'create', array('uri' => 'dummy_data')); + $file = $this->callAPISuccess('File', 'create', ['uri' => 'dummy_data']); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'File', 'html_type' => 'File', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); - $params[] = array( - $customField['id'] => array( + $params[] = [ + $customField['id'] => [ 'value' => 'i/contact_house.png', 'type' => 'File', 'custom_field_id' => $customField['id'], @@ -70,8 +70,8 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => $file['id'], - ), - ); + ], + ]; CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); @@ -86,17 +86,17 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { public function testStoreStateProvince() { $contactID = $this->individualCreate(); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'StateProvince', 'html_type' => 'Select State/Province', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); - $params[] = array( - $customField['id'] => array( + $params[] = [ + $customField['id'] => [ 'value' => 1029, 'type' => 'StateProvince', 'custom_field_id' => $customField['id'], @@ -104,8 +104,8 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => 1, - ), - ); + ], + ]; CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); @@ -118,20 +118,20 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { * Test store function for date. */ public function testStoreDate() { - $params = array(); + $params = []; $contactID = $this->individualCreate(); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); - $params[] = array( - $customField['id'] => array( + $params[] = [ + $customField['id'] => [ 'value' => '20080608000000', 'type' => 'Date', 'custom_field_id' => $customField['id'], @@ -139,8 +139,8 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => '', - ), - ); + ], + ]; CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); @@ -153,19 +153,19 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { * Test store function for rich text editor. */ public function testStoreRichTextEditor() { - $params = array(); + $params = []; $contactID = $this->individualCreate(); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'html_type' => 'RichTextEditor', 'data_type' => 'Memo', - ); + ]; $customField = $this->customFieldCreate($fields); - $params[] = array( - $customField['id'] => array( + $params[] = [ + $customField['id'] => [ 'value' => '

This is a test

', 'type' => 'Memo', 'custom_field_id' => $customField['id'], @@ -173,8 +173,8 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => '', - ), - ); + ], + ]; CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); @@ -188,19 +188,19 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { */ public function testGetEntityValues() { - $params = array(); + $params = []; $contactID = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); - $fields = array( + $customGroup = $this->customGroupCreate(['extends' => 'Individual']); + $fields = [ 'custom_group_id' => $customGroup['id'], 'html_type' => 'RichTextEditor', 'data_type' => 'Memo', - ); + ]; $customField = $this->customFieldCreate($fields); - $params[] = array( - $customField['id'] => array( + $params[] = [ + $customField['id'] => [ 'value' => '

This is a test

', 'type' => 'Memo', 'custom_field_id' => $customField['id'], @@ -208,8 +208,8 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => '', - ), - ); + ], + ]; CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); @@ -224,28 +224,28 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { } public function testCustomGroupMultiple() { - $params = array(); + $params = []; $contactID = $this->individualCreate(); $customGroup = $this->customGroupCreate(); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'String', 'html_type' => 'Text', - ); + ]; $customField = $this->customFieldCreate($fields); - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $customField['id'] . '_-1' => 'First String', - ); + ]; $error = CRM_Core_BAO_CustomValueTable::setValues($params); - $newParams = array( + $newParams = [ 'entityID' => $contactID, 'custom_' . $customField['id'] => 1, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); $this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]); diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTest.php index 16fcde5311..a2eb7be07a 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTest.php @@ -39,7 +39,7 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { public function testTypeCheckWithValidInput() { - $values = array( + $values = [ 'Memo' => 'Test1', 'String' => 'Test', 'Int' => 1, @@ -49,7 +49,7 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { 'StateProvince' => 'California', 'Country' => 'US', 'Link' => 'http://civicrm.org', - ); + ]; foreach ($values as $type => $value) { $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); if ($type == 'Date') { @@ -62,7 +62,7 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function testTypeCheckWithInvalidInput() { - $values = array('check1' => 'chk'); + $values = ['check1' => 'chk']; foreach ($values as $type => $value) { $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); $this->assertEquals($valid, NULL, 'Checking invalid type for returned CustomField Type.'); @@ -70,10 +70,10 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function testTypeCheckWithWrongInput() { - $values = array( + $values = [ 'String' => 1, 'Boolean' => 'US', - ); + ]; foreach ($values as $type => $value) { $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); $this->assertEquals($valid, NULL, 'Checking type ' . $type . ' for returned CustomField Type.'); @@ -81,7 +81,7 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function testTypeToFieldWithValidInput() { - $values = array( + $values = [ 'String' => 'char_data', 'File' => 'char_data', 'Boolean' => 'int_data', @@ -93,7 +93,7 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { 'Money' => 'decimal_data', 'Date' => 'date_data', 'Link' => 'char_data', - ); + ]; foreach ($values as $type => $value) { $valid = CRM_Core_BAO_CustomValue::typeToField($type); @@ -102,11 +102,11 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function testTypeToFieldWithWrongInput() { - $values = array( + $values = [ 'String' => 'memo_data', 'File' => 'date_data', 'Boolean' => 'char_data', - ); + ]; foreach ($values as $type => $value) { $valid = CRM_Core_BAO_CustomValue::typeToField($type); $this->assertNotEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.'); @@ -114,22 +114,22 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function fixCustomFieldValue() { - $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); + $customGroup = $this->customGroupCreate(['extends' => 'Individual']); - $fields = array( + $fields = [ 'custom_group_id' => $customGroup['id'], 'data_type' => 'Memo', 'html_type' => 'TextArea', 'default_value' => '', - ); + ]; $customField = $this->customFieldCreate($fields); $custom = 'custom_' . $customField['id']; - $params = array( + $params = [ 'email' => 'abc@webaccess.co.in', $custom => 'note', - ); + ]; CRM_Core_BAO_CustomValue::fixCustomFieldValue($params); $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.'); @@ -139,7 +139,7 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function testFixCustomFieldValueWithEmptyParams() { - $params = array(); + $params = []; $result = CRM_Core_BAO_CustomValue::fixCustomFieldValue($params); $this->assertEquals($result, NULL, 'Checking the returned value of type Memo.'); } diff --git a/tests/phpunit/CRM/Core/BAO/DashboardTest.php b/tests/phpunit/CRM/Core/BAO/DashboardTest.php index 3ed776e3b8..32560baa0f 100644 --- a/tests/phpunit/CRM/Core/BAO/DashboardTest.php +++ b/tests/phpunit/CRM/Core/BAO/DashboardTest.php @@ -52,10 +52,10 @@ class CRM_Core_BAO_DashboardTest extends CiviUnitTestCase { } public function parseUrlTestData() { - return array( - array('https://foo.bar', 'https://foo.bar'), - array('civicrm/path?reset=1&unit=test', CRM_Utils_System::url('civicrm/path', 'reset=1&unit=test', FALSE, NULL, FALSE)), - ); + return [ + ['https://foo.bar', 'https://foo.bar'], + ['civicrm/path?reset=1&unit=test', CRM_Utils_System::url('civicrm/path', 'reset=1&unit=test', FALSE, NULL, FALSE)], + ]; } } diff --git a/tests/phpunit/CRM/Core/BAO/EmailTest.php b/tests/phpunit/CRM/Core/BAO/EmailTest.php index 530a4030a7..765150d615 100644 --- a/tests/phpunit/CRM/Core/BAO/EmailTest.php +++ b/tests/phpunit/CRM/Core/BAO/EmailTest.php @@ -9,7 +9,7 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->quickCleanup(array('civicrm_contact', 'civicrm_email')); + $this->quickCleanup(['civicrm_contact', 'civicrm_email']); } /** @@ -18,13 +18,13 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { public function testAdd() { $contactId = $this->individualCreate(); - $params = array(); - $params = array( + $params = []; + $params = [ 'email' => 'jane.doe@example.com', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Email::add($params); @@ -34,13 +34,13 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { // Now call add() to modify an existing email address - $params = array(); - $params = array( + $params = []; + $params = [ 'id' => $emailId, 'contact_id' => $contactId, 'is_bulkmail' => 1, 'on_hold' => 1, - ); + ]; CRM_Core_BAO_Email::add($params); @@ -58,12 +58,12 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { public function testHoldEmail() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'email' => 'jane.doe@example.com', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Email::add($params); @@ -72,12 +72,12 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { ); // Now call add() to update on_hold=1 ("On Hold Bounce") and check record state - $params = array(); - $params = array( + $params = []; + $params = [ 'id' => $emailId, 'contact_id' => $contactId, 'on_hold' => 1, - ); + ]; CRM_Core_BAO_Email::add($params); @@ -96,12 +96,12 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { ); // Now call add() to update on_hold=2 ("On Hold Opt-out") and check record state - $params = array(); - $params = array( + $params = []; + $params = [ 'id' => $emailId, 'contact_id' => $contactId, 'on_hold' => 2, - ); + ]; CRM_Core_BAO_Email::add($params); @@ -120,12 +120,12 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { ); // Now call add() with on_hold=null (not on hold) and verify that reset_date is set. - $params = array(); - $params = array( + $params = []; + $params = [ 'id' => $emailId, 'contact_id' => $contactId, 'on_hold' => 'null', - ); + ]; CRM_Core_BAO_Email::add($params); $this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 0, @@ -152,13 +152,13 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { * AllEmails() method - get all emails for our contact, with primary email first */ public function testAllEmails() { - $contactParams = array( + $contactParams = [ 'first_name' => 'Alan', 'last_name' => 'Smith', 'email' => 'alan.smith1@example.com', - 'api.email.create.0' => array('email' => 'alan.smith2@example.com', 'location_type_id' => 'Home'), - 'api.email.create.1' => array('email' => 'alan.smith3@example.com', 'location_type_id' => 'Main'), - ); + 'api.email.create.0' => ['email' => 'alan.smith2@example.com', 'location_type_id' => 'Home'], + 'api.email.create.1' => ['email' => 'alan.smith3@example.com', 'location_type_id' => 'Main'], + ]; $contactId = $this->individualCreate($contactParams); diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index 6173bc3476..ee66811b23 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -41,11 +41,11 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { public function testCreate() { $contactId = $this->individualCreate(); $financialTypeId = 1; - $this->contributionCreate(array( + $this->contributionCreate([ 'contact_id' => $contactId, 'financial_type_id' => $financialTypeId, - )); - $params = array( + ]); + $params = [ 'contribution_id' => $financialTypeId, 'to_financial_account_id' => 1, 'trxn_date' => 20091021184930, @@ -55,7 +55,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { 'currency' => 'USD', 'payment_processor' => 'Dummy', 'trxn_id' => 'test_01014000', - ); + ]; $FinancialTrxn = CRM_Core_BAO_FinancialTrxn::create($params); $result = $this->assertDBNotNull('CRM_Core_BAO_FinancialTrxn', $FinancialTrxn->id, @@ -72,7 +72,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { public function testGetTotalPayments() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -89,7 +89,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { 'trxn_id' => '22ereerwwe4444yy', 'invoice_id' => '86ed39e9e9yy6ef6541621ce0eafe7eb81', 'thankyou_date' => '20080522', - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); $contribution = $contribution['values'][$contribution['id']]; @@ -123,7 +123,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { $cmp = bccomp($total, $paid, 5); // If paid amount is greater or equal to total amount if ($cmp == 0 || $cmp == -1) { - civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); + civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id']]); } $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution['id']); @@ -134,17 +134,17 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { * Test for createDeferredTrxn(). */ public function testCreateDeferredTrxn() { - Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1')); + Civi::settings()->set('contribution_invoice_settings', ['deferred_revenue_enabled' => '1']); $cid = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 622, 'financial_type_id' => 4, - 'line_items' => array( - array( - 'line_item' => array( - array( + 'line_items' => [ + [ + 'line_item' => [ + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 16, @@ -153,23 +153,23 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { 'unit_price' => 100, 'line_total' => 100, 'financial_type_id' => 4, - ), - ), - 'params' => array(), - ), - ), - ); + ], + ], + 'params' => [], + ], + ], + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); $lineItems[1] = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']); $lineItemId = key($lineItems[1]); $lineItems[1][$lineItemId]['financial_item_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_item WHERE entity_table = 'civicrm_line_item' AND entity_id = {$lineItemId}"); // Get financial trxns for contribution - $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622)); + $trxn = $this->callAPISuccess("FinancialTrxn", "get", ['total_amount' => 622]); $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime('2016-01-20'))); $contributionObj = $this->getContributionObject($contribution['id']); $contributionObj->revenue_recognition_date = date('Ymd', strtotime("+1 month")); CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItems, $contributionObj); - $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622, 'id' => array("NOT IN" => array($trxn['id'])))); + $trxn = $this->callAPISuccess("FinancialTrxn", "get", ['total_amount' => 622, 'id' => ["NOT IN" => [$trxn['id']]]]); $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime("+1 month"))); } @@ -178,35 +178,35 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { */ public function testUpdateCreditCardDetailsUsingContributionAPI() { $cid = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 100, 'financial_type_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), NULL); $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL); - $params = array( + $params = [ 'card_type_id' => 2, 'pan_truncation' => 4567, 'id' => $contribution['id'], - ); + ]; $this->callAPISuccess("Contribution", "create", $params); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals($financialTrxn['card_type_id'], 2); $this->assertEquals($financialTrxn['pan_truncation'], 4567); @@ -217,30 +217,30 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { */ public function testUpdateCreditCardDetails() { $cid = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 100, 'financial_type_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), NULL); $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL); CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($contribution['id'], 4567, 2); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals($financialTrxn['card_type_id'], 2); $this->assertEquals($financialTrxn['pan_truncation'], 4567); @@ -252,7 +252,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { public function testGetPartialPaymentWithType() { //create the contribution that isn't paid yet $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -261,13 +261,13 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { 'total_amount' => 300.00, 'fee_amount' => 0.00, 'net_amount' => 300.00, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][7]; //make a payment one cent short - $params = array( + $params = [ 'contribution_id' => $contribution['id'], 'total_amount' => 299.99, - ); + ]; $this->callAPISuccess('Payment', 'create', $params); //amount owed should be one cent $amountOwed = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($contribution['id'], 'contribution')['amount_owed']; diff --git a/tests/phpunit/CRM/Core/BAO/IMTest.php b/tests/phpunit/CRM/Core/BAO/IMTest.php index 6c766ceeed..cc82bd0eb0 100644 --- a/tests/phpunit/CRM/Core/BAO/IMTest.php +++ b/tests/phpunit/CRM/Core/BAO/IMTest.php @@ -16,14 +16,14 @@ class CRM_Core_BAO_IMTest extends CiviUnitTestCase { public function testAdd() { $contactId = $this->individualCreate(); - $params = array(); - $params = array( + $params = []; + $params = [ 'name' => 'jane.doe', 'provider_id' => 1, 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_IM::add($params); @@ -33,13 +33,13 @@ class CRM_Core_BAO_IMTest extends CiviUnitTestCase { // Now call add() to modify an existing IM - $params = array(); - $params = array( + $params = []; + $params = [ 'id' => $imId, 'contact_id' => $contactId, 'provider_id' => 3, 'name' => 'doe.jane', - ); + ]; CRM_Core_BAO_IM::add($params); diff --git a/tests/phpunit/CRM/Core/BAO/LocationTest.php b/tests/phpunit/CRM/Core/BAO/LocationTest.php index 548b3f71e1..7df8d0ec80 100644 --- a/tests/phpunit/CRM/Core/BAO/LocationTest.php +++ b/tests/phpunit/CRM/Core/BAO/LocationTest.php @@ -42,14 +42,14 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->quickCleanup(array( + $this->quickCleanup([ 'civicrm_contact', 'civicrm_address', 'civicrm_loc_block', 'civicrm_email', 'civicrm_phone', 'civicrm_im', - )); + ]); } /** @@ -57,20 +57,20 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { * This method is called after a test is executed. */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_openid', 'civicrm_loc_block', - ); + ]; $this->quickCleanup($tablesToTruncate); } public function testCreateWithMissingParams() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'street_address' => 'Saint Helier St', - ); + ]; CRM_Core_BAO_Location::create($params); @@ -92,9 +92,9 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //create various element of location block //like address, phone, email, openid, im. - $params = array( - 'address' => array( - '1' => array( + $params = [ + 'address' => [ + '1' => [ 'street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', @@ -107,44 +107,44 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'geo_code_2' => '-105.00973', 'is_primary' => 1, 'location_type_id' => 1, - ), - ), - 'email' => array( - '1' => array( + ], + ], + 'email' => [ + '1' => [ 'email' => 'john.smith@example.org', 'is_primary' => 1, 'location_type_id' => 1, - ), - ), - 'phone' => array( - '1' => array( + ], + ], + 'phone' => [ + '1' => [ 'phone_type_id' => 1, 'phone' => '303443689', 'is_primary' => 1, 'location_type_id' => 1, - ), - '2' => array( + ], + '2' => [ 'phone_type_id' => 2, 'phone' => '9833910234', 'location_type_id' => 1, - ), - ), - 'openid' => array( - '1' => array( + ], + ], + 'openid' => [ + '1' => [ 'openid' => 'http://civicrm.org/', 'location_type_id' => 1, 'is_primary' => 1, - ), - ), - 'im' => array( - '1' => array( + ], + ], + 'im' => [ + '1' => [ 'name' => 'jane.doe', 'provider_id' => 1, 'location_type_id' => 1, 'is_primary' => 1, - ), - ), - ); + ], + ], + ]; $params['contact_id'] = $contactId; @@ -153,12 +153,12 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $locBlockId = CRM_Utils_Array::value('id', $location); //Now check DB for contact - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', @@ -169,36 +169,36 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); - $compareParams = array('email' => 'john.smith@example.org'); + $compareParams = ['email' => 'john.smith@example.org']; $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); - $compareParams = array('openid' => 'http://civicrm.org/'); + $compareParams = ['openid' => 'http://civicrm.org/']; $this->assertDBCompareValues('CRM_Core_DAO_OpenID', $searchParams, $compareParams); - $compareParams = array( + $compareParams = [ 'name' => 'jane.doe', 'provider_id' => 1, - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1, 'phone_type_id' => 1, - ); - $compareParams = array('phone' => '303443689'); + ]; + $compareParams = ['phone' => '303443689']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); - $searchParams = array( + $searchParams = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => 2, - ); - $compareParams = array('phone' => '9833910234'); + ]; + $compareParams = ['phone' => '9833910234']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //delete the location block @@ -214,9 +214,9 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { public function testCreateWithLocBlock() { $this->_contactId = $this->individualCreate(); $event = $this->eventCreate(); - $params = array( - 'address' => array( - '1' => array( + $params = [ + 'address' => [ + '1' => [ 'street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', @@ -229,37 +229,37 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'geo_code_2' => '-105.00973', 'is_primary' => 1, 'location_type_id' => 1, - ), - ), - 'email' => array( - '1' => array( + ], + ], + 'email' => [ + '1' => [ 'email' => 'john.smith@example.org', 'is_primary' => 1, 'location_type_id' => 1, - ), - ), - 'phone' => array( - '1' => array( + ], + ], + 'phone' => [ + '1' => [ 'phone_type_id' => 1, 'phone' => '303443689', 'is_primary' => 1, 'location_type_id' => 1, - ), - '2' => array( + ], + '2' => [ 'phone_type_id' => 2, 'phone' => '9833910234', 'location_type_id' => 1, - ), - ), - 'im' => array( - '1' => array( + ], + ], + 'im' => [ + '1' => [ 'name' => 'jane.doe', 'provider_id' => 1, 'location_type_id' => 1, 'is_primary' => 1, - ), - ), - ); + ], + ], + ]; $params['entity_id'] = $event['id']; $params['entity_table'] = 'civicrm_event'; @@ -271,10 +271,10 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $locBlockId = CRM_Utils_Array::value('id', $location); //update event record with location block id - $eventParams = array( + $eventParams = [ 'id' => $event['id'], 'loc_block_id' => $locBlockId, - ); + ]; CRM_Event_BAO_Event::add($eventParams); @@ -287,20 +287,20 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $locBlockId, 'Checking database for the record.' ); - $locElementIds = array(); - $locParams = array('id' => $locBlockId); + $locElementIds = []; + $locParams = ['id' => $locBlockId]; CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_LocBlock', $locParams, $locElementIds ); //Now check DB for location elements. - $searchParams = array( + $searchParams = [ 'id' => CRM_Utils_Array::value('address_id', $locElementIds), 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', @@ -311,43 +311,43 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); - $searchParams = array( + $searchParams = [ 'id' => CRM_Utils_Array::value('email_id', $locElementIds), 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array('email' => 'john.smith@example.org'); + ]; + $compareParams = ['email' => 'john.smith@example.org']; $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); - $searchParams = array( + $searchParams = [ 'id' => CRM_Utils_Array::value('phone_id', $locElementIds), 'location_type_id' => 1, 'is_primary' => 1, 'phone_type_id' => 1, - ); - $compareParams = array('phone' => '303443689'); + ]; + $compareParams = ['phone' => '303443689']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); - $searchParams = array( + $searchParams = [ 'id' => CRM_Utils_Array::value('phone_2_id', $locElementIds), 'location_type_id' => 1, 'phone_type_id' => 2, - ); - $compareParams = array('phone' => '9833910234'); + ]; + $compareParams = ['phone' => '9833910234']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); - $searchParams = array( + $searchParams = [ 'id' => CRM_Utils_Array::value('im_id', $locElementIds), 'location_type_id' => 1, 'is_primary' => 1, - ); - $compareParams = array( + ]; + $compareParams = [ 'name' => 'jane.doe', 'provider_id' => 1, - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); // Cleanup. @@ -365,10 +365,10 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $this->_contactId = $this->individualCreate(); //create test event record. $event = $this->eventCreate(); - $params['location'][1] = array( + $params['location'][1] = [ 'location_type_id' => 1, 'is_primary' => 1, - 'address' => array( + 'address' => [ 'street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', @@ -379,27 +379,27 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', - ), - 'email' => array( - '1' => array('email' => 'john.smith@example.org'), - ), - 'phone' => array( - '1' => array( + ], + 'email' => [ + '1' => ['email' => 'john.smith@example.org'], + ], + 'phone' => [ + '1' => [ 'phone_type_id' => 1, 'phone' => '303443689', - ), - '2' => array( + ], + '2' => [ 'phone_type_id' => 2, 'phone' => '9833910234', - ), - ), - 'im' => array( - '1' => array( + ], + ], + 'im' => [ + '1' => [ 'name' => 'jane.doe', 'provider_id' => 1, - ), - ), - ); + ], + ], + ]; $params['entity_id'] = $event['id']; $params['entity_table'] = 'civicrm_event'; @@ -409,10 +409,10 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $location = CRM_Core_BAO_Location::create($params, NULL, TRUE); $locBlockId = CRM_Utils_Array::value('id', $location); //update event record with location block id - $eventParams = array( + $eventParams = [ 'id' => $event['id'], 'loc_block_id' => $locBlockId, - ); + ]; CRM_Event_BAO_Event::add($eventParams); //delete the location block @@ -459,9 +459,9 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //create various element of location block //like address, phone, email, openid, im. - $params = array( - 'address' => array( - '1' => array( + $params = [ + 'address' => [ + '1' => [ 'street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', @@ -474,44 +474,44 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'geo_code_2' => '-105.00973', 'is_primary' => 1, 'location_type_id' => 1, - ), - ), - 'email' => array( - '1' => array( + ], + ], + 'email' => [ + '1' => [ 'email' => 'john.smith@example.org', 'is_primary' => 1, 'location_type_id' => 1, - ), - ), - 'phone' => array( - '1' => array( + ], + ], + 'phone' => [ + '1' => [ 'phone_type_id' => 1, 'phone' => '303443689', 'is_primary' => 1, 'location_type_id' => 1, - ), - '2' => array( + ], + '2' => [ 'phone_type_id' => 2, 'phone' => '9833910234', 'location_type_id' => 1, - ), - ), - 'openid' => array( - '1' => array( + ], + ], + 'openid' => [ + '1' => [ 'openid' => 'http://civicrm.org/', 'location_type_id' => 1, 'is_primary' => 1, - ), - ), - 'im' => array( - '1' => array( + ], + ], + 'im' => [ + '1' => [ 'name' => 'jane.doe', 'provider_id' => 1, 'location_type_id' => 1, 'is_primary' => 1, - ), - ), - ); + ], + ], + ]; $params['contact_id'] = $contactId; diff --git a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php index 45a5bc4a9a..1009943a71 100644 --- a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php +++ b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php @@ -1,57 +1,56 @@ -individualCreate(); - $contact_id = $this->individualCreate(); - - $tplParams = array( - 'isCaseActivity' => 1, - 'client_id' => $client_id, - 'activityTypeName' => 'Follow up', - 'activity' => array( - 'fields' => array( - array( - 'label' => 'Case ID', - 'type' => 'String', - 'value' => '1234', - ), - ), - ), - 'activitySubject' => 'Test 123', - 'idHash' => substr(sha1(CIVICRM_SITE_KEY . '1234'), 0, 7), - ); - - list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate( - array( - 'groupName' => 'msg_tpl_workflow_case', - 'valueName' => 'case_activity', - 'contactId' => $contact_id, - 'tplParams' => $tplParams, - 'from' => 'admin@example.com', - 'toName' => 'Demo', - 'toEmail' => 'admin@example.com', - 'attachments' => NULL, - ) - ); - - $this->assertEquals('[case #' . $tplParams['idHash'] . '] Test 123', $subject); - $this->assertContains('Your Case Role', $message); - $this->assertContains('Case ID : 1234', $message); - } - -} +individualCreate(); + $contact_id = $this->individualCreate(); + + $tplParams = [ + 'isCaseActivity' => 1, + 'client_id' => $client_id, + 'activityTypeName' => 'Follow up', + 'activity' => [ + 'fields' => [ + [ + 'label' => 'Case ID', + 'type' => 'String', + 'value' => '1234', + ], + ], + ], + 'activitySubject' => 'Test 123', + 'idHash' => substr(sha1(CIVICRM_SITE_KEY . '1234'), 0, 7), + ]; + + list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate( + [ + 'groupName' => 'msg_tpl_workflow_case', + 'valueName' => 'case_activity', + 'contactId' => $contact_id, + 'tplParams' => $tplParams, + 'from' => 'admin@example.com', + 'toName' => 'Demo', + 'toEmail' => 'admin@example.com', + 'attachments' => NULL, + ] + ); + + $this->assertEquals('[case #' . $tplParams['idHash'] . '] Test 123', $subject); + $this->assertContains('Your Case Role', $message); + $this->assertContains('Case ID : 1234', $message); + } + +} diff --git a/tests/phpunit/CRM/Core/BAO/NavigationTest.php b/tests/phpunit/CRM/Core/BAO/NavigationTest.php index 2a46be219f..5b16491b17 100644 --- a/tests/phpunit/CRM/Core/BAO/NavigationTest.php +++ b/tests/phpunit/CRM/Core/BAO/NavigationTest.php @@ -57,10 +57,10 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase { * by rebuilding reports. */ public function testNoDuplicateAllReportsLink() { - $existing_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1)); + $existing_links = $this->callAPISuccess('Navigation', 'get', ['label' => 'All Reports', 'sequential' => 1]); $this->assertNotEquals($existing_links['values'][0]['parent_id'], $existing_links['values'][1]['parent_id']); CRM_Core_BAO_Navigation::rebuildReportsNavigation(CRM_Core_Config::domainID()); - $new_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1)); + $new_links = $this->callAPISuccess('Navigation', 'get', ['label' => 'All Reports', 'sequential' => 1]); $this->assertEquals($existing_links['values'][0]['parent_id'], $new_links['values'][0]['parent_id']); $this->assertEquals($existing_links['values'][1]['parent_id'], $new_links['values'][1]['parent_id']); } @@ -98,16 +98,16 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase { $name = "Test Menu Link {$random_string}"; $url = "civicrm/test/{$random_string}"; $url_params = "reset=1"; - $params = array( + $params = [ 'name' => $name, 'label' => ts($name), 'url' => "{$url}?{$url_params}", 'parent_id' => NULL, 'is_active' => TRUE, - 'permission' => array( + 'permission' => [ 'access CiviCRM', - ), - ); + ], + ]; CRM_Core_BAO_Navigation::add($params); $new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, $url_params); $this->assertObjectHasAttribute('id', $new_nav); @@ -126,16 +126,16 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase { $name = "Test Menu Link {$random_string}"; $url = "civicrm/test/{$random_string}"; $url_params = "reset=1&output=criteria"; - $params = array( + $params = [ 'name' => $name, 'label' => ts($name), 'url' => "{$url}?{$url_params}", 'parent_id' => NULL, 'is_active' => TRUE, - 'permission' => array( + 'permission' => [ 'access CiviCRM', - ), - ); + ], + ]; CRM_Core_BAO_Navigation::add($params); $new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, 'reset=1%'); $this->assertObjectHasAttribute('id', $new_nav); @@ -169,24 +169,24 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase { * everywhere. They should be unchanged. */ public function testFixNavigationMenu_preserveIDs() { - $input[10] = array( - 'attributes' => array( + $input[10] = [ + 'attributes' => [ 'label' => 'Custom Menu Entry', 'parentID' => NULL, 'navID' => 10, 'active' => 1, - ), - 'child' => array( - '11' => array( - 'attributes' => array( + ], + 'child' => [ + '11' => [ + 'attributes' => [ 'label' => 'Custom Child Menu', 'parentID' => 10, 'navID' => 11, - ), + ], 'child' => NULL, - ), - ), - ); + ], + ], + ]; $output = $input; CRM_Core_BAO_Navigation::fixNavigationMenu($output); @@ -202,29 +202,29 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase { * should be filled in, and others should be preserved. */ public function testFixNavigationMenu_inferIDs() { - $input[10] = array( - 'attributes' => array( + $input[10] = [ + 'attributes' => [ 'label' => 'Custom Menu Entry', 'parentID' => NULL, 'navID' => 10, 'active' => 1, - ), - 'child' => array( - '0' => array( - 'attributes' => array( + ], + 'child' => [ + '0' => [ + 'attributes' => [ 'label' => 'Custom Child Menu', - ), + ], 'child' => NULL, - ), - '100' => array( - 'attributes' => array( + ], + '100' => [ + 'attributes' => [ 'label' => 'Custom Child Menu 2', 'navID' => 100, - ), + ], 'child' => NULL, - ), - ), - ); + ], + ], + ]; $output = $input; CRM_Core_BAO_Navigation::fixNavigationMenu($output); @@ -243,30 +243,30 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase { } public function testFixNavigationMenu_inferIDs_deep() { - $input[10] = array( - 'attributes' => array( + $input[10] = [ + 'attributes' => [ 'label' => 'Custom Menu Entry', 'parentID' => NULL, 'navID' => 10, 'active' => 1, - ), - 'child' => array( - '0' => array( - 'attributes' => array( + ], + 'child' => [ + '0' => [ + 'attributes' => [ 'label' => 'Custom Child Menu', - ), - 'child' => array( - '100' => array( - 'attributes' => array( + ], + 'child' => [ + '100' => [ + 'attributes' => [ 'label' => 'Custom Child Menu 2', 'navID' => 100, - ), + ], 'child' => NULL, - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; $output = $input; CRM_Core_BAO_Navigation::fixNavigationMenu($output); diff --git a/tests/phpunit/CRM/Core/BAO/OpenIDTest.php b/tests/phpunit/CRM/Core/BAO/OpenIDTest.php index 313fbe0ac4..1d0886b5c4 100644 --- a/tests/phpunit/CRM/Core/BAO/OpenIDTest.php +++ b/tests/phpunit/CRM/Core/BAO/OpenIDTest.php @@ -26,12 +26,12 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); $openIdURL = "http://test-username.civicrm.org/"; - $params = array( + $params = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'openid' => $openIdURL, 'is_primary' => 1, - ); + ]; $openObject = CRM_Core_BAO_OpenID::add($params); @@ -43,13 +43,13 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { // Now call add() to modify an existing open-id record - $params = array( + $params = [ 'id' => $openId, 'contact_id' => $contactId, 'openid' => $openIdURL, 'is_bulkmail' => 1, 'allowed_to_login' => 1, - ); + ]; CRM_Core_BAO_OpenID::add($params); @@ -70,12 +70,12 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); $openIdURL = "http://test-username.civicrm.org/"; - $params = array( + $params = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'openid' => $openIdURL, 'is_primary' => 1, - ); + ]; $openObject = CRM_Core_BAO_OpenID::add($params); @@ -89,13 +89,13 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { // Now call add() to modify an existing open-id record - $params = array( + $params = [ 'id' => $openId, 'contact_id' => $contactId, 'openid' => $openIdURL, 'is_bulkmail' => 1, 'allowed_to_login' => 1, - ); + ]; CRM_Core_BAO_OpenID::add($params); @@ -116,13 +116,13 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { // create first openid $openIdURLOne = "http://test-one-username.civicrm.org/"; - $params = array( + $params = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'openid' => $openIdURLOne, 'is_primary' => 1, 'allowed_to_login' => 1, - ); + ]; $openObjectOne = CRM_Core_BAO_OpenID::add($params); @@ -133,11 +133,11 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { // create second openid $openIdURLTwo = "http://test-two-username.civicrm.org/"; - $params = array( + $params = [ 'contact_id' => $contactId, 'location_type_id' => 1, 'openid' => $openIdURLTwo, - ); + ]; $openObjectTwo = CRM_Core_BAO_OpenID::add($params); $openIdTwo = $openObjectTwo->id; diff --git a/tests/phpunit/CRM/Core/BAO/OptionGroupTest.php b/tests/phpunit/CRM/Core/BAO/OptionGroupTest.php index 320d6f638e..caf27f618b 100644 --- a/tests/phpunit/CRM/Core/BAO/OptionGroupTest.php +++ b/tests/phpunit/CRM/Core/BAO/OptionGroupTest.php @@ -46,20 +46,20 @@ class CRM_Core_BAO_OptionGroupTest extends CiviUnitTestCase { * Ensure only one option value exists after calling ensureOptionValueExists. */ public function testEnsureOptionGroupExistsExistingValue() { - CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'contribution_status')); - $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'contribution_status')); + CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'contribution_status']); + $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'contribution_status']); } /** * Ensure only one option value exists adds a new value. */ public function testEnsureOptionGroupExistsNewValue() { - CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'Bombed')); - $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', array('field' => 'option_group_id'))['values']; + CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed']); + $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values']; $this->assertTrue(in_array('Bombed', $optionGroups)); - CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'Bombed Again')); - $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', array('field' => 'option_group_id'))['values']; + CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed Again']); + $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values']; $this->assertTrue(in_array('Bombed Again', $optionGroups)); } diff --git a/tests/phpunit/CRM/Core/BAO/OptionValueTest.php b/tests/phpunit/CRM/Core/BAO/OptionValueTest.php index 778812833c..88afe72db9 100644 --- a/tests/phpunit/CRM/Core/BAO/OptionValueTest.php +++ b/tests/phpunit/CRM/Core/BAO/OptionValueTest.php @@ -46,16 +46,16 @@ class CRM_Core_BAO_OptionValueTest extends CiviUnitTestCase { * Ensure only one option value exists after calling ensureOptionValueExists. */ public function testEnsureOptionValueExistsExistingValue() { - CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Completed', 'option_group_id' => 'contribution_status')); - $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Completed', 'option_group_id' => 'contribution_status')); + CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Completed', 'option_group_id' => 'contribution_status']); + $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Completed', 'option_group_id' => 'contribution_status']); } /** * Ensure only one option value exists adds a new value. */ public function testEnsureOptionValueExistsNewValue() { - CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Bombed', 'option_group_id' => 'contribution_status')); - $optionValues = $this->callAPISuccess('OptionValue', 'get', array('option_group_id' => 'contribution_status')); + CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Bombed', 'option_group_id' => 'contribution_status']); + $optionValues = $this->callAPISuccess('OptionValue', 'get', ['option_group_id' => 'contribution_status']); foreach ($optionValues['values'] as $value) { if ($value['name'] == 'Bombed') { return; @@ -71,13 +71,13 @@ class CRM_Core_BAO_OptionValueTest extends CiviUnitTestCase { * decision to disable it & leaving it in that state. */ public function testEnsureOptionValueExistsDisabled() { - $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0)); - $value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status')); + $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0]); + $value = $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Crashed', 'option_group_id' => 'contribution_status']); $this->assertEquals(0, $value['is_active']); $this->assertEquals($value['id'], $optionValue['id']); - $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status')); - $value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status')); + $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Crashed', 'option_group_id' => 'contribution_status']); + $value = $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Crashed', 'option_group_id' => 'contribution_status']); $this->assertEquals(0, $value['is_active']); $this->assertEquals($value['id'], $optionValue['id']); } diff --git a/tests/phpunit/CRM/Core/BAO/PhoneTest.php b/tests/phpunit/CRM/Core/BAO/PhoneTest.php index b876b141a5..e3621c8064 100644 --- a/tests/phpunit/CRM/Core/BAO/PhoneTest.php +++ b/tests/phpunit/CRM/Core/BAO/PhoneTest.php @@ -41,14 +41,14 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { public function testAdd() { $contactId = $this->individualCreate(); - $params = array(); - $params = array( + $params = []; + $params = [ 'phone' => '(415) 222-1011 x 221', 'is_primary' => 1, 'location_type_id' => 1, 'phone_type' => 'Mobile', 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Phone::add($params); @@ -62,12 +62,12 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { // Now call add() to modify the existing phone number - $params = array(); - $params = array( + $params = []; + $params = [ 'id' => $phoneId, 'contact_id' => $contactId, 'phone' => '(415) 222-5432', - ); + ]; CRM_Core_BAO_Phone::add($params); @@ -82,12 +82,12 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { * AllPhones() method - get all Phones for our contact, with primary Phone first. */ public function testAllPhones() { - $contactParams = array( + $contactParams = [ 'first_name' => 'Alan', 'last_name' => 'Smith', - 'api.phone.create' => array('phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'), - 'api.phone.create.1' => array('phone' => '(415) 222-5432', 'location_type_id' => 'Work'), - ); + 'api.phone.create' => ['phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'], + 'api.phone.create.1' => ['phone' => '(415) 222-5432', 'location_type_id' => 'Work'], + ]; $contactId = $this->individualCreate($contactParams); diff --git a/tests/phpunit/CRM/Core/BAO/PrevNextCacheTest.php b/tests/phpunit/CRM/Core/BAO/PrevNextCacheTest.php index 39c491dc40..c841dfb044 100644 --- a/tests/phpunit/CRM/Core/BAO/PrevNextCacheTest.php +++ b/tests/phpunit/CRM/Core/BAO/PrevNextCacheTest.php @@ -35,31 +35,31 @@ class CRM_Core_BAO_PrevNextCacheTest extends CiviUnitTestCase { $dao = new CRM_Core_BAO_PrevNextCache(); $dao->entity_id1 = 1; $dao->entity_id2 = 2; - $dao->data = serialize(array( + $dao->data = serialize([ 'srcID' => 1, 'srcName' => 'Ms. Meliissa Mouse II', 'dstID' => 2, 'dstName' => 'Mr. Maurice Mouse II', 'weight' => 20, 'canMerge' => TRUE, - )); + ]); $dao->save(); $dao = new CRM_Core_BAO_PrevNextCache(); $dao->id = 1; - CRM_Core_BAO_PrevNextCache::flipPair(array(1), 0); + CRM_Core_BAO_PrevNextCache::flipPair([1], 0); $dao->find(TRUE); $this->assertEquals(1, $dao->entity_id1); $this->assertEquals(2, $dao->entity_id2); - $this->assertEquals(serialize(array( + $this->assertEquals(serialize([ 'srcName' => 'Mr. Maurice Mouse II', 'dstID' => 1, 'dstName' => 'Ms. Meliissa Mouse II', 'weight' => 20, 'canMerge' => TRUE, 'srcID' => 2, - )), $dao->data); + ]), $dao->data); - $this->quickCleanup(array('civicrm_prevnext_cache')); + $this->quickCleanup(['civicrm_prevnext_cache']); } public function testSetItem() { diff --git a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php index 73943396a3..4c0e6563a2 100644 --- a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php +++ b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php @@ -60,8 +60,8 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { $recursion = new CRM_Core_BAO_RecurringEntity(); $recursion->entity_id = $daoActivity->id; $recursion->entity_table = 'civicrm_activity'; - $recursion->dateColumns = array('activity_date_time'); - $recursion->schedule = array( + $recursion->dateColumns = ['activity_date_time']; + $recursion->schedule = [ 'entity_value' => $daoActivity->id, 'start_action_date' => $daoActivity->activity_date_time, 'entity_status' => 'fourth saturday', @@ -69,17 +69,17 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { 'repetition_frequency_interval' => 3, 'start_action_offset' => 5, 'used_for' => 'activity', - ); + ]; $generatedEntities = $recursion->generate(); $this->assertEquals(5, count($generatedEntities['civicrm_activity']), "Cehck if number of iterations are 5"); - $expectedDates = array( + $expectedDates = [ '20141025103000', '20141227103000', '20150328103000', '20150627103000', '20150926103000', - ); + ]; foreach ($generatedEntities['civicrm_activity'] as $entityID) { $this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id', 'id', 'Check DB if repeating activities were created' @@ -95,7 +95,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { $daoActivity->save(); // check if other activities were affected - $actualDates = array(); + $actualDates = []; foreach ($generatedEntities['civicrm_activity'] as $entityID) { $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Changed Activity', 'Check if subject was updated'); $actualDates[] = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $entityID, 'activity_date_time', 'id'))); @@ -109,7 +109,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { * Creating action schedule */ private function createActionSchedule($entity_id, $entity_table) { - $params = array( + $params = [ "used_for" => $entity_table, "entity_value" => $entity_id, "start_action_date" => date("YmdHis"), @@ -117,7 +117,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { "repetition_frequency_interval" => "3", "start_action_condition" => "monday,tuesday,wednesday,thursday,friday,saturday", "start_action_offset" => "2", - ); + ]; $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($params); return $actionScheduleObj; } @@ -127,25 +127,25 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { */ private function createRecurringEntities($actionScheduleObj, $entity_id, $entity_table) { $recursion = new CRM_Core_BAO_RecurringEntity(); - $recursion->dateColumns = array( + $recursion->dateColumns = [ "start_date", - ); + ]; $recursion->scheduleId = $actionScheduleObj->id; $recursion->entity_id = $entity_id; $recursion->entity_table = $entity_table; - $recursion->linkedEntities = array( - array( + $recursion->linkedEntities = [ + [ "table" => "civicrm_price_set_entity", - "findCriteria" => array( + "findCriteria" => [ "entity_id" => $entity_id, "entity_table" => $entity_table, - ), - "linkedColumns" => array( + ], + "linkedColumns" => [ "entity_id", - ), + ], "isRecurringEntityRecord" => FALSE, - ), - ); + ], + ]; return $recursion->generate(); } @@ -159,7 +159,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { CRM_Price_BAO_PriceSet::addTo($entity_table, $entity_id, 1); $actionScheduleObj = $this->createActionSchedule($entity_id, $entity_table); $recurringEntities = $this->createRecurringEntities($actionScheduleObj, $entity_id, $entity_table); - $finalResult = CRM_Core_BAO_RecurringEntity::updateModeAndPriceSet($entity_id, $entity_table, CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES, array(), 2); + $finalResult = CRM_Core_BAO_RecurringEntity::updateModeAndPriceSet($entity_id, $entity_table, CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES, [], 2); $this->assertEquals(2, count($recurringEntities["civicrm_event"]), "Recurring events not created."); $this->assertEquals(2, count($recurringEntities["civicrm_price_set_entity"]), "Recurring price sets not created."); $priceSetOne = CRM_Price_BAO_PriceSet::getFor($entity_table, $recurringEntities["civicrm_price_set_entity"][0]); @@ -198,8 +198,8 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { $recursion = new CRM_Core_BAO_RecurringEntity(); $recursion->entity_id = $daoEvent->id; $recursion->entity_table = 'civicrm_event'; - $recursion->dateColumns = array('start_date'); - $recursion->schedule = array( + $recursion->dateColumns = ['start_date']; + $recursion->schedule = [ 'entity_value' => $daoEvent->id, 'start_action_date' => $daoEvent->start_date, 'start_action_condition' => 'monday', @@ -207,33 +207,33 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { 'repetition_frequency_interval' => 1, 'start_action_offset' => 4, 'used_for' => 'event', - ); + ]; - $recursion->linkedEntities = array( - array( + $recursion->linkedEntities = [ + [ 'table' => 'civicrm_tell_friend', - 'findCriteria' => array( + 'findCriteria' => [ 'entity_id' => $recursion->entity_id, 'entity_table' => 'civicrm_event', - ), - 'linkedColumns' => array('entity_id'), + ], + 'linkedColumns' => ['entity_id'], 'isRecurringEntityRecord' => TRUE, - ), - ); + ], + ]; $interval = $recursion->getInterval($daoEvent->start_date, $daoEvent->end_date); - $recursion->intervalDateColumns = array('end_date' => $interval); + $recursion->intervalDateColumns = ['end_date' => $interval]; $generatedEntities = $recursion->generate(); $this->assertArrayHasKey('civicrm_event', $generatedEntities, 'Check if generatedEntities has civicrm_event as required key'); - $expectedDates = array( + $expectedDates = [ '20141027103000' => '20141029103000', '20141103103000' => '20141105103000', '20141110103000' => '20141112103000', '20141117103000' => '20141119103000', - ); + ]; $this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_event'], 'Check if the number of events created are right'); - $actualDates = array(); + $actualDates = []; foreach ($generatedEntities['civicrm_event'] as $key => $val) { $this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id', 'id', 'Check if repeating events were created.'); $startDate = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $val, 'start_date', 'id'))); @@ -272,25 +272,25 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { $this->assertEquals($key, $actKey, "Check if both the keys are same"); //Cross check event exists before we test deletion - $searchParamsEventBeforeDelete = array( + $searchParamsEventBeforeDelete = [ 'entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event', - ); - $expectedValuesEventBeforeDelete = array( + ]; + $expectedValuesEventBeforeDelete = [ 'entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event', - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsEventBeforeDelete, $expectedValuesEventBeforeDelete); //Cross check event exists before we test deletion - $searchParamsTellAFriendBeforeDelete = array( + $searchParamsTellAFriendBeforeDelete = [ 'entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend', - ); - $expectedValuesTellAFriendBeforeDelete = array( + ]; + $expectedValuesTellAFriendBeforeDelete = [ 'entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend', - ); + ]; $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsTellAFriendBeforeDelete, $expectedValuesTellAFriendBeforeDelete); //Delete an event from recurring set and respective linked entity should be deleted from civicrm_recurring_entity_table @@ -302,19 +302,19 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { //Check if this event_id was deleted $this->assertDBNull('CRM_Event_DAO_Event', $generatedEntities['civicrm_event'][$key], 'id', 'id', 'Check if event was deleted'); - $searchParams = array( + $searchParams = [ 'entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event', - ); - $compareParams = array(); + ]; + $compareParams = []; $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParams, $compareParams); //Find tell_a_friend id if that was deleted from civicrm - $searchActParams = array( + $searchActParams = [ 'entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend', - ); - $compareActParams = array(); + ]; + $compareActParams = []; $this->assertDBCompareValues('CRM_Friend_DAO_Friend', $searchActParams, $compareActParams); } @@ -328,10 +328,9 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { 'extends' => 'Activity', ]); $customField = $this->customFieldCreate([ - 'custom_group_id' => $customGroup['id'], - 'default_value' => '', - ] - ); + 'custom_group_id' => $customGroup['id'], + 'default_value' => '', + ]); // Create activity Tag $tag = $this->tagCreate([ diff --git a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php index a5b2d6634a..0666921f7f 100644 --- a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php +++ b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php @@ -41,7 +41,7 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * already exists. */ public function testCreateIndex() { - $tables = array('civicrm_uf_join' => array('weight')); + $tables = ['civicrm_uf_join' => ['weight']]; CRM_Core_BAO_SchemaHandler::createIndexes($tables); CRM_Core_BAO_SchemaHandler::createIndexes($tables); $dao = CRM_Core_DAO::executeQuery("SHOW INDEX FROM civicrm_uf_join"); @@ -60,7 +60,7 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * Test CRM_Core_BAO_SchemaHandler::getIndexes() function */ public function testGetIndexes() { - $indexes = CRM_Core_BAO_SchemaHandler::getIndexes(array('civicrm_contact')); + $indexes = CRM_Core_BAO_SchemaHandler::getIndexes(['civicrm_contact']); $this->assertTrue(array_key_exists('index_contact_type', $indexes['civicrm_contact'])); } @@ -71,15 +71,15 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * already exists. */ public function testCombinedIndex() { - $tables = array('civicrm_uf_join' => array('weight')); + $tables = ['civicrm_uf_join' => ['weight']]; CRM_Core_BAO_SchemaHandler::createIndexes($tables); - $tables = array('civicrm_uf_join' => array(array('weight', 'module'))); + $tables = ['civicrm_uf_join' => [['weight', 'module']]]; CRM_Core_BAO_SchemaHandler::createIndexes($tables); $dao = CRM_Core_DAO::executeQuery("SHOW INDEX FROM civicrm_uf_join"); $weightCount = 0; $combinedCount = 0; - $indexes = array(); + $indexes = []; while ($dao->fetch()) { if ($dao->Column_name == 'weight') { @@ -127,17 +127,17 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { $this->assertFalse(CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_contact', 'index_hash')); // Recreate it to clean up after the test. - CRM_Core_BAO_SchemaHandler::createIndexes(array('civicrm_contact' => array('hash'))); + CRM_Core_BAO_SchemaHandler::createIndexes(['civicrm_contact' => ['hash']]); } /** * @return array */ public function columnTests() { - $columns = array(); - $columns[] = array('civicrm_contribution', 'total_amount'); - $columns[] = array('civicrm_contact', 'first_name'); - $columns[] = array('civicrm_contact', 'xxxx'); + $columns = []; + $columns[] = ['civicrm_contribution', 'total_amount']; + $columns[] = ['civicrm_contact', 'first_name']; + $columns[] = ['civicrm_contact', 'xxxx']; return $columns; } @@ -160,9 +160,9 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * @return array */ public function foreignKeyTests() { - $keys = array(); - $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id'); - $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_id'); + $keys = []; + $keys[] = ['civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id']; + $keys[] = ['civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_id']; return $keys; } @@ -192,36 +192,36 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * Test that missing indices are correctly created */ public function testCreateMissingIndices() { - $indices = array( - 'test_table' => array( - 'test_index1' => array( + $indices = [ + 'test_table' => [ + 'test_index1' => [ 'name' => 'test_index1', - 'field' => array( + 'field' => [ 'title', - ), + ], 'unique' => FALSE, - ), - 'test_index2' => array( + ], + 'test_index2' => [ 'name' => 'test_index2', - 'field' => array( + 'field' => [ 'title', - ), + ], 'unique' => TRUE, - ), - 'test_index3' => array( + ], + 'test_index3' => [ 'name' => 'test_index3', - 'field' => array( + 'field' => [ 'title(3)', 'name', - ), + ], 'unique' => FALSE, - ), - ), - ); + ], + ], + ]; CRM_Core_DAO::executeQuery('DROP table if exists `test_table`'); CRM_Core_DAO::executeQuery('CREATE table `test_table` (`title` varchar(255), `name` varchar(255))'); CRM_Core_BAO_SchemaHandler::createMissingIndices($indices); - $actualIndices = CRM_Core_BAO_SchemaHandler::getIndexes(array('test_table')); + $actualIndices = CRM_Core_BAO_SchemaHandler::getIndexes(['test_table']); $this->assertEquals($actualIndices, $indices); } @@ -231,17 +231,17 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { public function testReconcileMissingIndices() { CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_contact DROP INDEX index_sort_name'); $missingIndices = CRM_Core_BAO_SchemaHandler::getMissingIndices(); - $this->assertEquals(array( - 'civicrm_contact' => array( - array( + $this->assertEquals([ + 'civicrm_contact' => [ + [ 'name' => 'index_sort_name', - 'field' => array('sort_name'), + 'field' => ['sort_name'], 'localizable' => FALSE, 'sig' => 'civicrm_contact::0::sort_name', - ), - ), - ), $missingIndices); - $this->callAPISuccess('System', 'updateindexes', array()); + ], + ], + ], $missingIndices); + $this->callAPISuccess('System', 'updateindexes', []); $missingIndices = CRM_Core_BAO_SchemaHandler::getMissingIndices(); $this->assertTrue(empty($missingIndices)); } @@ -250,10 +250,10 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * Check for partial indices */ public function testPartialIndices() { - $tables = array( + $tables = [ 'index_all' => 'civicrm_prevnext_cache', 'UI_entity_id_entity_table_tag_id' => 'civicrm_entity_tag', - ); + ]; CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_prevnext_cache', 'index_all'); //Missing Column `is_selected`. CRM_Core_DAO::executeQuery('CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table)'); @@ -283,15 +283,15 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { * Test index signatures are added correctly */ public function testAddIndexSignatures() { - $indices = array( - 'one' => array( - 'field' => array('id', 'name(3)'), + $indices = [ + 'one' => [ + 'field' => ['id', 'name(3)'], 'unique' => TRUE, - ), - 'two' => array( - 'field' => array('title'), - ), - ); + ], + 'two' => [ + 'field' => ['title'], + ], + ]; CRM_Core_BAO_SchemaHandler::addIndexSignature('my_table', $indices); $this->assertEquals($indices['one']['sig'], 'my_table::1::id::name(3)'); $this->assertEquals($indices['two']['sig'], 'my_table::0::title'); diff --git a/tests/phpunit/CRM/Core/BAO/SettingTest.php b/tests/phpunit/CRM/Core/BAO/SettingTest.php index b9bf5507d0..893bfaac5b 100644 --- a/tests/phpunit/CRM/Core/BAO/SettingTest.php +++ b/tests/phpunit/CRM/Core/BAO/SettingTest.php @@ -129,15 +129,15 @@ class CRM_Core_BAO_SettingTest extends CiviUnitTestCase { */ public function testOnChange() { global $_testOnChange_hookCalls; - $this->setMockSettingsMetaData(array( - 'onChangeExample' => array( + $this->setMockSettingsMetaData([ + 'onChangeExample' => [ 'group_name' => 'CiviCRM Preferences', 'group' => 'core', 'name' => 'onChangeExample', 'type' => 'Array', 'quick_form_type' => 'Element', 'html_type' => 'advmultiselect', - 'default' => array('CiviEvent', 'CiviContribute'), + 'default' => ['CiviEvent', 'CiviContribute'], 'add' => '4.4', 'title' => 'List of Components', 'is_domain' => '1', @@ -145,25 +145,25 @@ class CRM_Core_BAO_SettingTest extends CiviUnitTestCase { 'description' => NULL, 'help_text' => NULL, // list of callbacks - 'on_change' => array( - array(__CLASS__, '_testOnChange_onChangeExample'), - ), - ), - )); + 'on_change' => [ + [__CLASS__, '_testOnChange_onChangeExample'], + ], + ], + ]); // set initial value - $_testOnChange_hookCalls = array('count' => 0); - Civi::settings()->set('onChangeExample', array('First', 'Value')); + $_testOnChange_hookCalls = ['count' => 0]; + Civi::settings()->set('onChangeExample', ['First', 'Value']); $this->assertEquals(1, $_testOnChange_hookCalls['count']); - $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['newValue']); + $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['newValue']); $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); // change value - $_testOnChange_hookCalls = array('count' => 0); - Civi::settings()->set('onChangeExample', array('Second', 'Value')); + $_testOnChange_hookCalls = ['count' => 0]; + Civi::settings()->set('onChangeExample', ['Second', 'Value']); $this->assertEquals(1, $_testOnChange_hookCalls['count']); - $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['oldValue']); - $this->assertEquals(array('Second', 'Value'), $_testOnChange_hookCalls['newValue']); + $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['oldValue']); + $this->assertEquals(['Second', 'Value'], $_testOnChange_hookCalls['newValue']); $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); } diff --git a/tests/phpunit/CRM/Core/BAO/UFFieldTest.php b/tests/phpunit/CRM/Core/BAO/UFFieldTest.php index 24b6d2597b..f5dc72b4b8 100644 --- a/tests/phpunit/CRM/Core/BAO/UFFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/UFFieldTest.php @@ -9,39 +9,39 @@ class CRM_Core_BAO_UFFieldTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->quickCleanup(array('civicrm_uf_group', 'civicrm_uf_field')); + $this->quickCleanup(['civicrm_uf_group', 'civicrm_uf_field']); } /** * When passing in a GID, fields should be omitted if they already appear in the group. */ public function testGetAvailable_byGid() { - $ufGroupId = $this->createUFGroup(array( - array( + $ufGroupId = $this->createUFGroup([ + [ 'field_name' => 'do_not_sms', 'field_type' => 'Contact', - ), - array( + ], + [ 'field_name' => 'first_name', 'field_type' => 'Individual', - ), - array( + ], + [ 'field_name' => 'amount_level', 'field_type' => 'Contribution', - ), - array( + ], + [ 'field_name' => 'participant_note', 'field_type' => 'Participant', - ), - array( + ], + [ 'field_name' => 'join_date', 'field_type' => 'Membership', - ), - array( + ], + [ 'field_name' => 'activity_date_time', 'field_type' => 'Activity', - ), - )); + ], + ]); $fields = CRM_Core_BAO_UFField::getAvailableFields($ufGroupId); // Make sure that each entity has 1+ present field and 1+ missing (already-used) field @@ -86,17 +86,17 @@ class CRM_Core_BAO_UFFieldTest extends CiviUnitTestCase { * it's already part of the profile. */ public function testGetAvailable_byGidDefaults() { - $ufGroupId = $this->createUFGroup(array( - array( + $ufGroupId = $this->createUFGroup([ + [ 'field_name' => 'do_not_sms', 'field_type' => 'Contact', - ), - array( + ], + [ 'field_name' => 'first_name', 'field_type' => 'Individual', - ), - )); - $defaults = array('field_name' => array('Individual', 'first_name')); + ], + ]); + $defaults = ['field_name' => ['Individual', 'first_name']]; $fields = CRM_Core_BAO_UFField::getAvailableFields($ufGroupId, $defaults); // already used @@ -201,7 +201,7 @@ class CRM_Core_BAO_UFFieldTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($ufGroup->id)); foreach ($fields as $field) { - $defaults = array( + $defaults = [ 'uf_group_id' => $ufGroup->id, 'visibility' => 'Public Pages and Listings', 'weight' => 1, @@ -209,7 +209,7 @@ class CRM_Core_BAO_UFFieldTest extends CiviUnitTestCase { 'is_searchable' => 1, 'is_active' => 1, 'location_type_id' => NULL, - ); + ]; $params = array_merge($field, $defaults); $ufField = $this->callAPISuccess('UFField', 'create', $params); $this->assertAPISuccess($ufField); diff --git a/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php b/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php index d58bbddbf6..2cd67ff188 100644 --- a/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php +++ b/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php @@ -11,7 +11,7 @@ class CRM_Core_CodeGen_FreshnessTest extends CiviUnitTestCase { public function testDAOs() { $tasks = $this->findTasks('CRM_Core_CodeGen_DAO'); - $names = array(); + $names = []; foreach ($tasks as $task) { /** @var CRM_Core_CodeGen_DAO $task */ $names[] = $task->name; @@ -40,7 +40,7 @@ class CRM_Core_CodeGen_FreshnessTest extends CiviUnitTestCase { protected function findTasks($clazz) { $genCode = $this->createCodeGen(); $tasks = $genCode->getTasks(); - $matches = array(); + $matches = []; foreach ($tasks as $task) { if ($task instanceof $clazz) { $matches[] = $task; diff --git a/tests/phpunit/CRM/Core/CommunityMessagesTest.php b/tests/phpunit/CRM/Core/CommunityMessagesTest.php index 2265cdde80..9edd143820 100644 --- a/tests/phpunit/CRM/Core/CommunityMessagesTest.php +++ b/tests/phpunit/CRM/Core/CommunityMessagesTest.php @@ -52,95 +52,95 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { */ public static function initWebResponses() { if (self::$webResponses === NULL) { - self::$webResponses = array( - 'http-error' => array( + self::$webResponses = [ + 'http-error' => [ CRM_Utils_HttpClient::STATUS_DL_ERROR, NULL, - ), - 'bad-json' => array( + ], + 'bad-json' => [ CRM_Utils_HttpClient::STATUS_OK, 'this is not json!', - ), - 'invalid-ttl-document' => array( + ], + 'invalid-ttl-document' => [ CRM_Utils_HttpClient::STATUS_OK, - json_encode(array( + json_encode([ // not an integer! 'ttl' => 'z', // not an integer! 'retry' => 'z', - 'messages' => array( - array( + 'messages' => [ + [ 'markup' => '

Invalid document

', - ), - ), - )), - ), - 'first-valid-response' => array( + ], + ], + ]), + ], + 'first-valid-response' => [ CRM_Utils_HttpClient::STATUS_OK, - json_encode(array( + json_encode([ 'ttl' => 600, 'retry' => 600, - 'messages' => array( - array( + 'messages' => [ + [ 'markup' => '

First valid response

', - ), - ), - )), - ), - 'second-valid-response' => array( + ], + ], + ]), + ], + 'second-valid-response' => [ CRM_Utils_HttpClient::STATUS_OK, - json_encode(array( + json_encode([ 'ttl' => 600, 'retry' => 600, - 'messages' => array( - array( + 'messages' => [ + [ 'markup' => '

Second valid response

', - ), - ), - )), - ), - 'two-messages' => array( + ], + ], + ]), + ], + 'two-messages' => [ CRM_Utils_HttpClient::STATUS_OK, - json_encode(array( + json_encode([ 'ttl' => 600, 'retry' => 600, - 'messages' => array( - array( + 'messages' => [ + [ 'markup' => '

One

', - 'components' => array('CiviMail'), - ), - array( + 'components' => ['CiviMail'], + ], + [ 'markup' => '

Two

', - 'components' => array('CiviMail'), - ), - ), - )), - ), - 'two-messages-halfbadcomp' => array( + 'components' => ['CiviMail'], + ], + ], + ]), + ], + 'two-messages-halfbadcomp' => [ CRM_Utils_HttpClient::STATUS_OK, - json_encode(array( + json_encode([ 'ttl' => 600, 'retry' => 600, - 'messages' => array( - array( + 'messages' => [ + [ 'markup' => '

One

', - 'components' => array('NotARealComponent'), - ), - array( + 'components' => ['NotARealComponent'], + ], + [ 'markup' => '

Two

', - 'components' => array('CiviMail'), - ), - ), - )), - ), - ); + 'components' => ['CiviMail'], + ], + ], + ]), + ], + ]; } return self::$webResponses; } public function setUp() { parent::setUp(); - $this->cache = new CRM_Utils_Cache_Arraycache(array()); + $this->cache = new CRM_Utils_Cache_Arraycache([]); self::initWebResponses(); } @@ -158,11 +158,11 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { */ public function badWebResponses() { self::initWebResponses(); - $result = array( - array(self::$webResponses['http-error']), - array(self::$webResponses['bad-json']), - array(self::$webResponses['invalid-ttl-document']), - ); + $result = [ + [self::$webResponses['http-error']], + [self::$webResponses['bad-json']], + [self::$webResponses['invalid-ttl-document']], + ]; return $result; } @@ -237,7 +237,7 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { $this->expectOneHttpRequest($badWebResponse) ); $doc1 = $communityMessages->getDocument(); - $this->assertEquals(array(), $doc1['messages']); + $this->assertEquals([], $doc1['messages']); $this->assertTrue($doc1['expires'] > CRM_Utils_Time::getTimeRaw()); // second try, $doc1 hasn't expired yet, so still use it @@ -247,7 +247,7 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { $this->expectNoHttpRequest() ); $doc2 = $communityMessages->getDocument(); - $this->assertEquals(array(), $doc2['messages']); + $this->assertEquals([], $doc2['messages']); $this->assertEquals($doc1['expires'], $doc2['expires']); // third try, $doc1 expired, try again, get a good response @@ -333,7 +333,7 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { // randomly pick many times $trials = 80; // array($message => $count) - $freq = array(); + $freq = []; for ($i = 0; $i < $trials; $i++) { $message = $communityMessages->pick(); $freq[$message['markup']] = CRM_Utils_Array::value($message['markup'], $freq, 0) + 1; @@ -361,7 +361,7 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { // randomly pick many times $trials = 10; // array($message => $count) - $freq = array(); + $freq = []; for ($i = 0; $i < $trials; $i++) { $message = $communityMessages->pick(); $freq[$message['markup']] = CRM_Utils_Array::value($message['markup'], $freq, 0) + 1; diff --git a/tests/phpunit/CRM/Core/ComposerConfigTest.php b/tests/phpunit/CRM/Core/ComposerConfigTest.php index 4cdd7ce005..b00ba4c502 100644 --- a/tests/phpunit/CRM/Core/ComposerConfigTest.php +++ b/tests/phpunit/CRM/Core/ComposerConfigTest.php @@ -20,14 +20,14 @@ class CRM_Core_ComposerConfigTest extends \PHPUnit\Framework\TestCase { * because reviewers' eyes tend to gloss over `composer.lock`. */ public function testHardLocks() { - $hardLocks = array( + $hardLocks = [ 'symfony/config' => '/^v2\.8\./', 'symfony/dependency-injection' => '/^v2\.8\./', 'symfony/event-dispatcher' => '/^v2\.8\./', 'symfony/filesystem' => '/^v2\.8\./', 'symfony/finder' => '/^v2\.8\./', 'symfony/process' => '/^v2\.8\./', - ); + ]; $lockFile = Civi::paths()->getPath('[civicrm.root]/composer.lock'); $lock = json_decode(file_get_contents($lockFile), 1); @@ -39,7 +39,7 @@ class CRM_Core_ComposerConfigTest extends \PHPUnit\Framework\TestCase { unset($hardLocks[$package['name']]); } } - $this->assertEquals(array(), $hardLocks, + $this->assertEquals([], $hardLocks, 'composer.lock should have references to all hardlocks'); } diff --git a/tests/phpunit/CRM/Core/Config/MailerTest.php b/tests/phpunit/CRM/Core/Config/MailerTest.php index 4db3883b8b..ada938c45b 100644 --- a/tests/phpunit/CRM/Core/Config/MailerTest.php +++ b/tests/phpunit/CRM/Core/Config/MailerTest.php @@ -45,34 +45,34 @@ class CRM_Core_Config_MailerTest extends CiviUnitTestCase { public $calls; public function setUp() { - $this->calls = array( + $this->calls = [ 'civicrm_alterMailer' => 0, 'send' => 0, - ); + ]; parent::setUp(); } public function testHookAlterMailer() { $test = $this; - $mockMailer = new CRM_Utils_FakeObject(array( + $mockMailer = new CRM_Utils_FakeObject([ 'send' => function ($recipients, $headers, $body) use ($test) { $test->calls['send']++; - $test->assertEquals(array('to@example.org'), $recipients); + $test->assertEquals(['to@example.org'], $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'))); + $test->assertTrue(is_callable([$mailer, 'send'])); $mailer = $mockMailer; } ); - $params = array(); + $params = []; $params['groupName'] = 'CRM_Core_Config_MailerTest'; $params['from'] = 'From Example '; $params['toName'] = 'To Example'; diff --git a/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php b/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php index 9931ac0265..e6998025be 100644 --- a/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php +++ b/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php @@ -24,7 +24,7 @@ class CRM_Core_DAO_AllCoreTablesTest extends CiviUnitTestCase { $this->assertFalse(isset($exports['contact_id'])); // 2. Now, let's hook into it... - $this->hookClass->setHook('civicrm_entityTypes', array($this, '_hook_civicrm_entityTypes')); + $this->hookClass->setHook('civicrm_entityTypes', [$this, '_hook_civicrm_entityTypes']); unset(Civi::$statics['CRM_Core_DAO_Email']); CRM_Core_DAO_AllCoreTables::init(1); @@ -69,7 +69,7 @@ class CRM_Core_DAO_AllCoreTablesTest extends CiviUnitTestCase { // Not sure how we should be setting the locales, but this works for testing purposes $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); - $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, array('en_UK', 'fr_FR')); + $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, ['en_UK', 'fr_FR']); $domain->save(); // Check indices with localization @@ -86,118 +86,118 @@ class CRM_Core_DAO_AllCoreTablesTest extends CiviUnitTestCase { */ public function testMultilingualize() { // in civicrm_group, title is localizable, name is not - $originalIndices = array( - 'test_index1' => array( + $originalIndices = [ + 'test_index1' => [ 'name' => 'test_index1', - 'field' => array( + 'field' => [ 'name', - ), + ], 'localizable' => 0, - ), - 'test_index2' => array( + ], + 'test_index2' => [ 'name' => 'test_index2', - 'field' => array( + 'field' => [ 'title', - ), + ], 'localizable' => 1, - ), - 'test_index3' => array( + ], + 'test_index3' => [ 'name' => 'test_index3', - 'field' => array( + 'field' => [ 'name(3)', - ), + ], 'localizable' => 0, - ), - 'test_index4' => array( + ], + 'test_index4' => [ 'name' => 'test_index4', - 'field' => array( + 'field' => [ 'title(4)', - ), + ], 'localizable' => 1, - ), - 'test_index5' => array( + ], + 'test_index5' => [ 'name' => 'test_index5', - 'field' => array( + 'field' => [ 'title(4)', 'name(3)', - ), + ], 'localizable' => 1, - ), - ); + ], + ]; - $expectedIndices = array( - 'test_index1' => array( + $expectedIndices = [ + 'test_index1' => [ 'name' => 'test_index1', - 'field' => array( + 'field' => [ 'name', - ), + ], 'localizable' => 0, 'sig' => 'civicrm_group::0::name', - ), - 'test_index2_en_UK' => array( + ], + 'test_index2_en_UK' => [ 'name' => 'test_index2_en_UK', - 'field' => array( + 'field' => [ 'title_en_UK', - ), + ], 'localizable' => 1, 'sig' => 'civicrm_group::0::title_en_UK', - ), - 'test_index2_fr_FR' => array( + ], + 'test_index2_fr_FR' => [ 'name' => 'test_index2_fr_FR', - 'field' => array( + 'field' => [ 'title_fr_FR', - ), + ], 'localizable' => 1, 'sig' => 'civicrm_group::0::title_fr_FR', - ), - 'test_index3' => array( + ], + 'test_index3' => [ 'name' => 'test_index3', - 'field' => array( + 'field' => [ 'name(3)', - ), + ], 'localizable' => 0, 'sig' => 'civicrm_group::0::name(3)', - ), - 'test_index4_en_UK' => array( + ], + 'test_index4_en_UK' => [ 'name' => 'test_index4_en_UK', - 'field' => array( + 'field' => [ 'title_en_UK(4)', - ), + ], 'localizable' => 1, 'sig' => 'civicrm_group::0::title_en_UK(4)', - ), - 'test_index4_fr_FR' => array( + ], + 'test_index4_fr_FR' => [ 'name' => 'test_index4_fr_FR', - 'field' => array( + 'field' => [ 'title_fr_FR(4)', - ), + ], 'localizable' => 1, 'sig' => 'civicrm_group::0::title_fr_FR(4)', - ), - 'test_index5_en_UK' => array( + ], + 'test_index5_en_UK' => [ 'name' => 'test_index5_en_UK', - 'field' => array( + 'field' => [ 'title_en_UK(4)', 'name(3)', - ), + ], 'localizable' => 1, 'sig' => 'civicrm_group::0::title_en_UK(4)::name(3)', - ), - 'test_index5_fr_FR' => array( + ], + 'test_index5_fr_FR' => [ 'name' => 'test_index5_fr_FR', - 'field' => array( + 'field' => [ 'title_fr_FR(4)', 'name(3)', - ), + ], 'localizable' => 1, 'sig' => 'civicrm_group::0::title_fr_FR(4)::name(3)', - ), - ); + ], + ]; // Not sure how we should be setting the locales, but this works for testing purposes $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); - $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, array('en_UK', 'fr_FR')); + $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, ['en_UK', 'fr_FR']); $domain->save(); // needs a real DAO so use Group diff --git a/tests/phpunit/CRM/Core/DAOConformanceTest.php b/tests/phpunit/CRM/Core/DAOConformanceTest.php index 7c30686276..faaa32ab63 100644 --- a/tests/phpunit/CRM/Core/DAOConformanceTest.php +++ b/tests/phpunit/CRM/Core/DAOConformanceTest.php @@ -28,9 +28,9 @@ class CRM_Core_DAOConformanceTest extends CiviUnitTestCase { // Ugh. Need full bootstrap to enumerate classes. $this->setUp(); $classList = CRM_Core_DAO_AllCoreTables::getClasses(); - $return = array(); + $return = []; foreach ($classList as $class) { - $return[] = array($class); + $return[] = [$class]; } return $return; } diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php index dee82c0b13..fea1a1aefe 100644 --- a/tests/phpunit/CRM/Core/DAOTest.php +++ b/tests/phpunit/CRM/Core/DAOTest.php @@ -11,7 +11,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { public function testGetReferenceColumns() { // choose CRM_Core_DAO_Email as an arbitrary example $emailRefs = CRM_Core_DAO_Email::getReferenceColumns(); - $refsByTarget = array(); + $refsByTarget = []; foreach ($emailRefs as $refSpec) { $refsByTarget[$refSpec->getTargetTable()] = $refSpec; } @@ -24,7 +24,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { public function testGetReferencesToTable() { $refs = CRM_Core_DAO::getReferencesToTable(CRM_Financial_DAO_FinancialType::getTableName()); - $refsBySource = array(); + $refsBySource = []; foreach ($refs as $refSpec) { $refsBySource[$refSpec->getReferenceTable()] = $refSpec; } @@ -37,26 +37,26 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { } public function testFindReferences() { - $params = array( + $params = [ 'first_name' => 'Testy', 'last_name' => 'McScallion', 'contact_type' => 'Individual', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); $this->assertNotNull($contact->id); - $params = array( + $params = [ 'email' => 'spam@dev.null', 'contact_id' => $contact->id, 'is_primary' => 0, 'location_type_id' => 1, - ); + ]; $email = CRM_Core_BAO_Email::add($params); $refs = $contact->findReferences(); - $refsByTable = array(); + $refsByTable = []; foreach ($refs as $refObj) { $refsByTable[$refObj->__table] = $refObj; } @@ -71,88 +71,88 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * @return array */ public function composeQueryExamples() { - $cases = array(); + $cases = []; // $cases[] = array('Input-SQL', 'Input-Params', 'Expected-SQL'); - $cases[0] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'String')), 'UPDATE civicrm_foo SET bar = \'\''); - $cases[1] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('the text', 'String')), 'UPDATE civicrm_foo SET bar = \'the text\''); - $cases[2] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'String')), self::ABORTED_SQL); - $cases[3] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'String')), 'UPDATE civicrm_foo SET bar = NULL'); + $cases[0] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'String']], 'UPDATE civicrm_foo SET bar = \'\'']; + $cases[1] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['the text', 'String']], 'UPDATE civicrm_foo SET bar = \'the text\'']; + $cases[2] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'String']], self::ABORTED_SQL]; + $cases[3] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'String']], 'UPDATE civicrm_foo SET bar = NULL']; - $cases[3] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Float')), self::ABORTED_SQL); - $cases[4] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('1.23', 'Float')), 'UPDATE civicrm_foo SET bar = 1.23'); - $cases[5] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Float')), self::ABORTED_SQL); - $cases[6] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Float')), self::ABORTED_SQL); + $cases[3] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Float']], self::ABORTED_SQL]; + $cases[4] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['1.23', 'Float']], 'UPDATE civicrm_foo SET bar = 1.23']; + $cases[5] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Float']], self::ABORTED_SQL]; + $cases[6] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Float']], self::ABORTED_SQL]; - $cases[11] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Money')), self::ABORTED_SQL); - $cases[12] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('1.23', 'Money')), 'UPDATE civicrm_foo SET bar = 1.23'); - $cases[13] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Money')), self::ABORTED_SQL); - $cases[14] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Money')), self::ABORTED_SQL); + $cases[11] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Money']], self::ABORTED_SQL]; + $cases[12] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['1.23', 'Money']], 'UPDATE civicrm_foo SET bar = 1.23']; + $cases[13] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Money']], self::ABORTED_SQL]; + $cases[14] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Money']], self::ABORTED_SQL]; - $cases[15] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Int')), self::ABORTED_SQL); - $cases[16] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('123', 'Int')), 'UPDATE civicrm_foo SET bar = 123'); - $cases[17] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Int')), self::ABORTED_SQL); - $cases[18] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Int')), self::ABORTED_SQL); + $cases[15] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Int']], self::ABORTED_SQL]; + $cases[16] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['123', 'Int']], 'UPDATE civicrm_foo SET bar = 123']; + $cases[17] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Int']], self::ABORTED_SQL]; + $cases[18] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Int']], self::ABORTED_SQL]; - $cases[19] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Timestamp')), 'UPDATE civicrm_foo SET bar = null'); - $cases[20] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('20150102030405', 'Timestamp')), 'UPDATE civicrm_foo SET bar = 20150102030405'); - $cases[21] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Timestamp')), 'UPDATE civicrm_foo SET bar = null'); - $cases[22] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Timestamp')), self::ABORTED_SQL); + $cases[19] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Timestamp']], 'UPDATE civicrm_foo SET bar = null']; + $cases[20] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['20150102030405', 'Timestamp']], 'UPDATE civicrm_foo SET bar = 20150102030405']; + $cases[21] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Timestamp']], 'UPDATE civicrm_foo SET bar = null']; + $cases[22] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Timestamp']], self::ABORTED_SQL]; // CASE: No params - $cases[1000] = array( + $cases[1000] = [ 'SELECT * FROM whatever', - array(), + [], 'SELECT * FROM whatever', - ); + ]; // CASE: Integer param - $cases[1001] = array( + $cases[1001] = [ 'SELECT * FROM whatever WHERE id = %1', - array( - 1 => array(10, 'Integer'), - ), + [ + 1 => [10, 'Integer'], + ], 'SELECT * FROM whatever WHERE id = 10', - ); + ]; // CASE: String param - $cases[1002] = array( + $cases[1002] = [ 'SELECT * FROM whatever WHERE name = %1', - array( - 1 => array('Alice', 'String'), - ), + [ + 1 => ['Alice', 'String'], + ], 'SELECT * FROM whatever WHERE name = \'Alice\'', - ); + ]; // CASE: Two params - $cases[1003] = array( + $cases[1003] = [ 'SELECT * FROM whatever WHERE name = %1 AND title = %2', - array( - 1 => array('Alice', 'String'), - 2 => array('Bob', 'String'), - ), + [ + 1 => ['Alice', 'String'], + 2 => ['Bob', 'String'], + ], 'SELECT * FROM whatever WHERE name = \'Alice\' AND title = \'Bob\'', - ); + ]; // CASE: Two params with special character (%1) - $cases[1004] = array( + $cases[1004] = [ 'SELECT * FROM whatever WHERE name = %1 AND title = %2', - array( - 1 => array('Alice %2', 'String'), - 2 => array('Bob', 'String'), - ), + [ + 1 => ['Alice %2', 'String'], + 2 => ['Bob', 'String'], + ], 'SELECT * FROM whatever WHERE name = \'Alice %2\' AND title = \'Bob\'', - ); + ]; // CASE: Two params with special character ($1) - $cases[1005] = array( + $cases[1005] = [ 'SELECT * FROM whatever WHERE name = %1 AND title = %2', - array( - 1 => array('Alice $1', 'String'), - 2 => array('Bob', 'String'), - ), + [ + 1 => ['Alice $1', 'String'], + 2 => ['Bob', 'String'], + ], 'SELECT * FROM whatever WHERE name = \'Alice $1\' AND title = \'Bob\'', - ); + ]; return $cases; } @@ -184,14 +184,14 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * i.e. the place holder should be unique and should not contain in any other operational use in query */ public function testComposeQueryFailure() { - $cases[] = array( + $cases[] = [ 'SELECT * FROM whatever WHERE name = %1 AND title = %2 AND year LIKE \'%2012\' ', - array( - 1 => array('Alice', 'String'), - 2 => array('Bob', 'String'), - ), + [ + 1 => ['Alice', 'String'], + 2 => ['Bob', 'String'], + ], 'SELECT * FROM whatever WHERE name = \'Alice\' AND title = \'Bob\' AND year LIKE \'%2012\' ', - ); + ]; list($inputSql, $inputParams, $expectSql) = $cases[0]; $actualSql = CRM_Core_DAO::composeQuery($inputSql, $inputParams); $this->assertFalse(($expectSql == $actualSql)); @@ -202,33 +202,33 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * @return array */ public function sqlNameDataProvider() { - return array( - array('this is a long string', 30, FALSE, 'this is a long string'), - array( + return [ + ['this is a long string', 30, FALSE, 'this is a long string'], + [ 'this is an even longer string which is exactly 60 character', 60, FALSE, 'this is an even longer string which is exactly 60 character', - ), - array( + ], + [ 'this is an even longer string which is exactly 60 character', 60, TRUE, 'this is an even longer string which is exactly 60 character', - ), - array( + ], + [ 'this is an even longer string which is a bit more than 60 character', 60, FALSE, 'this is an even longer string which is a bit more than 60 ch', - ), - array( + ], + [ 'this is an even longer string which is a bit more than 60 character', 60, TRUE, 'this is an even longer string which is a bit more th_c1cbd519', - ), - ); + ], + ]; } /** @@ -263,7 +263,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * requireSafeDBName() method (to check valid database name) */ public function testRequireSafeDBName() { - $databases = array( + $databases = [ 'testdb' => TRUE, 'test_db' => TRUE, 'TEST_db' => TRUE, @@ -276,8 +276,8 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { 'testdb;Delete test' => FALSE, '123456' => FALSE, 'test#$%^&*' => FALSE, - ); - $testDetails = array(); + ]; + $testDetails = []; foreach ($databases as $database => $val) { $this->assertEquals(CRM_Core_DAO::requireSafeDBName($database), $val); } @@ -318,19 +318,19 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { */ public function testDAOtoArray() { $format = 'user[%s]'; - $params = array( + $params = [ 'first_name' => 'Testy', 'last_name' => 'McScallion', 'contact_type' => 'Individual', - ); + ]; $dao = CRM_Contact_BAO_Contact::add($params); $query = "SELECT contact_type, display_name FROM civicrm_contact WHERE id={$dao->id}"; - $toArray = array( + $toArray = [ 'contact_type' => 'Individual', 'display_name' => 'Testy McScallion', - ); - $modifiedKeyArray = array(); + ]; + $modifiedKeyArray = []; foreach ($toArray as $k => $v) { $modifiedKeyArray[sprintf($format, $k)] = $v; } @@ -348,12 +348,12 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * CRM-17748: Test internal DAO options */ public function testDBOptions() { - $contactIDs = array(); + $contactIDs = []; for ($i = 0; $i < 10; $i++) { - $contactIDs[] = $this->individualCreate(array( + $contactIDs[] = $this->individualCreate([ 'first_name' => 'Alan' . substr(sha1(rand()), 0, 7), 'last_name' => 'Smith' . substr(sha1(rand()), 0, 4), - )); + ]); } // Test option 'result_buffering' @@ -361,7 +361,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { // cleanup foreach ($contactIDs as $contactID) { - $this->callAPISuccess('Contact', 'delete', array('id' => $contactID)); + $this->callAPISuccess('Contact', 'delete', ['id' => $contactID]); } } @@ -396,27 +396,27 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * @return array */ public function serializationMethods() { - $constants = array(); - $simpleData = array( + $constants = []; + $simpleData = [ NULL, - array('Foo', 'Bar', '3', '4', '5'), - array(), - array('0'), - ); - $complexData = array( - array( + ['Foo', 'Bar', '3', '4', '5'], + [], + ['0'], + ]; + $complexData = [ + [ 'foo' => 'bar', - 'baz' => array('1', '2', '3', array('one', 'two')), + 'baz' => ['1', '2', '3', ['one', 'two']], '3' => '0', - ), - ); + ], + ]; $daoInfo = new ReflectionClass('CRM_Core_DAO'); foreach ($daoInfo->getConstants() as $constant => $val) { if ($constant == 'SERIALIZE_JSON' || $constant == 'SERIALIZE_PHP') { - $constants[] = array($val, array_merge($simpleData, $complexData)); + $constants[] = [$val, array_merge($simpleData, $complexData)]; } elseif (strpos($constant, 'SERIALIZE_') === 0) { - $constants[] = array($val, $simpleData); + $constants[] = [$val, $simpleData]; } } return $constants; diff --git a/tests/phpunit/CRM/Core/FieldOptionsTest.php b/tests/phpunit/CRM/Core/FieldOptionsTest.php index 8ac635e529..a601b15791 100644 --- a/tests/phpunit/CRM/Core/FieldOptionsTest.php +++ b/tests/phpunit/CRM/Core/FieldOptionsTest.php @@ -48,12 +48,12 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', array($this, 'hook_civicrm_fieldOptions')); + CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', [$this, 'hook_civicrm_fieldOptions']); } public function tearDown() { parent::tearDown(); - $this->quickCleanup(array('civicrm_custom_field', 'civicrm_custom_group')); + $this->quickCleanup(['civicrm_custom_field', 'civicrm_custom_group']); } /** @@ -72,30 +72,30 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { * - exclude: Any one value which should not be in the list. * - max: integer (default = 10) maximum number of option values expected. */ - $fields = array( - 'CRM_Core_BAO_Address' => array( - array( + $fields = [ + 'CRM_Core_BAO_Address' => [ + [ 'fieldName' => 'state_province_id', 'sample' => 'California', 'max' => 60, - 'props' => array('country_id' => 1228), - ), - ), - 'CRM_Contact_BAO_Contact' => array( - array( + 'props' => ['country_id' => 1228], + ], + ], + 'CRM_Contact_BAO_Contact' => [ + [ 'fieldName' => 'contact_sub_type', 'sample' => 'Team', 'exclude' => 'Organization', - 'props' => array('contact_type' => 'Organization'), - ), - ), - ); + 'props' => ['contact_type' => 'Organization'], + ], + ], + ]; foreach ($fields as $baoName => $baoFields) { foreach ($baoFields as $field) { $message = "BAO name: '{$baoName}', field: '{$field['fieldName']}'"; - $props = CRM_Utils_Array::value('props', $field, array()); + $props = CRM_Utils_Array::value('props', $field, []); $optionValues = $baoName::buildOptions($field['fieldName'], 'create', $props); $this->assertNotEmpty($optionValues, $message); @@ -122,8 +122,8 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { // Test replacing all options with a hook $this->targetField = 'case_type_id'; - $this->replaceOptions = array('foo' => 'Foo', 'bar' => 'Bar'); - $result = $this->callAPISuccess('case', 'getoptions', array('field' => 'case_type_id')); + $this->replaceOptions = ['foo' => 'Foo', 'bar' => 'Bar']; + $result = $this->callAPISuccess('case', 'getoptions', ['field' => 'case_type_id']); $this->assertEquals($result['values'], $this->replaceOptions); // TargetField doesn't match - should get unmodified option list @@ -132,7 +132,7 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { // This time we should get foo bar appended to the list $this->targetField = 'gender_id'; - $this->appendOptions = array('foo' => 'Foo', 'bar' => 'Bar'); + $this->appendOptions = ['foo' => 'Foo', 'bar' => 'Bar']; $this->replaceOptions = NULL; CRM_Core_PseudoConstant::flush(); $result = CRM_Contact_BAO_Contact::buildOptions('gender_id'); @@ -145,65 +145,65 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { public function testHookFieldOptionsWithCustomFields() { // Create a custom field group for testing. $custom_group_name = md5(microtime()); - $api_params = array( + $api_params = [ 'title' => $custom_group_name, 'extends' => 'Individual', 'is_active' => TRUE, - ); + ]; $customGroup = $this->callAPISuccess('customGroup', 'create', $api_params); // Add a custom select field. - $api_params = array( + $api_params = [ 'custom_group_id' => $customGroup['id'], 'label' => $custom_group_name . 1, 'html_type' => 'Select', 'data_type' => 'String', - 'option_values' => array( + 'option_values' => [ 'foo' => 'Foo', 'bar' => 'Bar', - ), - ); + ], + ]; $result = $this->callAPISuccess('custom_field', 'create', $api_params); $customField1 = $result['id']; // Add a custom country field. - $api_params = array( + $api_params = [ 'custom_group_id' => $customGroup['id'], 'label' => $custom_group_name . 2, 'html_type' => 'Select Country', 'data_type' => 'Country', - ); + ]; $result = $this->callAPISuccess('custom_field', 'create', $api_params); $customField2 = $result['id']; // Add a custom boolean field. - $api_params = array( + $api_params = [ 'custom_group_id' => $customGroup['id'], 'label' => $custom_group_name . 3, 'html_type' => 'Radio', 'data_type' => 'Boolean', - ); + ]; $result = $this->callAPISuccess('custom_field', 'create', $api_params); $customField3 = $result['id']; $this->targetField = 'custom_' . $customField1; $this->replaceOptions = NULL; - $this->appendOptions = array('baz' => 'Baz'); + $this->appendOptions = ['baz' => 'Baz']; $field = new CRM_Core_BAO_CustomField(); $field->id = $customField1; - $this->assertEquals(array('foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'), $field->getOptions()); + $this->assertEquals(['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'], $field->getOptions()); $this->targetField = 'custom_' . $customField2; - $this->replaceOptions = array('nowhere' => 'Nowhere'); + $this->replaceOptions = ['nowhere' => 'Nowhere']; $field = new CRM_Core_BAO_CustomField(); $field->id = $customField2; $this->assertEquals($this->replaceOptions + $this->appendOptions, $field->getOptions()); $this->targetField = 'custom_' . $customField3; $this->replaceOptions = NULL; - $this->appendOptions = array(2 => 'Maybe'); + $this->appendOptions = [2 => 'Maybe']; $options = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', $this->targetField); - $this->assertEquals(array(1 => 'Yes', 0 => 'No', 2 => 'Maybe'), $options); + $this->assertEquals([1 => 'Yes', 0 => 'No', 2 => 'Maybe'], $options); } /** diff --git a/tests/phpunit/CRM/Core/I18n/SchemaTest.php b/tests/phpunit/CRM/Core/I18n/SchemaTest.php index a205b00db6..8cbd3c8718 100644 --- a/tests/phpunit/CRM/Core/I18n/SchemaTest.php +++ b/tests/phpunit/CRM/Core/I18n/SchemaTest.php @@ -35,10 +35,10 @@ class CRM_Core_I18n_SchemaTest extends CiviUnitTestCase { * @return array */ public static function translateTables() { - $tables = array(); - $tables[] = array('civicrm_option_group', 'civicrm_option_group_en_US'); - $tables[] = array('civicrm_events_in_carts', 'civicrm_events_in_carts'); - $tables[] = array('civicrm_event', 'civicrm_event_en_US'); + $tables = []; + $tables[] = ['civicrm_option_group', 'civicrm_option_group_en_US']; + $tables[] = ['civicrm_events_in_carts', 'civicrm_events_in_carts']; + $tables[] = ['civicrm_event', 'civicrm_event_en_US']; return $tables; } @@ -60,7 +60,7 @@ class CRM_Core_I18n_SchemaTest extends CiviUnitTestCase { public function testI18nSchemaRewrite($table, $expectedRewrite) { CRM_Core_I18n_Schema::makeMultilingual('en_US'); $skip_tests = FALSE; - if (in_array($table, array('civicrm_option_group', 'civicrm_event'))) { + if (in_array($table, ['civicrm_option_group', 'civicrm_event'])) { $skip_tests = TRUE; } global $dbLocale; diff --git a/tests/phpunit/CRM/Core/InnoDBIndexerTest.php b/tests/phpunit/CRM/Core/InnoDBIndexerTest.php index 60470e2ffd..8ec73a16a8 100644 --- a/tests/phpunit/CRM/Core/InnoDBIndexerTest.php +++ b/tests/phpunit/CRM/Core/InnoDBIndexerTest.php @@ -10,46 +10,46 @@ class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase { // May or may not cleanup well if there's a bug in the indexer. // This is better than nothing -- and better than duplicating the // cleanup logic. - $idx = new CRM_Core_InnoDBIndexer(FALSE, array()); + $idx = new CRM_Core_InnoDBIndexer(FALSE, []); $idx->fixSchemaDifferences(); parent::tearDown(); } public function testHasDeclaredIndex() { - $idx = new CRM_Core_InnoDBIndexer(TRUE, array( - 'civicrm_contact' => array( - array('first_name', 'last_name'), - array('foo'), - ), - 'civicrm_email' => array( - array('whiz'), - ), - )); + $idx = new CRM_Core_InnoDBIndexer(TRUE, [ + 'civicrm_contact' => [ + ['first_name', 'last_name'], + ['foo'], + ], + 'civicrm_email' => [ + ['whiz'], + ], + ]); - $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name', 'last_name'))); - $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name', 'first_name'))); + $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name', 'last_name'])); + $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name', 'first_name'])); // not sure if this is right behavior - $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name'))); + $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name'])); // not sure if this is right behavior - $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name'))); - $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('foo'))); - $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', array('whiz'))); + $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name'])); + $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['foo'])); + $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', ['whiz'])); - $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('first_name', 'last_name'))); - $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('foo'))); - $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', array('whiz'))); + $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', ['first_name', 'last_name'])); + $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', ['foo'])); + $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', ['whiz'])); } /** * When disabled, there is no FTS index, so queries that rely on FTS index fail. */ public function testDisabled() { - $idx = new CRM_Core_InnoDBIndexer(FALSE, array( - 'civicrm_contact' => array( - array('first_name', 'last_name'), - ), - )); + $idx = new CRM_Core_InnoDBIndexer(FALSE, [ + 'civicrm_contact' => [ + ['first_name', 'last_name'], + ], + ]); $idx->fixSchemaDifferences(); try { @@ -70,11 +70,11 @@ class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase { return; } - $idx = new CRM_Core_InnoDBIndexer(TRUE, array( - 'civicrm_contact' => array( - array('first_name', 'last_name'), - ), - )); + $idx = new CRM_Core_InnoDBIndexer(TRUE, [ + 'civicrm_contact' => [ + ['first_name', 'last_name'], + ], + ]); $idx->fixSchemaDifferences(); CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")'); diff --git a/tests/phpunit/CRM/Core/ManagedEntitiesTest.php b/tests/phpunit/CRM/Core/ManagedEntitiesTest.php index 7e95163fa5..6c61fc0083 100644 --- a/tests/phpunit/CRM/Core/ManagedEntitiesTest.php +++ b/tests/phpunit/CRM/Core/ManagedEntitiesTest.php @@ -25,58 +25,58 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { public function setUp() { $this->useTransaction(TRUE); parent::setUp(); - $this->modules = array( + $this->modules = [ 'one' => new CRM_Core_Module('com.example.one', TRUE), 'two' => new CRM_Core_Module('com.example.two', TRUE), - ); + ]; // Testing on drupal-demo fails because some extensions have mgd ents. CRM_Core_DAO::singleValueQuery('DELETE FROM civicrm_managed'); - $this->fixtures['com.example.one-foo'] = array( + $this->fixtures['com.example.one-foo'] = [ 'module' => 'com.example.one', 'name' => 'foo', 'entity' => 'CustomSearch', - 'params' => array( + 'params' => [ 'version' => 3, 'class_name' => 'CRM_Example_One_Foo', 'is_reserved' => 1, - ), - ); - $this->fixtures['com.example.one-bar'] = array( + ], + ]; + $this->fixtures['com.example.one-bar'] = [ 'module' => 'com.example.one', 'name' => 'bar', 'entity' => 'CustomSearch', - 'params' => array( + 'params' => [ 'version' => 3, 'class_name' => 'CRM_Example_One_Bar', 'is_reserved' => 1, - ), - ); - $this->fixtures['com.example.one-CustomGroup'] = array( + ], + ]; + $this->fixtures['com.example.one-CustomGroup'] = [ 'module' => 'com.example.one', 'name' => 'CustomGroup', 'entity' => 'CustomGroup', - 'params' => array( + 'params' => [ 'version' => 3, 'name' => 'test_custom_group', 'title' => 'Test custom group', 'extends' => 'Individual', - ), - ); - $this->fixtures['com.example.one-CustomField'] = array( + ], + ]; + $this->fixtures['com.example.one-CustomField'] = [ 'module' => 'com.example.one', 'name' => 'CustomField', 'entity' => 'CustomField', - 'params' => array( + 'params' => [ 'version' => 3, 'name' => 'test_custom_field', 'label' => 'Test custom field', 'custom_group_id' => 'test_custom_group', 'data_type' => 'String', 'html_type' => 'Text', - ), - ); + ], + ]; $this->apiKernel = \Civi::service('civi_api_kernel'); $this->adhocProvider = new \Civi\API\Provider\AdhocProvider(3, 'CustomSearch'); @@ -94,7 +94,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { * entity */ public function testAddRemoveEntitiesModule_UpdateAlways_DeleteAlways() { - $decls = array(); + $decls = []; // create first managed entity ('foo') $decls[] = $this->fixtures['com.example.one-foo']; @@ -143,7 +143,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { * time, the content of the entity changes */ public function testModifyDeclaration_UpdateAlways() { - $decls = array(); + $decls = []; // create first managed entity ('foo') $decls[] = $this->fixtures['com.example.one-foo']; @@ -169,13 +169,13 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { * time, the content of the entity changes */ public function testModifyDeclaration_UpdateNever() { - $decls = array(); + $decls = []; // create first managed entity ('foo') - $decls[] = array_merge($this->fixtures['com.example.one-foo'], array( + $decls[] = array_merge($this->fixtures['com.example.one-foo'], [ // Policy is to never update after initial creation 'update' => 'never', - )); + ]); $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo = $me->get('com.example.one', 'foo'); @@ -200,12 +200,12 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { * deleted). */ public function testRemoveDeclaration_CleanupNever() { - $decls = array(); + $decls = []; // create first managed entity ('foo') - $decls[] = array_merge($this->fixtures['com.example.one-foo'], array( + $decls[] = array_merge($this->fixtures['com.example.one-foo'], [ 'cleanup' => 'never', - )); + ]); $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo = $me->get('com.example.one', 'foo'); @@ -213,7 +213,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"'); // later on, entity definition disappears; but we decide not to do any cleanup (per policy) - $decls = array(); + $decls = []; $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo2 = $me->get('com.example.one', 'foo'); @@ -229,12 +229,12 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { * deleted). */ public function testRemoveDeclaration_CleanupUnused() { - $decls = array(); + $decls = []; // create first managed entity ('foo') - $decls[] = array_merge($this->fixtures['com.example.one-foo'], array( + $decls[] = array_merge($this->fixtures['com.example.one-foo'], [ 'cleanup' => 'unused', - )); + ]); $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo = $me->get('com.example.one', 'foo'); @@ -243,17 +243,17 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { // Override 'getrefcount' ==> The refcount is 1 $this->adhocProvider->addAction('getrefcount', 'access CiviCRM', function ($apiRequest) { - return civicrm_api3_create_success(array( - array( + return civicrm_api3_create_success([ + [ 'name' => 'mock', 'type' => 'mock', 'count' => 1, - ), - )); + ], + ]); }); // Later on, entity definition disappears; but we decide not to do any cleanup (per policy) - $decls = array(); + $decls = []; $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo2 = $me->get('com.example.one', 'foo'); @@ -263,11 +263,11 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { // Override 'getrefcount' ==> The refcount is 0 $this->adhocProvider->addAction('getrefcount', 'access CiviCRM', function ($apiRequest) { - return civicrm_api3_create_success(array()); + return civicrm_api3_create_success([]); }); // The entity definition disappeared and there's no reference; we decide to cleanup (per policy) - $decls = array(); + $decls = []; $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo3 = $me->get('com.example.one', 'foo'); @@ -280,18 +280,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { */ public function testInvalidDeclarationModule() { // create first managed entity ('foo') - $decls = array(); - $decls[] = array( + $decls = []; + $decls[] = [ // erroneous 'module' => 'com.example.unknown', 'name' => 'foo', 'entity' => 'CustomSearch', - 'params' => array( + 'params' => [ 'version' => 3, 'class_name' => 'CRM_Example_One_Foo', 'is_reserved' => 1, - ), - ); + ], + ]; $me = new CRM_Core_ManagedEntities($this->modules, $decls); try { $me->reconcile(); @@ -307,18 +307,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { */ public function testMissingName() { // create first managed entity ('foo') - $decls = array(); - $decls[] = array( + $decls = []; + $decls[] = [ 'module' => 'com.example.unknown', // erroneous 'name' => NULL, 'entity' => 'CustomSearch', - 'params' => array( + 'params' => [ 'version' => 3, 'class_name' => 'CRM_Example_One_Foo', 'is_reserved' => 1, - ), - ); + ], + ]; $me = new CRM_Core_ManagedEntities($this->modules, $decls); try { $me->reconcile(); @@ -334,18 +334,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { */ public function testMissingEntity() { // create first managed entity ('foo') - $decls = array(); - $decls[] = array( + $decls = []; + $decls[] = [ 'module' => 'com.example.unknown', 'name' => 'foo', // erroneous 'entity' => NULL, - 'params' => array( + 'params' => [ 'version' => 3, 'class_name' => 'CRM_Example_One_Foo', 'is_reserved' => 1, - ), - ); + ], + ]; $me = new CRM_Core_ManagedEntities($this->modules, $decls); try { $me->reconcile(); @@ -362,7 +362,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { */ public function testDeactivateReactivateModule() { // create first managed entity ('foo') - $decls = array(); + $decls = []; $decls[] = $this->fixtures['com.example.one-foo']; $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); @@ -373,7 +373,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { // now deactivate module, which has empty decls and which cascades to managed object $this->modules['one']->is_active = FALSE; - $me = new CRM_Core_ManagedEntities($this->modules, array()); + $me = new CRM_Core_ManagedEntities($this->modules, []); $me->reconcile(); $foo = $me->get('com.example.one', 'foo'); $this->assertEquals(0, $foo['is_active']); @@ -396,7 +396,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { */ public function testUninstallModule() { // create first managed entity ('foo') - $decls = array(); + $decls = []; $decls[] = $this->fixtures['com.example.one-foo']; $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); @@ -406,7 +406,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { // then destroy module; note that decls go away unset($this->modules['one']); - $me = new CRM_Core_ManagedEntities($this->modules, array()); + $me = new CRM_Core_ManagedEntities($this->modules, []); $me->reconcile(); $fooNew = $me->get('com.example.one', 'foo'); $this->assertTrue(NULL === $fooNew); @@ -416,7 +416,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { public function testDependentEntitiesUninstallCleanly() { // Install a module with two dependent managed entities - $decls = array(); + $decls = []; $decls[] = $this->fixtures['com.example.one-CustomGroup']; $decls[] = $this->fixtures['com.example.one-CustomField']; $me = new CRM_Core_ManagedEntities($this->modules, $decls); diff --git a/tests/phpunit/CRM/Core/MenuTest.php b/tests/phpunit/CRM/Core/MenuTest.php index fcb4c7ec6c..b0cae39957 100644 --- a/tests/phpunit/CRM/Core/MenuTest.php +++ b/tests/phpunit/CRM/Core/MenuTest.php @@ -21,7 +21,7 @@ class CRM_Core_MenuTest extends CiviUnitTestCase { '; $xml = simplexml_load_string($xmlString); - $menu = array(); + $menu = []; CRM_Core_Menu::readXML($xml, $menu); $this->assertTrue(isset($menu['civicrm/foo/bar'])); $this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']); @@ -48,13 +48,13 @@ class CRM_Core_MenuTest extends CiviUnitTestCase { '; $xml = simplexml_load_string($xmlString); - $menu = array(); + $menu = []; CRM_Core_Menu::readXML($xml, $menu); $this->assertTrue(isset($menu['civicrm/foo/bar'])); $this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']); - $this->assertEquals(array('alpha', 'beta'), $menu['civicrm/foo/bar']['ids_arguments']['json']); - $this->assertEquals(array('gamma'), $menu['civicrm/foo/bar']['ids_arguments']['exceptions']); - $this->assertEquals(array(), $menu['civicrm/foo/bar']['ids_arguments']['html']); + $this->assertEquals(['alpha', 'beta'], $menu['civicrm/foo/bar']['ids_arguments']['json']); + $this->assertEquals(['gamma'], $menu['civicrm/foo/bar']['ids_arguments']['exceptions']); + $this->assertEquals([], $menu['civicrm/foo/bar']['ids_arguments']['html']); $idsConfig = CRM_Core_IDS::createRouteConfig($menu['civicrm/foo/bar']); // XML @@ -93,37 +93,37 @@ class CRM_Core_MenuTest extends CiviUnitTestCase { */ public function pathArguments() { // array(0 => string $input, 1 => array $expectedOutput) - $cases = array(); + $cases = []; //$cases[] = array(NULL, array()); //$cases[] = array('', array()); //$cases[] = array('freestanding', array('freestanding' => NULL)); - $cases[] = array('addSequence=1', array('addSequence' => '1')); - $cases[] = array('attachUpload=1', array('attachUpload' => '1')); - $cases[] = array('mode=256', array('mode' => '256')); - $cases[] = array( + $cases[] = ['addSequence=1', ['addSequence' => '1']]; + $cases[] = ['attachUpload=1', ['attachUpload' => '1']]; + $cases[] = ['mode=256', ['mode' => '256']]; + $cases[] = [ 'mode=256,addSequence=1,attachUpload=1', - array('mode' => '256', 'addSequence' => '1', 'attachUpload' => 1), - ); - $cases[] = array( + ['mode' => '256', 'addSequence' => '1', 'attachUpload' => 1], + ]; + $cases[] = [ 'mode=256,urlToSession=a:b:c:d', - array( + [ 'mode' => '256', - 'urlToSession' => array( - array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'), - ), - ), - ); - $cases[] = array( + 'urlToSession' => [ + ['urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'], + ], + ], + ]; + $cases[] = [ 'mode=256,urlToSession=a:b:c:d;z:y:x:w', - array( + [ 'mode' => '256', - 'urlToSession' => array( - array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'), - array('urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'), - ), - ), - ); - $cases[] = array('url=whiz!;.:#=%/|+bang?', array('url' => 'whiz!;.:#=%/|+bang?')); + 'urlToSession' => [ + ['urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'], + ['urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'], + ], + ], + ]; + $cases[] = ['url=whiz!;.:#=%/|+bang?', ['url' => 'whiz!;.:#=%/|+bang?']]; return $cases; } diff --git a/tests/phpunit/CRM/Core/OptionGroupTest.php b/tests/phpunit/CRM/Core/OptionGroupTest.php index 340756d0db..9449393aea 100644 --- a/tests/phpunit/CRM/Core/OptionGroupTest.php +++ b/tests/phpunit/CRM/Core/OptionGroupTest.php @@ -42,7 +42,7 @@ class CRM_Core_OptionGroupTest extends CiviUnitTestCase { * Ensure only one option value exists after calling ensureOptionValueExists. */ public function testWeightOptionGroup() { - $values = array(); + $values = []; $options1 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE); $options2 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE, FALSE, 'value', 'name'); // Verify that arrays are equal. @@ -68,10 +68,10 @@ class CRM_Core_OptionGroupTest extends CiviUnitTestCase { * @return array */ public function optionGroupTests() { - $tests = array(); - $tests[] = array('event_type', 'Integer'); - $tests[] = array('addressee', 'null'); - $tests[] = array('activity_status', 'Integer'); + $tests = []; + $tests[] = ['event_type', 'Integer']; + $tests[] = ['addressee', 'null']; + $tests[] = ['activity_status', 'Integer']; return $tests; } @@ -92,9 +92,9 @@ class CRM_Core_OptionGroupTest extends CiviUnitTestCase { } public function emailAddressTests() { - $tests[] = array('"Name"', '"Name" '); - $tests[] = array('"Name" ', '"Name" '); - $tests[] = array('"Name" ', '"Name" '); + $tests[] = ['"Name"', '"Name" ']; + $tests[] = ['"Name" ', '"Name" ']; + $tests[] = ['"Name" ', '"Name" ']; return $tests; } diff --git a/tests/phpunit/CRM/Core/Page/AJAXTest.php b/tests/phpunit/CRM/Core/Page/AJAXTest.php index 4ba11db870..330f0daa9e 100644 --- a/tests/phpunit/CRM/Core/Page/AJAXTest.php +++ b/tests/phpunit/CRM/Core/Page/AJAXTest.php @@ -7,45 +7,45 @@ class CRM_Core_Page_AJAXTest extends CiviUnitTestCase { public function testCheckAuthz() { - $cases = array(); + $cases = []; - $cases[] = array('method', 'CRM_Foo', FALSE, 'method'); - $cases[] = array('method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method'); - $cases[] = array('method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay'); - $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method('); - $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method()'); - $cases[] = array('method', 'othermethod;CRM_Foo_Page_AJAX', FALSE, 'method'); - $cases[] = array('method', 'CRM_Foo_Page_AJAX;othermethod', FALSE, 'method'); - $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, ''); - $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method'); - $cases[] = array('method', 'CRM_Foo->method', FALSE); + $cases[] = ['method', 'CRM_Foo', FALSE, 'method']; + $cases[] = ['method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method']; + $cases[] = ['method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay']; + $cases[] = ['method', 'CRM_Foo_Page_AJAX', FALSE, 'method(']; + $cases[] = ['method', 'CRM_Foo_Page_AJAX', FALSE, 'method()']; + $cases[] = ['method', 'othermethod;CRM_Foo_Page_AJAX', FALSE, 'method']; + $cases[] = ['method', 'CRM_Foo_Page_AJAX;othermethod', FALSE, 'method']; + $cases[] = ['method', 'CRM_Foo_Page_Inline_Bar', FALSE, '']; + $cases[] = ['method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method']; + $cases[] = ['method', 'CRM_Foo->method', FALSE]; - $cases[] = array('page', 'CRM_Foo', FALSE); - $cases[] = array('page', 'CRM_Foo_Bar', FALSE); - $cases[] = array('page', 'CRM_Foo_Page', FALSE); - $cases[] = array('page', 'CRM_Foo_Page_Bar', FALSE); - $cases[] = array('page', 'CRM_Foo_Page_Inline', FALSE); - $cases[] = array('page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE); - $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE); - $cases[] = array('page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE); - $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE); - $cases[] = array('page', 'CRM_Foo_Form', FALSE); - $cases[] = array('page', 'CRM_Foo_Form_Bar', FALSE); - $cases[] = array('page', 'CRM_Foo_Form_Inline', FALSE); - $cases[] = array('page', 'CRM_Contact_Form_Inline_Email', TRUE); - $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE); - $cases[] = array('page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE); - $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE); + $cases[] = ['page', 'CRM_Foo', FALSE]; + $cases[] = ['page', 'CRM_Foo_Bar', FALSE]; + $cases[] = ['page', 'CRM_Foo_Page', FALSE]; + $cases[] = ['page', 'CRM_Foo_Page_Bar', FALSE]; + $cases[] = ['page', 'CRM_Foo_Page_Inline', FALSE]; + $cases[] = ['page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE]; + $cases[] = ['page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE]; + $cases[] = ['page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE]; + $cases[] = ['page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE]; + $cases[] = ['page', 'CRM_Foo_Form', FALSE]; + $cases[] = ['page', 'CRM_Foo_Form_Bar', FALSE]; + $cases[] = ['page', 'CRM_Foo_Form_Inline', FALSE]; + $cases[] = ['page', 'CRM_Contact_Form_Inline_Email', TRUE]; + $cases[] = ['page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE]; + $cases[] = ['page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE]; + $cases[] = ['page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE]; // aliases for 'page' - $cases[] = array('class', 'CRM_Foo_Bar', FALSE); - $cases[] = array('class', 'CRM_Contact_Page_Inline_Phone', TRUE); - $cases[] = array('', 'CRM_Foo_Bar', FALSE); - $cases[] = array('', 'CRM_Contact_Page_Inline_Demographics', TRUE); + $cases[] = ['class', 'CRM_Foo_Bar', FALSE]; + $cases[] = ['class', 'CRM_Contact_Page_Inline_Phone', TRUE]; + $cases[] = ['', 'CRM_Foo_Bar', FALSE]; + $cases[] = ['', 'CRM_Contact_Page_Inline_Demographics', TRUE]; // invalid type - $cases[] = array('invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE); - $cases[] = array('invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE); + $cases[] = ['invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE]; + $cases[] = ['invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE]; foreach ($cases as $case) { list ($type, $className, $expectedResult) = $case; diff --git a/tests/phpunit/CRM/Core/Page/HookTest.php b/tests/phpunit/CRM/Core/Page/HookTest.php index ce905772f0..d6168763a1 100644 --- a/tests/phpunit/CRM/Core/Page/HookTest.php +++ b/tests/phpunit/CRM/Core/Page/HookTest.php @@ -12,14 +12,14 @@ class CRM_Core_Page_HookTest extends CiviUnitTestCase { * * @var array */ - public $basicPages = array(); + public $basicPages = []; /** * A place to hold the counts of hook invocations. * * @var array */ - public $hookCount = array(); + public $hookCount = []; /** * Classes that should be skipped @@ -32,7 +32,7 @@ class CRM_Core_Page_HookTest extends CiviUnitTestCase { * * @var array */ - public $skip = array( + public $skip = [ 'CRM_Contact_Page_DedupeFind', 'CRM_Mailing_Page_Report', 'CRM_Financial_Page_BatchTransaction', @@ -42,7 +42,7 @@ class CRM_Core_Page_HookTest extends CiviUnitTestCase { 'CRM_Admin_Page_LabelFormats', // This is a page with no corresponding form: 'CRM_Admin_Page_EventTemplate', - ); + ]; /** * Set up the list of pages to evaluate by going through the menu. @@ -67,15 +67,15 @@ class CRM_Core_Page_HookTest extends CiviUnitTestCase { * Make sure form hooks are only invoked once. */ public function testFormsCallBuildFormOnce() { - CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_buildForm', array($this, 'onBuildForm')); - CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_preProcess', array($this, 'onPreProcess')); - $_REQUEST = array('action' => 'add'); + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_buildForm', [$this, 'onBuildForm']); + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_preProcess', [$this, 'onPreProcess']); + $_REQUEST = ['action' => 'add']; foreach ($this->basicPages as $pageName) { // Reset the counters - $this->hookCount = array( - 'buildForm' => array(), - 'preProcess' => array(), - ); + $this->hookCount = [ + 'buildForm' => [], + 'preProcess' => [], + ]; $page = new $pageName(); ob_start(); $page->run(); @@ -107,11 +107,11 @@ class CRM_Core_Page_HookTest extends CiviUnitTestCase { * Make sure pageRun hook is only invoked once. */ public function testPagesCallPageRunOnce() { - CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_pageRun', array($this, 'onPageRun')); - $_REQUEST = array('action' => 'browse'); + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_pageRun', [$this, 'onPageRun']); + $_REQUEST = ['action' => 'browse']; foreach ($this->basicPages as $pageName) { // Reset the counters - $this->hookCount = array('pageRun' => array()); + $this->hookCount = ['pageRun' => []]; $page = new $pageName(); ob_start(); $page->run(); diff --git a/tests/phpunit/CRM/Core/Page/RedirectTest.php b/tests/phpunit/CRM/Core/Page/RedirectTest.php index 85514f6dd0..9e8f0733f1 100644 --- a/tests/phpunit/CRM/Core/Page/RedirectTest.php +++ b/tests/phpunit/CRM/Core/Page/RedirectTest.php @@ -15,25 +15,25 @@ class CRM_Core_Page_RedirectTest extends CiviUnitTestCase { * @return array */ public function examples() { - $cases = array(); + $cases = []; // $cases[] = array(string $requestPath, string $requestArgs, string $pageArgs, string $expectedUrl) // Note: CRM_Utils_System::url() and CRM_Utils_System::redirect() represent the // URL in "htmlized" format, so the $expectedUrl is "htmlized". - $cases[] = array('', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard'); - $cases[] = array('', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard'); - $cases[] = array('', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar'); - $cases[] = array('', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&whiz=1&bang=2'); - $cases[] = array('', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&unknown='); - $cases[] = array('civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar'); + $cases[] = ['', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard']; + $cases[] = ['', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard']; + $cases[] = ['', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar']; + $cases[] = ['', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&whiz=1&bang=2']; + $cases[] = ['', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&unknown=']; + $cases[] = ['civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar']; - $cases[] = array( + $cases[] = [ '', 'gid=2&reset=1', 'url=civicrm/newfoo/%%gid%%?reset=%%reset%%', '/index.php?q=civicrm/newfoo/2&reset=1', - ); + ]; return $cases; } diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index 0c302a5b41..75fc3a28b1 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -15,9 +15,9 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate(array('is_test' => 0)); + $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate(['is_test' => 0]); $this->_contactID = $this->individualCreate(); - $contributionPage = $this->callAPISuccess('contribution_page', 'create', array( + $contributionPage = $this->callAPISuccess('contribution_page', 'create', [ 'title' => "Test Contribution Page", 'financial_type_id' => $this->_financialTypeID, 'currency' => 'USD', @@ -26,7 +26,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'receipt_from_email' => 'gaia@the.cosmos', 'receipt_from_name' => 'Pachamama', 'is_email_receipt' => TRUE, - )); + ]); $this->_contributionPageID = $contributionPage['id']; } @@ -41,10 +41,10 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { public function testIPNPaymentRecurNoReceipt() { $mut = new CiviMailUtils($this, TRUE); // Turn off receipts in contribution page. - $api_params = array( + $api_params = [ 'id' => $this->_contributionPageID, 'is_email_receipt' => FALSE, - ); + ]; $this->callAPISuccess('contributionPage', 'update', $api_params); // Create initial recurring payment and initial contribution. @@ -57,7 +57,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { // has is_email_receipt set to 0. $form = new CRM_Contribute_Form_Contribution(); $form->_mode = 'Live'; - $contribution = $form->testSubmit(array( + $contribution = $form->testSubmit([ 'total_amount' => 200, 'financial_type_id' => 1, 'receive_date' => date('m/d/Y'), @@ -66,10 +66,10 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'contribution_status_id' => 1, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -89,25 +89,25 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'source' => 'bob sled race', 'contribution_page_id' => $this->_contributionPageID, 'is_recur' => TRUE, - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); $this->_contributionID = $contribution->id; $this->_contributionRecurID = $contribution->contribution_recur_id; - $recur_params = array( + $recur_params = [ 'id' => $this->_contributionRecurID, 'return' => 'processor_id', - ); + ]; $processor_id = civicrm_api3('ContributionRecur', 'getvalue', $recur_params); // Process the initial one. $IPN = new CRM_Core_Payment_AuthorizeNetIPN( - $this->getRecurTransaction(array('x_subscription_id' => $processor_id)) + $this->getRecurTransaction(['x_subscription_id' => $processor_id]) ); $IPN->main(); // Now send a second one (authorize seems to treat first and second contributions // differently. $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction( - array('x_subscription_id' => $processor_id) + ['x_subscription_id' => $processor_id] )); $IPN->main(); @@ -122,19 +122,19 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $this->setupRecurringPaymentProcessorTransaction(); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('6511143069', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction()); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][1]['receive_date']))); @@ -145,18 +145,18 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { */ public function testIPNPaymentRecurSuccessMultiAuthNetProcessor() { //Create and set up recur payment using second instance of AuthNet Processor. - $this->_paymentProcessorID2 = $this->paymentProcessorAuthorizeNetCreate(array('name' => 'Authorize2', 'is_test' => 0)); - $this->setupRecurringPaymentProcessorTransaction(array('payment_processor_id' => $this->_paymentProcessorID2)); + $this->_paymentProcessorID2 = $this->paymentProcessorAuthorizeNetCreate(['name' => 'Authorize2', 'is_test' => 0]); + $this->setupRecurringPaymentProcessorTransaction(['payment_processor_id' => $this->_paymentProcessorID2]); //Call IPN with processor id. - $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('processor_id' => $this->_paymentProcessorID2))); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(['processor_id' => $this->_paymentProcessorID2])); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('6511143069', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); } @@ -167,19 +167,19 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $this->setupRecurringPaymentProcessorTransaction(); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('6511143069', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); - $IPN = new CRM_Core_Payment_AuthorizeNetIPN(array_merge(array('receive_date' => '1 July 2010'), $this->getRecurSubsequentTransaction())); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN(array_merge(['receive_date' => '1 July 2010'], $this->getRecurSubsequentTransaction())); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); $this->assertEquals('2010-07-01', date('Y-m-d', strtotime($contribution['values'][1]['receive_date']))); @@ -192,29 +192,29 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $this->setupMembershipRecurringPaymentProcessorTransaction(); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('6511143069', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction()); $IPN->main(); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); // Ensure both contributions are coded as credit card contributions. $this->assertEquals(1, $contribution['values'][0]['payment_instrument_id']); $this->assertEquals(1, $contribution['values'][1]['payment_instrument_id']); $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); - $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'])); - $this->callAPISuccessGetSingle('line_item', array( + $this->callAPISuccessGetSingle('membership_payment', ['contribution_id' => $contribution['values'][1]['id']]); + $this->callAPISuccessGetSingle('line_item', [ 'contribution_id' => $contribution['values'][1]['id'], 'entity_table' => 'civicrm_membership', - )); + ]); } /** @@ -222,7 +222,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { */ public function testIPNPaymentMembershipRecurSuccessNoLeakage() { $mut = new CiviMailUtils($this, TRUE); - $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); + $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]); $this->addProfile('supporter_profile', $this->_contributionPageID); $this->addProfile('honoree_individual', $this->_contributionPageID, 'soft_credit'); @@ -235,7 +235,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); $IPN->main(); - $mut->checkAllMailLog(array( + $mut->checkAllMailLog([ 'Membership Type: General', 'Mr. Anthony Anderson II" ', 'Amount: $ 200.00', @@ -249,18 +249,18 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'Dear Mr. Anthony Anderson II', 'Thanks for your auto renew membership sign-up', 'In Memory of', - )); + ]); $mut->clearMessages(); - $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org')); + $this->_contactID = $this->individualCreate(['first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org']); $this->_invoiceID = uniqid(); // Note, the second contribution is not in honor of anyone and the // receipt should not mention honor at all. - $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); - $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers'))); + $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(['x_trans_id' => 'hers'])); $IPN->main(); - $mut->checkAllMailLog(array( + $mut->checkAllMailLog([ 'Membership Type: General', 'Mrs. Antonia Anderson II', 'antonia_anderson@civicrm.org', @@ -274,15 +274,15 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'This membership will be automatically renewed every', 'Dear Mrs. Antonia Anderson II', 'Thanks for your auto renew membership sign-up', - )); + ]); - $shouldNotBeInMailing = array( + $shouldNotBeInMailing = [ 'Honor', 'In Memory of', - ); + ]; $mails = $mut->getAllMessages('raw'); foreach ($mails as $mail) { - $mut->checkMailForStrings(array(), $shouldNotBeInMailing, '', $mail); + $mut->checkMailForStrings([], $shouldNotBeInMailing, '', $mail); } $mut->stop(); $mut->clearMessages(); @@ -293,11 +293,11 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { */ public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline() { $mut = new CiviMailUtils($this, TRUE); - $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); + $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]); $this->addProfile('supporter_profile', $this->_contributionPageID); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); $IPN->main(); - $mut->checkAllMailLog(array( + $mut->checkAllMailLog([ 'Membership Type: General', 'Mr. Anthony Anderson II" ', 'Amount: $ 200.00', @@ -309,18 +309,18 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'This membership will be automatically renewed every', 'Dear Mr. Anthony Anderson II', 'Thanks for your auto renew membership sign-up', - )); + ]); - $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org')); + $this->_contactID = $this->individualCreate(['first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org']); $this->_invoiceID = uniqid(); $this->_contributionPageID = NULL; - $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); + $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]); $mut->clearMessages(); - $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers'))); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(['x_trans_id' => 'hers'])); $IPN->main(); - $mut->checkAllMailLog(array( + $mut->checkAllMailLog([ 'Membership Type: General', 'Mrs. Antonia Anderson II', 'antonia_anderson@civicrm.org', @@ -330,14 +330,14 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'This membership will be automatically renewed every', 'Dear Mrs. Antonia Anderson II', 'Thanks for your auto renew membership sign-up', - ), - array( + ], + [ 'First Name: Anthony', 'First Name: Antonia', 'Last Name: Anderson', 'Supporter Profile', 'Email Address: antonia_anderson@civicrm.org', - )); + ]); $mut->stop(); $mut->clearMessages(); @@ -352,8 +352,8 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { * @return array * Parameters like AuthorizeNet silent post paramters. */ - public function getRecurTransaction($params = array()) { - return array_merge(array( + public function getRecurTransaction($params = []) { + return array_merge([ "x_amount" => "200.00", "x_country" => 'US', "x_phone" => "", @@ -398,17 +398,17 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'x_response_reason_text' => 'This transaction has been approved.', 'x_response_reason_code' => '1', 'x_response_code' => '1', - ), $params); + ], $params); } /** * @return array */ - public function getRecurSubsequentTransaction($params = array()) { - return array_merge($this->getRecurTransaction(), array( + public function getRecurSubsequentTransaction($params = []) { + return array_merge($this->getRecurTransaction(), [ 'x_trans_id' => 'second_one', 'x_MD5_Hash' => 'EA7A3CD65A85757827F51212CA1486A8', - ), $params); + ], $params); } } diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php index 3138456490..4060c5b56c 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php @@ -40,7 +40,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { // for some strange unknown reason, in batch mode this value gets set to null // so crude hack here to avoid an exception and hence an error - $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array(); + $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = []; } public function tearDown() { @@ -55,13 +55,13 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { public function testCreateSingleNowDated() { $firstName = 'John_' . substr(sha1(rand()), 0, 7) . uniqid(); $lastName = 'Smith_' . substr(sha1(rand()), 0, 7) . uniqid(); - $nameParams = array('first_name' => $firstName, 'last_name' => $lastName); + $nameParams = ['first_name' => $firstName, 'last_name' => $lastName]; $contactId = $this->individualCreate($nameParams); $invoiceID = sha1(rand()); $amount = rand(100, 1000) . '.00'; - $recur = $this->callAPISuccess('ContributionRecur', 'create', array( + $recur = $this->callAPISuccess('ContributionRecur', 'create', [ 'contact_id' => $contactId, 'amount' => $amount, 'currency' => 'USD', @@ -74,9 +74,9 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'contribution_status_id' => 2, 'is_test' => 1, 'payment_processor_id' => $this->_paymentProcessorID, - )); + ]); - $contribution = $this->callAPISuccess('Contribution', 'create', array( + $contribution = $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $contactId, 'financial_type_id' => $this->_financialTypeId, 'receive_date' => date('Ymd'), @@ -86,9 +86,9 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'contribution_recur_id' => $recur['id'], 'is_test' => 1, 'contribution_status_id' => 2, - )); + ]); - $params = array( + $params = [ 'qfKey' => '08ed21c7ca00a1f7d32fff2488596ef7_4454', 'hidden_CreditCard' => 1, 'billing_first_name' => $firstName, @@ -101,10 +101,10 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'billing_country_id-5' => 1228, 'credit_card_number' => '4007000000027', 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 10, 'Y' => 2019, - ), + ], 'credit_card_type' => 'Visa', 'is_recur' => 1, 'frequency_interval' => 1, @@ -158,7 +158,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'contributionID' => $contribution['id'], 'contributionTypeID' => $this->_financialTypeId, 'contributionRecurID' => $recur['id'], - ); + ]; // turn verifySSL off Civi::settings()->set('verifySSL', '0'); @@ -174,7 +174,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { // cancel it or the transaction will be rejected by A.net if the test is re-run $subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur['id'], 'processor_id'); $message = ''; - $result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID)); + $result = $this->processor->cancelSubscription($message, ['subscriptionId' => $subscriptionID]); $this->assertTrue($result, 'Failed to cancel subscription with Authorize.'); } @@ -186,14 +186,14 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { $firstName = 'John_' . substr(sha1(rand()), 0, 7); $lastName = 'Smith_' . substr(sha1(rand()), 0, 7); - $nameParams = array('first_name' => $firstName, 'last_name' => $lastName); + $nameParams = ['first_name' => $firstName, 'last_name' => $lastName]; $contactId = $this->individualCreate($nameParams); - $ids = array('contribution' => NULL); + $ids = ['contribution' => NULL]; $invoiceID = sha1(rand()); $amount = rand(100, 1000) . '.00'; - $contributionRecurParams = array( + $contributionRecurParams = [ 'contact_id' => $contactId, 'amount' => $amount, 'currency' => 'USD', @@ -206,10 +206,10 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'contribution_status_id' => 2, 'is_test' => 1, 'payment_processor_id' => $this->_paymentProcessorID, - ); + ]; $recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams, $ids); - $contributionParams = array( + $contributionParams = [ 'contact_id' => $contactId, 'financial_type_id' => $this->_financialTypeId, 'receive_date' => $start_date, @@ -219,11 +219,11 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'contribution_recur_id' => $recur->id, 'is_test' => 1, 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); - $params = array( + $params = [ 'qfKey' => '00ed21c7ca00a1f7d555555596ef7_4454', 'hidden_CreditCard' => 1, 'billing_first_name' => $firstName, @@ -236,10 +236,10 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'billing_country_id-5' => 1228, 'credit_card_number' => '4007000000027', 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 11, 'Y' => 2022, - ), + ], 'credit_card_type' => 'Visa', 'is_recur' => 1, 'frequency_interval' => 1, @@ -291,7 +291,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { 'contactID' => $contactId, 'contributionID' => $contribution['id'], 'contributionRecurID' => $recur->id, - ); + ]; // if cancel-subscription has been called earlier 'subscriptionType' would be set to cancel. // to make a successful call for another trxn, we need to set it to something else. @@ -312,7 +312,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { // cancel it or the transaction will be rejected by A.net if the test is re-run $subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id'); $message = ''; - $result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID)); + $result = $this->processor->cancelSubscription($message, ['subscriptionId' => $subscriptionID]); $this->assertTrue($result, 'Failed to cancel subscription with Authorize.'); } diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php index a1e6073706..10eae5e7bf 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -47,7 +47,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { * * @var array */ - protected $_membershipParams = array(); + protected $_membershipParams = []; /** * IPN instance. @@ -77,15 +77,15 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function setUp() { parent::setUp(); - $this->_processorId = $this->paymentProcessorAuthorizeNetCreate(array('is_test' => 0)); - $this->input = $this->ids = $this->objects = array(); + $this->_processorId = $this->paymentProcessorAuthorizeNetCreate(['is_test' => 0]); + $this->input = $this->ids = $this->objects = []; $this->IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->input); $this->_contactId = $this->individualCreate(); $this->ids['contact'] = $this->_contactId; $this->_financialTypeId = 1; - $this->_contributionParams = array( + $this->_contributionParams = [ 'contact_id' => $this->_contactId, 'financial_type_id' => $this->_financialTypeId, 'receive_date' => date('Ymd'), @@ -94,7 +94,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { 'currency' => 'USD', 'contribution_recur_id' => $this->_recurId, 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $this->_contributionParams); $this->_contributionId = $contribution['id']; @@ -137,12 +137,12 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); $this->assertEquals('Anthony', $this->objects['contact']->first_name); - $this->ids['contact'] = $this->_contactId = $this->individualCreate(array( + $this->ids['contact'] = $this->_contactId = $this->individualCreate([ 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com', - )); - $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, array('invoice_id' => 'abc'))); + ]); + $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc'])); $this->_contributionId = $contribution['id']; $this->_setUpMembershipObjects(); $this->input['invoiceID'] = 'abc'; @@ -174,7 +174,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testsendMailMembershipObjects() { $this->_setUpMembershipObjects(); - $values = array(); + $values = []; $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); $this->assertTrue(is_array($msg), "Message returned as an array in line"); @@ -190,17 +190,17 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testSendMailMembershipObjectsNoLeakage() { $this->_setUpMembershipObjects(); - $values = array(); + $values = []; $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); $this->assertContains('Membership Type: General', $msg['body']); - $this->ids['contact'] = $this->_contactId = $this->individualCreate(array('prefix_id' => 'Dr.', 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com')); - $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, array('invoice_id' => 'abc'))); + $this->ids['contact'] = $this->_contactId = $this->individualCreate(['prefix_id' => 'Dr.', 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com']); + $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc'])); $this->_contributionId = $contribution['id']; - $this->_membershipTypeID = $this->membershipTypeCreate(array('name' => 'Fowl')); + $this->_membershipTypeID = $this->membershipTypeCreate(['name' => 'Fowl']); $this->_setUpMembershipObjects(); $this->input['invoiceID'] = 'abc'; $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); @@ -215,7 +215,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testsendMailMembershipWithoutLoadObjects() { $this->_setUpMembershipObjects(); - $values = array(); + $values = []; $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); @@ -244,7 +244,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { public function testComposeMailParticipant() { $this->_setUpParticipantObjects(); $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); - $values = array(); + $values = []; $this->assertFalse(empty($this->objects['event'])); $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); $this->assertContains('registration has been received and your status has been updated to Attended.', $msg['body']); @@ -255,7 +255,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testComposeMailParticipantObjects() { $this->_setUpParticipantObjects(); - $values = array(); + $values = []; $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); @@ -268,15 +268,15 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testsendMailParticipantObjectsCheckLog() { $this->_setUpParticipantObjects(); - $values = array(); + $values = []; $mut = new CiviMailUtils($this, TRUE); $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Thank you for your participation', 'Annual CiviCRM meet', 'Mr. Anthony Anderson II', - )); + ]); $mut->stop(); } @@ -289,10 +289,10 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $event->id = $this->_eventId; $event->is_email_confirm = FALSE; $event->save(); - $values = array(); - $tablesToTruncate = array( + $values = []; + $tablesToTruncate = [ 'civicrm_mailing_spool', - ); + ]; $this->quickCleanup($tablesToTruncate, FALSE); $mut = new CiviMailUtils($this, TRUE); $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); @@ -325,23 +325,23 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { public function testLoadPledgeObjectsInvalidPledgeID() { $this->_setUpPledgeObjects(); $this->ids['pledge_payment'][0] = 0; - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]); $this->assertArrayHasKey('error_message', $result); $this->assertArrayNotHasKey('pledge_payment', $this->objects); $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); $this->ids['pledge_payment'][0] = NULL; - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]); $this->assertArrayHasKey('error_message', $result); $this->assertArrayNotHasKey('pledge_payment', $this->objects); $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); $this->ids['pledge_payment'][0] = ''; - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]); $this->assertArrayHasKey('error_message', $result); $this->assertArrayNotHasKey('pledge_payment', $this->objects); $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); $this->ids['pledge_payment'][0] = 999; - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, ['return_error' => 1]); $this->assertArrayHasKey('error_message', $result); $this->assertEquals('Could not find pledge payment record: 999', $result['error_message']); } @@ -351,7 +351,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testsendMailPledge() { $this->_setUpPledgeObjects(); - $values = array(); + $values = []; $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL); $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); $this->assertContains('Contribution Information', $msg['html']); @@ -362,14 +362,14 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testRequiredWithoutProcessorID() { $this->_setUpPledgeObjects(); - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]); $this->assertArrayHasKey('error_message', $result); $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); // error is only returned if $required set to True - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, ['return_error' => 1]); $this->assertFalse(is_array($result)); //check that error is not returned if error checking not set - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['log_error' => 1]); $this->assertFalse(is_array($result)); } @@ -378,7 +378,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testRequiredWithContributionPage() { $this->_setUpContributionObjects(TRUE); - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]); $this->assertEquals(1, $result['is_error']); ; } @@ -390,8 +390,8 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testPaymentProcessorLoadsAsParam() { $this->_setUpContributionObjects(); - $this->input = array_merge($this->input, array('payment_processor_id' => $this->_processorId)); - $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1))); + $this->input = array_merge($this->input, ['payment_processor_id' => $this->_processorId]); + $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1])); } /** @@ -399,25 +399,25 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testRequiredWithContributionPageError() { $this->_setUpContributionObjects(); - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]); $this->assertArrayHasKey('error_message', $result); $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); // error is only returned if $required set to True - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, ['return_error' => 1]); $this->assertFalse(is_array($result)); //check that error is not returned if error checking not set - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1)); + $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['log_error' => 1]); $this->assertFalse(is_array($result)); } public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() { $this->_setUpParticipantObjects('Pending from incomplete transaction'); $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); - $additionalParticipantId = $this->participantCreate(array( + $additionalParticipantId = $this->participantCreate([ 'event_id' => $this->_eventId, 'registered_by_id' => $this->_participantId, 'status_id' => 'Pending from incomplete transaction', - )); + ]); $transaction = new CRM_Core_Transaction(); $this->IPN->cancelled($this->objects, $transaction); @@ -442,11 +442,11 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { public function testThatFailedEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() { $this->_setUpParticipantObjects('Pending from incomplete transaction'); $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); - $additionalParticipantId = $this->participantCreate(array( + $additionalParticipantId = $this->participantCreate([ 'event_id' => $this->_eventId, 'registered_by_id' => $this->_participantId, 'status_id' => 'Pending from incomplete transaction', - )); + ]); $transaction = new CRM_Core_Transaction(); $this->IPN->failed($this->objects, $transaction); @@ -497,14 +497,14 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { } $this->objects['contribution'] = $contribution; - $this->input = array( + $this->input = [ 'component' => 'contribute', 'contribution_page_id' => $contributionPageID, 'total_amount' => 110.00, 'invoiceID' => "c8acb91e080ad7777a2adc119c192885", 'contactID' => $this->_contactId, 'contributionID' => $this->objects['contribution']->id, - ); + ]; } /** @@ -524,7 +524,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { } CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE); CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE); - $this->_membershipParams = array( + $this->_membershipParams = [ 'contact_id' => $this->_contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2009-01-21', @@ -534,36 +534,36 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { 'is_override' => 1, 'status_id' => $this->_membershipStatusID, 'version' => 3, - ); + ]; $membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams); if ($this->objects['contribution']->id != $this->_contributionId) { $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; $contribution->find(TRUE); - $this->objects = array('contribution' => $contribution); + $this->objects = ['contribution' => $contribution]; } $this->_membershipId = $membership['id']; //we'll create membership payment here because to make setup more re-usable - $this->callAPISuccess('membership_payment', 'create', array( + $this->callAPISuccess('membership_payment', 'create', [ 'contribution_id' => $this->_contributionId, 'membership_id' => $this->_membershipId, - )); + ]); - $this->input = array( + $this->input = [ 'component' => 'contribute', 'total_amount' => 150.00, 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", 'contactID' => $this->_contactId, 'contributionID' => $this->_contributionId, 'membershipID' => $this->_membershipId, - ); + ]; $this->ids['membership'] = $this->_membershipId; } public function _setUpRecurringContribution() { - $this->_contributionRecurParams = array( + $this->_contributionRecurParams = [ 'contact_id' => $this->_contactId, 'amount' => 150.00, 'currency' => 'USD', @@ -577,7 +577,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { 'financial_type_id' => $this->_financialTypeId, 'version' => 3, 'payment_processor_id' => $this->_processorId, - ); + ]; $this->_recurId = $this->callAPISuccess('contribution_recur', 'create', $this->_contributionRecurParams); $this->_recurId = $this->_recurId['id']; $this->input['contributionRecurId'] = $this->_recurId; @@ -591,32 +591,32 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { * The participant to create status */ public function _setUpParticipantObjects($participantStatus = 'Attended') { - $event = $this->eventCreate(array('is_email_confirm' => 1)); + $event = $this->eventCreate(['is_email_confirm' => 1]); $this->_eventId = $event['id']; - $this->_participantId = $this->participantCreate(array( + $this->_participantId = $this->participantCreate([ 'event_id' => $this->_eventId, 'contact_id' => $this->_contactId, 'status_id' => $participantStatus, - )); + ]); - $this->callAPISuccess('participant_payment', 'create', array( + $this->callAPISuccess('participant_payment', 'create', [ 'contribution_id' => $this->_contributionId, 'participant_id' => $this->_participantId, - )); + ]); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; $contribution->find(); $this->objects['contribution'] = $contribution; - $this->input = array( + $this->input = [ 'component' => 'event', 'total_amount' => 150.00, 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", 'contactID' => $this->_contactId, 'contributionID' => $contribution->id, 'participantID' => $this->_participantId, - ); + ]; $this->ids['participant'] = $this->_participantId; $this->ids['event'] = $this->_eventId; @@ -626,24 +626,24 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { * Set up participant requirements for test. */ public function _setUpPledgeObjects() { - $this->_pledgeId = $this->pledgeCreate(array('contact_id' => $this->_contactId)); + $this->_pledgeId = $this->pledgeCreate(['contact_id' => $this->_contactId]); //we'll create membership payment here because to make setup more re-usable - $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', array( + $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', [ 'version' => 3, 'pledge_id' => $this->_pledgeId, 'contribution_id' => $this->_contributionId, 'status_id' => 1, 'actual_amount' => 50, - )); + ]); - $this->input = array( + $this->input = [ 'component' => 'contribute', 'total_amount' => 150.00, 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", 'contactID' => $this->_contactId, 'contributionID' => $this->_contributionId, 'pledgeID' => $this->_pledgeId, - ); + ]; $this->ids['pledge_payment'][] = $pledgePayment['id']; } diff --git a/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php b/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php index 126bc6cb6f..05d1694d13 100644 --- a/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php @@ -43,21 +43,21 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { * * @var array */ - protected $ids = array(); + protected $ids = []; /** * Set up function. */ public function setUp() { parent::setUp(); - $this->_paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0, 'payment_processor_type_id' => 'PayPal_Standard')); + $this->_paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0, 'payment_processor_type_id' => 'PayPal_Standard']); $this->_contactID = $this->individualCreate(); - $contributionPage = $this->callAPISuccess('contribution_page', 'create', array( + $contributionPage = $this->callAPISuccess('contribution_page', 'create', [ 'title' => "Test Contribution Page", 'financial_type_id' => $this->_financialTypeID, 'currency' => 'USD', 'payment_processor' => $this->_paymentProcessorID, - )); + ]); $this->_contributionPageID = $contributionPage['id']; } @@ -79,37 +79,37 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { $pendingStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); $completedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); - $params = array( + $params = [ 'payment_processor_id' => $this->_paymentProcessorID, 'contact_id' => $this->_contactID, 'trxn_id' => NULL, 'invoice_id' => $this->_invoiceID, 'contribution_status_id' => $pendingStatusID, 'is_email_receipt' => TRUE, - ); + ]; $this->_contributionID = $this->contributionCreate($params); - $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1)); + $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]); // assert that contribution created before handling payment via paypal standard has no transaction id set and pending status $this->assertEquals(NULL, $contribution['values'][0]['trxn_id']); $this->assertEquals($pendingStatusID, $contribution['values'][0]['contribution_status_id']); global $_REQUEST; - $_REQUEST = array('q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)) + $this->getPaypalTransaction(); + $_REQUEST = ['q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)] + $this->getPaypalTransaction(); $mut = new CiviMailUtils($this, TRUE); - $paymentProcesors = civicrm_api3('PaymentProcessor', 'getsingle', array('id' => $this->_paymentProcessorID)); + $paymentProcesors = civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $this->_paymentProcessorID]); $payment = Civi\Payment\System::singleton()->getByProcessor($paymentProcesors); $payment->handlePaymentNotification(); // Check if invoice pdf is attached with contribution mail reciept - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Content-Transfer-Encoding: base64', 'Content-Type: application/pdf', 'filename=Invoice.pdf', - )); + ]); $mut->stop(); - $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1)); + $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]); // assert that contribution is completed after getting response from paypal standard which has transaction id set and completed status $this->assertEquals($_REQUEST['txn_id'], $contribution['values'][0]['trxn_id']); $this->assertEquals($completedStatusID, $contribution['values'][0]['contribution_status_id']); @@ -125,19 +125,19 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { $this->setupRecurringPaymentProcessorTransaction([], ['total_amount' => '15.00']); $paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurTransaction()); $paypalIPN->main(); - $contribution1 = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution1 = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(1, $contribution1['contribution_status_id']); $this->assertEquals('8XA571746W2698126', $contribution1['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution1['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurSubsequentTransaction()); $paypalIPN->main(); - $contributions = $this->callAPISuccess('contribution', 'get', array( + $contributions = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contributions['count']); $contribution2 = $contributions['values'][1]; $this->assertEquals('secondone', $contribution2['trxn_id']); @@ -160,37 +160,37 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { */ public function testIPNPaymentMembershipRecurSuccess() { $durationUnit = 'year'; - $this->setupMembershipRecurringPaymentProcessorTransaction(array('duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit)); - $this->callAPISuccessGetSingle('membership_payment', array()); + $this->setupMembershipRecurringPaymentProcessorTransaction(['duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit]); + $this->callAPISuccessGetSingle('membership_payment', []); $paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurTransaction()); $paypalIPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); - $membershipEndDate = $this->callAPISuccessGetValue('membership', array('return' => 'end_date')); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); + $membershipEndDate = $this->callAPISuccessGetValue('membership', ['return' => 'end_date']); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('8XA571746W2698126', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $paypalIPN = new CRM_Core_Payment_PaypalIPN($this->getPaypalRecurSubsequentTransaction()); $paypalIPN->main(); $renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membershipEndDate); - $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', array('return' => 'end_date'))); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', ['return' => 'end_date'])); + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); $this->assertEquals('secondone', $contribution['values'][1]['trxn_id']); - $this->callAPISuccessGetCount('line_item', array( + $this->callAPISuccessGetCount('line_item', [ 'entity_id' => $this->ids['membership'], 'entity_table' => 'civicrm_membership', - ), 2); - $this->callAPISuccessGetSingle('line_item', array( + ], 2); + $this->callAPISuccessGetSingle('line_item', [ 'contribution_id' => $contribution['values'][1]['id'], 'entity_table' => 'civicrm_membership', - )); - $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'])); + ]); + $this->callAPISuccessGetSingle('membership_payment', ['contribution_id' => $contribution['values'][1]['id']]); } @@ -198,7 +198,7 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { * Get IPN style details for an incoming recurring transaction. */ public function getPaypalRecurTransaction() { - return array( + return [ 'contactID' => $this->_contactID, 'contributionID' => $this->_contributionID, 'invoice' => $this->_invoiceID, @@ -214,14 +214,14 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { 'first_name' => 'Robert', 'txn_id' => '8XA571746W2698126', 'residence_country' => 'US', - ); + ]; } /** * Get IPN style details for an incoming paypal standard transaction. */ public function getPaypalTransaction() { - return array( + return [ 'contactID' => $this->_contactID, 'contributionID' => $this->_contributionID, 'invoice' => $this->_invoiceID, @@ -239,7 +239,7 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { 'txn_id' => '8XA571746W2698126', 'residence_country' => 'US', 'custom' => json_encode(['cgid' => 'test12345']), - ); + ]; } /** @@ -248,7 +248,7 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { * @return array */ public function getPaypalRecurSubsequentTransaction() { - return array_merge($this->getPaypalRecurTransaction(), array('txn_id' => 'secondone')); + return array_merge($this->getPaypalRecurTransaction(), ['txn_id' => 'secondone']); } /** @@ -261,28 +261,28 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { $pendingStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); $completedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); - $params = array( + $params = [ 'payment_processor_id' => $this->_paymentProcessorID, 'contact_id' => $this->_contactID, 'trxn_id' => NULL, 'invoice_id' => $this->_invoiceID, 'contribution_status_id' => $pendingStatusID, 'is_email_receipt' => TRUE, - ); + ]; $this->_contributionID = $this->contributionCreate($params); $this->createCustomField(); - $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1)); + $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]); // assert that contribution created before handling payment via paypal standard has no transaction id set and pending status $this->assertEquals(NULL, $contribution['values'][0]['trxn_id']); $this->assertEquals($pendingStatusID, $contribution['values'][0]['contribution_status_id']); - $this->hookClass->setHook('civicrm_postIPNProcess', array($this, 'hookCiviCRMAlterIPNData')); + $this->hookClass->setHook('civicrm_postIPNProcess', [$this, 'hookCiviCRMAlterIPNData']); global $_REQUEST; - $_REQUEST = array('q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)) + $this->getPaypalTransaction(); + $_REQUEST = ['q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)] + $this->getPaypalTransaction(); $mut = new CiviMailUtils($this, TRUE); $payment = CRM_Core_Payment::handlePaymentMethod('PaymentNotification', ['processor_id' => $this->_paymentProcessorID]); - $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1)); + $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]); // assert that contribution is completed after getting response from paypal standard which has transaction id set and completed status $this->assertEquals($_REQUEST['txn_id'], $contribution['values'][0]['trxn_id']); $this->assertEquals($completedStatusID, $contribution['values'][0]['contribution_status_id']); @@ -304,13 +304,13 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { * @return array */ protected function createCustomField() { - $customGroup = $this->customGroupCreate(array('extends' => 'Contribution')); - $fields = array( + $customGroup = $this->customGroupCreate(['extends' => 'Contribution']); + $fields = [ 'label' => 'TestCustomFieldIPNHook', 'data_type' => 'String', 'html_type' => 'Text', 'custom_group_id' => $customGroup['id'], - ); + ]; $field = CRM_Core_BAO_CustomField::create($fields); $this->_customFieldID = $field->id; return $customGroup; diff --git a/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php b/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php index f1cb8d2919..7480015756 100644 --- a/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php @@ -42,21 +42,21 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { * * @var array */ - protected $ids = array(); + protected $ids = []; /** * Set up function. */ public function setUp() { parent::setUp(); - $this->_paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0)); + $this->_paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0]); $this->_contactID = $this->individualCreate(); - $contributionPage = $this->callAPISuccess('contribution_page', 'create', array( + $contributionPage = $this->callAPISuccess('contribution_page', 'create', [ 'title' => "Test Contribution Page", 'financial_type_id' => $this->_financialTypeID, 'currency' => 'USD', 'payment_processor' => $this->_paymentProcessorID, - )); + ]); $this->_contributionPageID = $contributionPage['id']; } @@ -79,19 +79,19 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { $_GET = $this->getPaypalProRecurTransaction(); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurTransaction()); $paypalIPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('8XA571746W2698126', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurSubsequentTransaction()); $paypalIPN->main(); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); $this->assertEquals('secondone', $contribution['values'][1]['trxn_id']); $this->assertEquals('Debit Card', $contribution['values'][1]['payment_instrument']); @@ -102,38 +102,38 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { */ public function testIPNPaymentMembershipRecurSuccess() { $durationUnit = 'year'; - $this->setupMembershipRecurringPaymentProcessorTransaction(array('duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit)); - $this->callAPISuccessGetSingle('membership_payment', array()); + $this->setupMembershipRecurringPaymentProcessorTransaction(['duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit]); + $this->callAPISuccessGetSingle('membership_payment', []); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurTransaction()); $paypalIPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); - $membershipEndDate = $this->callAPISuccessGetValue('membership', array('return' => 'end_date')); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); + $membershipEndDate = $this->callAPISuccessGetValue('membership', ['return' => 'end_date']); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('8XA571746W2698126', $contribution['trxn_id']); // source gets set by processor $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $paypalIPN = new CRM_Core_Payment_PaypalProIPN($this->getPaypalProRecurSubsequentTransaction()); $paypalIPN->main(); $renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membershipEndDate); - $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', array('return' => 'end_date'))); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', ['return' => 'end_date'])); + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); $this->assertEquals('secondone', $contribution['values'][1]['trxn_id']); - $this->callAPISuccessGetCount('line_item', array( + $this->callAPISuccessGetCount('line_item', [ 'entity_id' => $this->ids['membership'], 'entity_table' => 'civicrm_membership', - ), 2); - $this->callAPISuccessGetSingle('line_item', array( + ], 2); + $this->callAPISuccessGetSingle('line_item', [ 'contribution_id' => $contribution['values'][1]['id'], 'entity_table' => 'civicrm_membership', - )); - $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'])); + ]); + $this->callAPISuccessGetSingle('membership_payment', ['contribution_id' => $contribution['values'][1]['id']]); } @@ -152,17 +152,17 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { $paypalIPN = new CRM_Core_Payment_PayPalProIPN($firstPaymentParams); $paypalIPN->main(); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); $this->assertEquals(2, $contribution['contribution_status_id']); $this->assertEquals('', $contribution['trxn_id']); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals(2, $contributionRecur['contribution_status_id']); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurSubsequentTransaction()); $paypalIPN->main(); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - )); + ]); $this->assertEquals(1, $contribution['count']); $this->assertEquals('secondone', $contribution['values'][0]['trxn_id']); $this->assertEquals(strtotime('03:59:05 Jul 14, 2013 PDT'), strtotime($contribution['values'][0]['receive_date'])); @@ -193,7 +193,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { $paypalIPN->main(); } catch (CRM_Core_Exception $e) { - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]); // no change $this->assertEquals(2, $contribution['contribution_status_id']); $this->assertEquals('Paypal IPNS not handled other than recurring_payments', $e->getMessage()); @@ -208,7 +208,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { * array representing a Paypal IPN POST */ public function getPaypalExpressTransactionIPN() { - return array( + return [ 'mc_gross' => '200.00', 'invoice' => $this->_invoiceID, 'protection_eligibility' => 'Eligible', @@ -250,7 +250,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { 'shipping' => '0.00', 'ipn_track_id' => '5r27c2e31rl7c', 'is_unit_test' => TRUE, - ); + ]; } /** @@ -259,7 +259,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { * array representing a Paypal IPN POST */ public function getSubsequentPaypalExpressTransaction() { - return array( + return [ 'mc_gross' => '5.00', 'period_type' => ' Regular', 'outstanding_balance' => '0.00', @@ -309,14 +309,14 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { 'product_type' => '1', 'time_created' => '12:02:25 May 14, 2013 PDT', 'ipn_track_id' => '912e5010eb5a6', - ); + ]; } /** * Get IPN style details for an incoming recurring transaction. */ public function getPaypalProRecurTransaction() { - return array( + return [ 'amount' => '15.00', 'initial_payment_amount' => '0.00', 'profile_status' => 'Active', @@ -359,7 +359,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { 'next_payment_date' => '03:00:00 Aug 14, 2013 PDT', 'tax' => '0.00', 'residence_country' => 'US', - ); + ]; } /** @@ -368,7 +368,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { * @return array */ public function getPaypalProRecurSubsequentTransaction() { - return array_merge($this->getPaypalProRecurTransaction(), array('txn_id' => 'secondone')); + return array_merge($this->getPaypalProRecurTransaction(), ['txn_id' => 'secondone']); } /** @@ -378,7 +378,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { $this->setupRecurringPaymentProcessorTransaction(['processor_id' => '']); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalExpressRecurSubscriptionConfirmation()); $paypalIPN->main(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]); $this->assertEquals('I-JW77S1PY2032', $contributionRecur['processor_id']); } diff --git a/tests/phpunit/CRM/Core/PaymentTest.php b/tests/phpunit/CRM/Core/PaymentTest.php index 27b8dd0101..d1da1b0154 100644 --- a/tests/phpunit/CRM/Core/PaymentTest.php +++ b/tests/phpunit/CRM/Core/PaymentTest.php @@ -35,14 +35,14 @@ class CRM_Core_PaymentTest extends CiviUnitTestCase { * Test the payment method is adequately logged - we don't expect the processing to succeed */ public function testHandlePaymentMethodLogging() { - $params = array('processor_name' => 'Paypal', 'data' => 'blah'); + $params = ['processor_name' => 'Paypal', 'data' => 'blah']; try { CRM_Core_Payment::handlePaymentMethod('method', $params); } catch (Exception $e) { } - $log = $this->callAPISuccess('SystemLog', 'get', array()); + $log = $this->callAPISuccess('SystemLog', 'get', []); $this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']); } diff --git a/tests/phpunit/CRM/Core/Permission/BaseTest.php b/tests/phpunit/CRM/Core/Permission/BaseTest.php index cba315305d..dca187540c 100644 --- a/tests/phpunit/CRM/Core/Permission/BaseTest.php +++ b/tests/phpunit/CRM/Core/Permission/BaseTest.php @@ -11,16 +11,16 @@ class CRM_Core_Permission_BaseTest extends CiviUnitTestCase { * (0 => input to translatePermission, 1 => expected output from translatePermission) */ public function translateData() { - $cases = array(); + $cases = []; - $cases[] = array("administer CiviCRM", "administer CiviCRM"); - $cases[] = array("cms:universal name", "local name"); - $cases[] = array("cms:universal name2", "local name2"); - $cases[] = array("cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION); - $cases[] = array("myruntime:foo", "foo"); - $cases[] = array("otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION); - $cases[] = array("otherruntime:foo:bar", CRM_Core_Permission::ALWAYS_DENY_PERMISSION); - $cases[] = array(CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION); + $cases[] = ["administer CiviCRM", "administer CiviCRM"]; + $cases[] = ["cms:universal name", "local name"]; + $cases[] = ["cms:universal name2", "local name2"]; + $cases[] = ["cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; + $cases[] = ["myruntime:foo", "foo"]; + $cases[] = ["otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; + $cases[] = ["otherruntime:foo:bar", CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; + $cases[] = [CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION]; return $cases; } @@ -34,11 +34,11 @@ class CRM_Core_Permission_BaseTest extends CiviUnitTestCase { */ public function testTranslate($input, $expected) { $perm = new CRM_Core_Permission_Base(); - $actual = $perm->translatePermission($input, "myruntime", array( + $actual = $perm->translatePermission($input, "myruntime", [ 'universal name' => 'local name', 'universal name2' => 'local name2', 'gunk' => 'gunky', - )); + ]); $this->assertEquals($expected, $actual); } diff --git a/tests/phpunit/CRM/Core/Permission/GenericTest.php b/tests/phpunit/CRM/Core/Permission/GenericTest.php index 60a1a5fd4d..97aa95c167 100644 --- a/tests/phpunit/CRM/Core/Permission/GenericTest.php +++ b/tests/phpunit/CRM/Core/Permission/GenericTest.php @@ -11,12 +11,12 @@ class CRM_Core_Permission_GenericTest extends CiviUnitTestCase { * Array of CRM_Core_Permission_Base */ public function permissionClasses() { - $cases = array(); + $cases = []; - $cases[] = array('CRM_Core_Permission_Drupal'); - $cases[] = array('CRM_Core_Permission_Drupal6'); - $cases[] = array('CRM_Core_Permission_Joomla'); - $cases[] = array('CRM_Core_Permission_WordPress'); + $cases[] = ['CRM_Core_Permission_Drupal']; + $cases[] = ['CRM_Core_Permission_Drupal6']; + $cases[] = ['CRM_Core_Permission_Joomla']; + $cases[] = ['CRM_Core_Permission_WordPress']; return $cases; } diff --git a/tests/phpunit/CRM/Core/Permission/JoomlaTest.php b/tests/phpunit/CRM/Core/Permission/JoomlaTest.php index ed1fd8cee5..7296bb29b9 100644 --- a/tests/phpunit/CRM/Core/Permission/JoomlaTest.php +++ b/tests/phpunit/CRM/Core/Permission/JoomlaTest.php @@ -11,19 +11,19 @@ class CRM_Core_Permission_JoomlaTest extends CiviUnitTestCase { * (0 => input to translatePermission, 1 => expected output from translatePermission) */ public function translateData() { - $cases = array(); + $cases = []; - $cases[] = array("administer CiviCRM", array("civicrm.administer_civicrm", "com_civicrm")); + $cases[] = ["administer CiviCRM", ["civicrm.administer_civicrm", "com_civicrm"]]; // TODO $cases[] = array("cms:universal name", "local name"); // TODO $cases[] = array("cms:universal name2", "local name2"); - $cases[] = array("cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION); - $cases[] = array( + $cases[] = ["cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; + $cases[] = [ "Joomla:civicrmplusplus.extragood:com_civicrmplusplus", - array("civicrmplusplus.extragood", "com_civicrmplusplus"), - ); - $cases[] = array("otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION); - $cases[] = array(CRM_Core_Permission::ALWAYS_DENY_PERMISSION, CRM_Core_Permission::ALWAYS_DENY_PERMISSION); - $cases[] = array(CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION); + ["civicrmplusplus.extragood", "com_civicrmplusplus"], + ]; + $cases[] = ["otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; + $cases[] = [CRM_Core_Permission::ALWAYS_DENY_PERMISSION, CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; + $cases[] = [CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION]; return $cases; } diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index 100f317ecb..668522cb29 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -48,44 +48,44 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { // Create a custom field group for testing. $custom_group_name = md5(microtime()); - $api_params = array( + $api_params = [ 'title' => $custom_group_name, 'extends' => 'Individual', 'is_active' => TRUE, - ); + ]; $result = civicrm_api3('customGroup', 'create', $api_params); // Add a custom field to the above field group. - $api_params = array( + $api_params = [ 'debug' => 1, 'custom_group_id' => $result['id'], 'label' => $custom_group_name, 'html_type' => 'Select', 'data_type' => 'String', 'is_active' => TRUE, - 'option_values' => array( - array( + 'option_values' => [ + [ 'label' => 'Foo', 'value' => 'foo', 'is_active' => 1, 'weight' => 0, - ), - ), - ); + ], + ], + ]; $result = civicrm_api3('custom_field', 'create', $api_params); $customFieldId = $result['id']; // Create a Contact Group for testing. $group_name = md5(microtime()); - $api_params = array( + $api_params = [ 'title' => $group_name, 'is_active' => TRUE, - ); + ]; $result = civicrm_api3('group', 'create', $api_params); // Create a PaymentProcessor for testing. $pp_name = md5(microtime()); - $api_params = array( + $api_params = [ 'domain_id' => 1, 'payment_processor_type_id' => 'Dummy', 'name' => $pp_name, @@ -94,21 +94,21 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { 'url_site' => 'https://test.com/', 'url_recur' => 'https://test.com/', 'is_active' => 1, - ); + ]; $result = civicrm_api3('payment_processor', 'create', $api_params); // Create a Campaign for testing. $campaign_name = md5(microtime()); - $api_params = array( + $api_params = [ 'title' => $campaign_name, 'is_active' => TRUE, 'status_id' => 2, - ); + ]; $result = civicrm_api3('campaign', 'create', $api_params); // Create a membership type for testing. $membership_type = md5(microtime()); - $api_params = array( + $api_params = [ 'name' => $membership_type, 'is_active' => TRUE, 'financial_type_id' => 1, @@ -117,16 +117,16 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { 'duration_unit' => 'day', 'duration_interval' => 1, 'period_type' => 'rolling', - ); + ]; $result = civicrm_api3('membership_type', 'create', $api_params); // Create a contribution page for testing. $contribution_page = md5(microtime()); - $api_params = array( + $api_params = [ 'title' => $contribution_page, 'is_active' => TRUE, 'financial_type_id' => 1, - ); + ]; $result = civicrm_api3('contribution_page', 'create', $api_params); /** @@ -138,898 +138,898 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { * - exclude: Any one value which should not be in the list. * - max: integer (default = 20) maximum number of option values expected. */ - $fields = array( - 'CRM_ACL_DAO_ACL' => array( - array( + $fields = [ + 'CRM_ACL_DAO_ACL' => [ + [ 'fieldName' => 'operation', 'sample' => 'View', - ), - ), - 'CRM_Contact_DAO_Group' => array( - array( + ], + ], + 'CRM_Contact_DAO_Group' => [ + [ 'fieldName' => 'visibility', 'sample' => 'Public Pages', - ), - ), - 'CRM_Contact_DAO_GroupContact' => array( - array( + ], + ], + 'CRM_Contact_DAO_GroupContact' => [ + [ 'fieldName' => 'group_id', 'sample' => $group_name, - ), - array( + ], + [ 'fieldName' => 'status', 'sample' => 'Added', - ), - ), - 'CRM_Contact_DAO_GroupContactCache' => array( - array( + ], + ], + 'CRM_Contact_DAO_GroupContactCache' => [ + [ 'fieldName' => 'group_id', 'sample' => $group_name, - ), - ), - 'CRM_Contact_DAO_GroupOrganization' => array( - array( + ], + ], + 'CRM_Contact_DAO_GroupOrganization' => [ + [ 'fieldName' => 'group_id', 'sample' => $group_name, - ), - ), - 'CRM_Contact_DAO_SubscriptionHistory' => array( - array( + ], + ], + 'CRM_Contact_DAO_SubscriptionHistory' => [ + [ 'fieldName' => 'group_id', 'sample' => $group_name, - ), - array( + ], + [ 'fieldName' => 'method', 'sample' => 'Web', - ), - array( + ], + [ 'fieldName' => 'status', 'sample' => 'Added', - ), - ), - 'CRM_Core_DAO_Cache' => array( - array( + ], + ], + 'CRM_Core_DAO_Cache' => [ + [ 'fieldName' => 'component_id', 'sample' => 'CiviMail', - ), - ), - 'CRM_Contact_DAO_ACLContactCache' => array( - array( + ], + ], + 'CRM_Contact_DAO_ACLContactCache' => [ + [ 'fieldName' => 'operation', 'sample' => 'All', - ), - ), - 'CRM_Core_DAO_Setting' => array( - array( + ], + ], + 'CRM_Core_DAO_Setting' => [ + [ 'fieldName' => 'component_id', 'sample' => 'CiviMail', - ), - ), - 'CRM_Core_DAO_ActionSchedule' => array( - array( + ], + ], + 'CRM_Core_DAO_ActionSchedule' => [ + [ 'fieldName' => 'group_id', 'sample' => $group_name, - ), - array( + ], + [ 'fieldName' => 'start_action_unit', 'sample' => 'hour', - ), - array( + ], + [ 'fieldName' => 'repetition_frequency_unit', 'sample' => 'hour', - ), - array( + ], + [ 'fieldName' => 'end_frequency_unit', 'sample' => 'hour', - ), - array( + ], + [ 'fieldName' => 'mode', 'sample' => 'Email', - ), - ), - 'CRM_Dedupe_DAO_RuleGroup' => array( - array( + ], + ], + 'CRM_Dedupe_DAO_RuleGroup' => [ + [ 'fieldName' => 'contact_type', 'sample' => 'Individual', - ), - array( + ], + [ 'fieldName' => 'used', 'sample' => 'Unsupervised', - ), - ), - 'CRM_Activity_DAO_Activity' => array( - array( + ], + ], + 'CRM_Activity_DAO_Activity' => [ + [ 'fieldName' => 'activity_type_id', 'sample' => 'Email', 'max' => 100, - ), - array( + ], + [ 'fieldName' => 'status_id', 'sample' => 'Scheduled', - ), - array( + ], + [ 'fieldName' => 'priority_id', 'sample' => 'Urgent', - ), - array( + ], + [ 'fieldName' => 'engagement_level', 'sample' => '1', - ), - array( + ], + [ 'fieldName' => 'medium_id', 'sample' => 'Phone', - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Campaign_DAO_Campaign' => array( - array( + ], + ], + 'CRM_Campaign_DAO_Campaign' => [ + [ 'fieldName' => 'campaign_type_id', 'sample' => 'Constituent Engagement', 'max' => 50, - ), - array( + ], + [ 'fieldName' => 'status_id', 'sample' => 'Completed', 'max' => 50, - ), - ), - 'CRM_Campaign_DAO_Survey' => array( - array( + ], + ], + 'CRM_Campaign_DAO_Survey' => [ + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - array( + ], + [ 'fieldName' => 'activity_type_id', 'sample' => 'Phone Call', 'max' => 100, - ), - ), - 'CRM_Campaign_DAO_CampaignGroup' => array( - array( + ], + ], + 'CRM_Campaign_DAO_CampaignGroup' => [ + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - array( + ], + [ 'fieldName' => 'group_type', 'sample' => 'Include', - ), - ), - 'CRM_Contact_DAO_RelationshipType' => array( - array( + ], + ], + 'CRM_Contact_DAO_RelationshipType' => [ + [ 'fieldName' => 'contact_type_a', 'sample' => 'Individual', - ), - array( + ], + [ 'fieldName' => 'contact_type_b', 'sample' => 'Organization', - ), - ), - 'CRM_Event_DAO_ParticipantStatusType' => array( - array( + ], + ], + 'CRM_Event_DAO_ParticipantStatusType' => [ + [ 'fieldName' => 'class', 'sample' => 'Waiting', - ), - array( + ], + [ 'fieldName' => 'visibility_id', 'sample' => 'Public', - ), - ), - 'CRM_Price_DAO_LineItem' => array( - array( + ], + ], + 'CRM_Price_DAO_LineItem' => [ + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - ), - 'CRM_Price_DAO_PriceField' => array( - array( + ], + ], + 'CRM_Price_DAO_PriceField' => [ + [ 'fieldName' => 'html_type', 'sample' => 'Select', - ), - array( + ], + [ 'fieldName' => 'visibility_id', 'sample' => 'Public', - ), - ), - 'CRM_Price_DAO_PriceFieldValue' => array( - array( + ], + ], + 'CRM_Price_DAO_PriceFieldValue' => [ + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - ), - 'CRM_Price_DAO_PriceSet' => array( - array( + ], + ], + 'CRM_Price_DAO_PriceSet' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - array( + ], + [ 'fieldName' => 'extends', 'sample' => 'CiviEvent', - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - ), - 'CRM_Financial_DAO_EntityFinancialAccount' => array( - array( + ], + ], + 'CRM_Financial_DAO_EntityFinancialAccount' => [ + [ 'fieldName' => 'financial_account_id', 'sample' => 'Member Dues', - ), - array( + ], + [ 'fieldName' => 'account_relationship', 'sample' => 'Income Account is', - ), - ), - 'CRM_Financial_DAO_FinancialItem' => array( - array( + ], + ], + 'CRM_Financial_DAO_FinancialItem' => [ + [ 'fieldName' => 'status_id', 'sample' => 'Partially paid', - ), - array( + ], + [ 'fieldName' => 'financial_account_id', 'sample' => 'Accounts Receivable', - ), - array( + ], + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - ), - 'CRM_Financial_DAO_FinancialTrxn' => array( - array( + ], + ], + 'CRM_Financial_DAO_FinancialTrxn' => [ + [ 'fieldName' => 'from_financial_account_id', 'sample' => 'Accounts Receivable', - ), - array( + ], + [ 'fieldName' => 'to_financial_account_id', 'sample' => 'Accounts Receivable', - ), - array( + ], + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'payment_instrument_id', 'sample' => 'Check', - ), - ), - 'CRM_Financial_DAO_FinancialAccount' => array( - array( + ], + ], + 'CRM_Financial_DAO_FinancialAccount' => [ + [ 'fieldName' => 'financial_account_type_id', 'sample' => 'Cost of Sales', - ), - ), - 'CRM_Financial_DAO_PaymentProcessor' => array( - array( + ], + ], + 'CRM_Financial_DAO_PaymentProcessor' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Financial_BAO_PaymentProcessorType' => array( - array( + ], + ], + 'CRM_Financial_BAO_PaymentProcessorType' => [ + [ 'fieldName' => 'billing_mode', 'sample' => 'form', - ), - ), - 'CRM_Core_DAO_UFField' => array( - array( + ], + ], + 'CRM_Core_DAO_UFField' => [ + [ 'fieldName' => 'uf_group_id', 'sample' => 'Name and Address', - ), - array( + ], + [ 'fieldName' => 'visibility', 'sample' => 'Expose Publicly', - ), - ), - 'CRM_Core_DAO_UFJoin' => array( - array( + ], + ], + 'CRM_Core_DAO_UFJoin' => [ + [ 'fieldName' => 'uf_group_id', 'sample' => 'Name and Address', - ), - ), - 'CRM_Core_DAO_UFMatch' => array( - array( + ], + ], + 'CRM_Core_DAO_UFMatch' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Core_DAO_Job' => array( - array( + ], + ], + 'CRM_Core_DAO_Job' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - array( + ], + [ 'fieldName' => 'run_frequency', 'sample' => 'Daily', - ), - ), - 'CRM_Core_DAO_JobLog' => array( - array( + ], + ], + 'CRM_Core_DAO_JobLog' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Contribute_DAO_ContributionSoft' => array( - array( + ], + ], + 'CRM_Contribute_DAO_ContributionSoft' => [ + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'soft_credit_type_id', 'sample' => 'In Honor of', - ), - ), - 'CRM_Contribute_DAO_Product' => array( - array( + ], + ], + 'CRM_Contribute_DAO_Product' => [ + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'period_type', 'sample' => 'Rolling', - ), - array( + ], + [ 'fieldName' => 'duration_unit', 'sample' => 'Day', - ), - array( + ], + [ 'fieldName' => 'frequency_unit', 'sample' => 'Day', - ), - ), - 'CRM_Contribute_DAO_ContributionProduct' => array( - array( + ], + ], + 'CRM_Contribute_DAO_ContributionProduct' => [ + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - ), - 'CRM_Contribute_DAO_ContributionRecur' => array( - array( + ], + ], + 'CRM_Contribute_DAO_ContributionRecur' => [ + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'frequency_unit', 'sample' => 'month', - ), - array( + ], + [ 'fieldName' => 'contribution_status_id', 'sample' => 'Completed', - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'payment_instrument_id', 'sample' => 'Check', - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Pledge_DAO_PledgePayment' => array( - array( + ], + ], + 'CRM_Pledge_DAO_PledgePayment' => [ + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - ), - 'CRM_Pledge_DAO_Pledge' => array( - array( + ], + ], + 'CRM_Pledge_DAO_Pledge' => [ + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'frequency_unit', 'sample' => 'month', - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_PCP_DAO_PCP' => array( - array( + ], + ], + 'CRM_PCP_DAO_PCP' => [ + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'status_id', 'sample' => 'Approved', - ), - ), - 'CRM_Core_DAO_CustomField' => array( - array( + ], + ], + 'CRM_Core_DAO_CustomField' => [ + [ 'fieldName' => 'custom_group_id', 'sample' => $custom_group_name, - ), - array( + ], + [ 'fieldName' => 'data_type', 'sample' => 'Alphanumeric', - ), - array( + ], + [ 'fieldName' => 'html_type', 'sample' => 'Select Date', - ), - ), - 'CRM_Core_DAO_CustomGroup' => array( - array( + ], + ], + 'CRM_Core_DAO_CustomGroup' => [ + [ 'fieldName' => 'style', 'sample' => 'Inline', - ), - ), - 'CRM_Core_DAO_Dashboard' => array( - array( + ], + ], + 'CRM_Core_DAO_Dashboard' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Core_DAO_Tag' => array( - array( + ], + ], + 'CRM_Core_DAO_Tag' => [ + [ 'fieldName' => 'used_for', 'sample' => 'Contacts', - ), - ), - 'CRM_Core_DAO_EntityTag' => array( - array( + ], + ], + 'CRM_Core_DAO_EntityTag' => [ + [ 'fieldName' => 'tag_id', 'sample' => 'Government Entity', - ), - ), - 'CRM_Core_DAO_Extension' => array( - array( + ], + ], + 'CRM_Core_DAO_Extension' => [ + [ 'fieldName' => 'type', 'sample' => 'Module', - ), - ), - 'CRM_Core_DAO_OptionValue' => array( - array( + ], + ], + 'CRM_Core_DAO_OptionValue' => [ + [ 'fieldName' => 'option_group_id', 'sample' => 'gender', 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'component_id', 'sample' => 'CiviContribute', - ), - array( + ], + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Core_DAO_MailSettings' => array( - array( + ], + ], + 'CRM_Core_DAO_MailSettings' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - array( + ], + [ 'fieldName' => 'protocol', 'sample' => 'Localdir', - ), - ), - 'CRM_Core_DAO_Managed' => array( - array( + ], + ], + 'CRM_Core_DAO_Managed' => [ + [ 'fieldName' => 'cleanup', 'sample' => 'Always', - ), - ), - 'CRM_Core_DAO_Mapping' => array( - array( + ], + ], + 'CRM_Core_DAO_Mapping' => [ + [ 'fieldName' => 'mapping_type_id', 'sample' => 'Search Builder', - ), - ), - 'CRM_Core_DAO_Navigation' => array( - array( + ], + ], + 'CRM_Core_DAO_Navigation' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Core_DAO_Phone' => array( - array( + ], + ], + 'CRM_Core_DAO_Phone' => [ + [ 'fieldName' => 'phone_type_id', 'sample' => 'Phone', - ), - array( + ], + [ 'fieldName' => 'location_type_id', 'sample' => 'Home', - ), - ), - 'CRM_Core_DAO_PrintLabel' => array( - array( + ], + ], + 'CRM_Core_DAO_PrintLabel' => [ + [ 'fieldName' => 'label_format_name', 'sample' => 'Avery 5395', - ), - array( + ], + [ 'fieldName' => 'label_type_id', 'sample' => 'Event Badge', - ), - ), - 'CRM_Core_DAO_Email' => array( - array( + ], + ], + 'CRM_Core_DAO_Email' => [ + [ 'fieldName' => 'location_type_id', 'sample' => 'Home', - ), - ), - 'CRM_Core_DAO_Address' => array( - array( + ], + ], + 'CRM_Core_DAO_Address' => [ + [ 'fieldName' => 'location_type_id', 'sample' => 'Home', - ), - ), - 'CRM_Core_DAO_Website' => array( - array( + ], + ], + 'CRM_Core_DAO_Website' => [ + [ 'fieldName' => 'website_type_id', 'sample' => 'Facebook', - ), - ), - 'CRM_Core_DAO_WordReplacement' => array( - array( + ], + ], + 'CRM_Core_DAO_WordReplacement' => [ + [ 'fieldName' => 'match_type', 'sample' => 'Exact Match', - ), - array( + ], + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - 'CRM_Core_DAO_MappingField' => array( - array( + ], + ], + 'CRM_Core_DAO_MappingField' => [ + [ 'fieldName' => 'website_type_id', 'sample' => 'Facebook', - ), - array( + ], + [ 'fieldName' => 'im_provider_id', 'sample' => 'Yahoo', - ), - array( + ], + [ 'fieldName' => 'operator', 'sample' => '=', - ), - ), - 'CRM_Contact_DAO_Contact' => array( - array( + ], + ], + 'CRM_Contact_DAO_Contact' => [ + [ 'fieldName' => 'prefix_id', 'sample' => 'Mr.', - ), - array( + ], + [ 'fieldName' => 'suffix_id', 'sample' => 'Sr.', - ), - array( + ], + [ 'fieldName' => 'gender_id', 'sample' => 'Male', - ), - array( + ], + [ 'fieldName' => 'preferred_communication_method', 'sample' => 'Postal Mail', - ), - array( + ], + [ 'fieldName' => 'contact_type', 'sample' => 'Individual', 'exclude' => 'Team', - ), - array( + ], + [ 'fieldName' => 'contact_sub_type', 'sample' => 'Team', 'exclude' => 'Individual', - ), - array( + ], + [ 'fieldName' => 'preferred_language', - 'sample' => array('en_US' => 'English (United States)'), + 'sample' => ['en_US' => 'English (United States)'], 'max' => 250, - ), - array( + ], + [ 'fieldName' => 'preferred_mail_format', 'sample' => 'Text', - ), - array( + ], + [ 'fieldName' => 'communication_style_id', 'sample' => 'Formal', - ), - array( + ], + [ 'fieldName' => "custom_$customFieldId", - 'sample' => array('foo' => 'Foo'), + 'sample' => ['foo' => 'Foo'], 'max' => 1, - ), - ), - 'CRM_Batch_DAO_Batch' => array( - array( + ], + ], + 'CRM_Batch_DAO_Batch' => [ + [ 'fieldName' => 'type_id', 'sample' => 'Membership', - ), - array( + ], + [ 'fieldName' => 'status_id', 'sample' => 'Reopened', - ), - array( + ], + [ 'fieldName' => 'mode_id', 'sample' => 'Automatic Batch', - ), - array( + ], + [ 'fieldName' => 'payment_instrument_id', 'sample' => 'Check', - ), - ), - 'CRM_Core_DAO_IM' => array( - array( + ], + ], + 'CRM_Core_DAO_IM' => [ + [ 'fieldName' => 'provider_id', 'sample' => 'Yahoo', - ), - array( + ], + [ 'fieldName' => 'location_type_id', 'sample' => 'Home', - ), - ), - 'CRM_Event_DAO_Participant' => array( - array( + ], + ], + 'CRM_Event_DAO_Participant' => [ + [ 'fieldName' => 'status_id', 'sample' => 'Registered', - ), - array( + ], + [ 'fieldName' => 'role_id', 'sample' => 'Speaker', - ), - array( + ], + [ 'fieldName' => 'fee_currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Event_DAO_Event' => array( - array( + ], + ], + 'CRM_Event_DAO_Event' => [ + [ 'fieldName' => 'event_type_id', 'sample' => 'Fundraiser', - ), - array( + ], + [ 'fieldName' => 'participant_listing_id', 'sample' => 'Name and Email', - ), - array( + ], + [ 'fieldName' => 'payment_processor', 'sample' => $pp_name, - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'default_role_id', 'sample' => 'Attendee', - ), - array( + ], + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Core_DAO_Menu' => array( - array( + ], + ], + 'CRM_Core_DAO_Menu' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - array( + ], + [ 'fieldName' => 'component_id', 'sample' => 'CiviMember', - ), - ), - 'CRM_Member_DAO_Membership' => array( - array( + ], + ], + 'CRM_Member_DAO_Membership' => [ + [ 'fieldName' => 'membership_type_id', 'sample' => $membership_type, - ), - array( + ], + [ 'fieldName' => 'status_id', 'sample' => 'New', - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Member_DAO_MembershipStatus' => array( - array( + ], + ], + 'CRM_Member_DAO_MembershipStatus' => [ + [ 'fieldName' => 'start_event', 'sample' => 'start date', - ), - array( + ], + [ 'fieldName' => 'end_event', 'sample' => 'member since', - ), - array( + ], + [ 'fieldName' => 'start_event_adjust_unit', 'sample' => 'month', - ), - array( + ], + [ 'fieldName' => 'end_event_adjust_unit', 'sample' => 'year', - ), - ), - 'CRM_Member_DAO_MembershipType' => array( - array( + ], + ], + 'CRM_Member_DAO_MembershipType' => [ + [ 'fieldName' => 'visibility', 'sample' => 'Public', - ), - array( + ], + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'duration_unit', 'sample' => 'lifetime', - ), - array( + ], + [ 'fieldName' => 'period_type', 'sample' => 'Rolling', - ), - ), - 'CRM_Mailing_DAO_Mailing' => array( - array( + ], + ], + 'CRM_Mailing_DAO_Mailing' => [ + [ 'fieldName' => 'approval_status_id', 'sample' => 'Approved', - ), - array( + ], + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - array( + ], + [ 'fieldName' => 'visibility', 'sample' => 'Public Pages', - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Mailing_DAO_MailingComponent' => array( - array( + ], + ], + 'CRM_Mailing_DAO_MailingComponent' => [ + [ 'fieldName' => 'component_type', 'sample' => 'Header', - ), - ), - 'CRM_Mailing_DAO_MailingGroup' => array( - array( + ], + ], + 'CRM_Mailing_DAO_MailingGroup' => [ + [ 'fieldName' => 'group_type', 'sample' => 'Include', - ), - ), - 'CRM_Mailing_DAO_MailingJob' => array( - array( + ], + ], + 'CRM_Mailing_DAO_MailingJob' => [ + [ 'fieldName' => 'status', 'sample' => 'Scheduled', - ), - ), - 'CRM_Mailing_Event_DAO_Bounce' => array( - array( + ], + ], + 'CRM_Mailing_Event_DAO_Bounce' => [ + [ 'fieldName' => 'bounce_type_id', 'sample' => 'Invalid', - ), - ), - 'CRM_Mailing_Event_DAO_Subscribe' => array( - array( + ], + ], + 'CRM_Mailing_Event_DAO_Subscribe' => [ + [ 'fieldName' => 'group_id', 'sample' => $group_name, - ), - ), - 'CRM_Grant_DAO_Grant' => array( - array( + ], + ], + 'CRM_Grant_DAO_Grant' => [ + [ 'fieldName' => 'status_id', 'sample' => 'Approved for Payment', - ), - array( + ], + [ 'fieldName' => 'grant_type_id', 'sample' => 'Emergency', - ), - array( + ], + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - ), - 'CRM_Contribute_DAO_Contribution' => array( - array( + ], + ], + 'CRM_Contribute_DAO_Contribution' => [ + [ 'fieldName' => 'payment_instrument_id', 'sample' => 'Credit Card', - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'contribution_status_id', 'sample' => 'Completed', - ), - array( + ], + [ 'fieldName' => 'contribution_page_id', 'sample' => $contribution_page, - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Contribute_DAO_PremiumsProduct' => array( - array( + ], + ], + 'CRM_Contribute_DAO_PremiumsProduct' => [ + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - ), - 'CRM_Contribute_DAO_ContributionPage' => array( - array( + ], + ], + 'CRM_Contribute_DAO_ContributionPage' => [ + [ 'fieldName' => 'payment_processor', 'sample' => $pp_name, - ), - array( + ], + [ 'fieldName' => 'financial_type_id', 'sample' => 'Donation', - ), - array( + ], + [ 'fieldName' => 'currency', - 'sample' => array('USD' => 'US Dollar'), + 'sample' => ['USD' => 'US Dollar'], 'max' => 200, - ), - array( + ], + [ 'fieldName' => 'campaign_id', 'sample' => $campaign_name, - ), - ), - 'CRM_Case_DAO_Case' => array( - array( + ], + ], + 'CRM_Case_DAO_Case' => [ + [ 'fieldName' => 'status_id', 'sample' => 'Ongoing', - ), - array( + ], + [ 'fieldName' => 'case_type_id', 'sample' => 'Housing Support', - ), - ), - 'CRM_Report_DAO_ReportInstance' => array( - array( + ], + ], + 'CRM_Report_DAO_ReportInstance' => [ + [ 'fieldName' => 'domain_id', 'sample' => 'Default Domain Name', - ), - ), - ); + ], + ], + ]; foreach ($fields as $daoName => $daoFields) { foreach ($daoFields as $field) { @@ -1063,42 +1063,42 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { } public function testContactTypes() { - $byName = array( + $byName = [ 'Individual' => 'Individual', 'Household' => 'Household', 'Organization' => 'Organization', - ); - $byId = array( + ]; + $byId = [ 1 => 'Individual', 2 => 'Household', 3 => 'Organization', - ); + ]; // By default this should return an array keyed by name $result = CRM_Contact_DAO_Contact::buildOptions('contact_type'); $this->assertEquals($byName, $result); // But we can also fetch by ID - $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', array( + $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', [ 'keyColumn' => 'id', 'labelColumn' => 'name', - )); + ]); $this->assertEquals($byId, $result); // Make sure flip param works - $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', array( + $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', [ 'keyColumn' => 'id', 'labelColumn' => 'name', 'flip' => TRUE, - )); + ]); $this->assertEquals(array_flip($byId), $result); } public function testGetTaxRates() { $contact = $this->createLoggedInUser(); - $financialType = $this->callAPISuccess('financial_type', 'create', array( + $financialType = $this->callAPISuccess('financial_type', 'create', [ 'name' => 'Test taxable financial Type', 'is_reserved' => 0, 'is_active' => 1, - )); - $financialAccount = $this->callAPISuccess('financial_account', 'create', array( + ]); + $financialAccount = $this->callAPISuccess('financial_account', 'create', [ 'name' => 'Test Tax financial account ', 'contact_id' => $contact, 'financial_account_type_id' => 2, @@ -1107,15 +1107,15 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0, - )); + ]); $financialTypeId = $financialType['id']; $financialAccountId = $financialAccount['id']; - $financialAccountParams = array( + $financialAccountParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialTypeId, 'account_relationship' => 10, 'financial_account_id' => $financialAccountId, - ); + ]; CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams); $taxRates = CRM_Core_PseudoConstant::getTaxRates(); $this->assertEquals('5.00', $taxRates[$financialType['id']]); diff --git a/tests/phpunit/CRM/Core/RegionTest.php b/tests/phpunit/CRM/Core/RegionTest.php index b4ed3894ed..406dd6ba38 100644 --- a/tests/phpunit/CRM/Core/RegionTest.php +++ b/tests/phpunit/CRM/Core/RegionTest.php @@ -42,12 +42,12 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Disable the normal content of a {crmRegion} and apply different content from a snippet */ public function testOverride() { - CRM_Core_Region::instance('testOverride')->update('default', array( + CRM_Core_Region::instance('testOverride')->update('default', [ 'disabled' => TRUE, - )); - CRM_Core_Region::instance('testOverride')->add(array( + ]); + CRM_Core_Region::instance('testOverride')->add([ 'markup' => 'override
', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testOverride}default
{/crmRegion}'); @@ -59,46 +59,46 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Test that each of the major content formats are correctly evaluated. */ public function testAllTypes() { - CRM_Core_Region::instance('testAllTypes')->add(array( + CRM_Core_Region::instance('testAllTypes')->add([ 'markup' => 'some-markup
', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: 'template' would normally be a file name 'template' => 'string:smarty-is-{$snippet.extrainfo}
', 'extrainfo' => 'dynamic', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: returns a value which gets appended to the region 'callback' => 'implode', - 'arguments' => array('-', array('callback', 'with', 'specific', 'args
')), - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + 'arguments' => ['-', ['callback', 'with', 'specific', 'args
']], + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: returns a value which gets appended to the region 'callback' => function(&$spec, &$html) { return "callback-return
"; }, - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: returns void; directly modifies region's $html 'callback' => function(&$spec, &$html) { $html = "callback-ref
" . $html; }, - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'scriptUrl' => '/foo%20bar.js', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'script' => 'alert("hi");', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'jquery' => '$("div");', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'styleUrl' => '/foo%20bar.css', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'style' => 'body { background: black; }', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testAllTypes}default
{/crmRegion}'); @@ -120,23 +120,23 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Test of nested arrangement in which one {crmRegion} directly includes another {crmRegion} */ public function testDirectNest() { - CRM_Core_Region::instance('testDirectNestOuter')->add(array( + CRM_Core_Region::instance('testDirectNestOuter')->add([ 'template' => 'string:O={$snippet.weight} ', 'weight' => -5, - )); - CRM_Core_Region::instance('testDirectNestOuter')->add(array( + ]); + CRM_Core_Region::instance('testDirectNestOuter')->add([ 'template' => 'string:O={$snippet.weight} ', 'weight' => 5, - )); + ]); - CRM_Core_Region::instance('testDirectNestInner')->add(array( + CRM_Core_Region::instance('testDirectNestInner')->add([ 'template' => 'string:I={$snippet.weight} ', 'weight' => -5, - )); - CRM_Core_Region::instance('testDirectNestInner')->add(array( + ]); + CRM_Core_Region::instance('testDirectNestInner')->add([ 'template' => 'string:I={$snippet.weight} ', 'weight' => 5, - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testDirectNestOuter}left {crmRegion name=testDirectNestInner}middle {/crmRegion}right {/crmRegion}'); @@ -148,15 +148,15 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Test of nested arrangement in which one {crmRegion} is enhanced with a snippet which, in turn, includes another {crmRegion} */ public function testIndirectNest() { - CRM_Core_Region::instance('testIndirectNestOuter')->add(array( + CRM_Core_Region::instance('testIndirectNestOuter')->add([ // Note: all three $snippet references are bound to the $snippet which caused this template to be included, // regardless of any nested {crmRegion}s 'template' => 'string: O={$snippet.region}{crmRegion name=testIndirectNestInner} O={$snippet.region}{/crmRegion} O={$snippet.region}', - )); + ]); - CRM_Core_Region::instance('testIndirectNestInner')->add(array( + CRM_Core_Region::instance('testIndirectNestInner')->add([ 'template' => 'string: I={$snippet.region}', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testIndirectNestOuter}default{/crmRegion}'); @@ -168,14 +168,14 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Output from an inner-region should not be executed verbatim; this is obvious but good to verify */ public function testNoInjection() { - CRM_Core_Region::instance('testNoInjectionOuter')->add(array( + CRM_Core_Region::instance('testNoInjectionOuter')->add([ 'template' => 'string:{$snippet.scarystuff} ', 'scarystuff' => '{$is_outer_scary}', - )); - CRM_Core_Region::instance('testNoInjectionInner')->add(array( + ]); + CRM_Core_Region::instance('testNoInjectionInner')->add([ 'template' => 'string:{$snippet.scarystuff} ', 'scarystuff' => '{$is_inner_scary}', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('is_outer_scary', 'egad'); @@ -193,14 +193,14 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { public function testSmartyVars() { $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('extrainfo', 'one'); - CRM_Core_Region::instance('testSmartyVars')->add(array( + CRM_Core_Region::instance('testSmartyVars')->add([ 'template' => 'string:var-style-{$extrainfo}
', - )); + ]); - CRM_Core_Region::instance('testSmartyVars')->add(array( + CRM_Core_Region::instance('testSmartyVars')->add([ 'template' => 'string:var-style-{$snippet.extrainfo}
', 'extrainfo' => 'two', - )); + ]); $actual = $smarty->fetch('string:{crmRegion name=testSmartyVars}default
{/crmRegion}'); $expected = 'default
var-style-one
var-style-two
'; @@ -208,22 +208,22 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { } public function testWeight() { - CRM_Core_Region::instance('testWeight')->add(array( + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'prepend-5
', 'weight' => -5, - )); - CRM_Core_Region::instance('testWeight')->add(array( + ]); + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'append+3
', 'weight' => 3, - )); - CRM_Core_Region::instance('testWeight')->add(array( + ]); + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'prepend-3
', 'weight' => -3, - )); - CRM_Core_Region::instance('testWeight')->add(array( + ]); + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'append+5
', 'weight' => 5, - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testWeight}default
{/crmRegion}'); diff --git a/tests/phpunit/CRM/Core/Resources/StringsTest.php b/tests/phpunit/CRM/Core/Resources/StringsTest.php index 667e4dffbd..782de6d352 100644 --- a/tests/phpunit/CRM/Core/Resources/StringsTest.php +++ b/tests/phpunit/CRM/Core/Resources/StringsTest.php @@ -40,11 +40,11 @@ class CRM_Core_Resources_StringsTest extends CiviUnitTestCase { new CRM_Utils_Cache_Arraycache(NULL) ); $this->assertEquals( - array('Hello from Javascript'), + ['Hello from Javascript'], $strings->get('example', "$basedir/hello.js", "text/javascript") ); $this->assertEquals( - array('Hello from HTML'), + ['Hello from HTML'], $strings->get('example', "$basedir/hello.html", "text/html") ); } diff --git a/tests/phpunit/CRM/Core/ResourcesTest.php b/tests/phpunit/CRM/Core/ResourcesTest.php index 55b2c7197f..a00a9ca67a 100644 --- a/tests/phpunit/CRM/Core/ResourcesTest.php +++ b/tests/phpunit/CRM/Core/ResourcesTest.php @@ -53,7 +53,7 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { parent::setUp(); list ($this->basedir, $this->container, $this->mapper) = $this->_createMapper(); - $cache = new CRM_Utils_Cache_Arraycache(array()); + $cache = new CRM_Utils_Cache_Arraycache([]); $this->res = new CRM_Core_Resources($this->mapper, $cache, NULL); $this->res->setCacheCode('resTest'); CRM_Core_Resources::singleton($this->res); @@ -138,34 +138,34 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { public function testAddVars() { $this->res - ->addVars('food', array('fruit' => array('mine' => 'apple', 'ours' => 'banana'))) - ->addVars('food', array('fruit' => array('mine' => 'new apple', 'yours' => 'orange'))); + ->addVars('food', ['fruit' => ['mine' => 'apple', 'ours' => 'banana']]) + ->addVars('food', ['fruit' => ['mine' => 'new apple', 'yours' => 'orange']]); $this->assertTreeEquals( - array( - 'vars' => array( - 'food' => array( - 'fruit' => array( + [ + 'vars' => [ + 'food' => [ + 'fruit' => [ 'yours' => 'orange', 'mine' => 'new apple', 'ours' => 'banana', - ), - ), - ), - ), + ], + ], + ], + ], $this->res->getSettings() ); } public function testAddSetting() { $this->res - ->addSetting(array('fruit' => array('mine' => 'apple'))) - ->addSetting(array('fruit' => array('yours' => 'orange'))); + ->addSetting(['fruit' => ['mine' => 'apple']]) + ->addSetting(['fruit' => ['yours' => 'orange']]); $this->assertTreeEquals( - array('fruit' => array('yours' => 'orange', 'mine' => 'apple')), + ['fruit' => ['yours' => 'orange', 'mine' => 'apple']], $this->res->getSettings() ); $actual = $this->res->renderSetting(); - $expected = json_encode(array('fruit' => array('yours' => 'orange', 'mine' => 'apple'))); + $expected = json_encode(['fruit' => ['yours' => 'orange', 'mine' => 'apple']]); $this->assertTrue(strpos($actual, $expected) !== FALSE); } @@ -175,40 +175,40 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { $test->assertEquals('apple', $event->data['fruit']['mine']); $event->data['fruit']['mine'] = 'banana'; }); - $this->res->addSetting(array('fruit' => array('mine' => 'apple'))); + $this->res->addSetting(['fruit' => ['mine' => 'apple']]); $settings = $this->res->getSettings(); - $this->assertTreeEquals(array('fruit' => array('mine' => 'banana')), $settings); + $this->assertTreeEquals(['fruit' => ['mine' => 'banana']], $settings); } public function testAddSettingFactory() { $this->res->addSettingsFactory(function () { - return array('fruit' => array('yours' => 'orange')); + return ['fruit' => ['yours' => 'orange']]; }); $this->res->addSettingsFactory(function () { - return array('fruit' => array('mine' => 'apple')); + return ['fruit' => ['mine' => 'apple']]; }); $actual = $this->res->getSettings(); - $expected = array('fruit' => array('yours' => 'orange', 'mine' => 'apple')); + $expected = ['fruit' => ['yours' => 'orange', 'mine' => 'apple']]; $this->assertTreeEquals($expected, $actual); } public function testAddSettingAndSettingFactory() { - $this->res->addSetting(array('fruit' => array('mine' => 'apple'))); + $this->res->addSetting(['fruit' => ['mine' => 'apple']]); - $muckableValue = array('fruit' => array('yours' => 'orange', 'theirs' => 'apricot')); + $muckableValue = ['fruit' => ['yours' => 'orange', 'theirs' => 'apricot']]; $this->res->addSettingsFactory(function () use (&$muckableValue) { return $muckableValue; }); $actual = $this->res->getSettings(); - $expected = array('fruit' => array('mine' => 'apple', 'yours' => 'orange', 'theirs' => 'apricot')); + $expected = ['fruit' => ['mine' => 'apple', 'yours' => 'orange', 'theirs' => 'apricot']]; $this->assertTreeEquals($expected, $actual); // note: the setting is not fixed based on what the factory returns when registered; it's based // on what the factory returns when getSettings is called - $muckableValue = array('fruit' => array('yours' => 'banana')); + $muckableValue = ['fruit' => ['yours' => 'banana']]; $actual = $this->res->getSettings(); - $expected = array('fruit' => array('mine' => 'apple', 'yours' => 'banana')); + $expected = ['fruit' => ['mine' => 'apple', 'yours' => 'banana']]; $this->assertTreeEquals($expected, $actual); } @@ -325,16 +325,16 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { public function testGlob() { $this->assertEquals( - array('info.xml'), + ['info.xml'], $this->res->glob('com.example.ext', 'info.xml') ); $this->assertEquals( - array('js/example.js'), + ['js/example.js'], $this->res->glob('com.example.ext', 'js/*.js') ); $this->assertEquals( - array('js/example.js'), - $this->res->glob('com.example.ext', array('js/*.js')) + ['js/example.js'], + $this->res->glob('com.example.ext', ['js/*.js']) ); } @@ -347,14 +347,14 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { } public function ajaxModeData() { - return array( - array(array('q' => 'civicrm/ajax/foo'), TRUE), - array(array('q' => 'civicrm/angularprofiles/template'), TRUE), - array(array('q' => 'civicrm/asset/builder'), TRUE), - array(array('q' => 'civicrm/test/page'), FALSE), - array(array('q' => 'civicrm/test/page', 'snippet' => 'json'), TRUE), - array(array('q' => 'civicrm/test/page', 'snippet' => 'foo'), FALSE), - ); + return [ + [['q' => 'civicrm/ajax/foo'], TRUE], + [['q' => 'civicrm/angularprofiles/template'], TRUE], + [['q' => 'civicrm/asset/builder'], TRUE], + [['q' => 'civicrm/test/page'], FALSE], + [['q' => 'civicrm/test/page', 'snippet' => 'json'], TRUE], + [['q' => 'civicrm/test/page', 'snippet' => 'foo'], FALSE], + ]; } /** @@ -373,7 +373,7 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { // not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", "cacheBusterString, - ), - array( + ], + [ 'www.civicrm.org/custom.css?foo=bar', 'www.civicrm.org/custom.css?foo=bar&r=' . $this->cacheBusterString, - ), - array( + ], + [ 'civicrm.org/custom.css?car=blue&foo=bar', 'civicrm.org/custom.css?car=blue&foo=bar&r=' . $this->cacheBusterString, - ), - ); + ], + ]; } /** diff --git a/tests/phpunit/CRM/Core/Smarty/plugins/CrmScopeTest.php b/tests/phpunit/CRM/Core/Smarty/plugins/CrmScopeTest.php index 54ac3a2e8d..e5da6d0ec3 100644 --- a/tests/phpunit/CRM/Core/Smarty/plugins/CrmScopeTest.php +++ b/tests/phpunit/CRM/Core/Smarty/plugins/CrmScopeTest.php @@ -19,23 +19,23 @@ class CRM_Core_Smarty_plugins_CrmScopeTest extends CiviUnitTestCase { * @return array */ public function scopeCases() { - $cases = array(); - $cases[] = array('', '{crmScope}{/crmScope}'); - $cases[] = array('', '{crmScope x=1}{/crmScope}'); - $cases[] = array('x=', 'x={$x}'); - $cases[] = array('x=1', '{crmScope x=1}x={$x}{/crmScope}'); - $cases[] = array('x=1', '{$x}{crmScope x=1}x={$x}{/crmScope}{$x}'); - $cases[] = array('x=1 x=2 x=1', '{crmScope x=1}x={$x} {crmScope x=2}x={$x}{/crmScope} x={$x}{/crmScope}'); - $cases[] = array( + $cases = []; + $cases[] = ['', '{crmScope}{/crmScope}']; + $cases[] = ['', '{crmScope x=1}{/crmScope}']; + $cases[] = ['x=', 'x={$x}']; + $cases[] = ['x=1', '{crmScope x=1}x={$x}{/crmScope}']; + $cases[] = ['x=1', '{$x}{crmScope x=1}x={$x}{/crmScope}{$x}']; + $cases[] = ['x=1 x=2 x=1', '{crmScope x=1}x={$x} {crmScope x=2}x={$x}{/crmScope} x={$x}{/crmScope}']; + $cases[] = [ 'x=1 x=2 x=3 x=2 x=1', '{crmScope x=1}x={$x} {crmScope x=2}x={$x} {crmScope x=3}x={$x}{/crmScope} x={$x}{/crmScope} x={$x}{/crmScope}', - ); - $cases[] = array('x=1,y=9', '{crmScope x=1 y=9}x={$x},y={$y}{/crmScope}'); - $cases[] = array( + ]; + $cases[] = ['x=1,y=9', '{crmScope x=1 y=9}x={$x},y={$y}{/crmScope}']; + $cases[] = [ 'x=1,y=9 x=1,y=8 x=1,y=9', '{crmScope x=1 y=9}x={$x},y={$y} {crmScope y=8}x={$x},y={$y}{/crmScope} x={$x},y={$y}{/crmScope}', - ); - $cases[] = array('x=', 'x={$x}'); + ]; + $cases[] = ['x=', 'x={$x}']; return $cases; } diff --git a/tests/phpunit/CRM/Core/TransactionTest.php b/tests/phpunit/CRM/Core/TransactionTest.php index 5836f791bb..9df2b95107 100644 --- a/tests/phpunit/CRM/Core/TransactionTest.php +++ b/tests/phpunit/CRM/Core/TransactionTest.php @@ -20,31 +20,31 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->quickCleanup(array('civicrm_contact', 'civicrm_activity')); - $this->callbackLog = array(); - $this->cids = array(); + $this->quickCleanup(['civicrm_contact', 'civicrm_activity']); + $this->callbackLog = []; + $this->cids = []; } /** * @return array */ public function dataCreateStyle() { - return array( - array('sql-insert'), - array('bao-create'), - ); + return [ + ['sql-insert'], + ['bao-create'], + ]; } /** * @return array */ public function dataCreateAndCommitStyles() { - return array( - array('sql-insert', 'implicit-commit'), - array('sql-insert', 'explicit-commit'), - array('bao-create', 'implicit-commit'), - array('bao-create', 'explicit-commit'), - ); + return [ + ['sql-insert', 'implicit-commit'], + ['sql-insert', 'explicit-commit'], + ['bao-create', 'implicit-commit'], + ['bao-create', 'explicit-commit'], + ]; } /** @@ -57,7 +57,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function testBasicCommit($createStyle, $commitStyle) { $this->createContactWithTransaction('reuse-tx', $createStyle, $commitStyle); $this->assertCount(1, $this->cids); - $this->assertContactsExistByOffset(array(0 => TRUE)); + $this->assertContactsExistByOffset([0 => TRUE]); } /** @@ -67,7 +67,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function testBasicRollback($createStyle) { $this->createContactWithTransaction('reuse-tx', $createStyle, 'rollback'); $this->assertCount(1, $this->cids); - $this->assertContactsExistByOffset(array(0 => FALSE)); + $this->assertContactsExistByOffset([0 => FALSE]); } /** @@ -83,17 +83,17 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function testBatchRollback($createStyle, $commitStyle) { $this->runBatch( 'reuse-tx', - array( + [ // cid 0 - array('reuse-tx', $createStyle, $commitStyle), + ['reuse-tx', $createStyle, $commitStyle], // cid 1 - array('reuse-tx', $createStyle, $commitStyle), - ), - array(0 => TRUE, 1 => TRUE), + ['reuse-tx', $createStyle, $commitStyle], + ], + [0 => TRUE, 1 => TRUE], 'rollback' ); $this->assertCount(2, $this->cids); - $this->assertContactsExistByOffset(array(0 => FALSE, 1 => FALSE)); + $this->assertContactsExistByOffset([0 => FALSE, 1 => FALSE]); } /** @@ -111,19 +111,19 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function testMixedBatchCommit_nesting($createStyle, $commitStyle) { $this->runBatch( 'reuse-tx', - array( + [ // cid 0 - array('nest-tx', $createStyle, $commitStyle), + ['nest-tx', $createStyle, $commitStyle], // cid 1 - array('nest-tx', $createStyle, 'rollback'), + ['nest-tx', $createStyle, 'rollback'], // cid 2 - array('nest-tx', $createStyle, $commitStyle), - ), - array(0 => TRUE, 1 => FALSE, 2 => TRUE), + ['nest-tx', $createStyle, $commitStyle], + ], + [0 => TRUE, 1 => FALSE, 2 => TRUE], $commitStyle ); $this->assertCount(3, $this->cids); - $this->assertContactsExistByOffset(array(0 => TRUE, 1 => FALSE, 2 => TRUE)); + $this->assertContactsExistByOffset([0 => TRUE, 1 => FALSE, 2 => TRUE]); } /** @@ -141,19 +141,19 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function testMixedBatchCommit_reuse($createStyle, $commitStyle) { $this->runBatch( 'reuse-tx', - array( + [ // cid 0 - array('reuse-tx', $createStyle, $commitStyle), + ['reuse-tx', $createStyle, $commitStyle], // cid 1 - array('reuse-tx', $createStyle, 'rollback'), + ['reuse-tx', $createStyle, 'rollback'], // cid 2 - array('reuse-tx', $createStyle, $commitStyle), - ), - array(0 => TRUE, 1 => TRUE, 2 => TRUE), + ['reuse-tx', $createStyle, $commitStyle], + ], + [0 => TRUE, 1 => TRUE, 2 => TRUE], $commitStyle ); $this->assertCount(3, $this->cids); - $this->assertContactsExistByOffset(array(0 => FALSE, 1 => FALSE, 2 => FALSE)); + $this->assertContactsExistByOffset([0 => FALSE, 1 => FALSE, 2 => FALSE]); } /** @@ -171,20 +171,20 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { $this->assertFalse(CRM_Core_Transaction::isActive()); $this->runBatch( 'reuse-tx', - array( + [ // cid 0 - array('nest-tx', $createStyle, $commitStyle), + ['nest-tx', $createStyle, $commitStyle], // cid 1 - array('nest-tx', $createStyle, 'rollback'), + ['nest-tx', $createStyle, 'rollback'], // cid 2 - array('nest-tx', $createStyle, $commitStyle), - ), - array(0 => TRUE, 1 => FALSE, 2 => TRUE), + ['nest-tx', $createStyle, $commitStyle], + ], + [0 => TRUE, 1 => FALSE, 2 => TRUE], 'rollback' ); $this->assertFalse(CRM_Core_Transaction::isActive()); $this->assertCount(3, $this->cids); - $this->assertContactsExistByOffset(array(0 => FALSE, 1 => FALSE, 2 => FALSE)); + $this->assertContactsExistByOffset([0 => FALSE, 1 => FALSE, 2 => FALSE]); } public function testIsActive() { @@ -218,58 +218,58 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function testCallback_commit() { $tx = new CRM_Core_Transaction(); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, array($this, '_preCommit'), array( + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, [$this, '_preCommit'], [ 'qwe', 'rty', - )); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, array($this, '_postCommit'), array( + ]); + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, [$this, '_postCommit'], [ 'uio', 'p[]', - )); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, array( + ]); + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, [ $this, '_preRollback', - ), array('asd', 'fgh')); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, array( + ], ['asd', 'fgh']); + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, [ $this, '_postRollback', - ), array('jkl', ';')); + ], ['jkl', ';']); CRM_Core_DAO::executeQuery('UPDATE civicrm_contact SET id = 100 WHERE id = 100'); - $this->assertEquals(array(), $this->callbackLog); + $this->assertEquals([], $this->callbackLog); $tx = NULL; - $this->assertEquals(array('_preCommit', 'qwe', 'rty'), $this->callbackLog[0]); - $this->assertEquals(array('_postCommit', 'uio', 'p[]'), $this->callbackLog[1]); + $this->assertEquals(['_preCommit', 'qwe', 'rty'], $this->callbackLog[0]); + $this->assertEquals(['_postCommit', 'uio', 'p[]'], $this->callbackLog[1]); } public function testCallback_rollback() { $tx = new CRM_Core_Transaction(); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, array($this, '_preCommit'), array( + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, [$this, '_preCommit'], [ 'ewq', 'ytr', - )); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, array($this, '_postCommit'), array( + ]); + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, [$this, '_postCommit'], [ 'oiu', '][p', - )); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, array( + ]); + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, [ $this, '_preRollback', - ), array('dsa', 'hgf')); - CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, array( + ], ['dsa', 'hgf']); + CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, [ $this, '_postRollback', - ), array('lkj', ';')); + ], ['lkj', ';']); CRM_Core_DAO::executeQuery('UPDATE civicrm_contact SET id = 100 WHERE id = 100'); $tx->rollback(); - $this->assertEquals(array(), $this->callbackLog); + $this->assertEquals([], $this->callbackLog); $tx = NULL; - $this->assertEquals(array('_preRollback', 'dsa', 'hgf'), $this->callbackLog[0]); - $this->assertEquals(array('_postRollback', 'lkj', ';'), $this->callbackLog[1]); + $this->assertEquals(['_preRollback', 'dsa', 'hgf'], $this->callbackLog[0]); + $this->assertEquals(['_postRollback', 'lkj', ';'], $this->callbackLog[1]); } /** @@ -283,9 +283,9 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { $test = $this; CRM_Core_Transaction::create(TRUE)->run(function ($tx) use (&$test, $createStyle, $commitStyle) { $test->createContactWithTransaction('nest-tx', $createStyle, $commitStyle); - $test->assertContactsExistByOffset(array(0 => TRUE)); + $test->assertContactsExistByOffset([0 => TRUE]); }); - $this->assertContactsExistByOffset(array(0 => TRUE)); + $this->assertContactsExistByOffset([0 => TRUE]); } /** @@ -303,7 +303,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { try { CRM_Core_Transaction::create(TRUE)->run(function ($tx) use (&$test, $createStyle, $commitStyle) { $test->createContactWithTransaction('nest-tx', $createStyle, $commitStyle); - $test->assertContactsExistByOffset(array(0 => TRUE)); + $test->assertContactsExistByOffset([0 => TRUE]); throw new Exception("Ruh-roh"); }); } @@ -314,7 +314,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { } } $this->assertTrue($e instanceof Exception); - $this->assertContactsExistByOffset(array(0 => FALSE)); + $this->assertContactsExistByOffset([0 => FALSE]); } /** @@ -324,9 +324,9 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { public function assertContactsExist($cids, $exist = TRUE) { foreach ($cids as $cid) { $this->assertTrue(is_numeric($cid)); - $this->assertDBQuery($exist ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', array( - 1 => array($cid, 'Integer'), - )); + $this->assertDBQuery($exist ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', [ + 1 => [$cid, 'Integer'], + ]); } } @@ -340,9 +340,9 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { $this->assertTrue(isset($this->cids[$generalOffset + $offset]), "Find cid at offset($generalOffset + $offset)"); $cid = $this->cids[$generalOffset + $offset]; $this->assertTrue(is_numeric($cid)); - $this->assertDBQuery($expectExists ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', array( - 1 => array($cid, 'Integer'), - ), "Check contact at offset($generalOffset + $offset)"); + $this->assertDBQuery($expectExists ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', [ + 1 => [$cid, 'Integer'], + ], "Check contact at offset($generalOffset + $offset)"); } } @@ -377,18 +377,18 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { $cid = $r->getConnection()->lastInsertId(); } elseif ($insert == 'bao-create') { - $params = array( + $params = [ 'contact_type' => 'Individual', 'first_name' => 'FF', 'last_name' => 'LL', - ); + ]; $r = CRM_Contact_BAO_Contact::create($params); $cid = $r->id; } $this->cids[] = $cid; - $this->assertContactsExist(array($cid), TRUE); + $this->assertContactsExist([$cid], TRUE); if ($outcome == 'rollback') { $tx->rollback(); @@ -444,7 +444,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { * @param $arg2 */ public function _preCommit($arg1, $arg2) { - $this->callbackLog[] = array('_preCommit', $arg1, $arg2); + $this->callbackLog[] = ['_preCommit', $arg1, $arg2]; } /** @@ -452,7 +452,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { * @param $arg2 */ public function _postCommit($arg1, $arg2) { - $this->callbackLog[] = array('_postCommit', $arg1, $arg2); + $this->callbackLog[] = ['_postCommit', $arg1, $arg2]; } /** @@ -460,7 +460,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { * @param $arg2 */ public function _preRollback($arg1, $arg2) { - $this->callbackLog[] = array('_preRollback', $arg1, $arg2); + $this->callbackLog[] = ['_preRollback', $arg1, $arg2]; } /** @@ -468,7 +468,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { * @param $arg2 */ public function _postRollback($arg1, $arg2) { - $this->callbackLog[] = array('_postRollback', $arg1, $arg2); + $this->callbackLog[] = ['_postRollback', $arg1, $arg2]; } } diff --git a/tests/phpunit/CRM/Custom/Page/AJAXTest.php b/tests/phpunit/CRM/Custom/Page/AJAXTest.php index d2234f09ab..79b11013c5 100644 --- a/tests/phpunit/CRM/Custom/Page/AJAXTest.php +++ b/tests/phpunit/CRM/Custom/Page/AJAXTest.php @@ -43,18 +43,18 @@ class CRM_Custom_Page_AJAXTest extends CiviUnitTestCase { */ public function testMultiRecordFieldList() { //create multi record custom group - $ids = $this->CustomGroupMultipleCreateWithFields(array('style' => 'Tab with table')); - $params = array( + $ids = $this->CustomGroupMultipleCreateWithFields(['style' => 'Tab with table']); + $params = [ 'contact_type' => 'Individual', 'first_name' => 'Test', 'last_name' => 'Contact', - ); + ]; $customFields = $ids['custom_field_id']; $result = $this->callAPISuccess('contact', 'create', $params); $contactId = $result['id']; //enter values for custom fields - $customParams = array( + $customParams = [ "custom_{$customFields[0]}_-1" => "test value {$customFields[0]} one", "custom_{$customFields[0]}_-2" => "test value {$customFields[0]} two", "custom_{$customFields[0]}_-3" => "test value {$customFields[0]} three", @@ -64,30 +64,30 @@ class CRM_Custom_Page_AJAXTest extends CiviUnitTestCase { "custom_{$customFields[2]}_-1" => "test value {$customFields[2]} one", "custom_{$customFields[2]}_-2" => "test value {$customFields[2]} two", "custom_{$customFields[2]}_-3" => "test value {$customFields[2]} three", - ); + ]; CRM_Core_BAO_CustomValueTable::postProcess($customParams, "civicrm_contact", $contactId, NULL); - $_GET = array( + $_GET = [ 'cid' => $contactId, 'cgid' => $ids['custom_group_id'], 'is_unit_test' => TRUE, - ); + ]; $multiRecordFields = CRM_Custom_Page_AJAX::getMultiRecordFieldList(); //check sorting foreach ($customFields as $fieldId) { $columnName = "field_{$fieldId}{$ids['custom_group_id']}_{$fieldId}"; - $_GET['columns'][] = array( + $_GET['columns'][] = [ 'data' => $columnName, - ); + ]; } // get the results in descending order - $_GET['order'] = array( - '0' => array( + $_GET['order'] = [ + '0' => [ 'column' => 0, 'dir' => 'desc', - ), - ); + ], + ]; $sortedRecords = CRM_Custom_Page_AJAX::getMultiRecordFieldList(); $this->assertEquals(3, $sortedRecords['recordsTotal']); @@ -106,8 +106,8 @@ class CRM_Custom_Page_AJAXTest extends CiviUnitTestCase { $sorted = FALSE; // sorted order result should be two, three, one - $sortedCount = array(1 => 2, 2 => 3, 3 => 1); - foreach (array($multiRecordFields, $sortedRecords) as $records) { + $sortedCount = [1 => 2, 2 => 3, 3 => 1]; + foreach ([$multiRecordFields, $sortedRecords] as $records) { $count = 1; foreach ($records['data'] as $key => $val) { //check links for result sorted in descending order diff --git a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php index 65a728c05c..6dca289540 100644 --- a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php +++ b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php @@ -11,7 +11,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { * * @var array */ - protected $contactIDs = array(); + protected $contactIDs = []; /** * ID of the group holding the contacts. @@ -29,7 +29,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { $this->contactDelete($contactId); } if ($this->groupID) { - $this->callAPISuccess('group', 'delete', array('id' => $this->groupID)); + $this->callAPISuccess('group', 'delete', ['id' => $this->groupID]); } parent::tearDown(); } @@ -52,7 +52,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { // will - dale - will@example.com $this->setupForGroupDedupe(); - $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', array('is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Unsupervised')); + $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', ['is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Unsupervised']); $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); $this->assertEquals(count($foundDupes), 3, 'Check Individual-Fuzzy dupe rule for dupesInGroup().'); @@ -66,16 +66,16 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { public function testCustomRule() { $this->setupForGroupDedupe(); - $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', array( + $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [ 'contact_type' => 'Individual', 'threshold' => 8, 'used' => 'General', 'name' => 'TestRule', 'title' => 'TestRule', 'is_reserved' => 0, - )); + ]); $rules = []; - foreach (array('birth_date', 'first_name', 'last_name') as $field) { + foreach (['birth_date', 'first_name', 'last_name'] as $field) { $rules[$field] = $this->callAPISuccess('Rule', 'create', [ 'dedupe_rule_group_id' => $ruleGroup['id'], 'rule_table' => 'civicrm_contact', @@ -95,16 +95,16 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { public function testCustomRuleWithAddress() { $this->setupForGroupDedupe(); - $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', array( + $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [ 'contact_type' => 'Individual', 'threshold' => 10, 'used' => 'General', 'name' => 'TestRule', 'title' => 'TestRule', 'is_reserved' => 0, - )); + ]); $rules = []; - foreach (array('postal_code') as $field) { + foreach (['postal_code'] as $field) { $rules[$field] = $this->callAPISuccess('Rule', 'create', [ 'dedupe_rule_group_id' => $ruleGroup['id'], 'rule_table' => 'civicrm_address', @@ -125,7 +125,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { */ public function testSupervisedDupes() { $this->setupForGroupDedupe(); - $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', array('is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Supervised')); + $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', ['is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Supervised']); $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); // ------------------------------------------------------------------------- // default dedupe rule: threshold = 20 => (First + Last + Email) Matches ( 1 pair ) @@ -153,62 +153,62 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { // contact data set // FIXME: move create params to separate function - $params = array( - array( + $params = [ + [ 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'robin@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'robin', 'last_name' => 'dale', 'email' => 'robin@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'little', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', - ), - ); + ], + ]; - $this->hookClass->setHook('civicrm_findDuplicates', array($this, 'hook_civicrm_findDuplicates')); + $this->hookClass->setHook('civicrm_findDuplicates', [$this, 'hook_civicrm_findDuplicates']); $count = 1; foreach ($params as $param) { $contact = $this->callAPISuccess('contact', 'create', $param); - $params = array( + $params = [ 'contact_id' => $contact['id'], 'street_address' => 'Ambachtstraat 23', 'location_type_id' => 1, - ); + ]; $this->callAPISuccess('address', 'create', $params); $contactIds[$count++] = $contact['id']; } @@ -216,12 +216,12 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { // verify that all contacts have been created separately $this->assertEquals(count($contactIds), 7, 'Check for number of contacts.'); - $fields = array( + $fields = [ 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'street_address' => 'Ambachtstraat 23', - ); + ]; CRM_Core_TemporaryErrorScope::useException(); $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($fields, 'Individual', 'General', [], TRUE, NULL, ['event_id' => 1]); @@ -271,75 +271,75 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { * Set up a group of dedupable contacts. */ protected function setupForGroupDedupe() { - $params = array( + $params = [ 'name' => 'Dupe Group', 'title' => 'New Test Dupe Group', 'domain_id' => 1, 'is_active' => 1, 'visibility' => 'Public Pages', - ); + ]; $result = $this->callAPISuccess('group', 'create', $params); $this->groupID = $result['id']; - $params = array( - array( + $params = [ + [ 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'robin@example.com', 'contact_type' => 'Individual', 'birth_date' => '2016-01-01', 'api.Address.create' => ['location_type_id' => 'Billing', 'postal_code' => '99999'], - ), - array( + ], + [ 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'contact_type' => 'Individual', 'birth_date' => '2016-01-01', 'api.Address.create' => ['location_type_id' => 'Billing', 'postal_code' => '99999'], - ), - array( + ], + [ 'first_name' => 'robin', 'last_name' => 'dale', 'email' => 'robin@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'little', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', - ), - array( + ], + [ 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', - ), - ); + ], + ]; $count = 1; foreach ($params as $param) { $contact = $this->callAPISuccess('contact', 'create', $param); $this->contactIDs[$count++] = $contact['id']; - $grpParams = array( + $grpParams = [ 'contact_id' => $contact['id'], 'group_id' => $this->groupID, - ); + ]; $this->callAPISuccess('group_contact', 'create', $grpParams); } diff --git a/tests/phpunit/CRM/Event/BAO/EventPermissionsTest.php b/tests/phpunit/CRM/Event/BAO/EventPermissionsTest.php index f42896803e..e6d739b20a 100644 --- a/tests/phpunit/CRM/Event/BAO/EventPermissionsTest.php +++ b/tests/phpunit/CRM/Event/BAO/EventPermissionsTest.php @@ -39,17 +39,17 @@ class CRM_Event_BAO_EventPermissionsTest extends CiviUnitTestCase { } public function createOwnEvent() { - $event = $this->eventCreate(array( + $event = $this->eventCreate([ 'created_id' => $this->_contactId, - )); + ]); $this->_ownEventId = $event['id']; } public function createOtherEvent() { $this->_otherContactId = $this->_contactId + 1; - $event = $this->eventCreate(array( + $event = $this->eventCreate([ 'created_id' => $this->_otherContactId, - )); + ]); $this->_otherEventId = $event['id']; } diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantStatusTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantStatusTest.php index 12c3993da2..0e8b89243f 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantStatusTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantStatusTest.php @@ -54,13 +54,13 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { public function testCreateAndDelete() { // create using required params - $params = array( + $params = [ 'name' => 'testStatus', 'label' => 'testParticipant', 'class' => 'Positive', 'weight' => 13, 'visibility_id' => 1, - ); + ]; $statusType = CRM_Event_BAO_ParticipantStatusType::create($params); // Checking for participant status type id in db. @@ -80,7 +80,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { */ public function testAddStatusType() { - $params = array( + $params = [ 'name' => 'testStatus', 'label' => 'testParticipant', 'class' => 'Positive', @@ -88,7 +88,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { 'is_counted' => 1, 'weight' => 13, 'visibility_id' => 1, - ); + ]; // check for add participant status type $statusType = CRM_Event_BAO_ParticipantStatusType::add($params); @@ -96,7 +96,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { $this->assertEquals($value, $statusType->$param); } - $params = array( + $params = [ 'id' => $statusType->id, 'name' => 'testStatus', 'label' => 'testAlterParticipant', @@ -105,7 +105,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { 'is_counted' => 0, 'weight' => 14, 'visibility_id' => 2, - ); + ]; // check for add participant status type $statusType = CRM_Event_BAO_ParticipantStatusType::add($params); @@ -119,7 +119,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { */ public function testRetrieveStatusType() { - $params = array( + $params = [ 'name' => 'testStatus', 'label' => 'testParticipant', 'class' => 'Positive', @@ -127,13 +127,13 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { 'is_counted' => 1, 'weight' => 13, 'visibility_id' => 1, - ); + ]; $statusType = CRM_Event_BAO_ParticipantStatusType::create($params); // retrieve status type - $retrieveParams = array('id' => $statusType->id); - $default = array(); + $retrieveParams = ['id' => $statusType->id]; + $default = []; $retrieveStatusType = CRM_Event_BAO_ParticipantStatusType::retrieve($retrieveParams, $default); // check on retrieve values @@ -147,7 +147,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { */ public function testSetIsActiveStatusType() { - $params = array( + $params = [ 'name' => 'testStatus', 'label' => 'testParticipant', 'class' => 'Positive', @@ -155,7 +155,7 @@ class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase { 'is_counted' => 1, 'weight' => 15, 'visibility_id' => 1, - ); + ]; $statusType = CRM_Event_BAO_ParticipantStatusType::create($params); $isActive = 1; diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index e08508f132..5960691e87 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -20,12 +20,12 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { */ public function testSubmit() { $event = $this->eventCreate(); - CRM_Event_Form_Registration_Confirm::testSubmit(array( + CRM_Event_Form_Registration_Confirm::testSubmit([ 'id' => $event['id'], 'contributeMode' => 'direct', 'registerByID' => $this->createLoggedInUser(), - 'params' => array( - array( + 'params' => [ + [ 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', 'first_name' => 'k', @@ -34,10 +34,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'hidden_processor' => '1', 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '1', 'Y' => '2019', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'p', 'billing_middle_name' => '', @@ -50,9 +50,9 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'scriptFee' => '', 'scriptArray' => '', 'priceSetId' => '6', - 'price_7' => array( + 'price_7' => [ 13 => 1, - ), + ], 'payment_processor_id' => '1', 'bypass_payment' => '', 'MAX_FILE_SIZE' => '33554432', @@ -72,10 +72,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'button' => '_qf_Register_upload', 'billing_state_province-5' => 'AP', 'billing_country-5' => 'US', - ), - ), - )); - $this->callAPISuccessGetSingle('Participant', array()); + ], + ], + ]); + $this->callAPISuccessGetSingle('Participant', []); } /** @@ -90,17 +90,17 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { public function testPaidSubmit($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); $paymentProcessorID = $this->processorCreate(); - $params = array('is_monetary' => 1, 'financial_type_id' => 1); + $params = ['is_monetary' => 1, 'financial_type_id' => 1]; $event = $this->eventCreate($params); $individualID = $this->individualCreate(); - CRM_Event_Form_Registration_Confirm::testSubmit(array( + CRM_Event_Form_Registration_Confirm::testSubmit([ 'id' => $event['id'], 'contributeMode' => 'direct', 'registerByID' => $individualID, 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), 'totalAmount' => $this->formatMoneyInput(8000.67), - 'params' => array( - array( + 'params' => [ + [ 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', 'first_name' => 'k', @@ -109,10 +109,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'hidden_processor' => '1', 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '1', 'Y' => '2019', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'p', 'billing_middle_name' => '', @@ -125,9 +125,9 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'scriptFee' => '', 'scriptArray' => '', 'priceSetId' => '6', - 'price_7' => array( + 'price_7' => [ 13 => 1, - ), + ], 'payment_processor_id' => $paymentProcessorID, 'bypass_payment' => '', 'MAX_FILE_SIZE' => '33554432', @@ -147,19 +147,19 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'button' => '_qf_Register_upload', 'billing_state_province-5' => 'AP', 'billing_country-5' => 'US', - ), - ), - )); - $this->callAPISuccessGetCount('Participant', array(), 1); - $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + ], + ], + ]); + $this->callAPISuccessGetCount('Participant', [], 1); + $contribution = $this->callAPISuccessGetSingle('Contribution', []); $this->assertEquals(8000.67, $contribution['total_amount']); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('payment_processor_id', 'card_type_id.label', 'pan_truncation'), - ) + 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'], + ] ); $this->assertEquals(CRM_Utils_Array::value('payment_processor_id', $financialTrxn), $paymentProcessorID); $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); @@ -172,16 +172,16 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { * @throws \Exception */ public function testTaxMultipleParticipant() { - $params = array('is_monetary' => 1, 'financial_type_id' => 1); + $params = ['is_monetary' => 1, 'financial_type_id' => 1]; $event = $this->eventCreate($params); - CRM_Event_Form_Registration_Confirm::testSubmit(array( + CRM_Event_Form_Registration_Confirm::testSubmit([ 'id' => $event['id'], 'contributeMode' => 'direct', 'registerByID' => $this->createLoggedInUser(), 'totalAmount' => 440, 'event' => reset($event['values']), - 'params' => array( - array( + 'params' => [ + [ 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", 'first_name' => 'Participant1', @@ -206,8 +206,8 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'invoiceID' => '57adc34957a29171948e8643ce906332', 'trxn_id' => '123456789', 'button' => '_qf_Register_upload', - ), - array( + ], + [ 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", 'first_name' => 'Participant2', @@ -222,8 +222,8 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'amount_level' => 'Tiny-tots (ages 9-18) - 1', 'amount' => '200.00', 'tax_amount' => 20, - ), - array( + ], + [ 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", 'first_name' => 'Participant3', @@ -238,15 +238,15 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'amount_level' => 'Tiny-tots (ages 5-8) - 1', 'amount' => '100.00', 'tax_amount' => 10, - ), - ), - )); - $this->callAPISuccessGetCount('Participant', array(), 3); + ], + ], + ]); + $this->callAPISuccessGetCount('Participant', [], 3); $contribution = $this->callAPISuccessGetSingle( 'Contribution', - array( - 'return' => array('tax_amount', 'total_amount'), - ) + [ + 'return' => ['tax_amount', 'total_amount'], + ] ); $this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.'); $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.'); @@ -256,9 +256,9 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { * Test online registration for event with no price options selected as per CRM-19964. */ public function testOnlineRegNoPrice() { - $paymentProcessorID = $this->processorCreate(array('is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE)); - $paymentProcessorID = $this->processorCreate(array('is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE)); - $params = array( + $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]); + $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]); + $params = [ 'start_date' => date('YmdHis', strtotime('+ 1 week')), 'end_date' => date('YmdHis', strtotime('+ 1 year')), 'registration_start_date' => date('YmdHis', strtotime('- 1 day')), @@ -266,28 +266,28 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'payment_processor_id' => $paymentProcessorID, 'is_monetary' => TRUE, 'financial_type_id' => 'Event Fee', - ); + ]; $event = $this->eventCreate($params); - $priceFieldOptions = array( + $priceFieldOptions = [ 'option_label' => 'Price Field', 'option_value' => 100, 'is_required' => FALSE, 'html_type' => 'Text', - ); + ]; $this->createPriceSet('event', $event['id'], $priceFieldOptions); $priceField = $this->callAPISuccess('PriceField', 'get', - array( + [ 'label' => 'Price Field', - ) + ] ); // Create online event registration. - CRM_Event_Form_Registration_Confirm::testSubmit(array( + CRM_Event_Form_Registration_Confirm::testSubmit([ 'id' => $event['id'], 'contributeMode' => 'direct', 'registerByID' => $this->createLoggedInUser(), - 'params' => array( - array( + 'params' => [ + [ 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", 'first_name' => 'Bruce', @@ -310,10 +310,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'button' => '_qf_Register_upload', 'scriptFee' => '', 'scriptArray' => '', - ), - ), - )); - $contribution = $this->callAPISuccess('Contribution', 'get', array('invoice_id' => '57adc34957a29171948e8643ce906332')); + ], + ], + ]); + $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']); $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected."); } diff --git a/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php b/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php index 260d2d422e..ec91a2cc4a 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php @@ -51,11 +51,11 @@ class CRM_Event_Form_Registration_RegistrationTest extends CiviUnitTestCase { $form->_values['event'] = $event['values'][$event['id']]; $form->_skipDupeRegistrationCheck = 1; - $priceField = $this->callAPISuccess('PriceField', 'get', array('price_set_id' => $priceSetId)); - $params = array( + $priceField = $this->callAPISuccess('PriceField', 'get', ['price_set_id' => $priceSetId]); + $params = [ 'email-Primary' => 'someone@example.com', 'priceSetId' => $priceSetId, - ); + ]; // Check empty values for price fields. foreach (array_keys($priceField['values']) as $fieldId) { $params['price_' . $fieldId] = 0; @@ -63,13 +63,13 @@ class CRM_Event_Form_Registration_RegistrationTest extends CiviUnitTestCase { $form->set('priceSetId', $priceSetId); $form->set('priceSet', $priceSet); $form->set('name', 'CRM_Event_Form_Registration_Register'); - $files = array(); + $files = []; $errors = CRM_Event_Form_Registration_Register::formRule($params, $files, $form); //Assert the validation Error. - $expectedResult = array( - '_qf_default' => ts('A minimum amount of %1 should be selected from Event Fee(s).', array(1 => CRM_Utils_Money::format($minAmt))), - ); + $expectedResult = [ + '_qf_default' => ts('A minimum amount of %1 should be selected from Event Fee(s).', [1 => CRM_Utils_Money::format($minAmt)]), + ]; $this->checkArrayEquals($expectedResult, $errors); } diff --git a/tests/phpunit/CRM/Event/Form/SearchTest.php b/tests/phpunit/CRM/Event/Form/SearchTest.php index d6b22fd439..76f885e958 100644 --- a/tests/phpunit/CRM/Event/Form/SearchTest.php +++ b/tests/phpunit/CRM/Event/Form/SearchTest.php @@ -14,11 +14,11 @@ class CRM_Event_Form_SearchTest extends CiviUnitTestCase { * Test that search form returns correct number of rows for complex regex filters. */ public function testSearch() { - $priceFieldValues = $this->createPriceSet('event', NULL, array( + $priceFieldValues = $this->createPriceSet('event', NULL, [ 'html_type' => 'Radio', - 'option_label' => array('1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'), - 'option_name' => array('1' => 'Radio Label A', '2' => 'Radio Label B'), - )); + 'option_label' => ['1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'], + 'option_name' => ['1' => 'Radio Label A', '2' => 'Radio Label B'], + ]); $priceFieldValues = $priceFieldValues['values']; $participantPrice = NULL; @@ -30,7 +30,7 @@ class CRM_Event_Form_SearchTest extends CiviUnitTestCase { $event = $this->eventCreate(); $individualID = $this->individualCreate(); $today = new DateTime(); - $this->participantCreate(array( + $this->participantCreate([ 'event_id' => $event['id'], 'contact_id' => $individualID, 'status_id' => 1, @@ -38,18 +38,18 @@ class CRM_Event_Form_SearchTest extends CiviUnitTestCase { 'fee_amount' => $participantPrice['amount'], 'fee_currency' => 'USD', 'register_date' => $today->format('YmdHis'), - )); + ]); $form = new CRM_Event_Form_Search(); $form->controller = new CRM_Event_Controller_Search(); $form->preProcess(); - $form->testSubmit(array( + $form->testSubmit([ 'participant_test' => 0, - 'participant_fee_id' => array( + 'participant_fee_id' => [ $participantPrice['id'], - ), + ], 'radio_ts' => 'ts_all', - )); + ]); $rows = $form->controller->get('rows'); $this->assertEquals(1, count($rows), 'Exactly one row should be returned for given price field value.'); } diff --git a/tests/phpunit/CRM/Extension/BrowserTest.php b/tests/phpunit/CRM/Extension/BrowserTest.php index 722bfdf803..fc185355f3 100644 --- a/tests/phpunit/CRM/Extension/BrowserTest.php +++ b/tests/phpunit/CRM/Extension/BrowserTest.php @@ -17,8 +17,8 @@ class CRM_Extension_BrowserTest extends CiviUnitTestCase { public function testDisabled() { $browser = new CRM_Extension_Browser(FALSE, '/index.html', 'file:///itd/oesn/tmat/ter'); $this->assertEquals(FALSE, $browser->isEnabled()); - $this->assertEquals(array(), $browser->checkRequirements()); - $this->assertEquals(array(), $browser->getExtensions()); + $this->assertEquals([], $browser->checkRequirements()); + $this->assertEquals([], $browser->getExtensions()); } public function testCheckRequirements_BadCachedir_false() { @@ -38,11 +38,11 @@ class CRM_Extension_BrowserTest extends CiviUnitTestCase { public function testGetExtensions_good() { $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); $this->assertEquals(TRUE, $browser->isEnabled()); - $this->assertEquals(array(), $browser->checkRequirements()); + $this->assertEquals([], $browser->checkRequirements()); $exts = $browser->getExtensions(); $keys = array_keys($exts); sort($keys); - $this->assertEquals(array('test.crm.extension.browsertest.a', 'test.crm.extension.browsertest.b'), $keys); + $this->assertEquals(['test.crm.extension.browsertest.a', 'test.crm.extension.browsertest.b'], $keys); $this->assertEquals('report', $exts['test.crm.extension.browsertest.a']->type); $this->assertEquals('module', $exts['test.crm.extension.browsertest.b']->type); $this->assertEquals('http://example.com/test.crm.extension.browsertest.a-0.1.zip', $exts['test.crm.extension.browsertest.a']->downloadUrl); @@ -52,7 +52,7 @@ class CRM_Extension_BrowserTest extends CiviUnitTestCase { public function testGetExtension_good() { $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); $this->assertEquals(TRUE, $browser->isEnabled()); - $this->assertEquals(array(), $browser->checkRequirements()); + $this->assertEquals([], $browser->checkRequirements()); $info = $browser->getExtension('test.crm.extension.browsertest.b'); $this->assertEquals('module', $info->type); @@ -62,7 +62,7 @@ class CRM_Extension_BrowserTest extends CiviUnitTestCase { public function testGetExtension_nonexistent() { $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); $this->assertEquals(TRUE, $browser->isEnabled()); - $this->assertEquals(array(), $browser->checkRequirements()); + $this->assertEquals([], $browser->checkRequirements()); $info = $browser->getExtension('test.crm.extension.browsertest.nonexistent'); $this->assertEquals(NULL, $info); diff --git a/tests/phpunit/CRM/Extension/Container/BasicTest.php b/tests/phpunit/CRM/Extension/Container/BasicTest.php index 7bd9ba822c..9efe456055 100644 --- a/tests/phpunit/CRM/Extension/Container/BasicTest.php +++ b/tests/phpunit/CRM/Extension/Container/BasicTest.php @@ -17,12 +17,12 @@ class CRM_Extension_Container_BasicTest extends CiviUnitTestCase { public function testGetKeysEmpty() { $basedir = $this->createTempDir('ext-empty-'); $c = new CRM_Extension_Container_Basic($basedir, 'http://example/basedir', NULL, NULL); - $this->assertEquals($c->getKeys(), array()); + $this->assertEquals($c->getKeys(), []); } public function testGetKeys() { list($basedir, $c) = $this->_createContainer(); - $this->assertEquals($c->getKeys(), array('test.foo', 'test.foo.bar')); + $this->assertEquals($c->getKeys(), ['test.foo', 'test.foo.bar']); } public function testGetPath() { @@ -82,7 +82,7 @@ class CRM_Extension_Container_BasicTest extends CiviUnitTestCase { } public function testCaching() { - $cache = new CRM_Utils_Cache_Arraycache(array()); + $cache = new CRM_Utils_Cache_Arraycache([]); $this->assertTrue(!is_array($cache->get('basic-scan'))); list($basedir, $c) = $this->_createContainer($cache, 'basic-scan'); $this->assertEquals('http://example/basedir/foo', $c->getResUrl('test.foo')); @@ -108,18 +108,18 @@ class CRM_Extension_Container_BasicTest extends CiviUnitTestCase { file_put_contents("$basedir/foo/bar/info.xml", "oddball"); // not needed for now // file_put_contents("$basedir/foo/bar/oddball.php", " 'foo\bar', 'whiz.bang' => 'tests\extensions\whiz\bang', - ); - $expectedRelUrls = array( + ]; + $expectedRelUrls = [ 'foo.bar' => 'foo/bar', 'whiz.bang' => 'tests/extensions/whiz/bang', - ); + ]; $actualRelUrls = CRM_Extension_Container_Basic::convertPathsToUrls('\\', $relPaths); $this->assertEquals($expectedRelUrls, $actualRelUrls); } diff --git a/tests/phpunit/CRM/Extension/Container/CollectionTest.php b/tests/phpunit/CRM/Extension/Container/CollectionTest.php index d79a0a0974..a026dc6b25 100644 --- a/tests/phpunit/CRM/Extension/Container/CollectionTest.php +++ b/tests/phpunit/CRM/Extension/Container/CollectionTest.php @@ -40,19 +40,19 @@ class CRM_Extension_Container_CollectionTest extends CiviUnitTestCase { } public function testGetKeysEmpty() { - $c = new CRM_Extension_Container_Collection(array()); - $this->assertEquals($c->getKeys(), array()); + $c = new CRM_Extension_Container_Collection([]); + $this->assertEquals($c->getKeys(), []); } public function testGetKeys() { $c = $this->_createContainer(); - $this->assertEquals(array( + $this->assertEquals([ 'test.conflict', 'test.whiz', 'test.whizbang', 'test.foo', 'test.foo.bar', - ), $c->getKeys()); + ], $c->getKeys()); } public function testGetPath() { @@ -90,7 +90,7 @@ class CRM_Extension_Container_CollectionTest extends CiviUnitTestCase { } public function testCaching() { - $cache = new CRM_Utils_Cache_Arraycache(array()); + $cache = new CRM_Utils_Cache_Arraycache([]); $this->assertTrue(!is_array($cache->get('ext-collection'))); $c = $this->_createContainer($cache, 'ext-collection'); $this->assertEquals('http://foo', $c->getResUrl('test.foo')); @@ -110,37 +110,37 @@ class CRM_Extension_Container_CollectionTest extends CiviUnitTestCase { * @return CRM_Extension_Container_Collection */ public function _createContainer(CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { - $containers = array(); - $containers['a'] = new CRM_Extension_Container_Static(array( - 'test.foo' => array( + $containers = []; + $containers['a'] = new CRM_Extension_Container_Static([ + 'test.foo' => [ 'path' => '/path/to/foo', 'resUrl' => 'http://foo', - ), - 'test.foo.bar' => array( + ], + 'test.foo.bar' => [ 'path' => '/path/to/bar', 'resUrl' => 'http://foobar', - ), - )); - $containers['b'] = new CRM_Extension_Container_Static(array( - 'test.whiz' => array( + ], + ]); + $containers['b'] = new CRM_Extension_Container_Static([ + 'test.whiz' => [ 'path' => '/path/to/whiz', 'resUrl' => 'http://whiz', - ), - 'test.whizbang' => array( + ], + 'test.whizbang' => [ 'path' => '/path/to/whizbang', 'resUrl' => 'http://whizbang', - ), - 'test.conflict' => array( + ], + 'test.conflict' => [ 'path' => '/path/to/conflict-b', 'resUrl' => 'http://conflict-b', - ), - )); - $containers['c'] = new CRM_Extension_Container_Static(array( - 'test.conflict' => array( + ], + ]); + $containers['c'] = new CRM_Extension_Container_Static([ + 'test.conflict' => [ 'path' => '/path/to/conflict-c', 'resUrl' => 'http://conflict-c', - ), - )); + ], + ]); $c = new CRM_Extension_Container_Collection($containers, $cache, $cacheKey); return $c; } diff --git a/tests/phpunit/CRM/Extension/Container/StaticTest.php b/tests/phpunit/CRM/Extension/Container/StaticTest.php index c5e460d93a..6a5a6835c1 100644 --- a/tests/phpunit/CRM/Extension/Container/StaticTest.php +++ b/tests/phpunit/CRM/Extension/Container/StaticTest.php @@ -15,13 +15,13 @@ class CRM_Extension_Container_StaticTest extends CiviUnitTestCase { } public function testGetKeysEmpty() { - $c = new CRM_Extension_Container_Static(array()); - $this->assertEquals($c->getKeys(), array()); + $c = new CRM_Extension_Container_Static([]); + $this->assertEquals($c->getKeys(), []); } public function testGetKeys() { $c = $this->_createContainer(); - $this->assertEquals($c->getKeys(), array('test.foo', 'test.foo.bar')); + $this->assertEquals($c->getKeys(), ['test.foo', 'test.foo.bar']); } public function testGetPath() { @@ -56,16 +56,16 @@ class CRM_Extension_Container_StaticTest extends CiviUnitTestCase { * @return CRM_Extension_Container_Static */ public function _createContainer() { - return new CRM_Extension_Container_Static(array( - 'test.foo' => array( + return new CRM_Extension_Container_Static([ + 'test.foo' => [ 'path' => '/path/to/foo', 'resUrl' => 'http://foo', - ), - 'test.foo.bar' => array( + ], + 'test.foo.bar' => [ 'path' => '/path/to/bar', 'resUrl' => 'http://foobar', - ), - )); + ], + ]); } } diff --git a/tests/phpunit/CRM/Extension/InfoTest.php b/tests/phpunit/CRM/Extension/InfoTest.php index 492a34b88c..12cfc4c16b 100644 --- a/tests/phpunit/CRM/Extension/InfoTest.php +++ b/tests/phpunit/CRM/Extension/InfoTest.php @@ -50,7 +50,7 @@ class CRM_Extension_InfoTest extends CiviUnitTestCase { $this->assertEquals('test.foo', $info->key); $this->assertEquals('foo', $info->file); $this->assertEquals('zamboni', $info->typeInfo['extra']); - $this->assertEquals(array(), $info->requires); + $this->assertEquals([], $info->requires); } public function testGood_string_extras() { @@ -65,7 +65,7 @@ class CRM_Extension_InfoTest extends CiviUnitTestCase { $this->assertEquals('testbar', $info->file); $this->assertEquals('Civi\\', $info->classloader[0]['prefix']); $this->assertEquals('Civi', $info->classloader[0]['path']); - $this->assertEquals(array('org.civicrm.a', 'org.civicrm.b'), $info->requires); + $this->assertEquals(['org.civicrm.a', 'org.civicrm.b'], $info->requires); } public function testBad_string() { diff --git a/tests/phpunit/CRM/Extension/Manager/ModuleTest.php b/tests/phpunit/CRM/Extension/Manager/ModuleTest.php index a193171490..f9a587d806 100644 --- a/tests/phpunit/CRM/Extension/Manager/ModuleTest.php +++ b/tests/phpunit/CRM/Extension/Manager/ModuleTest.php @@ -11,12 +11,12 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { // $query = "INSERT INTO civicrm_domain ( name, version ) VALUES ( 'domain', 3 )"; // $result = CRM_Core_DAO::executeQuery($query); global $_test_extension_manager_moduletest_counts; - $_test_extension_manager_moduletest_counts = array(); + $_test_extension_manager_moduletest_counts = []; $this->basedir = $this->createTempDir('ext-'); - $this->system = new CRM_Extension_System(array( + $this->system = new CRM_Extension_System([ 'extensionsDir' => $this->basedir, 'extensionsURL' => 'http://testbase/', - )); + ]); $this->setExtensionSystem($this->system); } @@ -32,36 +32,36 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertModuleActiveByName(FALSE, 'moduletest'); - $manager->install(array('test.extension.manager.moduletest')); - $this->assertHookCounts('moduletest', array( + $manager->install(['test.extension.manager.moduletest']); + $this->assertHookCounts('moduletest', [ 'install' => 1, 'postInstall' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(TRUE, 'moduletest'); $this->assertModuleActiveByKey(TRUE, 'test.extension.manager.moduletest'); - $manager->disable(array('test.extension.manager.moduletest')); - $this->assertHookCounts('moduletest', array( + $manager->disable(['test.extension.manager.moduletest']); + $this->assertHookCounts('moduletest', [ 'install' => 1, 'postInstall' => 1, 'enable' => 1, 'disable' => 1, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(FALSE, 'moduletest'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest'); - $manager->uninstall(array('test.extension.manager.moduletest')); - $this->assertHookCounts('moduletest', array( + $manager->uninstall(['test.extension.manager.moduletest']); + $this->assertHookCounts('moduletest', [ 'install' => 1, 'postInstall' => 1, 'enable' => 1, 'disable' => 1, 'uninstall' => 1, - )); + ]); $this->assertModuleActiveByName(FALSE, 'moduletest'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest'); } @@ -74,33 +74,33 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $this->assertModuleActiveByName(FALSE, 'moduletest'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest'); - $manager->install(array('test.extension.manager.moduletest')); - $this->assertHookCounts('moduletest', array( + $manager->install(['test.extension.manager.moduletest']); + $this->assertHookCounts('moduletest', [ 'install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(TRUE, 'moduletest'); $this->assertModuleActiveByKey(TRUE, 'test.extension.manager.moduletest'); - $manager->disable(array('test.extension.manager.moduletest')); - $this->assertHookCounts('moduletest', array( + $manager->disable(['test.extension.manager.moduletest']); + $this->assertHookCounts('moduletest', [ 'install' => 1, 'enable' => 1, 'disable' => 1, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(FALSE, 'moduletest'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest'); - $manager->enable(array('test.extension.manager.moduletest')); - $this->assertHookCounts('moduletest', array( + $manager->enable(['test.extension.manager.moduletest']); + $this->assertHookCounts('moduletest', [ 'install' => 1, 'enable' => 2, 'disable' => 1, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(TRUE, 'moduletest'); $this->assertModuleActiveByKey(TRUE, 'test.extension.manager.moduletest'); } @@ -118,14 +118,14 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto1'); // install it - $manager->install(array('test.extension.manager.module.auto1')); + $manager->install(['test.extension.manager.module.auto1']); $this->assertEquals('installed', $manager->getStatus('test.extension.manager.module.auto1')); - $this->assertHookCounts('test_extension_manager_module_auto1', array( + $this->assertHookCounts('test_extension_manager_module_auto1', [ 'install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(TRUE, 'test_extension_manager_module_auto1'); $this->assertModuleActiveByKey(TRUE, 'test.extension.manager.module.auto1'); @@ -135,27 +135,27 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $this->assertEquals('installed-missing', $manager->getStatus('test.extension.manager.module.auto1')); // disable while missing - $manager->disable(array('test.extension.manager.module.auto1')); + $manager->disable(['test.extension.manager.module.auto1']); $this->assertEquals('disabled-missing', $manager->getStatus('test.extension.manager.module.auto1')); - $this->assertHookCounts('test_extension_manager_module_auto1', array( + $this->assertHookCounts('test_extension_manager_module_auto1', [ 'install' => 1, 'enable' => 1, // normally called -- but not for missing modules! 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto1'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest'); - $manager->uninstall(array('test.extension.manager.module.auto1')); - $this->assertHookCounts('test_extension_manager_module_auto1', array( + $manager->uninstall(['test.extension.manager.module.auto1']); + $this->assertHookCounts('test_extension_manager_module_auto1', [ 'install' => 1, 'enable' => 1, // normally called -- but not for missing modules! 'disable' => 0, // normally called -- but not for missing modules! 'uninstall' => 0, - )); + ]); $this->assertEquals('unknown', $manager->getStatus('test.extension.manager.module.auto1')); $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto1'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto1'); @@ -174,14 +174,14 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto2'); // install it - $manager->install(array('test.extension.manager.module.auto2')); + $manager->install(['test.extension.manager.module.auto2']); $this->assertEquals('installed', $manager->getStatus('test.extension.manager.module.auto2')); - $this->assertHookCounts('test_extension_manager_module_auto2', array( + $this->assertHookCounts('test_extension_manager_module_auto2', [ 'install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(TRUE, 'test_extension_manager_module_auto2'); $this->assertModuleActiveByKey(TRUE, 'test.extension.manager.module.auto2'); @@ -191,27 +191,27 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $this->assertEquals('installed-missing', $manager->getStatus('test.extension.manager.module.auto2')); // disable while missing - $manager->disable(array('test.extension.manager.module.auto2')); + $manager->disable(['test.extension.manager.module.auto2']); $this->assertEquals('disabled-missing', $manager->getStatus('test.extension.manager.module.auto2')); - $this->assertHookCounts('test_extension_manager_module_auto2', array( + $this->assertHookCounts('test_extension_manager_module_auto2', [ 'install' => 1, 'enable' => 1, // normally called -- but not for missing modules! 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest'); // restore the code $this->_createExtension('test.extension.manager.module.auto2', 'module', 'test_extension_manager_module_auto2'); $manager->refresh(); - $this->assertHookCounts('test_extension_manager_module_auto2', array( + $this->assertHookCounts('test_extension_manager_module_auto2', [ 'install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0, - )); + ]); $this->assertEquals('disabled', $manager->getStatus('test.extension.manager.module.auto2')); $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2'); $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto2'); @@ -272,7 +272,7 @@ class CRM_Extension_Manager_ModuleTest extends CiviUnitTestCase { $basedir = $this->basedir; mkdir("$basedir/$key"); file_put_contents("$basedir/$key/info.xml", "$file"); - file_put_contents("$basedir/$key/$file.php", strtr($template, array('_FILE_' => $file))); + file_put_contents("$basedir/$key/$file.php", strtr($template, ['_FILE_' => $file])); $this->system->getCache()->flush(); $this->system->getManager()->refresh(); } diff --git a/tests/phpunit/CRM/Extension/Manager/PaymentTest.php b/tests/phpunit/CRM/Extension/Manager/PaymentTest.php index 12607f9fcb..49696571f1 100644 --- a/tests/phpunit/CRM/Extension/Manager/PaymentTest.php +++ b/tests/phpunit/CRM/Extension/Manager/PaymentTest.php @@ -34,19 +34,19 @@ class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); if (class_exists('test_extension_manager_paymenttest')) { - test_extension_manager_paymenttest::$counts = array(); + test_extension_manager_paymenttest::$counts = []; } - $this->system = new CRM_Extension_System(array( + $this->system = new CRM_Extension_System([ 'extensionsDir' => '', 'extensionsURL' => '', - )); - $this->quickCleanup(array('civicrm_payment_processor')); + ]); + $this->quickCleanup(['civicrm_payment_processor']); } public function tearDown() { parent::tearDown(); $this->system = NULL; - $this->quickCleanup(array('civicrm_payment_processor')); + $this->quickCleanup(['civicrm_payment_processor']); CRM_Core_DAO::executeQuery('DELETE FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); } @@ -56,16 +56,16 @@ class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase { public function testInstallDisableUninstall() { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); - $manager->install(array('test.extension.manager.paymenttest')); + $manager->install(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1'); - $manager->disable(array('test.extension.manager.paymenttest')); + $manager->disable(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0'); - $manager->uninstall(array('test.extension.manager.paymenttest')); + $manager->uninstall(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['uninstall']); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); } @@ -77,16 +77,16 @@ class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); - $manager->install(array('test.extension.manager.paymenttest')); + $manager->install(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1'); - $manager->disable(array('test.extension.manager.paymenttest')); + $manager->disable(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0'); - $manager->enable(array('test.extension.manager.paymenttest')); + $manager->enable(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['enable']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1'); @@ -100,24 +100,24 @@ class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); - $manager->install(array('test.extension.manager.paymenttest')); + $manager->install(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1'); $payment_processor_type_id = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); - $ppDAO = CRM_Financial_BAO_PaymentProcessor::create(array( + $ppDAO = CRM_Financial_BAO_PaymentProcessor::create([ 'payment_processor_type_id' => $payment_processor_type_id, 'domain_id' => CRM_Core_Config::domainID(), - )); + ]); - $manager->disable(array('test.extension.manager.paymenttest')); + $manager->disable(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0'); // first attempt to uninstall -- fail try { - $manager->uninstall(array('test.extension.manager.paymenttest')); + $manager->uninstall(['test.extension.manager.paymenttest']); $this->fail('Failed to catch expected exception'); } catch (CRM_Extension_Exception_DependencyException $e) { @@ -128,7 +128,7 @@ class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase { $ppDAO->delete(); // second attempt to uninstall -- ok - $manager->uninstall(array('test.extension.manager.paymenttest')); + $manager->uninstall(['test.extension.manager.paymenttest']); $this->assertEquals(1, test_extension_manager_paymenttest::getCount('uninstall')); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); } diff --git a/tests/phpunit/CRM/Extension/Manager/ReportTest.php b/tests/phpunit/CRM/Extension/Manager/ReportTest.php index 3d44db92bf..110b505ce9 100644 --- a/tests/phpunit/CRM/Extension/Manager/ReportTest.php +++ b/tests/phpunit/CRM/Extension/Manager/ReportTest.php @@ -11,10 +11,10 @@ class CRM_Extension_Manager_ReportTest extends CiviUnitTestCase { //if (class_exists('test_extension_manager_reporttest')) { // test_extension_manager_reporttest::$counts = array(); //} - $this->system = new CRM_Extension_System(array( + $this->system = new CRM_Extension_System([ 'extensionsDir' => '', 'extensionsURL' => '', - )); + ]); } public function tearDown() { @@ -28,14 +28,14 @@ class CRM_Extension_Manager_ReportTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"'); - $manager->install(array('test.extension.manager.reporttest')); + $manager->install(['test.extension.manager.reporttest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 1'); - $manager->disable(array('test.extension.manager.reporttest')); + $manager->disable(['test.extension.manager.reporttest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 0'); - $manager->uninstall(array('test.extension.manager.reporttest')); + $manager->uninstall(['test.extension.manager.reporttest']); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"'); } @@ -46,14 +46,14 @@ class CRM_Extension_Manager_ReportTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"'); - $manager->install(array('test.extension.manager.reporttest')); + $manager->install(['test.extension.manager.reporttest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 1'); - $manager->disable(array('test.extension.manager.reporttest')); + $manager->disable(['test.extension.manager.reporttest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 0'); - $manager->enable(array('test.extension.manager.reporttest')); + $manager->enable(['test.extension.manager.reporttest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 1'); } diff --git a/tests/phpunit/CRM/Extension/Manager/SearchTest.php b/tests/phpunit/CRM/Extension/Manager/SearchTest.php index d6b28e52eb..1f4e5964c8 100644 --- a/tests/phpunit/CRM/Extension/Manager/SearchTest.php +++ b/tests/phpunit/CRM/Extension/Manager/SearchTest.php @@ -11,10 +11,10 @@ class CRM_Extension_Manager_SearchTest extends CiviUnitTestCase { //if (class_exists('test_extension_manager_searchtest')) { // test_extension_manager_searchtest::$counts = array(); //} - $this->system = new CRM_Extension_System(array( + $this->system = new CRM_Extension_System([ 'extensionsDir' => '', 'extensionsURL' => '', - )); + ]); } public function tearDown() { @@ -29,14 +29,14 @@ class CRM_Extension_Manager_SearchTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"'); - $manager->install(array('test.extension.manager.searchtest')); + $manager->install(['test.extension.manager.searchtest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 1'); - $manager->disable(array('test.extension.manager.searchtest')); + $manager->disable(['test.extension.manager.searchtest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 0'); - $manager->uninstall(array('test.extension.manager.searchtest')); + $manager->uninstall(['test.extension.manager.searchtest']); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"'); } @@ -47,14 +47,14 @@ class CRM_Extension_Manager_SearchTest extends CiviUnitTestCase { $manager = $this->system->getManager(); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"'); - $manager->install(array('test.extension.manager.searchtest')); + $manager->install(['test.extension.manager.searchtest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 1'); - $manager->disable(array('test.extension.manager.searchtest')); + $manager->disable(['test.extension.manager.searchtest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 0'); - $manager->enable(array('test.extension.manager.searchtest')); + $manager->enable(['test.extension.manager.searchtest']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"'); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 1'); } diff --git a/tests/phpunit/CRM/Extension/ManagerTest.php b/tests/phpunit/CRM/Extension/ManagerTest.php index 3cf5b894c1..1c3667f7f0 100644 --- a/tests/phpunit/CRM/Extension/ManagerTest.php +++ b/tests/phpunit/CRM/Extension/ManagerTest.php @@ -53,10 +53,10 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); $testingTypeManager->expects($this->never()) ->method('onPreInstall'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::OTHER_TESTING_TYPE => $testingTypeManager, - )); - $manager->install(array('test.foo.bar')); + ]); + $manager->install(['test.foo.bar']); } /** @@ -69,9 +69,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testInstall_Disable_Uninstall() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); @@ -81,7 +81,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->exactly(2)) ->method('onPostInstall'); - $manager->install(array('test.whiz.bang', 'test.foo.bar')); + $manager->install(['test.whiz.bang', 'test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); @@ -91,7 +91,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostDisable'); - $manager->disable(array('test.foo.bar')); + $manager->disable(['test.foo.bar']); $this->assertEquals('disabled', $manager->getStatus('test.foo.bar')); // no side-effect $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); @@ -102,7 +102,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostUninstall'); - $manager->uninstall(array('test.foo.bar')); + $manager->uninstall(['test.foo.bar']); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); // no side-effect $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); @@ -116,35 +116,35 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function test_InstallAuto_DisableDownstream_UninstallDownstream() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $testingTypeManager->expects($this->exactly(2))->method('onPreInstall'); $testingTypeManager->expects($this->exactly(2))->method('onPostInstall'); - $this->assertEquals(array('test.foo.bar', 'test.foo.downstream'), - $manager->findInstallRequirements(array('test.foo.downstream'))); + $this->assertEquals(['test.foo.bar', 'test.foo.downstream'], + $manager->findInstallRequirements(['test.foo.downstream'])); $manager->install( - $manager->findInstallRequirements(array('test.foo.downstream'))); + $manager->findInstallRequirements(['test.foo.downstream'])); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $testingTypeManager->expects($this->once())->method('onPreDisable'); $testingTypeManager->expects($this->once())->method('onPostDisable'); - $this->assertEquals(array('test.foo.downstream'), - $manager->findDisableRequirements(array('test.foo.downstream'))); - $manager->disable(array('test.foo.downstream')); + $this->assertEquals(['test.foo.downstream'], + $manager->findDisableRequirements(['test.foo.downstream'])); + $manager->disable(['test.foo.downstream']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('disabled', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $testingTypeManager->expects($this->once())->method('onPreUninstall'); $testingTypeManager->expects($this->once())->method('onPostUninstall'); - $manager->uninstall(array('test.foo.downstream')); + $manager->uninstall(['test.foo.downstream']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); @@ -158,19 +158,19 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testInstallAuto_Twice() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $testingTypeManager->expects($this->exactly(2))->method('onPreInstall'); $testingTypeManager->expects($this->exactly(2))->method('onPostInstall'); - $this->assertEquals(array('test.foo.bar', 'test.foo.downstream'), - $manager->findInstallRequirements(array('test.foo.downstream'))); + $this->assertEquals(['test.foo.bar', 'test.foo.downstream'], + $manager->findInstallRequirements(['test.foo.downstream'])); $manager->install( - $manager->findInstallRequirements(array('test.foo.downstream'))); + $manager->findInstallRequirements(['test.foo.downstream'])); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); @@ -179,7 +179,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager->expects($this->exactly(0))->method('onPreInstall'); $testingTypeManager->expects($this->exactly(0))->method('onPostInstall'); $manager->install( - $manager->findInstallRequirements(array('test.foo.downstream'))); + $manager->findInstallRequirements(['test.foo.downstream'])); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); @@ -188,30 +188,30 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function test_InstallAuto_DisableUpstream() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $testingTypeManager->expects($this->exactly(2))->method('onPreInstall'); $testingTypeManager->expects($this->exactly(2))->method('onPostInstall'); - $this->assertEquals(array('test.foo.bar', 'test.foo.downstream'), - $manager->findInstallRequirements(array('test.foo.downstream'))); + $this->assertEquals(['test.foo.bar', 'test.foo.downstream'], + $manager->findInstallRequirements(['test.foo.downstream'])); $manager->install( - $manager->findInstallRequirements(array('test.foo.downstream'))); + $manager->findInstallRequirements(['test.foo.downstream'])); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.foo.downstream')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $testingTypeManager->expects($this->never())->method('onPreDisable'); $testingTypeManager->expects($this->never())->method('onPostDisable'); - $this->assertEquals(array('test.foo.downstream', 'test.foo.bar'), - $manager->findDisableRequirements(array('test.foo.bar'))); + $this->assertEquals(['test.foo.downstream', 'test.foo.bar'], + $manager->findDisableRequirements(['test.foo.bar'])); try { - $manager->disable(array('test.foo.bar')); + $manager->disable(['test.foo.bar']); $this->fail('Expected disable to fail due to dependency'); } catch (CRM_Extension_Exception $e) { @@ -231,12 +231,12 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testInstall_DirtyRemove_Disable_Uninstall() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); - $manager->install(array('test.foo.bar')); + $manager->install(['test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertTrue(file_exists("{$this->basedir}/weird/foobar/info.xml")); @@ -251,7 +251,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostDisable'); - $manager->disable(array('test.foo.bar')); + $manager->disable(['test.foo.bar']); $this->assertEquals('disabled-missing', $manager->getStatus('test.foo.bar')); $testingTypeManager @@ -260,7 +260,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostUninstall'); - $manager->uninstall(array('test.foo.bar')); + $manager->uninstall(['test.foo.bar']); $this->assertEquals('unknown', $manager->getStatus('test.foo.bar')); } @@ -270,9 +270,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testInstall_Disable_Enable() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); @@ -282,7 +282,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->exactly(2)) ->method('onPostInstall'); - $manager->install(array('test.whiz.bang', 'test.foo.bar')); + $manager->install(['test.whiz.bang', 'test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); @@ -292,7 +292,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostDisable'); - $manager->disable(array('test.foo.bar')); + $manager->disable(['test.foo.bar']); $this->assertEquals('disabled', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); @@ -302,7 +302,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostEnable'); - $manager->enable(array('test.foo.bar')); + $manager->enable(['test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); } @@ -313,9 +313,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testInstall_Disable_Install() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $testingTypeManager @@ -324,7 +324,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostInstall'); - $manager->install(array('test.foo.bar')); + $manager->install(['test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); $testingTypeManager @@ -333,7 +333,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager ->expects($this->once()) ->method('onPostDisable'); - $manager->disable(array('test.foo.bar')); + $manager->disable(['test.foo.bar']); $this->assertEquals('disabled', $manager->getStatus('test.foo.bar')); $testingTypeManager @@ -343,7 +343,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { ->expects($this->once()) ->method('onPostEnable'); // install() instead of enable() - $manager->install(array('test.foo.bar')); + $manager->install(['test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); } @@ -353,9 +353,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testEnableBare() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar')); $testingTypeManager @@ -371,7 +371,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { ->expects($this->never()) ->method('onPostEnable'); // enable not install - $manager->enable(array('test.foo.bar')); + $manager->enable(['test.foo.bar']); $this->assertEquals('installed', $manager->getStatus('test.foo.bar')); } @@ -383,9 +383,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); $testingTypeManager->expects($this->never()) ->method('onPreInstall'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('unknown', $manager->getStatus('test.foo.bar.whiz.bang')); } @@ -395,9 +395,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testReplace_Unknown() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('unknown', $manager->getStatus('test.newextension')); $this->download = $this->_createDownload('test.newextension', 'newextension'); @@ -424,9 +424,9 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testReplace_Uninstalled() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $this->assertEquals('oddball', $this->mapper->keyToInfo('test.whiz.bang')->file); @@ -458,13 +458,13 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testReplace_Installed() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); $this->assertEquals('oddball', $this->mapper->keyToInfo('test.whiz.bang')->file); - $manager->install(array('test.whiz.bang')); + $manager->install(['test.whiz.bang']); $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); $this->assertEquals('oddball', $this->mapper->keyToInfo('test.whiz.bang')->file); $this->assertDBQuery('oddball', 'SELECT file FROM civicrm_extension WHERE full_name ="test.whiz.bang"'); @@ -496,13 +496,13 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { public function testReplace_InstalledMissing() { $mockFunction = $this->mockMethod; $testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface'); - $manager = $this->_createManager(array( + $manager = $this->_createManager([ self::TESTING_TYPE => $testingTypeManager, - )); + ]); // initial installation $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang')); - $manager->install(array('test.whiz.bang')); + $manager->install(['test.whiz.bang']); $this->assertEquals('installed', $manager->getStatus('test.whiz.bang')); // dirty remove @@ -559,7 +559,7 @@ class CRM_Extension_ManagerTest extends CiviUnitTestCase { file_put_contents("$basedir/weird/downstream/info.xml", "oddballtest.foo.bar"); // not needed for now // file_put_contents("$basedir/weird/downstream/oddball.php", "basedir => $this->mapper, $this->basedir2 => $this->mapperWithSlash, - ); + ]; foreach ($mappers as $basedir => $mapper) { /** @var CRM_Extension_Mapper $mapper */ - $this->assertEquals(array(), $mapper->getKeysByPath($basedir)); - $this->assertEquals(array(), $mapper->getKeysByPath($basedir . '/weird')); - $this->assertEquals(array(), $mapper->getKeysByPath($basedir . '/weird/')); - $this->assertEquals(array(), $mapper->getKeysByPath($basedir . '/weird//')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/*')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '//*')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/*')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar/')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar//')); - $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar/*')); + $this->assertEquals([], $mapper->getKeysByPath($basedir)); + $this->assertEquals([], $mapper->getKeysByPath($basedir . '/weird')); + $this->assertEquals([], $mapper->getKeysByPath($basedir . '/weird/')); + $this->assertEquals([], $mapper->getKeysByPath($basedir . '/weird//')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/*')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '//*')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/*')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar/')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar//')); + $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar/*')); } } @@ -146,7 +146,7 @@ class CRM_Extension_MapperTest extends CiviUnitTestCase { file_put_contents("$basedir/weird/foobar/info.xml", "oddball"); // not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", " 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); $result = $this->assertDBNotNull( @@ -64,12 +64,12 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Check method retrive() */ public function testRetrieve() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = $defaults = array(); + ]; + $ids = $defaults = []; CRM_Financial_BAO_FinancialAccount::add($params); $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); @@ -81,12 +81,12 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Check method setIsActive() */ public function testSetIsActive() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); $result = CRM_Financial_BAO_FinancialAccount::setIsActive($financialAccount->id, 0); $this->assertEquals($result, TRUE, 'Verify financial account record updation for is_active.'); @@ -105,16 +105,16 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Check method del() */ public function testdel() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); CRM_Financial_BAO_FinancialAccount::del($financialAccount->id); - $params = array('id' => $financialAccount->id); + $params = ['id' => $financialAccount->id]; $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial account record deletion.'); } @@ -123,31 +123,31 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Check method del() */ public function testdelIfHasContribution() { - $params = array( + $params = [ 'name' => 'Donation Test', 'is_active' => 1, 'is_deductible' => 1, 'is_reserved' => 1, - ); + ]; $financialType = CRM_Financial_BAO_FinancialType::add($params); - $defaults = array(); - $params = array( + $defaults = []; + $params = [ 'name' => 'Donation Test', 'is_active' => 1, - ); + ]; $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); $contactId = $this->individualCreate(); - $contributionParams = array( + $contributionParams = [ 'total_amount' => 300, 'currency' => 'USD', 'contact_id' => $contactId, 'financial_type_id' => $financialType->id, 'contribution_status_id' => 1, - ); + ]; $this->callAPISuccess('Contribution', 'create', $contributionParams); CRM_Financial_BAO_FinancialAccount::del($result->id); - $params = array('id' => $result->id); + $params = ['id' => $result->id]; $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); $this->assertEquals(empty($result), FALSE, 'Verify financial account record deletion.'); } @@ -156,13 +156,13 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Check method getAccountingCode() */ public function testGetAccountingCode() { - $params = array( + $params = [ 'name' => 'Donations', 'is_active' => 1, 'is_reserved' => 0, - ); + ]; - $ids = array(); + $ids = []; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); $financialAccountid = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Donations', 'id', 'name'); CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountid, 'accounting_code', '4800'); @@ -195,17 +195,17 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Test getting financial account for a given financial Type with a particular relationship. */ public function testGetFinancialAccountByFinancialTypeAndRelationshipCustomAddedRefunded() { - $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array( + $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', [ 'name' => 'Refund Account', 'is_active' => TRUE, - )); + ]); - $this->callAPISuccess('EntityFinancialAccount', 'create', array( + $this->callAPISuccess('EntityFinancialAccount', 'create', [ 'entity_id' => 2, 'entity_table' => 'civicrm_financial_type', 'account_relationship' => 'Credit/Contra Revenue Account is', 'financial_account_id' => 'Refund Account', - )); + ]); $this->assertEquals($financialAccount['id'], CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(2, 'Credit/Contra Revenue Account is')); } @@ -214,9 +214,9 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Test getting financial account relations for a given financial type. */ public function testGetFinancialAccountRelations() { - $fAccounts = $rAccounts = array(); + $fAccounts = $rAccounts = []; $relations = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations(); - $links = array( + $links = [ 'Expense Account is' => 'Expenses', 'Accounts Receivable Account is' => 'Asset', 'Income Account is' => 'Revenue', @@ -226,7 +226,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { 'Discounts Account is' => 'Revenue', 'Sales Tax Account is' => 'Liability', 'Deferred Revenue Account is' => 'Liability', - ); + ]; $dao = CRM_Core_DAO::executeQuery("SELECT ov.value, ov.name FROM civicrm_option_value ov INNER JOIN civicrm_option_group og ON og.id = ov.option_group_id @@ -280,16 +280,16 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { $valid = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params); $this->assertFalse($valid, "This should have been false"); $cid = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 100, 'financial_type_id' => 4, 'revenue_recognition_date' => date('Ymd', strtotime("+1 month")), - 'line_items' => array( - array( - 'line_item' => array( - array( + 'line_items' => [ + [ + 'line_item' => [ + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 16, @@ -298,8 +298,8 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { 'unit_price' => 100, 'line_total' => 100, 'financial_type_id' => 4, - ), - array( + ], + [ 'entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 17, @@ -308,24 +308,24 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { 'unit_price' => 200, 'line_total' => 200, 'financial_type_id' => 4, - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; try { CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params); } catch (CRM_Core_Exception $e) { $this->fail("Missed expected exception"); } - $params = array( + $params = [ 'contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 100, 'financial_type_id' => 1, 'revenue_recognition_date' => date('Ymd', strtotime("+1 month")), - ); + ]; try { CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params); $this->fail("Missed expected exception"); @@ -341,10 +341,10 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { public function testGetAllDeferredFinancialAccount() { $financialAccount = CRM_Financial_BAO_FinancialAccount::getAllDeferredFinancialAccount(); // The two deferred financial accounts which are created by default. - $expected = array( + $expected = [ "Deferred Revenue - Member Dues (2740)", "Deferred Revenue - Event Fee (2730)", - ); + ]; $this->assertEquals(array_count_values($expected), array_count_values($financialAccount), "The two arrays are not the same"); $this->_createDeferredFinancialAccount(); $financialAccount = CRM_Financial_BAO_FinancialAccount::getAllDeferredFinancialAccount(); @@ -356,11 +356,11 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * CRM-20037: Test balance due amount, if contribution is done using deferred Financial Type */ public function testBalanceDueIfDeferredRevenueEnabled() { - Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1')); + Civi::settings()->set('contribution_invoice_settings', ['deferred_revenue_enabled' => '1']); $deferredFinancialTypeID = $this->_createDeferredFinancialAccount(); $totalAmount = 100.00; - $contribution = $this->callAPISuccess('Contribution', 'create', array( + $contribution = $this->callAPISuccess('Contribution', 'create', [ 'contact_id' => $this->individualCreate(), 'receive_date' => '20120511', 'total_amount' => $totalAmount, @@ -370,7 +370,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { 'net_amount' => 95.00, 'source' => 'SSF', 'contribution_status_id' => 1, - )); + ]); $balance = CRM_Contribute_BAO_Contribution::getContributionBalance($contribution['id'], $totalAmount); $this->assertEquals(0.0, $balance); Civi::settings()->revert('contribution_invoice_settings'); @@ -380,25 +380,25 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { * Helper function to create deferred financial account. */ public function _createDeferredFinancialAccount() { - $params = array( + $params = [ 'name' => 'TestFinancialAccount_1', 'accounting_code' => 4800, 'contact_id' => 1, 'is_deductible' => 0, 'is_active' => 1, 'is_reserved' => 0, - ); + ]; $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', $params); $params['name'] = 'test_financialType1'; $financialType = $this->callAPISuccess('FinancialType', 'create', $params); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' ")); - $financialParams = array( + $financialParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType['id'], 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount['id'], - ); + ]; $this->callAPISuccess('EntityFinancialAccount', 'create', $financialParams); $result = $this->assertDBNotNull( diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialItemTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialItemTest.php index 6217d95b16..fc4d7b31fb 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialItemTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialItemTest.php @@ -65,7 +65,7 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { ]; $contribution = $this->callAPISuccess('Contribution', 'create', $cParams); - $lParams = array( + $lParams = [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'price_field_id' => 1, @@ -75,7 +75,7 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { 'line_total' => $price, 'price_field_value_id' => 1, 'financial_type_id' => 1, - ); + ]; $lineItem = CRM_Price_BAO_LineItem::create($lParams); $contributionObj = $this->getContributionObject($contribution['id']); @@ -112,7 +112,7 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { ]; $contribution = $this->callAPISuccess('Contribution', 'create', $cParams); - $lParams = array( + $lParams = [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'price_field_id' => 1, @@ -122,16 +122,16 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { 'line_total' => $price, 'price_field_value_id' => 1, 'financial_type_id' => 1, - ); + ]; $contributionObj = $this->getContributionObject($contribution['id']); $lineItem = CRM_Price_BAO_LineItem::create($lParams); CRM_Financial_BAO_FinancialItem::add($lineItem, $contributionObj); - $values = array(); - $fParams = array( + $values = []; + $fParams = [ 'entity_id' => $lineItem->id, 'entity_table' => 'civicrm_line_item', - ); + ]; $financialItem = CRM_Financial_BAO_FinancialItem::retrieve($fParams, $values); $this->assertEquals($financialItem->amount, $price, 'Verify financial item amount.'); } @@ -148,16 +148,16 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { $contact = $this->callAPISuccess('Contact', 'create', $params); $price = 100.00; - $cParams = array( + $cParams = [ 'contact_id' => $contact['id'], 'total_amount' => $price, 'financial_type_id' => 1, 'is_active' => 1, 'skipLineItem' => 1, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $cParams); - $lParams = array( + $lParams = [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'price_field_id' => 1, @@ -167,10 +167,10 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { 'line_total' => $price, 'price_field_value_id' => 1, 'financial_type_id' => 1, - ); + ]; $lineItem = CRM_Price_BAO_LineItem::create($lParams); - $fParams = array( + $fParams = [ 'contact_id' => $contact['id'], 'description' => 'Contribution Amount', 'amount' => $price, @@ -179,7 +179,7 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { 'transaction_date' => date('YmdHis'), 'entity_id' => $lineItem->id, 'entity_table' => 'civicrm_line_item', - ); + ]; CRM_Financial_BAO_FinancialItem::create($fParams); $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn(); @@ -213,25 +213,25 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { * Check method del() */ public function testCreateEntityTrxn() { - $fParams = array( + $fParams = [ 'name' => 'Donations' . substr(sha1(rand()), 0, 7), 'is_deductible' => 0, 'is_active' => 1, - ); + ]; $amount = 200; - $ids = array(); + $ids = []; $financialAccount = CRM_Financial_BAO_FinancialAccount::add($fParams, $ids); $financialTrxn = new CRM_Financial_DAO_FinancialTrxn(); $financialTrxn->to_financial_account_id = $financialAccount->id; $financialTrxn->total_amount = $amount; $financialTrxn->save(); - $params = array( + $params = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => 1, 'financial_trxn_id' => $financialTrxn->id, 'amount' => $amount, - ); + ]; $entityTrxn = CRM_Financial_BAO_FinancialItem::createEntityTrxn($params); $entityResult = $this->assertDBNotNull( @@ -250,12 +250,12 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { */ public function testRetrieveEntityFinancialTrxn() { $entityTrxn = self::testCreateEntityTrxn(); - $params = array( + $params = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => 1, 'financial_trxn_id' => $entityTrxn->financial_trxn_id, 'amount' => $entityTrxn->amount, - ); + ]; CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params); $entityResult = $this->assertDBNotNull( @@ -274,7 +274,7 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { public function testGetPreviousFinancialItem() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, @@ -287,18 +287,18 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { 'total_amount' => 100.00, 'trxn_id' => '22ereerwww444444', 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81', - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); - $params = array( + $params = [ 'id' => $contribution['id'], 'total_amount' => 300.00, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $params); $financialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']); - $params = array('id' => $financialItem['id']); + $params = ['id' => $financialItem['id']]; $financialItem = $this->callAPISuccess('FinancialItem', 'get', $params); $this->assertEquals(200.00, $financialItem['values'][$financialItem['id']]['amount'], "The amounts do not match."); } @@ -317,36 +317,36 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase { $this->enableTaxAndInvoicing(); $this->relationForFinancialTypeWithFinancialAccount(1); $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 100, 'financial_type_id' => 1, 'contact_id' => $contactId, 'contribution_status_id' => 1, 'price_set_id' => 0, - ), CRM_Core_Action::ADD); + ], CRM_Core_Action::ADD); $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contact_id' => $contactId, - 'return' => array('id'), - ) + 'return' => ['id'], + ] ); $financialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']); - $params = array( + $params = [ 'id' => $financialItem['id'], - 'return' => array( + 'return' => [ 'description', 'status_id', 'amount', 'financial_account_id', - ), - ); - $checkAgainst = array( + ], + ]; + $checkAgainst = [ 'id' => $financialItem['id'], 'description' => 'Contribution Amount', 'status_id' => '1', 'amount' => '100.00', 'financial_account_id' => '1', - ); + ]; $this->callAPISuccessGetSingle('FinancialItem', $params, $checkAgainst); } diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php index 223e33f8ad..c2f8e63db7 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php @@ -64,7 +64,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { ); CRM_Financial_BAO_FinancialTypeAccount::del($financialAccountType->id); - $params = array('id' => $financialAccountType->id); + $params = ['id' => $financialAccountType->id]; $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); } @@ -78,14 +78,14 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { 'Asset Account is' ); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); - $financialParams = array( + $financialParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount->id, - ); + ]; - $defaults = array(); + $defaults = []; $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::retrieve($financialParams, $defaults); $this->assertEquals($financialAccountType['entity_id'], $financialType->id, 'Verify Entity Id.'); $this->assertEquals($financialAccountType['financial_account_id'], $financialAccount->id, 'Verify Financial Account Id.'); @@ -99,18 +99,18 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount( 'Asset' ); - $optionParams = array( + $optionParams = [ 'name' => 'Credit Card', 'value' => $paymentInstrumentValue, - ); + ]; $optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); - $financialParams = array( + $financialParams = [ 'entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount->id, - ); + ]; CRM_Financial_BAO_FinancialTypeAccount::add($financialParams); $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentValue); @@ -122,7 +122,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { * Test validate account relationship with financial account type. */ public function testValidateRelationship() { - $params = array('labelColumn' => 'name'); + $params = ['labelColumn' => 'name']; $financialAccount = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params); $accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params); $financialType = CRM_Contribute_PseudoConstant::financialType(); @@ -152,27 +152,27 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { * obj CRM_Financial_DAO_FinancialAccount, obj CRM_Financial_DAO_FinancialType, obj CRM_Financial_DAO_EntityFinancialAccount */ public function createFinancialAccount($financialAccountType, $relationType = NULL) { - $params = array('labelColumn' => 'name'); + $params = ['labelColumn' => 'name']; $relationTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params); $financialAccountTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params); - $params = array( + $params = [ 'name' => 'TestFinancialAccount_' . rand(), 'contact_id' => 1, 'is_deductible' => 0, 'is_active' => 1, 'is_reserved' => 0, 'financial_account_type_id' => array_search($financialAccountType, $financialAccountTypes), - ); + ]; $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params); $financialType = $financialAccountType = NULL; if ($relationType) { $params['name'] = 'test_financialType1'; $financialType = CRM_Financial_BAO_FinancialType::add($params); - $financialParams = array( + $financialParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, 'account_relationship' => array_search($relationType, $relationTypes), - ); + ]; //CRM-20313: As per unique index added in civicrm_entity_financial_account table, // first check if there's any record on basis of unique key (entity_table, account_relationship, entity_id) @@ -185,7 +185,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $financialParams['financial_account_id'] = $financialAccount->id; $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::add($financialParams); } - return array($financialAccount, $financialType, $financialAccountType); + return [$financialAccount, $financialType, $financialAccountType]; } } diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php index 36424c20ff..c438c9d5bb 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php @@ -44,13 +44,13 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { * Check method add(). */ public function testAdd() { - $params = array( + $params = [ 'name' => 'Donations', 'is_active' => 1, 'is_deductible' => 1, 'is_reserved' => 1, - ); - $ids = array(); + ]; + $ids = []; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); $result = $this->assertDBNotNull( 'CRM_Financial_DAO_FinancialType', @@ -66,17 +66,17 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { * Check method retrieve(). */ public function testRetrieve() { - $params = array( + $params = [ 'name' => 'Donations', 'is_active' => 1, 'is_deductible' => 1, 'is_reserved' => 1, - ); + ]; - $ids = array(); + $ids = []; CRM_Financial_BAO_FinancialType::add($params, $ids); - $defaults = array(); + $defaults = []; $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals($result->name, 'Donations', 'Verify Name for Financial Type'); } @@ -85,12 +85,12 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { * Check method setIsActive() */ public function testSetIsActive() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); $result = CRM_Financial_BAO_FinancialType::setIsActive($financialType->id, 0); $this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.'); @@ -108,16 +108,16 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { * Check method del() */ public function testDel() { - $params = array( + $params = [ 'name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); CRM_Financial_BAO_FinancialType::del($financialType->id); - $params = array('id' => $financialType->id); + $params = ['id' => $financialType->id]; $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); } @@ -126,7 +126,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { * Set ACLs for Financial Types() */ public function setACL() { - CRM_Core_BAO_Setting::setItem(array('acl_financial_type' => 1), NULL, 'contribution_invoice_settings'); + CRM_Core_BAO_Setting::setItem(['acl_financial_type' => 1], NULL, 'contribution_invoice_settings'); } /** @@ -134,21 +134,21 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { */ public function testGetAvailableFinancialTypes() { $this->setACL(); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', 'view contributions of type Member Dues', - )); - $types = array(); + ]); + $types = []; CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types); - $expectedResult = array( + $expectedResult = [ 1 => "Donation", 2 => "Member Dues", - ); + ]; $this->assertEquals($expectedResult, $types, 'Verify that only certain financial types can be retrieved'); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', - )); + ]); unset($expectedResult[2]); CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types); $this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available financial types'); @@ -159,8 +159,8 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { */ public function testgetAvailableMembershipTypes() { // Create Membership types - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'Type One', 'domain_id' => 1, 'minimum_fee' => 10, @@ -171,7 +171,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); // Add another @@ -181,19 +181,19 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $this->setACL(); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', 'view contributions of type Member Dues', - )); + ]); CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($types); - $expectedResult = array( + $expectedResult = [ 1 => "Type One", 2 => "Type Two", - ); + ]; $this->assertEquals($expectedResult, $types, 'Verify that only certain membership types can be retrieved'); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', - )); + ]); unset($expectedResult[2]); CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($types); $this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available membership types'); @@ -209,19 +209,19 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { CRM_Financial_BAO_FinancialType::permissionedFinancialTypes($permissions, TRUE); $financialTypes = CRM_Contribute_PseudoConstant::financialType(); $prefix = ts('CiviCRM') . ': '; - $actions = array('add', 'view', 'edit', 'delete'); + $actions = ['add', 'view', 'edit', 'delete']; foreach ($financialTypes as $id => $type) { foreach ($actions as $action) { - $checkPerms[$action . ' contributions of type ' . $type] = array( + $checkPerms[$action . ' contributions of type ' . $type] = [ $prefix . ts($action . ' contributions of type ') . $type, ts(ucfirst($action) . ' contributions of type ') . $type, - ); + ]; } } - $checkPerms['administer CiviCRM Financial Types'] = array( + $checkPerms['administer CiviCRM Financial Types'] = [ $prefix . ts('administer CiviCRM Financial Types'), ts('Administer access to Financial Types'), - ); + ]; $this->assertEquals($permissions, $checkPerms, 'Verify that permissions for each financial type have been added'); } @@ -243,36 +243,36 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset' ); - $paramsField = array( + $paramsField = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', - 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_value' => array('1' => 100, '2' => 200), - 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_weight' => array('1' => 1, '2' => 2), - 'option_amount' => array('1' => 100, '2' => 200), + 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_value' => ['1' => 100, '2' => 200], + 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_weight' => ['1' => 1, '2' => 2], + 'option_amount' => ['1' => 100, '2' => 200], 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, - 'is_active' => array('1' => 1, '2' => 1), + 'is_active' => ['1' => 1, '2' => 1], 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => 1, - ); + ]; $priceField = CRM_Price_BAO_PriceField::create($paramsField); - $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); - $contributionParams = array( + $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]); + $contributionParams = [ 'total_amount' => 300, 'currency' => 'USD', 'contact_id' => $contactId, 'financial_type_id' => 1, 'contribution_status_id' => 1, 'skipCleanMoney' => TRUE, - ); + ]; foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[1][$key] = array( + $lineItems[1][$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -281,16 +281,16 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id'], - ); + ]; } $contributionParams['line_item'] = $lineItems; $contributions = CRM_Contribute_BAO_Contribution::create($contributionParams); - CRM_Financial_BAO_FinancialType::$_statusACLFt = array(); + CRM_Financial_BAO_FinancialType::$_statusACLFt = []; $this->setACL(); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Member Dues', - )); + ]); try { CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view'); @@ -300,9 +300,9 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $this->assertEquals("A fatal error was triggered: You do not have permission to access this page.", $e->getMessage()); } - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', - )); + ]); $perm = CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view'); $this->assertEquals($perm, TRUE, 'Verify that lineitems now have permission.'); } @@ -315,7 +315,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $this->assertEquals(array_search('acl_financial_type', $isACL), NULL); $this->setACL(); $isACL = CRM_Core_BAO_Setting::getItem(NULL, 'contribution_invoice_settings'); - $this->assertEquals($isACL, array('acl_financial_type' => 1)); + $this->assertEquals($isACL, ['acl_financial_type' => 1]); } /** @@ -323,17 +323,17 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { */ public function testBuildPermissionedClause() { $this->setACL(); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', 'view contributions of type Member Dues', - )); + ]); CRM_Financial_BAO_FinancialType::buildPermissionedClause($whereClause, 'contribution'); $this->assertEquals($whereClause, ' civicrm_contribution.financial_type_id IN (1,2)'); - $this->setPermissions(array( + $this->setPermissions([ 'view contributions of type Donation', 'view contributions of type Member Dues', 'view contributions of type Event Fee', - )); + ]); $whereClause = NULL; CRM_Financial_BAO_FinancialType::buildPermissionedClause($whereClause, 'contribution'); diff --git a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php index 729bd1cd63..33bc618ce4 100644 --- a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php +++ b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php @@ -39,7 +39,7 @@ class CRM_Financial_BAO_PaymentProcessorTest extends CiviUnitTestCase { * Check method create() */ public function testGetCreditCards() { - $params = array( + $params = [ 'name' => 'API_Test_PP_Type', 'title' => 'API Test Payment Processor Type', 'class_name' => 'CRM_Core_Payment_APITest', @@ -47,18 +47,18 @@ class CRM_Financial_BAO_PaymentProcessorTest extends CiviUnitTestCase { 'payment_processor_type_id' => 1, 'is_recur' => 0, 'domain_id' => 1, - 'accepted_credit_cards' => json_encode(array( + 'accepted_credit_cards' => json_encode([ 'Visa' => 'Visa', 'Mastercard' => 'Mastercard', 'Amex' => 'Amex', - )), - ); + ]), + ]; $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($params); - $expectedCards = array( + $expectedCards = [ 'Visa' => 'Visa', 'Mastercard' => 'Mastercard', 'Amex' => 'Amex', - ); + ]; $cards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessor->id); $this->assertEquals($cards, $expectedCards, 'Verify correct credit card types are returned'); } diff --git a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php index 433505a8de..7aaab9e7fc 100644 --- a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php +++ b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php @@ -39,11 +39,11 @@ class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check method create() */ public function testCreate() { - $params = array( + $params = [ 'name' => 'Test_Payment_Processor', 'title' => 'Test Payment Processor', 'billing_mode' => 1, - ); + ]; $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params); $result = $this->assertDBNotNull( 'CRM_Financial_DAO_PaymentProcessorType', @@ -59,12 +59,12 @@ class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check method retrieve() */ public function testRetrieve() { - $params = array( + $params = [ 'name' => 'Test_Retrieve_Payment_Processor', 'title' => 'Test Retrieve Payment Processor', 'billing_mode' => 1, - ); - $defaults = array(); + ]; + $defaults = []; CRM_Financial_BAO_PaymentProcessorType::create($params); $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults); $this->assertEquals($result->name, 'Test_Retrieve_Payment_Processor', 'Verify Payment Processor Type'); @@ -74,12 +74,12 @@ class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check method setIsActive() */ public function testSetIsActive() { - $params = array( + $params = [ 'name' => 'Test_Set_Payment_Processor', 'title' => 'Test Set Payment Processor', 'billing_mode' => 1, 'is_active' => 1, - ); + ]; $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params); $result = CRM_Financial_BAO_PaymentProcessorType::setIsActive($paymentProcessor->id, 0); @@ -99,8 +99,8 @@ class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check method getDefault() */ public function testGetDefault() { - $params = array('is_default' => 1); - $defaults = array(); + $params = ['is_default' => 1]; + $defaults = []; $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults); $default = CRM_Financial_BAO_PaymentProcessorType::getDefault(); @@ -111,18 +111,18 @@ class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check method del() */ public function testDel() { - $params = array( + $params = [ 'name' => 'Test_Del_Payment_Processor', 'title' => 'Test Del Payment Processor', 'billing_mode' => 1, 'is_active' => 1, - ); + ]; - $defaults = array(); + $defaults = []; $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params); CRM_Financial_BAO_PaymentProcessorType::del($paymentProcessor->id); - $params = array('id' => $paymentProcessor->id); + $params = ['id' => $paymentProcessor->id]; $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); } diff --git a/tests/phpunit/CRM/Financial/Form/PaymentEditTest.php b/tests/phpunit/CRM/Financial/Form/PaymentEditTest.php index 64a8c9c4b1..de578b2503 100644 --- a/tests/phpunit/CRM/Financial/Form/PaymentEditTest.php +++ b/tests/phpunit/CRM/Financial/Form/PaymentEditTest.php @@ -47,7 +47,7 @@ class CRM_Financial_Form_PaymentEditTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address')); + $this->quickCleanup(['civicrm_note', 'civicrm_uf_match', 'civicrm_address']); } /** @@ -56,7 +56,7 @@ class CRM_Financial_Form_PaymentEditTest extends CiviUnitTestCase { public function testSubmitOnPaymentInstrumentChange() { // First create a contribution using 'Check' as payment instrument $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'receive_date' => '2015-04-21 23:27:00', 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), @@ -64,15 +64,15 @@ class CRM_Financial_Form_PaymentEditTest extends CiviUnitTestCase { 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'check_number' => '123XA', 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), - ), + ], CRM_Core_Action::ADD); // fetch the financial trxn record later used in setting default values of payment edit form - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualID)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualID]); $payments = CRM_Contribute_BAO_Contribution::getPaymentInfo($contribution['id'], 'contribute', TRUE); $financialTrxnInfo = $payments['transaction'][0]; // build parameters which changed payment instrument and tran date values - $params = array( + $params = [ 'id' => $financialTrxnInfo['id'], 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit Card'), 'card_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_FinancialTrxn', 'card_type_id', 'Visa'), @@ -80,35 +80,35 @@ class CRM_Financial_Form_PaymentEditTest extends CiviUnitTestCase { 'trnx_id' => 'txn_12AAAA', 'trxn_date' => date('Y-m-d H:i:s'), 'contribution_id' => $contribution['id'], - ); + ]; $form = new CRM_Financial_Form_PaymentEdit(); $form->testSubmit($params); $payments = CRM_Contribute_BAO_Contribution::getPaymentInfo($contribution['id'], 'contribute', TRUE); - $expectedPaymentParams = array( - array( + $expectedPaymentParams = [ + [ 'total_amount' => 50.00, 'financial_type' => 'Donation', 'payment_instrument' => 'Check', 'status' => 'Completed', 'receive_date' => '2015-04-21 23:27:00', 'check_number' => '123XA', - ), - array( + ], + [ 'total_amount' => -50.00, 'financial_type' => 'Donation', 'payment_instrument' => 'Check', 'status' => 'Completed', 'receive_date' => $params['trxn_date'], 'check_number' => '123XA', - ), - array( + ], + [ 'total_amount' => 50.00, 'financial_type' => 'Donation', 'payment_instrument' => sprintf('Credit Card (Visa: %s)', $params['pan_truncation']), 'status' => 'Completed', 'receive_date' => $params['trxn_date'], - ), - ); + ], + ]; $this->assertEquals(3, count($payments['transaction'])); foreach ($expectedPaymentParams as $key => $paymentParams) { foreach ($paymentParams as $fieldName => $expectedValue) { @@ -127,16 +127,16 @@ class CRM_Financial_Form_PaymentEditTest extends CiviUnitTestCase { $checkPaymentInstrumentID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); // First create a contribution using 'Check' as payment instrument $form = new CRM_Contribute_Form_Contribution(); - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 50, 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), 'contact_id' => $this->_individualID, 'payment_instrument_id' => $checkPaymentInstrumentID, 'check_number' => $checkNumber1, 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), - ), + ], CRM_Core_Action::ADD); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualID)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualID]); $payments = CRM_Contribute_BAO_Contribution::getPaymentInfo($contribution['id'], 'contribute', TRUE); $financialTrxnInfo = $payments['transaction'][0]; @@ -144,23 +144,23 @@ class CRM_Financial_Form_PaymentEditTest extends CiviUnitTestCase { // ensure that contribution's check_number has concatenated check-numbers $checkNumber2 = '456XA'; // build parameters which changed payment instrument and tran date values - $params = array( + $params = [ 'id' => $financialTrxnInfo['id'], 'payment_instrument_id' => $checkPaymentInstrumentID, 'check_number' => $checkNumber2, 'trxn_date' => date('Y-m-d H:i:s'), 'contribution_id' => $contribution['id'], - ); + ]; $form = new CRM_Financial_Form_PaymentEdit(); $form->testSubmit($params); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contribution['id'])); - $expectedConcatanatedCheckNumbers = implode(',', array($checkNumber1, $checkNumber2)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]); + $expectedConcatanatedCheckNumbers = implode(',', [$checkNumber1, $checkNumber2]); $this->assertEquals($expectedConcatanatedCheckNumbers, $contribution['check_number']); // CASE 3: Submit payment details via edit form without any change, // ensure that contribution's check_number concatenated value isn't changed $form->testSubmit($params); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contribution['id'])); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]); $this->assertEquals($expectedConcatanatedCheckNumbers, $contribution['check_number']); } diff --git a/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php b/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php index 9ae40bcb89..1c46d8b780 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php @@ -38,10 +38,10 @@ class CRM_Financial_Page_AjaxBatchSummaryTest extends CiviUnitTestCase { * does not cause any regression. */ public function testMakeBatchSummary() { - $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open', 'payment_instrument_id' => 'Cash')); + $batch = $this->callAPISuccess('Batch', 'create', ['title' => 'test', 'status_id' => 'Open', 'payment_instrument_id' => 'Cash']); $batchID = $batch['id']; - $params = array('id' => $batchID); + $params = ['id' => $batchID]; $makeBatchSummary = CRM_Financial_Page_AJAX::makeBatchSummary($batchID, $params); $this->assertEquals('Open', $makeBatchSummary['status']); diff --git a/tests/phpunit/CRM/Financial/Page/AjaxTest.php b/tests/phpunit/CRM/Financial/Page/AjaxTest.php index 767605c871..1fef00acf0 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxTest.php @@ -38,8 +38,8 @@ class CRM_Financial_Page_AjaxTest extends CiviUnitTestCase { */ public function testGetFinancialTransactionsList() { $individualID = $this->individualCreate(); - $this->contributionCreate(array('contact_id' => $individualID, 'trxn_id' => 12345)); - $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open')); + $this->contributionCreate(['contact_id' => $individualID, 'trxn_id' => 12345]); + $batch = $this->callAPISuccess('Batch', 'create', ['title' => 'test', 'status_id' => 'Open']); CRM_Core_DAO::executeQuery(" INSERT INTO civicrm_entity_batch (entity_table, entity_id, batch_id) values('civicrm_financial_trxn', 1, 1) diff --git a/tests/phpunit/CRM/Group/Page/AjaxTest.php b/tests/phpunit/CRM/Group/Page/AjaxTest.php index d05371a6ed..5325d28072 100644 --- a/tests/phpunit/CRM/Group/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Group/Page/AjaxTest.php @@ -23,11 +23,11 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public $hookClass; - protected $_params = array(); + protected $_params = []; public function setUp() { parent::setUp(); - $this->_params = array( + $this->_params = [ 'page' => 1, 'rp' => 50, 'offset' => 0, @@ -35,26 +35,26 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { 'sort' => NULL, 'parentsOnly' => FALSE, 'is_unit_test' => TRUE, - ); + ]; $this->hookClass = CRM_Utils_Hook::singleton(); $this->createLoggedInUser(); - $this->_permissionedDisabledGroup = $this->groupCreate(array( + $this->_permissionedDisabledGroup = $this->groupCreate([ 'title' => 'pick-me-disabled', 'is_active' => 0, 'name' => 'pick-me-disabled', - )); - $this->_permissionedGroup = $this->groupCreate(array( + ]); + $this->_permissionedGroup = $this->groupCreate([ 'title' => 'pick-me-active', 'is_active' => 1, 'name' => 'pick-me-active', - )); - $this->groupCreate(array('title' => 'not-me-disabled', 'is_active' => 0, 'name' => 'not-me-disabled')); - $this->groupCreate(array('title' => 'not-me-active', 'is_active' => 1, 'name' => 'not-me-active')); + ]); + $this->groupCreate(['title' => 'not-me-disabled', 'is_active' => 0, 'name' => 'not-me-disabled']); + $this->groupCreate(['title' => 'not-me-active', 'is_active' => 1, 'name' => 'not-me-active']); } public function tearDown() { CRM_Utils_Hook::singleton()->reset(); - $this->quickCleanup(array('civicrm_group')); + $this->quickCleanup(['civicrm_group']); $config = CRM_Core_Config::singleton(); unset($config->userPermissionClass->permissions); parent::tearDown(); @@ -75,7 +75,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function setHookAndRequest($permission, $hook) { CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission; - $this->hookClass->setHook('civicrm_aclGroup', array($this, $hook)); + $this->hookClass->setHook('civicrm_aclGroup', [$this, $hook]); global $_REQUEST; $_REQUEST = $this->_params; } @@ -84,7 +84,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { * CRM-18528 - Retrieve groups with filter */ public function testGroupListWithFilter() { - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $_GET = $this->_params; $obj = new CRM_Group_Page_AJAX(); @@ -108,7 +108,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { * Retrieve groups as 'view all contacts' */ public function testGroupListViewAllContacts() { - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); @@ -130,7 +130,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->assertEquals('Contacts', $groups['data'][1]['links']); // as per changes made in PR-6822 - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); @@ -145,7 +145,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListViewAllContactsFoundTitle() { $this->_params['title'] = 'p'; - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); @@ -168,7 +168,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { * Retrieve groups as 'edit all contacts' */ public function testGroupListEditAllContacts() { - $this->setPermissionAndRequest(array('edit all contacts', 'edit groups')); + $this->setPermissionAndRequest(['edit all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); @@ -181,7 +181,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListViewAllContactsEnabled() { $this->_params['status'] = 1; - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); @@ -194,7 +194,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListViewAllContactsDisabled() { $this->_params['status'] = 2; - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); @@ -208,7 +208,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { public function testGroupListViewAllContactsDisabledNotFoundTitle() { $this->_params['status'] = 2; $this->_params['title'] = 'n'; - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(1, $groups['recordsTotal']); @@ -221,7 +221,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { public function testGroupListViewAllContactsDisabledFoundTitle() { $this->_params['status'] = 2; $this->_params['title'] = 'p'; - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(1, $groups['recordsTotal']); @@ -233,7 +233,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListViewAllContactsAll() { $this->_params['status'] = 3; - $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); + $this->setPermissionAndRequest(['view all contacts', 'edit groups']); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(4, $groups['recordsTotal']); @@ -408,7 +408,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListAclGroupHookDisabled() { $this->_params['status'] = 2; - $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup'); + $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup'); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default'); @@ -422,7 +422,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { public function testGroupListAclGroupHookDisabledFound() { $this->_params['status'] = 2; $this->_params['title'] = 'p'; - $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup'); + $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup'); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default'); @@ -447,7 +447,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { * ACL Group hook. */ public function testGroupListAclGroupHook() { - $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup'); + $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup'); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default'); @@ -472,7 +472,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListAclGroupHookTitleFound() { $this->_params['title'] = 'p'; - $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup'); + $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup'); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, count($groups['data']), 'Returned groups should exclude disabled by default'); @@ -486,7 +486,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListAclGroupHookAll() { $this->_params['status'] = 3; - $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup'); + $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup'); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, count($groups['data']), 'Returned groups should exclude disabled by default'); @@ -500,7 +500,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { */ public function testGroupListAclGroupHookEnabled() { $this->_params['status'] = 1; - $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup'); + $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup'); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default'); @@ -517,18 +517,18 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { // Create a contact. $firstName = 'Tweak'; $lastName = 'Octonaut'; - $params = array( + $params = [ 'first_name' => $firstName, 'last_name' => $lastName, 'contact_type' => 'Individual', - ); + ]; $contact = CRM_Contact_BAO_Contact::add($params); // Create a smart group. - $searchParams = array( + $searchParams = [ 'last_name' => $lastName, - ); - $groupParams = array('title' => 'Find all Octonauts', 'formValues' => $searchParams, 'is_active' => 1); + ]; + $groupParams = ['title' => 'Find all Octonauts', 'formValues' => $searchParams, 'is_active' => 1]; $group = CRM_Contact_BAO_Group::createSmartGroup($groupParams); // Ensure the smart group is created. @@ -537,7 +537,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { // Ensure it is populating the cache when loaded. $sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1'; - $params = array(1 => array($group->id, 'Integer')); + $params = [1 => [$group->id, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($sql, $params); $this->assertEquals($dao->N, 1, '1 record should be found in smart group'); @@ -582,7 +582,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { // Ensure we did not populate the cache. $sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1'; - $params = array(1 => array($group->id, 'Integer')); + $params = [1 => [$group->id, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($sql, $params); $test = 'Group contact cache should not be populated on Manage Groups ' . 'when cache_date is null'; @@ -599,10 +599,10 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $cache_date = date('YmdHis', time() - $timeout - 60); $sql = "UPDATE civicrm_group SET cache_date = %1 WHERE id = %2"; - $update_params = array( - 1 => array($cache_date, 'Timestamp'), - 2 => array($group->id, 'Integer'), - ); + $update_params = [ + 1 => [$cache_date, 'Timestamp'], + 2 => [$group->id, 'Integer'], + ]; CRM_Core_DAO::executeQuery($sql, $update_params); // Load the Manage Group page code. @@ -613,7 +613,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { // Ensure we did not regenerate the cache. $sql = 'SELECT DATE_FORMAT(cache_date, "%Y%m%d%H%i%s") AS cache_date ' . 'FROM civicrm_group WHERE id = %1'; - $params = array(1 => array($group->id, 'Integer')); + $params = [1 => [$group->id, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($sql, $params); $dao->fetch(); $test = 'Group contact cache should not be re-populated on Manage Groups ' . @@ -633,7 +633,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { public function hook_civicrm_aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) { //don't use api - you will get a loop $sql = " SELECT * FROM civicrm_group WHERE name LIKE '%pick%'"; - $groups = array(); + $groups = []; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $groups[] = $dao->id; @@ -667,19 +667,19 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { global $_REQUEST; $_REQUEST = $this->_params; - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); - $optionGroupID = $this->callAPISuccessGetValue('option_group', array('return' => 'id', 'name' => 'acl_role')); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; + $optionGroupID = $this->callAPISuccessGetValue('option_group', ['return' => 'id', 'name' => 'acl_role']); $ov = new CRM_Core_DAO_OptionValue(); $ov->option_group_id = $optionGroupID; $ov->value = 55; if ($ov->find(TRUE)) { CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_value WHERE id = {$ov->id}"); } - $optionValue = $this->callAPISuccess('option_value', 'create', array( + $optionValue = $this->callAPISuccess('option_value', 'create', [ 'option_group_id' => $optionGroupID, 'label' => 'groupmaster', 'value' => 55, - )); + ]); $groupId = $this->groupCreate(['name' => 'groupmaster group']); // Assign groupmaster to groupmaster group in civicrm_acl_entity_role CRM_Core_DAO::executeQuery(" @@ -689,10 +689,10 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { "); // Put the user into this group $this->_loggedInUser = CRM_Core_Session::singleton()->get('userID'); - $this->callAPISuccess('group_contact', 'create', array( + $this->callAPISuccess('group_contact', 'create', [ 'group_id' => $groupId, 'contact_id' => $this->_loggedInUser, - )); + ]); // Add the ACL CRM_Core_DAO::executeQuery(" INSERT INTO civicrm_acl ( diff --git a/tests/phpunit/CRM/Import/DataSource/CsvTest.php b/tests/phpunit/CRM/Import/DataSource/CsvTest.php index 2f93b6da9b..6a8149e18a 100644 --- a/tests/phpunit/CRM/Import/DataSource/CsvTest.php +++ b/tests/phpunit/CRM/Import/DataSource/CsvTest.php @@ -39,12 +39,12 @@ class CRM_Import_DataSource_CsvTest extends CiviUnitTestCase { */ public function testToCsv($fileName) { $dataSource = new CRM_Import_DataSource_Csv(); - $params = array( - 'uploadFile' => array( + $params = [ + 'uploadFile' => [ 'name' => __DIR__ . '/' . $fileName, - ), + ], 'skipColumnHeader' => TRUE, - ); + ]; // Get the PEAR::DB object $dao = new CRM_Core_DAO(); @@ -72,7 +72,7 @@ class CRM_Import_DataSource_CsvTest extends CiviUnitTestCase { * @return array */ public function getCsvFiles() { - return array(array('import.csv'), array('yogi.csv')); + return [['import.csv'], ['yogi.csv']]; } } diff --git a/tests/phpunit/CRM/Logging/LoggingTest.php b/tests/phpunit/CRM/Logging/LoggingTest.php index a545cada4d..acce7ee0fa 100644 --- a/tests/phpunit/CRM/Logging/LoggingTest.php +++ b/tests/phpunit/CRM/Logging/LoggingTest.php @@ -14,7 +14,7 @@ class CRM_Logging_LoggingTest extends CiviUnitTestCase { CRM_Core_I18n_Schema::makeSinglelingual('en_US'); $logging = new CRM_Logging_Schema(); $logging->dropAllLogTables(); - \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array(); + \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; parent::tearDown(); } @@ -25,7 +25,7 @@ class CRM_Logging_LoggingTest extends CiviUnitTestCase { CRM_Core_I18n_Schema::makeMultilingual('en_US'); $logging = new CRM_Logging_Schema(); $logging->enableLogging(); - $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE); + $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE); $this->assertNotNull($value, 'Logging not enabled successfully'); $logging->disableLogging(); } @@ -38,11 +38,11 @@ class CRM_Logging_LoggingTest extends CiviUnitTestCase { CRM_Core_I18n_Schema::makeMultilingual('en_US'); $logging = new CRM_Logging_Schema(); $logging->enableLogging(); - $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE); + $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE); $this->assertNotNull($value, 'Logging not enabled successfully'); - CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT '0'", array(), FALSE, NULL, FALSE, FALSE); - CRM_Core_I18n_Schema::rebuildMultilingualSchema(array('en_US')); - \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array(); + CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT '0'", [], FALSE, NULL, FALSE, FALSE); + CRM_Core_I18n_Schema::rebuildMultilingualSchema(['en_US']); + \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; $logging->fixSchemaDifferencesFor('civicrm_option_value'); Civi::service('sql_triggers')->rebuild('civicrm_option_value'); $query = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", [], TRUE, NULL, FALSE, FALSE); diff --git a/tests/phpunit/CRM/Logging/SchemaTest.php b/tests/phpunit/CRM/Logging/SchemaTest.php index 7b1a06ff0f..41f30ac2ed 100644 --- a/tests/phpunit/CRM/Logging/SchemaTest.php +++ b/tests/phpunit/CRM/Logging/SchemaTest.php @@ -64,7 +64,7 @@ class CRM_Logging_SchemaTest extends CiviUnitTestCase { * Test that the log table engine can be changed via hook to e.g. MyISAM */ public function testHookLogEngine() { - $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'alterLogTables')); + $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'alterLogTables']); $schema = new CRM_Logging_Schema(); $schema->enableLogging(); $log_table = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE log_civicrm_acl"); @@ -168,7 +168,7 @@ class CRM_Logging_SchemaTest extends CiviUnitTestCase { $this->assertTrue(empty($diffs['ADD'])); $this->assertTrue(empty($diffs['OBSOLETE'])); CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_test_table ADD COLUMN test_varchar varchar(255) DEFAULT NULL"); - \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array(); + \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; // Check that it still picks up new columns added. $diffs = $schema->columnsWithDiffSpecs("civicrm_test_table", "log_civicrm_test_table"); $this->assertTrue(!empty($diffs['ADD'])); @@ -177,7 +177,7 @@ class CRM_Logging_SchemaTest extends CiviUnitTestCase { $schema->fixSchemaDifferences(); CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_test_table CHANGE COLUMN test_varchar test_varchar varchar(400) DEFAULT NULL"); // Check that it properly picks up modifications to columns. - \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array(); + \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; $diffs = $schema->columnsWithDiffSpecs("civicrm_test_table", "log_civicrm_test_table"); $this->assertTrue(!empty($diffs['MODIFY'])); $this->assertTrue(empty($diffs['ADD'])); @@ -185,7 +185,7 @@ class CRM_Logging_SchemaTest extends CiviUnitTestCase { $schema->fixSchemaDifferences(); CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_test_table CHANGE COLUMN test_varchar test_varchar varchar(300) DEFAULT NULL"); // Check that when we reduce the size of column that the log table doesn't shrink as well. - \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array(); + \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; $diffs = $schema->columnsWithDiffSpecs("civicrm_test_table", "log_civicrm_test_table"); $this->assertTrue(empty($diffs['MODIFY'])); $this->assertTrue(empty($diffs['ADD'])); diff --git a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php index 326f434085..bdc6891df2 100644 --- a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php @@ -59,8 +59,8 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { // Load the recipients as a list of contact IDs CRM_Mailing_BAO_Mailing::getRecipients($mailingID); - $recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailingID)); - $contactIDs = array(); + $recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailingID]); + $contactIDs = []; foreach ($recipients['values'] as $recipient) { $contactIDs[] = $recipient['contact_id']; } @@ -78,12 +78,12 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { * @return array|int */ private function createMailingGroup($mailingID, $groupID, $type = 'Include') { - return $this->callAPISuccess('MailingGroup', 'create', array( + return $this->callAPISuccess('MailingGroup', 'create', [ 'mailing_id' => $mailingID, 'group_type' => $type, 'entity_table' => CRM_Contact_BAO_Group::getTableName(), 'entity_id' => $groupID, - )); + ]); } /** @@ -93,8 +93,8 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { $this->prepareForACLs(); $this->createLoggedInUser(); // create hook to build ACL where clause which choses $this->allowedContactId as the only contact to be considered as mail recipient - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereAllowedOnlyOne')); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view my contact'); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereAllowedOnlyOne']); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view my contact']; // Create dummy group and assign 2 contacts $name = 'Test static group ' . substr(sha1(rand()), 0, 7); @@ -104,19 +104,19 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { 'is_active' => 1, ]); // Create 2 contacts where one of them identified as $this->allowedContactId will be used in ACL where clause - $contactID1 = $this->individualCreate(array(), 0); - $this->allowedContactId = $this->individualCreate(array(), 1); - $this->callAPISuccess('GroupContact', 'Create', array( + $contactID1 = $this->individualCreate([], 0); + $this->allowedContactId = $this->individualCreate([], 1); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID1, - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $this->allowedContactId, - )); + ]); // Create dummy mailing - $mailingID = $this->callAPISuccess('Mailing', 'create', array())['id']; + $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id']; $this->createMailingGroup($mailingID, $groupID); // Check that the desired contact (identified as Contact ID - $this->allowedContactId) is the only @@ -146,33 +146,33 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { 'title' => $groupName2, 'is_active' => 1, ]); - $contactID = $this->individualCreate(array(), 0); - $contactID2 = $this->individualCreate(array(), 2); - $this->callAPISuccess('GroupContact', 'Create', array( + $contactID = $this->individualCreate([], 0); + $contactID2 = $this->individualCreate([], 2); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID, - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID2, - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID2, 'contact_id' => $contactID2, - )); + ]); // Create dummy mailing - $mailingID = $this->callAPISuccess('Mailing', 'create', array())['id']; + $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id']; $this->createMailingGroup($mailingID, $groupID); $expectedContactIDs = [$contactID, $contactID2]; $this->assertRecipientsCorrect($mailingID, $expectedContactIDs); - $mailingID2 = $this->callAPISuccess('Mailing', 'create', array())['id']; + $mailingID2 = $this->callAPISuccess('Mailing', 'create', [])['id']; $this->createMailingGroup($mailingID2, $groupID2, 'Exclude'); - $this->callAPISuccess('MailingGroup', 'create', array( + $this->callAPISuccess('MailingGroup', 'create', [ 'mailing_id' => $mailingID2, 'group_type' => 'Include', 'entity_table' => CRM_Mailing_BAO_Mailing::getTableName(), 'entity_id' => $mailingID, - )); + ]); $expectedContactIDs = [$contactID]; $this->assertRecipientsCorrect($mailingID2, $expectedContactIDs); $this->callAPISuccess('mailing', 'delete', ['id' => $mailingID2]); @@ -190,9 +190,9 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { $this->prepareForACLs(); $this->createLoggedInUser(); // create hook to build ACL where clause which choses $this->allowedContactId as the only contact to be considered as mail recipient - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereAllowedOnlyOne')); - $this->hookClass->setHook('civicrm_aclGroup', array($this, 'hook_civicrm_aclGroup')); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit groups'); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereAllowedOnlyOne']); + $this->hookClass->setHook('civicrm_aclGroup', [$this, 'hook_civicrm_aclGroup']); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit groups']; // Create dummy group and assign 2 contacts $name = 'Test static group ' . substr(sha1(rand()), 0, 7); $groupID = $this->groupCreate([ @@ -200,14 +200,14 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { 'title' => $name, 'is_active' => 1, ]); - $contactID = $this->individualCreate(array(), 0); - $this->callAPISuccess('GroupContact', 'Create', array( + $contactID = $this->individualCreate([], 0); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID, - )); + ]); // Create dummy mailing - $mailingID = $this->callAPISuccess('Mailing', 'create', array())['id']; + $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id']; $this->createMailingGroup($mailingID, $groupID); // Now disable the group. $this->callAPISuccess('group', 'create', [ @@ -250,7 +250,7 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { public function hook_civicrm_aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) { //don't use api - you will get a loop $sql = " SELECT * FROM civicrm_group"; - $groups = array(); + $groups = []; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $groups[] = $dao->id; @@ -294,57 +294,57 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { */ public function testgetRecipientsEmailGroupIncludeExclude() { // Set up groups; 3 standard, 4 smart - $groupIDs = array(); + $groupIDs = []; for ($i = 0; $i < 7; $i++) { - $params = array( + $params = [ 'name' => 'Test static group ' . $i, 'title' => 'Test static group ' . $i, 'is_active' => 1, - ); + ]; if ($i < 3) { $groupIDs[$i] = $this->groupCreate($params); } else { - $groupIDs[$i] = $this->smartGroupCreate(array( + $groupIDs[$i] = $this->smartGroupCreate([ 'formValues' => ['last_name' => (($i == 6) ? 'smart5' : 'smart' . $i)], - ), $params); + ], $params); } } // Create contacts - $contactIDs = array( - $this->individualCreate(array('last_name' => 'smart5'), 0), - $this->individualCreate(array(), 1), - $this->individualCreate(array(), 2), - $this->individualCreate(array(), 3), - $this->individualCreate(array('last_name' => 'smart3'), 4), - $this->individualCreate(array('last_name' => 'smart3'), 5), - $this->individualCreate(array('last_name' => 'smart4'), 6), - $this->individualCreate(array('last_name' => 'smart4'), 7), - $this->individualCreate(array('last_name' => 'smart5'), 8), - ); + $contactIDs = [ + $this->individualCreate(['last_name' => 'smart5'], 0), + $this->individualCreate([], 1), + $this->individualCreate([], 2), + $this->individualCreate([], 3), + $this->individualCreate(['last_name' => 'smart3'], 4), + $this->individualCreate(['last_name' => 'smart3'], 5), + $this->individualCreate(['last_name' => 'smart4'], 6), + $this->individualCreate(['last_name' => 'smart4'], 7), + $this->individualCreate(['last_name' => 'smart5'], 8), + ]; // Add contacts to static groups - $this->callAPISuccess('GroupContact', 'Create', array( + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupIDs[0], 'contact_id' => $contactIDs[0], - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupIDs[0], 'contact_id' => $contactIDs[1], - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupIDs[1], 'contact_id' => $contactIDs[2], - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupIDs[1], 'contact_id' => $contactIDs[3], - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupIDs[2], 'contact_id' => $contactIDs[4], - )); + ]); // Force rebuild the smart groups for ($i = 3; $i < 7; $i++) { @@ -356,7 +356,7 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { // Check that we can include static groups in the mailing. // Expected: Contacts [0-3] should be included. - $mailing = $this->callAPISuccess('Mailing', 'create', array()); + $mailing = $this->callAPISuccess('Mailing', 'create', []); $this->createMailingGroup($mailing['id'], $groupIDs[0]); $this->createMailingGroup($mailing['id'], $groupIDs[1]); $this->createMailingGroup($mailing['id'], $groupIDs[6], 'Base'); @@ -403,12 +403,12 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { // In this case groupIDs6 will only pick up contacts[0] amd contacts[8] with it's // criteria. However we are deliberly going to remove contactIds[8] from the group // Which should mean the mainling only finds 1 contact that is contactIds[0] - $mailing = $this->callAPISuccess('Mailing', 'create', array()); - $this->callAPISuccess('GroupContact', 'Create', array( + $mailing = $this->callAPISuccess('Mailing', 'create', []); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupIDs[6], 'contact_id' => $contactIDs[8], 'status' => 'Removed', - )); + ]); $this->createMailingGroup($mailing['id'], $groupIDs[6]); $this->assertRecipientsCorrect($mailing['id'], [$contactIDs[0]]); // Tear down: delete mailing, groups, contacts @@ -430,11 +430,11 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { // +core/384 Ensure that a secondary mobile number is selected if the primary can not receive SMS // Setup - $smartGroupParams = array( - 'formValues' => array('contact_type' => array('IN' => array('Individual'))), - ); + $smartGroupParams = [ + 'formValues' => ['contact_type' => ['IN' => ['Individual']]], + ]; $group = $this->smartGroupCreate($smartGroupParams); - $sms_provider = $this->callAPISuccess('SmsProvider', 'create', array( + $sms_provider = $this->callAPISuccess('SmsProvider', 'create', [ 'sequential' => 1, 'name' => 1, 'title' => "Test", @@ -442,96 +442,96 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { 'password' => "Test", 'api_type' => 1, 'is_active' => 1, - )); + ]); // Create Contact 1 and add in group - $contactID1 = $this->individualCreate(array(), 0); - $this->callAPISuccess('GroupContact', 'Create', array( + $contactID1 = $this->individualCreate([], 0); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $group, 'contact_id' => $contactID1, - )); + ]); // Create contact 2 and add in group - $contactID2 = $this->individualCreate(array(), 1); - $this->callAPISuccess('GroupContact', 'Create', array( + $contactID2 = $this->individualCreate([], 1); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $group, 'contact_id' => $contactID2, - )); + ]); // Create contact 3 and add in group - $contactID3 = $this->individualCreate(array(), 2); - $this->callAPISuccess('GroupContact', 'Create', array( + $contactID3 = $this->individualCreate([], 2); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $group, 'contact_id' => $contactID3, - )); + ]); - $contactIDPhoneRecords = array( - $contactID1 => array( - 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array( + $contactIDPhoneRecords = [ + $contactID1 => [ + 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $contactID1, 'phone' => "01 01", 'location_type_id' => "Home", 'phone_type_id' => "Mobile", 'is_primary' => 1, - ))), - 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array( + ])), + 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $contactID1, 'phone' => "01 02", 'location_type_id' => "Work", 'phone_type_id' => "Mobile", 'is_primary' => 0, - ))), - ), + ])), + ], // Create the non-primary with a lower ID than the primary, to test CRM-21320 - $contactID2 => array( - 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array( + $contactID2 => [ + 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $contactID2, 'phone' => "02 01", 'location_type_id' => "Home", 'phone_type_id' => "Mobile", 'is_primary' => 0, - ))), - 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array( + ])), + 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $contactID2, 'phone' => "02 02", 'location_type_id' => "Work", 'phone_type_id' => "Mobile", 'is_primary' => 1, - ))), - ), + ])), + ], // Create primary that cant recieve SMS but a secondary that can, to test core/384 - $contactID3 => array( - 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array( + $contactID3 => [ + 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $contactID3, 'phone' => "03 01", 'location_type_id' => "Home", 'phone_type_id' => "Mobile", 'is_primary' => 0, - ))), - 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array( + ])), + 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $contactID3, 'phone' => "03 02", 'location_type_id' => "Work", 'phone_type_id' => "Phone", 'is_primary' => 1, - ))), - ), - ); + ])), + ], + ]; // Prepare expected results - $checkPhoneIDs = array( + $checkPhoneIDs = [ $contactID1 => $contactIDPhoneRecords[$contactID1]['primary_phone_id'], $contactID2 => $contactIDPhoneRecords[$contactID2]['primary_phone_id'], $contactID3 => $contactIDPhoneRecords[$contactID3]['other_phone_id'], - ); + ]; // Create mailing - $mailing = $this->callAPISuccess('Mailing', 'create', array('sms_provider_id' => $sms_provider['id'])); + $mailing = $this->callAPISuccess('Mailing', 'create', ['sms_provider_id' => $sms_provider['id']]); $mailingInclude = $this->createMailingGroup($mailing['id'], $group); // Get recipients CRM_Mailing_BAO_Mailing::getRecipients($mailing['id']); - $recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailing['id'])); + $recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailing['id']]); // Check the count is correct $this->assertEquals(3, $recipients['count'], 'Check recipient count'); @@ -543,7 +543,7 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { // Tidy up $this->deleteMailing($mailing['id']); - $this->callAPISuccess('SmsProvider', 'Delete', array('id' => $sms_provider['id'])); + $this->callAPISuccess('SmsProvider', 'Delete', ['id' => $sms_provider['id']]); $this->groupDelete($group); $this->contactDelete($contactID1); $this->contactDelete($contactID2); @@ -557,43 +557,43 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { */ public function testAlterMailingRecipientsHook() { $groupID = $this->groupCreate(); - $this->tagCreate(array('name' => 'Tagged')); + $this->tagCreate(['name' => 'Tagged']); // Create deseased Contact 1 and add in group - $contactID1 = $this->individualCreate(array('email' => 'abc@test.com', 'is_deceased' => 1), 0); + $contactID1 = $this->individualCreate(['email' => 'abc@test.com', 'is_deceased' => 1], 0); // Create deseased Contact 2 and add in group - $contactID2 = $this->individualCreate(array('email' => 'def@test.com'), 1); + $contactID2 = $this->individualCreate(['email' => 'def@test.com'], 1); // Create deseased Contact 3 and add in group - $contactID3 = $this->individualCreate(array('email' => 'ghi@test.com', 'is_deceased' => 1), 2); + $contactID3 = $this->individualCreate(['email' => 'ghi@test.com', 'is_deceased' => 1], 2); // Add both the created contacts in group - $this->callAPISuccess('GroupContact', 'Create', array( + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID1, - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID2, - )); - $this->callAPISuccess('GroupContact', 'Create', array( + ]); + $this->callAPISuccess('GroupContact', 'Create', [ 'group_id' => $groupID, 'contact_id' => $contactID3, - )); - $this->entityTagAdd(array('contact_id' => $contactID3, 'tag_id' => 'Tagged')); + ]); + $this->entityTagAdd(['contact_id' => $contactID3, 'tag_id' => 'Tagged']); // trigger the alterMailingRecipients hook - $this->hookClass->setHook('civicrm_alterMailingRecipients', array($this, 'alterMailingRecipients')); + $this->hookClass->setHook('civicrm_alterMailingRecipients', [$this, 'alterMailingRecipients']); // create mailing that will trigger alterMailingRecipients hook - $params = array( + $params = [ 'name' => 'mailing name', 'subject' => 'Test Subject', 'body_html' => '

HTML Body

', 'text_html' => 'Text Body', 'created_id' => 1, - 'groups' => array('include' => array($groupID)), + 'groups' => ['include' => [$groupID]], 'scheduled_date' => 'now', - ); + ]; $this->callAPISuccess('Mailing', 'create', $params); } @@ -614,13 +614,13 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { ->where("t.name = 'Tagged'"); } else { - $mailingRecipients = $this->callAPISuccess('MailingRecipients', 'get', array( + $mailingRecipients = $this->callAPISuccess('MailingRecipients', 'get', [ 'mailing_id' => $mailingObject->id, - 'api.Email.getvalue' => array( + 'api.Email.getvalue' => [ 'id' => '$value.email_id', 'return' => 'email', - ), - )); + ], + ]); $this->assertEquals(1, $mailingRecipients['count'], 'Check recipient count'); $this->assertEquals('ghi@test.com', $mailingRecipients['values'][$mailingRecipients['id']]['api.Email.getvalue'], 'Check if recipient email belong to deceased contact'); } diff --git a/tests/phpunit/CRM/Mailing/BAO/QueryTest.php b/tests/phpunit/CRM/Mailing/BAO/QueryTest.php index 9dc0ede1f2..f5fcd8292c 100644 --- a/tests/phpunit/CRM/Mailing/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/QueryTest.php @@ -18,7 +18,7 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { } public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_delivered', 'civicrm_mailing_event_opened', @@ -31,7 +31,7 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { 'civicrm_mailing_recipients', 'civicrm_email', 'civicrm_contact', - ); + ]; $this->quickCleanup($tablesToTruncate); } @@ -54,7 +54,7 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { $dao = $obj->searchQuery(); - $contacts = array(); + $contacts = []; while ($dao->fetch()) { $contacts[] = $dao->contact_id; } diff --git a/tests/phpunit/CRM/Mailing/BAO/QueryTestDataProvider.php b/tests/phpunit/CRM/Mailing/BAO/QueryTestDataProvider.php index 5a24b3c436..2f795a2a2b 100644 --- a/tests/phpunit/CRM/Mailing/BAO/QueryTestDataProvider.php +++ b/tests/phpunit/CRM/Mailing/BAO/QueryTestDataProvider.php @@ -18,96 +18,96 @@ class CRM_Mailing_BAO_QueryTestDataProvider implements Iterator { * IDs should be selected when the form values are applied to the * database in dataset.xml */ - private $dataset = array( - array( - 'fv' => array('mailing_name' => 'First%', 'mailing_open_status' => 'Y'), - 'id' => array(109, 110, 111, 112), - ), - array( - 'fv' => array('mailing_name' => 'First%', 'mailing_open_status' => 'N'), - 'id' => array(102, 103, 104, 105, 108), - ), + private $dataset = [ + [ + 'fv' => ['mailing_name' => 'First%', 'mailing_open_status' => 'Y'], + 'id' => [109, 110, 111, 112], + ], + [ + 'fv' => ['mailing_name' => 'First%', 'mailing_open_status' => 'N'], + 'id' => [102, 103, 104, 105, 108], + ], /*bounce*/ - array( - 'fv' => array( + [ + 'fv' => [ 'mailing_name' => 'First%', 'mailing_delivery_status' => 'N', - ), - 'id' => array(105), - ), + ], + 'id' => [105], + ], /*bounce*/ - array( - 'fv' => array( + [ + 'fv' => [ 'mailing_name' => 'First%', 'mailing_delivery_status' => 'Y', - ), - 'id' => array(102, 103, 104, 108, 109, 110, 111, 112), - ), - array( - 'fv' => array('mailing_name' => 'First%', 'mailing_reply_status' => 'Y'), - 'id' => array(103, 108, 110, 112), - ), - array( - 'fv' => array('mailing_name' => 'First%', 'mailing_reply_status' => 'N'), - 'id' => array(102, 104, 105, 109, 111), - ), - array( - 'fv' => array('mailing_name' => 'First%', 'mailing_click_status' => 'Y'), - 'id' => array(104, 108, 111, 112), - ), - array( - 'fv' => array('mailing_name' => 'First%', 'mailing_click_status' => 'N'), - 'id' => array(102, 103, 105, 109, 110), - ), + ], + 'id' => [102, 103, 104, 108, 109, 110, 111, 112], + ], + [ + 'fv' => ['mailing_name' => 'First%', 'mailing_reply_status' => 'Y'], + 'id' => [103, 108, 110, 112], + ], + [ + 'fv' => ['mailing_name' => 'First%', 'mailing_reply_status' => 'N'], + 'id' => [102, 104, 105, 109, 111], + ], + [ + 'fv' => ['mailing_name' => 'First%', 'mailing_click_status' => 'Y'], + 'id' => [104, 108, 111, 112], + ], + [ + 'fv' => ['mailing_name' => 'First%', 'mailing_click_status' => 'N'], + 'id' => [102, 103, 105, 109, 110], + ], /*bounce*/ - array( - 'fv' => array( + [ + 'fv' => [ 'mailing_name' => 'Second%', 'mailing_delivery_status' => 'N', - ), - 'id' => array(), - ), + ], + 'id' => [], + ], /*bounce*/ - array( - 'fv' => array( + [ + 'fv' => [ 'mailing_name' => 'Second%', 'mailing_delivery_status' => 'Y', - ), - 'id' => array(102, 103, 104, 108, 109, 110, 111, 112), - ), - array( - 'fv' => array('mailing_name' => 'Second%', 'mailing_reply_status' => 'Y'), - 'id' => array(103), - ), - array( - 'fv' => array('mailing_name' => 'Second%', 'mailing_click_status' => 'Y'), - 'id' => array(104), - ), - array( - 'fv' => array('mailing_name' => 'Second%', 'mailing_click_status' => 'N'), - 'id' => array(102, 103, 108, 109, 110, 111, 112), - ), - array( - 'fv' => array('mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'Y'), - 'id' => array(109, 110, 111, 112), - ), - array( - 'fv' => array('mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'N'), - 'id' => array(102, 103, 104, 105, 108), - ), - array( - 'fv' => array('mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'Y'), - 'id' => array(102), - ), - array( - 'fv' => array('mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'N'), - 'id' => array(103, 104, 108, 109, 110, 111, 112), - ), - ); + ], + 'id' => [102, 103, 104, 108, 109, 110, 111, 112], + ], + [ + 'fv' => ['mailing_name' => 'Second%', 'mailing_reply_status' => 'Y'], + 'id' => [103], + ], + [ + 'fv' => ['mailing_name' => 'Second%', 'mailing_click_status' => 'Y'], + 'id' => [104], + ], + [ + 'fv' => ['mailing_name' => 'Second%', 'mailing_click_status' => 'N'], + 'id' => [102, 103, 108, 109, 110, 111, 112], + ], + [ + 'fv' => ['mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'Y'], + 'id' => [109, 110, 111, 112], + ], + [ + 'fv' => ['mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'N'], + 'id' => [102, 103, 104, 105, 108], + ], + [ + 'fv' => ['mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'Y'], + 'id' => [102], + ], + [ + 'fv' => ['mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'N'], + 'id' => [103, 104, 108, 109, 110, 111, 112], + ], + ]; public function _construct() { $this->i = 0; @@ -123,15 +123,15 @@ class CRM_Mailing_BAO_QueryTestDataProvider implements Iterator { public function current() { $count = count($this->dataset[$this->i]['id']); $ids = $this->dataset[$this->i]['id']; - $full = array(); + $full = []; foreach ($this->dataset[$this->i]['id'] as $key => $value) { - $full[] = array( + $full[] = [ 'contact_id' => $value, 'contact_type' => 'Individual', 'sort_name' => "Test Contact $value", - ); + ]; } - return array($this->dataset[$this->i]['fv'], $count, $ids, $full); + return [$this->dataset[$this->i]['fv'], $count, $ids, $full]; } /** diff --git a/tests/phpunit/CRM/Mailing/BAO/SpoolTest.php b/tests/phpunit/CRM/Mailing/BAO/SpoolTest.php index d2645204bb..b23abe5aef 100644 --- a/tests/phpunit/CRM/Mailing/BAO/SpoolTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/SpoolTest.php @@ -28,31 +28,31 @@ class CRM_Mailing_BAO_SpoolTest extends CiviUnitTestCase { * Basic send. */ public function testSend() { - $contact_params_1 = array( + $contact_params_1 = [ 'first_name' => substr(sha1(rand()), 0, 7), 'last_name' => 'Anderson', 'email' => substr(sha1(rand()), 0, 7) . '@example.org', 'contact_type' => 'Individual', - ); + ]; $contact_id_1 = $this->individualCreate($contact_params_1); - $contact_params_2 = array( + $contact_params_2 = [ 'first_name' => substr(sha1(rand()), 0, 7), 'last_name' => 'Xylophone', 'email' => substr(sha1(rand()), 0, 7) . '@example.org', 'contact_type' => 'Individual', - ); + ]; $contact_id_2 = $this->individualCreate($contact_params_2); $subject = 'Test spool'; - $params = array( + $params = [ 'from' => CRM_Utils_Mail::formatRFC822Email($contact_params_1['first_name'] . " " . $contact_params_1['last_name'], $contact_params_1['email']), 'toName' => $contact_params_2['first_name'] . " " . $contact_params_2['last_name'], 'toEmail' => $contact_params_2['email'], 'subject' => $subject, 'text' => self::$bodytext, 'html' => "

\n" . self::$bodytext . '

', - ); + ]; CRM_Utils_Mail::send($params); @@ -66,7 +66,7 @@ class CRM_Mailing_BAO_SpoolTest extends CiviUnitTestCase { $this->assertContains($contact_params_1['email'], $mail->from->email, 'From address incorrect.'); $this->assertContains($contact_params_2['email'], $mail->to[0]->email, 'Recipient incorrect.'); - $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback')); + $context = new ezcMailPartWalkContext([get_class($this), 'mailWalkCallback']); $mail->walkParts($context, $mail); } diff --git a/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php b/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php index 5b1238a72e..c8bec7e77c 100644 --- a/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php +++ b/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php @@ -44,7 +44,7 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { protected $_apiversion = 3; public $DBResetRequired = FALSE; - public $defaultParams = array(); + public $defaultParams = []; private $_groupID; /** @@ -60,15 +60,15 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { $this->_groupID = $this->groupCreate(); $this->createContactsInGroup(2, $this->_groupID); - $this->defaultParams = array( + $this->defaultParams = [ 'name' => 'mailing name', 'created_id' => 1, - 'groups' => array('include' => array($this->_groupID)), + 'groups' => ['include' => [$this->_groupID]], 'scheduled_date' => 'now', - ); + ]; $this->_mut = new CiviMailUtils($this, TRUE); $this->callAPISuccess('mail_settings', 'get', - array('api.mail_settings.create' => array('domain' => 'chaos.org'))); + ['api.mail_settings.create' => ['domain' => 'chaos.org']]); } /** @@ -85,10 +85,10 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * Generate a fully-formatted mailing with standard email headers. */ public function testBasicHeaders() { - $allMessages = $this->runMailingSuccess(array( + $allMessages = $this->runMailingSuccess([ 'subject' => 'Accidents in cars cause children for {contact.display_name}!', 'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.', - )); + ]); foreach ($allMessages as $k => $message) { /** @var ezcMail $message */ @@ -111,12 +111,12 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * Generate a fully-formatted mailing (with body_text content). */ public function testText() { - $allMessages = $this->runMailingSuccess(array( + $allMessages = $this->runMailingSuccess([ 'subject' => 'Accidents in cars cause children for {contact.display_name}!', 'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.', 'open_tracking' => 1, // Note: open_tracking does nothing with text, but we'll just verify that it does nothing - )); + ]); foreach ($allMessages as $message) { /** @var ezcMail $message */ /** @var ezcMailText $textPart */ @@ -141,12 +141,12 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * Generate a fully-formatted mailing (with body_html content). */ public function testHtmlWithOpenTracking() { - $allMessages = $this->runMailingSuccess(array( + $allMessages = $this->runMailingSuccess([ 'subject' => 'Example Subject', 'body_html' => '

You can go to Google or opt out.

', 'open_tracking' => 1, 'url_tracking' => 0, - )); + ]); foreach ($allMessages as $message) { /** @var ezcMail $message */ /** @var ezcMailText $htmlPart */ @@ -197,12 +197,12 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * Generate a fully-formatted mailing (with body_html content). */ public function testHtmlWithOpenAndUrlTracking() { - $allMessages = $this->runMailingSuccess(array( + $allMessages = $this->runMailingSuccess([ 'subject' => 'Example Subject', 'body_html' => '

You can go to Google or opt out.

', 'open_tracking' => 1, 'url_tracking' => 1, - )); + ]); foreach ($allMessages as $message) { /** @var ezcMail $message */ /** @var ezcMailText $htmlPart */ @@ -256,80 +256,80 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * @return array */ public function urlTrackingExamples() { - $cases = array(); + $cases = []; // Tracking disabled - $cases[] = array( + $cases[] = [ '

Foo

', ';

Foo

;', ';\\[1\\] http://example\.net/;', - array('url_tracking' => 0), - ); - $cases[] = array( + ['url_tracking' => 0], + ]; + $cases[] = [ '

Foo

', // FIXME: Legacy tracker adds extra quote after URL ';

Foo

;', ';\\[1\\] http://example\.net/\?id=\d+;', - array('url_tracking' => 0), - ); - $cases[] = array( + ['url_tracking' => 0], + ]; + $cases[] = [ '

Foo

', ';

Foo

;', ';\\[1\\] http.*civicrm/mailing/optout.*;', - array('url_tracking' => 0), - ); - $cases[] = array( + ['url_tracking' => 0], + ]; + $cases[] = [ '

Look at .

', ';

Look at \.

;', ';Look at \.;', - array('url_tracking' => 0), - ); - $cases[] = array( + ['url_tracking' => 0], + ]; + $cases[] = [ // Plain-text URL's are tracked in plain-text emails... // but not in HTML emails. "

Please go to: http://example.net/

", ";

Please go to: http://example\.net/

;", ';Please go to: http://example\.net/;', - array('url_tracking' => 0), - ); + ['url_tracking' => 0], + ]; // Tracking enabled - $cases[] = array( + $cases[] = [ '

Foo

', ';

Foo

;', ';\\[1\\] .*extern/url\.php\?u=\d+.*;', - array('url_tracking' => 1), - ); - $cases[] = array( + ['url_tracking' => 1], + ]; + $cases[] = [ // FIXME: CiviMail URL tracking doesn't track tokenized links. '

Foo

', // FIXME: Legacy tracker adds extra quote after URL ';

Foo

;', ';\\[1\\] http://example\.net/\?id=\d+;', - array('url_tracking' => 1), - ); - $cases[] = array( + ['url_tracking' => 1], + ]; + $cases[] = [ // It would be redundant/slow to track the action URLs? '

Foo

', ';

Foo

;', ';\\[1\\] http.*civicrm/mailing/optout.*;', - array('url_tracking' => 1), - ); - $cases[] = array( + ['url_tracking' => 1], + ]; + $cases[] = [ // It would be excessive/slow to track every embedded image. '

Look at .

', ';

Look at \.

;', ';Look at \.;', - array('url_tracking' => 1), - ); - $cases[] = array( + ['url_tracking' => 1], + ]; + $cases[] = [ // Plain-text URL's are tracked in plain-text emails... // but not in HTML emails. "

Please go to: http://example.net/

", ";

Please go to: http://example\.net/

;", ';Please go to: .*extern/url.php\?u=\d+&qid=\d+;', - array('url_tracking' => 1), - ); + ['url_tracking' => 1], + ]; return $cases; } @@ -340,12 +340,12 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * @dataProvider urlTrackingExamples */ public function testUrlTracking($inputHtml, $htmlUrlRegex, $textUrlRegex, $params) { - $caseName = print_r(array('inputHtml' => $inputHtml, 'params' => $params), 1); + $caseName = print_r(['inputHtml' => $inputHtml, 'params' => $params], 1); - $allMessages = $this->runMailingSuccess($params + array( + $allMessages = $this->runMailingSuccess($params + [ 'subject' => 'Example Subject', 'body_html' => $inputHtml, - )); + ]); foreach ($allMessages as $message) { /** @var ezcMail $message */ /** @var ezcMailText $htmlPart */ @@ -380,15 +380,15 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { $domain = 'nul.example.com' ) { for ($i = 1; $i <= $count; $i++) { - $contactID = $this->individualCreate(array( + $contactID = $this->individualCreate([ 'first_name' => "Foo{$i}", 'email' => 'mail' . $i . '@' . $domain, - )); - $this->callAPISuccess('group_contact', 'create', array( + ]); + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $contactID, 'group_id' => $groupID, 'status' => 'Added', - )); + ]); } } @@ -402,8 +402,8 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { protected function runMailingSuccess($params) { $mailingParams = array_merge($this->defaultParams, $params); $this->callAPISuccess('mailing', 'create', $mailingParams); - $this->_mut->assertRecipients(array()); - $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE)); + $this->_mut->assertRecipients([]); + $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]); $allMessages = $this->_mut->getAllMessages('ezc'); // There are exactly two contacts produced by setUp(). diff --git a/tests/phpunit/CRM/Mailing/MailingSystemTest.php b/tests/phpunit/CRM/Mailing/MailingSystemTest.php index 0b9193dfc1..a837721461 100644 --- a/tests/phpunit/CRM/Mailing/MailingSystemTest.php +++ b/tests/phpunit/CRM/Mailing/MailingSystemTest.php @@ -56,11 +56,11 @@ class CRM_Mailing_MailingSystemTest extends CRM_Mailing_BaseMailingSystemTest { public function setUp() { parent::setUp(); - Civi::settings()->add(array('experimentalFlexMailerEngine' => FALSE)); + Civi::settings()->add(['experimentalFlexMailerEngine' => FALSE]); $hooks = \CRM_Utils_Hook::singleton(); $hooks->setHook('civicrm_alterMailParams', - array($this, 'hook_alterMailParams')); + [$this, 'hook_alterMailParams']); } /** diff --git a/tests/phpunit/CRM/Mailing/TokensTest.php b/tests/phpunit/CRM/Mailing/TokensTest.php index 8b31fe906e..10d7db76b0 100644 --- a/tests/phpunit/CRM/Mailing/TokensTest.php +++ b/tests/phpunit/CRM/Mailing/TokensTest.php @@ -9,18 +9,18 @@ class CRM_Mailing_TokensTest extends \CiviUnitTestCase { $this->useTransaction(); parent::setUp(); $this->callAPISuccess('mail_settings', 'get', - array('api.mail_settings.create' => array('domain' => 'chaos.org'))); + ['api.mail_settings.create' => ['domain' => 'chaos.org']]); } public function getExampleTokens() { - $cases = array(); + $cases = []; - $cases[] = array('text/plain', 'The {mailing.id}!', ';The [0-9]+!;'); - $cases[] = array('text/plain', 'The {mailing.name}!', ';The Example Name!;'); - $cases[] = array('text/plain', 'The {mailing.editUrl}!', ';The http.*civicrm/mailing/send.*!;'); - $cases[] = array('text/plain', 'To subscribe: {action.subscribeUrl}!', ';To subscribe: http.*civicrm/mailing/subscribe.*!;'); - $cases[] = array('text/plain', 'To optout: {action.optOutUrl}!', ';To optout: http.*civicrm/mailing/optout.*!;'); - $cases[] = array('text/plain', 'To unsubscribe: {action.unsubscribe}!', ';To unsubscribe: u\.123\.456\.abcd1234@chaos.org!;'); + $cases[] = ['text/plain', 'The {mailing.id}!', ';The [0-9]+!;']; + $cases[] = ['text/plain', 'The {mailing.name}!', ';The Example Name!;']; + $cases[] = ['text/plain', 'The {mailing.editUrl}!', ';The http.*civicrm/mailing/send.*!;']; + $cases[] = ['text/plain', 'To subscribe: {action.subscribeUrl}!', ';To subscribe: http.*civicrm/mailing/subscribe.*!;']; + $cases[] = ['text/plain', 'To optout: {action.optOutUrl}!', ';To optout: http.*civicrm/mailing/optout.*!;']; + $cases[] = ['text/plain', 'To unsubscribe: {action.unsubscribe}!', ';To unsubscribe: u\.123\.456\.abcd1234@chaos.org!;']; // TODO: Think about supporting dynamic tokens like "{action.subscribe.\d+}" @@ -38,24 +38,24 @@ class CRM_Mailing_TokensTest extends \CiviUnitTestCase { * @dataProvider getExampleTokens */ public function testTokensWithMailingId($inputTemplateFormat, $inputTemplate, $expectRegex) { - $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', array( + $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', [ 'name' => 'Example Name', - )); + ]); $contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact'); - $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), array( + $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), [ 'mailingId' => $mailing->id, - )); + ]); $p->addMessage('example', $inputTemplate, $inputTemplateFormat); - $p->addRow()->context(array( + $p->addRow()->context([ 'contactId' => $contact->id, 'mailingJobId' => 123, - 'mailingActionTarget' => array( + 'mailingActionTarget' => [ 'id' => 456, 'hash' => 'abcd1234', 'email' => 'someone@example.com', - ), - )); + ], + ]); $p->evaluate(); $count = 0; foreach ($p->getRows() as $row) { @@ -75,24 +75,24 @@ class CRM_Mailing_TokensTest extends \CiviUnitTestCase { $inputTemplate = 'To optout: {action.optOutUrl}!'; $expectRegex = ';To optout: http.*civicrm/mailing/optout.*!;'; - $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', array( + $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', [ 'name' => 'Example Name', - )); + ]); $contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact'); - $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), array( + $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), [ 'mailing' => $mailing, - )); + ]); $p->addMessage('example', $inputTemplate, $inputTemplateFormat); - $p->addRow()->context(array( + $p->addRow()->context([ 'contactId' => $contact->id, 'mailingJobId' => 123, - 'mailingActionTarget' => array( + 'mailingActionTarget' => [ 'id' => 456, 'hash' => 'abcd1234', 'email' => 'someone@example.com', - ), - )); + ], + ]); $p->evaluate(); $count = 0; foreach ($p->getRows() as $row) { @@ -121,18 +121,18 @@ class CRM_Mailing_TokensTest extends \CiviUnitTestCase { * @dataProvider getExampleTokensForUseWithoutMailingJob */ public function testTokensWithoutMailingJob($inputTemplateFormat, $inputTemplateText, $expectRegex) { - $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', array( + $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', [ 'name' => 'Example Name', - )); + ]); $contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact'); - $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), array( + $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), [ 'mailing' => $mailing, - )); + ]); $p->addMessage('example', $inputTemplateText, $inputTemplateFormat); - $p->addRow()->context(array( + $p->addRow()->context([ 'contactId' => $contact->id, - )); + ]); // try { // $p->evaluate(); // $this->fail('TokenProcessor::evaluate() should have thrown an exception'); diff --git a/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php b/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php index 7c1fda9927..1b7c27a792 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php @@ -35,17 +35,17 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $params = array( + $params = [ 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', 'name_a_b' => 'Test Employee of', 'name_b_a' => 'Test Employer of', - ); + ]; $this->_relationshipTypeId = $this->relationshipTypeCreate($params); $this->_orgContactID = $this->organizationCreate(); $this->_financialTypeId = 1; - $params = array( + $params = [ 'name' => 'test type', 'description' => NULL, 'minimum_fee' => 10, @@ -57,8 +57,8 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); - $ids = array(); + ]; + $ids = []; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); $this->_membershipTypeID = $membershipType->id; $this->_mebershipStatusID = $this->membershipStatusCreate('test status'); @@ -70,7 +70,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { */ public function tearDown() { $this->relationshipTypeDelete($this->_relationshipTypeId); - $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); + $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); $this->membershipStatusDelete($this->_mebershipStatusID); $this->contactDelete($this->_orgContactID); } @@ -81,7 +81,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { public function testadd() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -90,9 +90,9 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_mebershipStatusID, - ); + ]; - $ids = array(); + $ids = []; $membership = CRM_Member_BAO_Membership::create($params, $ids); $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $membership->id, 'membership_id', 'id', @@ -109,7 +109,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { public function testdel() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -118,10 +118,10 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_mebershipStatusID, - ); - $ids = array( + ]; + $ids = [ 'userId' => $contactId, - ); + ]; $membership = CRM_Member_BAO_Membership::create($params, $ids); $membershipDelete = CRM_Member_BAO_MembershipLog::del($membership->id); $this->assertDBNull('CRM_Member_BAO_MembershipLog', $membership->id, 'membership_id', @@ -138,7 +138,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { public function testresetmodifiedId() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -147,10 +147,10 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_mebershipStatusID, - ); - $ids = array( + ]; + $ids = [ 'userId' => $contactId, - ); + ]; $membership = CRM_Member_BAO_Membership::create($params, $ids); $resetModifiedId = CRM_Member_BAO_MembershipLog::resetModifiedID($contactId); $this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactId, 'modified_id', diff --git a/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php b/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php index 777ced84f2..5286129969 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php @@ -39,10 +39,10 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { * Check function add() */ public function testAdd() { - $params = array( + $params = [ 'name' => 'pending', 'is_active' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); @@ -55,33 +55,33 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { public function testRetrieve() { - $params = array( + $params = [ 'name' => 'testStatus', 'is_active' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); - $defaults = array(); + $defaults = []; $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults); $this->assertEquals($result->name, 'testStatus', 'Verify membership status name.'); CRM_Member_BAO_MembershipStatus::del($membershipStatus->id); } public function testPseudoConstantflush() { - $params = array( + $params = [ 'name' => 'testStatus', 'is_active' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); - $defaults = array(); + $defaults = []; $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults); $this->assertEquals($result->name, 'testStatus', 'Verify membership status name.'); - $updateParams = array( + $updateParams = [ 'id' => $membershipStatus->id, 'name' => 'testStatus', 'label' => 'Changed Status', 'is_active' => 1, - ); + ]; $membershipStatus2 = CRM_Member_BAO_MembershipStatus::add($updateParams); $result = CRM_Member_PseudoConstant::membershipStatus($membershipStatus->id, NULL, 'label', FALSE, FALSE); $this->assertEquals($result, 'Changed Status', 'Verify updated membership status label From PseudoConstant.'); @@ -90,10 +90,10 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { public function testSetIsActive() { - $params = array( + $params = [ 'name' => 'pending', 'is_active' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); $result = CRM_Member_BAO_MembershipStatus::setIsActive($membershipStatus->id, 0); @@ -107,10 +107,10 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { } public function testGetMembershipStatus() { - $params = array( + $params = [ 'name' => 'pending', 'is_active' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); $result = CRM_Member_BAO_MembershipStatus::getMembershipStatus($membershipStatus->id); @@ -118,14 +118,14 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { } public function testDel() { - $params = array( + $params = [ 'name' => 'testStatus', 'is_active' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); CRM_Member_BAO_MembershipStatus::del($membershipStatus->id); - $defaults = array(); + $defaults = []; $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify membership status record deletion.'); } @@ -173,12 +173,12 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { } public function testGetMembershipStatusByDate() { - $params = array( + $params = [ 'name' => 'Current', 'is_active' => 1, 'start_event' => 'start_date', 'end_event' => 'end_date', - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); $toDate = date('Ymd'); @@ -188,11 +188,11 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { } public function testgetMembershipStatusCurrent() { - $params = array( + $params = [ 'name' => 'Current', 'is_active' => 1, 'is_current_member' => 1, - ); + ]; $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params); $result = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent(); diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index edea7ade40..cf50231bba 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -34,24 +34,24 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together - $GLOBALS['_HTML_QuickForm_registered_rules'] = array( - 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'), - 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), - 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'), - 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'), - ); + $GLOBALS['_HTML_QuickForm_registered_rules'] = [ + 'required' => ['html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'], + 'maxlength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'], + 'minlength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'], + 'rangelength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'], + 'email' => ['html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'], + 'regex' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], + 'lettersonly' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], + 'alphanumeric' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], + 'numeric' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], + 'nopunctuation' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], + 'nonzero' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], + 'callback' => ['html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'], + 'compare' => ['html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'], + ]; $this->_contactID = $this->organizationCreate(); - $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); + $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); // add a random number to avoid silly conflicts with old data $this->_membershipStatusID = $this->membershipStatusCreate('test status' . rand(1, 1000)); } @@ -61,7 +61,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * This method is called after a test is executed. */ public function tearDown() { - $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); + $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); $this->membershipStatusDelete($this->_membershipStatusID); $this->contactDelete($this->_contactID); @@ -75,7 +75,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * @return array|int */ private function createMembershipType($organizationId, $withRelationship = FALSE) { - $membershipType = $this->callAPISuccess('MembershipType', 'create', array( + $membershipType = $this->callAPISuccess('MembershipType', 'create', [ //Default domain ID 'domain_id' => 1, 'member_of_contact_id' => $organizationId, @@ -86,7 +86,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'name' => "Organiation Membership Type", 'relationship_type_id' => ($withRelationship) ? 5 : NULL, 'relationship_direction' => ($withRelationship) ? 'b_a' : NULL, - )); + ]); return $membershipType["values"][$membershipType["id"]]; } @@ -96,9 +96,9 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * @return array|int */ private function getRelatedMembershipsCount($membershipId) { - return $this->callAPISuccess("Membership", "getcount", array( + return $this->callAPISuccess("Membership", "getcount", [ 'owner_membership_id' => $membershipId, - )); + ]); } /** @@ -112,24 +112,24 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $organizationId = $this->organizationCreate(); // Create relationship between organization and individual contact - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ // Employer of relationship 'relationship_type_id' => 5, 'contact_id_a' => $contactId, 'contact_id_b' => $organizationId, 'is_active' => 1, - )); + ]); // Create two membership types one with relationship and one without. $membershipTypeWithRelationship = $this->createMembershipType($membershipOrganizationId, TRUE); $membershipTypeWithoutRelationship = $this->createMembershipType($membershipOrganizationId); // Creating membership of organisation - $membership = $this->callAPISuccess("Membership", "create", array( + $membership = $this->callAPISuccess("Membership", "create", [ 'membership_type_id' => $membershipTypeWithRelationship["id"], 'contact_id' => $organizationId, 'status_id' => $this->_membershipStatusID, - )); + ]); $membership = $membership["values"][$membership["id"]]; @@ -153,7 +153,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -162,8 +162,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -172,8 +172,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { // Now call create() to modify an existing Membership - $params = array(); - $params = array( + $params = []; + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -182,10 +182,10 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array( + ]; + $ids = [ 'membership' => $membershipId, - ); + ]; CRM_Member_BAO_Membership::create($params, $ids); $membershipTypeId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, @@ -208,7 +208,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd'), @@ -217,16 +217,16 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; - $ids = array(); + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.' ); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', $last_month), @@ -235,16 +235,16 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Source123', 'is_override' => 0, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'source123', 'id', 'source', 'Database check for created membership.' ); - $membership = array('contact_id' => $contactId); - $membershipValues = array(); + $membership = ['contact_id' => $contactId]; + $membershipValues = []; CRM_Member_BAO_Membership::getValues($membership, $membershipValues, TRUE); $this->assertEquals($membershipValues[$membershipId1]['membership_id'], $membershipId1, 'Verify membership record 1 is fetched.'); @@ -259,7 +259,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testRetrieve() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -268,15 +268,15 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.' ); - $params = array('id' => $membershipId); - $values = array(); + $params = ['id' => $membershipId]; + $values = []; CRM_Member_BAO_Membership::retrieve($params, $values); $this->assertEquals($values['id'], $membershipId, 'Verify membership record is retrieved.'); @@ -287,7 +287,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testActiveMembers() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -296,20 +296,20 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.' ); - $params = array('id' => $membershipId1); - $values1 = array(); + $params = ['id' => $membershipId1]; + $values1 = []; CRM_Member_BAO_Membership::retrieve($params, $values1); - $membership = array($membershipId1 => $values1); + $membership = [$membershipId1 => $values1]; - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -318,16 +318,16 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'PaySource', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'PaySource', 'id', 'source', 'Database check for created membership.' ); - $params = array('id' => $membershipId2); - $values2 = array(); + $params = ['id' => $membershipId2]; + $values2 = []; CRM_Member_BAO_Membership::retrieve($params, $values2); $membership[$membershipId2] = $values2; @@ -347,7 +347,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testDeleteMembership() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -356,8 +356,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -374,7 +374,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testGetContactMembership() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -383,8 +383,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -406,7 +406,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testgetContributionPageId() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -415,8 +415,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -436,7 +436,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testgetMembershipStarts() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -445,8 +445,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -467,7 +467,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testGetMembershipCount() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -476,8 +476,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -497,7 +497,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testSortName() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2006-01-21', @@ -506,7 +506,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $membership = $this->callAPISuccess('Membership', 'create', $params); @@ -522,7 +522,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testdeleteRelatedMemberships() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), @@ -531,8 +531,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; CRM_Member_BAO_Membership::create($params, $ids); @@ -553,7 +553,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $contactId = $this->individualCreate(); $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -6 month")); $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => $joinDate, @@ -562,8 +562,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; $membership = CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.' @@ -620,7 +620,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $contactId = $this->individualCreate(); $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -1 year -15 days")); $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => $joinDate, @@ -628,9 +628,9 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'end_date' => $endDate, 'source' => 'Payment', 'status_id' => $statusId, - ); + ]; - $ids = array(); + $ids = []; $membership = CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', @@ -643,11 +643,11 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { ); //verify all dates. - $dates = array( + $dates = [ 'startDate' => 'start_date', 'joinDate' => 'join_date', 'endDate' => 'end_date', - ); + ]; foreach ($dates as $date => $dbDate) { $this->assertEquals($membership->$dbDate, $$date, @@ -697,7 +697,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testUpdateAllMembershipStatusConvertExpiredOverriddenStatusToNormal() { - $params = array( + $params = [ 'contact_id' => $this->individualCreate(), 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', time()), @@ -707,17 +707,17 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'is_override' => 1, 'status_override_end_date' => date('Ymd', strtotime('-1 day')), 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; $createdMembership = CRM_Member_BAO_Membership::create($params, $ids); CRM_Member_BAO_Membership::updateAllMembershipStatus(); - $membershipAfterProcess = civicrm_api3('Membership', 'get', array( + $membershipAfterProcess = civicrm_api3('Membership', 'get', [ 'sequential' => 1, 'id' => $createdMembership->id, - 'return' => array('id', 'is_override', 'status_override_end_date'), - ))['values'][0]; + 'return' => ['id', 'is_override', 'status_override_end_date'], + ])['values'][0]; $this->assertEquals($createdMembership->id, $membershipAfterProcess['id']); $this->assertArrayNotHasKey('is_override', $membershipAfterProcess); @@ -725,7 +725,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testUpdateAllMembershipStatusHandleOverriddenWithEndOverrideDateEqualTodayAsExpired() { - $params = array( + $params = [ 'contact_id' => $this->individualCreate(), 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', time()), @@ -735,17 +735,17 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'is_override' => 1, 'status_override_end_date' => date('Ymd', time()), 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; $createdMembership = CRM_Member_BAO_Membership::create($params, $ids); CRM_Member_BAO_Membership::updateAllMembershipStatus(); - $membershipAfterProcess = civicrm_api3('Membership', 'get', array( + $membershipAfterProcess = civicrm_api3('Membership', 'get', [ 'sequential' => 1, 'id' => $createdMembership->id, - 'return' => array('id', 'is_override', 'status_override_end_date'), - ))['values'][0]; + 'return' => ['id', 'is_override', 'status_override_end_date'], + ])['values'][0]; $this->assertEquals($createdMembership->id, $membershipAfterProcess['id']); $this->assertArrayNotHasKey('is_override', $membershipAfterProcess); @@ -753,7 +753,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testUpdateAllMembershipStatusDoesNotConvertOverridenMembershipWithoutEndOverrideDateToNormal() { - $params = array( + $params = [ 'contact_id' => $this->individualCreate(), 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', time()), @@ -762,17 +762,17 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; $createdMembership = CRM_Member_BAO_Membership::create($params, $ids); CRM_Member_BAO_Membership::updateAllMembershipStatus(); - $membershipAfterProcess = civicrm_api3('Membership', 'get', array( + $membershipAfterProcess = civicrm_api3('Membership', 'get', [ 'sequential' => 1, 'id' => $createdMembership->id, - 'return' => array('id', 'is_override', 'status_override_end_date'), - ))['values'][0]; + 'return' => ['id', 'is_override', 'status_override_end_date'], + ])['values'][0]; $this->assertEquals($createdMembership->id, $membershipAfterProcess['id']); $this->assertEquals(1, $membershipAfterProcess['is_override']); diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php index 64dd0c0725..892adaa0a8 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php @@ -35,14 +35,14 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { parent::setUp(); //create relationship - $params = array( + $params = [ 'name_a_b' => 'Relation 1', 'name_b_a' => 'Relation 2', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $this->_relationshipTypeId = $this->relationshipTypeCreate($params); $this->_orgContactID = $this->organizationCreate(); $this->_indiviContactID = $this->individualCreate(); @@ -66,8 +66,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testAdd() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'test type', 'domain_id' => 1, 'description' => NULL, @@ -79,7 +79,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'financial_type_id' => $this->_financialTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', - ); + ]; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); @@ -89,7 +89,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { ); $this->assertEquals($membership, 'test type', 'Verify membership type name.'); - $this->membershipTypeDelete(array('id' => $membershipType->id)); + $this->membershipTypeDelete(['id' => $membershipType->id]); } /** @@ -97,8 +97,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testRetrieve() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'domain_id' => 1, @@ -110,14 +110,14 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'financial_type_id' => $this->_financialTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', - ); + ]; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); - $params = array('name' => 'General'); - $default = array(); + $params = ['name' => 'General']; + $default = []; $result = CRM_Member_BAO_MembershipType::retrieve($params, $default); $this->assertEquals($result->name, 'General', 'Verify membership type name.'); - $this->membershipTypeDelete(array('id' => $membershipType->id)); + $this->membershipTypeDelete(['id' => $membershipType->id]); } /** @@ -125,8 +125,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testSetIsActive() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'domain_id' => 1, @@ -139,7 +139,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membership = CRM_Member_BAO_MembershipType::add($params, $ids); CRM_Member_BAO_MembershipType::setIsActive($membership->id, 0); @@ -150,7 +150,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { ); $this->assertEquals($isActive, 0, 'Verify membership type status.'); - $this->membershipTypeDelete(array('id' => $membership->id)); + $this->membershipTypeDelete(['id' => $membership->id]); } /** @@ -158,8 +158,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testdel() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'minimum_fee' => 100, @@ -172,7 +172,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membership = CRM_Member_BAO_MembershipType::add($params, $ids); $result = CRM_Member_BAO_MembershipType::del($membership->id); @@ -185,8 +185,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testConvertDayFormat() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'minimum_fee' => 100, @@ -201,14 +201,14 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membership = CRM_Member_BAO_MembershipType::add($params, $ids); $membershipType[$membership->id] = $params; CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); $this->assertEquals($membershipType[$membership->id]['fixed_period_rollover_day'], 'Dec 14', 'Verify memberFixed Period Rollover Day.'); - $this->membershipTypeDelete(array('id' => $membership->id)); + $this->membershipTypeDelete(['id' => $membership->id]); } /** @@ -216,8 +216,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testGetMembershipTypes() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'minimum_fee' => 100, @@ -230,11 +230,11 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membership = CRM_Member_BAO_MembershipType::add($params, $ids); $result = CRM_Member_BAO_MembershipType::getMembershipTypes(); $this->assertEquals($result[$membership->id], 'General', 'Verify membership types.'); - $this->membershipTypeDelete(array('id' => $membership->id)); + $this->membershipTypeDelete(['id' => $membership->id]); } /** @@ -242,8 +242,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testGetMembershipTypeDetails() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'minimum_fee' => 100, @@ -256,13 +256,13 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membership = CRM_Member_BAO_MembershipType::add($params, $ids); $result = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membership->id); $this->assertEquals($result['name'], 'General', 'Verify membership type details.'); $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.'); - $this->membershipTypeDelete(array('id' => $membership->id)); + $this->membershipTypeDelete(['id' => $membership->id]); } /** @@ -270,8 +270,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testGetDatesForMembershipType() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'minimum_fee' => 100, @@ -284,12 +284,12 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membership = CRM_Member_BAO_MembershipType::add($params, $ids); $membershipDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->id); $this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.'); - $this->membershipTypeDelete(array('id' => $membership->id)); + $this->membershipTypeDelete(['id' => $membership->id]); } /** @@ -297,8 +297,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testGetRenewalDatesForMembershipType() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'domain_id' => 1, 'description' => NULL, @@ -311,10 +311,10 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); - $params = array( + $params = [ 'contact_id' => $this->_indiviContactID, 'membership_type_id' => $membershipType->id, 'join_date' => '20060121000000', @@ -323,8 +323,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); - $ids = array(); + ]; + $ids = []; $membership = CRM_Member_BAO_Membership::create($params, $ids); $membershipRenewDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id); @@ -333,7 +333,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { $this->assertEquals($membershipRenewDates['end_date'], '20080120', 'Verify membership renewal end date.'); $this->membershipDelete($membership->id); - $this->membershipTypeDelete(array('id' => $membershipType->id)); + $this->membershipTypeDelete(['id' => $membershipType->id]); } /** @@ -341,8 +341,8 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { * */ public function testGetMembershipTypesByOrg() { - $ids = array(); - $params = array( + $ids = []; + $params = [ 'name' => 'General', 'description' => NULL, 'domain_id' => 1, @@ -355,28 +355,28 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); - $membershipTypesResult = civicrm_api3('MembershipType', 'get', array( + $membershipTypesResult = civicrm_api3('MembershipType', 'get', [ 'member_of_contact_id' => $this->_orgContactID, - 'options' => array( + 'options' => [ 'limit' => 0, - ), - )); + ], + ]); $result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL); $this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.'); - $membershipTypesResult = civicrm_api3('MembershipType', 'get', array( + $membershipTypesResult = civicrm_api3('MembershipType', 'get', [ 'member_of_contact_id' => 501, - 'options' => array( + 'options' => [ 'limit' => 0, - ), - )); + ], + ]); $result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL); $this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.'); - $this->membershipTypeDelete(array('id' => $membershipType->id)); + $this->membershipTypeDelete(['id' => $membershipType->id]); } } diff --git a/tests/phpunit/CRM/Member/BAO/QueryTest.php b/tests/phpunit/CRM/Member/BAO/QueryTest.php index 0d52c59c35..0d1df9c75f 100644 --- a/tests/phpunit/CRM/Member/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Member/BAO/QueryTest.php @@ -23,11 +23,11 @@ class CRM_Member_BAO_QueryTest extends CiviUnitTestCase { * 1) membership_type_id => 1 */ public function testConvertEntityFieldSingleValue() { - $formValues = array('membership_type_id' => 2); - $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id')); - $this->assertEquals(array('membership_type_id', '=', 2, 0, 0), $params[0]); + $formValues = ['membership_type_id' => 2]; + $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']); + $this->assertEquals(['membership_type_id', '=', 2, 0, 0], $params[0]); $obj = new CRM_Contact_BAO_Query($params); - $this->assertEquals(array('civicrm_membership.membership_type_id = 2'), $obj->_where[0]); + $this->assertEquals(['civicrm_membership.membership_type_id = 2'], $obj->_where[0]); } /** @@ -39,11 +39,11 @@ class CRM_Member_BAO_QueryTest extends CiviUnitTestCase { * The last of these is the format used prior to converting membership_type_id to an entity reference field. */ public function testConvertEntityFieldMultipleValueEntityRef() { - $formValues = array('membership_type_id' => '1,2'); - $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id')); - $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]); + $formValues = ['membership_type_id' => '1,2']; + $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']); + $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]); $obj = new CRM_Contact_BAO_Query($params); - $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]); + $this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]); } /** @@ -56,11 +56,11 @@ class CRM_Member_BAO_QueryTest extends CiviUnitTestCase { * be used by pre-existing smart groups. */ public function testConvertEntityFieldMultipleValueLegacy() { - $formValues = array('membership_type_id' => array(1, 2)); - $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id')); - $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]); + $formValues = ['membership_type_id' => [1, 2]]; + $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']); + $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]); $obj = new CRM_Contact_BAO_Query($params); - $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]); + $this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]); } /** @@ -71,13 +71,13 @@ class CRM_Member_BAO_QueryTest extends CiviUnitTestCase { * The convertFormValues function should cope with this until such time as we can rationalise that. */ public function testConvertEntityFieldMultipleValueEntityRefDoubleRun() { - $formValues = array('membership_type_id' => '1,2'); - $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id')); - $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]); - $params = CRM_Contact_BAO_Query::convertFormValues($params, 0, FALSE, NULL, array('membership_type_id')); - $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]); + $formValues = ['membership_type_id' => '1,2']; + $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']); + $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]); + $params = CRM_Contact_BAO_Query::convertFormValues($params, 0, FALSE, NULL, ['membership_type_id']); + $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]); $obj = new CRM_Contact_BAO_Query($params); - $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]); + $this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]); } } diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index d05442136c..94405ce678 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -87,7 +87,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $this->_paymentProcessorID = $this->processorCreate(); $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml'); - $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array( + $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [ 'domain_id' => 1, 'name' => "AnnualFixed", 'member_of_contact_id' => 23, @@ -98,12 +98,12 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'fixed_period_rollover_day' => "1231", 'relationship_type_id' => 20, 'financial_type_id' => 2, - )); + ]); $this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id']; - $membership = $this->callAPISuccess('Membership', 'create', array( + $membership = $this->callAPISuccess('Membership', 'create', [ 'contact_id' => $this->_individualId, 'membership_type_id' => $this->membershipTypeAnnualFixedID, - )); + ]); $this->_membershipID = $membership['id']; $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); @@ -116,18 +116,18 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { public function tearDown() { $this->quickCleanUpFinancialEntities(); $this->quickCleanup( - array( + [ 'civicrm_relationship', 'civicrm_membership_type', 'civicrm_membership', 'civicrm_uf_match', 'civicrm_address', - ) + ] ); - foreach (array(17, 18, 23, 32) as $contactID) { - $this->callAPISuccess('contact', 'delete', array('id' => $contactID, 'skip_undelete' => TRUE)); + foreach ([17, 18, 23, 32] as $contactID) { + $this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]); } - $this->callAPISuccess('relationship_type', 'delete', array('id' => 20)); + $this->callAPISuccess('relationship_type', 'delete', ['id' => 20]); } /** @@ -142,7 +142,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '1', @@ -157,11 +157,11 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessorID, 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '9', // TODO: Future proof 'Y' => '2024', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Test', 'billing_middlename' => 'Last', @@ -175,27 +175,27 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $form->testSubmit($params); $form->setRenewalMessage(); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0); - $contribution = $this->callAPISuccess('Contribution', 'get', array( + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 0); + $contribution = $this->callAPISuccess('Contribution', 'get', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, - )); + ]); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); - $this->_checkFinancialRecords(array( + ], 1); + $this->_checkFinancialRecords([ 'id' => $contribution['id'], 'total_amount' => 50, 'financial_account_id' => 2, - 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( + 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $this->_paymentProcessorID, 'return' => 'payment_instrument_id', - )), - ), 'online'); + ]), + ], 'online'); $this->assertEquals([ [ 'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been renewed.', @@ -212,15 +212,15 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { public function testSubmitRecur() { $form = $this->getForm(); - $this->callAPISuccess('MembershipType', 'create', array( + $this->callAPISuccess('MembershipType', 'create', [ 'id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', 'duration_interval' => 1, 'auto_renew' => TRUE, - )); + ]); $form->preProcess(); $this->createLoggedInUser(); - $params = array( + $params = [ 'cid' => $this->_individualId, 'price_set_id' => 0, 'join_date' => date('m/d/Y', time()), @@ -228,7 +228,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'end_date' => '', 'campaign_id' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '1', 'is_recur' => 1, 'max_related' => 0, @@ -244,11 +244,11 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessorID, 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '9', // TODO: Future proof 'Y' => '2019', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Test', 'billing_middlename' => 'Last', @@ -258,46 +258,46 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'billing_postal_code-5' => '90210', 'billing_country_id-5' => '1228', 'send_receipt' => 1, - ); + ]; $form->_mode = 'test'; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); $this->assertEquals(1, $contributionRecur['is_email_receipt']); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date']))); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date']))); $this->assertNotEmpty($contributionRecur['invoice_id']); $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), $contributionRecur['contribution_status_id']); - $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', array( + $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $this->_paymentProcessorID, 'return' => 'payment_instrument_id', - )), $contributionRecur['payment_instrument_id']); + ]), $contributionRecur['payment_instrument_id']); - $contribution = $this->callAPISuccess('Contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('Contribution', 'getsingle', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, - )); + ]); - $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', array( + $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $this->_paymentProcessorID, 'return' => 'payment_instrument_id', - )), $contribution['payment_instrument_id']); + ]), $contribution['payment_instrument_id']); $this->assertEquals($contributionRecur['id'], $contribution['contribution_recur_id']); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); + ], 1); - $this->callAPISuccessGetSingle('address', array( + $this->callAPISuccessGetSingle('address', [ 'contact_id' => $this->_individualId, 'street_address' => '10 Test St', 'postal_code' => 90210, - )); + ]); } /** @@ -307,18 +307,18 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $form = $this->getForm(); /** @var \CRM_Core_Payment_Dummy $processor */ $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); - $processor->setDoDirectPaymentResult(array( + $processor->setDoDirectPaymentResult([ 'payment_status_id' => 1, 'trxn_id' => 'kettles boil water', 'fee_amount' => .29, - )); + ]); - $this->callAPISuccess('MembershipType', 'create', array( + $this->callAPISuccess('MembershipType', 'create', [ 'id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', 'duration_interval' => 1, 'auto_renew' => TRUE, - )); + ]); $this->createLoggedInUser(); $form->preProcess(); @@ -327,8 +327,8 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $form->_mode = 'test'; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); $this->assertEquals($contributionRecur['id'], $membership['contribution_recur_id']); $this->assertEquals(0, $contributionRecur['is_email_receipt']); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date']))); @@ -339,16 +339,16 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'In Progress'), $contributionRecur['contribution_status_id']); $this->assertNotEmpty($contributionRecur['next_sched_contribution_date']); */ - $paymentInstrumentID = $this->callAPISuccessGetValue('PaymentProcessor', array( + $paymentInstrumentID = $this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $this->_paymentProcessorID, 'return' => 'payment_instrument_id', - )); + ]); $this->assertEquals($paymentInstrumentID, $contributionRecur['payment_instrument_id']); - $contribution = $this->callAPISuccess('Contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('Contribution', 'getsingle', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, - )); + ]); $this->assertEquals($paymentInstrumentID, $contribution['payment_instrument_id']); $this->assertEquals('kettles boil water', $contribution['trxn_id']); @@ -356,11 +356,11 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $this->assertEquals(7800.90, $contribution['total_amount']); $this->assertEquals(7800.61, $contribution['net_amount']); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); + ], 1); } /** @@ -376,18 +376,18 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $this->mut = new CiviMailUtils($this, TRUE); /** @var \CRM_Core_Payment_Dummy $processor */ $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); - $processor->setDoDirectPaymentResult(array( + $processor->setDoDirectPaymentResult([ 'payment_status_id' => 1, 'trxn_id' => 'kettles boil water', 'fee_amount' => .29, - )); + ]); - $this->callAPISuccess('MembershipType', 'create', array( + $this->callAPISuccess('MembershipType', 'create', [ 'id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', 'duration_interval' => 1, 'auto_renew' => TRUE, - )); + ]); $this->createLoggedInUser(); $form->preProcess(); @@ -397,7 +397,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $form->_mode = 'test'; $form->testSubmit($params); - $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId)); + $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); $this->assertEquals(1, $contributionRecur['is_email_receipt']); $this->mut->checkMailLog([ '$ ' . $this->formatMoneyInput(7800.90), @@ -412,14 +412,14 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { public function testSubmitPayLater() { $form = $this->getForm(NULL); $this->createLoggedInUser(); - $originalMembership = $this->callAPISuccessGetSingle('membership', array()); - $params = array( + $originalMembership = $this->callAPISuccessGetSingle('membership', []); + $params = [ 'cid' => $this->_individualId, 'join_date' => date('m/d/Y', time()), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '2', @@ -436,25 +436,25 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'record_contribution' => TRUE, 'trxn_id' => 777, 'contribution_status_id' => 2, - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date'])); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 2, - 'return' => array("tax_amount", "trxn_id"), - )); + 'return' => ["tax_amount", "trxn_id"], + ]); $this->assertEquals($contribution['trxn_id'], 777); $this->assertEquals($contribution['tax_amount'], NULL); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); + ], 1); } /** @@ -463,14 +463,14 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { public function testSubmitPayLaterWithBilling() { $form = $this->getForm(NULL); $this->createLoggedInUser(); - $originalMembership = $this->callAPISuccessGetSingle('membership', array()); - $params = array( + $originalMembership = $this->callAPISuccessGetSingle('membership', []); + $params = [ 'cid' => $this->_individualId, 'join_date' => date('m/d/Y', time()), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '2', @@ -494,28 +494,28 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'billing_state_province_id-5' => '1003', 'billing_postal_code-5' => '90210', 'billing_country_id-5' => '1228', - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date'])); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 2, - )); + ]); $this->assertEquals($contribution['trxn_id'], 777); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); - $this->callAPISuccessGetSingle('address', array( + ], 1); + $this->callAPISuccessGetSingle('address', [ 'contact_id' => $this->_individualId, 'street_address' => '10 Test St', 'postal_code' => 90210, - )); + ]); } /** @@ -524,14 +524,14 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { public function testSubmitComplete() { $form = $this->getForm(NULL); $this->createLoggedInUser(); - $originalMembership = $this->callAPISuccessGetSingle('membership', array()); - $params = array( + $originalMembership = $this->callAPISuccessGetSingle('membership', []); + $params = [ 'cid' => $this->_individualId, 'join_date' => date('m/d/Y', time()), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '2', @@ -549,25 +549,25 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'trxn_id' => 777, 'contribution_status_id' => 1, 'fee_amount' => .5, - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->assertEquals(strtotime($membership['end_date']), strtotime('+ 2 years', strtotime($originalMembership['end_date']))); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 1, - )); + ]); $this->assertEquals($contribution['trxn_id'], 777); $this->assertEquals(.5, $contribution['fee_amount']); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); + ], 1); } /** @@ -596,7 +596,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { * @return array */ protected function getBaseSubmitParams() { - $params = array( + $params = [ 'cid' => $this->_individualId, 'price_set_id' => 0, 'join_date' => date('m/d/Y', time()), @@ -604,7 +604,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'end_date' => '', 'campaign_id' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '1', 'is_recur' => 1, 'max_related' => 0, @@ -620,11 +620,11 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessorID, 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '9', // TODO: Future proof 'Y' => '2019', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Test', 'billing_middlename' => 'Last', @@ -633,7 +633,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'billing_state_province_id-5' => '1003', 'billing_postal_code-5' => '90210', 'billing_country_id-5' => '1228', - ); + ]; return $params; } diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index f00b4fa1be..ef3d5e05de 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -47,7 +47,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { protected $_apiversion; protected $_entity = 'Membership'; protected $_params; - protected $_ids = array(); + protected $_ids = []; protected $_paymentProcessorID; /** @@ -62,7 +62,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * * @var array */ - protected $_processorParams = array(); + protected $_processorParams = []; /** * ID of created membership. @@ -76,7 +76,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * * @var array */ - protected $paymentInstruments = array(); + protected $paymentInstruments = []; /** * @var CiviMailUtils @@ -98,7 +98,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml'); - $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array( + $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [ 'domain_id' => 1, 'name' => "AnnualFixed", 'member_of_contact_id' => 23, @@ -110,10 +110,10 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'fixed_period_rollover_day' => "1231", 'relationship_type_id' => 20, 'financial_type_id' => 2, - )); + ]); $this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id']; - $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); $this->paymentInstruments = $instruments['values']; } @@ -123,18 +123,18 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function tearDown() { $this->quickCleanUpFinancialEntities(); $this->quickCleanup( - array( + [ 'civicrm_relationship', 'civicrm_membership_type', 'civicrm_membership', 'civicrm_uf_match', 'civicrm_email', - ) + ] ); - foreach (array(17, 18, 23, 32) as $contactID) { - $this->callAPISuccess('contact', 'delete', array('id' => $contactID, 'skip_undelete' => TRUE)); + foreach ([17, 18, 23, 32] as $contactID) { + $this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]); } - $this->callAPISuccess('relationship_type', 'delete', array('id' => 20)); + $this->callAPISuccess('relationship_type', 'delete', ['id' => 20]); } /** @@ -142,17 +142,17 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * that has an empty contact_select_id value */ public function testFormRuleEmptyContact() { - $params = array( + $params = [ 'contact_select_id' => 0, - 'membership_type_id' => array(1 => NULL), - ); - $files = array(); + 'membership_type_id' => [1 => NULL], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); $this->assertType('array', $rc); $this->assertTrue(array_key_exists('membership_type_id', $rc)); - $params['membership_type_id'] = array(1 => 3); + $params['membership_type_id'] = [1 => 3]; $rc = $obj->formRule($params, $files, $obj); $this->assertType('array', $rc); $this->assertTrue(array_key_exists('join_date', $rc)); @@ -169,15 +169,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $unixNow = time(); $unixYesterday = $unixNow - (24 * 60 * 60); $ymdYesterday = date('Y-m-d', $unixYesterday); - $params = array( + $params = [ 'join_date' => date('Y-m-d'), 'start_date' => $ymdYesterday, 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); - $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'), + $rc = call_user_func(['CRM_Member_Form_Membership', 'formRule'], $params, $files, $obj ); $this->assertType('array', $rc); @@ -193,13 +193,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $unixNow = time(); $unixYesterday = $unixNow - (24 * 60 * 60); $ymdYesterday = date('Y-m-d', $unixYesterday); - $params = array( + $params = [ 'join_date' => date('Y-m-d'), 'start_date' => date('Y-m-d'), 'end_date' => $ymdYesterday, - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); $this->assertType('array', $rc); @@ -213,13 +213,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $unixNow = time(); $unixYearFromNow = $unixNow + (365 * 24 * 60 * 60); $ymdYearFromNow = date('Y-m-d', $unixYearFromNow); - $params = array( + $params = [ 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => $ymdYearFromNow, - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); $this->assertType('array', $rc); @@ -233,15 +233,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleRollingLifetimeEnd() { $unixNow = time(); $unixYearFromNow = $unixNow + (365 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d'), 'start_date' => date('Y-m-d'), 'end_date' => date('Y-m-d', $unixYearFromNow ), - 'membership_type_id' => array('23', '25'), - ); - $files = array(); + 'membership_type_id' => ['23', '25'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); $this->assertType('array', $rc); @@ -254,12 +254,12 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { */ public function testFormRulePermanentOverrideWithNoStatus() { $unixNow = time(); - $params = array( + $params = [ 'join_date' => date('Y-m-d'), - 'membership_type_id' => array('23', '25'), + 'membership_type_id' => ['23', '25'], 'is_override' => TRUE, - ); - $files = array(); + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); $this->assertType('array', $rc); @@ -267,27 +267,27 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { } public function testFormRuleUntilDateOverrideWithValidOverrideEndDate() { - $params = array( + $params = [ 'join_date' => date('Y-m-d'), - 'membership_type_id' => array('23', '25'), + 'membership_type_id' => ['23', '25'], 'is_override' => TRUE, 'status_id' => 1, 'status_override_end_date' => date('Y-m-d'), - ); - $files = array(); + ]; + $files = []; $membershipForm = new CRM_Member_Form_Membership(); $validationResponse = $membershipForm->formRule($params, $files, $membershipForm); $this->assertTrue($validationResponse); } public function testFormRuleUntilDateOverrideWithNoOverrideEndDate() { - $params = array( + $params = [ 'join_date' => date('Y-m-d'), - 'membership_type_id' => array('23', '25'), + 'membership_type_id' => ['23', '25'], 'is_override' => CRM_Member_StatusOverrideTypes::UNTIL_DATE, 'status_id' => 1, - ); - $files = array(); + ]; + $files = []; $membershipForm = new CRM_Member_Form_Membership(); $validationResponse = $membershipForm->formRule($params, $files, $membershipForm); $this->assertType('array', $validationResponse); @@ -301,13 +301,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleRollingJoin1MonthFromNow() { $unixNow = time(); $unix1MFmNow = $unixNow + (31 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d', $unix1MFmNow), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -320,13 +320,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * Test CRM_Member_Form_Membership::formRule() with a join date of today and a rolling membership type. */ public function testFormRuleRollingJoinToday() { - $params = array( + $params = [ 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -341,13 +341,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleRollingJoin1MonthAgo() { $unixNow = time(); $unix1MAgo = $unixNow - (31 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d', $unix1MAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -361,13 +361,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleRollingJoin6MonthsAgo() { $unixNow = time(); $unix6MAgo = $unixNow - (180 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d', $unix6MAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -382,13 +382,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleRollingJoin1YearAgo() { $unixNow = time(); $unix1YAgo = $unixNow - (370 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d', $unix1YAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -403,13 +403,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleRollingJoin2YearsAgo() { $unixNow = time(); $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d', $unix2YAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '15'), - ); - $files = array(); + 'membership_type_id' => ['23', '15'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -424,13 +424,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { public function testFormRuleFixedJoin6MonthsAgo() { $unixNow = time(); $unix6MAgo = $unixNow - (180 * 24 * 60 * 60); - $params = array( + $params = [ 'join_date' => date('Y-m-d', $unix6MAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '7'), - ); - $files = array(); + 'membership_type_id' => ['23', '7'], + ]; + $files = []; $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); @@ -453,13 +453,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $this->mut = new CiviMailUtils($this, TRUE); $form->_mode = 'test'; $this->createLoggedInUser(); - $params = array( + $params = [ 'cid' => $this->_individualId, 'join_date' => date('2/d/Y', time()), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '1', @@ -473,11 +473,11 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessorID, 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '9', // TODO: Future proof 'Y' => '2024', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Test', 'billing_middlename' => 'Last', @@ -488,47 +488,47 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'billing_country_id-5' => '1228', 'send_receipt' => TRUE, 'receipt_text' => 'Receipt text', - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0); - $contribution = $this->callAPISuccess('Contribution', 'get', array( + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 0); + $contribution = $this->callAPISuccess('Contribution', 'get', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, - )); + ]); //CRM-20264 : Check that CC type and number (last 4 digit) is stored during backoffice membership payment $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals(1, $financialTrxn['card_type_id']); $this->assertEquals(1111, $financialTrxn['pan_truncation']); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); + ], 1); - $this->_checkFinancialRecords(array( + $this->_checkFinancialRecords([ 'id' => $contribution['id'], 'total_amount' => 1234.56, 'financial_account_id' => 2, - 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( + 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $this->_paymentProcessorID, 'return' => 'payment_instrument_id', - )), - ), 'online'); - $this->mut->checkMailLog(array( + ]), + ], 'online'); + $this->mut->checkMailLog([ CRM_Utils_Money::format('1234.56'), 'Receipt text', - )); + ]); $this->mut->stop(); $this->assertEquals([ [ @@ -550,16 +550,16 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $form->preProcess(); $this->mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); - $priceSet = $this->callAPISuccess('PriceSet', 'Get', array("extends" => "CiviMember")); + $priceSet = $this->callAPISuccess('PriceSet', 'Get', ["extends" => "CiviMember"]); $form->set('priceSetId', $priceSet['id']); CRM_Price_BAO_PriceSet::buildPriceSet($form); - $params = array( + $params = [ 'cid' => $this->_individualId, 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'record_contribution' => 1, 'total_amount' => 50, 'receive_date' => date('Y-m-d', time()) . ' 20:36:00', @@ -568,21 +568,21 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { //Member dues, see data.xml 'financial_type_id' => '2', 'payment_processor_id' => $this->_paymentProcessorID, - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); // check the membership status after partial payment, if its Pending $this->assertEquals(array_search('New', CRM_Member_PseudoConstant::membershipStatus()), $membership['status_id']); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, - )); + ]); $this->assertEquals('Completed', $contribution['contribution_status']); $this->assertEquals(50.00, $contribution['total_amount']); $this->assertEquals(50.00, $contribution['net_amount']); // Step 2: Change the membership type whose minimum free is less than earlier membership - $secondMembershipType = $this->callAPISuccess('membership_type', 'create', array( + $secondMembershipType = $this->callAPISuccess('membership_type', 'create', [ 'domain_id' => 1, 'name' => "Second Test Membership", 'member_of_contact_id' => 23, @@ -594,7 +594,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'fixed_period_rollover_day' => "1231", 'relationship_type_id' => 20, 'financial_type_id' => 2, - )); + ]); Civi::settings()->set('update_contribution_on_membership_type_change', TRUE); $form = $this->getForm(); $form->preProcess(); @@ -602,13 +602,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $form->set('priceSetId', $priceSet['id']); CRM_Price_BAO_PriceSet::buildPriceSet($form); $form->_action = CRM_Core_Action::UPDATE; - $params = array( + $params = [ 'cid' => $this->_individualId, 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $secondMembershipType['id']), + 'membership_type_id' => [23, $secondMembershipType['id']], 'record_contribution' => 1, 'status_id' => 1, 'total_amount' => 25, @@ -617,14 +617,14 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { //Member dues, see data.xml 'financial_type_id' => '2', 'payment_processor_id' => $this->_paymentProcessorID, - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); // check the membership status after partial payment, if its Pending - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, - )); + ]); $payment = CRM_Contribute_BAO_Contribution::getPaymentInfo($membership['id'], 'membership', FALSE, TRUE); // Check the contribution status on membership type change whose minimum fee was less than earlier memebership $this->assertEquals('Pending refund', $contribution['contribution_status']); @@ -649,17 +649,17 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $form->preProcess(); $this->mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); - $priceSet = $this->callAPISuccess('PriceSet', 'Get', array("extends" => "CiviMember")); + $priceSet = $this->callAPISuccess('PriceSet', 'Get', ["extends" => "CiviMember"]); $form->set('priceSetId', $priceSet['id']); $partiallyPaidAmount = 25; CRM_Price_BAO_PriceSet::buildPriceSet($form); - $params = array( + $params = [ 'cid' => $this->_individualId, 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'receive_date' => date('Y-m-d', time()) . ' 20:36:00', 'record_contribution' => 1, 'total_amount' => $this->formatMoneyInput($partiallyPaidAmount), @@ -668,15 +668,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { //Member dues, see data.xml 'financial_type_id' => '2', 'payment_processor_id' => $this->_paymentProcessorID, - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); // check the membership status after partial payment, if its Pending $this->assertEquals(array_search('Pending', CRM_Member_PseudoConstant::membershipStatus()), $membership['status_id']); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, - )); + ]); $this->assertEquals('Partially paid', $contribution['contribution_status']); // $this->assertEquals(50.00, $contribution['total_amount']); // $this->assertEquals(25.00, $contribution['net_amount']); @@ -684,7 +684,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { // Step 2: submit the other half of the partial payment // via AdditionalPayment form to complete the related contribution $form = new CRM_Contribute_Form_AdditionalPayment(); - $submitParams = array( + $submitParams = [ 'contribution_id' => $contribution['contribution_id'], 'contact_id' => $this->_individualId, 'total_amount' => $this->formatMoneyInput($partiallyPaidAmount), @@ -695,17 +695,17 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'payment_processor_id' => 0, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'check_number' => 'check-12345', - ); + ]; $form->cid = $this->_individualId; $form->testSubmit($submitParams); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); // check the membership status after additional payment, if its changed to 'New' $this->assertEquals(array_search('New', CRM_Member_PseudoConstant::membershipStatus()), $membership['status_id']); // check the contribution status and net amount after additional payment - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, - )); + ]); $this->assertEquals('Completed', $contribution['contribution_status']); // $this->assertEquals(50.00, $contribution['net_amount']); } @@ -715,51 +715,51 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { */ public function testSubmitRecur() { CRM_Core_Session::singleton()->getStatus(TRUE); - $pendingVal = $this->callAPISuccessGetValue('OptionValue', array( + $pendingVal = $this->callAPISuccessGetValue('OptionValue', [ 'return' => "id", 'option_group_id' => "contribution_status", 'label' => "Pending", - )); + ]); //Update label for Pending contribution status. - $this->callAPISuccess('OptionValue', 'create', array( + $this->callAPISuccess('OptionValue', 'create', [ 'id' => $pendingVal, 'label' => "PendingEdited", - )); + ]); $form = $this->getForm(); - $this->callAPISuccess('MembershipType', 'create', array( + $this->callAPISuccess('MembershipType', 'create', [ 'id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', 'duration_interval' => 1, 'auto_renew' => TRUE, - )); + ]); $form->preProcess(); $this->createLoggedInUser(); $params = $this->getBaseSubmitParams(); $form->_mode = 'test'; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 1); - $contribution = $this->callAPISuccess('Contribution', 'get', array( + $contribution = $this->callAPISuccess('Contribution', 'get', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, - )); + ]); //Check if Membership Payment is recorded. - $this->callAPISuccessGetCount('MembershipPayment', array( + $this->callAPISuccessGetCount('MembershipPayment', [ 'membership_id' => $membership['id'], 'contribution_id' => $contribution['id'], - ), 1); + ], 1); // CRM-16992. - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); + ], 1); $this->assertEquals([ [ 'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been added. The new membership End Date is ' . date('F jS, Y', strtotime('last day of this month')) . ' 12:00 AM.', @@ -779,14 +779,14 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $this->createTwoMembershipsViaPriceSetInBackEnd($this->_individualId); // cancel the related contribution via API - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 2, - )); - $this->callAPISuccess('Contribution', 'create', array( + ]); + $this->callAPISuccess('Contribution', 'create', [ 'id' => $contribution['id'], 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Cancelled'), - )); + ]); // fetch financial_trxn ID of the related contribution $sql = "SELECT financial_trxn_id @@ -795,18 +795,18 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { ORDER BY id DESC LIMIT 1 "; - $financialTrxnID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($contribution['id'], 'Int'))); + $financialTrxnID = CRM_Core_DAO::singleValueQuery($sql, [1 => [$contribution['id'], 'Int']]); // fetch entity_financial_trxn records and compare their cancelled records - $result = $this->callAPISuccess('EntityFinancialTrxn', 'Get', array( + $result = $this->callAPISuccess('EntityFinancialTrxn', 'Get', [ 'financial_trxn_id' => $financialTrxnID, 'entity_table' => 'civicrm_financial_item', - )); + ]); // compare the reversed amounts of respective memberships after cancelling contribution - $cancelledMembershipAmounts = array( + $cancelledMembershipAmounts = [ -20.00, -10.00, - ); + ]; $count = 0; foreach ($result['values'] as $record) { $this->assertEquals($cancelledMembershipAmounts[$count], $record['amount']); @@ -821,13 +821,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $form = $this->getForm(NULL); $form->preProcess(); $this->createLoggedInUser(); - $params = array( + $params = [ 'cid' => $this->_individualId, 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '2', @@ -851,27 +851,27 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'billing_state_province_id-5' => '1003', 'billing_postal_code-5' => '90210', 'billing_country_id-5' => '1228', - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $contribution = $this->callAPISuccessGetSingle('Contribution', array( + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'contribution_status_id' => 2, - )); + ]); $this->assertEquals($contribution['trxn_id'], 777); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); - $this->callAPISuccessGetSingle('address', array( + ], 1); + $this->callAPISuccessGetSingle('address', [ 'contact_id' => $this->_individualId, 'street_address' => '10 Test St', 'postal_code' => 90210, - )); + ]); } /** @@ -883,34 +883,34 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { //Perform a pay later membership contribution. $this->testSubmitPayLaterWithBilling(); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->assertEquals($membership['status_id'], array_search('Pending', $memStatus)); - $contribution = $this->callAPISuccessGetSingle('MembershipPayment', array( + $contribution = $this->callAPISuccessGetSingle('MembershipPayment', [ 'membership_id' => $membership['id'], - )); + ]); //Update contribution to Partially paid. - $prevContribution = $this->callAPISuccess('Contribution', 'create', array( + $prevContribution = $this->callAPISuccess('Contribution', 'create', [ 'id' => $contribution['contribution_id'], 'contribution_status_id' => 'Partially paid', - )); + ]); $prevContribution = $prevContribution['values'][1]; //Complete the contribution from offline form. $form = new CRM_Contribute_Form_Contribution(); - $submitParams = array( + $submitParams = [ 'id' => $contribution['contribution_id'], 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), 'price_set_id' => 0, - ); - $fields = array('total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id'); + ]; + $fields = ['total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id']; foreach ($fields as $val) { $submitParams[$val] = $prevContribution[$val]; } $form->testSubmit($submitParams, CRM_Core_Action::UPDATE); //Check if Membership is updated to New. - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->assertEquals($membership['status_id'], array_search('New', $memStatus)); } @@ -921,42 +921,42 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $form = $this->getForm(); $mut = new CiviMailUtils($this, TRUE); $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); - $processor->setDoDirectPaymentResult(array( + $processor->setDoDirectPaymentResult([ 'payment_status_id' => 1, 'trxn_id' => 'kettles boil water', 'fee_amount' => .14, - )); + ]); $processorDetail = $processor->getPaymentProcessor(); - $this->callAPISuccess('MembershipType', 'create', array( + $this->callAPISuccess('MembershipType', 'create', [ 'id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', 'duration_interval' => 1, 'auto_renew' => TRUE, - )); + ]); $form->preProcess(); $this->createLoggedInUser(); $params = $this->getBaseSubmitParams(); $form->_mode = 'test'; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 1); - $contribution = $this->callAPISuccess('Contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('Contribution', 'getsingle', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, - )); + ]); $this->assertEquals(.14, $contribution['fee_amount']); $this->assertEquals('kettles boil water', $contribution['trxn_id']); $this->assertEquals($processorDetail['payment_instrument_id'], $contribution['payment_instrument_id']); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], - ), 1); - $mut->checkMailLog(array( + ], 1); + $mut->checkMailLog([ '=========================================================== Billing Name and Address =========================================================== @@ -975,7 +975,7 @@ Credit Card Information Visa ************1111 Expires: ', - )); + ]); $mut->stop(); } @@ -1002,9 +1002,9 @@ Expires: ', $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->assertEquals($membership['status_id'], array_search('Pending', CRM_Member_PseudoConstant::membershipStatus())); } @@ -1018,22 +1018,22 @@ Expires: ', public function testTwoInheritedMembershipsViaPriceSetInBackend() { // Create an organization and give it a "Member of" relationship to $this->_individualId. $orgID = $this->organizationCreate(); - $relationship = $this->callAPISuccess('relationship', 'create', array( + $relationship = $this->callAPISuccess('relationship', 'create', [ 'contact_id_a' => $this->_individualId, 'contact_id_b' => $orgID, 'relationship_type_id' => 20, 'is_active' => 1, - )); + ]); // Create two memberships for the organization, via a price set in the back end. $this->createTwoMembershipsViaPriceSetInBackEnd($orgID); // Check the primary memberships on the organization. - $orgMembershipResult = $this->callAPISuccess('membership', 'get', array( + $orgMembershipResult = $this->callAPISuccess('membership', 'get', [ 'contact_id' => $orgID, - )); + ]); $this->assertEquals(2, $orgMembershipResult['count'], "2 primary memberships should have been created on the organization."); - $primaryMembershipIds = array(); + $primaryMembershipIds = []; foreach ($orgMembershipResult['values'] as $membership) { $primaryMembershipIds[] = $membership['id']; $this->assertTrue(empty($membership['owner_membership_id']), "Membership on the organization has owner_membership_id so is inherited."); @@ -1041,9 +1041,9 @@ Expires: ', // CRM-20955: check that correct inherited memberships were created for the individual, // for both of the primary memberships. - $individualMembershipResult = $this->callAPISuccess('membership', 'get', array( + $individualMembershipResult = $this->callAPISuccess('membership', 'get', [ 'contact_id' => $this->_individualId, - )); + ]); $this->assertEquals(2, $individualMembershipResult['count'], "2 inherited memberships should have been created on the individual."); foreach ($individualMembershipResult['values'] as $membership) { $this->assertNotEmpty($membership['owner_membership_id'], "Membership on the individual lacks owner_membership_id so is not inherited."); @@ -1053,12 +1053,12 @@ Expires: ', // CRM-20966: check that the correct membership contribution, line items // & membership_payment records were created for the organization. - $contributionResult = $this->callAPISuccess('contribution', 'get', array( + $contributionResult = $this->callAPISuccess('contribution', 'get', [ 'contact_id' => $orgID, 'sequential' => 1, - 'api.line_item.get' => array(), - 'api.membership_payment.get' => array(), - )); + 'api.line_item.get' => [], + 'api.membership_payment.get' => [], + ]); $this->assertEquals(1, $contributionResult['count'], "One contribution should have been created for the organization's memberships."); $this->assertEquals(2, $contributionResult['values'][0]['api.line_item.get']['count'], "2 line items should have been created for the organization's memberships."); @@ -1074,14 +1074,14 @@ Expires: ', } // CRM-20966: check that deleting relationship used for inheritance does not delete contribution. - $this->callAPISuccess('relationship', 'delete', array( + $this->callAPISuccess('relationship', 'delete', [ 'id' => $relationship['id'], - )); + ]); - $contributionResultAfterRelationshipDelete = $this->callAPISuccess('contribution', 'get', array( + $contributionResultAfterRelationshipDelete = $this->callAPISuccess('contribution', 'get', [ 'id' => $contributionResult['values'][0]['id'], 'contact_id' => $orgID, - )); + ]); $this->assertEquals(1, $contributionResultAfterRelationshipDelete['count'], "Contribution has been wrongly deleted."); } @@ -1106,7 +1106,7 @@ Expires: ', * @return array */ protected function getBaseSubmitParams() { - $params = array( + $params = [ 'cid' => $this->_individualId, 'price_set_id' => 0, 'join_date' => date('Y-m-d'), @@ -1114,7 +1114,7 @@ Expires: ', 'end_date' => '', 'campaign_id' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'auto_renew' => '1', 'is_recur' => 1, 'max_related' => 0, @@ -1130,11 +1130,11 @@ Expires: ', 'payment_processor_id' => $this->_paymentProcessorID, 'credit_card_number' => '4111111111111111', 'cvv2' => '123', - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => '9', // TODO: Future proof 'Y' => '2019', - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Test', 'billing_middlename' => 'Last', @@ -1144,7 +1144,7 @@ Expires: ', 'billing_postal_code-5' => '90210', 'billing_country_id-5' => '1228', 'send_receipt' => 1, - ); + ]; return $params; } @@ -1160,22 +1160,22 @@ Expires: ', $this->createLoggedInUser(); // create a price-set of price-field of type checkbox and each price-option corresponds to a membership type - $priceSet = $this->callAPISuccess('price_set', 'create', array( + $priceSet = $this->callAPISuccess('price_set', 'create', [ 'is_quick_config' => 0, 'extends' => 'CiviMember', 'financial_type_id' => 1, 'title' => 'my Page', - )); + ]); $priceSetID = $priceSet['id']; // create respective checkbox price-field - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $priceSetID, 'label' => 'Memberships', 'html_type' => 'Checkbox', - )); + ]); $priceFieldID = $priceField['id']; // create two price options, each represent a membership type of amount 20 and 10 respectively - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Long Haired Goat', @@ -1183,9 +1183,9 @@ Expires: ', 'financial_type_id' => 'Donation', 'membership_type_id' => 15, 'membership_num_terms' => 1, - )); - $pfvIDs = array($priceFieldValue['id'] => 1); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $pfvIDs = [$priceFieldValue['id'] => 1]; + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating Goat', @@ -1193,11 +1193,11 @@ Expires: ', 'financial_type_id' => 'Donation', 'membership_type_id' => 35, 'membership_num_terms' => 2, - )); + ]); $pfvIDs[$priceFieldValue['id']] = 1; // register for both of these memberships via backoffice membership form submission - $params = array( + $params = [ 'cid' => $contactId, 'join_date' => date('Y-m-d'), 'start_date' => '', @@ -1205,7 +1205,7 @@ Expires: ', // This format reflects the 23 being the organisation & the 25 being the type. "price_$priceFieldID" => $pfvIDs, "price_set_id" => $priceSetID, - 'membership_type_id' => array(1 => 0), + 'membership_type_id' => [1 => 0], 'auto_renew' => '0', 'max_related' => '', 'num_terms' => '2', @@ -1229,7 +1229,7 @@ Expires: ', 'billing_state_province_id-5' => '1003', 'billing_postal_code-5' => '90210', 'billing_country_id-5' => '1228', - ); + ]; $form->testSubmit($params); } @@ -1241,31 +1241,31 @@ Expires: ', //Create a membership with status = 'New'. $this->_individualId = $this->createLoggedInUser(); - $memParams = array( + $memParams = [ 'contact_id' => $this->_individualId, 'membership_type_id' => $this->membershipTypeAnnualFixedID, 'status_id' => array_search('New', CRM_Member_PseudoConstant::membershipStatus()), - ); - $cancelledStatusId = $this->callAPISuccessGetValue('OptionValue', array( + ]; + $cancelledStatusId = $this->callAPISuccessGetValue('OptionValue', [ 'return' => "value", 'option_group_id' => "contribution_status", 'name' => "Cancelled", - )); - $params = array( + ]); + $params = [ 'total_amount' => 50, 'financial_type_id' => 2, 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => $cancelledStatusId, - ); + ]; $membershipId = $this->contactMembershipCreate($memParams); - $contriParams = array( + $contriParams = [ 'membership_id' => $membershipId, 'total_amount' => 50, 'financial_type_id' => 2, 'contact_id' => $this->_individualId, - ); + ]; $contribution = CRM_Member_BAO_Membership::recordMembershipContribution($contriParams); //Update Contribution to Cancelled. @@ -1273,14 +1273,14 @@ Expires: ', $form->_mode = NULL; $form->_contactID = $this->_individualId; $form->testSubmit($params, CRM_Core_Action::UPDATE); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); //Assert membership status overrides when the contribution cancelled. $this->assertEquals($membership['is_override'], TRUE); - $this->assertEquals($membership['status_id'], $this->callAPISuccessGetValue('MembershipStatus', array( + $this->assertEquals($membership['status_id'], $this->callAPISuccessGetValue('MembershipStatus', [ 'return' => "id", 'name' => "Cancelled", - ))); + ])); } /** @@ -1296,22 +1296,22 @@ Expires: ', $form->preProcess(); $this->mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); - $priceSet = $this->callAPISuccess('PriceSet', 'Get', array("extends" => "CiviMember")); + $priceSet = $this->callAPISuccess('PriceSet', 'Get', ["extends" => "CiviMember"]); $form->set('priceSetId', $priceSet['id']); // we are simulating the creation of a Price Set in Administer -> CiviContribute -> Manage Price Sets so set is_quick_config = 0 - $this->callAPISuccess('PriceSet', 'Create', array("id" => $priceSet['id'], 'is_quick_config' => 0)); + $this->callAPISuccess('PriceSet', 'Create', ["id" => $priceSet['id'], 'is_quick_config' => 0]); // clean the price options static variable to repopulate the options, in order to fetch tax information \Civi::$statics['CRM_Price_BAO_PriceField']['priceOptions'] = NULL; CRM_Price_BAO_PriceSet::buildPriceSet($form); // rebuild the price set form variable to include the tax information against each price options $form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSet['id'])); - $params = array( + $params = [ 'cid' => $this->_individualId, 'join_date' => date('Y-m-d'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. - 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), + 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], 'record_contribution' => 1, 'total_amount' => 55, 'receive_date' => date('Y-m-d', time()) . ' 20:36:00', @@ -1320,12 +1320,12 @@ Expires: ', //Member dues, see data.xml 'financial_type_id' => 2, 'payment_processor_id' => $this->_paymentProcessorID, - ); + ]; $form->_contactID = $this->_individualId; $form->testSubmit($params); - $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership')); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership']); $this->assertEquals(1, $lineItem['qty']); $this->assertEquals(50.00, $lineItem['unit_price']); $this->assertEquals(50.00, $lineItem['line_total']); @@ -1334,17 +1334,17 @@ Expires: ', // Simply save the 'Edit Contribution' form $form = new CRM_Contribute_Form_Contribution(); $form->_context = 'membership'; - $form->_values = $this->callAPISuccessGetSingle('Contribution', array('id' => $lineItem['contribution_id'], 'return' => array('total_amount', 'net_amount', 'fee_amount', 'tax_amount'))); - $form->testSubmit(array( + $form->_values = $this->callAPISuccessGetSingle('Contribution', ['id' => $lineItem['contribution_id'], 'return' => ['total_amount', 'net_amount', 'fee_amount', 'tax_amount']]); + $form->testSubmit([ 'contact_id' => $this->_individualId, 'id' => $lineItem['contribution_id'], 'financial_type_id' => 2, 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), - ), + ], CRM_Core_Action::UPDATE); // ensure that the LineItem data remain the same - $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership')); + $lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership']); $this->assertEquals(1, $lineItem['qty']); $this->assertEquals(50.00, $lineItem['unit_price']); $this->assertEquals(50.00, $lineItem['line_total']); @@ -1352,15 +1352,15 @@ Expires: ', // ensure that the LineItem data add up to the data at the Contribution level $contribution = $this->callAPISuccessGetSingle('Contribution', - array( + [ 'contribution_id' => 1, - 'return' => array('tax_amount', 'total_amount'), - ) + 'return' => ['tax_amount', 'total_amount'], + ] ); $this->assertEquals($contribution['total_amount'], $lineItem['line_total'] + $lineItem['tax_amount']); $this->assertEquals($contribution['tax_amount'], $lineItem['tax_amount']); - $financialItems = $this->callAPISuccess('FinancialItem', 'get', array()); + $financialItems = $this->callAPISuccess('FinancialItem', 'get', []); $financialItems_sum = 0; foreach ($financialItems['values'] as $financialItem) { $financialItems_sum += $financialItem['amount']; diff --git a/tests/phpunit/CRM/Member/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Member/Form/Task/PDFLetterCommonTest.php index a9546c9b04..19d36afc8c 100644 --- a/tests/phpunit/CRM/Member/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Member/Form/Task/PDFLetterCommonTest.php @@ -44,35 +44,35 @@ class CRM_Member_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { * Test token replacement for Print/Merge Task */ public function testMembershipTokenReplacementInPDF() { - $membershipIds = $returnProperties = $categories = $expected = array(); + $membershipIds = $returnProperties = $categories = $expected = []; list($tokens, $htmlMessage) = self::getSampleHTML(); - $membershipDates = array( + $membershipDates = [ date('Y-m-d'), date('Y-m-d', strtotime('-1 month')), - ); + ]; // Create sample memberships with different dates. foreach ($membershipDates as $date) { $contactId = $this->individualCreate(); - $membershipTypeID = $this->membershipTypeCreate(array( + $membershipTypeID = $this->membershipTypeCreate([ 'minimum_fee' => '100.00', 'member_of_contact_id' => $contactId, - )); - $params = array( + ]); + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $membershipTypeID, 'join_date' => $date, 'start_date' => $date, 'end_date' => date('Y-m-d', strtotime("{$date} +1 year")), - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); $membershipIds[] = $result['id']; $params = array_merge($params, - array( + [ 'fee' => '100.00', 'type' => 'General', 'status' => 'New', - ) + ] ); // Form an expected array replacing tokens for each contact. @@ -109,20 +109,20 @@ class CRM_Member_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { * Generate sample HTML for testing. */ public static function getSampleHTML() { - $tokens = array( + $tokens = [ 'Test Fee' => 'fee', 'Test Type' => 'type', 'Test Status' => 'status', 'Test Join Date' => 'join_date', 'Test Start Date' => 'start_date', 'Test End Date' => 'end_date', - ); + ]; $html = ''; foreach ($tokens as $key => $val) { $html .= "

{$key} - {membership.{$val}}

"; } - return array($tokens, $html); + return [$tokens, $html]; } } diff --git a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php index 17b6ec9ef9..4585ab9e77 100644 --- a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php @@ -48,17 +48,17 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $params = array( + $params = [ 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', 'name_a_b' => 'Test Employee of', 'name_b_a' => 'Test Employer of', - ); + ]; $this->_relationshipTypeId = $this->relationshipTypeCreate($params); $this->_orgContactID = $this->organizationCreate(); $this->_financialTypeId = 1; $this->_membershipTypeName = 'Mickey Mouse Club Member'; - $params = array( + $params = [ 'name' => $this->_membershipTypeName, 'description' => NULL, 'minimum_fee' => 10, @@ -72,8 +72,8 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { 'is_active' => 1, 'fixed_period_start_day' => 101, 'fixed_period_rollover_day' => 1231, - ); - $ids = array(); + ]; + $ids = []; $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); $this->_membershipTypeID = $membershipType->id; @@ -87,15 +87,15 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { * This method is called after a test is executed. */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_membership', 'civicrm_membership_log', 'civicrm_contribution', 'civicrm_membership_payment', - ); + ]; $this->quickCleanup($tablesToTruncate); $this->relationshipTypeDelete($this->_relationshipTypeId); - $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); + $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); $this->membershipStatusDelete($this->_mebershipStatusID); $this->contactDelete($this->_orgContactID); } @@ -105,7 +105,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { */ public function testImport() { $this->individualCreate(); - $contact2Params = array( + $contact2Params = [ 'first_name' => 'Anthonita', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -113,28 +113,28 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'b@c.com', 'contact_type' => 'Individual', - ); + ]; $this->individualCreate($contact2Params); $year = date('Y') - 1; $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year)); - $params = array( - array( + $params = [ + [ 'anthony_anderson@civicrm.org', $this->_membershipTypeID, date('Y-m-d'), - ), - array( + ], + [ $contact2Params['email'], $this->_membershipTypeName, $startDate2, - ), - ); - $fieldMapper = array( + ], + ]; + $fieldMapper = [ 'mapper[0][0]' => 'email', 'mapper[1][0]' => 'membership_type_id', 'mapper[2][0]' => 'membership_start_date', - ); + ]; $importObject = new CRM_Member_Import_Parser_Membership($fieldMapper); $importObject->init(); @@ -142,29 +142,29 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { foreach ($params as $values) { $this->assertEquals(CRM_Import_Parser::VALID, $importObject->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), $values[0]); } - $result = $this->callAPISuccess('membership', 'get', array()); + $result = $this->callAPISuccess('membership', 'get', []); $this->assertEquals(2, $result['count']); } public function testImportOverriddenMembershipButWithoutStatus() { - $this->individualCreate(array('email' => 'anthony_anderson2@civicrm.org')); + $this->individualCreate(['email' => 'anthony_anderson2@civicrm.org']); - $fieldMapper = array( + $fieldMapper = [ 'mapper[0][0]' => 'email', 'mapper[1][0]' => 'membership_type_id', 'mapper[2][0]' => 'membership_start_date', 'mapper[3][0]' => 'is_override', - ); + ]; $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper); $membershipImporter->init(); $membershipImporter->_contactType = 'Individual'; - $importValues = array( + $importValues = [ 'anthony_anderson2@civicrm.org', $this->_membershipTypeID, date('Y-m-d'), TRUE, - ); + ]; $importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues); $this->assertEquals(CRM_Import_Parser::ERROR, $importResponse); @@ -172,82 +172,82 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { } public function testImportOverriddenMembershipWithStatus() { - $this->individualCreate(array('email' => 'anthony_anderson3@civicrm.org')); + $this->individualCreate(['email' => 'anthony_anderson3@civicrm.org']); - $fieldMapper = array( + $fieldMapper = [ 'mapper[0][0]' => 'email', 'mapper[1][0]' => 'membership_type_id', 'mapper[2][0]' => 'membership_start_date', 'mapper[3][0]' => 'is_override', 'mapper[4][0]' => 'status_id', - ); + ]; $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper); $membershipImporter->init(); $membershipImporter->_contactType = 'Individual'; - $importValues = array( + $importValues = [ 'anthony_anderson3@civicrm.org', $this->_membershipTypeID, date('Y-m-d'), TRUE, 'New', - ); + ]; $importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues); $this->assertEquals(CRM_Import_Parser::VALID, $importResponse); } public function testImportOverriddenMembershipWithValidOverrideEndDate() { - $this->individualCreate(array('email' => 'anthony_anderson4@civicrm.org')); + $this->individualCreate(['email' => 'anthony_anderson4@civicrm.org']); - $fieldMapper = array( + $fieldMapper = [ 'mapper[0][0]' => 'email', 'mapper[1][0]' => 'membership_type_id', 'mapper[2][0]' => 'membership_start_date', 'mapper[3][0]' => 'is_override', 'mapper[4][0]' => 'status_id', 'mapper[5][0]' => 'status_override_end_date', - ); + ]; $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper); $membershipImporter->init(); $membershipImporter->_contactType = 'Individual'; - $importValues = array( + $importValues = [ 'anthony_anderson4@civicrm.org', $this->_membershipTypeID, date('Y-m-d'), TRUE, 'New', date('Y-m-d'), - ); + ]; $importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues); $this->assertEquals(CRM_Import_Parser::VALID, $importResponse); } public function testImportOverriddenMembershipWithInvalidOverrideEndDate() { - $this->individualCreate(array('email' => 'anthony_anderson5@civicrm.org')); + $this->individualCreate(['email' => 'anthony_anderson5@civicrm.org']); - $fieldMapper = array( + $fieldMapper = [ 'mapper[0][0]' => 'email', 'mapper[1][0]' => 'membership_type_id', 'mapper[2][0]' => 'membership_start_date', 'mapper[3][0]' => 'is_override', 'mapper[4][0]' => 'status_id', 'mapper[5][0]' => 'status_override_end_date', - ); + ]; $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper); $membershipImporter->init(); $membershipImporter->_contactType = 'Individual'; - $importValues = array( + $importValues = [ 'anthony_anderson5@civicrm.org', 'New', date('Y-m-d'), TRUE, $this->_mebershipStatusID, 'abc', - ); + ]; $importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues); $this->assertEquals(CRM_Import_Parser::ERROR, $importResponse); diff --git a/tests/phpunit/CRM/PCP/BAO/PCPTest.php b/tests/phpunit/CRM/PCP/BAO/PCPTest.php index d0c2189142..c44b5e4531 100644 --- a/tests/phpunit/CRM/PCP/BAO/PCPTest.php +++ b/tests/phpunit/CRM/PCP/BAO/PCPTest.php @@ -58,7 +58,7 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { $this->assertEquals($params['link_text'], $pcpBlock->link_text, 'Check for link text.'); $this->assertEquals($params['is_active'], $pcpBlock->is_active, 'Check for is_active.'); // Delete our test object - $delParams = array('id' => $pcpBlock->id); + $delParams = ['id' => $pcpBlock->id]; // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 ) // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCPBlock', $delParams ); } @@ -85,7 +85,7 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { $this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.'); // Delete our test object - $delParams = array('id' => $pcp->id); + $delParams = ['id' => $pcp->id]; // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 ) // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams ); } @@ -113,7 +113,7 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { $this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.'); // Delete our test object - $delParams = array('id' => $pcp->id); + $delParams = ['id' => $pcp->id]; // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 ) // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams ); } diff --git a/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php b/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php index 50c9200547..ea453a0a6a 100644 --- a/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php +++ b/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php @@ -55,20 +55,20 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { */ public function testCreateAndDeletePledgeBlock() { - $pledgeFrequencyUnit = array( + $pledgeFrequencyUnit = [ 'week' => 1, 'month' => 1, 'year' => 1, - ); + ]; - $params = array( + $params = [ 'entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', 'pledge_frequency_unit' => $pledgeFrequencyUnit, 'max_reminders' => 2, 'initial_reminder_day' => 2, 'additional_reminder_day' => 1, - ); + ]; //Checking for pledgeBlock id in the Pledge_block table. $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); @@ -88,20 +88,20 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { */ public function testAddPledgeBlock() { - $pledgeFrequencyUnit = array( + $pledgeFrequencyUnit = [ 'week' => 1, 'month' => 1, 'year' => 1, - ); + ]; - $params = array( + $params = [ 'entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', 'pledge_frequency_unit' => $pledgeFrequencyUnit, 'max_reminders' => 2, 'initial_reminder_day' => 2, 'additional_reminder_day' => 1, - ); + ]; // check for add pledge block $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::add($params); @@ -109,7 +109,7 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { $this->assertEquals($value, $pledgeBlock->$param); } - $params = array( + $params = [ 'id' => $pledgeBlock->id, 'entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', @@ -118,7 +118,7 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { 'initial_reminder_day' => 3, 'additional_reminder_day' => 2, 'is_pledge_interval' => 1, - ); + ]; // also check for edit pledge block $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::add($params); @@ -132,29 +132,29 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { */ public function testRetrieveAndGetPledgeBlock() { - $pledgeFrequencyUnit = array( + $pledgeFrequencyUnit = [ 'week' => 1, 'month' => 1, 'year' => 1, - ); + ]; - $params = array( + $params = [ 'entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', 'pledge_frequency_unit' => $pledgeFrequencyUnit, 'max_reminders' => 2, 'initial_reminder_day' => 2, 'additional_reminder_day' => 1, - ); + ]; $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); // use retrieve() method - $retrieveParams = array( + $retrieveParams = [ 'entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', - ); - $default = array(); + ]; + $default = []; $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock::retrieve($retrieveParams, $default); // use getPledgeBlock() method diff --git a/tests/phpunit/CRM/Pledge/BAO/PledgePaymentTest.php b/tests/phpunit/CRM/Pledge/BAO/PledgePaymentTest.php index fcc0d3a2ba..6aef960146 100644 --- a/tests/phpunit/CRM/Pledge/BAO/PledgePaymentTest.php +++ b/tests/phpunit/CRM/Pledge/BAO/PledgePaymentTest.php @@ -53,7 +53,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { */ public function testAdd() { $pledge = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_Pledge'); - $params = array( + $params = [ 'pledge_id' => $pledge->id, 'scheduled_amount' => 100.55, 'currency' => 'USD', @@ -61,7 +61,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { 'reminder_date' => '20100520000000', 'reminder_count' => 5, 'status_id' => 1, - ); + ]; //do test for normal add. $payment = CRM_Pledge_BAO_PledgePayment::add($params); @@ -70,7 +70,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { } //do test for update mode. - $params = array( + $params = [ 'id' => $payment->id, 'pledge_id' => $pledge->id, 'scheduled_amount' => 55.55, @@ -79,7 +79,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { 'reminder_date' => '20100425000000', 'reminder_count' => 10, 'status_id' => 2, - ); + ]; $payment = CRM_Pledge_BAO_PledgePayment::add($params); foreach ($params as $param => $value) { @@ -93,8 +93,8 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { */ public function testRetrieveZeroPledeID() { $payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment'); - $params = array('pledge_id' => 0); - $defaults = array(); + $params = ['pledge_id' => 0]; + $defaults = []; $paymentid = CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults); $this->assertEquals(is_null($paymentid), 1, "Pledge Id must be greater than 0"); @@ -106,8 +106,8 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { */ public function testRetrieveStringPledgeID() { $payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment'); - $params = array('pledge_id' => 'Test'); - $defaults = array(); + $params = ['pledge_id' => 'Test']; + $defaults = []; $paymentid = CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults); $this->assertEquals(is_null($paymentid), 1, "Pledge Id cannot be a string"); @@ -120,8 +120,8 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { public function testRetrieveKnownPledgeID() { $payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment'); $pledgeId = $payment->pledge_id; - $params = array('pledge_id' => $pledgeId); - $defaults = array(); + $params = ['pledge_id' => $pledgeId]; + $defaults = []; $paymentid = CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults); $this->assertEquals($paymentid->N, 1, "Pledge was retrieved"); @@ -144,7 +144,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { */ public function testDeletePledgePayments() { $contactId = $this->individualCreate(); - $pledgeId = $this->pledgeCreate(array('contact_id' => $contactId)); + $pledgeId = $this->pledgeCreate(['contact_id' => $contactId]); CRM_Pledge_BAO_PledgePayment::deletePayments($pledgeId); // No payments should be retrieved @@ -175,12 +175,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * Test calculateBaseScheduleDate - should give 15th day of month */ public function testcalculateBaseScheduleDateMonth() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'month', 'frequency_day' => 15, 'frequency_interval' => 2, - ); + ]; $date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params); $this->assertEquals('20110515000000', $date); @@ -190,12 +190,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * Test calculateBaseScheduleDate - should give original date */ public function testcalculateBaseScheduleDateDay() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'day', 'frequency_day' => 15, 'frequency_interval' => 2, - ); + ]; $date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params); $this->assertEquals('20110510000000', $date); @@ -206,12 +206,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * testing each day as this is really the only unit that does anything */ public function testcalculateBaseScheduleDateWeek() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'week', 'frequency_day' => 1, 'frequency_interval' => 2, - ); + ]; $date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params); $this->assertEquals('20110509000000', $date); @@ -239,12 +239,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * Test calculateBaseScheduleDate - should give original date */ public function testcalculateBaseScheduleDateYear() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'year', 'frequency_day' => 15, 'frequency_interval' => 2, - ); + ]; $date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params); $this->assertEquals('20110510000000', $date); @@ -254,12 +254,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * Test calculateNextScheduledDate - no date provided */ public function testcalculateNextScheduledDateYear() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'year', 'frequency_day' => 15, 'frequency_interval' => 2, - ); + ]; $date = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 1); $this->assertEquals('20130510000000', $date); @@ -270,12 +270,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * Test culateNextScheduledDateMonth for months. */ public function testcalculateNextScheduledDateMonth() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'month', 'frequency_day' => 31, 'frequency_interval' => 1, - ); + ]; $nextScheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 2); $this->assertEquals('20110731000000', $nextScheduleDate); // assert pledge scheduled date for month february. @@ -334,12 +334,12 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { * Test calculateNextScheduledDate - no date provided */ public function testcalculateNextScheduledDateYearDateProvided() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'year', 'frequency_day' => 15, 'frequency_interval' => 2, - ); + ]; $date = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 3, '20080510'); $this->assertEquals('20140510000000', $date); @@ -354,7 +354,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { $scheduled_date = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y"))); $contact_id = 2; - $pledge = $this->callAPISuccess('Pledge', 'create', array( + $pledge = $this->callAPISuccess('Pledge', 'create', [ 'contact_id' => $contact_id, 'pledge_create_date' => date('Ymd'), 'start_date' => date('Ymd'), @@ -369,9 +369,9 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { 'frequency_day' => 1, 'installments' => 12, 'sequential' => 1, - )); + ]); - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $contact_id, 'financial_type_id' => 1, 'invoice_id' => 46, @@ -381,13 +381,13 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { 'net_amount' => 404.70, 'payment_instrument_id' => 1, 'non_deductible_amount' => 0.00, - )); + ]); // Fetch the first planned pledge payment/installment - $pledgePayments = civicrm_api3('PledgePayment', 'get', array( + $pledgePayments = civicrm_api3('PledgePayment', 'get', [ 'pledge_id' => $pledge['id'], 'sequential' => 1, - )); + ]); // Does all sorts of shenanigans if the amount was not the expected amount, // and this is what we really want to test in this function. @@ -407,10 +407,10 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { // Fetch the pledge payments again to see if the amounts and statuses // have been updated correctly. - $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', array( + $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', [ 'pledge_id' => $pledge['id'], 'sequential' => 1, - )); + ]); // The status of the first 3 pledges should be set to complete $this->assertEquals($pledgePayments['values'][0]['status_id'], 1); @@ -426,9 +426,9 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { $this->assertEquals($pledgePayments['values'][3]['status_id'], 2); // Cleanup - civicrm_api3('Pledge', 'delete', array( + civicrm_api3('Pledge', 'delete', [ 'id' => $pledge['id'], - )); + ]); } /** @@ -445,7 +445,7 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { $scheduled_date = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y"))); $contact_id = 2; - $params = array( + $params = [ 'contact_id' => $contact_id, 'pledge_create_date' => date('Ymd'), 'start_date' => date('Ymd'), @@ -460,11 +460,11 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { 'frequency_day' => 1, 'installments' => 12, 'sequential' => 1, - ); + ]; $pledge = CRM_Pledge_BAO_Pledge::create($params); - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $contact_id, 'financial_type_id' => 1, 'invoice_id' => 47, @@ -474,13 +474,13 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { 'net_amount' => 100.00, 'payment_instrument_id' => 1, 'non_deductible_amount' => 0.00, - )); + ]); // Fetch the first planned pledge payment/installment - $pledgePayments = civicrm_api3('PledgePayment', 'get', array( + $pledgePayments = civicrm_api3('PledgePayment', 'get', [ 'pledge_id' => $pledge->id, 'sequential' => 1, - )); + ]); // The last pledge payment is 8.37 because 12*8.33 = 99.96 // So CiviCRM automatically creates a larger final pledge to catch the missing cents. @@ -507,10 +507,10 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { // Fetch the pledge payments again to see if the amounts and statuses // have been updated correctly. - $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', array( + $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', [ 'pledge_id' => $pledge->id, 'sequential' => 1, - )); + ]); foreach ($pledgePayments['values'] as $key => $pp) { if ($key == 0) { @@ -530,9 +530,9 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase { $this->assertEquals(count($pledgePayments['values']), CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($pledge->id, 2)); // Cleanup - civicrm_api3('Pledge', 'delete', array( + civicrm_api3('Pledge', 'delete', [ 'id' => $pledge->id, - )); + ]); } } diff --git a/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php b/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php index b29ccbce3d..7093440b19 100644 --- a/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php +++ b/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php @@ -40,7 +40,7 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); $this->_contactId = $this->individualCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_contactId, 'frequency_unit' => 'month', 'original_installment_amount' => 25.00, @@ -54,7 +54,7 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { 'status_id' => 2, 'currency' => 'USD', 'amount' => 300, - ); + ]; } /** @@ -101,8 +101,8 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { * Retrieve a pledge based on a pledge id = 0 */ public function testRetrieveZeroPledeID() { - $defaults = array(); - $params = array('pledge_id' => 0); + $defaults = []; + $params = ['pledge_id' => 0]; $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults); $this->assertEquals(is_null($pledgeId), 1, "Pledge Id must be greater than 0"); @@ -112,8 +112,8 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { * Retrieve a payment based on a Null pledge id random string. */ public function testRetrieveStringPledgeID() { - $defaults = array(); - $params = array('pledge_id' => 'random text'); + $defaults = []; + $params = ['pledge_id' => 'random text']; $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults); $this->assertEquals(is_null($pledgeId), 1, "Pledge Id must be a string"); @@ -123,7 +123,7 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { * Test that payment retrieve wrks based on known pledge id. */ public function testRetrieveKnownPledgeID() { - $params = array( + $params = [ 'contact_id' => $this->_contactId, 'frequency_unit' => 'month', 'frequency_interval' => 1, @@ -137,12 +137,12 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { 'status_id' => 2, 'currency' => 'USD', 'amount' => 300, - ); + ]; $pledge = CRM_Pledge_BAO_Pledge::add($params); - $defaults = array(); - $pledgeParams = array('pledge_id' => $pledge->id); + $defaults = []; + $pledgeParams = ['pledge_id' => $pledge->id]; $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($pledgeParams, $defaults); @@ -153,13 +153,13 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { * Test build recur params. */ public function testGetPledgeStartDate() { - $startDate = json_encode(array('calendar_month' => 6)); + $startDate = json_encode(['calendar_month' => 6]); - $params = array( + $params = [ 'pledge_start_date' => $startDate, 'is_pledge_start_date_editable' => TRUE, 'is_pledge_start_date_visible' => TRUE, - ); + ]; // Try with relative date $date = CRM_Pledge_BAO_Pledge::getPledgeStartDate(6, $params); @@ -169,10 +169,10 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { // Try with fixed date $date = NULL; - $params = array( - 'pledge_start_date' => json_encode(array('calendar_date' => '06/10/2016')), + $params = [ + 'pledge_start_date' => json_encode(['calendar_date' => '06/10/2016']), 'is_pledge_start_date_visible' => FALSE, - ); + ]; $date = CRM_Pledge_BAO_Pledge::getPledgeStartDate($date, $params); $this->assertEquals(date('m/d/Y', strtotime($date)), '06/10/2016', "The two dates do not match"); diff --git a/tests/phpunit/CRM/Pledge/Form/SearchTest.php b/tests/phpunit/CRM/Pledge/Form/SearchTest.php index bff24470a6..46eb73ebb3 100644 --- a/tests/phpunit/CRM/Pledge/Form/SearchTest.php +++ b/tests/phpunit/CRM/Pledge/Form/SearchTest.php @@ -9,16 +9,16 @@ class CRM_Pledge_Form_SearchTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->individualID = $this->individualCreate(); - $this->pledgeCreate(array('contact_id' => $this->individualID)); + $this->pledgeCreate(['contact_id' => $this->individualID]); } public function tearDown() { parent::tearDown(); - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_activity', 'civicrm_activity_contact', 'civicrm_pledge', - ); + ]; $this->quickCleanup($tablesToTruncate); } @@ -34,7 +34,7 @@ class CRM_Pledge_Form_SearchTest extends CiviUnitTestCase { $qfKey = $form->controller->_key; $date = date('Y-m-d') . ' 00:00:00'; $rows = $form->controller->get('rows'); - $this->assertEquals(array( + $this->assertEquals([ 'contact_id' => '3', 'sort_name' => 'Anderson, Anthony', 'display_name' => 'Mr. Anthony Anderson II', @@ -54,7 +54,7 @@ class CRM_Pledge_Form_SearchTest extends CiviUnitTestCase { 'checkbox' => 'mark_x_1', 'action' => 'ViewEditmore', 'contact_type' => '
', - ), $rows[0]); + ], $rows[0]); } } diff --git a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php index 6e5e66b93e..a9788e7d62 100644 --- a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php +++ b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php @@ -54,13 +54,13 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { $priceSetID = $this->eventPriceSetCreate(9); $priceSet = CRM_Price_BAO_PriceSet::getCachedPriceSetDetail($priceSetID); $field = reset($priceSet['fields']); - $params = array('priceSetId' => $priceSetID, 'price_' . $field['id'] => 1); + $params = ['priceSetId' => $priceSetID, 'price_' . $field['id'] => 1]; $amountLevel = CRM_Price_BAO_PriceSet::getAmountLevelText($params); $this->assertEquals(CRM_Core_DAO::VALUE_SEPARATOR . 'Price Field - 1' . CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel); - $priceFieldValue = $this->callAPISuccess('pricefieldvalue', 'getsingle', array('price_field_id' => $field['id'])); - $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $priceFieldValue['id'])); - $this->callAPISuccess('PriceField', 'delete', array('id' => $field['id'])); - $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceSetID)); + $priceFieldValue = $this->callAPISuccess('pricefieldvalue', 'getsingle', ['price_field_id' => $field['id']]); + $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $priceFieldValue['id']]); + $this->callAPISuccess('PriceField', 'delete', ['id' => $field['id']]); + $this->callAPISuccess('PriceSet', 'delete', ['id' => $priceSetID]); } /** @@ -68,28 +68,28 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { */ public function testCopyPriceSet() { $priceSetID = $this->eventPriceSetCreate(9); - $oldPriceSetInfo = $this->callAPISuccess('PriceSet', 'getsingle', array('id' => $priceSetID)); + $oldPriceSetInfo = $this->callAPISuccess('PriceSet', 'getsingle', ['id' => $priceSetID]); $newPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetID); $this->assertEquals(substr($oldPriceSetInfo['name'], 0, 20) . 'price_set_' . $newPriceSet->id, $newPriceSet->name); $this->assertEquals($oldPriceSetInfo['title'] . ' [Copy id ' . $newPriceSet->id . ']', $newPriceSet->title); $new2PriceSet = CRM_Price_BAO_PriceSet::copy($newPriceSet->id); $this->assertEquals(substr($newPriceSet->name, 0, 20) . 'price_set_' . $new2PriceSet->id, $new2PriceSet->name); $this->assertEquals($oldPriceSetInfo['title'] . ' [Copy id ' . $new2PriceSet->id . ']', $new2PriceSet->title); - $oldPriceField = $this->callAPISuccess('priceField', 'getsingle', array('price_set_id' => $priceSetID)); - $oldPriceFieldValue = $this->callAPISuccess('priceFieldValue', 'getsingle', array('price_field_id' => $oldPriceField['id'])); - $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $oldPriceFieldValue['id'])); - $this->callAPISuccess('PriceField', 'delete', array('id' => $oldPriceField['id'])); - $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceSetID)); - $newPriceField = $this->callAPISuccess('PriceField', 'getsingle', array('price_set_id' => $newPriceSet->id)); - $newPriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', array('price_field_id' => $newPriceField['id'])); - $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $newPriceFieldValue['id'])); - $this->callAPISuccess('PriceField', 'delete', array('id' => $newPriceField['id'])); - $this->callAPISuccess('PriceSet', 'delete', array('id' => $newPriceSet->id)); - $new2PriceField = $this->callAPISuccess('PriceField', 'getsingle', array('price_set_id' => $new2PriceSet->id)); - $new2PriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', array('price_field_id' => $new2PriceField['id'])); - $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $new2PriceFieldValue['id'])); - $this->callAPISuccess('PriceField', 'delete', array('id' => $new2PriceField['id'])); - $this->callAPISuccess('PriceSet', 'delete', array('id' => $new2PriceSet->id)); + $oldPriceField = $this->callAPISuccess('priceField', 'getsingle', ['price_set_id' => $priceSetID]); + $oldPriceFieldValue = $this->callAPISuccess('priceFieldValue', 'getsingle', ['price_field_id' => $oldPriceField['id']]); + $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $oldPriceFieldValue['id']]); + $this->callAPISuccess('PriceField', 'delete', ['id' => $oldPriceField['id']]); + $this->callAPISuccess('PriceSet', 'delete', ['id' => $priceSetID]); + $newPriceField = $this->callAPISuccess('PriceField', 'getsingle', ['price_set_id' => $newPriceSet->id]); + $newPriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $newPriceField['id']]); + $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $newPriceFieldValue['id']]); + $this->callAPISuccess('PriceField', 'delete', ['id' => $newPriceField['id']]); + $this->callAPISuccess('PriceSet', 'delete', ['id' => $newPriceSet->id]); + $new2PriceField = $this->callAPISuccess('PriceField', 'getsingle', ['price_set_id' => $new2PriceSet->id]); + $new2PriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $new2PriceField['id']]); + $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $new2PriceFieldValue['id']]); + $this->callAPISuccess('PriceField', 'delete', ['id' => $new2PriceField['id']]); + $this->callAPISuccess('PriceSet', 'delete', ['id' => $new2PriceSet->id]); } /** @@ -102,18 +102,18 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { $organization2 = $this->organizationCreate(); // create three membership type where first two belong to same organisation - $membershipType1 = $this->membershipTypeCreate(array( + $membershipType1 = $this->membershipTypeCreate([ 'name' => 'Membership Type 1', 'member_of_contact_id' => $organization1, - )); - $membershipType2 = $this->membershipTypeCreate(array( + ]); + $membershipType2 = $this->membershipTypeCreate([ 'name' => 'Membership Type 2', 'member_of_contact_id' => $organization1, - )); - $membershipType3 = $this->membershipTypeCreate(array( + ]); + $membershipType3 = $this->membershipTypeCreate([ 'name' => 'Membership Type 3', 'member_of_contact_id' => $organization2, - )); + ]); $priceDetails = CRM_Price_BAO_PriceSet::getSetDetail(CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceSet', @@ -121,11 +121,11 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { 'id', 'name' )); // fetch price field value IDs in array('membership_type_id' => 'price_field_value_id') format - $priceFieldValueIDs = array(); + $priceFieldValueIDs = []; foreach ($priceDetails as $priceFields) { foreach ($priceFields['fields'] as $priceField) { foreach ($priceField['options'] as $id => $priceFieldValue) { - if (in_array($priceFieldValue['membership_type_id'], array($membershipType1, $membershipType2, $membershipType3))) { + if (in_array($priceFieldValue['membership_type_id'], [$membershipType1, $membershipType2, $membershipType3])) { $priceFieldValueIDs[$priceFieldValue['membership_type_id']] = $id; } } @@ -133,10 +133,10 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { } // CASE 1: when two price field value IDs of membership type that belong to same organization, are chosen - $sameOrgPriceFieldIDs = implode(', ', array( + $sameOrgPriceFieldIDs = implode(', ', [ $priceFieldValueIDs[$membershipType1], $priceFieldValueIDs[$membershipType2], - )); + ]); $occurences = CRM_Price_BAO_PriceSet::getMembershipCount($sameOrgPriceFieldIDs); // total number of membership type occurences of same organisation is one $this->assertEquals(1, count($occurences)); @@ -145,10 +145,10 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { $this->assertEquals(2, $occurences[$organization1]); // CASE 2: when two price field value IDs of membership type that belong to different organizations, are chosen - $differentOrgPriceFieldIDs = implode(', ', array( + $differentOrgPriceFieldIDs = implode(', ', [ $priceFieldValueIDs[$membershipType1], $priceFieldValueIDs[$membershipType3], - )); + ]); $occurences = CRM_Price_BAO_PriceSet::getMembershipCount($differentOrgPriceFieldIDs); // total number of membership type occurences of different organisation is two $this->assertEquals(2, count($occurences)); diff --git a/tests/phpunit/CRM/Price/Form/FieldTest.php b/tests/phpunit/CRM/Price/Form/FieldTest.php index 08ede64999..3792650976 100644 --- a/tests/phpunit/CRM/Price/Form/FieldTest.php +++ b/tests/phpunit/CRM/Price/Form/FieldTest.php @@ -11,22 +11,22 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array( + $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [ 'labelColumn' => 'name', 'flip' => TRUE, - )); + ]); - $this->publicFieldParams = $this->initializeFieldParameters(array( + $this->publicFieldParams = $this->initializeFieldParameters([ 'label' => 'Public Price Field', 'name' => 'public_price', 'visibility_id' => $this->visibilityOptionsKeys['public'], - )); + ]); - $this->adminFieldParams = $this->initializeFieldParameters(array( + $this->adminFieldParams = $this->initializeFieldParameters([ 'label' => 'Public Price Field', 'name' => 'public_price', 'visibility_id' => $this->visibilityOptionsKeys['admin'], - )); + ]); } public function testPublicFieldWithOnlyAdminOptionsIsNotAllowed() { @@ -36,7 +36,7 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase { $form = new CRM_Price_Form_Field(); $form->_action = CRM_Core_Action::ADD; - $files = array(); + $files = []; $validationResult = $form->formRule($this->publicFieldParams, $files, $form); $this->assertType('array', $validationResult); @@ -50,7 +50,7 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase { $form = new CRM_Price_Form_Field(); $form->_action = CRM_Core_Action::ADD; - $files = array(); + $files = []; $validationResult = $form->formRule($this->adminFieldParams, $files, $form); $this->assertType('array', $validationResult); @@ -58,7 +58,7 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase { } private function initializeFieldParameters($params) { - $defaultParams = array( + $defaultParams = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Select', @@ -68,7 +68,7 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase { 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), 'visibility_id' => $this->visibilityOptionsKeys['public'], - ); + ]; for ($index = 1; $index <= CRM_Price_Form_Field::NUM_OPTION; $index++) { $defaultParams['option_label'][$index] = NULL; diff --git a/tests/phpunit/CRM/Queue/Queue/SqlTest.php b/tests/phpunit/CRM/Queue/Queue/SqlTest.php index 9ad85a79e4..21136193f6 100644 --- a/tests/phpunit/CRM/Queue/Queue/SqlTest.php +++ b/tests/phpunit/CRM/Queue/Queue/SqlTest.php @@ -41,13 +41,13 @@ class CRM_Queue_Queue_SqlTest extends CiviUnitTestCase { * Return a list of persistent and transient queue providers. */ public function getQueueSpecs() { - $queueSpecs = array(); - $queueSpecs[] = array( - array( + $queueSpecs = []; + $queueSpecs[] = [ + [ 'type' => 'Sql', 'name' => 'test-queue', - ), - ); + ], + ]; return $queueSpecs; } @@ -63,7 +63,7 @@ class CRM_Queue_Queue_SqlTest extends CiviUnitTestCase { public function tearDown() { CRM_Utils_Time::resetTime(); - $tablesToTruncate = array('civicrm_queue_item'); + $tablesToTruncate = ['civicrm_queue_item']; $this->quickCleanup($tablesToTruncate); } @@ -77,15 +77,15 @@ class CRM_Queue_Queue_SqlTest extends CiviUnitTestCase { $this->queue = $this->queueService->create($queueSpec); $this->assertTrue($this->queue instanceof CRM_Queue_Queue); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'b', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'c', - )); + ]); $this->assertEquals(3, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); @@ -98,24 +98,24 @@ class CRM_Queue_Queue_SqlTest extends CiviUnitTestCase { $this->queue->deleteItem($item); $this->queue->createItem( - array( + [ 'test-key' => 'start', - ), - array( + ], + [ 'weight' => -1, - ) + ] ); $this->queue->createItem( - array( + [ 'test-key' => 'end', - ), - array( + ], + [ 'weight' => 1, - ) + ] ); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'd', - )); + ]); $this->assertEquals(4, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); diff --git a/tests/phpunit/CRM/Queue/QueueTest.php b/tests/phpunit/CRM/Queue/QueueTest.php index bad275d666..d6a5b0aeeb 100644 --- a/tests/phpunit/CRM/Queue/QueueTest.php +++ b/tests/phpunit/CRM/Queue/QueueTest.php @@ -39,19 +39,19 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { * Return a list of persistent and transient queue providers. */ public function getQueueSpecs() { - $queueSpecs = array(); - $queueSpecs[] = array( - array( + $queueSpecs = []; + $queueSpecs[] = [ + [ 'type' => 'Sql', 'name' => 'test-queue', - ), - ); - $queueSpecs[] = array( - array( + ], + ]; + $queueSpecs[] = [ + [ 'type' => 'Memory', 'name' => 'test-queue', - ), - ); + ], + ]; return $queueSpecs; } @@ -66,7 +66,7 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { public function tearDown() { CRM_Utils_Time::resetTime(); - $tablesToTruncate = array('civicrm_queue_item'); + $tablesToTruncate = ['civicrm_queue_item']; $this->quickCleanup($tablesToTruncate); } @@ -80,15 +80,15 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { $this->queue = $this->queueService->create($queueSpec); $this->assertTrue($this->queue instanceof CRM_Queue_Queue); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'b', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'c', - )); + ]); $this->assertEquals(3, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); @@ -100,9 +100,9 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { $this->assertEquals('b', $item->data['test-key']); $this->queue->deleteItem($item); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'd', - )); + ]); $this->assertEquals(2, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); @@ -127,9 +127,9 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { $this->queue = $this->queueService->create($queueSpec); $this->assertTrue($this->queue instanceof CRM_Queue_Queue); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); + ]); $item = $this->queue->claimItem(); $this->assertEquals('a', $item->data['test-key']); @@ -156,9 +156,9 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { $this->assertTrue($this->queue instanceof CRM_Queue_Queue); CRM_Utils_Time::setTime('2012-04-01 1:00:00'); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); + ]); $item = $this->queue->claimItem(); $this->assertEquals('a', $item->data['test-key']); @@ -191,9 +191,9 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { $this->assertTrue($this->queue instanceof CRM_Queue_Queue); CRM_Utils_Time::setTime('2012-04-01 1:00:00'); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); + ]); $item = $this->queue->claimItem(); $this->assertEquals('a', $item->data['test-key']); @@ -222,17 +222,17 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { */ public function testCreateResetTrue($queueSpec) { $this->queue = $this->queueService->create($queueSpec); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'b', - )); + ]); $this->assertEquals(2, $this->queue->numberOfItems()); unset($this->queue); $queue2 = $this->queueService->create( - $queueSpec + array('reset' => TRUE) + $queueSpec + ['reset' => TRUE] ); $this->assertEquals(0, $queue2->numberOfItems()); } @@ -245,12 +245,12 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { */ public function testCreateResetFalse($queueSpec) { $this->queue = $this->queueService->create($queueSpec); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'b', - )); + ]); $this->assertEquals(2, $this->queue->numberOfItems()); unset($this->queue); @@ -270,12 +270,12 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase { */ public function testLoad($queueSpec) { $this->queue = $this->queueService->create($queueSpec); - $this->queue->createItem(array( + $this->queue->createItem([ 'test-key' => 'a', - )); - $this->queue->createItem(array( + ]); + $this->queue->createItem([ 'test-key' => 'b', - )); + ]); $this->assertEquals(2, $this->queue->numberOfItems()); unset($this->queue); diff --git a/tests/phpunit/CRM/Queue/RunnerTest.php b/tests/phpunit/CRM/Queue/RunnerTest.php index 1216ce41f9..81852801d0 100644 --- a/tests/phpunit/CRM/Queue/RunnerTest.php +++ b/tests/phpunit/CRM/Queue/RunnerTest.php @@ -34,11 +34,11 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->queueService = CRM_Queue_Service::singleton(TRUE); - $this->queue = $this->queueService->create(array( + $this->queue = $this->queueService->create([ 'type' => 'Sql', 'name' => 'test-queue', - )); - self::$_recordedValues = array(); + ]); + self::$_recordedValues = []; } public function tearDown() { @@ -47,38 +47,38 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { CRM_Utils_Time::resetTime(); - $tablesToTruncate = array('civicrm_queue_item'); + $tablesToTruncate = ['civicrm_queue_item']; $this->quickCleanup($tablesToTruncate); } public function testRunAllNormal() { // prepare a list of tasks with an error in the middle $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('a'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['a'], 'Add "a"' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('b'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['b'], 'Add "b"' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('c'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['c'], 'Add "c"' )); // run the list of tasks - $runner = new CRM_Queue_Runner(array( + $runner = new CRM_Queue_Runner([ 'queue' => $this->queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, - )); - $this->assertEquals(self::$_recordedValues, array()); + ]); + $this->assertEquals(self::$_recordedValues, []); $this->assertEquals(3, $this->queue->numberOfItems()); $result = $runner->runAll(); $this->assertEquals(TRUE, $result); - $this->assertEquals(self::$_recordedValues, array('a', 'b', 'c')); + $this->assertEquals(self::$_recordedValues, ['a', 'b', 'c']); $this->assertEquals(0, $this->queue->numberOfItems()); } @@ -90,31 +90,31 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { public function testRunAll_AddMore() { // Prepare a list of tasks with an error in the middle. $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('a'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['a'], 'Add "a"' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_enqueueNumbers'), - array(1, 3), + ['CRM_Queue_RunnerTest', '_enqueueNumbers'], + [1, 3], 'Add more' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('b'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['b'], 'Add "b"' )); // run the list of tasks - $runner = new CRM_Queue_Runner(array( + $runner = new CRM_Queue_Runner([ 'queue' => $this->queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, - )); - $this->assertEquals(self::$_recordedValues, array()); + ]); + $this->assertEquals(self::$_recordedValues, []); $this->assertEquals(3, $this->queue->numberOfItems()); $result = $runner->runAll(); $this->assertEquals(TRUE, $result); - $this->assertEquals(self::$_recordedValues, array('a', 1, 2, 3, 'b')); + $this->assertEquals(self::$_recordedValues, ['a', 1, 2, 3, 'b']); $this->assertEquals(0, $this->queue->numberOfItems()); } @@ -125,32 +125,32 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { public function testRunAll_Continue_Exception() { // prepare a list of tasks with an error in the middle $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('a'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['a'], 'Add "a"' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_throwException'), - array('b'), + ['CRM_Queue_RunnerTest', '_throwException'], + ['b'], 'Throw exception' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('c'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['c'], 'Add "c"' )); // run the list of tasks - $runner = new CRM_Queue_Runner(array( + $runner = new CRM_Queue_Runner([ 'queue' => $this->queue, 'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE, - )); - $this->assertEquals(self::$_recordedValues, array()); + ]); + $this->assertEquals(self::$_recordedValues, []); $this->assertEquals(3, $this->queue->numberOfItems()); $result = $runner->runAll(); // FIXME useless return $this->assertEquals(TRUE, $result); - $this->assertEquals(self::$_recordedValues, array('a', 'c')); + $this->assertEquals(self::$_recordedValues, ['a', 'c']); $this->assertEquals(0, $this->queue->numberOfItems()); } @@ -161,32 +161,32 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { public function testRunAll_Abort_Exception() { // prepare a list of tasks with an error in the middle $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('a'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['a'], 'Add "a"' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_throwException'), - array('b'), + ['CRM_Queue_RunnerTest', '_throwException'], + ['b'], 'Throw exception' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('c'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['c'], 'Add "c"' )); // run the list of tasks - $runner = new CRM_Queue_Runner(array( + $runner = new CRM_Queue_Runner([ 'queue' => $this->queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, - )); - $this->assertEquals(self::$_recordedValues, array()); + ]); + $this->assertEquals(self::$_recordedValues, []); $this->assertEquals(3, $this->queue->numberOfItems()); $result = $runner->runAll(); $this->assertEquals(1, $result['is_error']); // nothing from 'c' - $this->assertEquals(self::$_recordedValues, array('a')); + $this->assertEquals(self::$_recordedValues, ['a']); // 'b' and 'c' remain $this->assertEquals(2, $this->queue->numberOfItems()); } @@ -198,32 +198,32 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { public function testRunAll_Abort_False() { // prepare a list of tasks with an error in the middle $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('a'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['a'], 'Add "a"' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_returnFalse'), - array(), + ['CRM_Queue_RunnerTest', '_returnFalse'], + [], 'Return false' )); $this->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array('c'), + ['CRM_Queue_RunnerTest', '_recordValue'], + ['c'], 'Add "c"' )); // run the list of tasks - $runner = new CRM_Queue_Runner(array( + $runner = new CRM_Queue_Runner([ 'queue' => $this->queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, - )); - $this->assertEquals(self::$_recordedValues, array()); + ]); + $this->assertEquals(self::$_recordedValues, []); $this->assertEquals(3, $this->queue->numberOfItems()); $result = $runner->runAll(); $this->assertEquals(1, $result['is_error']); // nothing from 'c' - $this->assertEquals(self::$_recordedValues, array('a')); + $this->assertEquals(self::$_recordedValues, ['a']); // 'b' and 'c' remain $this->assertEquals(2, $this->queue->numberOfItems()); } @@ -274,12 +274,12 @@ class CRM_Queue_RunnerTest extends CiviUnitTestCase { public static function _enqueueNumbers($taskCtx, $low, $high) { for ($i = $low; $i <= $high; $i++) { $taskCtx->queue->createItem(new CRM_Queue_Task( - array('CRM_Queue_RunnerTest', '_recordValue'), - array($i), + ['CRM_Queue_RunnerTest', '_recordValue'], + [$i], sprintf('Add number "%d"', $i) - ), array( + ), [ 'weight' => -1, - )); + ]); } return TRUE; } diff --git a/tests/phpunit/CRM/Report/Form/ActivityTest.php b/tests/phpunit/CRM/Report/Form/ActivityTest.php index d7001ea91a..8a3ac33ca7 100644 --- a/tests/phpunit/CRM/Report/Form/ActivityTest.php +++ b/tests/phpunit/CRM/Report/Form/ActivityTest.php @@ -31,13 +31,13 @@ * @package CiviCRM */ class CRM_Report_Form_ActivityTest extends CiviReportTestCase { - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_contact', 'civicrm_email', 'civicrm_phone', 'civicrm_address', 'civicrm_contribution', - ); + ]; public function setUp() { parent::setUp(); @@ -55,23 +55,23 @@ class CRM_Report_Form_ActivityTest extends CiviReportTestCase { public function testLongCustomFieldNames() { // Create custom group with long name and custom field with long name. $long_name = 'this is a very very very very long name with 65 characters in it'; - $group_params = array( + $group_params = [ 'title' => $long_name, 'extends' => 'Activity', - ); + ]; $result = $this->customGroupCreate($group_params); $custom_group_id = $result['id']; - $field_params = array( + $field_params = [ 'custom_group_id' => $custom_group_id, 'label' => $long_name, - ); + ]; $result = $this->customFieldCreate($field_params); $custom_field_id = $result['id']; - $input = array( - 'fields' => array( + $input = [ + 'fields' => [ 'custom_' . $custom_field_id, - ), - ); + ], + ]; $obj = $this->getReportObject('CRM_Report_Form_Activity', $input); //$params = $obj->_params; //$params['fields'] = array('custom_' . $custom_field_id); @@ -86,40 +86,40 @@ class CRM_Report_Form_ActivityTest extends CiviReportTestCase { public function testTargetAddressFields() { $countryNames = array_flip(CRM_Core_PseudoConstant::country()); // Create contact 1 and 2 with address fields, later considered as target contacts for activity - $contactID1 = $this->individualCreate(array( - 'api.Address.create' => array( + $contactID1 = $this->individualCreate([ + 'api.Address.create' => [ 'contact_id' => '$value.id', 'location_type_id' => 'Home', 'city' => 'ABC', 'country_id' => $countryNames['India'], - ), - )); - $contactID2 = $this->individualCreate(array( - 'api.Address.create' => array( + ], + ]); + $contactID2 = $this->individualCreate([ + 'api.Address.create' => [ 'contact_id' => '$value.id', 'location_type_id' => 'Home', 'city' => 'DEF', 'country_id' => $countryNames['United States'], - ), - )); + ], + ]); // Create Contact 3 later considered as assignee contact of activity - $contactID3 = $this->individualCreate(array( - 'api.Address.create' => array( + $contactID3 = $this->individualCreate([ + 'api.Address.create' => [ 'contact_id' => '$value.id', 'location_type_id' => 'Home', 'city' => 'GHI', 'country_id' => $countryNames['China'], - ), - )); + ], + ]); // create dummy activity type - $activityTypeID = CRM_Utils_Array::value('id', $this->callAPISuccess('option_value', 'create', array( + $activityTypeID = CRM_Utils_Array::value('id', $this->callAPISuccess('option_value', 'create', [ 'option_group_id' => 'activity_type', 'name' => 'Test activity type', 'label' => 'Test activity type', - ))); + ])); // create activity - $result = $this->callAPISuccess('activity', 'create', array( + $result = $this->callAPISuccess('activity', 'create', [ 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -128,20 +128,20 @@ class CRM_Report_Form_ActivityTest extends CiviReportTestCase { 'status_id' => 1, 'activity_type_id' => 'Test activity type', 'source_contact_id' => $this->individualCreate(), - 'target_contact_id' => array($contactID1, $contactID2), + 'target_contact_id' => [$contactID1, $contactID2], 'assignee_contact_id' => $contactID3, - )); + ]); // display city and country field so that we can check its value - $input = array( - 'fields' => array( + $input = [ + 'fields' => [ 'city', 'country_id', - ), - 'order_bys' => array( - 'city' => array(), - 'country_id' => array('default' => TRUE), - ), - ); + ], + 'order_bys' => [ + 'city' => [], + 'country_id' => ['default' => TRUE], + ], + ]; // generate result $obj = $this->getReportObject('CRM_Report_Form_Activity', $input); $rows = $obj->getResultSet(); diff --git a/tests/phpunit/CRM/Report/Form/ContactSummaryTest.php b/tests/phpunit/CRM/Report/Form/ContactSummaryTest.php index 4a4077707e..b173d4d462 100644 --- a/tests/phpunit/CRM/Report/Form/ContactSummaryTest.php +++ b/tests/phpunit/CRM/Report/Form/ContactSummaryTest.php @@ -31,12 +31,12 @@ * @package CiviCRM */ class CRM_Report_Form_ContactSummaryTest extends CiviReportTestCase { - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_contact', 'civicrm_email', 'civicrm_phone', 'civicrm_address', - ); + ]; public function setUp() { parent::setUp(); diff --git a/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php b/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php index acea3ddb88..84e12169f1 100644 --- a/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php +++ b/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php @@ -31,38 +31,38 @@ * @package CiviCRM */ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase { - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_contact', 'civicrm_email', 'civicrm_phone', 'civicrm_address', 'civicrm_contribution', - ); + ]; /** * @return array */ public function dataProvider() { - return array( - array( + return [ + [ 'CRM_Report_Form_Contribute_Detail', - array( - 'fields' => array( + [ + 'fields' => [ 'sort_name', 'first_name', 'email', 'total_amount', - ), - 'filters' => array( + ], + 'filters' => [ 'total_amount_op' => 'gte', 'total_amount_value' => 50, - ), + ], // FIXME: add filters - ), + ], 'fixtures/dataset-ascii.sql', 'fixtures/report-ascii.csv', - ), - ); + ], + ]; } public function setUp() { @@ -111,26 +111,26 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase { * @return array */ public function postalCodeDataProvider() { - return array( - array( + return [ + [ 'CRM_Report_Form_Contribute_Detail', - array( - 'fields' => array( + [ + 'fields' => [ 'sort_name', 'first_name', 'email', 'total_amount', 'postal_code', - ), - 'filters' => array( + ], + 'filters' => [ 'postal_code_value' => 'B10 G56', 'postal_code_op' => 'has', - ), - ), + ], + ], 'fixtures/dataset-ascii.sql', 'fixtures/DetailPostalCodeTest-ascii.csv', - ), - ); + ], + ]; } /** @@ -159,11 +159,11 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase { public function testMultipleSoftCredits() { $this->quickCleanup($this->_tablesToTruncate); - $solParams = array( + $solParams = [ 'first_name' => 'Solicitor 1', 'last_name' => 'User ' . rand(), 'contact_type' => 'Individual', - ); + ]; $solicitor1Id = $this->individualCreate($solParams); $solParams['first_name'] = 'Solicitor 2'; $solicitor2Id = $this->individualCreate($solParams); diff --git a/tests/phpunit/CRM/Report/Form/TestCaseTest.php b/tests/phpunit/CRM/Report/Form/TestCaseTest.php index 20b1fe7026..a4a8945d65 100644 --- a/tests/phpunit/CRM/Report/Form/TestCaseTest.php +++ b/tests/phpunit/CRM/Report/Form/TestCaseTest.php @@ -38,38 +38,38 @@ require_once 'CiviTest/CiviReportTestCase.php'; * @package CiviCRM */ class CRM_Report_Form_TestCaseTest extends CiviReportTestCase { - protected $_tablesToTruncate = array( + protected $_tablesToTruncate = [ 'civicrm_contact', 'civicrm_email', 'civicrm_phone', 'civicrm_address', 'civicrm_contribution', - ); + ]; /** * @return array */ public function dataProvider() { - $testCaseA = array( + $testCaseA = [ 'CRM_Report_Form_Contribute_Detail', - array( - 'fields' => array( + [ + 'fields' => [ 'sort_name', 'first_name', 'email', 'total_amount', - ), - 'filters' => array( + ], + 'filters' => [ 'total_amount_op' => 'gte', 'total_amount_value' => 50, - ), + ], // FIXME: add filters - ), + ], 'Contribute/fixtures/dataset-ascii.sql', 'Contribute/fixtures/report-ascii.csv', - ); + ]; - return array( + return [ $testCaseA, $testCaseA, $testCaseA, @@ -77,56 +77,56 @@ class CRM_Report_Form_TestCaseTest extends CiviReportTestCase { // ensure that CiviReportTestCase can // clean up sufficiently to run // multiple tests. - ); + ]; } /** * @return array */ public function badDataProvider() { - return array( + return [ // This test-case is bad because the dataset-ascii.sql does not match the // report.csv (due to differences in international chars) - array( + [ 'CRM_Report_Form_Contribute_Detail', - array( - 'fields' => array( + [ + 'fields' => [ 'sort_name', 'first_name', 'email', 'total_amount', - ), - 'filters' => array( + ], + 'filters' => [ 'total_amount_op' => 'gte', 'total_amount_value' => 50, - ), + ], // FIXME: add filters - ), + ], 'Contribute/fixtures/dataset-ascii.sql', 'Contribute/fixtures/report.csv', - ), + ], // This test-case is bad because the filters check for // an amount >= $100, but the test data includes records // for $50. - array( + [ 'CRM_Report_Form_Contribute_Detail', - array( - 'fields' => array( + [ + 'fields' => [ 'sort_name', 'first_name', 'email', 'total_amount', - ), - 'filters' => array( + ], + 'filters' => [ 'total_amount_op' => 'gte', 'total_amount_value' => 100, - ), + ], // FIXME: add filters - ), + ], 'Contribute/fixtures/dataset-ascii.sql', 'Contribute/fixtures/report.csv', - ), - ); + ], + ]; } public function setUp() { @@ -192,15 +192,15 @@ class CRM_Report_Form_TestCaseTest extends CiviReportTestCase { $outputMode = $clazz->getProperty('_outputMode'); $outputMode->setAccessible(TRUE); - $params->setValue($reportForm, array('groups' => 4)); + $params->setValue($reportForm, ['groups' => 4]); $reportForm->processReportMode(); $this->assertEquals('group', $outputMode->getValue($reportForm)); - $params->setValue($reportForm, array('task' => 'copy')); + $params->setValue($reportForm, ['task' => 'copy']); $reportForm->processReportMode(); $this->assertEquals('copy', $outputMode->getValue($reportForm)); - $params->setValue($reportForm, array('task' => 'print')); + $params->setValue($reportForm, ['task' => 'print']); $reportForm->processReportMode(); $this->assertEquals('print', $outputMode->getValue($reportForm)); } diff --git a/tests/phpunit/CRM/Report/FormTest.php b/tests/phpunit/CRM/Report/FormTest.php index 5d0b0313a4..e25eae3971 100644 --- a/tests/phpunit/CRM/Report/FormTest.php +++ b/tests/phpunit/CRM/Report/FormTest.php @@ -53,20 +53,20 @@ class CRM_Report_FormTest extends CiviUnitTestCase { } public function fromToData() { - $cases = array(); + $cases = []; // Absolute dates - $cases[] = array('20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017'); + $cases[] = ['20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017']; // "Today" relative date filter $date = new DateTime(); $expectedFrom = $date->format('Ymd') . '000000'; $expectedTo = $date->format('Ymd') . '235959'; - $cases[] = array($expectedFrom, $expectedTo, 'this.day', '', ''); + $cases[] = [$expectedFrom, $expectedTo, 'this.day', '', '']; // "yesterday" relative date filter $date = new DateTime(); $date->sub(new DateInterval('P1D')); $expectedFrom = $date->format('Ymd') . '000000'; $expectedTo = $date->format('Ymd') . '235959'; - $cases[] = array($expectedFrom, $expectedTo, 'previous.day', '', ''); + $cases[] = [$expectedFrom, $expectedTo, 'previous.day', '', '']; return $cases; } diff --git a/tests/phpunit/CRM/SMS/BAO/ProviderTest.php b/tests/phpunit/CRM/SMS/BAO/ProviderTest.php index c495627c99..6840485d33 100644 --- a/tests/phpunit/CRM/SMS/BAO/ProviderTest.php +++ b/tests/phpunit/CRM/SMS/BAO/ProviderTest.php @@ -39,7 +39,7 @@ class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { */ public function setUp() { parent::setUp(); - $option = $this->callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1)); + $option = $this->callAPISuccess('option_value', 'create', ['option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1]); $this->option_value = $option['id']; } @@ -48,14 +48,14 @@ class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { */ public function tearDown() { parent::tearDown(); - $this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value)); + $this->callAPISuccess('option_value', 'delete', ['id' => $this->option_value]); } /** * CRM-19961 Check that when saving and updating a SMS provider with domain as NULL that it stays null */ public function testCreateAndUpdateProvider() { - $values = array( + $values = [ 'domain_id' => NULL, 'title' => 'test SMS provider', 'username' => 'test', @@ -63,14 +63,14 @@ class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { 'name' => 1, 'is_active' => 1, 'api_type' => 1, - ); + ]; $this->callAPISuccess('SmsProvider', 'create', $values); - $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider')); + $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['title' => 'test SMS provider']); $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id'); $this->assertNull($domain_id); - $values2 = array('title' => 'Test SMS Provider2', 'id' => $provider['id']); + $values2 = ['title' => 'Test SMS Provider2', 'id' => $provider['id']]; $this->callAPISuccess('SmsProvider', 'create', $values2); - $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('id' => $provider['id'])); + $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['id' => $provider['id']]); $this->assertEquals('Test SMS Provider2', $provider['title']); $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id'); $this->assertNull($domain_id); @@ -82,7 +82,7 @@ class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { * Add unit test to ensure that filtering by domain works in get Active Providers */ public function testActiveProviderCount() { - $values = array( + $values = [ 'domain_id' => NULL, 'title' => 'test SMS provider', 'username' => 'test', @@ -90,12 +90,12 @@ class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { 'name' => 1, 'is_active' => 1, 'api_type' => 1, - ); + ]; $provider = $this->callAPISuccess('SmsProvider', 'create', $values); - $provider2 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, array('domain_id' => 2))); + $provider2 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, ['domain_id' => 2])); $result = CRM_SMS_BAO_Provider::activeProviderCount(); $this->assertEquals(1, $result); - $provider3 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, array('domain_id' => 1))); + $provider3 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, ['domain_id' => 1])); $result = CRM_SMS_BAO_Provider::activeProviderCount(); $this->assertEquals(2, $result); CRM_SMS_BAO_Provider::del($provider['id']); @@ -107,16 +107,16 @@ class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { * CRM-19961 Check that when a domain is not passed when saving it defaults to current domain when create */ public function testCreateWithoutDomain() { - $values = array( + $values = [ 'title' => 'test SMS provider', 'username' => 'test', 'password' => 'dummpy password', 'name' => 1, 'is_active' => 1, 'api_type' => 1, - ); + ]; $this->callAPISuccess('SmsProvider', 'create', $values); - $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider')); + $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['title' => 'test SMS provider']); $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id'); $this->assertEquals(CRM_Core_Config::domainID(), $domain_id); CRM_SMS_BAO_Provider::del($provider['id']); diff --git a/tests/phpunit/CRM/SMS/ProviderTest.php b/tests/phpunit/CRM/SMS/ProviderTest.php index bf03ef8ec2..5bb81b18bb 100644 --- a/tests/phpunit/CRM/SMS/ProviderTest.php +++ b/tests/phpunit/CRM/SMS/ProviderTest.php @@ -41,7 +41,7 @@ class CRM_SMS_ProviderTest extends CiviUnitTestCase { */ public function setUp() { parent::setUp(); - $option = $this->callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1)); + $option = $this->callAPISuccess('option_value', 'create', ['option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1]); $this->option_value = $option['id']; } @@ -50,15 +50,15 @@ class CRM_SMS_ProviderTest extends CiviUnitTestCase { */ public function tearDown() { parent::tearDown(); - $this->quickCleanup(array('civicrm_email', 'civicrm_phone', 'civicrm_activity', 'civicrm_activity_contact')); - $this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value)); + $this->quickCleanup(['civicrm_email', 'civicrm_phone', 'civicrm_activity', 'civicrm_activity_contact']); + $this->callAPISuccess('option_value', 'delete', ['id' => $this->option_value]); } /** * CRM-20238 Add test of the processInbound function for SMSs */ public function testProcessInbound() { - $testSourceContact = $this->individualCreate(array('phone' => array(1 => array('phone_type_id' => 'Phone', 'location_type_id' => 'Home', 'phone' => '+61487654321')))); + $testSourceContact = $this->individualCreate(['phone' => [1 => ['phone_type_id' => 'Phone', 'location_type_id' => 'Home', 'phone' => '+61487654321']]]); $provider = new CiviTestSMSProvider('CiviTestSMSProvider'); $result = $provider->processInbound('+61412345678', 'This is a test message', '+61487654321'); $this->assertEquals('This is a test message', $result->details); @@ -74,8 +74,8 @@ class CRM_SMS_ProviderTest extends CiviUnitTestCase { $this->assertEquals('This is a test message', $result->details); $this->assertEquals('+61412345678', $result->phone_number); $this->assertEquals('12345', $result->result); - $activity = $this->callAPISuccess('activity', 'getsingle', array('id' => $result->id, 'return' => array('source_contact_id', 'target_contact_id', 'assignee_contact_id'))); - $contact = $this->callAPISuccess('contact', 'getsingle', array('phone' => '61412345678')); + $activity = $this->callAPISuccess('activity', 'getsingle', ['id' => $result->id, 'return' => ['source_contact_id', 'target_contact_id', 'assignee_contact_id']]); + $contact = $this->callAPISuccess('contact', 'getsingle', ['phone' => '61412345678']); // Verify that when no to is passed in by default the same contact is used for the source and target. $this->assertEquals($contact['id'], $activity['source_contact_id']); $this->assertEquals($contact['id'], $activity['target_contact_id'][0]); @@ -86,18 +86,18 @@ class CRM_SMS_ProviderTest extends CiviUnitTestCase { */ public function testProcessInboundSetToContactIDUsingHook() { $provider = new CiviTestSMSProvider('CiviTestSMSProvider'); - $this->hookClass->setHook('civicrm_inboundSMS', array($this, 'smsHookTest')); + $this->hookClass->setHook('civicrm_inboundSMS', [$this, 'smsHookTest']); $result = $provider->processInbound('+61412345678', 'This is a test message', NULL, '12345'); $this->assertEquals('This is a test message', $result->details); $this->assertEquals('+61412345678', $result->phone_number); $this->assertEquals('12345', $result->result); - $contact = $this->callAPISuccess('contact', 'getsingle', array('phone' => '+61487654321')); - $activity = $this->callAPISuccess('activity', 'getsingle', array('id' => $result->id, 'return' => array('source_contact_id', 'target_contact_id', 'assignee_contact_id'))); + $contact = $this->callAPISuccess('contact', 'getsingle', ['phone' => '+61487654321']); + $activity = $this->callAPISuccess('activity', 'getsingle', ['id' => $result->id, 'return' => ['source_contact_id', 'target_contact_id', 'assignee_contact_id']]); $this->assertEquals($contact['id'], $activity['source_contact_id']); } public function smsHookTest(&$message) { - $testSourceContact = $this->individualCreate(array('phone' => array(1 => array('phone' => '+61487654321')))); + $testSourceContact = $this->individualCreate(['phone' => [1 => ['phone' => '+61487654321']]]); $message->toContactID = $testSourceContact; } diff --git a/tests/phpunit/CRM/UF/Page/ProfileEditorTest.php b/tests/phpunit/CRM/UF/Page/ProfileEditorTest.php index 94e4321cb1..6ee808a435 100644 --- a/tests/phpunit/CRM/UF/Page/ProfileEditorTest.php +++ b/tests/phpunit/CRM/UF/Page/ProfileEditorTest.php @@ -14,7 +14,7 @@ class CRM_UF_Page_ProfileEditorTest extends CiviUnitTestCase { * Spot check a few fields that should appear in schema. */ public function testGetSchema() { - $schema = CRM_UF_Page_ProfileEditor::getSchema(array('IndividualModel', 'ActivityModel')); + $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'ActivityModel']); foreach ($schema as $entityName => $entityDef) { foreach ($entityDef['schema'] as $fieldName => $fieldDef) { $this->assertNotEmpty($fieldDef['type']); diff --git a/tests/phpunit/CRM/Utils/API/MatchOptionTest.php b/tests/phpunit/CRM/Utils/API/MatchOptionTest.php index 4ba2d584bf..aa42826065 100644 --- a/tests/phpunit/CRM/Utils/API/MatchOptionTest.php +++ b/tests/phpunit/CRM/Utils/API/MatchOptionTest.php @@ -16,34 +16,34 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_contact WHERE first_name='Jeffrey' and last_name='Lebowski'"); // Create noise to ensure we don't accidentally/coincidentally match the first record - $this->noise['individual'] = $this->individualCreate(array( + $this->noise['individual'] = $this->individualCreate([ 'email' => 'ignore1@example.com', // 'street_address-1' => 'Irrelevant' - 'api.Address.create' => array( + 'api.Address.create' => [ 'location_type_id' => 1, 'street_address' => '123 Irrelevant Str', 'supplemental_address_1' => 'Room 987', - ), - )); + ], + ]); } public function tearDown() { - $noise = $this->callAPISuccess('Contact', 'get', array( + $noise = $this->callAPISuccess('Contact', 'get', [ 'id' => $this->noise['individual'], - 'return' => array('email'), + 'return' => ['email'], 'api.Address.get' => 1, - )); + ]); $this->assertEquals(1, count($noise['values'])); foreach ($noise['values'] as $value) { $this->assertEquals('ignore1@example.com', $value['email']); $this->assertEquals(1, count($value['api.Address.get']['values'])); } - CRM_core_DAO::executeQuery('DELETE FROM civicrm_address WHERE contact_id=%1', array( - 1 => array($this->noise['individual'], 'Positive'), - )); - $this->callAPISuccess('Contact', 'delete', array( + CRM_core_DAO::executeQuery('DELETE FROM civicrm_address WHERE contact_id=%1', [ + 1 => [$this->noise['individual'], 'Positive'], + ]); + $this->callAPISuccess('Contact', 'delete', [ 'id' => $this->noise['individual'], - )); + ]); parent::tearDown(); } @@ -51,16 +51,16 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { * If there's no pre-existing record, then insert a new one. */ public function testCreateMatch_none() { - $result = $this->callAPISuccess('contact', 'create', array( - 'options' => array( - 'match' => array('first_name', 'last_name'), - ), + $result = $this->callAPISuccess('contact', 'create', [ + 'options' => [ + 'match' => ['first_name', 'last_name'], + ], 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => '', 'external_identifier' => '1', - )); + ]); $this->assertEquals('Jeffrey', $result['values'][$result['id']]['first_name']); $this->assertEquals('Lebowski', $result['values'][$result['id']]['last_name']); } @@ -69,26 +69,26 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { * If there's no pre-existing record, then throw an error. */ public function testCreateMatchMandatory_none() { - $this->callAPIFailure('contact', 'create', array( - 'options' => array( - 'match-mandatory' => array('first_name', 'last_name'), - ), + $this->callAPIFailure('contact', 'create', [ + 'options' => [ + 'match-mandatory' => ['first_name', 'last_name'], + ], 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => '', 'external_identifier' => '1', - ), 'Failed to match existing record'); + ], 'Failed to match existing record'); } /** * @return array */ public function apiOptionNames() { - return array( - array('match'), - array('match-mandatory'), - ); + return [ + ['match'], + ['match-mandatory'], + ]; } /** @@ -100,28 +100,28 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { */ public function testCreateMatch_one($apiOptionName) { // create basic record - $result1 = $this->callAPISuccess('contact', 'create', array( + $result1 = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => '', 'external_identifier' => '1', - )); + ]); // more noise! - $this->individualCreate(array('email' => 'ignore2@example.com')); + $this->individualCreate(['email' => 'ignore2@example.com']); // update the record by matching first/last name - $result2 = $this->callAPISuccess('contact', 'create', array( - 'options' => array( - $apiOptionName => array('first_name', 'last_name'), - ), + $result2 = $this->callAPISuccess('contact', 'create', [ + 'options' => [ + $apiOptionName => ['first_name', 'last_name'], + ], 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => 'The Dude', 'external_identifier' => '2', - )); + ]); $this->assertEquals($result1['id'], $result2['id']); $this->assertEquals('Jeffrey', $result2['values'][$result2['id']]['first_name']); @@ -140,37 +140,37 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { */ public function testCreateMatch_many($apiOptionName) { // create the first Lebowski - $result1 = $this->callAPISuccess('contact', 'create', array( + $result1 = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => 'The Dude', 'external_identifier' => '1', - )); + ]); // create the second Lebowski - $result2 = $this->callAPISuccess('contact', 'create', array( + $result2 = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => 'The Big Lebowski', 'external_identifier' => '2', - )); + ]); // more noise! - $this->individualCreate(array('email' => 'ignore2@example.com')); + $this->individualCreate(['email' => 'ignore2@example.com']); // Try to update - but fail due to ambiguity - $result3 = $this->callAPIFailure('contact', 'create', array( - 'options' => array( - $apiOptionName => array('first_name', 'last_name'), - ), + $result3 = $this->callAPIFailure('contact', 'create', [ + 'options' => [ + $apiOptionName => ['first_name', 'last_name'], + ], 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', 'nick_name' => '', 'external_identifier' => 'new', - ), 'Ambiguous match criteria'); + ], 'Ambiguous match criteria'); } /** @@ -179,22 +179,22 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { */ public function testReplaceMatch_Email() { // Create contact with two emails (j1,j2) - $createResult = $this->callAPISuccess('contact', 'create', array( + $createResult = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', - 'api.Email.replace' => array( - 'options' => array('match' => 'location_type_id'), - 'values' => array( - array('location_type_id' => 1, 'email' => 'j1-a@example.com', 'signature_text' => 'The Dude abides.'), - array( + 'api.Email.replace' => [ + 'options' => ['match' => 'location_type_id'], + 'values' => [ + ['location_type_id' => 1, 'email' => 'j1-a@example.com', 'signature_text' => 'The Dude abides.'], + [ 'location_type_id' => 2, 'email' => 'j2@example.com', 'signature_text' => 'You know, a lotta ins, a lotta outs, a lotta what-have-yous.', - ), - ), - ), - )); + ], + ], + ], + ]); $this->assertEquals(1, $createResult['count']); foreach ($createResult['values'] as $value) { $this->assertAPISuccess($value['api.Email.replace']); @@ -206,17 +206,17 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { } // Update contact's emails -- specifically, modify j1, delete j2, add j3 - $updateResult = $this->callAPISuccess('contact', 'create', array( + $updateResult = $this->callAPISuccess('contact', 'create', [ 'id' => $createResult['id'], 'nick_name' => 'The Dude', - 'api.Email.replace' => array( - 'options' => array('match' => 'location_type_id'), - 'values' => array( - array('location_type_id' => 1, 'email' => 'j1-b@example.com'), - array('location_type_id' => 3, 'email' => 'j3@example.com'), - ), - ), - )); + 'api.Email.replace' => [ + 'options' => ['match' => 'location_type_id'], + 'values' => [ + ['location_type_id' => 1, 'email' => 'j1-b@example.com'], + ['location_type_id' => 3, 'email' => 'j3@example.com'], + ], + ], + ]); $this->assertEquals(1, $updateResult['count']); foreach ($updateResult['values'] as $value) { $this->assertAPISuccess($value['api.Email.replace']); @@ -228,9 +228,9 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { } // Re-read from DB - $getResult = $this->callAPISuccess('Email', 'get', array( + $getResult = $this->callAPISuccess('Email', 'get', [ 'contact_id' => $createResult['id'], - )); + ]); $this->assertEquals(2, $getResult['count']); $getValues = array_values($getResult['values']); @@ -261,26 +261,26 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { */ public function testReplaceMatch_Address() { // Create contact with two addresses (j1,j2) - $createResult = $this->callAPISuccess('contact', 'create', array( + $createResult = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Jeffrey', 'last_name' => 'Lebowski', - 'api.Address.replace' => array( - 'options' => array('match' => 'location_type_id'), - 'values' => array( - array( + 'api.Address.replace' => [ + 'options' => ['match' => 'location_type_id'], + 'values' => [ + [ 'location_type_id' => 1, 'street_address' => 'j1-a Example Ave', 'supplemental_address_1' => 'The Dude abides.', - ), - array( + ], + [ 'location_type_id' => 2, 'street_address' => 'j2 Example Ave', 'supplemental_address_1' => 'You know, a lotta ins, a lotta outs, a lotta what-have-yous.', - ), - ), - ), - )); + ], + ], + ], + ]); $this->assertEquals(1, $createResult['count']); foreach ($createResult['values'] as $value) { $this->assertAPISuccess($value['api.Address.replace']); @@ -292,17 +292,17 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { } // Update contact's addresses -- specifically, modify j1, delete j2, add j3 - $updateResult = $this->callAPISuccess('contact', 'create', array( + $updateResult = $this->callAPISuccess('contact', 'create', [ 'id' => $createResult['id'], 'nick_name' => 'The Dude', - 'api.Address.replace' => array( - 'options' => array('match' => 'location_type_id'), - 'values' => array( - array('location_type_id' => 1, 'street_address' => 'j1-b Example Ave'), - array('location_type_id' => 3, 'street_address' => 'j3 Example Ave'), - ), - ), - )); + 'api.Address.replace' => [ + 'options' => ['match' => 'location_type_id'], + 'values' => [ + ['location_type_id' => 1, 'street_address' => 'j1-b Example Ave'], + ['location_type_id' => 3, 'street_address' => 'j3 Example Ave'], + ], + ], + ]); $this->assertEquals(1, $updateResult['count']); foreach ($updateResult['values'] as $value) { $this->assertAPISuccess($value['api.Address.replace']); @@ -314,9 +314,9 @@ class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase { } // Re-read from DB - $getResult = $this->callAPISuccess('Address', 'get', array( + $getResult = $this->callAPISuccess('Address', 'get', [ 'contact_id' => $createResult['id'], - )); + ]); $this->assertEquals(2, $getResult['count']); $getValues = array_values($getResult['values']); diff --git a/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php b/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php index 3fcb389df6..44491e8ce0 100644 --- a/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php +++ b/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php @@ -13,7 +13,7 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_post', array($this, 'onPost')); + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_post', [$this, 'onPost']); } /** @@ -21,12 +21,12 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * fact that the hook manipulated the actual DB content. */ public function testNoReload() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - )); + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); // munged by hook, but we haven't realized it $this->assertEquals('Firstie', $result['values'][$result['id']]['nick_name']); @@ -36,15 +36,15 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * When the reload option is unrecognized, generate an error */ public function testReloadInvalid() { - $this->callAPIFailure('contact', 'create', array( + $this->callAPIFailure('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'options' => array( + 'options' => [ 'reload' => 'invalid', - ), - )); + ], + ]); } /** @@ -52,15 +52,15 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * differs from the inputted nick_name. */ public function testReloadDefault() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'options' => array( + 'options' => [ 'reload' => 1, - ), - )); + ], + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); $this->assertEquals('munged', $result['values'][$result['id']]['nick_name']); } @@ -70,18 +70,18 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * the chain results. */ public function testReloadNoChainInterference() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'api.Email.create' => array( + 'api.Email.create' => [ 'email' => 'test@example.com', - ), - 'options' => array( + ], + 'options' => [ 'reload' => 1, - ), - )); + ], + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); $this->assertEquals('munged', $result['values'][$result['id']]['nick_name']); $this->assertAPISuccess($result['values'][$result['id']]['api.Email.create']); @@ -92,19 +92,19 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * the chain results, even if sequential=1. */ public function testReloadNoChainInterferenceSequential() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'sequential' => 1, 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'api.Email.create' => array( + 'api.Email.create' => [ 'email' => 'test@example.com', - ), - 'options' => array( + ], + 'options' => [ 'reload' => 1, - ), - )); + ], + ]); $this->assertEquals('First', $result['values'][0]['first_name']); $this->assertEquals('munged', $result['values'][0]['nick_name']); $this->assertAPISuccess($result['values'][0]['api.Email.create']); diff --git a/tests/phpunit/CRM/Utils/AddressTest.php b/tests/phpunit/CRM/Utils/AddressTest.php index 1f66726cae..3ce0a367fc 100644 --- a/tests/phpunit/CRM/Utils/AddressTest.php +++ b/tests/phpunit/CRM/Utils/AddressTest.php @@ -11,12 +11,12 @@ class CRM_Utils_AddressTest extends CiviUnitTestCase { } public function testAddressFormat() { - $contact = $this->callAPISuccess('contact', 'create', array( + $contact = $this->callAPISuccess('contact', 'create', [ 'first_name' => 'Micky', 'last_name' => 'mouse', 'contact_type' => 'Individual', - )); - $address = $this->callAPISuccess('address', 'create', array( + ]); + $address = $this->callAPISuccess('address', 'create', [ 'street_address' => '1 Happy Place', 'city' => 'Miami', 'state_province' => 'Flordia', @@ -25,7 +25,7 @@ class CRM_Utils_AddressTest extends CiviUnitTestCase { 'contact_id' => $contact['id'], 'location_type_id' => 5, 'is_primary' => 1, - )); + ]); $addressDetails = $address['values'][$address['id']]; $countries = CRM_Core_PseudoConstant::country(); $addressDetails['country'] = $countries[$addressDetails['country_id']]; @@ -38,14 +38,14 @@ class CRM_Utils_AddressTest extends CiviUnitTestCase { * and test using alternate names for state_province field */ public function testStateProvinceFormattedBillingAddress() { - $params = array( + $params = [ 'billing_street_address-99' => '123 Happy Place', 'billing_city-99' => 'Miami', 'billing_postal_code-99' => 33101, // 1000 => Alabama (AL) 'state_province-99' => '1000', 'country-99' => 'United States', - ); + ]; // set address_format (we are only interested in state_province & state_province_name) $addFormat = '{contact.state_province}'; diff --git a/tests/phpunit/CRM/Utils/ArrayTest.php b/tests/phpunit/CRM/Utils/ArrayTest.php index c4d56cbe51..7403576c5f 100644 --- a/tests/phpunit/CRM/Utils/ArrayTest.php +++ b/tests/phpunit/CRM/Utils/ArrayTest.php @@ -7,41 +7,41 @@ class CRM_Utils_ArrayTest extends CiviUnitTestCase { public function testIndexArray() { - $inputs = array(); - $inputs[] = array( + $inputs = []; + $inputs[] = [ 'lang' => 'en', 'msgid' => 'greeting', 'familiar' => FALSE, 'value' => 'Hello', - ); - $inputs[] = array( + ]; + $inputs[] = [ 'lang' => 'en', 'msgid' => 'parting', 'value' => 'Goodbye', - ); - $inputs[] = array( + ]; + $inputs[] = [ 'lang' => 'fr', 'msgid' => 'greeting', 'value' => 'Bon jour', - ); - $inputs[] = array( + ]; + $inputs[] = [ 'lang' => 'fr', 'msgid' => 'parting', 'value' => 'Au revoir', - ); - $inputs[] = array( + ]; + $inputs[] = [ 'lang' => 'en', 'msgid' => 'greeting', 'familiar' => TRUE, 'value' => 'Hey', - ); - $inputs[] = array( + ]; + $inputs[] = [ 'msgid' => 'greeting', 'familiar' => TRUE, 'value' => 'Universal greeting', - ); + ]; - $byLangMsgid = CRM_Utils_Array::index(array('lang', 'msgid'), $inputs); + $byLangMsgid = CRM_Utils_Array::index(['lang', 'msgid'], $inputs); $this->assertEquals($inputs[4], $byLangMsgid['en']['greeting']); $this->assertEquals($inputs[1], $byLangMsgid['en']['parting']); $this->assertEquals($inputs[2], $byLangMsgid['fr']['greeting']); @@ -50,157 +50,157 @@ class CRM_Utils_ArrayTest extends CiviUnitTestCase { } public function testCollect() { - $arr = array( - array('catWord' => 'cat', 'dogWord' => 'dog'), - array('catWord' => 'chat', 'dogWord' => 'chien'), - array('catWord' => 'gato'), - ); - $expected = array('cat', 'chat', 'gato'); + $arr = [ + ['catWord' => 'cat', 'dogWord' => 'dog'], + ['catWord' => 'chat', 'dogWord' => 'chien'], + ['catWord' => 'gato'], + ]; + $expected = ['cat', 'chat', 'gato']; $this->assertEquals($expected, CRM_Utils_Array::collect('catWord', $arr)); - $arr = array(); - $arr['en'] = (object) array('catWord' => 'cat', 'dogWord' => 'dog'); - $arr['fr'] = (object) array('catWord' => 'chat', 'dogWord' => 'chien'); - $arr['es'] = (object) array('catWord' => 'gato'); - $expected = array('en' => 'cat', 'fr' => 'chat', 'es' => 'gato'); + $arr = []; + $arr['en'] = (object) ['catWord' => 'cat', 'dogWord' => 'dog']; + $arr['fr'] = (object) ['catWord' => 'chat', 'dogWord' => 'chien']; + $arr['es'] = (object) ['catWord' => 'gato']; + $expected = ['en' => 'cat', 'fr' => 'chat', 'es' => 'gato']; $this->assertEquals($expected, CRM_Utils_Array::collect('catWord', $arr)); } public function testProduct0() { $actual = CRM_Utils_Array::product( - array(), - array('base data' => 1) + [], + ['base data' => 1] ); - $this->assertEquals(array( - array('base data' => 1), - ), $actual); + $this->assertEquals([ + ['base data' => 1], + ], $actual); } public function testProduct1() { $actual = CRM_Utils_Array::product( - array('dim1' => array('a', 'b')), - array('base data' => 1) + ['dim1' => ['a', 'b']], + ['base data' => 1] ); - $this->assertEquals(array( - array('base data' => 1, 'dim1' => 'a'), - array('base data' => 1, 'dim1' => 'b'), - ), $actual); + $this->assertEquals([ + ['base data' => 1, 'dim1' => 'a'], + ['base data' => 1, 'dim1' => 'b'], + ], $actual); } public function testProduct3() { $actual = CRM_Utils_Array::product( - array('dim1' => array('a', 'b'), 'dim2' => array('alpha', 'beta'), 'dim3' => array('one', 'two')), - array('base data' => 1) + ['dim1' => ['a', 'b'], 'dim2' => ['alpha', 'beta'], 'dim3' => ['one', 'two']], + ['base data' => 1] ); - $this->assertEquals(array( - array('base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'one'), - array('base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'two'), - array('base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'one'), - array('base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'two'), - array('base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'one'), - array('base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'two'), - array('base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'one'), - array('base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'two'), - ), $actual); + $this->assertEquals([ + ['base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'one'], + ['base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'two'], + ['base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'one'], + ['base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'two'], + ['base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'one'], + ['base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'two'], + ['base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'one'], + ['base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'two'], + ], $actual); } public function testIsSubset() { - $this->assertTrue(CRM_Utils_Array::isSubset(array(), array())); - $this->assertTrue(CRM_Utils_Array::isSubset(array('a'), array('a'))); - $this->assertTrue(CRM_Utils_Array::isSubset(array('a'), array('b', 'a', 'c'))); - $this->assertTrue(CRM_Utils_Array::isSubset(array('b', 'd'), array('a', 'b', 'c', 'd'))); - $this->assertFalse(CRM_Utils_Array::isSubset(array('a'), array())); - $this->assertFalse(CRM_Utils_Array::isSubset(array('a'), array('b'))); - $this->assertFalse(CRM_Utils_Array::isSubset(array('a'), array('b', 'c', 'd'))); + $this->assertTrue(CRM_Utils_Array::isSubset([], [])); + $this->assertTrue(CRM_Utils_Array::isSubset(['a'], ['a'])); + $this->assertTrue(CRM_Utils_Array::isSubset(['a'], ['b', 'a', 'c'])); + $this->assertTrue(CRM_Utils_Array::isSubset(['b', 'd'], ['a', 'b', 'c', 'd'])); + $this->assertFalse(CRM_Utils_Array::isSubset(['a'], [])); + $this->assertFalse(CRM_Utils_Array::isSubset(['a'], ['b'])); + $this->assertFalse(CRM_Utils_Array::isSubset(['a'], ['b', 'c', 'd'])); } public function testRemove() { - $data = array( + $data = [ 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5, 'six' => 6, - ); - CRM_Utils_Array::remove($data, 'one', 'two', array('three', 'four'), 'five'); - $this->assertEquals($data, array('six' => 6)); + ]; + CRM_Utils_Array::remove($data, 'one', 'two', ['three', 'four'], 'five'); + $this->assertEquals($data, ['six' => 6]); } public function testGetSetPathParts() { - $arr = array( + $arr = [ 'one' => '1', - 'two' => array( + 'two' => [ 'half' => 2, - ), - ); - $this->assertEquals('1', CRM_Utils_Array::pathGet($arr, array('one'))); - $this->assertEquals('2', CRM_Utils_Array::pathGet($arr, array('two', 'half'))); - $this->assertEquals(NULL, CRM_Utils_Array::pathGet($arr, array('zoo', 'half'))); - CRM_Utils_Array::pathSet($arr, array('zoo', 'half'), '3'); - $this->assertEquals(3, CRM_Utils_Array::pathGet($arr, array('zoo', 'half'))); + ], + ]; + $this->assertEquals('1', CRM_Utils_Array::pathGet($arr, ['one'])); + $this->assertEquals('2', CRM_Utils_Array::pathGet($arr, ['two', 'half'])); + $this->assertEquals(NULL, CRM_Utils_Array::pathGet($arr, ['zoo', 'half'])); + CRM_Utils_Array::pathSet($arr, ['zoo', 'half'], '3'); + $this->assertEquals(3, CRM_Utils_Array::pathGet($arr, ['zoo', 'half'])); $this->assertEquals(3, $arr['zoo']['half']); } public function getSortExamples() { - $red = array('label' => 'Red', 'id' => 1, 'weight' => '90'); - $orange = array('label' => 'Orange', 'id' => 2, 'weight' => '70'); - $yellow = array('label' => 'Yellow', 'id' => 3, 'weight' => '10'); - $green = array('label' => 'Green', 'id' => 4, 'weight' => '70'); - $blue = array('label' => 'Blue', 'id' => 5, 'weight' => '70'); + $red = ['label' => 'Red', 'id' => 1, 'weight' => '90']; + $orange = ['label' => 'Orange', 'id' => 2, 'weight' => '70']; + $yellow = ['label' => 'Yellow', 'id' => 3, 'weight' => '10']; + $green = ['label' => 'Green', 'id' => 4, 'weight' => '70']; + $blue = ['label' => 'Blue', 'id' => 5, 'weight' => '70']; - $examples = array(); - $examples[] = array( - array( + $examples = []; + $examples[] = [ + [ 'r' => $red, 'y' => $yellow, 'g' => $green, 'o' => $orange, 'b' => $blue, - ), + ], 'id', - array( + [ 'r' => $red, 'o' => $orange, 'y' => $yellow, 'g' => $green, 'b' => $blue, - ), - ); - $examples[] = array( - array( + ], + ]; + $examples[] = [ + [ 'r' => $red, 'y' => $yellow, 'g' => $green, 'o' => $orange, 'b' => $blue, - ), + ], 'label', - array( + [ 'b' => $blue, 'g' => $green, 'o' => $orange, 'r' => $red, 'y' => $yellow, - ), - ); - $examples[] = array( - array( + ], + ]; + $examples[] = [ + [ 'r' => $red, 'g' => $green, 'y' => $yellow, 'o' => $orange, 'b' => $blue, - ), - array('weight', 'id'), - array( + ], + ['weight', 'id'], + [ 'y' => $yellow, 'o' => $orange, 'g' => $green, 'b' => $blue, 'r' => $red, - ), - ); + ], + ]; return $examples; } diff --git a/tests/phpunit/CRM/Utils/AutoCleanTest.php b/tests/phpunit/CRM/Utils/AutoCleanTest.php index bcd4935330..a48d0192bb 100644 --- a/tests/phpunit/CRM/Utils/AutoCleanTest.php +++ b/tests/phpunit/CRM/Utils/AutoCleanTest.php @@ -26,7 +26,7 @@ class CRM_Utils_AutoCleanTest extends CiviUnitTestCase { public function nestedWithArrayCb() { $this->foo = 'arraycb'; - $ac = CRM_Utils_AutoClean::with(array($this, 'setFoo'), 'orig'); + $ac = CRM_Utils_AutoClean::with([$this, 'setFoo'], 'orig'); $this->assertEquals('arraycb', $this->foo); } @@ -42,7 +42,7 @@ class CRM_Utils_AutoCleanTest extends CiviUnitTestCase { } public function nestedSwap() { - $ac = CRM_Utils_AutoClean::swap(array($this, 'getFoo'), array($this, 'setFoo'), 'tmp'); + $ac = CRM_Utils_AutoClean::swap([$this, 'getFoo'], [$this, 'setFoo'], 'tmp'); $this->assertEquals('tmp', $this->foo); } diff --git a/tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php b/tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php index 130eaa5334..68d1ac3250 100644 --- a/tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php +++ b/tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php @@ -18,14 +18,14 @@ class CRM_Utils_Cache_SqlGroupTest extends CiviUnitTestCase { * Add and remove two items from the same cache instance. */ public function testSameInstance() { - $a = new CRM_Utils_Cache_SqlGroup(array( + $a = new CRM_Utils_Cache_SqlGroup([ 'group' => 'testSameInstance', - )); + ]); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_cache WHERE group_name = "testSameInstance"'); - $fooValue = array('whiz' => 'bang', 'bar' => 2); + $fooValue = ['whiz' => 'bang', 'bar' => 2]; $a->set('foo', $fooValue); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_cache WHERE group_name = "testSameInstance"'); - $this->assertEquals($a->get('foo'), array('whiz' => 'bang', 'bar' => 2)); + $this->assertEquals($a->get('foo'), ['whiz' => 'bang', 'bar' => 2]); $barValue = 45.78; $a->set('bar', $barValue); @@ -43,20 +43,20 @@ class CRM_Utils_Cache_SqlGroupTest extends CiviUnitTestCase { * Add item to one cache instance then read with another. */ public function testTwoInstance() { - $a = new CRM_Utils_Cache_SqlGroup(array( + $a = new CRM_Utils_Cache_SqlGroup([ 'group' => 'testTwoInstance', - )); - $fooValue = array('whiz' => 'bang', 'bar' => 3); + ]); + $fooValue = ['whiz' => 'bang', 'bar' => 3]; $a->set('foo', $fooValue); $getValue = $a->get('foo'); - $expectValue = array('whiz' => 'bang', 'bar' => 3); + $expectValue = ['whiz' => 'bang', 'bar' => 3]; $this->assertEquals($getValue, $expectValue); - $b = new CRM_Utils_Cache_SqlGroup(array( + $b = new CRM_Utils_Cache_SqlGroup([ 'group' => 'testTwoInstance', 'prefetch' => FALSE, - )); - $this->assertEquals($b->get('foo'), array('whiz' => 'bang', 'bar' => 3)); + ]); + $this->assertEquals($b->get('foo'), ['whiz' => 'bang', 'bar' => 3]); } /** @@ -64,29 +64,29 @@ class CRM_Utils_Cache_SqlGroupTest extends CiviUnitTestCase { */ public function testPrefetch() { // 1. put data in cache - $a = new CRM_Utils_Cache_SqlGroup(array( + $a = new CRM_Utils_Cache_SqlGroup([ 'group' => 'testPrefetch', 'prefetch' => FALSE, - )); - $fooValue = array('whiz' => 'bang', 'bar' => 4); + ]); + $fooValue = ['whiz' => 'bang', 'bar' => 4]; $a->set('foo', $fooValue); - $this->assertEquals($a->get('foo'), array('whiz' => 'bang', 'bar' => 4)); + $this->assertEquals($a->get('foo'), ['whiz' => 'bang', 'bar' => 4]); // 2. see what happens when prefetch is TRUE - $b = new CRM_Utils_Cache_SqlGroup(array( + $b = new CRM_Utils_Cache_SqlGroup([ 'group' => 'testPrefetch', 'prefetch' => TRUE, - )); + ]); // should work b/c value was prefetched $this->assertEquals($fooValue, $b->getFromFrontCache('foo')); // should work b/c value was prefetched $this->assertEquals($fooValue, $b->get('foo')); // 3. see what happens when prefetch is FALSE - $c = new CRM_Utils_Cache_SqlGroup(array( + $c = new CRM_Utils_Cache_SqlGroup([ 'group' => 'testPrefetch', 'prefetch' => FALSE, - )); + ]); // should be NULL b/c value was NOT prefetched $this->assertEquals(NULL, $c->getFromFrontCache('foo')); // should work b/c value is fetched on demand diff --git a/tests/phpunit/CRM/Utils/DateTest.php b/tests/phpunit/CRM/Utils/DateTest.php index c7828ea166..82b8f4efa7 100644 --- a/tests/phpunit/CRM/Utils/DateTest.php +++ b/tests/phpunit/CRM/Utils/DateTest.php @@ -53,20 +53,20 @@ class CRM_Utils_DateTest extends CiviUnitTestCase { } public function fromToData() { - $cases = array(); + $cases = []; // Absolute dates - $cases[] = array('20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017'); + $cases[] = ['20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017']; // "Today" relative date filter $date = new DateTime(); $expectedFrom = $date->format('Ymd') . '000000'; $expectedTo = $date->format('Ymd') . '235959'; - $cases[] = array($expectedFrom, $expectedTo, 'this.day', '', ''); + $cases[] = [$expectedFrom, $expectedTo, 'this.day', '', '']; // "yesterday" relative date filter $date = new DateTime(); $date->sub(new DateInterval('P1D')); $expectedFrom = $date->format('Ymd') . '000000'; $expectedTo = $date->format('Ymd') . '235959'; - $cases[] = array($expectedFrom, $expectedTo, 'previous.day', '', ''); + $cases[] = [$expectedFrom, $expectedTo, 'previous.day', '', '']; return $cases; } diff --git a/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php b/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php index e202473a21..2cb51c4195 100644 --- a/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php +++ b/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php @@ -14,12 +14,12 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { public function tearDown() { // truncate a few tables - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_email', 'civicrm_contribution', 'civicrm_website', - ); + ]; $this->quickCleanup($tablesToTruncate); } @@ -28,7 +28,7 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { * Test civicrm_contact_check_params with no contact type. */ public function testCheckParamsWithNoContactType() { - $params = array('foo' => 'bar'); + $params = ['foo' => 'bar']; $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); $this->assertEquals(1, $contact['is_error']); } @@ -58,7 +58,7 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { * params and no params */ public function testCheckParamsWithNoParams() { - $params = array(); + $params = []; $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); $this->assertEquals(1, $contact['is_error']); } diff --git a/tests/phpunit/CRM/Utils/FileTest.php b/tests/phpunit/CRM/Utils/FileTest.php index 692bbee803..84be8a936d 100644 --- a/tests/phpunit/CRM/Utils/FileTest.php +++ b/tests/phpunit/CRM/Utils/FileTest.php @@ -10,12 +10,12 @@ class CRM_Utils_FileTest extends CiviUnitTestCase { * Test is child path. */ public function testIsChildPath() { - $testCases = array(); - $testCases[] = array('/ab/cd/ef', '/ab/cd', FALSE); - $testCases[] = array('/ab/cd', '/ab/cd/ef', TRUE); - $testCases[] = array('/ab/cde', '/ab/cd/ef', FALSE); - $testCases[] = array('/ab/cde', '/ab/cd', FALSE); - $testCases[] = array('/ab/cd', 'ab/cd/ef', FALSE); + $testCases = []; + $testCases[] = ['/ab/cd/ef', '/ab/cd', FALSE]; + $testCases[] = ['/ab/cd', '/ab/cd/ef', TRUE]; + $testCases[] = ['/ab/cde', '/ab/cd/ef', FALSE]; + $testCases[] = ['/ab/cde', '/ab/cd', FALSE]; + $testCases[] = ['/ab/cd', 'ab/cd/ef', FALSE]; foreach ($testCases as $testCase) { $actual = CRM_Utils_File::isChildPath($testCase[0], $testCase[1], FALSE); $this->assertEquals($testCase[2], $actual, sprintf("parent=[%s] child=[%s] expected=[%s] actual=[%s]", @@ -25,7 +25,7 @@ class CRM_Utils_FileTest extends CiviUnitTestCase { } public function testStripComment() { - $strings = array( + $strings = [ "\nab\n-- cd\nef" => "\nab\nef", "ab\n-- cd\nef" => "ab\nef", "ab\n-- cd\nef\ngh" => "ab\nef\ngh", @@ -38,7 +38,7 @@ class CRM_Utils_FileTest extends CiviUnitTestCase { "ab\r\n--cd\r\nef" => "ab\r\nef", "ab\r\n#cd\r\nef" => "ab\r\nef", "ab\r\nfoo#cd\r\nef" => "ab\r\nfoo#cd\r\nef", - ); + ]; foreach ($strings as $string => $check) { $test = CRM_Utils_File::stripComments($string); $this->assertEquals($test, @@ -53,10 +53,10 @@ class CRM_Utils_FileTest extends CiviUnitTestCase { } public function fileExtensions() { - return array( - array('txt'), - array('danger'), - ); + return [ + ['txt'], + ['danger'], + ]; } /** diff --git a/tests/phpunit/CRM/Utils/GlobalStackTest.php b/tests/phpunit/CRM/Utils/GlobalStackTest.php index 186a67e3ae..7c9c45a86c 100644 --- a/tests/phpunit/CRM/Utils/GlobalStackTest.php +++ b/tests/phpunit/CRM/Utils/GlobalStackTest.php @@ -22,13 +22,13 @@ class CRM_Utils_GlobalStackTest extends CiviUnitTestCase { $this->assertFalse(isset($_FOO['bang'])); $this->assertEquals(1, $_EXTRA); - CRM_Utils_GlobalStack::singleton()->push(array( - '_FOO' => array( + CRM_Utils_GlobalStack::singleton()->push([ + '_FOO' => [ 'bar' => 2, 'bang' => 2, - ), + ], '_EXTRA' => 2, - )); + ]); $this->assertEquals(2, $_FOO['bar']); $this->assertEquals(1, $_FOO['whiz']); diff --git a/tests/phpunit/CRM/Utils/HTMLTest.php b/tests/phpunit/CRM/Utils/HTMLTest.php index f0baa01662..b520cf3ab9 100644 --- a/tests/phpunit/CRM/Utils/HTMLTest.php +++ b/tests/phpunit/CRM/Utils/HTMLTest.php @@ -35,91 +35,91 @@ class CRM_Utils_HTMLTest extends CiviUnitTestCase { * @return array */ public function translateExamples() { - $cases = array(); - $cases[] = array( + $cases = []; + $cases[] = [ '', - array(), - ); + [], + ]; // missing ts - $cases[] = array( + $cases[] = [ '
Hello world
', - array(), - ); + [], + ]; // text, no arg - $cases[] = array( + $cases[] = [ '
{{ts("Hello world")}}
', - array('Hello world'), - ); + ['Hello world'], + ]; // text, no arg, alternate text - $cases[] = array( + $cases[] = [ '
{{ts("Good morning, Dave")}}
', - array('Good morning, Dave'), - ); + ['Good morning, Dave'], + ]; // text, with arg - $cases[] = array( + $cases[] = [ '
{{ts("Hello world", {1: "whiz"})}}
', - array('Hello world'), - ); + ['Hello world'], + ]; // text, not really ts(), no arg - $cases[] = array( + $cases[] = [ '
{{clients("Hello world")}}
', - array(), - ); + [], + ]; // text, not really ts(), with arg - $cases[] = array( + $cases[] = [ '
{{clients("Hello world", {1: "whiz"})}}
', - array(), - ); + [], + ]; // two strings, duplicate - $cases[] = array( + $cases[] = [ '
{{ts("Hello world")}}

{{ts("Hello world")}}

', - array('Hello world'), - ); + ['Hello world'], + ]; // two strings, addition - $cases[] = array( + $cases[] = [ '
{{ts("Hello world") + "-" + ts("How do you do?")}}

', - array('Hello world', 'How do you do?'), - ); + ['Hello world', 'How do you do?'], + ]; // two strings, separate calls - $cases[] = array( + $cases[] = [ '
{{ts("Hello world")}}

{{ts("How do you do?")}}

', - array('Hello world', 'How do you do?'), - ); + ['Hello world', 'How do you do?'], + ]; // single quoted - $cases[] = array( + $cases[] = [ '
{{ts(\'Hello world\')}}
', - array('Hello world'), - ); + ['Hello world'], + ]; // unclear string - $cases[] = array( + $cases[] = [ '
{{ts(message)}}
', - array(), - ); + [], + ]; // ts() within a string - $cases[] = array( + $cases[] = [ '
{{ts("Does the ts(\'example\') notation work?")}}
', - array('Does the ts(\'example\') notation work?'), - ); + ['Does the ts(\'example\') notation work?'], + ]; // attribute, no arg - $cases[] = array( + $cases[] = [ '
', - array('Hello world'), - ); + ['Hello world'], + ]; // attribute, with arg - $cases[] = array( + $cases[] = [ '
', - array('Hello world'), - ); + ['Hello world'], + ]; // attribute, two strings, with arg - $cases[] = array( + $cases[] = [ '
', - array('Hello world', 'How do you do, %1?'), - ); + ['Hello world', 'How do you do, %1?'], + ]; // trick question! Not used on Smarty templates. - $cases[] = array( + $cases[] = [ '
{ts}Hello world{/ts}
', - array(), - ); + [], + ]; return $cases; } diff --git a/tests/phpunit/CRM/Utils/HookTest.php b/tests/phpunit/CRM/Utils/HookTest.php index e3167f2002..6924840b6c 100644 --- a/tests/phpunit/CRM/Utils/HookTest.php +++ b/tests/phpunit/CRM/Utils/HookTest.php @@ -14,16 +14,16 @@ class CRM_Utils_HookTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->fakeModules = array( + $this->fakeModules = [ 'hooktesta', 'hooktestb', 'hooktestc', 'hooktestd', 'hookteste', - ); + ]; // our goal is to test a helper in CRM_Utils_Hook, but we need a concrete class $this->hook = new CRM_Utils_Hook_UnitTests(); - $this->log = array(); + $this->log = []; self::$activeTest = $this; } @@ -39,14 +39,14 @@ class CRM_Utils_HookTest extends CiviUnitTestCase { $arg1 = 'whatever'; $this->hook->runHooks($this->fakeModules, 'civicrm_testRunHooks_outer', 1, $arg1, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject); $this->assertEquals( - array( + [ 'a-outer', 'b-outer-1', 'a-inner', 'b-inner', 'b-outer-2', 'c-outer', - ), + ], $this->log ); } @@ -57,11 +57,11 @@ class CRM_Utils_HookTest extends CiviUnitTestCase { public function testRunHooks_merge() { $result = $this->hook->runHooks($this->fakeModules, 'civicrm_testRunHooks_merge', 0, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject); $this->assertEquals( - array( + [ 'from-module-a1', 'from-module-a2', 'from-module-e', - ), + ], $result ); } @@ -104,7 +104,7 @@ function hooktestb_civicrm_testRunHooks_inner() { * @return array */ function hooktesta_civicrm_testRunHooks_merge() { - return array('from-module-a1', 'from-module-a2'); + return ['from-module-a1', 'from-module-a2']; } // OMIT: function hooktestb_civicrm_testRunHooks_merge @@ -113,7 +113,7 @@ function hooktesta_civicrm_testRunHooks_merge() { * Implements hook_civicrm_testRunHooks_merge(). */ function hooktestc_civicrm_testRunHooks_merge() { - return array(); + return []; } /** @@ -127,5 +127,5 @@ function hooktestd_civicrm_testRunHooks_merge() { * @return array */ function hookteste_civicrm_testRunHooks_merge() { - return array('from-module-e'); + return ['from-module-e']; } diff --git a/tests/phpunit/CRM/Utils/HtmlToTextTest.php b/tests/phpunit/CRM/Utils/HtmlToTextTest.php index 928bc7147d..a4d2193fbf 100644 --- a/tests/phpunit/CRM/Utils/HtmlToTextTest.php +++ b/tests/phpunit/CRM/Utils/HtmlToTextTest.php @@ -15,14 +15,14 @@ class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase { */ public function htmlToTextExamples() { // array(0 => string $html, 1 => string $text) - $cases = array(); + $cases = []; - $cases[] = array( + $cases[] = [ '

', '', - ); + ]; - $cases[] = array( + $cases[] = [ "\n

\n" . "This is a paragraph with Bold and italics\n" . "Also some hrefs and a\n" . @@ -36,16 +36,16 @@ class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase { "------\n" . "[1] http://www.example.com\n" . "", - ); + ]; - $cases[] = array( + $cases[] = [ "

\nA token\nis not treated as a relative URL", "A token [1] is not treated as a relative URL\n" . "\n" . "Links:\n" . "------\n" . "[1] {action.do_something}\n", - ); + ]; return $cases; } diff --git a/tests/phpunit/CRM/Utils/HttpClientTest.php b/tests/phpunit/CRM/Utils/HttpClientTest.php index 4d1b1bf2ca..3dea0047dc 100644 --- a/tests/phpunit/CRM/Utils/HttpClientTest.php +++ b/tests/phpunit/CRM/Utils/HttpClientTest.php @@ -28,10 +28,10 @@ class CRM_Utils_HttpClientTest extends CiviUnitTestCase { $this->tmpFile = $this->createTempDir() . '/example.txt'; - $result = civicrm_api('Setting', 'create', array( + $result = civicrm_api('Setting', 'create', [ 'version' => 3, 'verifySSL' => TRUE, - )); + ]); $this->assertAPISuccess($result); $this->client = new CRM_Utils_HttpClient(); } @@ -61,10 +61,10 @@ class CRM_Utils_HttpClientTest extends CiviUnitTestCase { } public function testFetchHttps_invalid_noVerify() { - $result = civicrm_api('Setting', 'create', array( + $result = civicrm_api('Setting', 'create', [ 'version' => 3, 'verifySSL' => FALSE, - )); + ]); $this->assertAPISuccess($result); $result = $this->client->fetch(self::SELF_SIGNED_HTTPS_URL, $this->tmpFile); @@ -96,10 +96,10 @@ class CRM_Utils_HttpClientTest extends CiviUnitTestCase { } public function testGetHttps_invalid_noVerify() { - $result = civicrm_api('Setting', 'create', array( + $result = civicrm_api('Setting', 'create', [ 'version' => 3, 'verifySSL' => FALSE, - )); + ]); $this->assertAPISuccess($result); list($status, $data) = $this->client->get(self::SELF_SIGNED_HTTPS_URL); diff --git a/tests/phpunit/CRM/Utils/ICalendarTest.php b/tests/phpunit/CRM/Utils/ICalendarTest.php index 1ed549e67b..052eb674ac 100644 --- a/tests/phpunit/CRM/Utils/ICalendarTest.php +++ b/tests/phpunit/CRM/Utils/ICalendarTest.php @@ -35,14 +35,14 @@ class CRM_Utils_ICalendarTest extends CiviUnitTestCase { * @return array */ public function escapeExamples() { - $cases = array(); - $cases[] = array("Hello + $cases = []; + $cases[] = ["Hello this is, a test!", - ); - $cases[] = array("Hello!! + ]; + $cases[] = ["Hello!! this is, a \"test\"!", - ); + ]; return $cases; } diff --git a/tests/phpunit/CRM/Utils/JSTest.php b/tests/phpunit/CRM/Utils/JSTest.php index 4f1e97d830..98a119fd74 100644 --- a/tests/phpunit/CRM/Utils/JSTest.php +++ b/tests/phpunit/CRM/Utils/JSTest.php @@ -35,38 +35,38 @@ class CRM_Utils_JSTest extends CiviUnitTestCase { * @return array */ public function translateExamples() { - $cases = array(); - $cases[] = array( + $cases = []; + $cases[] = [ '', - array(), - ); + [], + ]; // missing ts - $cases[] = array( + $cases[] = [ 'alert("Hello world")', - array(), - ); + [], + ]; // basic function call - $cases[] = array( + $cases[] = [ 'alert(ts("Hello world"));', - array('Hello world'), - ); + ['Hello world'], + ]; // with arg - $cases[] = array( + $cases[] = [ 'alert(ts("Hello world", {1: "whiz"}));', - array('Hello world'), - ); + ['Hello world'], + ]; // not really ts() - $cases[] = array( + $cases[] = [ 'alert(clients("Hello world"));', - array(), - ); + [], + ]; // not really ts() - $cases[] = array( + $cases[] = [ 'alert(clients("Hello world", {1: "whiz"}));', - array(), - ); + [], + ]; // with arg - $cases[] = array( + $cases[] = [ "\n" . "public function whits() {\n" . " for (a in b) {\n" . @@ -75,37 +75,37 @@ class CRM_Utils_JSTest extends CiviUnitTestCase { " });\n" . " }\n" . "}\n", - array('Hello'), - ); + ['Hello'], + ]; // duplicate - $cases[] = array( + $cases[] = [ 'alert(ts("Hello world") + "-" + ts("Hello world"));', - array('Hello world'), - ); + ['Hello world'], + ]; // two strings, addition - $cases[] = array( + $cases[] = [ 'alert(ts("Hello world") + "-" + ts("How do you do?"));', - array('Hello world', 'How do you do?'), - ); + ['Hello world', 'How do you do?'], + ]; // two strings, separate calls - $cases[] = array( + $cases[] = [ 'alert(ts("Hello world");\nalert(ts("How do you do?"));', - array('Hello world', 'How do you do?'), - ); - $cases[] = array( + ['Hello world', 'How do you do?'], + ]; + $cases[] = [ 'alert(ts(\'Single quoted\'));', - array('Single quoted'), - ); + ['Single quoted'], + ]; // unclear string - $cases[] = array( + $cases[] = [ 'alert(ts(message));', - array(), - ); + [], + ]; // ts() within a string - $cases[] = array( + $cases[] = [ 'alert(ts("Does the ts(\'example\') notation work?"));', - array('Does the ts(\'example\') notation work?'), - ); + ['Does the ts(\'example\') notation work?'], + ]; return $cases; } @@ -136,18 +136,18 @@ class CRM_Utils_JSTest extends CiviUnitTestCase { $abc = "(function (angular, $, _) {\na();\n\nb();\n\nc();\n})(angular,CRM.$, CRM._);"; $cb = "(function( angular, $,_) {\nc();\n\nb();\n})(angular,CRM.$,CRM._);"; - $cases = array(); - $cases[] = array(array($a), "$a"); - $cases[] = array(array($b), "$b"); - $cases[] = array(array($c), "$c"); - $cases[] = array(array($d), "$d"); - $cases[] = array(array($m), "$m"); - $cases[] = array(array($a, $b), "$ab"); - $cases[] = array(array($a, $m, $b), "$a$m$b"); - $cases[] = array(array($a, $d), "$a$d"); - $cases[] = array(array($a, $d, $b), "$a$d$b"); - $cases[] = array(array($a, $b, $c), "$abc"); - $cases[] = array(array($a, $b, $d, $c, $b), "$ab$d$cb"); + $cases = []; + $cases[] = [[$a], "$a"]; + $cases[] = [[$b], "$b"]; + $cases[] = [[$c], "$c"]; + $cases[] = [[$d], "$d"]; + $cases[] = [[$m], "$m"]; + $cases[] = [[$a, $b], "$ab"]; + $cases[] = [[$a, $m, $b], "$a$m$b"]; + $cases[] = [[$a, $d], "$a$d"]; + $cases[] = [[$a, $d, $b], "$a$d$b"]; + $cases[] = [[$a, $b, $c], "$abc"]; + $cases[] = [[$a, $b, $d, $c, $b], "$ab$d$cb"]; return $cases; } @@ -159,34 +159,34 @@ class CRM_Utils_JSTest extends CiviUnitTestCase { public function testDedupeClosure($scripts, $expectedOutput) { $actualOutput = CRM_Utils_JS::dedupeClosures( $scripts, - array('angular', '$', '_'), - array('angular', 'CRM.$', 'CRM._') + ['angular', '$', '_'], + ['angular', 'CRM.$', 'CRM._'] ); $this->assertEquals($expectedOutput, implode("", $actualOutput)); } public function stripCommentsExamples() { - $cases = array(); - $cases[] = array( + $cases = []; + $cases[] = [ "a();\n//# sourceMappingURL=../foo/bar/baz.js\nb();", "a();\n\nb();", - ); - $cases[] = array( + ]; + $cases[] = [ "// foo\na();", "\na();", - ); - $cases[] = array( + ]; + $cases[] = [ "b();\n // foo", "b();\n", - ); - $cases[] = array( + ]; + $cases[] = [ "/// foo\na();\n\t \t//bar\nb();\n// whiz", "\na();\n\nb();\n", - ); - $cases[] = array( + ]; + $cases[] = [ "alert('//# sourceMappingURL=../foo/bar/baz.js');\n//zoop\na();", "alert('//# sourceMappingURL=../foo/bar/baz.js');\n\na();", - ); + ]; return $cases; } diff --git a/tests/phpunit/CRM/Utils/Mail/EmailProcessorTest.php b/tests/phpunit/CRM/Utils/Mail/EmailProcessorTest.php index 8abebc844a..89354b9783 100644 --- a/tests/phpunit/CRM/Utils/Mail/EmailProcessorTest.php +++ b/tests/phpunit/CRM/Utils/Mail/EmailProcessorTest.php @@ -11,7 +11,7 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { * * @var array */ - protected $eventQueue = array(); + protected $eventQueue = []; /** * ID of our sample contact. @@ -24,20 +24,20 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { parent::setUp(); CRM_Utils_File::cleanDir(__DIR__ . '/data/mail'); mkdir(__DIR__ . '/data/mail'); - $this->callAPISuccess('MailSettings', 'get', array( - 'api.MailSettings.create' => array( + $this->callAPISuccess('MailSettings', 'get', [ + 'api.MailSettings.create' => [ 'name' => 'local', 'protocol' => 'Localdir', 'source' => __DIR__ . '/data/mail', 'domain' => 'example.com', - ), - )); + ], + ]); } public function tearDown() { CRM_Utils_File::cleanDir(__DIR__ . '/data/mail'); parent::tearDown(); - $this->quickCleanup(array('civicrm_group', 'civicrm_group_contact', 'civicrm_mailing', 'civicrm_mailing_job', 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_queue', 'civicrm_mailing_group', 'civicrm_mailing_recipients', 'civicrm_contact', 'civicrm_email')); + $this->quickCleanup(['civicrm_group', 'civicrm_group_contact', 'civicrm_mailing', 'civicrm_mailing_job', 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_queue', 'civicrm_mailing_group', 'civicrm_mailing_recipients', 'civicrm_contact', 'civicrm_email']); } /** @@ -48,7 +48,7 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { copy(__DIR__ . '/data/bounces/bounce_no_verp.txt', __DIR__ . '/data/mail/bounce_no_verp.txt'); $this->assertTrue(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt')); - $this->callAPISuccess('job', 'fetch_bounces', array()); + $this->callAPISuccess('job', 'fetch_bounces', []); $this->assertFalse(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt')); $this->checkMailingBounces(1); } @@ -61,7 +61,7 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { $mail = 'test_invalid_character.eml'; copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail); - $this->callAPISuccess('job', 'fetch_bounces', array()); + $this->callAPISuccess('job', 'fetch_bounces', []); $this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail)); $this->checkMailingBounces(1); } @@ -74,7 +74,7 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { $mail = 'test_utf8mb4_character.txt'; copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail); - $this->callAPISuccess('job', 'fetch_bounces', array()); + $this->callAPISuccess('job', 'fetch_bounces', []); $this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail)); $this->checkMailingBounces(1); } @@ -89,7 +89,7 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { $mail = 'test_sample_message.eml'; copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail); - $this->callAPISuccess('job', 'fetch_bounces', array()); + $this->callAPISuccess('job', 'fetch_bounces', []); $this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail)); $this->checkMailingBounces(1); } @@ -104,7 +104,7 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { $mail = 'test_nested_message.eml'; copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail); - $this->callAPISuccess('job', 'fetch_bounces', array()); + $this->callAPISuccess('job', 'fetch_bounces', []); $this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail)); $this->checkMailingBounces(1); } @@ -126,14 +126,14 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { */ public function testBounceProcessingDeletedEmail() { $this->setUpMailing(); - $this->callAPISuccess('Email', 'get', array( + $this->callAPISuccess('Email', 'get', [ 'contact_id' => $this->contactID, 'api.email.delete' => 1, - )); + ]); copy(__DIR__ . '/data/bounces/bounce_no_verp.txt', __DIR__ . '/data/mail/bounce_no_verp.txt'); $this->assertTrue(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt')); - $this->callAPISuccess('job', 'fetch_bounces', array()); + $this->callAPISuccess('job', 'fetch_bounces', []); $this->assertFalse(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt')); $this->checkMailingBounces(1); } @@ -157,16 +157,16 @@ class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase { * Set up a mailing. */ public function setUpMailing() { - $this->contactID = $this->individualCreate(array('email' => 'undeliverable@example.com')); - $groupID = $this->callAPISuccess('Group', 'create', array( + $this->contactID = $this->individualCreate(['email' => 'undeliverable@example.com']); + $groupID = $this->callAPISuccess('Group', 'create', [ 'title' => 'Mailing group', - 'api.GroupContact.create' => array( + 'api.GroupContact.create' => [ 'contact_id' => $this->contactID, - ), - )); - $this->createMailing(array('scheduled_date' => 'now', 'groups' => array('include' => array($groupID)))); - $this->callAPISuccess('job', 'process_mailing', array()); - $this->eventQueue = $this->callAPISuccess('MailingEventQueue', 'get', array('api.MailingEventQueue.create' => array('hash' => 'aaaaaaaaaaaaaaaa'))); + ], + ]); + $this->createMailing(['scheduled_date' => 'now', 'groups' => ['include' => [$groupID]]]); + $this->callAPISuccess('job', 'process_mailing', []); + $this->eventQueue = $this->callAPISuccess('MailingEventQueue', 'get', ['api.MailingEventQueue.create' => ['hash' => 'aaaaaaaaaaaaaaaa']]); } } diff --git a/tests/phpunit/CRM/Utils/MailTest.php b/tests/phpunit/CRM/Utils/MailTest.php index e9f77b6c53..f87b9f8392 100644 --- a/tests/phpunit/CRM/Utils/MailTest.php +++ b/tests/phpunit/CRM/Utils/MailTest.php @@ -16,40 +16,40 @@ class CRM_Utils_MailTest extends CiviUnitTestCase { */ public function testFormatRFC822() { - $values = array( - array( + $values = [ + [ 'name' => "Test User", 'email' => "foo@bar.com", 'result' => "Test User ", - ), - array( + ], + [ 'name' => '"Test User"', 'email' => "foo@bar.com", 'result' => "Test User ", - ), - array( + ], + [ 'name' => "User, Test", 'email' => "foo@bar.com", 'result' => '"User, Test" ', - ), - array( + ], + [ 'name' => '"User, Test"', 'email' => "foo@bar.com", 'result' => '"User, Test" ', - ), - array( + ], + [ 'name' => '"Test User"', 'email' => "foo@bar.com", 'result' => '"Test User" ', 'useQuote' => TRUE, - ), - array( + ], + [ 'name' => "User, Test", 'email' => "foo@bar.com", 'result' => '"User, Test" ', 'useQuote' => TRUE, - ), - ); + ], + ]; foreach ($values as $value) { $result = CRM_Utils_Mail::formatRFC822Email($value['name'], $value['email'], diff --git a/tests/phpunit/CRM/Utils/Migrate/ImportExportTest.php b/tests/phpunit/CRM/Utils/Migrate/ImportExportTest.php index 082a7409ed..423aa36525 100644 --- a/tests/phpunit/CRM/Utils/Migrate/ImportExportTest.php +++ b/tests/phpunit/CRM/Utils/Migrate/ImportExportTest.php @@ -13,10 +13,10 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { } public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_custom_group', 'civicrm_custom_field', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); } @@ -29,8 +29,8 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { */ public function basicXmlTestCases() { // a small library which we use to describe test cases - $fixtures = array(); - $fixtures['textField'] = array( + $fixtures = []; + $fixtures['textField'] = [ 'name' => 'test_textfield', 'label' => 'Name1', 'html_type' => 'Text', @@ -40,8 +40,8 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1, - ); - $fixtures['selectField'] = array( + ]; + $fixtures['selectField'] = [ // custom_group_id 'label' => 'Our select field', 'html_type' => 'Select', @@ -51,36 +51,36 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { 'is_searchable' => 0, 'is_active' => 1, // 'option_group_name' => 'our_select_field_20130818044104', - 'option_values' => array( - array( + 'option_values' => [ + [ 'weight' => 1, 'label' => 'Label1', 'value' => 1, 'is_active' => 1, - ), - array( + ], + [ 'weight' => 2, 'label' => 'Label2', 'value' => 2, 'is_active' => 1, - ), - ), - ); + ], + ], + ]; // the actual test cases - $cases = array(); + $cases = []; - $cases[] = array( + $cases[] = [ // CustomGroup params - array( + [ 'extends' => 'Contact', 'title' => 'example', - ), + ], // CustomField params $fixtures['textField'], // expectedXmlFilePath __DIR__ . '/fixtures/Contact-text.xml', - ); + ]; /* @codingStandardsIgnoreStart $cases[] = array( @@ -96,55 +96,55 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { ); @codingStandardsIgnoreEnd */ - $cases[] = array( + $cases[] = [ // CustomGroup params - array( + [ 'extends' => 'Individual', 'title' => 'example', - ), + ], // CustomField params $fixtures['textField'], // expectedXmlFilePath __DIR__ . '/fixtures/Individual-text.xml', - ); + ]; - $cases[] = array( + $cases[] = [ // CustomGroup params - array( + [ 'extends' => 'Individual', - 'extends_entity_column_value' => array('Student'), + 'extends_entity_column_value' => ['Student'], 'title' => 'example', - ), + ], // CustomField params $fixtures['textField'], // expectedXmlFilePath __DIR__ . '/fixtures/IndividualStudent-text.xml', - ); + ]; - $cases[] = array( + $cases[] = [ // CustomGroup params - array( + [ 'extends' => 'Activity', 'title' => 'example', - ), + ], // CustomField params $fixtures['textField'], // expectedXmlFilePath __DIR__ . '/fixtures/Activity-text.xml', - ); + ]; - $cases[] = array( + $cases[] = [ // CustomGroup params - array( + [ 'extends' => 'Activity', 'extends_entity_column_value' => [1], 'title' => 'example', - ), + ], // CustomField params $fixtures['textField'], // expectedXmlFilePath __DIR__ . '/fixtures/ActivityMeeting-text.xml', - ); + ]; return $cases; } @@ -159,20 +159,20 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { * @dataProvider basicXmlTestCases */ public function testBasicXMLExports($customGroupParams, $fieldParams, $expectedXmlFilePath) { - $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array( - 1 => array($customGroupParams['title'], 'String'), - )); + $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', [ + 1 => [$customGroupParams['title'], 'String'], + ]); $customGroup = $this->customGroupCreate($customGroupParams); $fieldParams['custom_group_id'] = $customGroup['id']; $customField = $this->callAPISuccess('custom_field', 'create', $fieldParams); $exporter = new CRM_Utils_Migrate_Export(); - $exporter->buildCustomGroups(array($customGroup['id'])); + $exporter->buildCustomGroups([$customGroup['id']]); // print $exporter->toXML(); $this->assertEquals(file_get_contents($expectedXmlFilePath), $exporter->toXML()); - $this->callAPISuccess('custom_field', 'delete', array('id' => $customField['id'])); - $this->callAPISuccess('custom_group', 'delete', array('id' => $customGroup['id'])); + $this->callAPISuccess('custom_field', 'delete', ['id' => $customField['id']]); + $this->callAPISuccess('custom_group', 'delete', ['id' => $customGroup['id']]); } /** @@ -184,21 +184,21 @@ class CRM_Utils_Migrate_ImportExportTest extends CiviUnitTestCase { * @dataProvider basicXmlTestCases */ public function testBasicXMLImports($expectCustomGroup, $expectCustomField, $inputXmlFilePath) { - $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array( - 1 => array($expectCustomGroup['title'], 'String'), - )); + $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', [ + 1 => [$expectCustomGroup['title'], 'String'], + ]); $importer = new CRM_Utils_Migrate_Import(); $importer->run($inputXmlFilePath); - $customGroups = $this->callAPISuccess('custom_group', 'get', array('title' => $expectCustomGroup['title'])); + $customGroups = $this->callAPISuccess('custom_group', 'get', ['title' => $expectCustomGroup['title']]); $this->assertEquals(1, $customGroups['count']); $customGroup = array_shift($customGroups['values']); foreach ($expectCustomGroup as $expectKey => $expectValue) { $this->assertEquals($expectValue, $customGroup[$expectKey]); } - $customFields = $this->callAPISuccess('custom_field', 'get', array('label' => $expectCustomField['label'])); + $customFields = $this->callAPISuccess('custom_field', 'get', ['label' => $expectCustomField['label']]); $this->assertEquals(1, $customFields['count']); $customField = array_shift($customFields['values']); foreach ($expectCustomField as $expectKey => $expectValue) { diff --git a/tests/phpunit/CRM/Utils/MoneyTest.php b/tests/phpunit/CRM/Utils/MoneyTest.php index 6d3044cd4a..41c5e7c985 100644 --- a/tests/phpunit/CRM/Utils/MoneyTest.php +++ b/tests/phpunit/CRM/Utils/MoneyTest.php @@ -36,14 +36,14 @@ class CRM_Utils_MoneyTest extends CiviUnitTestCase { * @return array */ public function subtractCurrenciesDataProvider() { - return array( - array(number_format(300.00, 2), number_format(299.99, 2), 'USD', number_format(0.01, 2)), - array(2, 1, 'USD', 1), - array(0, 0, 'USD', 0), - array(1, 2, 'USD', -1), - array(number_format(19.99, 2), number_format(20.00, 2), 'USD', number_format(-0.01, 2)), - array('notanumber', 5.00, 'USD', NULL), - ); + return [ + [number_format(300.00, 2), number_format(299.99, 2), 'USD', number_format(0.01, 2)], + [2, 1, 'USD', 1], + [0, 0, 'USD', 0], + [1, 2, 'USD', -1], + [number_format(19.99, 2), number_format(20.00, 2), 'USD', number_format(-0.01, 2)], + ['notanumber', 5.00, 'USD', NULL], + ]; } /** diff --git a/tests/phpunit/CRM/Utils/NumberTest.php b/tests/phpunit/CRM/Utils/NumberTest.php index 9804bce4ef..ea7af8ddab 100644 --- a/tests/phpunit/CRM/Utils/NumberTest.php +++ b/tests/phpunit/CRM/Utils/NumberTest.php @@ -10,11 +10,11 @@ class CRM_Utils_NumberTest extends CiviUnitTestCase { * @return array */ public function randomDecimalCases() { - $cases = array(); + $cases = []; // array(array $precision, int $expectedMinInclusive, int $expectedMaxExclusive) - $cases[] = array(array(1, 0), 0, 10); - $cases[] = array(array(5, 2), 0, 1000); - $cases[] = array(array(10, 8), 0, 100); + $cases[] = [[1, 0], 0, 10]; + $cases[] = [[5, 2], 0, 1000]; + $cases[] = [[10, 8], 0, 100]; return $cases; } @@ -43,14 +43,14 @@ class CRM_Utils_NumberTest extends CiviUnitTestCase { * @return array */ public function truncDecimalCases() { - $cases = array(); + $cases = []; // array($value, $precision, $expectedValue) - $cases[] = array(523, array(1, 0), 5); - $cases[] = array(523, array(5, 2), 523); - $cases[] = array(523, array(10, 8), 52.3); - $cases[] = array(12345, array(3, 3), 0.123); - $cases[] = array(0.12345, array(10, 0), 12345); - $cases[] = array(-123.45, array(4, 2), -12.34); + $cases[] = [523, [1, 0], 5]; + $cases[] = [523, [5, 2], 523]; + $cases[] = [523, [10, 8], 52.3]; + $cases[] = [12345, [3, 3], 0.123]; + $cases[] = [0.12345, [10, 0], 12345]; + $cases[] = [-123.45, [4, 2], -12.34]; return $cases; } diff --git a/tests/phpunit/CRM/Utils/QueryFormatterTest.php b/tests/phpunit/CRM/Utils/QueryFormatterTest.php index 68072e3cab..de557c933e 100644 --- a/tests/phpunit/CRM/Utils/QueryFormatterTest.php +++ b/tests/phpunit/CRM/Utils/QueryFormatterTest.php @@ -17,29 +17,29 @@ class CRM_Utils_QueryFormatterTest extends CiviUnitTestCase { PRIMARY KEY (id) ) '); - $idx = new CRM_Core_InnoDBIndexer(self::supportsFts(), array( - 'civicrm_contact' => array( - array('first_name', 'last_name'), - ), - )); + $idx = new CRM_Core_InnoDBIndexer(self::supportsFts(), [ + 'civicrm_contact' => [ + ['first_name', 'last_name'], + ], + ]); $idx->fixSchemaDifferences(); - $rows = array( - array(1, 'someone@example.com'), - array(2, 'this is someone@example.com!'), - array(3, 'first second'), - array(4, 'zeroth first second'), - array(5, 'zeroth first second third'), - array(6, 'never say never'), - array(7, 'first someone@example.com second'), - array(8, 'first someone'), - array(9, 'firstly someone'), - ); + $rows = [ + [1, 'someone@example.com'], + [2, 'this is someone@example.com!'], + [3, 'first second'], + [4, 'zeroth first second'], + [5, 'zeroth first second third'], + [6, 'never say never'], + [7, 'first someone@example.com second'], + [8, 'first someone'], + [9, 'firstly someone'], + ]; foreach ($rows as $row) { CRM_Core_DAO::executeQuery("INSERT INTO civicrm_fts_example (id,name) VALUES (%1, %2)", - array( - 1 => array($row[0], 'Int'), - 2 => array($row[1], 'String'), - )); + [ + 1 => [$row[0], 'Int'], + 2 => [$row[1], 'String'], + ]); } } @@ -58,70 +58,70 @@ class CRM_Utils_QueryFormatterTest extends CiviUnitTestCase { */ public function dataProvider() { // Array(0=>$inputText, 1=>$language, 2=>$options, 3=>$expectedText, 4=>$matchingIds). - $cases = array(); - - $allEmailRows = array(1, 2, 7); - - $cases[] = array('someone@example.com', 'like', 'simple', '%someone@example.com%', $allEmailRows); - $cases[] = array('someone@example.com', 'like', 'phrase', '%someone@example.com%', $allEmailRows); - $cases[] = array('someone@example.com', 'like', 'wildphrase', '%someone@example.com%', $allEmailRows); - $cases[] = array('someone@example.com', 'like', 'wildwords', '%someone@example.com%', $allEmailRows); - $cases[] = array('someone@example.com', 'like', 'wildwords-suffix', '%someone@example.com%', $allEmailRows); - - $cases[] = array('someone@example.com', 'fts', 'simple', 'someone@example.com', $allEmailRows); - $cases[] = array('someone@example.com', 'fts', 'phrase', '"someone@example.com"', $allEmailRows); - $cases[] = array('someone@example.com', 'fts', 'wildphrase', '"*someone@example.com*"', $allEmailRows); - $cases[] = array('someone@example.com', 'fts', 'wildwords', '*someone* *example*', $allEmailRows); - $cases[] = array('someone@example.com', 'fts', 'wildwords-suffix', 'someone* example*', $allEmailRows); - - $cases[] = array('someone@example.com', 'ftsbool', 'simple', '+"someone" +"example"', $allEmailRows); - $cases[] = array('someone@example.com', 'ftsbool', 'phrase', '+"someone@example.com"', $allEmailRows); - $cases[] = array('someone@example.com', 'ftsbool', 'wildphrase', '+"*someone@example.com*"', $allEmailRows); - $cases[] = array('someone@example.com', 'ftsbool', 'wildwords', '+*someone* +*example*', $allEmailRows); - $cases[] = array('someone@example.com', 'ftsbool', 'wildwords-suffix', '+someone* +example*', $allEmailRows); - - $cases[] = array('first second', 'like', 'simple', '%first second%', array(3, 4, 5)); - $cases[] = array('first second', 'like', 'phrase', '%first second%', array(3, 4, 5)); - $cases[] = array('first second', 'like', 'wildphrase', '%first second%', array(3, 4, 5)); - $cases[] = array('first second', 'like', 'wildwords', '%first%second%', array(3, 4, 5, 7)); - $cases[] = array('first second', 'like', 'wildwords-suffix', '%first%second%', array(3, 4, 5, 7)); - - $cases[] = array('first second', 'fts', 'simple', 'first second', array(3, 4, 5)); - $cases[] = array('first second', 'fts', 'phrase', '"first second"', array(3, 4, 5)); - $cases[] = array('first second', 'fts', 'wildphrase', '"*first second*"', array(3, 4, 5)); - $cases[] = array('first second', 'fts', 'wildwords', '*first* *second*', array(3, 4, 5, 7)); - $cases[] = array('first second', 'fts', 'wildwords-suffix', 'first* second*', array(3, 4, 5, 7)); - - $cases[] = array('first second', 'ftsbool', 'simple', '+"first" +"second"', array(3, 4, 5)); - $cases[] = array('first second', 'ftsbool', 'phrase', '+"first second"', array(3, 4, 5)); - $cases[] = array('first second', 'ftsbool', 'wildphrase', '+"*first second*"', array(3, 4, 5)); - $cases[] = array('first second', 'ftsbool', 'wildwords', '+*first* +*second*', array(3, 4, 5, 7)); - $cases[] = array('first second', 'ftsbool', 'wildwords-suffix', '+first* +second*', array(3, 4, 5, 7)); - - $cases[] = array('first second', 'solr', 'simple', 'first second', NULL); - $cases[] = array('first second', 'solr', 'phrase', '"first second"', NULL); - $cases[] = array('first second', 'solr', 'wildphrase', '"*first second*"', NULL); - $cases[] = array('first second', 'solr', 'wildwords', '*first* *second*', NULL); - $cases[] = array('first second', 'solr', 'wildwords-suffix', 'first* second*', NULL); - - $cases[] = array('someone@', 'ftsbool', 'simple', '+"someone"', $allEmailRows); - $cases[] = array('@example.com', 'ftsbool', 'simple', '+"example.com"', $allEmailRows); + $cases = []; + + $allEmailRows = [1, 2, 7]; + + $cases[] = ['someone@example.com', 'like', 'simple', '%someone@example.com%', $allEmailRows]; + $cases[] = ['someone@example.com', 'like', 'phrase', '%someone@example.com%', $allEmailRows]; + $cases[] = ['someone@example.com', 'like', 'wildphrase', '%someone@example.com%', $allEmailRows]; + $cases[] = ['someone@example.com', 'like', 'wildwords', '%someone@example.com%', $allEmailRows]; + $cases[] = ['someone@example.com', 'like', 'wildwords-suffix', '%someone@example.com%', $allEmailRows]; + + $cases[] = ['someone@example.com', 'fts', 'simple', 'someone@example.com', $allEmailRows]; + $cases[] = ['someone@example.com', 'fts', 'phrase', '"someone@example.com"', $allEmailRows]; + $cases[] = ['someone@example.com', 'fts', 'wildphrase', '"*someone@example.com*"', $allEmailRows]; + $cases[] = ['someone@example.com', 'fts', 'wildwords', '*someone* *example*', $allEmailRows]; + $cases[] = ['someone@example.com', 'fts', 'wildwords-suffix', 'someone* example*', $allEmailRows]; + + $cases[] = ['someone@example.com', 'ftsbool', 'simple', '+"someone" +"example"', $allEmailRows]; + $cases[] = ['someone@example.com', 'ftsbool', 'phrase', '+"someone@example.com"', $allEmailRows]; + $cases[] = ['someone@example.com', 'ftsbool', 'wildphrase', '+"*someone@example.com*"', $allEmailRows]; + $cases[] = ['someone@example.com', 'ftsbool', 'wildwords', '+*someone* +*example*', $allEmailRows]; + $cases[] = ['someone@example.com', 'ftsbool', 'wildwords-suffix', '+someone* +example*', $allEmailRows]; + + $cases[] = ['first second', 'like', 'simple', '%first second%', [3, 4, 5]]; + $cases[] = ['first second', 'like', 'phrase', '%first second%', [3, 4, 5]]; + $cases[] = ['first second', 'like', 'wildphrase', '%first second%', [3, 4, 5]]; + $cases[] = ['first second', 'like', 'wildwords', '%first%second%', [3, 4, 5, 7]]; + $cases[] = ['first second', 'like', 'wildwords-suffix', '%first%second%', [3, 4, 5, 7]]; + + $cases[] = ['first second', 'fts', 'simple', 'first second', [3, 4, 5]]; + $cases[] = ['first second', 'fts', 'phrase', '"first second"', [3, 4, 5]]; + $cases[] = ['first second', 'fts', 'wildphrase', '"*first second*"', [3, 4, 5]]; + $cases[] = ['first second', 'fts', 'wildwords', '*first* *second*', [3, 4, 5, 7]]; + $cases[] = ['first second', 'fts', 'wildwords-suffix', 'first* second*', [3, 4, 5, 7]]; + + $cases[] = ['first second', 'ftsbool', 'simple', '+"first" +"second"', [3, 4, 5]]; + $cases[] = ['first second', 'ftsbool', 'phrase', '+"first second"', [3, 4, 5]]; + $cases[] = ['first second', 'ftsbool', 'wildphrase', '+"*first second*"', [3, 4, 5]]; + $cases[] = ['first second', 'ftsbool', 'wildwords', '+*first* +*second*', [3, 4, 5, 7]]; + $cases[] = ['first second', 'ftsbool', 'wildwords-suffix', '+first* +second*', [3, 4, 5, 7]]; + + $cases[] = ['first second', 'solr', 'simple', 'first second', NULL]; + $cases[] = ['first second', 'solr', 'phrase', '"first second"', NULL]; + $cases[] = ['first second', 'solr', 'wildphrase', '"*first second*"', NULL]; + $cases[] = ['first second', 'solr', 'wildwords', '*first* *second*', NULL]; + $cases[] = ['first second', 'solr', 'wildwords-suffix', 'first* second*', NULL]; + + $cases[] = ['someone@', 'ftsbool', 'simple', '+"someone"', $allEmailRows]; + $cases[] = ['@example.com', 'ftsbool', 'simple', '+"example.com"', $allEmailRows]; // If user supplies wildcards, then ignore mode. - foreach (array( + foreach ([ 'simple', 'wildphrase', 'wildwords', 'wildwords-suffix', - ) as $mode) { - $cases[] = array('first% second', 'like', $mode, 'first% second', array(3, 7)); - $cases[] = array('first% second', 'fts', $mode, 'first* second', array(3, 7)); - $cases[] = array('first% second', 'ftsbool', $mode, '+first* +second', array(3, 7)); - $cases[] = array('first% second', 'solr', $mode, 'first* second', NULL); - $cases[] = array('first second%', 'like', $mode, 'first second%', array(3)); - $cases[] = array('first second%', 'fts', $mode, 'first second*', array(3)); - $cases[] = array('first second%', 'ftsbool', $mode, '+first +second*', array(3)); - $cases[] = array('first second%', 'solr', $mode, 'first second*', NULL); + ] as $mode) { + $cases[] = ['first% second', 'like', $mode, 'first% second', [3, 7]]; + $cases[] = ['first% second', 'fts', $mode, 'first* second', [3, 7]]; + $cases[] = ['first% second', 'ftsbool', $mode, '+first* +second', [3, 7]]; + $cases[] = ['first% second', 'solr', $mode, 'first* second', NULL]; + $cases[] = ['first second%', 'like', $mode, 'first second%', [3]]; + $cases[] = ['first second%', 'fts', $mode, 'first second*', [3]]; + $cases[] = ['first second%', 'ftsbool', $mode, '+first +second*', [3]]; + $cases[] = ['first second%', 'solr', $mode, 'first second*', NULL]; } return $cases; @@ -148,7 +148,7 @@ class CRM_Utils_QueryFormatterTest extends CiviUnitTestCase { $this->createExampleTable(); $this->assertSqlIds($expectedRowIds, "SELECT id FROM civicrm_fts_example WHERE " . $formatter->formatSql('civicrm_fts_example', 'name', $text)); } - elseif (in_array($language, array('fts', 'ftsbool'))) { + elseif (in_array($language, ['fts', 'ftsbool'])) { if ($this->supportsFts()) { $this->createExampleTable(); $this->assertSqlIds($expectedRowIds, "SELECT id FROM civicrm_fts_example WHERE " . $formatter->formatSql('civicrm_fts_example', 'name', $text)); diff --git a/tests/phpunit/CRM/Utils/RestTest.php b/tests/phpunit/CRM/Utils/RestTest.php index ac6a59c3ce..00c7d3f406 100644 --- a/tests/phpunit/CRM/Utils/RestTest.php +++ b/tests/phpunit/CRM/Utils/RestTest.php @@ -12,24 +12,24 @@ class CRM_Utils_RestTest extends CiviUnitTestCase { public function testProcessMultiple() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $input = array( - 'cow' => array( + $input = [ + 'cow' => [ 'contact', 'create', - array( + [ 'contact_type' => 'Individual', 'first_name' => 'Cow', - ), - ), - 'sheep' => array( + ], + ], + 'sheep' => [ 'contact', 'create', - array( + [ 'contact_type' => 'Individual', 'first_name' => 'Sheep', - ), - ), - ); + ], + ], + ]; $_REQUEST['json'] = json_encode($input); $output = CRM_Utils_REST::processMultiple(); $this->assertGreaterThan(0, $output['cow']['id']); diff --git a/tests/phpunit/CRM/Utils/RuleTest.php b/tests/phpunit/CRM/Utils/RuleTest.php index 0189c9c13f..cb047d79a9 100644 --- a/tests/phpunit/CRM/Utils/RuleTest.php +++ b/tests/phpunit/CRM/Utils/RuleTest.php @@ -23,14 +23,14 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase { * @return array */ public function integerDataProvider() { - return array( - array(10, TRUE), - array('145E+3', FALSE), - array('10', TRUE), - array(-10, TRUE), - array('-10', TRUE), - array('-10foo', FALSE), - ); + return [ + [10, TRUE], + ['145E+3', FALSE], + ['10', TRUE], + [-10, TRUE], + ['-10', TRUE], + ['-10foo', FALSE], + ]; } /** @@ -46,14 +46,14 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase { * @return array */ public function positiveDataProvider() { - return array( - array(10, TRUE), - array('145.0E+3', FALSE), - array('10', TRUE), - array(-10, FALSE), - array('-10', FALSE), - array('-10foo', FALSE), - ); + return [ + [10, TRUE], + ['145.0E+3', FALSE], + ['10', TRUE], + [-10, FALSE], + ['-10', FALSE], + ['-10foo', FALSE], + ]; } /** @@ -69,14 +69,14 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase { * @return array */ public function numericDataProvider() { - return array( - array(10, TRUE), - array('145.0E+3', FALSE), - array('10', TRUE), - array(-10, TRUE), - array('-10', TRUE), - array('-10foo', FALSE), - ); + return [ + [10, TRUE], + ['145.0E+3', FALSE], + ['10', TRUE], + [-10, TRUE], + ['-10', TRUE], + ['-10foo', FALSE], + ]; } /** @@ -92,24 +92,24 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase { * @return array */ public function moneyDataProvider() { - return array( - array(10, TRUE), - array('145.0E+3', FALSE), - array('10', TRUE), - array(-10, TRUE), - array('-10', TRUE), - array('-10foo', FALSE), - array('-10.0345619', TRUE), - array('-10.010,4345619', TRUE), - array('10.0104345619', TRUE), - array('-0', TRUE), - array('-.1', TRUE), - array('.1', TRUE), + return [ + [10, TRUE], + ['145.0E+3', FALSE], + ['10', TRUE], + [-10, TRUE], + ['-10', TRUE], + ['-10foo', FALSE], + ['-10.0345619', TRUE], + ['-10.010,4345619', TRUE], + ['10.0104345619', TRUE], + ['-0', TRUE], + ['-.1', TRUE], + ['.1', TRUE], // Test currency symbols too, default locale uses $, so if we wanted to test others we'd need to reconfigure locale - array('$500.3333', TRUE), - array('-$500.3333', TRUE), - array('$-500.3333', TRUE), - ); + ['$500.3333', TRUE], + ['-$500.3333', TRUE], + ['$-500.3333', TRUE], + ]; } /** @@ -146,10 +146,10 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase { * @return array */ public function extenionKeyTests() { - $keys = array(); - $keys[] = array('org.civicrm.multisite', TRUE); - $keys[] = array('au.org.contribute2016', TRUE); - $keys[] = array('%3Csvg%20onload=alert(0)%3E', FALSE); + $keys = []; + $keys[] = ['org.civicrm.multisite', TRUE]; + $keys[] = ['au.org.contribute2016', TRUE]; + $keys[] = ['%3Csvg%20onload=alert(0)%3E', FALSE]; return $keys; } diff --git a/tests/phpunit/CRM/Utils/SQL/DeleteTest.php b/tests/phpunit/CRM/Utils/SQL/DeleteTest.php index f0903be19e..6eda504d61 100644 --- a/tests/phpunit/CRM/Utils/SQL/DeleteTest.php +++ b/tests/phpunit/CRM/Utils/SQL/DeleteTest.php @@ -14,23 +14,23 @@ class CRM_Utils_SQL_DeleteTest extends CiviUnitTestCase { public function testWherePlain() { $del = CRM_Utils_SQL_Delete::from('foo') ->where('foo = bar') - ->where(array('whiz = bang', 'frob > nicate')); + ->where(['whiz = bang', 'frob > nicate']); $this->assertLike('DELETE FROM foo WHERE (foo = bar) AND (whiz = bang) AND (frob > nicate)', $del->toSQL()); } public function testWhereArg() { $del = CRM_Utils_SQL_Delete::from('foo') - ->where('foo = @value', array('@value' => 'not"valid')) - ->where(array('whiz > @base', 'frob != @base'), array('@base' => 'in"valid')); + ->where('foo = @value', ['@value' => 'not"valid']) + ->where(['whiz > @base', 'frob != @base'], ['@base' => 'in"valid']); $this->assertLike('DELETE FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $del->toSQL()); } public function testWhereNullArg() { $del = CRM_Utils_SQL_Delete::from('foo') - ->where('foo IS @value', array('@value' => NULL)) + ->where('foo IS @value', ['@value' => NULL]) ->where('nonexistent IS @nonexistent', []) ->where('morenonexistent IS @nonexistent', NULL) - ->where('bar IS @value', array('@value' => 'null')); + ->where('bar IS @value', ['@value' => 'null']); $this->assertLike('DELETE FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $del->toSQL()); } diff --git a/tests/phpunit/CRM/Utils/SQL/InsertTest.php b/tests/phpunit/CRM/Utils/SQL/InsertTest.php index 95bf5ea0cb..2750876d08 100644 --- a/tests/phpunit/CRM/Utils/SQL/InsertTest.php +++ b/tests/phpunit/CRM/Utils/SQL/InsertTest.php @@ -8,8 +8,8 @@ class CRM_Utils_SQL_InsertTest extends CiviUnitTestCase { public function testRow_twice() { $insert = CRM_Utils_SQL_Insert::into('foo') - ->row(array('first' => '1', 'second' => '2')) - ->row(array('second' => '2b', 'first' => '1b')); + ->row(['first' => '1', 'second' => '2']) + ->row(['second' => '2b', 'first' => '1b']); $expected = ' INSERT INTO foo (`first`,`second`) VALUES ("1","2"), @@ -20,13 +20,13 @@ class CRM_Utils_SQL_InsertTest extends CiviUnitTestCase { public function testRows() { $insert = CRM_Utils_SQL_Insert::into('foo') - ->row(array('first' => '1', 'second' => '2')) - ->rows(array( - array('second' => '2b', 'first' => '1b'), - array('first' => '1c', 'second' => '2c'), - )) - ->row(array('second' => '2d', 'first' => '1d')) - ->row(array('first' => NULL, 'second' => '2e')); + ->row(['first' => '1', 'second' => '2']) + ->rows([ + ['second' => '2b', 'first' => '1b'], + ['first' => '1c', 'second' => '2c'], + ]) + ->row(['second' => '2d', 'first' => '1d']) + ->row(['first' => NULL, 'second' => '2e']); $expected = ' INSERT INTO foo (`first`,`second`) VALUES ("1","2"), diff --git a/tests/phpunit/CRM/Utils/SQL/SelectTest.php b/tests/phpunit/CRM/Utils/SQL/SelectTest.php index f9ff68d3aa..c784919ec7 100644 --- a/tests/phpunit/CRM/Utils/SQL/SelectTest.php +++ b/tests/phpunit/CRM/Utils/SQL/SelectTest.php @@ -54,37 +54,37 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { public function testGetFields() { $select = CRM_Utils_SQL_Select::from('foo') ->select('bar') - ->select(array('whiz', 'bang')); + ->select(['whiz', 'bang']); $this->assertLike('SELECT bar, whiz, bang FROM foo', $select->toSQL()); } public function testWherePlain() { $select = CRM_Utils_SQL_Select::from('foo') ->where('foo = bar') - ->where(array('whiz = bang', 'frob > nicate')); + ->where(['whiz = bang', 'frob > nicate']); $this->assertLike('SELECT * FROM foo WHERE (foo = bar) AND (whiz = bang) AND (frob > nicate)', $select->toSQL()); } public function testWhereArg() { $select = CRM_Utils_SQL_Select::from('foo') - ->where('foo = @value', array('@value' => 'not"valid')) - ->where(array('whiz > @base', 'frob != @base'), array('@base' => 'in"valid')); + ->where('foo = @value', ['@value' => 'not"valid']) + ->where(['whiz > @base', 'frob != @base'], ['@base' => 'in"valid']); $this->assertLike('SELECT * FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $select->toSQL()); } public function testWhereNullArg() { $select = CRM_Utils_SQL_Select::from('foo') - ->where('foo IS @value', array('@value' => NULL)) + ->where('foo IS @value', ['@value' => NULL]) ->where('nonexistent IS @nonexistent', []) ->where('morenonexistent IS @nonexistent', NULL) - ->where('bar IS @value', array('@value' => 'null')); + ->where('bar IS @value', ['@value' => 'null']); $this->assertLike('SELECT * FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $select->toSQL()); } public function testGroupByPlain() { $select = CRM_Utils_SQL_Select::from('foo') ->groupBy("bar_id") - ->groupBy(array('whiz_id*2', 'lower(bang)')); + ->groupBy(['whiz_id*2', 'lower(bang)']); $this->assertLike('SELECT * FROM foo GROUP BY bar_id, whiz_id*2, lower(bang)', $select->toSQL()); } @@ -92,22 +92,22 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { $select = CRM_Utils_SQL_Select::from('foo') ->groupBy("bar_id") ->having('count(id) > 2') - ->having(array('sum(id) > 10', 'avg(id) < 200')); + ->having(['sum(id) > 10', 'avg(id) < 200']); $this->assertLike('SELECT * FROM foo GROUP BY bar_id HAVING (count(id) > 2) AND (sum(id) > 10) AND (avg(id) < 200)', $select->toSQL()); } public function testHavingArg() { $select = CRM_Utils_SQL_Select::from('foo') ->groupBy("bar_id") - ->having('count(id) > #mincnt', array('#mincnt' => 2)) - ->having(array('sum(id) > #whiz', 'avg(id) < #whiz'), array('#whiz' => 10)); + ->having('count(id) > #mincnt', ['#mincnt' => 2]) + ->having(['sum(id) > #whiz', 'avg(id) < #whiz'], ['#whiz' => 10]); $this->assertLike('SELECT * FROM foo GROUP BY bar_id HAVING (count(id) > 2) AND (sum(id) > 10) AND (avg(id) < 10)', $select->toSQL()); } public function testOrderByPlain() { $select = CRM_Utils_SQL_Select::from('foo bar') ->orderBy('first asc') - ->orderBy(array('second desc', 'third')); + ->orderBy(['second desc', 'third']); $this->assertLike('SELECT * FROM foo bar ORDER BY first asc, second desc, third', $select->toSQL()); } @@ -131,21 +131,21 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { } public function testModeOutput() { - $select = CRM_Utils_SQL_Select::from('foo', array('mode' => 'out')) + $select = CRM_Utils_SQL_Select::from('foo', ['mode' => 'out']) ->where('foo = @value') - ->where(array( + ->where([ 'whiz > @base', 'frob != @base', - )) + ]) ->param('@value', 'not"valid') - ->param(array( + ->param([ '@base' => 'in"valid', - )); + ]); $this->assertLike('SELECT * FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $select->toSQL()); try { - CRM_Utils_SQL_Select::from('foo', array('mode' => 'out')) - ->where('foo = @value', array('@value' => 'not"valid')); + CRM_Utils_SQL_Select::from('foo', ['mode' => 'out']) + ->where('foo = @value', ['@value' => 'not"valid']); $this->fail('In output mode, we should reject requests to interpolate inputs.'); } catch (Exception $e) { @@ -155,7 +155,7 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { $outputModeFragment = CRM_Utils_SQL_Select::fragment() ->param('value', 'whatever'); $inputModeFragment = CRM_Utils_SQL_Select::fragment() - ->where('foo = @value', array('@value' => 'not"valid')); + ->where('foo = @value', ['@value' => 'not"valid']); try { $outputModeFragment->merge($inputModeFragment); $this->fail('In output-mode, we should reject requests to merge from input-mode.'); @@ -170,7 +170,7 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { ->select('foo.id') ->join('rel1', 'INNER JOIN rel1_table rel1 ON foo.id = rel1.foo_id') ->join('rel2', 'LEFT JOIN rel2_table rel2 ON foo.id = rel2.foo_id') - ->where('foo.type = @theType', array('@theType' => 'mytype')) + ->where('foo.type = @theType', ['@theType' => 'mytype']) ->groupBy("foo.id") ->having('sum(rel1.stat) > 10') ->orderBy('rel2.whiz') @@ -194,22 +194,22 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { */ public function testNoIterativeInterpolation() { $select = CRM_Utils_SQL_Select::from('foo') - ->where('a = @a and b = @b and c = @c', array( + ->where('a = @a and b = @b and c = @c', [ 'a' => '@b', 'b' => '@c', 'c' => '@a', - )); + ]); $this->assertLike('SELECT * FROM foo WHERE (a = "@b" and b = "@c" and c = "@a")', $select->toSQL()); } public function testInterpolate() { $actual = CRM_Utils_SQL_Select::from('ignore')->interpolate( '@escaped !unescaped #validated', - array( + [ '@escaped' => 'foo"bar', '!unescaped' => 'concat(foo,bar)', '#validated' => 15.2, - ) + ] ); $this->assertLike('"foo\"bar" concat(foo,bar) 15.2', $actual); } @@ -217,11 +217,11 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { public function testInterpolateWildcard() { $actual = CRM_Utils_SQL_Select::from('ignore')->interpolate( 'escaped @escaped unescaped !unescaped validated #validated', - array( + [ 'escaped' => 'foo"bar', 'unescaped' => 'concat(foo,bar)', 'validated' => 15.2, - ) + ] ); $this->assertLike('escaped "foo\"bar" unescaped concat(foo,bar) validated 15.2', $actual); } @@ -229,9 +229,9 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { public function testInterpolateUnknown() { $actual = CRM_Utils_SQL_Select::from('ignore')->interpolate( 'escaped @escaped unescaped !unescaped validated #validated', - array( + [ 'irrelevant' => 'foo', - ) + ] ); $this->assertLike('escaped @escaped unescaped !unescaped validated #validated', $actual); } @@ -241,9 +241,9 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { CRM_Utils_SQL_Select::from('ignore') ->strict() ->interpolate('@johnMcClane', - array( + [ 'irrelevant' => 'foo', - ) + ] ); $this->fail('Unknown variables should throw errors in strict mode.'); } @@ -255,20 +255,20 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { public function testInterpolateArray() { $actual = CRM_Utils_SQL_Select::from('ignore')->interpolate( '(@escaped) (!unescaped) (#validated)', - array( - '@escaped' => array('foo"bar', "whiz", "null", NULL, "bang"), - '!unescaped' => array('foo"bar', 'bar'), - '#validated' => array(1, 10, NULL, 100.1), - ) + [ + '@escaped' => ['foo"bar', "whiz", "null", NULL, "bang"], + '!unescaped' => ['foo"bar', 'bar'], + '#validated' => [1, 10, NULL, 100.1], + ] ); $this->assertLike('("foo\\"bar", "whiz", "null", NULL, "bang") (foo"bar, bar) (1, 10, NULL, 100.1)', $actual); } public function testInterpolateBadNumber() { try { - $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', array( + $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', [ '#num' => '5not-a-number5', - )); + ]); $this->fail('Expected exception; got: ' . var_export($result, TRUE)); } catch (CRM_Core_Exception $e) { @@ -276,9 +276,9 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { } try { - $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', array( - '#num' => array(1, '5not-a-number5', 2), - )); + $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', [ + '#num' => [1, '5not-a-number5', 2], + ]); $this->fail('Expected exception; got: ' . var_export($result, TRUE)); } catch (CRM_Core_Exception $e) { @@ -288,14 +288,14 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { public function testMerge() { $fragmentOutMode = CRM_Utils_SQL_Select::fragment() - ->select(array('a', 'b')) + ->select(['a', 'b']) ->where('a = #two') ->param('two', 2); $fragmentAutoMode = CRM_Utils_SQL_Select::fragment() ->select('e') ->where('whipit()'); $query = CRM_Utils_SQL_Select::from('foo') - ->select(array('c', 'd')) + ->select(['c', 'd']) ->where('c = @four') ->param('four', 4) ->merge($fragmentOutMode) @@ -311,17 +311,17 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { public function testInsertInto_WithDupes() { $select = CRM_Utils_SQL_Select::from('foo') - ->insertInto('bar', array('first', 'second', 'third', 'fourth')) + ->insertInto('bar', ['first', 'second', 'third', 'fourth']) ->select('fid') ->select('1') ->select('fid') ->select('1') - ->where('!field = #value', array('field' => 'zoo', 'value' => 3)) - ->where('!field = #value', array('field' => 'aviary', 'value' => 3)) - ->where('!field = #value', array('field' => 'zoo', 'value' => 3)) - ->groupBy('!colName', array('colName' => 'noodle')) - ->groupBy('!colName', array('colName' => 'sauce')) - ->groupBy('!colName', array('colName' => 'noodle')); + ->where('!field = #value', ['field' => 'zoo', 'value' => 3]) + ->where('!field = #value', ['field' => 'aviary', 'value' => 3]) + ->where('!field = #value', ['field' => 'zoo', 'value' => 3]) + ->groupBy('!colName', ['colName' => 'noodle']) + ->groupBy('!colName', ['colName' => 'sauce']) + ->groupBy('!colName', ['colName' => 'noodle']); $this->assertLike('INSERT INTO bar (first, second, third, fourth) SELECT fid, 1, fid, 1 FROM foo WHERE (zoo = 3) AND (aviary = 3) GROUP BY noodle, sauce', $select->toSQL()); } diff --git a/tests/phpunit/CRM/Utils/SignerTest.php b/tests/phpunit/CRM/Utils/SignerTest.php index 51de429319..1dac526dec 100644 --- a/tests/phpunit/CRM/Utils/SignerTest.php +++ b/tests/phpunit/CRM/Utils/SignerTest.php @@ -36,121 +36,121 @@ class CRM_Utils_SignerTest extends CiviUnitTestCase { } public function testSignValidate() { - $cases = array(); - $cases[] = array( - 'signParams' => array( + $cases = []; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), + ], 'isValid' => TRUE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, 'irrelevant' => 'totally-irrelevant', - ), + ], 'isValid' => TRUE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => '', - ), + ], 'isValid' => TRUE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => 0, - ), + ], 'isValid' => FALSE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => 0, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), + ], 'isValid' => FALSE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bay', 'c' => NULL, - ), + ], 'isValid' => FALSE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => NULL, - ), - 'validateParams' => array( + ], + 'validateParams' => [ 'a' => 'eh', 'b' => 'bee', 'c' => FALSE, - ), + ], 'isValid' => FALSE, - ); - $cases[] = array( - 'signParams' => array( + ]; + $cases[] = [ + 'signParams' => [ // int 'a' => 1, 'b' => 'bee', - ), - 'validateParams' => array( + ], + 'validateParams' => [ // string 'a' => '1', 'b' => 'bee', - ), + ], 'isValid' => TRUE, - ); + ]; foreach ($cases as $caseId => $case) { - $signer = new CRM_Utils_Signer('secret', array('a', 'b', 'c')); + $signer = new CRM_Utils_Signer('secret', ['a', 'b', 'c']); $signature = $signer->sign($case['signParams']); // arbitrary $this->assertTrue(!empty($signature) && is_string($signature)); // same as $signer but physically separate - $validator = new CRM_Utils_Signer('secret', array('a', 'b', 'c')); + $validator = new CRM_Utils_Signer('secret', ['a', 'b', 'c']); $isValid = $validator->validate($signature, $case['validateParams']); if ($isValid !== $case['isValid']) { diff --git a/tests/phpunit/CRM/Utils/StringTest.php b/tests/phpunit/CRM/Utils/StringTest.php index 4bc1bd3ade..b407f855fc 100644 --- a/tests/phpunit/CRM/Utils/StringTest.php +++ b/tests/phpunit/CRM/Utils/StringTest.php @@ -11,7 +11,7 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { } public function testStripPathChars() { - $testSet = array( + $testSet = [ '' => '', NULL => NULL, 'civicrm' => 'civicrm', @@ -19,7 +19,7 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { 'civicrm/contribute/transact' => 'civicrm/contribute/transact', 'civicrm/attempt' => 'civicrm/_hack_attempt_/hack_', 'civicrm dashboard & force = 1,;' => 'civicrm_dashboard___force___1__', - ); + ]; foreach ($testSet as $in => $expected) { $out = CRM_Utils_String::stripPathChars($in); @@ -28,47 +28,47 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { } public function testExtractName() { - $cases = array( - array( + $cases = [ + [ 'full_name' => 'Alan', 'first_name' => 'Alan', - ), - array( + ], + [ 'full_name' => 'Alan Arkin', 'first_name' => 'Alan', 'last_name' => 'Arkin', - ), - array( + ], + [ 'full_name' => '"Alan Arkin"', 'first_name' => 'Alan', 'last_name' => 'Arkin', - ), - array( + ], + [ 'full_name' => 'Alan A Arkin', 'first_name' => 'Alan', 'middle_name' => 'A', 'last_name' => 'Arkin', - ), - array( + ], + [ 'full_name' => 'Adams, Amy', 'first_name' => 'Amy', 'last_name' => 'Adams', - ), - array( + ], + [ 'full_name' => 'Adams, Amy A', 'first_name' => 'Amy', 'middle_name' => 'A', 'last_name' => 'Adams', - ), - array( + ], + [ 'full_name' => '"Adams, Amy A"', 'first_name' => 'Amy', 'middle_name' => 'A', 'last_name' => 'Adams', - ), - ); + ], + ]; foreach ($cases as $case) { - $actual = array(); + $actual = []; CRM_Utils_String::extractName($case['full_name'], $actual); $this->assertEquals($actual['first_name'], $case['first_name']); $this->assertEquals(CRM_Utils_Array::value('last_name', $actual), CRM_Utils_Array::value('last_name', $case)); @@ -78,11 +78,11 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { public function testEllipsify() { $maxLen = 5; - $cases = array( + $cases = [ '1' => '1', '12345' => '12345', '123456' => '12...', - ); + ]; foreach ($cases as $input => $expected) { $this->assertEquals($expected, CRM_Utils_String::ellipsify($input, $maxLen)); } @@ -108,11 +108,11 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { * @return array */ public function parsePrefixData() { - $cases = array(); - $cases[] = array('administer CiviCRM', NULL, array(NULL, 'administer CiviCRM')); - $cases[] = array('administer CiviCRM', 'com_civicrm', array('com_civicrm', 'administer CiviCRM')); - $cases[] = array('Drupal:access user profiles', NULL, array('Drupal', 'access user profiles')); - $cases[] = array('Joomla:component:perm', NULL, array('Joomla', 'component:perm')); + $cases = []; + $cases[] = ['administer CiviCRM', NULL, [NULL, 'administer CiviCRM']]; + $cases[] = ['administer CiviCRM', 'com_civicrm', ['com_civicrm', 'administer CiviCRM']]; + $cases[] = ['Drupal:access user profiles', NULL, ['Drupal', 'access user profiles']]; + $cases[] = ['Joomla:component:perm', NULL, ['Joomla', 'component:perm']]; return $cases; } @@ -132,27 +132,27 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { */ public function booleanDataProvider() { // array(0 => $input, 1 => $expectedOutput) - $cases = array(); - $cases[] = array(TRUE, TRUE); - $cases[] = array(FALSE, FALSE); - $cases[] = array(1, TRUE); - $cases[] = array(0, FALSE); - $cases[] = array('1', TRUE); - $cases[] = array('0', FALSE); - $cases[] = array(TRUE, TRUE); - $cases[] = array(FALSE, FALSE); - $cases[] = array('Y', TRUE); - $cases[] = array('N', FALSE); - $cases[] = array('y', TRUE); - $cases[] = array('n', FALSE); - $cases[] = array('Yes', TRUE); - $cases[] = array('No', FALSE); - $cases[] = array('True', TRUE); - $cases[] = array('False', FALSE); - $cases[] = array('yEs', TRUE); - $cases[] = array('nO', FALSE); - $cases[] = array('tRuE', TRUE); - $cases[] = array('FaLsE', FALSE); + $cases = []; + $cases[] = [TRUE, TRUE]; + $cases[] = [FALSE, FALSE]; + $cases[] = [1, TRUE]; + $cases[] = [0, FALSE]; + $cases[] = ['1', TRUE]; + $cases[] = ['0', FALSE]; + $cases[] = [TRUE, TRUE]; + $cases[] = [FALSE, FALSE]; + $cases[] = ['Y', TRUE]; + $cases[] = ['N', FALSE]; + $cases[] = ['y', TRUE]; + $cases[] = ['n', FALSE]; + $cases[] = ['Yes', TRUE]; + $cases[] = ['No', FALSE]; + $cases[] = ['True', TRUE]; + $cases[] = ['False', FALSE]; + $cases[] = ['yEs', TRUE]; + $cases[] = ['nO', FALSE]; + $cases[] = ['tRuE', TRUE]; + $cases[] = ['FaLsE', FALSE]; return $cases; } @@ -167,20 +167,20 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { } public function startEndCases() { - $cases = array(); - $cases[] = array('startsWith', 'foo', '', TRUE); - $cases[] = array('startsWith', 'foo', 'f', TRUE); - $cases[] = array('startsWith', 'foo', 'fo', TRUE); - $cases[] = array('startsWith', 'foo', 'foo', TRUE); - $cases[] = array('startsWith', 'foo', 'fooo', FALSE); - $cases[] = array('startsWith', 'foo', 'o', FALSE); - $cases[] = array('endsWith', 'foo', 'f', FALSE); - $cases[] = array('endsWith', 'foo', '', TRUE); - $cases[] = array('endsWith', 'foo', 'o', TRUE); - $cases[] = array('endsWith', 'foo', 'oo', TRUE); - $cases[] = array('endsWith', 'foo', 'foo', TRUE); - $cases[] = array('endsWith', 'foo', 'fooo', FALSE); - $cases[] = array('endsWith', 'foo*', '*', TRUE); + $cases = []; + $cases[] = ['startsWith', 'foo', '', TRUE]; + $cases[] = ['startsWith', 'foo', 'f', TRUE]; + $cases[] = ['startsWith', 'foo', 'fo', TRUE]; + $cases[] = ['startsWith', 'foo', 'foo', TRUE]; + $cases[] = ['startsWith', 'foo', 'fooo', FALSE]; + $cases[] = ['startsWith', 'foo', 'o', FALSE]; + $cases[] = ['endsWith', 'foo', 'f', FALSE]; + $cases[] = ['endsWith', 'foo', '', TRUE]; + $cases[] = ['endsWith', 'foo', 'o', TRUE]; + $cases[] = ['endsWith', 'foo', 'oo', TRUE]; + $cases[] = ['endsWith', 'foo', 'foo', TRUE]; + $cases[] = ['endsWith', 'foo', 'fooo', FALSE]; + $cases[] = ['endsWith', 'foo*', '*', TRUE]; return $cases; } @@ -198,12 +198,12 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { } public function wildcardCases() { - $cases = array(); - $cases[] = array('*', array('foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang')); - $cases[] = array('foo.*', array('foo.bar.1', 'foo.bar.2', 'foo.whiz')); - $cases[] = array('foo.bar.*', array('foo.bar.1', 'foo.bar.2')); - $cases[] = array(array('foo.bar.*', 'foo.bar.2'), array('foo.bar.1', 'foo.bar.2')); - $cases[] = array(array('foo.bar.2', 'foo.w*'), array('foo.bar.2', 'foo.whiz')); + $cases = []; + $cases[] = ['*', ['foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang']]; + $cases[] = ['foo.*', ['foo.bar.1', 'foo.bar.2', 'foo.whiz']]; + $cases[] = ['foo.bar.*', ['foo.bar.1', 'foo.bar.2']]; + $cases[] = [['foo.bar.*', 'foo.bar.2'], ['foo.bar.1', 'foo.bar.2']]; + $cases[] = [['foo.bar.2', 'foo.w*'], ['foo.bar.2', 'foo.whiz']]; return $cases; } @@ -213,7 +213,7 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { * @dataProvider wildcardCases */ public function testFilterByWildCards($patterns, $expectedResults) { - $data = array('foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang'); + $data = ['foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang']; $actualResults = CRM_Utils_String::filterByWildcards($patterns, $data); $this->assertEquals($expectedResults, $actualResults); @@ -225,7 +225,7 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { $this->assertEquals($expectedResults, $actualResults); $actualResults = CRM_Utils_String::filterByWildcards($patterns, $data, TRUE); - $this->assertEquals(array_merge($expectedResults, array('noise')), $actualResults); + $this->assertEquals(array_merge($expectedResults, ['noise']), $actualResults); } /** @@ -264,43 +264,43 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { $externalDomain = 'example.net'; } - return array( - 'prototypical example' => array( + return [ + 'prototypical example' => [ "https://$localDomain/sites/default/files/coffee-mug.jpg", FALSE, '/sites/default/files/coffee-mug.jpg', - ), - 'external domain with https' => array( + ], + 'external domain with https' => [ "https://$externalDomain/sites/default/files/coffee-mug.jpg", FALSE, "https://$externalDomain/sites/default/files/coffee-mug.jpg", - ), - 'external domain with http forced to https' => array( + ], + 'external domain with http forced to https' => [ "http://$externalDomain/sites/default/files/coffee-mug.jpg", TRUE, "https://$externalDomain/sites/default/files/coffee-mug.jpg", - ), - 'external domain with http not forced' => array( + ], + 'external domain with http not forced' => [ "http://$externalDomain/sites/default/files/coffee-mug.jpg", FALSE, "http://$externalDomain/sites/default/files/coffee-mug.jpg", - ), - 'local URL' => array( + ], + 'local URL' => [ "/sites/default/files/coffee-mug.jpg", FALSE, "/sites/default/files/coffee-mug.jpg", - ), - 'local URL without a forward slash' => array( + ], + 'local URL without a forward slash' => [ "sites/default/files/coffee-mug.jpg", FALSE, "/sites/default/files/coffee-mug.jpg", - ), - 'empty input' => array( + ], + 'empty input' => [ '', FALSE, '', - ), - ); + ], + ]; } /** @@ -322,36 +322,36 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { * @return array */ public function parseURLProvider() { - return array( - "prototypical example" => array( + return [ + "prototypical example" => [ "https://example.com:8000/foo/bar/?id=1#fragment", - array( + [ 'host+port' => "example.com:8000", 'path+query' => "/foo/bar/?id=1", - ), - ), - "default port example" => array( + ], + ], + "default port example" => [ "https://example.com/foo/bar/?id=1#fragment", - array( + [ 'host+port' => "example.com", 'path+query' => "/foo/bar/?id=1", - ), - ), - "empty" => array( + ], + ], + "empty" => [ "", - array( + [ 'host+port' => "", 'path+query' => "", - ), - ), - "path only" => array( + ], + ], + "path only" => [ "/foo/bar/image.png", - array( + [ 'host+port' => "", 'path+query' => "/foo/bar/image.png", - ), - ), - ); + ], + ], + ]; } public function purifyHTMLProvider() { diff --git a/tests/phpunit/CRM/Utils/SystemTest.php b/tests/phpunit/CRM/Utils/SystemTest.php index 457e736329..602184984e 100644 --- a/tests/phpunit/CRM/Utils/SystemTest.php +++ b/tests/phpunit/CRM/Utils/SystemTest.php @@ -23,10 +23,10 @@ class CRM_Utils_SystemTest extends CiviUnitTestCase { $config = CRM_Core_Config::singleton(); $this->assertTrue($config->userSystem instanceof CRM_Utils_System_UnitTests); $expected = '/index.php?q=civicrm/foo/bar&foo=ab&bar=cd%26ef'; - $actual = CRM_Utils_System::url('civicrm/foo/bar', array( + $actual = CRM_Utils_System::url('civicrm/foo/bar', [ 'foo' => 'ab', 'bar' => 'cd&ef', - ), FALSE, NULL, FALSE); + ], FALSE, NULL, FALSE); $this->assertEquals($expected, $actual); } @@ -45,7 +45,7 @@ class CRM_Utils_SystemTest extends CiviUnitTestCase { * @dataProvider getURLs */ public function testRedirectHook($url, $parsedUrl) { - $this->hookClass->setHook('civicrm_alterRedirect', array($this, 'hook_civicrm_alterRedirect')); + $this->hookClass->setHook('civicrm_alterRedirect', [$this, 'hook_civicrm_alterRedirect']); try { CRM_Utils_System::redirect($url, [ 'expected' => $parsedUrl, diff --git a/tests/phpunit/CRM/Utils/TimeTest.php b/tests/phpunit/CRM/Utils/TimeTest.php index 55c647d1bd..d2d7d0835f 100644 --- a/tests/phpunit/CRM/Utils/TimeTest.php +++ b/tests/phpunit/CRM/Utils/TimeTest.php @@ -13,14 +13,14 @@ class CRM_Utils_TimeTest extends CiviUnitTestCase { */ public function equalCases() { // array(0 => $timeA, 1 => $timeB, 2 => $threshold, 3 => $expectedResult) - $cases = array(); - $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:00', 0, 1); - $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:01', 0, 0); - $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:50', 60, 1); - $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:01:02', 60, 0); - $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 0, 0); - $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 60, 1); - $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 120, 1); + $cases = []; + $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:00:00', 0, 1]; + $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:00:01', 0, 0]; + $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:00:50', 60, 1]; + $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:01:02', 60, 0]; + $cases[] = ['2012-04-01 12:00', '2012-04-01 12:01', 0, 0]; + $cases[] = ['2012-04-01 12:00', '2012-04-01 12:01', 60, 1]; + $cases[] = ['2012-04-01 12:00', '2012-04-01 12:01', 120, 1]; return $cases; } diff --git a/tests/phpunit/CRM/Utils/TokenTest.php b/tests/phpunit/CRM/Utils/TokenTest.php index 795ce797f0..c42ca966f0 100644 --- a/tests/phpunit/CRM/Utils/TokenTest.php +++ b/tests/phpunit/CRM/Utils/TokenTest.php @@ -10,8 +10,8 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { * Basic test on getTokenDetails function. */ public function testGetTokenDetails() { - $contactID = $this->individualCreate(array('preferred_communication_method' => array('Phone', 'Fax'))); - $resolvedTokens = CRM_Utils_Token::getTokenDetails(array($contactID)); + $contactID = $this->individualCreate(['preferred_communication_method' => ['Phone', 'Fax']]); + $resolvedTokens = CRM_Utils_Token::getTokenDetails([$contactID]); $this->assertEquals('Phone, Fax', $resolvedTokens[0][$contactID]['preferred_communication_method']); } @@ -27,26 +27,26 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { // create a contact with multiple email address and among which one is primary $contactID = $this->individualCreate(); $primaryEmail = uniqid() . '@primary.com'; - $this->callAPISuccess('Email', 'create', array( + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $contactID, 'email' => $primaryEmail, 'location_type_id' => 'Other', 'is_primary' => 1, - )); - $this->callAPISuccess('Email', 'create', array( + ]); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $contactID, 'email' => uniqid() . '@galaxy.com', 'location_type_id' => 'Work', 'is_primary' => 0, - )); - $this->callAPISuccess('Email', 'create', array( + ]); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $contactID, 'email' => uniqid() . '@galaxy.com', 'location_type_id' => 'Work', 'is_primary' => 0, - )); + ]); - $contactIDs = array($contactID); + $contactIDs = [$contactID]; // when we are fetching contact details ON basis of primary address fields $contactDetails = CRM_Utils_Token::getTokenDetails($contactIDs); @@ -62,17 +62,17 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { */ public function testReplaceGreetingTokens() { $tokenString = 'First Name: {contact.first_name} Last Name: {contact.last_name} Birth Date: {contact.birth_date} Prefix: {contact.prefix_id} Suffix: {contact.individual_suffix}'; - $contactDetails = array( - array( - 2811 => array( + $contactDetails = [ + [ + 2811 => [ 'id' => '2811', 'contact_type' => 'Individual', 'first_name' => 'Morticia', 'last_name' => 'Addams', 'prefix_id' => 2, - ), - ), - ); + ], + ], + ]; $contactId = 2811; $className = 'CRM_Contact_BAO_Contact'; $escapeSmarty = TRUE; @@ -88,7 +88,7 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { public function testGetTokenDetailsMultipleEmails() { $i = 0; - $params = array( + $params = [ 'do_not_phone' => 1, 'do_not_email' => 0, 'do_not_mail' => 1, @@ -104,22 +104,22 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { 'gender_id' => '1', 'birth_date' => '2017-01-01', // 'city' => 'Metropolis', - ); - $contactIDs = array(); + ]; + $contactIDs = []; while ($i < 27) { $contactIDs[] = $contactID = $this->individualCreate($params); - $this->callAPISuccess('Email', 'create', array( + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $contactID, 'email' => 'goodguy@galaxy.com', 'location_type_id' => 'Other', 'is_primary' => 0, - )); - $this->callAPISuccess('Email', 'create', array( + ]); + $this->callAPISuccess('Email', 'create', [ 'contact_id' => $contactID, 'email' => 'villain@galaxy.com', 'location_type_id' => 'Work', 'is_primary' => 1, - )); + ]); $i++; } unset($params['email']); diff --git a/tests/phpunit/CRM/Utils/TypeTest.php b/tests/phpunit/CRM/Utils/TypeTest.php index dab58cbfe5..21a47fa35b 100644 --- a/tests/phpunit/CRM/Utils/TypeTest.php +++ b/tests/phpunit/CRM/Utils/TypeTest.php @@ -26,59 +26,59 @@ class CRM_Utils_TypeTest extends CiviUnitTestCase { * @return array */ public function validateDataProvider() { - return array( - array(10, 'Int', 10), - array('145E+3', 'Int', NULL), - array('10', 'Integer', 10), - array(-10, 'Int', -10), - array('-10', 'Integer', -10), - array('-10foo', 'Int', NULL), - array(10, 'Positive', 10), - array('145.0E+3', 'Positive', NULL), - array('10', 'Positive', 10), - array(-10, 'Positive', NULL), - array('-10', 'Positive', NULL), - array('-10foo', 'Positive', NULL), - array('civicrm_column_name', 'MysqlColumnNameOrAlias', 'civicrm_column_name'), - array('table.civicrm_column_name', 'MysqlColumnNameOrAlias', 'table.civicrm_column_name'), - array('table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL), - array('Home-street_address', 'MysqlColumnNameOrAlias', 'Home-street_address'), - array('`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'), - array('`Home-street_address', 'MysqlColumnNameOrAlias', NULL), - array('table.`Home-street_address`', 'MysqlColumnNameOrAlias', 'table.`Home-street_address`'), - array('`table-alias`.`Home-street_address`', 'MysqlColumnNameOrAlias', '`table-alias`.`Home-street_address`'), - array('`table-alias`.column', 'MysqlColumnNameOrAlias', '`table-alias`.column'), + return [ + [10, 'Int', 10], + ['145E+3', 'Int', NULL], + ['10', 'Integer', 10], + [-10, 'Int', -10], + ['-10', 'Integer', -10], + ['-10foo', 'Int', NULL], + [10, 'Positive', 10], + ['145.0E+3', 'Positive', NULL], + ['10', 'Positive', 10], + [-10, 'Positive', NULL], + ['-10', 'Positive', NULL], + ['-10foo', 'Positive', NULL], + ['civicrm_column_name', 'MysqlColumnNameOrAlias', 'civicrm_column_name'], + ['table.civicrm_column_name', 'MysqlColumnNameOrAlias', 'table.civicrm_column_name'], + ['table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL], + ['Home-street_address', 'MysqlColumnNameOrAlias', 'Home-street_address'], + ['`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'], + ['`Home-street_address', 'MysqlColumnNameOrAlias', NULL], + ['table.`Home-street_address`', 'MysqlColumnNameOrAlias', 'table.`Home-street_address`'], + ['`table-alias`.`Home-street_address`', 'MysqlColumnNameOrAlias', '`table-alias`.`Home-street_address`'], + ['`table-alias`.column', 'MysqlColumnNameOrAlias', '`table-alias`.column'], // Spaces also permitted, only when enclosed in backticks. - array('`column alias`', 'MysqlColumnNameOrAlias', '`column alias`'), - array('`table alias`.column', 'MysqlColumnNameOrAlias', '`table alias`.column'), - array('`table alias`.`column alias`', 'MysqlColumnNameOrAlias', '`table alias`.`column alias`'), - array('table alias.column alias', 'MysqlColumnNameOrAlias', NULL), - array('table alias.column_alias', 'MysqlColumnNameOrAlias', NULL), - array('table_alias.column alias', 'MysqlColumnNameOrAlias', NULL), + ['`column alias`', 'MysqlColumnNameOrAlias', '`column alias`'], + ['`table alias`.column', 'MysqlColumnNameOrAlias', '`table alias`.column'], + ['`table alias`.`column alias`', 'MysqlColumnNameOrAlias', '`table alias`.`column alias`'], + ['table alias.column alias', 'MysqlColumnNameOrAlias', NULL], + ['table alias.column_alias', 'MysqlColumnNameOrAlias', NULL], + ['table_alias.column alias', 'MysqlColumnNameOrAlias', NULL], // Functions are not permitted. - array('column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL), + ['column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL], // Length checking permits only 64 chars. - array(str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64)), - array(str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL), - array(str_repeat('a', 64) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64) . '.' . str_repeat('a', 64)), - array('`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`', 'MysqlColumnNameOrAlias', '`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`'), - array(str_repeat('a', 64) . '.' . str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL), - array(str_repeat('a', 65) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', NULL), + [str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64)], + [str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL], + [str_repeat('a', 64) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64) . '.' . str_repeat('a', 64)], + ['`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`', 'MysqlColumnNameOrAlias', '`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`'], + [str_repeat('a', 64) . '.' . str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL], + [str_repeat('a', 65) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', NULL], // ORDER BY can be ASC or DESC, case not significant. - array('asc', 'MysqlOrderByDirection', 'asc'), - array('DESC', 'MysqlOrderByDirection', 'desc'), - array('DESCc', 'MysqlOrderByDirection', NULL), - array('table.civicrm_column_name desc', 'MysqlOrderBy', 'table.civicrm_column_name desc'), - array('field(civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(civicrm_column_name,4,5,6)'), - array('field(table.civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(table.civicrm_column_name,4,5,6)'), - array('table.civicrm_column_name desc,other_column, another_column desc', 'MysqlOrderBy', 'table.civicrm_column_name desc,other_column, another_column desc'), - array('table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', 'table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column'), + ['asc', 'MysqlOrderByDirection', 'asc'], + ['DESC', 'MysqlOrderByDirection', 'desc'], + ['DESCc', 'MysqlOrderByDirection', NULL], + ['table.civicrm_column_name desc', 'MysqlOrderBy', 'table.civicrm_column_name desc'], + ['field(civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(civicrm_column_name,4,5,6)'], + ['field(table.civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(table.civicrm_column_name,4,5,6)'], + ['table.civicrm_column_name desc,other_column, another_column desc', 'MysqlOrderBy', 'table.civicrm_column_name desc,other_column, another_column desc'], + ['table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', 'table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column'], // Lab issue dev/core#93 allow for 3 column orderby - array('contact_id.gender_id.label', 'MysqlOrderBy', 'contact_id.gender_id.label'), - array('a string', 'String', 'a string'), - array('{"contact":{"contact_id":205}}', 'Json', '{"contact":{"contact_id":205}}'), - array('{"contact":{"contact_id":!n†rude®}}', 'Json', NULL), - ); + ['contact_id.gender_id.label', 'MysqlOrderBy', 'contact_id.gender_id.label'], + ['a string', 'String', 'a string'], + ['{"contact":{"contact_id":205}}', 'Json', '{"contact":{"contact_id":205}}'], + ['{"contact":{"contact_id":!n†rude®}}', 'Json', NULL], + ]; } /** @@ -95,43 +95,43 @@ class CRM_Utils_TypeTest extends CiviUnitTestCase { * @return array */ public function escapeDataProvider() { - return array( - array(10, 'Int', 10), - array('145E+3', 'Int', NULL), - array('10', 'Integer', 10), - array(-10, 'Int', -10), - array(array(), 'Integer', NULL), - array('-10foo', 'Int', NULL), - array(10, 'Positive', 10), - array('145.0E+3', 'Positive', NULL), - array('10', 'Positive', 10), - array(-10, 'Positive', NULL), - array('-10', 'Positive', NULL), - array('-10foo', 'Positive', NULL), - array(array('10', 20), 'Country', array('10', 20)), - array(array('10', '-10foo'), 'Country', NULL), - array('', 'Timestamp', ''), - array('', 'ContactReference', ''), - array('3', 'ContactReference', 3), - array('-3', 'ContactReference', NULL), + return [ + [10, 'Int', 10], + ['145E+3', 'Int', NULL], + ['10', 'Integer', 10], + [-10, 'Int', -10], + [[], 'Integer', NULL], + ['-10foo', 'Int', NULL], + [10, 'Positive', 10], + ['145.0E+3', 'Positive', NULL], + ['10', 'Positive', 10], + [-10, 'Positive', NULL], + ['-10', 'Positive', NULL], + ['-10foo', 'Positive', NULL], + [['10', 20], 'Country', ['10', 20]], + [['10', '-10foo'], 'Country', NULL], + ['', 'Timestamp', ''], + ['', 'ContactReference', ''], + ['3', 'ContactReference', 3], + ['-3', 'ContactReference', NULL], // Escape function is meant for sql, not xss - array('

Hello

', 'Memo', '

Hello

'), - array('civicrm_column_name', 'MysqlColumnNameOrAlias', '`civicrm_column_name`'), - array('table.civicrm_column_name', 'MysqlColumnNameOrAlias', '`table`.`civicrm_column_name`'), - array('table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL), - array('Home-street_address', 'MysqlColumnNameOrAlias', '`Home-street_address`'), - array('`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'), - array('`Home-street_address', 'MysqlColumnNameOrAlias', NULL), - array('column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL), - array('asc', 'MysqlOrderByDirection', 'asc'), - array('DESC', 'MysqlOrderByDirection', 'desc'), - array('DESCc', 'MysqlOrderByDirection', NULL), - array('table.civicrm_column_name desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc'), - array('field(contribution_status_id,4,5,6) asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc'), - array('field(contribution_status_id,4,5,6) asc, contact_id asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc, `contact_id` asc'), - array('table.civicrm_column_name desc,other_column,another_column desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc, `other_column`, `another_column` desc'), - array('table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', '`table`.`Home-street_address` asc, `table-alias`.`Home-street_address` desc, `table-alias`.`column`'), - ); + ['

Hello

', 'Memo', '

Hello

'], + ['civicrm_column_name', 'MysqlColumnNameOrAlias', '`civicrm_column_name`'], + ['table.civicrm_column_name', 'MysqlColumnNameOrAlias', '`table`.`civicrm_column_name`'], + ['table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL], + ['Home-street_address', 'MysqlColumnNameOrAlias', '`Home-street_address`'], + ['`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'], + ['`Home-street_address', 'MysqlColumnNameOrAlias', NULL], + ['column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL], + ['asc', 'MysqlOrderByDirection', 'asc'], + ['DESC', 'MysqlOrderByDirection', 'desc'], + ['DESCc', 'MysqlOrderByDirection', NULL], + ['table.civicrm_column_name desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc'], + ['field(contribution_status_id,4,5,6) asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc'], + ['field(contribution_status_id,4,5,6) asc, contact_id asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc, `contact_id` asc'], + ['table.civicrm_column_name desc,other_column,another_column desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc, `other_column`, `another_column` desc'], + ['table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', '`table`.`Home-street_address` asc, `table-alias`.`Home-street_address` desc, `table-alias`.`column`'], + ]; } } diff --git a/tests/phpunit/CRM/Utils/ZipTest.php b/tests/phpunit/CRM/Utils/ZipTest.php index d348d6ed25..d982a0a7ba 100644 --- a/tests/phpunit/CRM/Utils/ZipTest.php +++ b/tests/phpunit/CRM/Utils/ZipTest.php @@ -45,104 +45,104 @@ class CRM_Utils_ZipTest extends CiviUnitTestCase { public function testFindBaseDirName_normal() { $this->_doFindBaseDirName('author-com.example.foo-random/', - array('author-com.example.foo-random'), - array('author-com.example.foo-random/README.txt' => 'hello') + ['author-com.example.foo-random'], + ['author-com.example.foo-random/README.txt' => 'hello'] ); } public function testFindBaseDirName_0() { $this->_doFindBaseDirName('0/', - array('0'), - array() + ['0'], + [] ); } public function testFindBaseDirName_plainfile() { $this->_doFindBaseDirName(FALSE, - array(), - array('README.txt' => 'hello') + [], + ['README.txt' => 'hello'] ); } public function testFindBaseDirName_twodir() { $this->_doFindBaseDirName(FALSE, - array('dir-1', 'dir-2'), - array('dir-1/README.txt' => 'hello') + ['dir-1', 'dir-2'], + ['dir-1/README.txt' => 'hello'] ); } public function testFindBaseDirName_dirfile() { $this->_doFindBaseDirName(FALSE, - array('dir-1'), - array('dir-1/README.txt' => 'hello', 'MANIFEST.MF' => 'extra') + ['dir-1'], + ['dir-1/README.txt' => 'hello', 'MANIFEST.MF' => 'extra'] ); } public function testFindBaseDirName_dot() { $this->_doFindBaseDirName(FALSE, - array('.'), - array('./README.txt' => 'hello') + ['.'], + ['./README.txt' => 'hello'] ); } public function testFindBaseDirName_dots() { $this->_doFindBaseDirName(FALSE, - array('..'), - array('../README.txt' => 'hello') + ['..'], + ['../README.txt' => 'hello'] ); } public function testFindBaseDirName_weird() { $this->_doFindBaseDirName(FALSE, - array('foo/../'), - array('foo/../README.txt' => 'hello') + ['foo/../'], + ['foo/../README.txt' => 'hello'] ); } public function testGuessBaseDir_normal() { $this->_doGuessBaseDir('author-com.example.foo-random', - array('author-com.example.foo-random'), - array('author-com.example.foo-random/README.txt' => 'hello'), + ['author-com.example.foo-random'], + ['author-com.example.foo-random/README.txt' => 'hello'], 'com.example.foo' ); } public function testGuessBaseDir_MACOSX() { $this->_doGuessBaseDir('com.example.foo', - array('com.example.foo', '__MACOSX'), - array('author-com.example.foo-random/README.txt' => 'hello', '__MACOSX/foo' => 'bar'), + ['com.example.foo', '__MACOSX'], + ['author-com.example.foo-random/README.txt' => 'hello', '__MACOSX/foo' => 'bar'], 'com.example.foo' ); } public function testGuessBaseDir_0() { $this->_doGuessBaseDir('0', - array('0'), - array(), + ['0'], + [], 'com.example.foo' ); } public function testGuessBaseDir_plainfile() { $this->_doGuessBaseDir(FALSE, - array(), - array('README.txt' => 'hello'), + [], + ['README.txt' => 'hello'], 'com.example.foo' ); } public function testGuessBaseDirTwoDir() { $this->_doGuessBaseDir(FALSE, - array('dir-1', 'dir-2'), - array('dir-1/README.txt' => 'hello'), + ['dir-1', 'dir-2'], + ['dir-1/README.txt' => 'hello'], 'com.example.foo' ); } public function testGuessBaseDirWeird() { $this->_doGuessBaseDir(FALSE, - array('foo/../'), - array('foo/../README.txt' => 'hello'), + ['foo/../'], + ['foo/../README.txt' => 'hello'], 'com.example.foo' ); } diff --git a/tests/phpunit/CRM/Utils/versionCheckTest.php b/tests/phpunit/CRM/Utils/versionCheckTest.php index 70096389ee..e747d49d4e 100644 --- a/tests/phpunit/CRM/Utils/versionCheckTest.php +++ b/tests/phpunit/CRM/Utils/versionCheckTest.php @@ -13,81 +13,81 @@ class CRM_Utils_versionCheckTest extends CiviUnitTestCase { /** * @var array */ - protected $sampleVersionInfo = array( - '4.2' => array( + protected $sampleVersionInfo = [ + '4.2' => [ 'status' => 'eol', - 'releases' => array( - array('version' => '4.2.0', 'date' => '2012-08-20'), - array('version' => '4.2.1', 'date' => '2012-09-12'), - array('version' => '4.2.2', 'date' => '2012-09-27'), - array('version' => '4.2.4', 'date' => '2012-10-18'), - array('version' => '4.2.6', 'date' => '2012-11-01', 'security' => TRUE), - array('version' => '4.2.7', 'date' => '2013-01-02', 'security' => TRUE), - array('version' => '4.2.8', 'date' => '2013-02-20'), - array('version' => '4.2.9', 'date' => '2013-04-03'), - array('version' => '4.2.10', 'date' => '2013-07-29', 'security' => TRUE), - array('version' => '4.2.11', 'date' => '2013-09-25'), - array('version' => '4.2.12', 'date' => '2013-10-02', 'security' => TRUE), - array('version' => '4.2.13', 'date' => '2013-11-06', 'security' => TRUE), - array('version' => '4.2.14', 'date' => '2013-11-20'), - array('version' => '4.2.15', 'date' => '2014-02-07', 'security' => TRUE), - array('version' => '4.2.16', 'date' => '2014-02-18'), - array('version' => '4.2.17', 'date' => '2014-07-01', 'security' => TRUE), - array('version' => '4.2.18', 'date' => '2014-08-06'), - array('version' => '4.2.19', 'date' => '2014-09-17', 'security' => TRUE), - ), - ), - '4.3' => array( + 'releases' => [ + ['version' => '4.2.0', 'date' => '2012-08-20'], + ['version' => '4.2.1', 'date' => '2012-09-12'], + ['version' => '4.2.2', 'date' => '2012-09-27'], + ['version' => '4.2.4', 'date' => '2012-10-18'], + ['version' => '4.2.6', 'date' => '2012-11-01', 'security' => TRUE], + ['version' => '4.2.7', 'date' => '2013-01-02', 'security' => TRUE], + ['version' => '4.2.8', 'date' => '2013-02-20'], + ['version' => '4.2.9', 'date' => '2013-04-03'], + ['version' => '4.2.10', 'date' => '2013-07-29', 'security' => TRUE], + ['version' => '4.2.11', 'date' => '2013-09-25'], + ['version' => '4.2.12', 'date' => '2013-10-02', 'security' => TRUE], + ['version' => '4.2.13', 'date' => '2013-11-06', 'security' => TRUE], + ['version' => '4.2.14', 'date' => '2013-11-20'], + ['version' => '4.2.15', 'date' => '2014-02-07', 'security' => TRUE], + ['version' => '4.2.16', 'date' => '2014-02-18'], + ['version' => '4.2.17', 'date' => '2014-07-01', 'security' => TRUE], + ['version' => '4.2.18', 'date' => '2014-08-06'], + ['version' => '4.2.19', 'date' => '2014-09-17', 'security' => TRUE], + ], + ], + '4.3' => [ 'status' => 'lts', - 'releases' => array( - array('version' => '4.3.0', 'date' => '2013-04-10'), - array('version' => '4.3.1', 'date' => '2013-04-18'), - array('version' => '4.3.2', 'date' => '2013-05-02'), - array('version' => '4.3.3', 'date' => '2013-05-08'), - array('version' => '4.3.4', 'date' => '2013-06-10', 'security' => TRUE), - array('version' => '4.3.5', 'date' => '2013-07-08', 'security' => TRUE), - array('version' => '4.3.6', 'date' => '2013-09-25'), - array('version' => '4.3.7', 'date' => '2013-10-02', 'security' => TRUE), - array('version' => '4.3.8', 'date' => '2013-11-06', 'security' => TRUE), - array('version' => '4.3.9', 'date' => '2014-09-07', 'security' => TRUE), - ), - ), - '4.4' => array( + 'releases' => [ + ['version' => '4.3.0', 'date' => '2013-04-10'], + ['version' => '4.3.1', 'date' => '2013-04-18'], + ['version' => '4.3.2', 'date' => '2013-05-02'], + ['version' => '4.3.3', 'date' => '2013-05-08'], + ['version' => '4.3.4', 'date' => '2013-06-10', 'security' => TRUE], + ['version' => '4.3.5', 'date' => '2013-07-08', 'security' => TRUE], + ['version' => '4.3.6', 'date' => '2013-09-25'], + ['version' => '4.3.7', 'date' => '2013-10-02', 'security' => TRUE], + ['version' => '4.3.8', 'date' => '2013-11-06', 'security' => TRUE], + ['version' => '4.3.9', 'date' => '2014-09-07', 'security' => TRUE], + ], + ], + '4.4' => [ 'status' => 'lts', - 'releases' => array( - array('version' => '4.4.0', 'date' => '2013-10-23'), - array('version' => '4.4.1', 'date' => '2013-11-06', 'security' => TRUE), - array('version' => '4.4.2', 'date' => '2013-11-20'), - array('version' => '4.4.3', 'date' => '2013-12-05'), - array('version' => '4.4.4', 'date' => '2014-02-07', 'security' => TRUE), - array('version' => '4.4.5', 'date' => '2014-04-17'), - array('version' => '4.4.6', 'date' => '2014-07-01', 'security' => TRUE), - array('version' => '4.4.7', 'date' => '2014-09-17', 'security' => TRUE), - array('version' => '4.4.8', 'date' => '2014-10-14'), - array('version' => '4.4.9', 'date' => '2014-11-05'), - array('version' => '4.4.10', 'date' => '2014-11-19'), - array('version' => '4.4.11', 'date' => '2014-12-17', 'security' => TRUE), - ), - ), - '4.5' => array( + 'releases' => [ + ['version' => '4.4.0', 'date' => '2013-10-23'], + ['version' => '4.4.1', 'date' => '2013-11-06', 'security' => TRUE], + ['version' => '4.4.2', 'date' => '2013-11-20'], + ['version' => '4.4.3', 'date' => '2013-12-05'], + ['version' => '4.4.4', 'date' => '2014-02-07', 'security' => TRUE], + ['version' => '4.4.5', 'date' => '2014-04-17'], + ['version' => '4.4.6', 'date' => '2014-07-01', 'security' => TRUE], + ['version' => '4.4.7', 'date' => '2014-09-17', 'security' => TRUE], + ['version' => '4.4.8', 'date' => '2014-10-14'], + ['version' => '4.4.9', 'date' => '2014-11-05'], + ['version' => '4.4.10', 'date' => '2014-11-19'], + ['version' => '4.4.11', 'date' => '2014-12-17', 'security' => TRUE], + ], + ], + '4.5' => [ 'status' => 'stable', - 'releases' => array( - array('version' => '4.5.0', 'date' => '2014-09-18'), - array('version' => '4.5.1', 'date' => '2014-10-09'), - array('version' => '4.5.2', 'date' => '2014-10-14'), - array('version' => '4.5.3', 'date' => '2014-11-05'), - array('version' => '4.5.4', 'date' => '2014-11-19'), - array('version' => '4.5.5', 'date' => '2014-12-17', 'security' => TRUE), - ), - ), - '4.6' => array( + 'releases' => [ + ['version' => '4.5.0', 'date' => '2014-09-18'], + ['version' => '4.5.1', 'date' => '2014-10-09'], + ['version' => '4.5.2', 'date' => '2014-10-14'], + ['version' => '4.5.3', 'date' => '2014-11-05'], + ['version' => '4.5.4', 'date' => '2014-11-19'], + ['version' => '4.5.5', 'date' => '2014-12-17', 'security' => TRUE], + ], + ], + '4.6' => [ 'status' => 'testing', - 'releases' => array( - array('version' => '4.6.alpha1', 'date' => '2015-02-01'), - array('version' => '4.6.beta1', 'date' => '2015-03-01'), - ), - ), - ); + 'releases' => [ + ['version' => '4.6.alpha1', 'date' => '2015-02-01'], + ['version' => '4.6.beta1', 'date' => '2015-03-01'], + ], + ], + ]; public function tearDown() { parent::tearDown(); @@ -114,7 +114,7 @@ class CRM_Utils_versionCheckTest extends CiviUnitTestCase { unset($vc); // Update "remote" source data - $remoteData = array('4.3' => $this->sampleVersionInfo['4.3']); + $remoteData = ['4.3' => $this->sampleVersionInfo['4.3']]; file_put_contents($tmpSrc, json_encode($remoteData)); // Cache was just updated, so fallback should not happen - assert we are still using cached data @@ -136,21 +136,21 @@ class CRM_Utils_versionCheckTest extends CiviUnitTestCase { public function testGetSiteStats() { // Create domain address so the domain country will come up in the stats. - $country_params = array( + $country_params = [ 'sequential' => 1, - 'options' => array( + 'options' => [ 'limit' => 1, - ), - ); + ], + ]; $country_result = civicrm_api3('country', 'get', $country_params); $country = $country_result['values'][0]; - $domain_params = array( + $domain_params = [ 'id' => CRM_Core_Config::domainID(), - ); + ]; CRM_Core_BAO_Domain::retrieve($domain_params, $domain_defaults); $location_type = CRM_Core_BAO_LocationType::getDefault(); - $address_params = array( + $address_params = [ 'contact_id' => $domain_defaults['contact_id'], 'location_type_id' => $location_type->id, 'is_primary' => '1', @@ -159,7 +159,7 @@ class CRM_Utils_versionCheckTest extends CiviUnitTestCase { 'city' => 'Anywhere', 'postal_code' => '99999', 'country_id' => $country['id'], - ); + ]; $address_result = civicrm_api3('address', 'create', $address_params); // Build stats and test them. @@ -198,13 +198,13 @@ class CRM_Utils_versionCheckTest extends CiviUnitTestCase { // Assert $stats['domain_isoCode'] is correct. $this->assertEquals($country['iso_code'], $stats['domain_isoCode']); - $entity_names = array(); + $entity_names = []; foreach ($stats['entities'] as $entity) { $entity_names[] = $entity['name']; $this->assertType('int', $entity['size'], "Stats entity {$entity['name']} has integer size?"); } - $expected_entity_names = array( + $expected_entity_names = [ 'Activity', 'Case', 'Contact', @@ -227,7 +227,7 @@ class CRM_Utils_versionCheckTest extends CiviUnitTestCase { 'Pledge', 'PledgeBlock', 'Delivered', - ); + ]; sort($entity_names); sort($expected_entity_names); $this->assertEquals($expected_entity_names, $entity_names); diff --git a/tests/phpunit/Civi/API/KernelTest.php b/tests/phpunit/Civi/API/KernelTest.php index 995c26dc17..0dca67834a 100644 --- a/tests/phpunit/Civi/API/KernelTest.php +++ b/tests/phpunit/Civi/API/KernelTest.php @@ -25,7 +25,7 @@ class KernelTest extends \CiviUnitTestCase { protected function setUp() { parent::setUp(); - $this->actualEventSequence = array(); + $this->actualEventSequence = []; $this->dispatcher = new EventDispatcher(); $this->monitorEvents(Events::allEvents()); $this->kernel = new Kernel($this->dispatcher); @@ -33,16 +33,16 @@ class KernelTest extends \CiviUnitTestCase { public function testNormalEvents() { $this->kernel->registerApiProvider($this->createWidgetFrobnicateProvider()); - $result = $this->kernel->run('Widget', 'frobnicate', array( + $result = $this->kernel->run('Widget', 'frobnicate', [ 'version' => self::MOCK_VERSION, - )); + ]); - $expectedEventSequence = array( - array('name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'), - array('name' => Events::AUTHORIZE, 'class' => 'Civi\API\Event\AuthorizeEvent'), - array('name' => Events::PREPARE, 'class' => 'Civi\API\Event\PrepareEvent'), - array('name' => Events::RESPOND, 'class' => 'Civi\API\Event\RespondEvent'), - ); + $expectedEventSequence = [ + ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'], + ['name' => Events::AUTHORIZE, 'class' => 'Civi\API\Event\AuthorizeEvent'], + ['name' => Events::PREPARE, 'class' => 'Civi\API\Event\PrepareEvent'], + ['name' => Events::RESPOND, 'class' => 'Civi\API\Event\RespondEvent'], + ]; $this->assertEquals($expectedEventSequence, $this->actualEventSequence); $this->assertEquals('frob', $result['values'][98]); } @@ -50,21 +50,21 @@ class KernelTest extends \CiviUnitTestCase { public function testResolveException() { $test = $this; $this->dispatcher->addListener(Events::RESOLVE, function () { - throw new \API_Exception('Oh My God', 'omg', array('the' => 'badzes')); + throw new \API_Exception('Oh My God', 'omg', ['the' => 'badzes']); }, Events::W_EARLY); $this->dispatcher->addListener(Events::EXCEPTION, function (\Civi\API\Event\ExceptionEvent $event) use ($test) { $test->assertEquals('Oh My God', $event->getException()->getMessage()); }); $this->kernel->registerApiProvider($this->createWidgetFrobnicateProvider()); - $result = $this->kernel->run('Widget', 'frobnicate', array( + $result = $this->kernel->run('Widget', 'frobnicate', [ 'version' => self::MOCK_VERSION, - )); + ]); - $expectedEventSequence = array( - array('name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'), - array('name' => Events::EXCEPTION, 'class' => 'Civi\API\Event\ExceptionEvent'), - ); + $expectedEventSequence = [ + ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'], + ['name' => Events::EXCEPTION, 'class' => 'Civi\API\Event\ExceptionEvent'], + ]; $this->assertEquals($expectedEventSequence, $this->actualEventSequence); $this->assertEquals('Oh My God', $result['error_message']); $this->assertEquals('omg', $result['error_code']); @@ -81,7 +81,7 @@ class KernelTest extends \CiviUnitTestCase { public function createWidgetFrobnicateProvider() { $provider = new \Civi\API\Provider\AdhocProvider(self::MOCK_VERSION, 'Widget'); $provider->addAction('frobnicate', 'access CiviCRM', function ($apiRequest) { - return civicrm_api3_create_success(array(98 => 'frob')); + return civicrm_api3_create_success([98 => 'frob']); }); return $provider; } @@ -98,10 +98,10 @@ class KernelTest extends \CiviUnitTestCase { foreach ($monitoredEvents as $monitoredEvent) { $test = $this; $this->dispatcher->addListener($monitoredEvent, function ($event) use ($monitoredEvent, &$test) { - $test->actualEventSequence[] = array( + $test->actualEventSequence[] = [ 'name' => $monitoredEvent, 'class' => get_class($event), - ); + ]; }, 2 * Events::W_EARLY); } } diff --git a/tests/phpunit/Civi/API/RequestTest.php b/tests/phpunit/Civi/API/RequestTest.php index 24e5c616b5..be0e6821c9 100644 --- a/tests/phpunit/Civi/API/RequestTest.php +++ b/tests/phpunit/Civi/API/RequestTest.php @@ -9,23 +9,23 @@ class RequestTest extends \CiviUnitTestCase { * @return array */ public function validEntityActionPairs() { - $cases = array(); - $cases[] = array( - array('MyEntity', 'MyAction', 3), - array('MyEntity', 'myaction', 3), - ); - $cases[] = array( - array('my+entity', 'MyAction', 3), - array('MyEntity', 'myaction', 3), - ); - $cases[] = array( - array('my entity with under_scores', 'My_Action', 3), - array('MyEntityWithUnderScores', 'my_action', 3), - ); - $cases[] = array( - array('u_f_match', 'get Something', 3), - array('UFMatch', 'get_something', 3), - ); + $cases = []; + $cases[] = [ + ['MyEntity', 'MyAction', 3], + ['MyEntity', 'myaction', 3], + ]; + $cases[] = [ + ['my+entity', 'MyAction', 3], + ['MyEntity', 'myaction', 3], + ]; + $cases[] = [ + ['my entity with under_scores', 'My_Action', 3], + ['MyEntityWithUnderScores', 'my_action', 3], + ]; + $cases[] = [ + ['u_f_match', 'get Something', 3], + ['UFMatch', 'get_something', 3], + ]; return $cases; } @@ -37,22 +37,22 @@ class RequestTest extends \CiviUnitTestCase { */ public function testCreateRequest_EntityActionMunging($input, $expected) { list ($inEntity, $inAction, $inVersion) = $input; - $apiRequest = Request::create($inEntity, $inAction, array('version' => $inVersion), NULL); - $this->assertEquals($expected, array($apiRequest['entity'], $apiRequest['action'], $apiRequest['version'])); + $apiRequest = Request::create($inEntity, $inAction, ['version' => $inVersion], NULL); + $this->assertEquals($expected, [$apiRequest['entity'], $apiRequest['action'], $apiRequest['version']]); } /** * @return array */ public function invalidEntityActionPairs() { - $cases = array(); - $cases[] = array('Not!Valid', 'create', 4); - $cases[] = array('My+Entity', 'MyAction', 4); - $cases[] = array('My Entity', 'MyAction', 4); - $cases[] = array('2MyEntity', 'MyAction', 4); - $cases[] = array('MyEntity', 'My+Action', 4); - $cases[] = array('MyEntity', 'My Action', 4); - $cases[] = array('MyEntity', '2Action', 4); + $cases = []; + $cases[] = ['Not!Valid', 'create', 4]; + $cases[] = ['My+Entity', 'MyAction', 4]; + $cases[] = ['My Entity', 'MyAction', 4]; + $cases[] = ['2MyEntity', 'MyAction', 4]; + $cases[] = ['MyEntity', 'My+Action', 4]; + $cases[] = ['MyEntity', 'My Action', 4]; + $cases[] = ['MyEntity', '2Action', 4]; return $cases; } @@ -65,7 +65,7 @@ class RequestTest extends \CiviUnitTestCase { * @throws \Civi\API\Exception\NotImplementedException */ public function testCreateRequest_InvalidEntityAction($inEntity, $inAction, $inVersion) { - Request::create($inEntity, $inAction, array('version' => $inVersion), NULL); + Request::create($inEntity, $inAction, ['version' => $inVersion], NULL); } } diff --git a/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php b/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php index 0576ddeb53..e1a4902218 100644 --- a/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php +++ b/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php @@ -35,36 +35,36 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { $fileProvider = new \Civi\API\Provider\StaticProvider( 3, 'FakeFile', - array('id', 'entity_table', 'entity_id'), - array(), - array( - array('id' => self::FILE_WIDGET_ID, 'entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID), - array('id' => self::FILE_FORBIDDEN_ID, 'entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID), - ) + ['id', 'entity_table', 'entity_id'], + [], + [ + ['id' => self::FILE_WIDGET_ID, 'entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID], + ['id' => self::FILE_FORBIDDEN_ID, 'entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID], + ] ); \CRM_Core_DAO_AllCoreTables::registerEntityType('Widget', 'CRM_Fake_DAO_Widget', 'fake_widget'); $widgetProvider = new \Civi\API\Provider\StaticProvider(3, 'Widget', - array('id', 'title'), - array(), - array( - array('id' => self::WIDGET_ID, 'title' => 'my widget'), - ) + ['id', 'title'], + [], + [ + ['id' => self::WIDGET_ID, 'title' => 'my widget'], + ] ); \CRM_Core_DAO_AllCoreTables::registerEntityType('Forbidden', 'CRM_Fake_DAO_Forbidden', 'fake_forbidden'); $forbiddenProvider = new \Civi\API\Provider\StaticProvider( 3, 'Forbidden', - array('id', 'label'), - array( + ['id', 'label'], + [ 'create' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION, 'get' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION, 'delete' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION, - ), - array( - array('id' => self::FORBIDDEN_ID, 'label' => 'my forbidden'), - ) + ], + [ + ['id' => self::FORBIDDEN_ID, 'label' => 'my forbidden'], + ] ); $this->dispatcher = new EventDispatcher(); @@ -76,7 +76,7 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { $this->dispatcher->addSubscriber(new DynamicFKAuthorization( $this->kernel, 'FakeFile', - array('create', 'get'), + ['create', 'get'], // Given a file ID, determine the entity+table it's attached to. "select case %1 @@ -97,7 +97,7 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { ", // Get a list of custom fields (field_name,table_name,extends) "select", - array('fake_widget', 'fake_forbidden') + ['fake_widget', 'fake_forbidden'] )); } @@ -110,18 +110,18 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { * @return array */ public function okDataProvider() { - $cases = array(); + $cases = []; - $cases[] = array('Widget', 'create', array('id' => self::WIDGET_ID)); - $cases[] = array('Widget', 'get', array('id' => self::WIDGET_ID)); + $cases[] = ['Widget', 'create', ['id' => self::WIDGET_ID]]; + $cases[] = ['Widget', 'get', ['id' => self::WIDGET_ID]]; - $cases[] = array('FakeFile', 'create', array('id' => self::FILE_WIDGET_ID)); - $cases[] = array('FakeFile', 'get', array('id' => self::FILE_WIDGET_ID)); - $cases[] = array( + $cases[] = ['FakeFile', 'create', ['id' => self::FILE_WIDGET_ID]]; + $cases[] = ['FakeFile', 'get', ['id' => self::FILE_WIDGET_ID]]; + $cases[] = [ 'FakeFile', 'create', - array('entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID), - ); + ['entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID], + ]; return $cases; } @@ -130,48 +130,48 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { * @return array */ public function badDataProvider() { - $cases = array(); + $cases = []; - $cases[] = array('Forbidden', 'create', array('id' => self::FORBIDDEN_ID), '/Authorization failed/'); - $cases[] = array('Forbidden', 'get', array('id' => self::FORBIDDEN_ID), '/Authorization failed/'); + $cases[] = ['Forbidden', 'create', ['id' => self::FORBIDDEN_ID], '/Authorization failed/']; + $cases[] = ['Forbidden', 'get', ['id' => self::FORBIDDEN_ID], '/Authorization failed/']; - $cases[] = array('FakeFile', 'create', array('id' => self::FILE_FORBIDDEN_ID), '/Authorization failed/'); - $cases[] = array('FakeFile', 'get', array('id' => self::FILE_FORBIDDEN_ID), '/Authorization failed/'); + $cases[] = ['FakeFile', 'create', ['id' => self::FILE_FORBIDDEN_ID], '/Authorization failed/']; + $cases[] = ['FakeFile', 'get', ['id' => self::FILE_FORBIDDEN_ID], '/Authorization failed/']; - $cases[] = array('FakeFile', 'create', array('entity_table' => 'fake_forbidden'), '/Authorization failed/'); - $cases[] = array('FakeFile', 'get', array('entity_table' => 'fake_forbidden'), '/Authorization failed/'); + $cases[] = ['FakeFile', 'create', ['entity_table' => 'fake_forbidden'], '/Authorization failed/']; + $cases[] = ['FakeFile', 'get', ['entity_table' => 'fake_forbidden'], '/Authorization failed/']; - $cases[] = array( + $cases[] = [ 'FakeFile', 'create', - array('entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID), + ['entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID], '/Authorization failed/', - ); - $cases[] = array( + ]; + $cases[] = [ 'FakeFile', 'get', - array('entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID), + ['entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID], '/Authorization failed/', - ); + ]; - $cases[] = array( + $cases[] = [ 'FakeFile', 'create', - array(), + [], "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table/", - ); - $cases[] = array( + ]; + $cases[] = [ 'FakeFile', 'get', - array(), + [], "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table/", - ); + ]; - $cases[] = array('FakeFile', 'create', array('entity_table' => 'unknown'), '/Unrecognized target entity/'); - $cases[] = array('FakeFile', 'get', array('entity_table' => 'unknown'), '/Unrecognized target entity/'); + $cases[] = ['FakeFile', 'create', ['entity_table' => 'unknown'], '/Unrecognized target entity/']; + $cases[] = ['FakeFile', 'get', ['entity_table' => 'unknown'], '/Unrecognized target entity/']; // We should be allowed to lookup files for fake_widgets, but we need an ID. - $cases[] = array('FakeFile', 'get', array('entity_table' => 'fake_widget'), '/Missing entity_id/'); + $cases[] = ['FakeFile', 'get', ['entity_table' => 'fake_widget'], '/Missing entity_id/']; return $cases; } @@ -187,12 +187,12 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { $params['debug'] = 1; $params['check_permissions'] = 1; $result = $this->kernel->run($entity, $action, $params); - $this->assertFalse((bool) $result['is_error'], print_r(array( + $this->assertFalse((bool) $result['is_error'], print_r([ '$entity' => $entity, '$action' => $action, '$params' => $params, '$result' => $result, - ), TRUE)); + ], TRUE)); } /** @@ -207,12 +207,12 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { $params['debug'] = 1; $params['check_permissions'] = 1; $result = $this->kernel->run($entity, $action, $params); - $this->assertTrue((bool) $result['is_error'], print_r(array( + $this->assertTrue((bool) $result['is_error'], print_r([ '$entity' => $entity, '$action' => $action, '$params' => $params, '$result' => $result, - ), TRUE)); + ], TRUE)); $this->assertRegExp($expectedError, $result['error_message']); } diff --git a/tests/phpunit/Civi/API/Subscriber/TransactionSubscriberTest.php b/tests/phpunit/Civi/API/Subscriber/TransactionSubscriberTest.php index 9ac2e23476..46d30d7f92 100644 --- a/tests/phpunit/Civi/API/Subscriber/TransactionSubscriberTest.php +++ b/tests/phpunit/Civi/API/Subscriber/TransactionSubscriberTest.php @@ -11,61 +11,61 @@ class TransactionSubscriberTest extends \CiviUnitTestCase { * @return array */ public function transactionOptions() { - $r = array(); + $r = []; // $r[] = array(string $entity, string $action, array $params, bool $isTransactional, bool $isForceRollback, bool $isNested); - $r[] = array(3, 'Widget', 'get', array(), FALSE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'create', array(), TRUE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'delete', array(), TRUE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'submit', array(), TRUE, FALSE, FALSE); + $r[] = [3, 'Widget', 'get', [], FALSE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'create', [], TRUE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'delete', [], TRUE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'submit', [], TRUE, FALSE, FALSE]; - $r[] = array(3, 'Widget', 'get', array('is_transactional' => TRUE), TRUE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'get', array('is_transactional' => FALSE), FALSE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'get', array('is_transactional' => 'nest'), TRUE, FALSE, TRUE); + $r[] = [3, 'Widget', 'get', ['is_transactional' => TRUE], TRUE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'get', ['is_transactional' => FALSE], FALSE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'get', ['is_transactional' => 'nest'], TRUE, FALSE, TRUE]; - $r[] = array(3, 'Widget', 'create', array('is_transactional' => TRUE), TRUE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'create', array('is_transactional' => FALSE), FALSE, FALSE, FALSE); - $r[] = array(3, 'Widget', 'create', array('is_transactional' => 'nest'), TRUE, FALSE, TRUE); + $r[] = [3, 'Widget', 'create', ['is_transactional' => TRUE], TRUE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'create', ['is_transactional' => FALSE], FALSE, FALSE, FALSE]; + $r[] = [3, 'Widget', 'create', ['is_transactional' => 'nest'], TRUE, FALSE, TRUE]; - $r[] = array(3, 'Widget', 'create', array('options' => array('force_rollback' => TRUE)), TRUE, TRUE, TRUE); - $r[] = array(3, 'Widget', 'create', array('options' => array('force_rollback' => FALSE)), TRUE, FALSE, FALSE); + $r[] = [3, 'Widget', 'create', ['options' => ['force_rollback' => TRUE]], TRUE, TRUE, TRUE]; + $r[] = [3, 'Widget', 'create', ['options' => ['force_rollback' => FALSE]], TRUE, FALSE, FALSE]; - $r[] = array( + $r[] = [ 3, 'Widget', 'create', - array('is_transactional' => TRUE, 'options' => array('force_rollback' => TRUE)), + ['is_transactional' => TRUE, 'options' => ['force_rollback' => TRUE]], TRUE, TRUE, TRUE, - ); - $r[] = array( + ]; + $r[] = [ 3, 'Widget', 'create', - array('is_transactional' => TRUE, 'options' => array('force_rollback' => FALSE)), + ['is_transactional' => TRUE, 'options' => ['force_rollback' => FALSE]], TRUE, FALSE, FALSE, - ); - $r[] = array( + ]; + $r[] = [ 3, 'Widget', 'create', - array('is_transactional' => FALSE, 'options' => array('force_rollback' => TRUE)), + ['is_transactional' => FALSE, 'options' => ['force_rollback' => TRUE]], TRUE, TRUE, TRUE, - ); - $r[] = array( + ]; + $r[] = [ 3, 'Widget', 'create', - array('is_transactional' => FALSE, 'options' => array('force_rollback' => FALSE)), + ['is_transactional' => FALSE, 'options' => ['force_rollback' => FALSE]], FALSE, FALSE, FALSE, - ); + ]; // $r[] = array(4, 'Widget', 'get', array(), FALSE, FALSE, FALSE); // $r[] = array(4, 'Widget', 'create', array(), TRUE, FALSE, FALSE); @@ -100,7 +100,7 @@ class TransactionSubscriberTest extends \CiviUnitTestCase { $apiProvider = NULL; $params['version'] = $version; - $apiRequest = \Civi\API\Request::create($entity, $action, $params, array()); + $apiRequest = \Civi\API\Request::create($entity, $action, $params, []); $this->assertEquals($isTransactional, $txs->isTransactional($apiProvider, $apiRequest), 'check isTransactional'); $this->assertEquals($isForceRollback, $txs->isForceRollback($apiProvider, $apiRequest), 'check isForceRollback'); @@ -108,18 +108,18 @@ class TransactionSubscriberTest extends \CiviUnitTestCase { } public function testForceRollback() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Me', 'last_name' => 'Myself', - 'options' => array( + 'options' => [ 'force_rollback' => TRUE, - ), - )); + ], + ]); $this->assertTrue(is_numeric($result['id'])); - $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', array( - 1 => array($result['id'], 'Integer'), - )); + $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', [ + 1 => [$result['id'], 'Integer'], + ]); } } diff --git a/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php b/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php index 4e4db9ce05..7340775286 100644 --- a/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php +++ b/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php @@ -25,316 +25,316 @@ use Symfony\Component\EventDispatcher\EventDispatcher; class WhitelistSubscriberTest extends \CiviUnitTestCase { protected function getFixtures() { - $recs = array(); + $recs = []; - $recs['widget'] = array( - 1 => array( + $recs['widget'] = [ + 1 => [ 'id' => 1, 'widget_type' => 'foo', 'provider' => 'george jetson', 'title' => 'first widget', 'comments' => 'this widget is the bomb', - ), - 2 => array( + ], + 2 => [ 'id' => 2, 'widget_type' => 'bar', 'provider' => 'george jetson', 'title' => 'second widget', 'comments' => 'this widget is a bomb', - ), - 3 => array( + ], + 3 => [ 'id' => 3, 'widget_type' => 'foo', 'provider' => 'cosmo spacely', 'title' => 'third widget', 'comments' => 'omg, that thing is a bomb! widgets are bombs! get out!', - ), - 8 => array( + ], + 8 => [ 'id' => 8, 'widget_type' => 'bax', 'provider' => 'cosmo spacely', 'title' => 'fourth widget', 'comments' => 'todo: rebuild garage', - ), - ); + ], + ]; - $recs['sprocket'] = array( - 1 => array( + $recs['sprocket'] = [ + 1 => [ 'id' => 1, 'sprocket_type' => 'whiz', 'provider' => 'cosmo spacely', 'title' => 'first sprocket', 'comment' => 'this sprocket is so good i could eat it up', 'widget_id' => 2, - ), - 5 => array( + ], + 5 => [ 'id' => 5, 'sprocket_type' => 'bang', 'provider' => 'george jetson', 'title' => 'second sprocket', 'comment' => 'this green sprocket was made by soylent', 'widget_id' => 2, - ), - 7 => array( + ], + 7 => [ 'id' => 7, 'sprocket_type' => 'quux', 'provider' => 'cosmo spacely', 'title' => 'third sprocket', 'comment' => 'sprocket green is people! sprocket green is people!', 'widget_id' => 3, - ), - 8 => array( + ], + 8 => [ 'id' => 8, 'sprocket_type' => 'baz', 'provider' => 'george jetson', 'title' => 'fourth sprocket', 'comment' => 'see also: cooking.com/hannibal/1981420-sprocket-fava', 'widget_id' => 3, - ), - ); + ], + ]; return $recs; } public function restrictionCases() { - $calls = $rules = array(); + $calls = $rules = []; $recs = $this->getFixtures(); - $calls['Widget.get-all'] = array( + $calls['Widget.get-all'] = [ 'entity' => 'Widget', 'action' => 'get', - 'params' => array('version' => 3), + 'params' => ['version' => 3], 'expectedResults' => $recs['widget'], - ); - $calls['Widget.get-foo'] = array( + ]; + $calls['Widget.get-foo'] = [ 'entity' => 'Widget', 'action' => 'get', - 'params' => array('version' => 3, 'widget_type' => 'foo'), - 'expectedResults' => array(1 => $recs['widget'][1], 3 => $recs['widget'][3]), - ); - $calls['Widget.get-spacely'] = array( + 'params' => ['version' => 3, 'widget_type' => 'foo'], + 'expectedResults' => [1 => $recs['widget'][1], 3 => $recs['widget'][3]], + ]; + $calls['Widget.get-spacely'] = [ 'entity' => 'Widget', 'action' => 'get', - 'params' => array('version' => 3, 'provider' => 'cosmo spacely'), - 'expectedResults' => array(3 => $recs['widget'][3], 8 => $recs['widget'][8]), - ); - $calls['Widget.get-spacely=>title'] = array( + 'params' => ['version' => 3, 'provider' => 'cosmo spacely'], + 'expectedResults' => [3 => $recs['widget'][3], 8 => $recs['widget'][8]], + ]; + $calls['Widget.get-spacely=>title'] = [ 'entity' => 'Widget', 'action' => 'get', - 'params' => array('version' => 3, 'provider' => 'cosmo spacely', 'return' => array('title')), - 'expectedResults' => array( - 3 => array('id' => 3, 'title' => 'third widget'), - 8 => array('id' => 8, 'title' => 'fourth widget'), - ), - ); - $calls['Widget.get-spacely-foo'] = array( + 'params' => ['version' => 3, 'provider' => 'cosmo spacely', 'return' => ['title']], + 'expectedResults' => [ + 3 => ['id' => 3, 'title' => 'third widget'], + 8 => ['id' => 8, 'title' => 'fourth widget'], + ], + ]; + $calls['Widget.get-spacely-foo'] = [ 'entity' => 'Widget', 'action' => 'get', - 'params' => array('version' => 3, 'provider' => 'cosmo spacely', 'widget_type' => 'foo'), - 'expectedResults' => array(3 => $recs['widget'][3]), - ); - $calls['Sprocket.get-all'] = array( + 'params' => ['version' => 3, 'provider' => 'cosmo spacely', 'widget_type' => 'foo'], + 'expectedResults' => [3 => $recs['widget'][3]], + ]; + $calls['Sprocket.get-all'] = [ 'entity' => 'Sprocket', 'action' => 'get', - 'params' => array('version' => 3), + 'params' => ['version' => 3], 'expectedResults' => $recs['sprocket'], - ); - $calls['Widget.get-bar=>title + Sprocket.get=>provider'] = array( + ]; + $calls['Widget.get-bar=>title + Sprocket.get=>provider'] = [ 'entity' => 'Widget', 'action' => 'get', - 'params' => array( + 'params' => [ 'version' => 3, 'widget_type' => 'bar', - 'return' => array('title'), - 'api.Sprocket.get' => array( + 'return' => ['title'], + 'api.Sprocket.get' => [ 'widget_id' => '$value.id', - 'return' => array('provider'), - ), - ), - 'expectedResults' => array( - 2 => array( + 'return' => ['provider'], + ], + ], + 'expectedResults' => [ + 2 => [ 'id' => 2, 'title' => 'second widget', - 'api.Sprocket.get' => array( + 'api.Sprocket.get' => [ 'is_error' => 0, 'count' => 2, 'version' => 3, - 'values' => array( - 0 => array('id' => 1, 'provider' => 'cosmo spacely'), - 1 => array('id' => 5, 'provider' => 'george jetson'), - ), + 'values' => [ + 0 => ['id' => 1, 'provider' => 'cosmo spacely'], + 1 => ['id' => 5, 'provider' => 'george jetson'], + ], // This is silly: - 'undefined_fields' => array('entity_id', 'entity_table', 'widget_id', 'api.has_parent'), - ), - ), - ), - ); + 'undefined_fields' => ['entity_id', 'entity_table', 'widget_id', 'api.has_parent'], + ], + ], + ], + ]; - $rules['*.*'] = array( + $rules['*.*'] = [ 'version' => 3, 'entity' => '*', 'actions' => '*', - 'required' => array(), + 'required' => [], 'fields' => '*', - ); - $rules['Widget.*'] = array( + ]; + $rules['Widget.*'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => '*', - 'required' => array(), + 'required' => [], 'fields' => '*', - ); - $rules['Sprocket.*'] = array( + ]; + $rules['Sprocket.*'] = [ 'version' => 3, 'entity' => 'Sprocket', 'actions' => '*', - 'required' => array(), + 'required' => [], 'fields' => '*', - ); - $rules['Widget.get'] = array( + ]; + $rules['Widget.get'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'get', - 'required' => array(), + 'required' => [], 'fields' => '*', - ); - $rules['Sprocket.get'] = array( + ]; + $rules['Sprocket.get'] = [ 'version' => 3, 'entity' => 'Sprocket', 'actions' => 'get', - 'required' => array(), + 'required' => [], 'fields' => '*', - ); - $rules['Sprocket.get=>title,misc'] = array( + ]; + $rules['Sprocket.get=>title,misc'] = [ 'version' => 3, 'entity' => 'Sprocket', 'actions' => 'get', - 'required' => array(), + 'required' => [], // To call api.Sprocket.get via chaining, you must accept superfluous fields. // It would be a mistake for the whitelist mechanism to approve these // automatically, so instead we have to enumerate them. Ideally, ChainSubscriber // wouldn't generate superfluous fields. - 'fields' => array('id', 'title', 'widget_id', 'entity_id', 'entity_table'), - ); - $rules['Sprocket.get=>provider,misc'] = array( + 'fields' => ['id', 'title', 'widget_id', 'entity_id', 'entity_table'], + ]; + $rules['Sprocket.get=>provider,misc'] = [ 'version' => 3, 'entity' => 'Sprocket', 'actions' => 'get', - 'required' => array(), + 'required' => [], // To call api.Sprocket.get via chaining, you must accept superfluous fields. // It would be a mistake for the whitelist mechanism to approve these // automatically, so instead we have to enumerate them. Ideally, ChainSubscriber // wouldn't generate superfluous fields. - 'fields' => array('id', 'provider', 'widget_id', 'entity_id', 'entity_table'), - ); - $rules['Widget.get-foo'] = array( + 'fields' => ['id', 'provider', 'widget_id', 'entity_id', 'entity_table'], + ]; + $rules['Widget.get-foo'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'get', - 'required' => array('widget_type' => 'foo'), + 'required' => ['widget_type' => 'foo'], 'fields' => '*', - ); - $rules['Widget.get-spacely'] = array( + ]; + $rules['Widget.get-spacely'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'get', - 'required' => array('provider' => 'cosmo spacely'), + 'required' => ['provider' => 'cosmo spacely'], 'fields' => '*', - ); - $rules['Widget.get-bar=>title'] = array( + ]; + $rules['Widget.get-bar=>title'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'get', - 'required' => array('widget_type' => 'bar'), - 'fields' => array('id', 'title'), - ); - $rules['Widget.get-spacely=>title'] = array( + 'required' => ['widget_type' => 'bar'], + 'fields' => ['id', 'title'], + ]; + $rules['Widget.get-spacely=>title'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'get', - 'required' => array('provider' => 'cosmo spacely'), - 'fields' => array('id', 'title'), - ); - $rules['Widget.get-spacely=>widget_type'] = array( + 'required' => ['provider' => 'cosmo spacely'], + 'fields' => ['id', 'title'], + ]; + $rules['Widget.get-spacely=>widget_type'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'get', - 'required' => array('provider' => 'cosmo spacely'), - 'fields' => array('id', 'widget_type'), - ); - $rules['Widget.getcreate'] = array( + 'required' => ['provider' => 'cosmo spacely'], + 'fields' => ['id', 'widget_type'], + ]; + $rules['Widget.getcreate'] = [ 'version' => 3, 'entity' => 'Widget', - 'actions' => array('get', 'create'), - 'required' => array(), + 'actions' => ['get', 'create'], + 'required' => [], 'fields' => '*', - ); - $rules['Widget.create'] = array( + ]; + $rules['Widget.create'] = [ 'version' => 3, 'entity' => 'Widget', 'actions' => 'create', - 'required' => array(), + 'required' => [], 'fields' => '*', - ); + ]; - $c = array(); + $c = []; - $c[] = array($calls['Widget.get-all'], array($rules['*.*']), TRUE); - $c[] = array($calls['Widget.get-all'], array($rules['Widget.*']), TRUE); - $c[] = array($calls['Widget.get-all'], array($rules['Widget.get']), TRUE); - $c[] = array($calls['Widget.get-all'], array($rules['Widget.create']), FALSE); - $c[] = array($calls['Widget.get-all'], array($rules['Widget.getcreate']), TRUE); - $c[] = array($calls['Widget.get-all'], array($rules['Sprocket.*']), FALSE); + $c[] = [$calls['Widget.get-all'], [$rules['*.*']], TRUE]; + $c[] = [$calls['Widget.get-all'], [$rules['Widget.*']], TRUE]; + $c[] = [$calls['Widget.get-all'], [$rules['Widget.get']], TRUE]; + $c[] = [$calls['Widget.get-all'], [$rules['Widget.create']], FALSE]; + $c[] = [$calls['Widget.get-all'], [$rules['Widget.getcreate']], TRUE]; + $c[] = [$calls['Widget.get-all'], [$rules['Sprocket.*']], FALSE]; - $c[] = array($calls['Sprocket.get-all'], array($rules['*.*']), TRUE); - $c[] = array($calls['Sprocket.get-all'], array($rules['Sprocket.*']), TRUE); - $c[] = array($calls['Sprocket.get-all'], array($rules['Widget.*']), FALSE); - $c[] = array($calls['Sprocket.get-all'], array($rules['Widget.get']), FALSE); + $c[] = [$calls['Sprocket.get-all'], [$rules['*.*']], TRUE]; + $c[] = [$calls['Sprocket.get-all'], [$rules['Sprocket.*']], TRUE]; + $c[] = [$calls['Sprocket.get-all'], [$rules['Widget.*']], FALSE]; + $c[] = [$calls['Sprocket.get-all'], [$rules['Widget.get']], FALSE]; - $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.*']), TRUE); - $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.get-spacely']), TRUE); - $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.get-foo']), FALSE); - $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.get-foo'], $rules['Sprocket.*']), FALSE); - $c[] = array( + $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.*']], TRUE]; + $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.get-spacely']], TRUE]; + $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.get-foo']], FALSE]; + $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.get-foo'], $rules['Sprocket.*']], FALSE]; + $c[] = [ // we do a broad get, but 'fields' filtering kicks in and restricts the results - array_merge($calls['Widget.get-spacely'], array( + array_merge($calls['Widget.get-spacely'], [ 'expectedResults' => $calls['Widget.get-spacely=>title']['expectedResults'], - )), - array($rules['Widget.get-spacely=>title']), + ]), + [$rules['Widget.get-spacely=>title']], TRUE, - ); + ]; - $c[] = array($calls['Widget.get-foo'], array($rules['Widget.*']), TRUE); - $c[] = array($calls['Widget.get-foo'], array($rules['Widget.get-foo']), TRUE); - $c[] = array($calls['Widget.get-foo'], array($rules['Widget.get-spacely']), FALSE); + $c[] = [$calls['Widget.get-foo'], [$rules['Widget.*']], TRUE]; + $c[] = [$calls['Widget.get-foo'], [$rules['Widget.get-foo']], TRUE]; + $c[] = [$calls['Widget.get-foo'], [$rules['Widget.get-spacely']], FALSE]; - $c[] = array($calls['Widget.get-spacely=>title'], array($rules['*.*']), TRUE); - $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.*']), TRUE); - $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.get-spacely']), TRUE); - $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.get-spacely=>title']), TRUE); + $c[] = [$calls['Widget.get-spacely=>title'], [$rules['*.*']], TRUE]; + $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.*']], TRUE]; + $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.get-spacely']], TRUE]; + $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.get-spacely=>title']], TRUE]; // We request returning title field, but the rule doesn't allow title to be returned. // Need it to fail so that control could pass to another rule which does allow it. - $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.get-spacely=>widget_type']), FALSE); + $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.get-spacely=>widget_type']], FALSE]; // One rule would allow, one would be irrelevant. The order of the two rules shouldn't matter. - $c[] = array( + $c[] = [ $calls['Widget.get-spacely=>title'], - array($rules['Widget.get-spacely=>widget_type'], $rules['Widget.get-spacely=>title']), + [$rules['Widget.get-spacely=>widget_type'], $rules['Widget.get-spacely=>title']], TRUE, - ); - $c[] = array( + ]; + $c[] = [ $calls['Widget.get-spacely=>title'], - array($rules['Widget.get-spacely=>title'], $rules['Widget.get-spacely=>widget_type']), + [$rules['Widget.get-spacely=>title'], $rules['Widget.get-spacely=>widget_type']], TRUE, - ); + ]; - $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['*.*']), TRUE); - $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get-bar=>title'], $rules['Sprocket.get']), TRUE); - $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get'], $rules['Sprocket.get=>title,misc']), FALSE); - $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get'], $rules['Sprocket.get=>provider,misc']), TRUE); - $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get-foo'], $rules['Sprocket.get']), FALSE); - $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get']), FALSE); + $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['*.*']], TRUE]; + $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get-bar=>title'], $rules['Sprocket.get']], TRUE]; + $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get'], $rules['Sprocket.get=>title,misc']], FALSE]; + $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get'], $rules['Sprocket.get=>provider,misc']], TRUE]; + $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get-foo'], $rules['Sprocket.get']], FALSE]; + $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get']], FALSE]; return $c; } @@ -361,8 +361,8 @@ class WhitelistSubscriberTest extends \CiviUnitTestCase { \CRM_Core_DAO_AllCoreTables::registerEntityType('Widget', 'CRM_Fake_DAO_Widget', 'fake_widget'); $widgetProvider = new \Civi\API\Provider\StaticProvider(3, 'Widget', - array('id', 'widget_type', 'provider', 'title'), - array(), + ['id', 'widget_type', 'provider', 'title'], + [], $recs['widget'] ); @@ -370,8 +370,8 @@ class WhitelistSubscriberTest extends \CiviUnitTestCase { $sprocketProvider = new \Civi\API\Provider\StaticProvider( 3, 'Sprocket', - array('id', 'sprocket_type', 'widget_id', 'provider', 'title', 'comment'), - array(), + ['id', 'sprocket_type', 'widget_id', 'provider', 'title', 'comment'], + [], $recs['sprocket'] ); diff --git a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php index 2ba6ebd090..5483a2e58a 100644 --- a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php +++ b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php @@ -190,12 +190,12 @@ abstract class AbstractMappingTest extends \CiviUnitTestCase { $this->mut = new \CiviMailUtils($this, TRUE); - $this->cronSchedule = array( + $this->cronSchedule = [ 'start' => '2015-01-20 00:00:00', 'end' => '2015-03-01 00:00:00', // seconds 'interval' => 24 * 60 * 60, - ); + ]; $this->schedule = new \CRM_Core_DAO_ActionSchedule(); $this->schedule->title = $this->getName(TRUE); @@ -209,24 +209,24 @@ abstract class AbstractMappingTest extends \CiviUnitTestCase { $this->schedule->msg_template_id = NULL; $this->schedule->record_activity = NULL; - $this->contacts['alice'] = $this->callAPISuccess('Contact', 'create', array( + $this->contacts['alice'] = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Alice', 'last_name' => 'Exemplar', 'email' => 'alice@example.org', - )); - $this->contacts['bob'] = $this->callAPISuccess('Contact', 'create', array( + ]); + $this->contacts['bob'] = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Exemplar', 'email' => 'bob@example.org', - )); - $this->contacts['carol'] = $this->callAPISuccess('Contact', 'create', array( + ]); + $this->contacts['carol'] = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'Carol', 'last_name' => 'Exemplar', 'email' => 'carol@example.org', - )); + ]); } /** @@ -248,30 +248,30 @@ abstract class AbstractMappingTest extends \CiviUnitTestCase { } $this->schedule->save(); - $actualMessages = array(); + $actualMessages = []; foreach ($this->cronTimes() as $time) { \CRM_Utils_Time::setTime($time); - $this->callAPISuccess('job', 'send_reminder', array()); + $this->callAPISuccess('job', 'send_reminder', []); foreach ($this->mut->getAllMessages('ezc') as $message) { /** @var \ezcMail $message */ - $simpleMessage = array( + $simpleMessage = [ 'time' => $time, 'to' => \CRM_Utils_Array::collect('email', $message->to), 'subject' => $message->subject, - ); + ]; sort($simpleMessage['to']); $actualMessages[] = $simpleMessage; $this->mut->clearMessages(); } } - $errorText = "Incorrect messages: " . print_r(array( + $errorText = "Incorrect messages: " . print_r([ 'actualMessages' => $actualMessages, 'expectMessages' => $expectMessages, - ), 1); + ], 1); $this->assertEquals(count($expectMessages), count($actualMessages), $errorText); - usort($expectMessages, array(__CLASS__, 'compareSimpleMsgs')); - usort($actualMessages, array(__CLASS__, 'compareSimpleMsgs')); + usort($expectMessages, [__CLASS__, 'compareSimpleMsgs']); + usort($actualMessages, [__CLASS__, 'compareSimpleMsgs']); foreach ($expectMessages as $offset => $expectMessage) { $actualMessage = $actualMessages[$offset]; $this->assertApproxEquals(strtotime($expectMessage['time']), strtotime($actualMessage['time']), $this->dateTolerance, $errorText); @@ -287,7 +287,7 @@ abstract class AbstractMappingTest extends \CiviUnitTestCase { protected function cronTimes() { $skew = 0; - $times = array(); + $times = []; $end = strtotime($this->cronSchedule['end']); for ($time = strtotime($this->cronSchedule['start']); $time < $end; $time += $this->cronSchedule['interval']) { $times[] = date('Y-m-d H:i:s', $time + $skew); diff --git a/tests/phpunit/Civi/Angular/ChangeSetTest.php b/tests/phpunit/Civi/Angular/ChangeSetTest.php index 8b145d0b48..5d9a7bbdef 100644 --- a/tests/phpunit/Civi/Angular/ChangeSetTest.php +++ b/tests/phpunit/Civi/Angular/ChangeSetTest.php @@ -37,7 +37,7 @@ class ChangeSetTest extends \CiviUnitTestCase { */ public function testInsertAfter() { $changeSet = ChangeSet::create(__FUNCTION__); - $counts = array('~/foo.html' => 0); + $counts = ['~/foo.html' => 0]; $changeSet->alterHtml('~/foo.html', function (\phpQueryObject $doc, $file) use (&$counts) { $counts[$file]++; @@ -51,9 +51,9 @@ class ChangeSetTest extends \CiviUnitTestCase { throw new \Exception("This should not be called. The file does not exist!"); }); - $results = ChangeSet::applyResourceFilters(array($changeSet), 'partials', array( + $results = ChangeSet::applyResourceFilters([$changeSet], 'partials', [ '~/foo.html' => '

Hello

Goodbye

', - )); + ]); $this->assertHtmlEquals( '

Hello

world

Goodbye

cruel world

', @@ -67,7 +67,7 @@ class ChangeSetTest extends \CiviUnitTestCase { */ public function testAppendPrepend() { $changeSet = ChangeSet::create(__FUNCTION__); - $counts = array('~/foo.html' => 0); + $counts = ['~/foo.html' => 0]; $changeSet->alterHtml('~/foo.html', function (\phpQueryObject $doc, $file) use (&$counts) { $counts[$file]++; @@ -81,10 +81,10 @@ class ChangeSetTest extends \CiviUnitTestCase { throw new \Exception("This should not be called. The file does not exist!"); }); - $originals = array( + $originals = [ '~/foo.html' => '

Hello

Goodbye

', - ); - $results = ChangeSet::applyResourceFilters(array($changeSet), 'partials', $originals); + ]; + $results = ChangeSet::applyResourceFilters([$changeSet], 'partials', $originals); $this->assertHtmlEquals( '

Hello

world

Cruel world,Goodbye

', diff --git a/tests/phpunit/Civi/Angular/ManagerTest.php b/tests/phpunit/Civi/Angular/ManagerTest.php index 2635469a93..8dff95ffee 100644 --- a/tests/phpunit/Civi/Angular/ManagerTest.php +++ b/tests/phpunit/Civi/Angular/ManagerTest.php @@ -59,12 +59,12 @@ class ManagerTest extends \CiviUnitTestCase { public function testGetModules() { $modules = $this->angular->getModules(); - $counts = array( + $counts = [ 'js' => 0, 'css' => 0, 'partials' => 0, 'settings' => 0, - ); + ]; foreach ($modules as $module) { $this->assertTrue(is_array($module)); @@ -117,7 +117,7 @@ class ManagerTest extends \CiviUnitTestCase { * Get HTML fragments from an example module. The HTML is modified via hook. */ public function testGetPartials_Hooked() { - \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', array($this, 'hook_civicrm_alterAngular')); + \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', [$this, 'hook_civicrm_alterAngular']); $partials = $this->angular->getPartials('crmMailing'); $this->assertRegExp('/ng-form="crmMailingSubform" cat-stevens="ts\\(\'wild world\'\\)">/', $partials['~/crmMailing/EditMailingCtrl/2step.html']); @@ -125,9 +125,9 @@ class ManagerTest extends \CiviUnitTestCase { } public function testGetJs_Asset() { - \CRM_Utils_Hook::singleton()->setHook('civicrm_angularModules', array($this, 'hook_civicrm_angularModules_fooBar')); + \CRM_Utils_Hook::singleton()->setHook('civicrm_angularModules', [$this, 'hook_civicrm_angularModules_fooBar']); - $paths = $this->angular->getResources(array('fooBar'), 'js', 'path'); + $paths = $this->angular->getResources(['fooBar'], 'js', 'path'); $this->assertRegExp('/visual-bundle.[a-z0-9]+.js/', $paths[0]); $this->assertRegExp('/crossfilter/', file_get_contents($paths[0])); @@ -149,7 +149,7 @@ class ManagerTest extends \CiviUnitTestCase { * Get a translatable string from an example module. The HTML is modified via hook. */ public function testGetStrings_Hooked() { - \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', array($this, 'hook_civicrm_alterAngular')); + \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', [$this, 'hook_civicrm_alterAngular']); $strings = $this->angular->getStrings('crmMailing'); $this->assertTrue(in_array('wild world', $strings)); @@ -160,7 +160,7 @@ class ManagerTest extends \CiviUnitTestCase { * Get the list of dependencies for an Angular module. */ public function testGetRequires() { - $requires = $this->angular->getResources(array('crmMailing'), 'requires', 'requires'); + $requires = $this->angular->getResources(['crmMailing'], 'requires', 'requires'); $this->assertTrue(in_array('ngRoute', $requires['crmMailing'])); $this->assertFalse(in_array('crmCatStevens', $requires['crmMailing'])); // If crmMailing changes, feel free to use a different example. @@ -170,9 +170,9 @@ class ManagerTest extends \CiviUnitTestCase { * Get the list of dependencies for an Angular module. It can be modified via hook. */ public function testGetRequires_Hooked() { - \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', array($this, 'hook_civicrm_alterAngular')); + \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', [$this, 'hook_civicrm_alterAngular']); - $requires = $this->angular->getResources(array('crmMailing'), 'requires', 'requires'); + $requires = $this->angular->getResources(['crmMailing'], 'requires', 'requires'); $this->assertTrue(in_array('ngRoute', $requires['crmMailing'])); $this->assertTrue(in_array('crmCatStevens', $requires['crmMailing'])); // If crmMailing changes, feel free to use a different example. @@ -183,7 +183,7 @@ class ManagerTest extends \CiviUnitTestCase { */ public function testResolveDeps() { // If crmMailing changes, feel free to use a different example. - $expected = array( + $expected = [ 'angularFileUpload', 'crmAttachment', 'crmAutosave', @@ -196,8 +196,8 @@ class ManagerTest extends \CiviUnitTestCase { 'ngRoute', 'ngSanitize', 'ui.utils', - ); - $input = array('crmMailing', 'crmCxn'); + ]; + $input = ['crmMailing', 'crmCxn']; $actual = $this->angular->resolveDependencies($input); sort($expected); sort($actual); @@ -221,13 +221,13 @@ class ManagerTest extends \CiviUnitTestCase { } public function hook_civicrm_angularModules_fooBar(&$angularModules) { - $angularModules['fooBar'] = array( + $angularModules['fooBar'] = [ 'ext' => 'civicrm', - 'js' => array( + 'js' => [ 'assetBuilder://visual-bundle.js', 'ext://civicrm/js/Common.js', - ), - ); + ], + ]; } } diff --git a/tests/phpunit/Civi/Angular/PartialSyntaxTest.php b/tests/phpunit/Civi/Angular/PartialSyntaxTest.php index f09ff1379a..5b22ef287f 100644 --- a/tests/phpunit/Civi/Angular/PartialSyntaxTest.php +++ b/tests/phpunit/Civi/Angular/PartialSyntaxTest.php @@ -54,36 +54,36 @@ class PartialSyntaxTest extends \CiviUnitTestCase { } public function basicConsistencyExamples() { - $cases = array(); + $cases = []; - $cases[0] = array( + $cases[0] = [ '
', '
', - ); - $cases[1] = array( + ]; + $cases[1] = [ '
', '
', - ); - $cases[2] = array( + ]; + $cases[2] = [ '
', '
', - ); - $cases[3] = array( + ]; + $cases[3] = [ '
', '
', - ); - $cases[4] = array( + ]; + $cases[4] = [ '
', '
', - ); - $cases[5] = array( + ]; + $cases[5] = [ '', '', - ); - $cases[6] = array( + ]; + $cases[6] = [ '
', '
', - ); + ]; return $cases; } @@ -102,7 +102,7 @@ class PartialSyntaxTest extends \CiviUnitTestCase { */ public function testAllPartials() { $coder = new \Civi\Angular\Coder(); - $errors = array(); + $errors = []; $count = 0; foreach ($this->angular->getModules() as $module => $moduleDefn) { $partials = $this->angular->getPartials($module); diff --git a/tests/phpunit/Civi/CCase/SequenceListenerTest.php b/tests/phpunit/Civi/CCase/SequenceListenerTest.php index 72ac7fd511..026b57556a 100644 --- a/tests/phpunit/Civi/CCase/SequenceListenerTest.php +++ b/tests/phpunit/Civi/CCase/SequenceListenerTest.php @@ -11,17 +11,17 @@ class SequenceListenerTest extends \CiviCaseTestCase { public function setUp() { parent::setUp(); - $this->_params = array( + $this->_params = [ 'case_type' => $this->caseType, 'subject' => 'Test case', 'contact_id' => 17, - ); + ]; //Add an activity status with Type = Completed - $this->callAPISuccess('OptionValue', 'create', array( + $this->callAPISuccess('OptionValue', 'create', [ 'option_group_id' => "activity_status", 'filter' => \CRM_Activity_BAO_Activity::COMPLETED, 'label' => "Skip Activity", - )); + ]); } public function testSequence() { @@ -41,10 +41,10 @@ class SequenceListenerTest extends \CiviCaseTestCase { // Edit details of first activity -- but don't finish it yet! \CRM_Utils_Time::setTime('2013-11-30 01:30:00'); - $this->callApiSuccess('Activity', 'create', array( + $this->callApiSuccess('Activity', 'create', [ 'id' => self::ag($analyzer->getSingleActivity('Medical evaluation'), 'id'), 'subject' => 'This is the new subject', - )); + ]); $analyzer = new \Civi\CCase\Analyzer($case['id']); $this->assertEquals($caseStatuses['Open'], self::ag($analyzer->getCase(), 'status_id')); $this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time')); @@ -54,10 +54,10 @@ class SequenceListenerTest extends \CiviCaseTestCase { // Complete first activity; schedule second \CRM_Utils_Time::setTime('2013-11-30 02:00:00'); - $this->callApiSuccess('Activity', 'create', array( + $this->callApiSuccess('Activity', 'create', [ 'id' => self::ag($analyzer->getSingleActivity('Medical evaluation'), 'id'), 'status_id' => $actStatuses['Completed'], - )); + ]); $analyzer->flush(); $this->assertEquals($caseStatuses['Open'], self::ag($analyzer->getCase(), 'status_id')); $this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time')); @@ -68,10 +68,10 @@ class SequenceListenerTest extends \CiviCaseTestCase { //Complete second activity using "Skip Activity"(Completed); schedule third \CRM_Utils_Time::setTime('2013-11-30 03:00:00'); - $this->callApiSuccess('Activity', 'create', array( + $this->callApiSuccess('Activity', 'create', [ 'id' => self::ag($analyzer->getSingleActivity('Mental health evaluation'), 'id'), 'status_id' => $actStatuses['Skip Activity'], - )); + ]); $analyzer->flush(); $this->assertEquals($caseStatuses['Open'], self::ag($analyzer->getCase(), 'status_id')); $this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time')); @@ -83,13 +83,13 @@ class SequenceListenerTest extends \CiviCaseTestCase { //Add an Activity before the case is closed \CRM_Utils_Time::setTime('2013-11-30 04:00:00'); - $this->callApiSuccess('Activity', 'create', array( + $this->callApiSuccess('Activity', 'create', [ 'activity_name' => 'Follow up', 'activity_type_id' => $actTypes['Follow up'], 'status_id' => $actStatuses['Scheduled'], 'case_id' => $case['id'], 'activity_date_time' => \CRM_Utils_Time::getTime(), - )); + ]); $analyzer->flush(); $this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time')); $this->assertEquals($actStatuses['Completed'], self::ag($analyzer->getSingleActivity('Medical evaluation'), 'status_id')); @@ -102,10 +102,10 @@ class SequenceListenerTest extends \CiviCaseTestCase { // Complete third activity; Case should remain open because of the Follow up activity \CRM_Utils_Time::setTime('2013-11-30 04:00:00'); - $this->callApiSuccess('Activity', 'create', array( + $this->callApiSuccess('Activity', 'create', [ 'id' => self::ag($analyzer->getSingleActivity('Secure temporary housing'), 'id'), 'status_id' => $actStatuses['Completed'], - )); + ]); $analyzer->flush(); $this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time')); $this->assertEquals($actStatuses['Completed'], self::ag($analyzer->getSingleActivity('Medical evaluation'), 'status_id')); @@ -119,10 +119,10 @@ class SequenceListenerTest extends \CiviCaseTestCase { // Complete the additional Activity; Case closed \CRM_Utils_Time::setTime('2013-11-30 04:00:00'); - $this->callApiSuccess('Activity', 'create', array( + $this->callApiSuccess('Activity', 'create', [ 'id' => self::ag($analyzer->getSingleActivity('Follow up'), 'id'), 'status_id' => $actStatuses['Completed'], - )); + ]); $analyzer->flush(); $this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time')); $this->assertEquals($actStatuses['Completed'], self::ag($analyzer->getSingleActivity('Medical evaluation'), 'status_id')); @@ -140,11 +140,11 @@ class SequenceListenerTest extends \CiviCaseTestCase { * @see \CRM_Utils_Hook::caseTypes */ public function hook_caseTypes(&$caseTypes) { - $caseTypes[$this->caseType] = array( + $caseTypes[$this->caseType] = [ 'module' => 'org.civicrm.hrcase', 'name' => $this->caseType, 'file' => __DIR__ . '/HousingSupportWithSequence.xml', - ); + ]; } /** diff --git a/tests/phpunit/Civi/Core/CiviEventInspectorTest.php b/tests/phpunit/Civi/Core/CiviEventInspectorTest.php index 144232d50f..a582215197 100644 --- a/tests/phpunit/Civi/Core/CiviEventInspectorTest.php +++ b/tests/phpunit/Civi/Core/CiviEventInspectorTest.php @@ -11,7 +11,7 @@ class CiviEventInspectorTest extends \CiviUnitTestCase { $inspector = new CiviEventInspector(); $eventDef = $inspector->get('hook_civicrm_alterSettingsMetaData'); $this->assertEquals('hook_civicrm_alterSettingsMetaData', $eventDef['name']); - $this->assertEquals(array('settingsMetaData', 'domainID', 'profile'), array_keys($eventDef['fields'])); + $this->assertEquals(['settingsMetaData', 'domainID', 'profile'], array_keys($eventDef['fields'])); $this->assertEquals('hook', $eventDef['type']); $this->assertNotEmpty($eventDef['description_html']); $this->assertTrue($eventDef['fields']['settingsMetaData']['ref']); diff --git a/tests/phpunit/Civi/Core/CiviFacadeTest.php b/tests/phpunit/Civi/Core/CiviFacadeTest.php index 0f678eac5d..76dbc4bdbe 100644 --- a/tests/phpunit/Civi/Core/CiviFacadeTest.php +++ b/tests/phpunit/Civi/Core/CiviFacadeTest.php @@ -11,7 +11,7 @@ class CiviFacadeTest extends \CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); - $this->mandates = array(); + $this->mandates = []; } public function tearDown() { diff --git a/tests/phpunit/Civi/Core/Event/GenericHookEventTest.php b/tests/phpunit/Civi/Core/Event/GenericHookEventTest.php index c6cb27b479..9a5c476af9 100644 --- a/tests/phpunit/Civi/Core/Event/GenericHookEventTest.php +++ b/tests/phpunit/Civi/Core/Event/GenericHookEventTest.php @@ -9,12 +9,12 @@ class GenericHookEventTest extends \CiviUnitTestCase { } public function testConstructParams() { - $event = GenericHookEvent::create(array( + $event = GenericHookEvent::create([ 'ab' => 123, - 'cd' => array('foo' => 'bar'), + 'cd' => ['foo' => 'bar'], 'nothingNull' => NULL, 'nothingZero' => 0, - )); + ]); $this->assertEquals(123, $event->ab); $this->assertEquals('bar', $event->cd['foo']); $this->assertTrue($event->hasField('ab')); @@ -27,8 +27,8 @@ class GenericHookEventTest extends \CiviUnitTestCase { public function testConstructOrdered() { $event = GenericHookEvent::createOrdered( - array('alpha', 'beta', 'nothingNull', 'nothingZero'), - array(456, array('whiz' => 'bang'), NULL, 0, \CRM_Utils_Hook::$_nullObject) + ['alpha', 'beta', 'nothingNull', 'nothingZero'], + [456, ['whiz' => 'bang'], NULL, 0, \CRM_Utils_Hook::$_nullObject] ); $this->assertEquals(456, $event->alpha); $this->assertEquals('bang', $event->beta['whiz']); @@ -43,14 +43,14 @@ class GenericHookEventTest extends \CiviUnitTestCase { public function testDispatch() { \CRM_Utils_Hook::singleton()->setHook('civicrm_ghet', - array($this, 'hook_civicrm_ghet')); + [$this, 'hook_civicrm_ghet']); \Civi::service('dispatcher')->addListener('hook_civicrm_ghet', - array($this, 'onGhet')); + [$this, 'onGhet']); $roString = 'readonly'; $rwString = 'readwrite'; - $roArray = array('readonly'); - $rwArray = array('readwrite'); + $roArray = ['readonly']; + $rwArray = ['readwrite']; $plainObj = new \stdClass(); $refObj = new \stdClass(); @@ -58,11 +58,11 @@ class GenericHookEventTest extends \CiviUnitTestCase { $this->assertEquals('readonly', $roString); $this->assertEquals('readwrite added-string-via-event added-string-via-hook', $rwString); - $this->assertEquals(array('readonly'), $roArray); - $this->assertEquals(array('readwrite', 'added-to-array-via-event', 'added-to-array-via-hook'), $rwArray); + $this->assertEquals(['readonly'], $roArray); + $this->assertEquals(['readwrite', 'added-to-array-via-event', 'added-to-array-via-hook'], $rwArray); $this->assertEquals('added-to-object-via-hook', $plainObj->prop1); $this->assertEquals('added-to-object-via-hook', $refObj->prop2); - $this->assertEquals(array('early-running-result', 'late-running-result'), $returnValue); + $this->assertEquals(['early-running-result', 'late-running-result'], $returnValue); } /** @@ -79,7 +79,7 @@ class GenericHookEventTest extends \CiviUnitTestCase { */ public function hookStub($roString, &$rwString, $roArray, &$rwArray, $plainObj, &$refObj) { return \CRM_Utils_Hook::singleton()->invoke( - array('roString', 'rwString', 'roArray', 'rwArray', 'plainObj', 'refObj'), + ['roString', 'rwString', 'roArray', 'rwArray', 'plainObj', 'refObj'], $roString, $rwString, $roArray, $rwArray, $plainObj, $refObj, 'civicrm_ghet' ); @@ -92,7 +92,7 @@ class GenericHookEventTest extends \CiviUnitTestCase { $rwArray[] = 'added-to-array-via-hook'; $plainObj->prop1 = 'added-to-object-via-hook'; $refObj->prop2 = 'added-to-object-via-hook'; - return array('late-running-result'); + return ['late-running-result']; } public function onGhet(GenericHookEvent $e) { @@ -102,7 +102,7 @@ class GenericHookEventTest extends \CiviUnitTestCase { $e->rwArray[] = 'added-to-array-via-event'; $e->plainObj->prop1 = 'added-to-object-via-event'; $e->refObj->prop2 = 'added-to-object-via-event'; - $e->addReturnValues(array('early-running-result')); + $e->addReturnValues(['early-running-result']); } } diff --git a/tests/phpunit/Civi/Core/ResolverTest.php b/tests/phpunit/Civi/Core/ResolverTest.php index 0f5f3c551a..cecc16ca0b 100644 --- a/tests/phpunit/Civi/Core/ResolverTest.php +++ b/tests/phpunit/Civi/Core/ResolverTest.php @@ -53,7 +53,7 @@ namespace Civi\Core { */ public function testStatic() { $cb = $this->resolver->get('Civi\Core\ResolverTest::dummy'); - $this->assertEquals(array('Civi\Core\ResolverTest', 'dummy'), $cb); + $this->assertEquals(['Civi\Core\ResolverTest', 'dummy'], $cb); $expected = 'static dummy received foo'; $actual = call_user_func($cb, 'foo'); diff --git a/tests/phpunit/Civi/Core/SettingsBagTest.php b/tests/phpunit/Civi/Core/SettingsBagTest.php index 3e2e6811ea..54993ff031 100644 --- a/tests/phpunit/Civi/Core/SettingsBagTest.php +++ b/tests/phpunit/Civi/Core/SettingsBagTest.php @@ -11,7 +11,7 @@ class SettingsBagTest extends \CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); - $this->mandates = array(); + $this->mandates = []; } public function tearDown() { diff --git a/tests/phpunit/Civi/Core/SettingsManagerTest.php b/tests/phpunit/Civi/Core/SettingsManagerTest.php index ef11330a84..640a968c21 100644 --- a/tests/phpunit/Civi/Core/SettingsManagerTest.php +++ b/tests/phpunit/Civi/Core/SettingsManagerTest.php @@ -14,7 +14,7 @@ class SettingsManagerTest extends \CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); - $this->domainDefaults = array( + $this->domainDefaults = [ 'd1' => 'alpha', 'd2' => 'beta', 'd3' => 'gamma', @@ -22,20 +22,20 @@ class SettingsManagerTest extends \CiviUnitTestCase { 'myabspath' => '/tmp/bar', 'myrelurl' => 'sites/foo', 'myabsurl' => 'http://example.com/bar', - ); - $this->contactDefaults = array( + ]; + $this->contactDefaults = [ 'c1' => 'alpha', 'c2' => 'beta', 'c3' => 'gamma', - ); - $this->mandates = array( - 'Mailing Preferences' => array( + ]; + $this->mandates = [ + 'Mailing Preferences' => [ 'd3' => 'GAMMA!', - ), - 'contact' => array( + ], + 'contact' => [ 'c3' => 'GAMMA MAN!', - ), - ); + ], + ]; } public function tearDown() { @@ -131,7 +131,7 @@ class SettingsManagerTest extends \CiviUnitTestCase { * @return SettingsManager */ protected function createManager() { - $cache = new \CRM_Utils_Cache_Arraycache(array()); + $cache = new \CRM_Utils_Cache_Arraycache([]); $cache->set('defaults_domain', $this->domainDefaults); $cache->set('defaults_contact', $this->contactDefaults); foreach ($this->mandates as $entity => $keyValues) { diff --git a/tests/phpunit/Civi/Test/ExampleHookTest.php b/tests/phpunit/Civi/Test/ExampleHookTest.php index 7437d5786b..fb81845ccb 100644 --- a/tests/phpunit/Civi/Test/ExampleHookTest.php +++ b/tests/phpunit/Civi/Test/ExampleHookTest.php @@ -20,9 +20,9 @@ class ExampleHookTest extends \PHPUnit\Framework\TestCase implements HeadlessInt } protected function setUp() { - $this->contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', array( + $this->contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', [ 'contact_type' => 'Individual', - )); + ]); $session = \CRM_Core_Session::singleton(); $session->set('userID', $this->contact->id); } diff --git a/tests/phpunit/Civi/Test/ExampleTransactionalTest.php b/tests/phpunit/Civi/Test/ExampleTransactionalTest.php index 8cd09420ad..17a93264e9 100644 --- a/tests/phpunit/Civi/Test/ExampleTransactionalTest.php +++ b/tests/phpunit/Civi/Test/ExampleTransactionalTest.php @@ -15,7 +15,7 @@ class ExampleTransactionalTest extends \PHPUnit\Framework\TestCase implements He * @var array * Array(int $id). */ - protected static $contactIds = array(); + protected static $contactIds = []; public function setUpHeadless() { return \Civi\Test::headless()->apply(); @@ -23,9 +23,9 @@ class ExampleTransactionalTest extends \PHPUnit\Framework\TestCase implements He protected function setUp() { /** @var \CRM_Contact_DAO_Contact $contact */ - $contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', array( + $contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', [ 'contact_type' => 'Individual', - )); + ]); self::$contactIds[$this->getName()] = $contact->id; } diff --git a/tests/phpunit/Civi/Token/TokenProcessorTest.php b/tests/phpunit/Civi/Token/TokenProcessorTest.php index 808e490693..faf1e71943 100644 --- a/tests/phpunit/Civi/Token/TokenProcessorTest.php +++ b/tests/phpunit/Civi/Token/TokenProcessorTest.php @@ -22,12 +22,12 @@ class TokenProcessorTest extends \CiviUnitTestCase { $this->useTransaction(TRUE); parent::setUp(); $this->dispatcher = new EventDispatcher(); - $this->dispatcher->addListener(Events::TOKEN_REGISTER, array($this, 'onListTokens')); - $this->dispatcher->addListener(Events::TOKEN_EVALUATE, array($this, 'onEvalTokens')); - $this->counts = array( + $this->dispatcher->addListener(Events::TOKEN_REGISTER, [$this, 'onListTokens']); + $this->dispatcher->addListener(Events::TOKEN_EVALUATE, [$this, 'onEvalTokens']); + $this->counts = [ 'onListTokens' => 0, 'onEvalTokens' => 0, - ); + ]; } /** @@ -35,20 +35,20 @@ class TokenProcessorTest extends \CiviUnitTestCase { * values. */ public function testRowContext() { - $p = new TokenProcessor($this->dispatcher, array( + $p = new TokenProcessor($this->dispatcher, [ 'controller' => __CLASS__, 'omega' => '99', - )); + ]); $createdRow = $p->addRow() ->context('one', 1) - ->context('two', array(2 => 3)) - ->context(array( - 'two' => array(4 => 5), - 'three' => array(6 => 7), + ->context('two', [2 => 3]) + ->context([ + 'two' => [4 => 5], + 'three' => [6 => 7], 'omega' => '98', - )); + ]); $gotRow = $p->getRow(0); - foreach (array($createdRow, $gotRow) as $row) { + foreach ([$createdRow, $gotRow] as $row) { $this->assertEquals(1, $row->context['one']); $this->assertEquals(3, $row->context['two'][2]); $this->assertEquals(5, $row->context['two'][4]); @@ -62,10 +62,10 @@ class TokenProcessorTest extends \CiviUnitTestCase { * Check that getContextValues() returns the correct data */ public function testGetContextValues() { - $p = new TokenProcessor($this->dispatcher, array( + $p = new TokenProcessor($this->dispatcher, [ 'controller' => __CLASS__, 'omega' => '99', - )); + ]); $p->addRow()->context('id', 10)->context('omega', '98'); $p->addRow()->context('id', 10)->context('contact', (object) ['cid' => 10]); $p->addRow()->context('id', 11)->context('contact', (object) ['cid' => 11]); @@ -79,19 +79,19 @@ class TokenProcessorTest extends \CiviUnitTestCase { * values. */ public function testRowTokens() { - $p = new TokenProcessor($this->dispatcher, array( + $p = new TokenProcessor($this->dispatcher, [ 'controller' => __CLASS__, - )); + ]); $createdRow = $p->addRow() ->tokens('one', 1) - ->tokens('two', array(2 => 3)) - ->tokens(array( - 'two' => array(4 => 5), - 'three' => array(6 => 7), - )) + ->tokens('two', [2 => 3]) + ->tokens([ + 'two' => [4 => 5], + 'three' => [6 => 7], + ]) ->tokens('four', 8, 9); $gotRow = $p->getRow(0); - foreach (array($createdRow, $gotRow) as $row) { + foreach ([$createdRow, $gotRow] as $row) { $this->assertEquals(1, $row->tokens['one']); $this->assertEquals(3, $row->tokens['two'][2]); $this->assertEquals(5, $row->tokens['two'][4]); @@ -101,24 +101,24 @@ class TokenProcessorTest extends \CiviUnitTestCase { } public function testGetMessageTokens() { - $p = new TokenProcessor($this->dispatcher, array( + $p = new TokenProcessor($this->dispatcher, [ 'controller' => __CLASS__, - )); + ]); $p->addMessage('greeting_html', 'Good morning,

{contact.display_name}

. {custom.foobar}!', 'text/html'); $p->addMessage('greeting_text', 'Good morning, {contact.display_name}. {custom.whizbang}, {contact.first_name}!', 'text/plain'); - $expected = array( - 'contact' => array('display_name', 'first_name'), - 'custom' => array('foobar', 'whizbang'), - ); + $expected = [ + 'contact' => ['display_name', 'first_name'], + 'custom' => ['foobar', 'whizbang'], + ]; $this->assertEquals($expected, $p->getMessageTokens()); } public function testListTokens() { - $p = new TokenProcessor($this->dispatcher, array( + $p = new TokenProcessor($this->dispatcher, [ 'controller' => __CLASS__, - )); - $p->addToken(array('entity' => 'MyEntity', 'field' => 'myField', 'label' => 'My Label')); - $this->assertEquals(array('{MyEntity.myField}' => 'My Label'), $p->listTokens()); + ]); + $p->addToken(['entity' => 'MyEntity', 'field' => 'myField', 'label' => 'My Label']); + $this->assertEquals(['{MyEntity.myField}' => 'My Label'], $p->listTokens()); } /** @@ -126,38 +126,38 @@ class TokenProcessorTest extends \CiviUnitTestCase { * contacts in multiple messages. */ public function testFull() { - $p = new TokenProcessor($this->dispatcher, array( + $p = new TokenProcessor($this->dispatcher, [ 'controller' => __CLASS__, - )); + ]); $p->addMessage('greeting_html', 'Good morning,

{contact.display_name}

. {custom.foobar} Bye!', 'text/html'); $p->addMessage('greeting_text', 'Good morning, {contact.display_name}. {custom.foobar} Bye!', 'text/plain'); $p->addRow() - ->context(array('contact_id' => 123)) - ->format('text/plain')->tokens(array( - 'contact' => array('display_name' => 'What'), - )); + ->context(['contact_id' => 123]) + ->format('text/plain')->tokens([ + 'contact' => ['display_name' => 'What'], + ]); $p->addRow() - ->context(array('contact_id' => 4)) - ->format('text/plain')->tokens(array( - 'contact' => array('display_name' => 'Who'), - )); + ->context(['contact_id' => 4]) + ->format('text/plain')->tokens([ + 'contact' => ['display_name' => 'Who'], + ]); $p->addRow() - ->context(array('contact_id' => 10)) - ->format('text/plain')->tokens(array( - 'contact' => array('display_name' => 'Darth Vader'), - )); + ->context(['contact_id' => 10]) + ->format('text/plain')->tokens([ + 'contact' => ['display_name' => 'Darth Vader'], + ]); - $expectHtml = array( + $expectHtml = [ 0 => 'Good morning,

What

. #0123 is a good number. Trickster {contact.display_name}. Bye!', 1 => 'Good morning,

Who

. #0004 is a good number. Trickster {contact.display_name}. Bye!', 2 => 'Good morning,

Darth Vader

. #0010 is a good number. Trickster {contact.display_name}. Bye!', - ); + ]; - $expectText = array( + $expectText = [ 0 => 'Good morning, What. #0123 is a good number. Trickster {contact.display_name}. Bye!', 1 => 'Good morning, Who. #0004 is a good number. Trickster {contact.display_name}. Bye!', 2 => 'Good morning, Darth Vader. #0010 is a good number. Trickster {contact.display_name}. Bye!', - ); + ]; $rowCount = 0; foreach ($p->evaluate()->getRows() as $key => $row) { @@ -175,9 +175,9 @@ class TokenProcessorTest extends \CiviUnitTestCase { public function onListTokens(TokenRegisterEvent $e) { $this->counts[__FUNCTION__]++; - $e->register('custom', array( + $e->register('custom', [ 'foobar' => 'A special message about foobar', - )); + ]); } public function onEvalTokens(TokenValueEvent $e) { diff --git a/tests/phpunit/api/v3/ACLCachingTest.php b/tests/phpunit/api/v3/ACLCachingTest.php index 6a0765e258..35080a87d8 100644 --- a/tests/phpunit/api/v3/ACLCachingTest.php +++ b/tests/phpunit/api/v3/ACLCachingTest.php @@ -46,9 +46,9 @@ class api_v3_ACLCachingTest extends CiviUnitTestCase { * @see CiviUnitTestCase::tearDown() */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_activity', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); } @@ -58,12 +58,12 @@ class api_v3_ACLCachingTest extends CiviUnitTestCase { */ public function testActivityCreateCustomBefore($version) { $this->_apiversion = $version; - $values = $this->callAPISuccess('custom_field', 'getoptions', array('field' => 'custom_group_id')); + $values = $this->callAPISuccess('custom_field', 'getoptions', ['field' => 'custom_group_id']); $this->assertTrue($values['count'] == 0); - $this->CustomGroupCreate(array('extends' => 'Activity')); - $groupCount = $this->callAPISuccess('custom_group', 'getcount', array('extends' => 'activity')); + $this->CustomGroupCreate(['extends' => 'Activity']); + $groupCount = $this->callAPISuccess('custom_group', 'getcount', ['extends' => 'activity']); $this->assertEquals($groupCount, 1, 'one group should now exist'); - $values = $this->callAPISuccess('custom_field', 'getoptions', array('field' => 'custom_group_id')); + $values = $this->callAPISuccess('custom_field', 'getoptions', ['field' => 'custom_group_id']); $this->assertTrue($values['count'] == 1, 'check that cached value is not retained for custom_group_id'); } diff --git a/tests/phpunit/api/v3/APITest.php b/tests/phpunit/api/v3/APITest.php index 0e25a87f62..9bc6c00878 100644 --- a/tests/phpunit/api/v3/APITest.php +++ b/tests/phpunit/api/v3/APITest.php @@ -37,7 +37,7 @@ class api_v3_APITest extends CiviUnitTestCase { protected $_apiversion = 3; public function testAPIReplaceVariables() { - $result = array(); + $result = []; $result['testfield'] = 6; $result['api.tag.get'] = 999; $result['api.tag.create']['id'] = 8; @@ -46,7 +46,7 @@ class api_v3_APITest extends CiviUnitTestCase { $result['api.tag.create']['values']['0']['display'] = 'batman'; $result['api.tag.create.api.tag.create']['values']['0']['display'] = 'krypton'; $result['api.tag.create']['values']['0']['api_tag_get'] = 'darth vader'; - $params = array( + $params = [ 'activity_type_id' => '$value.testfield', 'tag_id' => '$value.api.tag.create.id', 'tag1_id' => '$value.api.entity.create.0.id', @@ -55,7 +55,7 @@ class api_v3_APITest extends CiviUnitTestCase { 'number' => '$value.api.tag.get', 'big_rock' => '$value.api.tag.create.api.tag.create.values.0.display', 'villain' => '$value.api.tag.create.values.0.api_tag_get.display', - ); + ]; _civicrm_api_replace_variables($params, $result); $this->assertEquals(999, $params['number']); $this->assertEquals(8, $params['tag_id']); @@ -73,17 +73,17 @@ class api_v3_APITest extends CiviUnitTestCase { $this->callAPIFailure( 'RandomFile', 'get', - array(), + [], 'API (RandomFile, get) does not exist (join the API team and implement it!)' ); } public function testAPIWrapperCamelCaseFunction() { - $this->callAPISuccess('OptionGroup', 'Get', array()); + $this->callAPISuccess('OptionGroup', 'Get', []); } public function testAPIWrapperLcaseFunction() { - $this->callAPISuccess('OptionGroup', 'get', array()); + $this->callAPISuccess('OptionGroup', 'get', []); } /** @@ -93,18 +93,18 @@ class api_v3_APITest extends CiviUnitTestCase { $oldPath = get_include_path(); set_include_path($oldPath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver'); - $result = $this->callAPISuccess('contact', 'example_action1', array()); + $result = $this->callAPISuccess('contact', 'example_action1', []); $this->assertEquals($result['values'][0], 'civicrm_api3_generic_example_action1 is ok'); - $result = $this->callAPISuccess('contact', 'example_action2', array()); + $result = $this->callAPISuccess('contact', 'example_action2', []); $this->assertEquals($result['values'][0], 'civicrm_api3_contact_example_action2 is ok'); - $result = $this->callAPISuccess('test_entity', 'example_action3', array()); + $result = $this->callAPISuccess('test_entity', 'example_action3', []); $this->assertEquals($result['values'][0], 'civicrm_api3_test_entity_example_action3 is ok'); set_include_path($oldPath); } public function testFromCamel() { - $cases = array( + $cases = [ 'Contribution' => 'contribution', 'contribution' => 'contribution', 'OptionValue' => 'option_value', @@ -113,7 +113,7 @@ class api_v3_APITest extends CiviUnitTestCase { 'UFJoin' => 'uf_join', 'ufJoin' => 'uf_join', 'uf_join' => 'uf_join', - ); + ]; foreach ($cases as $input => $expected) { $actual = _civicrm_api_get_entity_name_from_camel($input); $this->assertEquals($expected, $actual, sprintf('input=%s expected=%s actual=%s', $input, $expected, $actual)); @@ -121,7 +121,7 @@ class api_v3_APITest extends CiviUnitTestCase { } public function testToCamel() { - $cases = array( + $cases = [ 'Contribution' => 'Contribution', 'contribution' => 'Contribution', 'OptionValue' => 'OptionValue', @@ -129,7 +129,7 @@ class api_v3_APITest extends CiviUnitTestCase { 'option_value' => 'OptionValue', 'UFJoin' => 'UFJoin', 'uf_join' => 'UFJoin', - ); + ]; foreach ($cases as $input => $expected) { $actual = _civicrm_api_get_camel_name($input); $this->assertEquals($expected, $actual, sprintf('input=%s expected=%s actual=%s', $input, $expected, $actual)); @@ -141,7 +141,7 @@ class api_v3_APITest extends CiviUnitTestCase { */ public function testv3Wrapper() { try { - $result = civicrm_api3('contact', 'get', array()); + $result = civicrm_api3('contact', 'get', []); } catch (CRM_Exception $e) { $this->fail("This should have been a success test"); @@ -155,7 +155,7 @@ class api_v3_APITest extends CiviUnitTestCase { */ public function testV3WrapperException() { try { - civicrm_api3('contact', 'create', array('debug' => 1)); + civicrm_api3('contact', 'create', ['debug' => 1]); } catch (CiviCRM_API3_Exception $e) { $this->assertEquals('mandatory_missing', $e->getErrorCode()); @@ -173,12 +173,12 @@ class api_v3_APITest extends CiviUnitTestCase { public function testCreateNoStringNullResult() { // create an example contact // $contact = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage')->toArray(); - $result = $this->callAPISuccess('ContributionPage', 'create', array( + $result = $this->callAPISuccess('ContributionPage', 'create', [ 'title' => "Test Contribution Page", 'financial_type_id' => 1, 'currency' => 'USD', 'goal_amount' => 100, - )); + ]); $contact = array_shift($result['values']); $this->assertTrue(is_numeric($contact['id'])); @@ -188,11 +188,11 @@ class api_v3_APITest extends CiviUnitTestCase { $this->assertNotEmpty($contact['currency']); // update the contact - $result = $this->callAPISuccess('ContributionPage', 'create', array( + $result = $this->callAPISuccess('ContributionPage', 'create', [ 'id' => $contact['id'], 'title' => 'New title', 'currency' => '', - )); + ]); // Check return format. $this->assertEquals(1, $result['count']); diff --git a/tests/phpunit/api/v3/APIWrapperTest.php b/tests/phpunit/api/v3/APIWrapperTest.php index 56c688b915..684be82e9c 100644 --- a/tests/phpunit/api/v3/APIWrapperTest.php +++ b/tests/phpunit/api/v3/APIWrapperTest.php @@ -46,7 +46,7 @@ class api_v3_APIWrapperTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); $this->useTransaction(TRUE); - CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_apiWrappers', array($this, 'onApiWrappers')); + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_apiWrappers', [$this, 'onApiWrappers']); } /** @@ -74,11 +74,11 @@ class api_v3_APIWrapperTest extends CiviUnitTestCase { // the wrapper intervenes (fromApiInput) // Note: The output would define "display_name", but the wrapper // intervenes (toApiOutput) and replaces with "display_name_munged". - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Invalid', 'first_name' => 'First', 'last_name' => 'Last', - )); + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); $this->assertEquals('MUNGE! First Last', $result['values'][$result['id']]['display_name_munged']); } diff --git a/tests/phpunit/api/v3/ActionScheduleTest.php b/tests/phpunit/api/v3/ActionScheduleTest.php index 144d09daec..8c3a4e1192 100644 --- a/tests/phpunit/api/v3/ActionScheduleTest.php +++ b/tests/phpunit/api/v3/ActionScheduleTest.php @@ -55,7 +55,7 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase { $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7); - $params = array( + $params = [ 'title' => $title, 'recipient' => $assigneeID, 'limit_to' => 1, @@ -65,7 +65,7 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase { 'record_activity' => 1, 'start_action_date' => 'activity_date_time', 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, - ); + ]; $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); $this->assertTrue(is_numeric($actionSchedule['id'])); $this->assertTrue($actionSchedule['id'] > 0); @@ -80,10 +80,10 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase { */ public function testActionScheduleCreateWithoutRequired($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'subject' => 'this case should fail', 'scheduled_date_time' => date('Ymd'), - ); + ]; $this->callAPIFailure('activity', 'create', $params); } @@ -98,7 +98,7 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase { $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7); - $params = array( + $params = [ 'title' => $title, 'recipient' => $assigneeID, 'limit_to' => 1, @@ -120,7 +120,7 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase { 'end_date' => 'activity_date_time', 'body_html' => 'Test description', 'subject' => 'Test subject', - ); + ]; $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); $this->assertTrue(is_numeric($actionSchedule['id'])); $this->assertTrue($actionSchedule['id'] > 0); diff --git a/tests/phpunit/api/v3/ActivityCaseTest.php b/tests/phpunit/api/v3/ActivityCaseTest.php index b2de06cdd8..4bba2e4a81 100644 --- a/tests/phpunit/api/v3/ActivityCaseTest.php +++ b/tests/phpunit/api/v3/ActivityCaseTest.php @@ -36,17 +36,17 @@ class api_v3_ActivityCaseTest extends CiviCaseTestCase { $this->_cid = $this->individualCreate(); - $this->_case = $this->callAPISuccess('case', 'create', array( + $this->_case = $this->callAPISuccess('case', 'create', [ 'case_type_id' => $this->caseTypeId, 'subject' => __CLASS__, 'contact_id' => $this->_cid, - )); + ]); - $this->_otherActivity = $this->callAPISuccess('Activity', 'create', array( + $this->_otherActivity = $this->callAPISuccess('Activity', 'create', [ 'source_contact_id' => $this->_cid, 'activity_type_id' => 'Phone Call', 'subject' => 'Ask not what your API can do for you, but what you can do for your API.', - )); + ]); } /** @@ -55,17 +55,17 @@ class api_v3_ActivityCaseTest extends CiviCaseTestCase { */ public function testActivityCreateOnCase() { $hash = substr(sha1(CIVICRM_SITE_KEY . $this->_case['id']), 0, 7); - $subjectArr = array( + $subjectArr = [ "[case #{$this->_case['id']}] test activity recording under case with id", "[case #{$hash}] test activity recording under case with id", - ); + ]; foreach ($subjectArr as $subject) { - $activity = $this->callAPISuccess('Activity', 'create', array( + $activity = $this->callAPISuccess('Activity', 'create', [ 'source_contact_id' => $this->_cid, 'activity_type_id' => 'Phone Call', 'subject' => $subject, - )); - $case = $this->callAPISuccessGetSingle('Activity', array('return' => array("case_id"), 'id' => $activity['id'])); + ]); + $case = $this->callAPISuccessGetSingle('Activity', ['return' => ["case_id"], 'id' => $activity['id']]); //Check if case id is present for the activity. $this->assertEquals($this->_case['id'], $case['case_id'][0]); } @@ -75,36 +75,36 @@ class api_v3_ActivityCaseTest extends CiviCaseTestCase { $this->assertTrue(is_numeric($this->_case['id'])); $this->assertTrue(is_numeric($this->_otherActivity['id'])); - $getByCaseId = $this->callAPIAndDocument('Activity', 'get', array( + $getByCaseId = $this->callAPIAndDocument('Activity', 'get', [ 'case_id' => $this->_case['id'], - ), __FUNCTION__, __FILE__); + ], __FUNCTION__, __FILE__); $this->assertNotEmpty($getByCaseId['values']); $getByCaseId_ids = array_keys($getByCaseId['values']); - $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', array( - 'case_id' => array('IS NOT NULL' => 1), - ), __FUNCTION__, __FILE__); + $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', [ + 'case_id' => ['IS NOT NULL' => 1], + ], __FUNCTION__, __FILE__); $this->assertNotEmpty($getByCaseNotNull['values']); $getByCaseNotNull_ids = array_keys($getByCaseNotNull['values']); - $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', array( - 'case_id' => array('IS NULL' => 1), - ), __FUNCTION__, __FILE__); + $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', [ + 'case_id' => ['IS NULL' => 1], + ], __FUNCTION__, __FILE__); $this->assertNotEmpty($getByCaseNull['values']); $getByCaseNull_ids = array_keys($getByCaseNull['values']); $this->assertTrue(in_array($this->_otherActivity['id'], $getByCaseNull_ids)); $this->assertNotTrue(in_array($this->_otherActivity['id'], $getByCaseId_ids)); $this->assertEquals($getByCaseId_ids, $getByCaseNotNull_ids); - $this->assertEquals(array(), array_intersect($getByCaseId_ids, $getByCaseNull_ids)); + $this->assertEquals([], array_intersect($getByCaseId_ids, $getByCaseNull_ids)); } public function testActivityGetWithCaseInfo() { - $activities = $this->callAPISuccess('Activity', 'get', array( + $activities = $this->callAPISuccess('Activity', 'get', [ 'sequential' => 1, 'case_id' => $this->_case['id'], - 'return' => array('case_id', 'case_id.subject'), - )); + 'return' => ['case_id', 'case_id.subject'], + ]); $this->assertEquals(__CLASS__, $activities['values'][0]['case_id.subject']); // Note - case_id is always an array $this->assertEquals($this->_case['id'], $activities['values'][0]['case_id'][0]); diff --git a/tests/phpunit/api/v3/ActivityContactTest.php b/tests/phpunit/api/v3/ActivityContactTest.php index 1a0783d390..af7f0580a3 100644 --- a/tests/phpunit/api/v3/ActivityContactTest.php +++ b/tests/phpunit/api/v3/ActivityContactTest.php @@ -47,11 +47,11 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { $activity = $this->activityCreate(); $this->_activityID = $activity['id']; CRM_Core_PseudoConstant::flush(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_contactID, 'activity_id' => $this->_activityID, 'record_type_id' => 2, - ); + ]; } /** @@ -65,7 +65,7 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('activity_contact', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('activity_contact', 'delete', ['id' => $result['id']]); } /** @@ -77,11 +77,11 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { //create one $create = $this->callAPISuccess('activity_contact', 'create', $this->_params); - $result = $this->callAPIAndDocument('activity_contact', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('activity_contact', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $get = $this->callAPISuccess('activity_contact', 'get', array( + $get = $this->callAPISuccess('activity_contact', 'get', [ 'id' => $create['id'], - )); + ]); $this->assertEquals(0, $get['count'], 'ActivityContact not successfully deleted'); } @@ -91,7 +91,7 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { */ public function testGetActivitiesByContact($version) { $this->_apiversion = $version; - $this->callAPISuccess('ActivityContact', 'Get', array('contact_id' => $this->_contactID)); + $this->callAPISuccess('ActivityContact', 'Get', ['contact_id' => $this->_contactID]); } /** @@ -100,7 +100,7 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { */ public function testGetActivitiesByActivity($version) { $this->_apiversion = $version; - $this->callAPISuccess('ActivityContact', 'Get', array('activity_id' => $this->_activityID)); + $this->callAPISuccess('ActivityContact', 'Get', ['activity_id' => $this->_activityID]); } /** @@ -110,7 +110,7 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { */ public function testGetEmptyParams($version) { $this->_apiversion = $version; - $this->callAPISuccess('ActivityContact', 'Get', array()); + $this->callAPISuccess('ActivityContact', 'Get', []); } /** @@ -118,9 +118,9 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { * FIXME: Api4 */ public function testGetWrongParams() { - $this->callAPIFailure('ActivityContact', 'Get', array('contact_id' => 'abc')); - $this->callAPIFailure('ActivityContact', 'Get', array('activity_id' => 'abc')); - $this->callAPIFailure('ActivityContact', 'Get', array('record_type_id' => 'abc')); + $this->callAPIFailure('ActivityContact', 'Get', ['contact_id' => 'abc']); + $this->callAPIFailure('ActivityContact', 'Get', ['activity_id' => 'abc']); + $this->callAPIFailure('ActivityContact', 'Get', ['record_type_id' => 'abc']); } } diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index 31bb080683..fd0c260eb4 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -66,15 +66,15 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->_contactID = $this->individualCreate(); //create activity types $this->test_activity_type_value = 9999; - $activityTypes = $this->callAPISuccess('option_value', 'create', array( + $activityTypes = $this->callAPISuccess('option_value', 'create', [ 'option_group_id' => 2, 'name' => 'Test activity type', 'label' => 'Test activity type', 'value' => $this->test_activity_type_value, 'sequential' => 1, - )); + ]); $this->test_activity_type_id = $activityTypes['id']; - $this->_params = array( + $this->_params = [ 'source_contact_id' => $this->_contactID, 'activity_type_id' => 'Test activity type', 'subject' => 'test activity type id', @@ -84,8 +84,8 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'duration' => 120, 'location' => 'Pennsylvania', 'details' => 'a test activity', - ); - $this->_params2 = array( + ]; + $this->_params2 = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Eat & drink', 'activity_date_time' => date('Ymd'), @@ -94,7 +94,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'discuss & eat', 'status_id' => 1, 'activity_type_id' => $this->test_activity_type_value, - ); + ]; // create a logged in USER since the code references it for source_contact_id $this->createLoggedInUser(); } @@ -105,16 +105,16 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * This method is called after a test is executed. */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_activity', 'civicrm_activity_contact', 'civicrm_uf_match', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); - $type = $this->callAPISuccess('optionValue', 'get', array('id' => $this->test_activity_type_id)); + $type = $this->callAPISuccess('optionValue', 'get', ['id' => $this->test_activity_type_id]); if (!empty($type['count'])) { - $this->callAPISuccess('option_value', 'delete', array('id' => $this->test_activity_type_id)); + $this->callAPISuccess('option_value', 'delete', ['id' => $this->test_activity_type_id]); } } @@ -125,7 +125,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateEmpty($version) { $this->_apiversion = $version; - $this->callAPIFailure('activity', 'create', array()); + $this->callAPIFailure('activity', 'create', []); } /** @@ -135,10 +135,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateWithoutRequired($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'subject' => 'this case should fail', 'scheduled_date_time' => date('Ymd'), - ); + ]; $this->callAPIFailure('activity', 'create', $params); } @@ -147,7 +147,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * and activity_name. */ public function testActivityCreateMismatchNameType() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Test activity', 'activity_date_time' => date('Ymd'), @@ -158,7 +158,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Fubar activity type', 'activity_type_id' => 5, 'scheduled_date_time' => date('Ymd'), - ); + ]; $this->callAPIFailure('activity', 'create', $params); } @@ -167,7 +167,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activity_id() with missing source_contact_id is put with the current user. */ public function testActivityCreateWithMissingContactId() { - $params = array( + $params = [ 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -175,7 +175,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_name' => 'Test activity type', - ); + ]; $this->callAPISuccess('activity', 'create', $params); } @@ -187,7 +187,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateWithMissingContactIdNoLoggedInUser() { CRM_Core_Session::singleton()->set('userID', NULL); - $params = array( + $params = [ 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -195,7 +195,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_name' => 'Test activity type', - ); + ]; $this->callAPIFailure('activity', 'create', $params, 'source_contact_id is not a valid integer'); } @@ -207,7 +207,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateWithNonNumericContactId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'source_contact_id' => 'fubar', 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), @@ -216,7 +216,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_name' => 'Test activity type', - ); + ]; $this->callAPIFailure('activity', 'create', $params); } @@ -228,7 +228,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * got added to the set up routine. Probably a mis-fix on a test */ public function testActivityCreateWithNonNumericActivityTypeId() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), @@ -237,7 +237,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_type_id' => 'Invalid Test activity type', - ); + ]; $this->callAPIFailure('activity', 'create', $params); } @@ -259,7 +259,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { } public function testActivityCreateWithInvalidPriority() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), @@ -269,7 +269,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'priority_id' => 44, 'activity_type_id' => 1, - ); + ]; $result = $this->callAPIFailure('activity', 'create', $params, "'44' is not a valid option for field priority_id"); @@ -280,7 +280,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test create succeeds with valid string for priority. */ public function testActivityCreateWithValidStringPriority() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), @@ -290,7 +290,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'priority_id' => 'Urgent', 'activity_type_id' => 1, - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals(1, $result['values'][$result['id']]['priority_id']); @@ -300,7 +300,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test create fails with invalid priority string. */ public function testActivityCreateWithInValidStringPriority() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), @@ -310,7 +310,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'priority_id' => 'ergUrgent', 'activity_type_id' => 1, - ); + ]; $this->callAPIFailure('activity', 'create', $params, "'ergUrgent' is not a valid option for field priority_id"); @@ -341,7 +341,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->_apiversion = $version; $this->enableCiviCampaign(); - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', @@ -350,11 +350,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_type_id' => 29, - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); - $result = $this->callAPISuccess('activity', 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess('activity', 'getsingle', ['id' => $result['id']]); $this->assertEquals($result['duration'], 120); $this->assertEquals($result['subject'], 'Make-it-Happen Meeting'); $this->assertEquals($result['activity_date_time'], '2011-03-16 00:00:00'); @@ -362,7 +362,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->assertEquals($result['details'], 'a test activity'); $this->assertEquals($result['status_id'], 1); - $priorities = $this->callAPISuccess('activity', 'getoptions', array('field' => 'priority_id')); + $priorities = $this->callAPISuccess('activity', 'getoptions', ['field' => 'priority_id']); $this->assertEquals($result['priority_id'], array_search('Normal', $priorities['values'])); } @@ -373,7 +373,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $description = "Demonstrates setting & retrieving activity target & source."; $subfile = "GetTargetandAssignee"; - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', @@ -385,15 +385,15 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'priority_id' => 1, 'target_contact_id' => $this->_contactID, 'assignee_contact_id' => $this->_contactID, - ); + ]; $result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPISuccess('activity', 'get', array( + $result = $this->callAPISuccess('activity', 'get', [ 'id' => $result['id'], 'version' => $this->_apiversion, 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1, - )); + ]); $this->assertEquals($this->_contactID, $result['values'][$result['id']]['assignee_contact_id'][0]); $this->assertEquals($this->_contactID, $result['values'][$result['id']]['target_contact_id'][0]); @@ -406,26 +406,26 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $description = "Demonstrates retrieving activity target & source contact names."; $subfile = "GetTargetandAssigneeName"; - $target1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'A', 'last_name' => 'Cat')); - $target2 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'B', 'last_name' => 'Good')); - $assignee = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'C', 'last_name' => 'Shore')); - $source = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'D', 'last_name' => 'Bug')); + $target1 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'A', 'last_name' => 'Cat']); + $target2 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'B', 'last_name' => 'Good']); + $assignee = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'C', 'last_name' => 'Shore']); + $source = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'D', 'last_name' => 'Bug']); - $params = array( + $params = [ 'source_contact_id' => $source['id'], 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20170316', 'status_id' => 1, 'activity_type_id' => 1, - 'target_contact_id' => array($target1['id'], $target2['id']), + 'target_contact_id' => [$target1['id'], $target2['id']], 'assignee_contact_id' => $assignee['id'], - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); - $result = $this->callAPIAndDocument('activity', 'getsingle', array( + $result = $this->callAPIAndDocument('activity', 'getsingle', [ 'id' => $result['id'], - 'return' => array('source_contact_name', 'target_contact_name', 'assignee_contact_name', 'subject'), - ), __FUNCTION__, __FILE__, $description, $subfile); + 'return' => ['source_contact_name', 'target_contact_name', 'assignee_contact_name', 'subject'], + ], __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($params['subject'], $result['subject']); $this->assertEquals($source['id'], $result['source_contact_id']); @@ -444,10 +444,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); @@ -474,19 +474,19 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateCustomSubType() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); - $this->callAPISuccess('CustomGroup', 'create', array( + $this->callAPISuccess('CustomGroup', 'create', [ 'extends_entity_column_value' => $this->test_activity_type_value, 'id' => $ids['custom_group_id'], 'extends' => 'Activity', 'is_active' => TRUE, - )); + ]); $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); $this->customFieldDelete($ids['custom_field_id']); @@ -498,11 +498,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateCustomContactRefField() { - $this->callAPISuccess('contact', 'create', array('id' => $this->_contactID, 'sort_name' => 'Contact, Test')); + $this->callAPISuccess('contact', 'create', ['id' => $this->_contactID, 'sort_name' => 'Contact, Test']); $subfile = 'ContactRefCustomField'; $description = "Demonstrates create with Contact Reference Custom Field."; $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); - $params = array( + $params = [ 'custom_group_id' => $ids['custom_group_id'], 'name' => 'Worker_Lookup', 'label' => 'Worker Lookup', @@ -511,17 +511,17 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'weight' => 4, 'is_searchable' => 1, 'is_active' => 1, - ); + ]; $customField = $this->callAPISuccess('custom_field', 'create', $params); $params = $this->_params; $params['custom_' . $customField['id']] = "$this->_contactID"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPIAndDocument($this->_entity, 'get', array( + $result = $this->callAPIAndDocument($this->_entity, 'get', [ 'return.custom_' . $customField['id'] => 1, 'id' => $result['id'], - ), __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet'); + ], __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet'); $this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id']]); $this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__); @@ -536,7 +536,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateBadTextStatus() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Discussion on Apis for v3', 'activity_date_time' => date('Ymd'), @@ -545,7 +545,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 'Invalid', 'activity_name' => 'Test activity type', - ); + ]; $this->callAPIFailure('activity', 'create', $params); } @@ -555,7 +555,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateSupportActivityStatus() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Discussion on Apis for v3', 'activity_date_time' => date('Ymd'), @@ -564,7 +564,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'activity_status_id' => 'Invalid', 'activity_name' => 'Test activity type', - ); + ]; $this->callAPIFailure('activity', 'create', $params, "'Invalid' is not a valid option for field status_id"); @@ -575,7 +575,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityCreateTextStatus() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), @@ -584,7 +584,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 'Scheduled', 'activity_name' => 'Test activity type', - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals($result['values'][$result['id']]['duration'], 120); @@ -598,7 +598,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activity_get() with no params */ public function testActivityGetEmpty() { - $this->callAPISuccess('activity', 'get', array()); + $this->callAPISuccess('activity', 'get', []); } /** @@ -610,26 +610,26 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $subfile = 'ReturnAssigneeContact'; $activity = $this->callAPISuccess('activity', 'create', $this->_params); - $contact = $this->callAPISuccess('Contact', 'Create', array( + $contact = $this->callAPISuccess('Contact', 'Create', [ 'first_name' => "The Rock", 'last_name' => 'roccky', 'contact_type' => 'Individual', 'version' => 3, - 'api.activity.create' => array( + 'api.activity.create' => [ 'id' => $activity['id'], 'assignee_contact_id' => '$value.id', - ), - )); + ], + ]); - $params = array( + $params = [ 'activity_id' => $activity['id'], 'version' => $this->_apiversion, 'sequential' => 1, 'return.assignee_contact_id' => 1, - 'api.contact.get' => array( + 'api.contact.get' => [ 'id' => '$value.source_contact_id', - ), - ); + ], + ]; $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); @@ -646,7 +646,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * test that get functioning does filtering. */ public function testGetFilter() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', @@ -656,12 +656,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'activity_name' => 'Test activity type', 'priority_id' => 1, - ); + ]; $result = $this->callAPISuccess('Activity', 'Create', $params); - $this->callAPISuccess('Activity', 'Get', array('subject' => 'Make-it-Happen Meeting')); + $this->callAPISuccess('Activity', 'Get', ['subject' => 'Make-it-Happen Meeting']); $this->assertEquals(1, $result['count']); $this->assertEquals('Make-it-Happen Meeting', $result['values'][$result['id']]['subject']); - $this->callAPISuccess('Activity', 'Delete', array('id' => $result['id'])); + $this->callAPISuccess('Activity', 'Delete', ['id' => $result['id']]); } /** @@ -669,7 +669,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityGetTargetFilter() { $params = $this->_params; - $contact1Params = array( + $contact1Params = [ 'first_name' => 'John', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -677,10 +677,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'john_anderson@civicrm.org', 'contact_type' => 'Individual', - ); + ]; $contact1 = $this->individualCreate($contact1Params); - $contact2Params = array( + $contact2Params = [ 'first_name' => 'Michal', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -688,29 +688,29 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'michal_anderson@civicrm.org', 'contact_type' => 'Individual', - ); + ]; $contact2 = $this->individualCreate($contact2Params); $this->callAPISuccess('OptionValue', 'get', ['name' => 'Activity Targets', 'api.OptionValue.create' => ['label' => 'oh so creative']]); - $params['assignee_contact_id'] = array($contact1, $contact2); - $params['target_contact_id'] = array($contact2 => $contact2); + $params['assignee_contact_id'] = [$contact1, $contact2]; + $params['target_contact_id'] = [$contact2 => $contact2]; $activity = $this->callAPISuccess('Activity', 'Create', $params); - $activityGet = $this->callAPISuccess('Activity', 'get', array( + $activityGet = $this->callAPISuccess('Activity', 'get', [ 'id' => $activity['id'], 'target_contact_id' => $contact2, 'return.target_contact_id' => 1, - )); + ]); $this->assertEquals($activity['id'], $activityGet['id']); $this->assertEquals($contact2, $activityGet['values'][$activityGet['id']]['target_contact_id'][0]); - $activityGet = $this->callAPISuccess('activity', 'get', array( + $activityGet = $this->callAPISuccess('activity', 'get', [ 'target_contact_id' => $this->_contactID, 'return.target_contact_id' => 1, 'id' => $activity['id'], - )); + ]); if ($activityGet['count'] > 0) { $this->assertNotEquals($contact2, $activityGet['values'][$activityGet['id']]['target_contact_id'][0]); } @@ -724,9 +724,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params = $this->_params; $params['subject'] = $subject; $this->callAPISuccess('Activity', 'Create', $params); - $activityGet = $this->callAPISuccess('activity', 'getsingle', array( + $activityGet = $this->callAPISuccess('activity', 'getsingle', [ 'subject' => $subject, - )); + ]); $this->assertEquals($activityGet['subject'], $subject); } @@ -738,9 +738,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params = $this->_params; $params['details'] = $details; $activity = $this->callAPISuccess('Activity', 'Create', $params); - $activityget = $this->callAPISuccess('activity', 'getsingle', array( + $activityget = $this->callAPISuccess('activity', 'getsingle', [ 'details' => $details, - )); + ]); $this->assertEquals($activityget['details'], $details); } @@ -748,12 +748,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test that activity.get api works when filtering on tag. */ public function testActivityGetTagFilter() { - $tag = $this->callAPISuccess('Tag', 'create', array('name' => mt_rand(), 'used_for' => 'Activities')); + $tag = $this->callAPISuccess('Tag', 'create', ['name' => mt_rand(), 'used_for' => 'Activities']); $activity = $this->callAPISuccess('Activity', 'Create', $this->_params); - $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id'])); - $activityget = $this->callAPISuccess('activity', 'getsingle', array( + $this->callAPISuccess('EntityTag', 'create', ['entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']]); + $activityget = $this->callAPISuccess('activity', 'getsingle', [ 'tag_id' => $tag['id'], - )); + ]); $this->assertEquals($activityget['id'], $activity['id']); } @@ -764,13 +764,13 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $tagName = 'act_tag_nm_' . mt_rand(); $tagDescription = 'act_tag_ds_' . mt_rand(); $tagColor = '#' . substr(md5(mt_rand()), 0, 6); - $tag = $this->callAPISuccess('Tag', 'create', array('name' => $tagName, 'color' => $tagColor, 'description' => $tagDescription, 'used_for' => 'Activities')); + $tag = $this->callAPISuccess('Tag', 'create', ['name' => $tagName, 'color' => $tagColor, 'description' => $tagDescription, 'used_for' => 'Activities']); $activity = $this->callAPISuccess('Activity', 'Create', $this->_params); - $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id'])); - $activityget = $this->callAPISuccess('activity', 'getsingle', array( + $this->callAPISuccess('EntityTag', 'create', ['entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']]); + $activityget = $this->callAPISuccess('activity', 'getsingle', [ 'id' => $activity['id'], - 'return' => array('tag_id.name', 'tag_id.description', 'tag_id.color'), - )); + 'return' => ['tag_id.name', 'tag_id.description', 'tag_id.color'], + ]); $this->assertEquals($tagName, $activityget['tag_id'][$tag['id']]['tag_id.name']); $this->assertEquals($tagColor, $activityget['tag_id'][$tag['id']]['tag_id.color']); $this->assertEquals($tagDescription, $activityget['tag_id'][$tag['id']]['tag_id.description']); @@ -782,18 +782,18 @@ class api_v3_ActivityTest extends CiviUnitTestCase { public function testActivityGetFile() { $activity = $this->callAPISuccess('Activity', 'create', $this->_params); $activity2 = $this->callAPISuccess('Activity', 'create', $this->_params2); - $file = $this->callAPISuccess('Attachment', 'create', array( + $file = $this->callAPISuccess('Attachment', 'create', [ 'name' => 'actAttachment.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $activity2['id'], - )); - $activityget = $this->callAPISuccess('activity', 'getsingle', array( + ]); + $activityget = $this->callAPISuccess('activity', 'getsingle', [ 'file_id' => $file['id'], 'return' => 'file_id', - )); + ]); $this->assertEquals($activityget['id'], $activity2['id']); $this->assertEquals($file['id'], $activityget['file_id'][0]); } @@ -802,7 +802,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * test that get functioning does filtering. */ public function testGetStatusID() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', @@ -812,20 +812,20 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'activity_name' => 'Test activity type', 'priority_id' => 1, - ); + ]; $this->callAPISuccess('Activity', 'Create', $params); - $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '1')); + $result = $this->callAPISuccess('Activity', 'Get', ['activity_status_id' => '1']); $this->assertEquals(1, $result['count'], 'one activity of status 1 should exist'); - $result = $this->callAPISuccess('Activity', 'Get', array('status_id' => '1')); + $result = $this->callAPISuccess('Activity', 'Get', ['status_id' => '1']); $this->assertEquals(1, $result['count'], 'status_id should also work'); - $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '2')); + $result = $this->callAPISuccess('Activity', 'Get', ['activity_status_id' => '2']); $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); - $result = $this->callAPISuccess('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', [ 'version' => $this->_apiversion, 'status_id' => '2', - )); + ]); $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); } @@ -834,7 +834,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * test that get functioning does filtering. */ public function testGetFilterMaxDate() { - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110101', @@ -845,39 +845,39 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Test activity type', 'version' => $this->_apiversion, 'priority_id' => 1, - ); + ]; $activityOne = $this->callAPISuccess('Activity', 'Create', $params); $params['activity_date_time'] = 20120216; $activityTwo = $this->callAPISuccess('Activity', 'Create', $params); - $result = $this->callAPISuccess('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', [ 'version' => 3, - )); + ]); $description = "Demonstrates _low filter (at time of writing doesn't work if contact_id is set."; $subfile = "DateTimeLow"; $this->assertEquals(2, $result['count']); - $params = array( + $params = [ 'version' => 3, 'filter.activity_date_time_low' => '20120101000000', 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['count']); $description = "Demonstrates _high filter (at time of writing doesn't work if contact_id is set."; $subfile = "DateTimeHigh"; $this->assertEquals('2012-02-16 00:00:00', $result['values'][0]['activity_date_time']); - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'version' => 3, 'filter.activity_date_time_high' => '20120101000000', 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['count']); $this->assertEquals('2011-01-01 00:00:00', $result['values'][0]['activity_date_time']); - $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityOne['id'])); - $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityTwo['id'])); + $this->callAPISuccess('Activity', 'Delete', ['version' => 3, 'id' => $activityOne['id']]); + $this->callAPISuccess('Activity', 'Delete', ['version' => 3, 'id' => $activityTwo['id']]); } /** @@ -893,11 +893,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', $params); // Retrieve the test value. - $params = array( + $params = [ 'activity_type_id' => $this->test_activity_type_value, 'sequential' => 1, 'return.custom_' . $ids['custom_field_id'] => 1, - ); + ]; $result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']]); @@ -919,12 +919,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $result = $this->callAPISuccess($this->_entity, 'create', $params); // Retrieve the test value - $params = array( + $params = [ 'contact_id' => $this->_params['source_contact_id'], 'activity_type_id' => $this->test_activity_type_value, 'sequential' => 1, 'return.custom_' . $ids['custom_field_id'] => 1, - ); + ]; $result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); @@ -970,12 +970,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activity_update() with non-numeric id */ public function testActivityUpdateWithNonNumericId() { - $params = array( + $params = [ 'id' => 'lets break it', 'activity_name' => 'Meeting', 'subject' => 'this case should fail', 'scheduled_date_time' => date('Ymd'), - ); + ]; $result = $this->callAPIFailure('activity', 'create', $params); } @@ -984,13 +984,13 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Check with incorrect required fields. */ public function testActivityUpdateWithIncorrectContactActivityType() { - $params = array( + $params = [ 'id' => 1, 'activity_name' => 'Test Activity', 'subject' => 'this case should fail', 'scheduled_date_time' => date('Ymd'), 'source_contact_id' => $this->_contactID, - ); + ]; $result = $this->callAPIFailure('activity', 'create', $params, 'Invalid Activity Id'); @@ -1003,7 +1003,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $result = $this->callAPISuccess('activity', 'create', $this->_params); $this->_contactID2 = $this->individualCreate(); - $params = array( + $params = [ 'id' => $result['id'], 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20091011123456', @@ -1014,7 +1014,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'source_contact_id' => $this->_contactID, 'assignee_contact_id' => $this->_contactID2, 'priority_id' => 1, - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); //hack on date comparison - really we should make getAndCheck smarter to handle dates @@ -1022,24 +1022,24 @@ class api_v3_ActivityTest extends CiviUnitTestCase { // we also unset source_contact_id since it is stored in an aux table unset($params['source_contact_id']); //Check if assignee created. - $assignee = $this->callAPISuccess('ActivityContact', 'get', array( + $assignee = $this->callAPISuccess('ActivityContact', 'get', [ 'activity_id' => $result['id'], - 'return' => array("contact_id"), + 'return' => ["contact_id"], 'record_type_id' => "Activity Assignees", - )); + ]); $this->assertNotEmpty($assignee['values']); //clear assignee contacts. - $updateParams = array( + $updateParams = [ 'id' => $result['id'], - 'assignee_contact_id' => array(), - ); + 'assignee_contact_id' => [], + ]; $activity = $this->callAPISuccess('activity', 'create', $updateParams); - $assignee = $this->callAPISuccess('ActivityContact', 'get', array( + $assignee = $this->callAPISuccess('ActivityContact', 'get', [ 'activity_id' => $activity['id'], - 'return' => array("contact_id"), + 'return' => ["contact_id"], 'record_type_id' => "Activity Assignees", - )); + ]); $this->assertEmpty($assignee['values']); $this->getAndCheck($params, $result['id'], 'activity'); } @@ -1055,7 +1055,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { // Create an activity with custom data //this has been updated from the previous 'old format' function - need to make it work - $params = array( + $params = [ 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '2009-10-18', @@ -1066,22 +1066,22 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Test activity type', 'version' => $this->_apiversion, 'custom_' . $ids['custom_field_id'] => 'custom string', - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $activityId = $result['id']; - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); $this->assertEquals("2009-10-18 00:00:00", $result['values'][$result['id']]['activity_date_time']); - $fields = $this->callAPISuccess('activity', 'getfields', array('version' => $this->_apiversion)); + $fields = $this->callAPISuccess('activity', 'getfields', ['version' => $this->_apiversion]); $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']])); // Update the activity with custom data. - $params = array( + $params = [ 'id' => $activityId, 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', @@ -1091,14 +1091,14 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_date_time' => date('Ymd'), 'custom_' . $ids['custom_field_id'] => 'Updated my test data', 'version' => $this->_apiversion, - ); + ]; $result = $this->callAPISuccess('Activity', 'Create', $params); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id'], - )); + ]); $this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); } @@ -1108,7 +1108,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityUpdateCheckCoreFields() { $params = $this->_params; - $contact1Params = array( + $contact1Params = [ 'first_name' => 'John', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -1116,10 +1116,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'john_anderson@civicrm.org', 'contact_type' => 'Individual', - ); + ]; $contact1 = $this->individualCreate($contact1Params); - $contact2Params = array( + $contact2Params = [ 'first_name' => 'Michal', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -1127,21 +1127,21 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'michal_anderson@civicrm.org', 'contact_type' => 'Individual', - ); + ]; $contact2 = $this->individualCreate($contact2Params); - $params['assignee_contact_id'] = array($contact1, $contact2); - $params['target_contact_id'] = array($contact2 => $contact2); + $params['assignee_contact_id'] = [$contact1, $contact2]; + $params['target_contact_id'] = [$contact2 => $contact2]; $result = $this->callAPISuccess('Activity', 'Create', $params); $activityId = $result['id']; - $getParams = array( + $getParams = [ 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1, 'version' => $this->_apiversion, 'id' => $activityId, - ); + ]; $result = $this->callAPISuccess($this->_entity, 'get', $getParams); $assignee = $result['values'][$result['id']]['assignee_contact_id']; $target = $result['values'][$result['id']]['target_contact_id']; @@ -1150,7 +1150,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->assertEquals(TRUE, in_array($contact1, $assignee), ' in line ' . __LINE__); $this->assertEquals(TRUE, in_array($contact2, $target), ' in line ' . __LINE__); - $contact3Params = array( + $contact3Params = [ 'first_name' => 'Jijo', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -1158,9 +1158,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'jijo_anderson@civicrm.org', 'contact_type' => 'Individual', - ); + ]; - $contact4Params = array( + $contact4Params = [ 'first_name' => 'Grant', 'middle_name' => 'J.', 'last_name' => 'Anderson', @@ -1168,15 +1168,15 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'grant_anderson@civicrm.org', 'contact_type' => 'Individual', - ); + ]; $contact3 = $this->individualCreate($contact3Params); $contact4 = $this->individualCreate($contact4Params); - $params = array(); + $params = []; $params['id'] = $activityId; - $params['assignee_contact_id'] = array($contact3 => $contact3); - $params['target_contact_id'] = array($contact4 => $contact4); + $params['assignee_contact_id'] = [$contact3 => $contact3]; + $params['target_contact_id'] = [$contact4 => $contact4]; $result = $this->callAPISuccess('activity', 'create', $params); @@ -1185,12 +1185,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $result = $this->callAPISuccess( $this->_entity, 'get', - array( + [ 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1, 'return.source_contact_id' => 1, 'id' => $result['id'], - ) + ] ); $assignee = $result['values'][$result['id']]['assignee_contact_id']; @@ -1213,7 +1213,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { public function testActivityUpdateNotDate() { $result = $this->callAPISuccess('activity', 'create', $this->_params); - $params = array( + $params = [ 'id' => $result['id'], 'subject' => 'Make-it-Happen Meeting', 'duration' => 120, @@ -1222,7 +1222,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'source_contact_id' => $this->_contactID, 'priority_id' => 1, - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); //hack on date comparison - really we should make getAndCheck smarter to handle dates @@ -1237,13 +1237,13 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testActivityUpdateWithStatus() { $activity = $this->callAPISuccess('activity', 'create', $this->_params); - $params = array( + $params = [ 'id' => $activity['id'], 'source_contact_id' => $this->_contactID, 'subject' => 'Hurry update works', 'status_id' => 1, 'activity_name' => 'Test activity type', - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals($result['id'], $activity['id']); @@ -1260,7 +1260,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $activity = $this->callAPISuccess('activity', 'create', $this->_params); // Updating the activity but not providing anything for the source contact // (It was set as $this->_contactID earlier.) - $params = array( + $params = [ 'id' => $activity['id'], 'subject' => 'Updated Make-it-Happen Meeting', 'duration' => 120, @@ -1269,10 +1269,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'activity_name' => 'Test activity type', 'priority_id' => 1, - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); - $findactivity = $this->callAPISuccess('Activity', 'Get', array('id' => $activity['id'])); + $findactivity = $this->callAPISuccess('Activity', 'Get', ['id' => $activity['id']]); } /** @@ -1282,9 +1282,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $activity = $this->callAPISuccess('activity', 'create', $this->_params); $activity2 = $this->callAPISuccess('activity', 'create', $this->_params2); // Get activities associated with contact $this->_contactID. - $params = array( + $params = [ 'contact_id' => $this->_contactID, - ); + ]; $result = $this->callAPISuccess('activity', 'get', $params); $this->assertEquals(2, $result['count']); @@ -1298,35 +1298,35 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ public function testChainedActivityGet() { - $activity = $this->callAPISuccess('Contact', 'Create', array( + $activity = $this->callAPISuccess('Contact', 'Create', [ 'display_name' => "bob brown", 'contact_type' => 'Individual', - 'api.activity_type.create' => array( + 'api.activity_type.create' => [ 'weight' => '2', 'label' => 'send out letters', 'filter' => 0, 'is_active' => 1, 'is_optgroup' => 1, 'is_default' => 0, - ), - 'api.activity.create' => array( + ], + 'api.activity.create' => [ 'subject' => 'send letter', 'activity_type_id' => '$value.api.activity_type.create.values.0.value', - ), - )); + ], + ]); - $result = $this->callAPISuccess('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', [ 'id' => $activity['id'], 'return.assignee_contact_id' => 1, - 'api.contact.get' => array('api.pledge.get' => 1), - )); + 'api.contact.get' => ['api.pledge.get' => 1], + ]); } /** * Test civicrm_activity_contact_get() with invalid Contact ID. */ public function testActivitiesContactGetWithInvalidContactId() { - $params = array('contact_id' => 'contact'); + $params = ['contact_id' => 'contact']; $this->callAPIFailure('activity', 'get', $params); } @@ -1334,17 +1334,17 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activity_contact_get() with contact having no Activity. */ public function testActivitiesContactGetHavingNoActivity() { - $params = array( + $params = [ 'first_name' => 'dan', 'last_name' => 'conberg', 'email' => 'dan.conberg@w.co.in', 'contact_type' => 'Individual', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $result = $this->callAPISuccess('activity', 'get', $params); $this->assertEquals($result['count'], 0); } @@ -1353,7 +1353,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test getfields function. */ public function testGetFields() { - $params = array('action' => 'create'); + $params = ['action' => 'create']; $result = $this->callAPIAndDocument('activity', 'getfields', $params, __FUNCTION__, __FILE__, NULL, NULL); $this->assertTrue(is_array($result['values']), 'get fields doesn\'t return values array'); foreach ($result['values'] as $key => $value) { @@ -1365,31 +1365,31 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test or operator in api params */ public function testGetWithOr() { - $acts = array( + $acts = [ 'test or 1' => 'orOperator', 'test or 2' => 'orOperator', 'test or 3' => 'nothing', - ); + ]; foreach ($acts as $subject => $details) { $params = $this->_params; $params['subject'] = $subject; $params['details'] = $details; $this->callAPISuccess('Activity', 'create', $params); } - $result = $this->callAPISuccess('Activity', 'get', array( + $result = $this->callAPISuccess('Activity', 'get', [ 'details' => 'orOperator', - )); + ]); $this->assertEquals(2, $result['count']); - $result = $this->callAPISuccess('Activity', 'get', array( + $result = $this->callAPISuccess('Activity', 'get', [ 'details' => 'orOperator', 'subject' => 'test or 3', - )); + ]); $this->assertEquals(0, $result['count']); - $result = $this->callAPISuccess('Activity', 'get', array( + $result = $this->callAPISuccess('Activity', 'get', [ 'details' => 'orOperator', 'subject' => 'test or 3', - 'options' => array('or' => array(array('details', 'subject'))), - )); + 'options' => ['or' => [['details', 'subject']]], + ]); $this->assertEquals(3, $result['count']); } @@ -1397,27 +1397,27 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test handling of is_overdue calculated field */ public function testGetOverdue() { - $overdueAct = $this->callAPISuccess('Activity', 'create', array( + $overdueAct = $this->callAPISuccess('Activity', 'create', [ 'activity_date_time' => 'now - 1 week', 'status_id' => 'Scheduled', - ) + $this->_params); - $completedAct = $this->callAPISuccess('Activity', 'create', array( + ] + $this->_params); + $completedAct = $this->callAPISuccess('Activity', 'create', [ 'activity_date_time' => 'now - 1 week', 'status_id' => 'Completed', - ) + $this->_params); - $ids = array($overdueAct['id'], $completedAct['id']); + ] + $this->_params); + $ids = [$overdueAct['id'], $completedAct['id']]; // Test sorting - $completedFirst = $this->callAPISuccess('Activity', 'get', array( - 'id' => array('IN' => $ids), - 'options' => array('sort' => 'is_overdue ASC'), - )); + $completedFirst = $this->callAPISuccess('Activity', 'get', [ + 'id' => ['IN' => $ids], + 'options' => ['sort' => 'is_overdue ASC'], + ]); $this->assertEquals(array_reverse($ids), array_keys($completedFirst['values'])); - $overdueFirst = $this->callAPISuccess('Activity', 'get', array( - 'id' => array('IN' => $ids), - 'options' => array('sort' => 'is_overdue DESC'), + $overdueFirst = $this->callAPISuccess('Activity', 'get', [ + 'id' => ['IN' => $ids], + 'options' => ['sort' => 'is_overdue DESC'], 'return' => 'is_overdue', - )); + ]); $this->assertEquals($ids, array_keys($overdueFirst['values'])); // Test return value @@ -1425,11 +1425,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->assertEquals(0, $overdueFirst['values'][$completedAct['id']]['is_overdue']); // Test filtering - $onlyOverdue = $this->callAPISuccess('Activity', 'get', array( - 'id' => array('IN' => $ids), + $onlyOverdue = $this->callAPISuccess('Activity', 'get', [ + 'id' => ['IN' => $ids], 'is_overdue' => 1, - )); - $this->assertEquals(array($overdueAct['id']), array_keys($onlyOverdue['values'])); + ]); + $this->assertEquals([$overdueAct['id']], array_keys($onlyOverdue['values'])); } } diff --git a/tests/phpunit/api/v3/ActivityTypeTest.php b/tests/phpunit/api/v3/ActivityTypeTest.php index 4388b9545d..9fbf0bba9c 100644 --- a/tests/phpunit/api/v3/ActivityTypeTest.php +++ b/tests/phpunit/api/v3/ActivityTypeTest.php @@ -45,7 +45,7 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase { * Test civicrm_activity_type_get(). */ public function testActivityTypeGet() { - $params = array(); + $params = []; $result = $this->callAPIAndDocument('activity_type', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values']['1'], 'Meeting'); } @@ -54,14 +54,14 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase { * Test civicrm_activity_type_create(). */ public function testActivityTypeCreate() { - $params = array( + $params = [ 'weight' => '2', 'label' => 'send out letters', 'filter' => 0, 'is_active' => 1, 'is_optgroup' => 1, 'is_default' => 0, - ); + ]; $result = $this->callAPIAndDocument('activity_type', 'create', $params, __FUNCTION__, __FILE__); } @@ -69,10 +69,10 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase { * Test civicrm_activity_type_create - check id */ public function testActivityTypecreatecheckId() { - $params = array( + $params = [ 'label' => 'type_create', 'weight' => '2', - ); + ]; $activitycreate = $this->callAPISuccess('activity_type', 'create', $params); $this->assertArrayHasKey('id', $activitycreate); $this->assertArrayHasKey('option_group_id', $activitycreate['values'][$activitycreate['id']]); @@ -82,14 +82,14 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase { * Test civicrm_activity_type_delete() */ public function testActivityTypeDelete() { - $params = array( + $params = [ 'label' => 'type_create_delete', 'weight' => '2', - ); + ]; $activitycreate = $this->callAPISuccess('activity_type', 'create', $params); - $params = array( + $params = [ 'activity_type_id' => $activitycreate['id'], - ); + ]; $result = $this->callAPISuccess('activity_type', 'delete', $params, __FUNCTION__, __FILE__); } diff --git a/tests/phpunit/api/v3/AddressTest.php b/tests/phpunit/api/v3/AddressTest.php index c7f28d3132..ee7bc0ab4a 100644 --- a/tests/phpunit/api/v3/AddressTest.php +++ b/tests/phpunit/api/v3/AddressTest.php @@ -51,7 +51,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->_locationType = $this->locationTypeCreate(); CRM_Core_PseudoConstant::flush(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, 'street_name' => 'Ambachtstraat', @@ -61,13 +61,13 @@ class api_v3_AddressTest extends CiviUnitTestCase { 'country_id' => '1152', 'city' => 'Brummen', 'is_primary' => 1, - ); + ]; } public function tearDown() { $this->locationTypeDelete($this->_locationType->id); $this->contactDelete($this->_contactID); - $this->quickCleanup(array('civicrm_address', 'civicrm_relationship')); + $this->quickCleanup(['civicrm_address', 'civicrm_relationship']); parent::tearDown(); } @@ -89,12 +89,12 @@ class api_v3_AddressTest extends CiviUnitTestCase { */ public function testCreateAddressParsing($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'street_parsing' => 1, 'street_address' => '54A Excelsior Ave. Apt 1C', 'location_type_id' => $this->_locationType->id, 'contact_id' => $this->_contactID, - ); + ]; $subfile = "AddressParse"; $description = "Demonstrates Use of address parsing param."; $result = $this->callAPIAndDocument('address', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); @@ -102,7 +102,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->assertEquals('A', $result['values'][$result['id']]['street_number_suffix']); $this->assertEquals('Excelsior Ave.', $result['values'][$result['id']]['street_name']); $this->assertEquals('Apt 1C', $result['values'][$result['id']]['street_unit']); - $this->callAPISuccess('address', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $result['id']]); } @@ -138,17 +138,17 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testCreateAddressWithMasterRelationshipHousehold($version) { $this->_apiversion = $version; $householdID = $this->householdCreate(); - $address = $this->callAPISuccess('address', 'create', array_merge($this->_params, $this->_params, array('contact_id' => $householdID))); + $address = $this->callAPISuccess('address', 'create', array_merge($this->_params, $this->_params, ['contact_id' => $householdID])); $individualID = $this->individualCreate(); - $individualParams = array( + $individualParams = [ 'contact_id' => $individualID, 'master_id' => $address['id'], - ); + ]; $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams)); - $this->callAPISuccess('relationship', 'getcount', array( + $this->callAPISuccess('relationship', 'getcount', [ 'contact_id_a' => $individualID, 'contact_id_b' => $this->_contactID, - )); + ]); } /** @@ -160,15 +160,15 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->_apiversion = $version; $address = $this->callAPISuccess('address', 'create', $this->_params); $individualID = $this->individualCreate(); - $individualParams = array( + $individualParams = [ 'contact_id' => $individualID, 'master_id' => $address['id'], - ); + ]; $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams)); - $this->callAPISuccess('relationship', 'getcount', array( + $this->callAPISuccess('relationship', 'getcount', [ 'contact_id_a' => $individualID, 'contact_id_b' => $this->_contactID, - ), 1); + ], 1); } /** @@ -180,16 +180,16 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->_apiversion = $version; $address = $this->callAPISuccess('address', 'create', $this->_params); $individualID = $this->individualCreate(); - $individualParams = array( + $individualParams = [ 'contact_id' => $individualID, 'master_id' => $address['id'], 'update_current_employer' => 0, - ); + ]; $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams)); - $this->callAPISuccess('relationship', 'getcount', array( + $this->callAPISuccess('relationship', 'getcount', [ 'contact_id_a' => $individualID, 'contact_id_b' => $this->_contactID, - ), 0); + ], 0); } /** @@ -201,24 +201,24 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->_apiversion = $version; $address = $this->callAPISuccess('address', 'create', $this->_params); $organisation2ID = $this->organizationCreate(); - $address2 = $this->callAPISuccess('address', 'create', array_merge($this->_params, array('contact_id' => $organisation2ID))); + $address2 = $this->callAPISuccess('address', 'create', array_merge($this->_params, ['contact_id' => $organisation2ID])); $individualID = $this->individualCreate(); - $individualParams = array_merge($this->_params, array( + $individualParams = array_merge($this->_params, [ 'contact_id' => $individualID, 'master_id' => $address['id'], - )); + ]); $individualAddress = $this->callAPISuccess('address', 'create', $individualParams); $individualParams['master_id'] = $address2['id']; $individualParams['id'] = $individualAddress['id']; $this->callAPISuccess('address', 'create', $individualParams); - $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID), 2); + $this->callAPISuccessGetCount('relationship', ['contact_id_a' => $individualID], 2); $this->markTestIncomplete('Remainder of test checks that employer relationship is disabled when new one is created but turns out to be not happening - by design?'); - $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID, 'is_active' => FALSE), 1); - $this->callAPISuccessGetCount('relationship', array( + $this->callAPISuccessGetCount('relationship', ['contact_id_a' => $individualID, 'is_active' => FALSE], 1); + $this->callAPISuccessGetCount('relationship', [ 'contact_id_a' => $individualID, 'is_active' => TRUE, 'contact_id_b' => $organisation2ID, - ), 1); + ], 1); } @@ -239,7 +239,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { unset($params['is_primary']); $params['id'] = $result['id']; $this->callAPISuccess('address', 'create', $params); - $result = $this->callAPISuccess('address', 'get', array('contact_id' => $params['contact_id'])); + $result = $this->callAPISuccess('address', 'get', ['contact_id' => $params['contact_id']]); $this->assertEquals(1, $result['count']); $this->assertEquals(1, $result['values'][$result['id']]['is_primary']); $this->getAndCheck($params, $result['id'], 'address', __FUNCTION__); @@ -253,19 +253,19 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testDeleteAddress($version) { $this->_apiversion = $version; //check there are no address to start with - $get = $this->callAPISuccess('address', 'get', array( + $get = $this->callAPISuccess('address', 'get', [ 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(0, $get['count'], 'Contact already exists '); //create one $create = $this->callAPISuccess('address', 'create', $this->_params); - $result = $this->callAPIAndDocument('address', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('address', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $get = $this->callAPISuccess('address', 'get', array( + $get = $this->callAPISuccess('address', 'get', [ 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__); } @@ -278,12 +278,12 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->_apiversion = $version; $address = $this->callAPISuccess('address', 'create', $this->_params); - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'street_name' => $address['values'][$address['id']]['street_name'], - ); + ]; $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__); - $this->callAPISuccess('Address', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('Address', 'delete', ['id' => $result['id']]); $this->assertEquals($address['values'][$address['id']]['location_type_id'], $result['values'][$address['id']]['location_type_id']); $this->assertEquals($address['values'][$address['id']]['is_primary'], $result['values'][$address['id']]['is_primary']); $this->assertEquals($address['values'][$address['id']]['street_address'], $result['values'][$address['id']]['street_address']); @@ -297,12 +297,12 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testGetSingleAddress($version) { $this->_apiversion = $version; $this->callAPISuccess('address', 'create', $this->_params); - $params = array( + $params = [ 'contact_id' => $this->_contactID, - ); + ]; $address = $this->callAPISuccess('Address', 'getsingle', ($params)); $this->assertEquals($address['location_type_id'], $this->_params['location_type_id']); - $this->callAPISuccess('address', 'delete', array('id' => $address['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $address['id']]); } /** @@ -313,20 +313,20 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testGetAddressSort($version) { $this->_apiversion = $version; $create = $this->callAPISuccess('address', 'create', $this->_params); - $this->callAPISuccess('address', 'create', array_merge($this->_params, array('street_address' => 'yzy'))); + $this->callAPISuccess('address', 'create', array_merge($this->_params, ['street_address' => 'yzy'])); $subfile = "AddressSort"; $description = "Demonstrates Use of sort filter."; - $params = array( - 'options' => array( + $params = [ + 'options' => [ 'sort' => 'street_address DESC', 'limit' => 2, - ), + ], 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(2, $result['count']); $this->assertEquals('Ambachtstraat 23', $result['values'][1]['street_address']); - $this->callAPISuccess('address', 'delete', array('id' => $create['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $create['id']]); } /** @@ -339,14 +339,14 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->callAPISuccess('address', 'create', $this->_params); $subfile = "AddressLike"; $description = "Demonstrates Use of Like."; - $params = array( - 'street_address' => array('LIKE' => '%mb%'), + $params = [ + 'street_address' => ['LIKE' => '%mb%'], 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['count']); $this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address']); - $this->callAPISuccess('address', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $result['id']]); } /** @@ -357,13 +357,13 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testGetAddressLikeFail($version) { $this->_apiversion = $version; $create = $this->callAPISuccess('address', 'create', $this->_params); - $params = array( - 'street_address' => array('LIKE' => "'%xy%'"), + $params = [ + 'street_address' => ['LIKE' => "'%xy%'"], 'sequential' => 1, - ); + ]; $result = $this->callAPISuccess('Address', 'Get', ($params)); $this->assertEquals(0, $result['count']); - $this->callAPISuccess('address', 'delete', array('id' => $create['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $create['id']]); } /** @@ -377,14 +377,14 @@ class api_v3_AddressTest extends CiviUnitTestCase { $result = $this->callAPISuccess($this->_entity, 'create', $params); - $getParams = array('id' => $result['id'], 'return' => array('custom')); + $getParams = ['id' => $result['id'], 'return' => ['custom']]; $check = $this->callAPISuccess($this->_entity, 'get', $getParams); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); - $this->callAPISuccess('address', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $result['id']]); } /** @@ -398,12 +398,12 @@ class api_v3_AddressTest extends CiviUnitTestCase { $address1 = $this->callAPISuccess('address', 'create', $params); $this->assertApiSuccess($address1); //now we check & make sure it has been set to primary - $check = $this->callAPISuccess('address', 'getcount', array( + $check = $this->callAPISuccess('address', 'getcount', [ 'is_primary' => 1, 'id' => $address1['id'], - )); + ]); $this->assertEquals(1, $check); - $this->callAPISuccess('address', 'delete', array('id' => $address1['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $address1['id']]); } /** @@ -414,12 +414,12 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->_apiversion = $version; $address1 = $this->callAPISuccess('address', 'create', $this->_params); $this->callAPISuccess('address', 'create', $this->_params); - $check = $this->callAPISuccess('address', 'getcount', array( + $check = $this->callAPISuccess('address', 'getcount', [ 'is_primary' => 1, 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(1, $check); - $this->callAPISuccess('address', 'delete', array('id' => $address1['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $address1['id']]); } /** @@ -431,36 +431,36 @@ class api_v3_AddressTest extends CiviUnitTestCase { */ public function testCreateDuplicateLocationTypes() { $address1 = $this->callAPISuccess('address', 'create', $this->_params); - $address2 = $this->callAPISuccess('address', 'create', array( + $address2 = $this->callAPISuccess('address', 'create', [ 'location_type_id' => $this->_locationType->id, 'street_address' => '1600 Pensilvania Avenue', 'city' => 'Washington DC', 'is_primary' => 0, 'is_billing' => 0, 'contact_id' => $this->_contactID, - )); - $check = $this->callAPISuccess('address', 'getcount', array( + ]); + $check = $this->callAPISuccess('address', 'getcount', [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(2, $check); - $this->callAPISuccess('address', 'delete', array('id' => $address1['id'])); - $this->callAPISuccess('address', 'delete', array('id' => $address2['id'])); + $this->callAPISuccess('address', 'delete', ['id' => $address1['id']]); + $this->callAPISuccess('address', 'delete', ['id' => $address2['id']]); } public function testGetWithJoin() { - $cid = $this->individualCreate(array( - 'api.Address.create' => array( + $cid = $this->individualCreate([ + 'api.Address.create' => [ 'street_address' => __FUNCTION__, 'location_type_id' => $this->_locationType->id, - ), - )); - $result = $this->callAPISuccess('address', 'getsingle', array( + ], + ]); + $result = $this->callAPISuccess('address', 'getsingle', [ 'check_permissions' => TRUE, 'contact_id' => $cid, 'street_address' => __FUNCTION__, 'return' => 'contact_id.contact_type', - )); + ]); $this->assertEquals('Individual', $result['contact_id.contact_type']); } diff --git a/tests/phpunit/api/v3/AttachmentTest.php b/tests/phpunit/api/v3/AttachmentTest.php index 9bb5c29dc7..89c94611f9 100644 --- a/tests/phpunit/api/v3/AttachmentTest.php +++ b/tests/phpunit/api/v3/AttachmentTest.php @@ -64,42 +64,42 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { */ public function okCreateProvider() { // array($entityClass, $createParams, $expectedContent) - $cases = array(); + $cases = []; - $cases[] = array( + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', - ), + ], 'My test content', - ); + ]; - $cases[] = array( + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => self::getFilePrefix() . 'exampleWithEmptyContent.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => '', - ), + ], '', - ); + ]; - $cases[] = array( + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => self::getFilePrefix() . 'exampleFromMove.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', - 'options' => array( + 'options' => [ 'move-file' => $this->tmpFile('mytest.txt'), - ), - ), + ], + ], 'This comes from a file', - ); + ]; return $cases; } @@ -109,62 +109,62 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { */ public function badCreateProvider() { // array($entityClass, $createParams, $expectedError) - $cases = array(); + $cases = []; - $cases[] = array( + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'id' => 12345, 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', - ), + ], '/Invalid ID/', - ); - $cases[] = array( + ]; + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => self::getFilePrefix() . 'failedExample.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', - ), + ], "/Mandatory key\\(s\\) missing from params array: 'id' or 'content' or 'options.move-file'/", - ); - $cases[] = array( + ]; + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => self::getFilePrefix() . 'failedExample.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'too much content', - 'options' => array( + 'options' => [ 'move-file' => $this->tmpFile('too-much.txt'), - ), - ), + ], + ], "/'content' and 'options.move-file' are mutually exclusive/", - ); - $cases[] = array( + ]; + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => 'inv/alid.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', - ), + ], "/Malformed name/", - ); - $cases[] = array( + ]; + $cases[] = [ 'CRM_Core_DAO_Domain', - array( + [ 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', 'check_permissions' => 1, - ), + ], "/Unrecognized target entity/", - ); + ]; return $cases; } @@ -174,29 +174,29 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { */ public function badUpdateProvider() { // array($entityClass, $createParams, $updateParams, $expectedError) - $cases = array(); + $cases = []; - $readOnlyFields = array( + $readOnlyFields = [ 'name' => 'newname.txt', 'entity_table' => 'civicrm_domain', 'entity_id' => 5, 'upload_date' => '2010-11-12 13:14:15', - ); + ]; foreach ($readOnlyFields as $readOnlyField => $newValue) { - $cases[] = array( + $cases[] = [ 'CRM_Activity_DAO_Activity', - array( + [ 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', - ), - array( + ], + [ 'check_permissions' => 1, $readOnlyField => $newValue, - ), + ], "/Cannot modify $readOnlyField/", - ); + ]; } return $cases; @@ -207,7 +207,7 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { */ public function okGetProvider() { // array($getParams, $expectedNames) - $cases = array(); + $cases = []; // Each search runs in a DB which contains these attachments: // Activity #123: example_123.txt (text/plain) and example_123.csv (text/csv) @@ -231,26 +231,26 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { // array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_456.txt'), //); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '123'), - array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_123.csv'), - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '456'), - array(self::getFilePrefix() . 'example_456.txt', self::getFilePrefix() . 'example_456.csv'), - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/csv'), - array(self::getFilePrefix() . 'example_456.csv'), - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/html'), - array(), - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '999'), - array(), - ); + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '123'], + [self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_123.csv'], + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '456'], + [self::getFilePrefix() . 'example_456.txt', self::getFilePrefix() . 'example_456.csv'], + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/csv'], + [self::getFilePrefix() . 'example_456.csv'], + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/html'], + [], + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '999'], + [], + ]; return $cases; } @@ -260,40 +260,40 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { */ public function badGetProvider() { // array($getParams, $expectedNames) - $cases = array(); + $cases = []; // Each search runs in a DB which contains these attachments: // Activity #123: example_123.txt (text/plain) and example_123.csv (text/csv) // Activity #456: example_456.txt (text/plain) and example_456.csv (text/csv) - $cases[] = array( - array('check_permissions' => 1, 'mime_type' => 'text/plain'), + $cases[] = [ + ['check_permissions' => 1, 'mime_type' => 'text/plain'], "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/", - ); - $cases[] = array( - array('check_permissions' => 1, 'entity_id' => '123'), + ]; + $cases[] = [ + ['check_permissions' => 1, 'entity_id' => '123'], "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/", - ); - $cases[] = array( - array('check_permissions' => 1), + ]; + $cases[] = [ + ['check_permissions' => 1], "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/", - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'name' => 'example_456.csv'), + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'name' => 'example_456.csv'], "/Get by name is not currently supported/", - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'content' => 'test'), + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'content' => 'test'], "/Get by content is not currently supported/", - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'path' => '/home/foo'), + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'path' => '/home/foo'], "/Get by path is not currently supported/", - ); - $cases[] = array( - array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'url' => '/index.php'), + ]; + $cases[] = [ + ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'url' => '/index.php'], "/Get by url is not currently supported/", - ); + ]; return $cases; } @@ -312,10 +312,10 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + array( + $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + [ 'entity_table' => $entity_table, 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertTrue(is_numeric($fileId)); $this->assertEquals($entity_table, $createResult['values'][$fileId]['entity_table']); @@ -326,23 +326,23 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $this->assertTrue(!empty($createResult['values'][$fileId]['url'])); $this->assertAttachmentExistence(TRUE, $createResult); - $getResult = $this->callAPISuccess('Attachment', 'get', array( + $getResult = $this->callAPISuccess('Attachment', 'get', [ 'entity_table' => $entity_table, 'entity_id' => $entity->id, - )); + ]); $this->assertEquals(1, $getResult['count']); - foreach (array('id', 'entity_table', 'entity_id', 'url') as $field) { + foreach (['id', 'entity_table', 'entity_id', 'url'] as $field) { $this->assertEquals($createResult['values'][$fileId][$field], $getResult['values'][$fileId][$field], "Expect field $field to match"); } $this->assertTrue(!isset($getResult['values'][$fileId]['content'])); - $getResult2 = $this->callAPISuccess('Attachment', 'get', array( + $getResult2 = $this->callAPISuccess('Attachment', 'get', [ 'entity_table' => $entity_table, 'entity_id' => $entity->id, - 'return' => array('content'), - )); + 'return' => ['content'], + ]); $this->assertEquals($expectedContent, $getResult2['values'][$fileId]['content']); - foreach (array('id', 'entity_table', 'entity_id', 'url') as $field) { + foreach (['id', 'entity_table', 'entity_id', 'url'] as $field) { $this->assertEquals($createResult['values'][$fileId][$field], $getResult['values'][$fileId][$field], "Expect field $field to match"); } } @@ -358,10 +358,10 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPIFailure('Attachment', 'create', $createParams + array( + $createResult = $this->callAPIFailure('Attachment', 'create', $createParams + [ 'entity_table' => $entity_table, 'entity_id' => $entity->id, - )); + ]); $this->assertRegExp($expectedError, $createResult['error_message']); } @@ -377,16 +377,16 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + array( + $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + [ 'entity_table' => $entity_table, 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertTrue(is_numeric($fileId)); - $updateResult = $this->callAPIFailure('Attachment', 'create', $updateParams + array( + $updateResult = $this->callAPIFailure('Attachment', 'create', $updateParams + [ 'id' => $fileId, - )); + ]); $this->assertRegExp($expectedError, $updateResult['error_message']); } @@ -398,14 +398,14 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity'); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', array( + $createResult = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'weird:na"me.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertTrue(is_numeric($fileId)); $this->assertEquals(self::getFilePrefix() . 'weird_na_me.txt', $createResult['values'][$fileId]['name']); @@ -421,13 +421,13 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', array( + $createResult = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'content' => 'My test content', 'entity_table' => $entity_table, 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertEquals($loggedInUser, $createResult['values'][$fileId]['created_id']); @@ -439,13 +439,13 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', array( + $createResult = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'content' => 'My test content', 'entity_table' => $entity_table, 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertEmpty($createResult['values'][$fileId]['created_id']); @@ -457,14 +457,14 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass); $this->assertTrue(is_numeric($entity->id)); - $attachmentParams = array( + $attachmentParams = [ 'name' => self::getFilePrefix() . 'exampleFromContent.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => $entity_table, 'entity_id' => $entity->id, - ); + ]; $createResult = $this->callAPISuccess('Attachment', 'create', $attachmentParams); @@ -478,11 +478,11 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $this->callAPISuccess('Attachment', 'create', $attachmentParams); - $updatedAttachment = $this->callAPISuccess('Attachment', 'get', array( + $updatedAttachment = $this->callAPISuccess('Attachment', 'get', [ 'id' => $fileId, 'entity_id' => $attachmentParams['entity_id'], 'entity_table' => $attachmentParams['entity_table'], - )); + ]); $this->assertNotEmpty($loggedInUser); $this->assertEmpty($updatedAttachment['values'][$fileId]['created_id']); @@ -495,16 +495,16 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { * @dataProvider okGetProvider */ public function testGet($getParams, $expectedNames) { - foreach (array(123, 456) as $entity_id) { - foreach (array('text/plain' => '.txt', 'text/csv' => '.csv') as $mime => $ext) { - $this->callAPISuccess('Attachment', 'create', array( + foreach ([123, 456] as $entity_id) { + foreach (['text/plain' => '.txt', 'text/csv' => '.csv'] as $mime => $ext) { + $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'example_' . $entity_id . $ext, 'mime_type' => $mime, 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity_id, - )); + ]); } } @@ -529,16 +529,16 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { * @dataProvider badGetProvider */ public function testGetError($getParams, $expectedError) { - foreach (array(123, 456) as $entity_id) { - foreach (array('text/plain' => '.txt', 'text/csv' => '.csv') as $mime => $ext) { - $this->callAPISuccess('Attachment', 'create', array( + foreach ([123, 456] as $entity_id) { + foreach (['text/plain' => '.txt', 'text/csv' => '.csv'] as $mime => $ext) { + $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'example_' . $entity_id . $ext, 'mime_type' => $mime, 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity_id, - )); + ]); } } @@ -555,22 +555,22 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity'); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', array( + $createResult = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'getThenUpdate.txt', 'mime_type' => 'text/plain', 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertTrue(is_numeric($fileId)); $this->assertEquals(self::getFilePrefix() . 'getThenUpdate.txt', $createResult['values'][$fileId]['name']); $this->assertAttachmentExistence(TRUE, $createResult); - $getResult = $this->callAPISuccess('Attachment', 'get', array( + $getResult = $this->callAPISuccess('Attachment', 'get', [ 'id' => $fileId, - )); + ]); $this->assertTrue(is_array($getResult['values'][$fileId])); $updateParams = $getResult['values'][$fileId]; @@ -587,23 +587,23 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity'); $this->assertTrue(is_numeric($entity->id)); - foreach (array('first', 'second') as $n) { - $createResults[$n] = $this->callAPISuccess('Attachment', 'create', array( + foreach (['first', 'second'] as $n) { + $createResults[$n] = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'testDeleteByID.txt', 'mime_type' => 'text/plain', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity->id, - )); + ]); $this->assertTrue(is_numeric($createResults[$n]['id'])); $this->assertEquals(self::getFilePrefix() . 'testDeleteByID.txt', $createResults[$n]['values'][$createResults[$n]['id']]['name']); } $this->assertAttachmentExistence(TRUE, $createResults['first']); $this->assertAttachmentExistence(TRUE, $createResults['second']); - $this->callAPISuccess('Attachment', 'delete', array( + $this->callAPISuccess('Attachment', 'delete', [ 'id' => $createResults['first']['id'], - )); + ]); $this->assertAttachmentExistence(FALSE, $createResults['first']); $this->assertAttachmentExistence(TRUE, $createResults['second']); } @@ -614,17 +614,17 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { */ public function testDeleteByEntity() { // create 2 entities (keepme,delme) -- each with 2 attachments (first,second) - foreach (array('keepme', 'delme') as $e) { + foreach (['keepme', 'delme'] as $e) { $entities[$e] = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity'); $this->assertTrue(is_numeric($entities[$e]->id)); - foreach (array('first', 'second') as $n) { - $createResults[$e][$n] = $this->callAPISuccess('Attachment', 'create', array( + foreach (['first', 'second'] as $n) { + $createResults[$e][$n] = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'testDeleteByEntity.txt', 'mime_type' => 'text/plain', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entities[$e]->id, - )); + ]); $this->assertTrue(is_numeric($createResults[$e][$n]['id'])); } } @@ -633,10 +633,10 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $this->assertAttachmentExistence(TRUE, $createResults['delme']['first']); $this->assertAttachmentExistence(TRUE, $createResults['delme']['second']); - $this->callAPISuccess('Attachment', 'delete', array( + $this->callAPISuccess('Attachment', 'delete', [ 'entity_table' => 'civicrm_activity', 'entity_id' => $entities[$e]->id, - )); + ]); $this->assertAttachmentExistence(TRUE, $createResults['keepme']['first']); $this->assertAttachmentExistence(TRUE, $createResults['keepme']['second']); $this->assertAttachmentExistence(FALSE, $createResults['delme']['first']); @@ -650,25 +650,25 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity'); $this->assertTrue(is_numeric($entity->id)); - $createResult = $this->callAPISuccess('Attachment', 'create', array( + $createResult = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'hasIcon.docx', 'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertEquals('fa-file-word-o', $createResult['values'][$fileId]['icon']); - $createResult = $this->callAPISuccess('Attachment', 'create', array( + $createResult = $this->callAPISuccess('Attachment', 'create', [ 'name' => self::getFilePrefix() . 'hasIcon.jpg', 'mime_type' => 'image/jpg', 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity->id, - )); + ]); $fileId = $createResult['id']; $this->assertEquals('fa-file-image-o', $createResult['values'][$fileId]['icon']); } @@ -685,10 +685,10 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { protected function cleanupFiles() { $config = CRM_Core_Config::singleton(); - $dirs = array( + $dirs = [ sys_get_temp_dir(), $config->customFileUploadDir, - ); + ]; foreach ($dirs as $dir) { $files = (array) glob($dir . "/" . self::getFilePrefix() . "*"); foreach ($files as $file) { diff --git a/tests/phpunit/api/v3/BatchTest.php b/tests/phpunit/api/v3/BatchTest.php index dc2dc31bb1..d85676f40a 100644 --- a/tests/phpunit/api/v3/BatchTest.php +++ b/tests/phpunit/api/v3/BatchTest.php @@ -33,7 +33,7 @@ */ class api_v3_BatchTest extends CiviUnitTestCase { - protected $_params = array(); + protected $_params = []; protected $_entity = 'batch'; /** @@ -50,9 +50,9 @@ class api_v3_BatchTest extends CiviUnitTestCase { * Test civicrm_batch_get - success expected. */ public function testGet() { - $params = array( + $params = [ 'id' => $this->batchCreate(), - ); + ]; $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($params['id'], $result['id']); } @@ -61,14 +61,14 @@ class api_v3_BatchTest extends CiviUnitTestCase { * Test civicrm_batch_create - success expected. */ public function testCreate() { - $params = array( + $params = [ 'name' => 'New_Batch_03', 'title' => 'New Batch 03', 'description' => 'This is description for New Batch 03', 'total' => '300.33', 'item_count' => 3, 'status_id' => 1, - ); + ]; $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); @@ -79,14 +79,14 @@ class api_v3_BatchTest extends CiviUnitTestCase { * Test civicrm_batch_create with id. */ public function testUpdate() { - $params = array( + $params = [ 'name' => 'New_Batch_04', 'title' => 'New Batch 04', 'description' => 'This is description for New Batch 04', 'total' => '400.44', 'item_count' => 4, 'id' => $this->batchCreate(), - ); + ]; $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); @@ -98,9 +98,9 @@ class api_v3_BatchTest extends CiviUnitTestCase { */ public function testBatchDeleteOldSyntax() { $batchID = $this->batchCreate(); - $params = array( + $params = [ 'batch_id' => $batchID, - ); + ]; $result = $this->callAPISuccess('batch', 'delete', $params); } @@ -109,9 +109,9 @@ class api_v3_BatchTest extends CiviUnitTestCase { */ public function testBatchDeleteCorrectSyntax() { $batchID = $this->batchCreate(); - $params = array( + $params = [ 'id' => $batchID, - ); + ]; $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__); } diff --git a/tests/phpunit/api/v3/CRM11793Test.php b/tests/phpunit/api/v3/CRM11793Test.php index b42cfc0f4e..b83fcfaba0 100644 --- a/tests/phpunit/api/v3/CRM11793Test.php +++ b/tests/phpunit/api/v3/CRM11793Test.php @@ -55,9 +55,9 @@ class api_v3_CRM11793Test extends CiviUnitTestCase { $result = $this->callAPISuccess( 'contact', 'get', - array( + [ 'contact_type' => $contactType, - ) + ] ); foreach ($result['values'] as $idx => $contact) { diff --git a/tests/phpunit/api/v3/CampaignTest.php b/tests/phpunit/api/v3/CampaignTest.php index e8b7aebc92..994490e167 100644 --- a/tests/phpunit/api/v3/CampaignTest.php +++ b/tests/phpunit/api/v3/CampaignTest.php @@ -36,11 +36,11 @@ class api_v3_CampaignTest extends CiviUnitTestCase { public $DBResetRequired = FALSE; public function setUp() { - $this->params = array( + $this->params = [ 'title' => "campaign title", 'description' => "Call people, ask for money", 'created_date' => 'first sat of July 2008', - ); + ]; parent::setUp(); $this->useTransaction(TRUE); } @@ -56,7 +56,7 @@ class api_v3_CampaignTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->getAndCheck(array_merge($this->params, array('created_date' => '2008-07-05 00:00:00')), $result['id'], 'campaign', TRUE); + $this->getAndCheck(array_merge($this->params, ['created_date' => '2008-07-05 00:00:00']), $result['id'], 'campaign', TRUE); } /** @@ -79,10 +79,10 @@ class api_v3_CampaignTest extends CiviUnitTestCase { $this->_apiversion = $version; $this->callAPISuccess('campaign', 'create', $this->params); $entity = $this->callAPISuccess('campaign', 'get', ($this->params)); - $delete = array('id' => $entity['id']); + $delete = ['id' => $entity['id']]; $result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess('campaign', 'get', array()); + $checkDeleted = $this->callAPISuccess('campaign', 'get', []); $this->assertEquals(0, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/CaseContactTest.php b/tests/phpunit/api/v3/CaseContactTest.php index cdfb5c0ed3..b65cf541e4 100644 --- a/tests/phpunit/api/v3/CaseContactTest.php +++ b/tests/phpunit/api/v3/CaseContactTest.php @@ -29,24 +29,24 @@ class api_v3_CaseContactTest extends CiviCaseTestCase { parent::setUp(); $this->_cid = $this->individualCreate(); - $this->_cid2 = $this->individualCreate(array(), 1); + $this->_cid2 = $this->individualCreate([], 1); - $this->_case = $this->callAPISuccess('case', 'create', array( + $this->_case = $this->callAPISuccess('case', 'create', [ 'case_type_id' => $this->caseTypeId, 'subject' => __CLASS__, 'contact_id' => $this->_cid, - )); + ]); - $this->_params = array( + $this->_params = [ 'case_id' => $this->_case['id'], 'contact_id' => $this->_cid2, - ); + ]; } public function testCaseContactGet() { - $result = $this->callAPIAndDocument('CaseContact', 'get', array( + $result = $this->callAPIAndDocument('CaseContact', 'get', [ 'contact_id' => $this->_cid, - ), __FUNCTION__, __FILE__); + ], __FUNCTION__, __FILE__); $this->assertEquals($this->_case['id'], $result['id']); } @@ -59,7 +59,7 @@ class api_v3_CaseContactTest extends CiviCaseTestCase { $id = $result['id']; // Check result - $result = $this->callAPISuccess('CaseContact', 'get', array('id' => $id)); + $result = $this->callAPISuccess('CaseContact', 'get', ['id' => $id]); $this->assertEquals($result['values'][$id]['case_id'], $params['case_id']); $this->assertEquals($result['values'][$id]['contact_id'], $params['contact_id']); } diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 5e53e3967c..f3baf27bc8 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -63,19 +63,19 @@ class api_v3_CaseTest extends CiviCaseTestCase { parent::setUp(); - $activityTypes = $this->callAPISuccess('option_value', 'get', array( + $activityTypes = $this->callAPISuccess('option_value', 'get', [ 'option_group_id' => 2, 'name' => 'Follow Up', 'label' => 'Follow Up', 'sequential' => 1, - )); + ]); $this->followup_activity_type_value = $activityTypes['values'][0]['value']; - $this->_params = array( + $this->_params = [ 'case_type_id' => $this->caseTypeId, 'subject' => 'Test case', 'contact_id' => 17, - ); + ]; $this->settingsStack = new \Civi\Core\SettingsStack(); } @@ -89,17 +89,17 @@ class api_v3_CaseTest extends CiviCaseTestCase { * Check with empty array. */ public function testCaseCreateEmpty() { - $this->callAPIFailure('case', 'create', array()); + $this->callAPIFailure('case', 'create', []); } /** * Check if required fields are not passed. */ public function testCaseCreateWithoutRequired() { - $params = array( + $params = [ 'subject' => 'this case should fail', 'case_type_id' => 1, - ); + ]; $this->callAPIFailure('case', 'create', $params); } @@ -118,17 +118,17 @@ class api_v3_CaseTest extends CiviCaseTestCase { $params['subject'] = 'Test Case 3'; $this->callAPISuccess('case', 'create', $params); - $getParams = array( - 'id' => array($case1['id']), - 'extra' => array('contact_id'), - 'params' => array( + $getParams = [ + 'id' => [$case1['id']], + 'extra' => ['contact_id'], + 'params' => [ 'version' => 3, - 'case_id' => array('!=' => $case2['id']), + 'case_id' => ['!=' => $case2['id']], 'case_id.is_deleted' => 0, - 'case_id.status_id' => array('!=' => "Closed"), - 'case_id.end_date' => array('IS NULL' => 1), - ), - ); + 'case_id.status_id' => ['!=' => "Closed"], + 'case_id.end_date' => ['IS NULL' => 1], + ], + ]; $result = $this->callAPISuccess('case', 'getlist', $getParams); //Only 1 case should be returned. @@ -148,7 +148,7 @@ class api_v3_CaseTest extends CiviCaseTestCase { $id = $result['id']; // Check result - $result = $this->callAPISuccess('case', 'get', array('id' => $id)); + $result = $this->callAPISuccess('case', 'get', ['id' => $id]); $this->assertEquals($result['values'][$id]['id'], $id); $this->assertEquals($result['values'][$id]['case_type_id'], $this->caseTypeId); $this->assertEquals($result['values'][$id]['subject'], $params['subject']); @@ -167,17 +167,17 @@ class api_v3_CaseTest extends CiviCaseTestCase { $id = $result['id']; // Check result - $result = $this->callAPISuccess('case', 'get', array('id' => $id)); + $result = $this->callAPISuccess('case', 'get', ['id' => $id]); $this->assertEquals($result['values'][$id]['id'], $id); $this->assertEquals($result['values'][$id]['case_type_id'], $this->caseTypeId); $this->assertEquals($result['values'][$id]['subject'], $params['subject']); $this->assertEquals($result['values'][$id]['end_date'], date('Y-m-d')); //Check all relationship end dates are set to case end date. - $relationships = $this->callAPISuccess('Relationship', 'get', array( + $relationships = $this->callAPISuccess('Relationship', 'get', [ 'sequential' => 1, 'case_id' => $id, - )); + ]); foreach ($relationships['values'] as $key => $values) { $this->assertEquals($values['end_date'], date('Y-m-d')); } @@ -199,10 +199,10 @@ class api_v3_CaseTest extends CiviCaseTestCase { $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); $this->customFieldDelete($ids['custom_field_id']); @@ -219,15 +219,15 @@ class api_v3_CaseTest extends CiviCaseTestCase { $params['case_type'] = $this->caseType; $result = $this->callAPISuccess('case', 'create', $params); $id = $result['id']; - $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id)); + $case = $this->callAPISuccess('case', 'getsingle', ['id' => $id]); // Update Case. - $params = array('id' => $id); + $params = ['id' => $id]; $params['subject'] = $case['subject'] = 'Something Else'; $this->callAPISuccess('case', 'create', $params); // Verify that updated case is equal to the original with new subject. - $result = $this->callAPISuccessGetSingle('Case', array('case_id' => $id)); + $result = $this->callAPISuccessGetSingle('Case', ['case_id' => $id]); // Modification dates are likely to differ by 0-2 sec. Check manually. $this->assertGreaterThanOrEqual($case['modified_date'], $result['modified_date']); unset($result['modified_date'], $case['modified_date']); @@ -245,7 +245,7 @@ class api_v3_CaseTest extends CiviCaseTestCase { $params['case_type'] = $this->caseType; $result = $this->callAPISuccess('case', 'create', $params); $id = $result['id']; - $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id)); + $case = $this->callAPISuccess('case', 'getsingle', ['id' => $id]); // Update Case, we specify existing case ID and existing contact ID to verify that CaseContact.create is not called $params = $this->_params; @@ -253,7 +253,7 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->callAPISuccess('case', 'create', $params); // Verify that updated case is equal to the original with new subject. - $result = $this->callAPISuccessGetSingle('Case', array('case_id' => $id)); + $result = $this->callAPISuccessGetSingle('Case', ['case_id' => $id]); // Modification dates are likely to differ by 0-2 sec. Check manually. $this->assertGreaterThanOrEqual($case['modified_date'], $result['modified_date']); unset($result['modified_date'], $case['modified_date']); @@ -273,28 +273,28 @@ class api_v3_CaseTest extends CiviCaseTestCase { $result = $this->callAPISuccess($this->_entity, 'create', $params); $caseId = $result['id']; - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); - $fields = $this->callAPISuccess($this->_entity, 'getfields', array('version' => $this->_apiversion)); + $fields = $this->callAPISuccess($this->_entity, 'getfields', ['version' => $this->_apiversion]); $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']])); // Update the activity with custom data. - $params = array( + $params = [ 'id' => $caseId, 'custom_' . $ids['custom_field_id'] => 'Updated my test data', 'version' => $this->_apiversion, - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', $params); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id'], - )); + ]); $this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); } @@ -307,24 +307,24 @@ class api_v3_CaseTest extends CiviCaseTestCase { // Move Case to Trash $id = $result['id']; - $this->callAPISuccess('case', 'delete', array('id' => $id, 'move_to_trash' => 1)); + $this->callAPISuccess('case', 'delete', ['id' => $id, 'move_to_trash' => 1]); // Check result - also check that 'case_id' works as well as 'id' - $result = $this->callAPISuccess('case', 'get', array('case_id' => $id)); + $result = $this->callAPISuccess('case', 'get', ['case_id' => $id]); $this->assertEquals(1, $result['values'][$id]['is_deleted']); // Restore Case from Trash - $this->callAPISuccess('case', 'restore', array('id' => $id)); + $this->callAPISuccess('case', 'restore', ['id' => $id]); // Check result - $result = $this->callAPISuccess('case', 'get', array('case_id' => $id)); + $result = $this->callAPISuccess('case', 'get', ['case_id' => $id]); $this->assertEquals(0, $result['values'][$id]['is_deleted']); // Delete Case Permanently - $this->callAPISuccess('case', 'delete', array('case_id' => $id)); + $this->callAPISuccess('case', 'delete', ['case_id' => $id]); // Check result - case should no longer exist - $result = $this->callAPISuccess('case', 'get', array('id' => $id)); + $result = $this->callAPISuccess('case', 'get', ['id' => $id]); $this->assertEquals(0, $result['count']); } @@ -335,34 +335,34 @@ class api_v3_CaseTest extends CiviCaseTestCase { public function testCaseRoleRelationships() { // Create Case $case = $this->callAPISuccess('case', 'create', $this->_params); - $relType = $this->relationshipTypeCreate(array('name_a_b' => 'Test AB', 'name_b_a' => 'Test BA', 'contact_type_b' => 'Individual')); - $relContact = $this->individualCreate(array('first_name' => 'First', 'last_name' => 'Last')); + $relType = $this->relationshipTypeCreate(['name_a_b' => 'Test AB', 'name_b_a' => 'Test BA', 'contact_type_b' => 'Individual']); + $relContact = $this->individualCreate(['first_name' => 'First', 'last_name' => 'Last']); - $_REQUEST = array( + $_REQUEST = [ 'rel_type' => "{$relType}_b_a", 'rel_contact' => $relContact, 'case_id' => $case['id'], 'is_unit_test' => TRUE, - ); + ]; $ret = CRM_Contact_Page_AJAX::relationship(); $this->assertEquals(0, $ret['is_error']); //Check if relationship exist for the case. - $relationship = $this->callAPISuccess('Relationship', 'get', array( + $relationship = $this->callAPISuccess('Relationship', 'get', [ 'sequential' => 1, 'relationship_type_id' => $relType, 'case_id' => $case['id'], - )); + ]); $this->assertEquals($relContact, $relationship['values'][0]['contact_id_a']); $this->assertEquals($this->_params['contact_id'], $relationship['values'][0]['contact_id_b']); //Check if activity is assigned to correct contact. - $activity = $this->callAPISuccess('Activity', 'get', array( + $activity = $this->callAPISuccess('Activity', 'get', [ 'subject' => 'Test BA : Mr. First Last II', - )); - $this->callAPISuccess('ActivityContact', 'get', array( + ]); + $this->callAPISuccess('ActivityContact', 'get', [ 'contact_id' => $relContact, 'activity_id' => $activity['id'], - )); + ]); } /** @@ -374,15 +374,15 @@ class api_v3_CaseTest extends CiviCaseTestCase { $id = $result['id']; // Check result - we should get a list of activity ids - $result = $this->callAPISuccess('case', 'get', array('id' => $id, 'return' => 'activities')); + $result = $this->callAPISuccess('case', 'get', ['id' => $id, 'return' => 'activities']); $case = $result['values'][$id]; $activity = $case['activities'][0]; // Fetch case based on an activity id - $result = $this->callAPISuccess('case', 'get', array( + $result = $this->callAPISuccess('case', 'get', [ 'activity_id' => $activity, 'return' => 'activities', - )); + ]); $this->assertEquals(FALSE, empty($result['values'][$id])); $this->assertEquals($result['values'][$id], $case); } @@ -396,13 +396,13 @@ class api_v3_CaseTest extends CiviCaseTestCase { $id = $result['id']; // Store result for later - $case = $this->callAPISuccessGetSingle('case', array('id' => $id, 'return' => array('activities', 'contacts'))); + $case = $this->callAPISuccessGetSingle('case', ['id' => $id, 'return' => ['activities', 'contacts']]); // Fetch case based on client contact id - $result = $this->callAPISuccess('case', 'get', array( + $result = $this->callAPISuccess('case', 'get', [ 'client_id' => $this->_params['contact_id'], - 'return' => array('activities', 'contacts'), - )); + 'return' => ['activities', 'contacts'], + ]); $this->assertAPIArrayComparison($result['values'][$id], $case); } @@ -415,13 +415,13 @@ class api_v3_CaseTest extends CiviCaseTestCase { $id = $result['id']; // Store result for later - $case = $this->callAPISuccessGetSingle('Case', array('id' => $id, 'return' => 'subject')); + $case = $this->callAPISuccessGetSingle('Case', ['id' => $id, 'return' => 'subject']); // Fetch case based on client contact id - $result = $this->callAPISuccess('case', 'get', array( + $result = $this->callAPISuccess('case', 'get', [ 'subject' => $this->_params['subject'], - 'return' => array('subject'), - )); + 'return' => ['subject'], + ]); $this->assertAPIArrayComparison($result['values'][$id], $case); } @@ -432,10 +432,10 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->callAPISuccess('case', 'create', $this->_params); // Append 'wrong' to subject so that it is no longer the same. - $result = $this->callAPISuccess('case', 'get', array( + $result = $this->callAPISuccess('case', 'get', [ 'subject' => $this->_params['subject'] . 'wrong', - 'return' => array('activities', 'contacts'), - )); + 'return' => ['activities', 'contacts'], + ]); $this->assertEquals(0, $result['count']); } @@ -447,9 +447,9 @@ class api_v3_CaseTest extends CiviCaseTestCase { $id = $result['id']; // Store result for later - $case = $this->callAPISuccessGetSingle('Case', array('id' => $id, 'return' => 'contact_id')); + $case = $this->callAPISuccessGetSingle('Case', ['id' => $id, 'return' => 'contact_id']); - $result = $this->callAPISuccess('case', 'get', array('limit' => 0, 'return' => array('contact_id'))); + $result = $this->callAPISuccess('case', 'get', ['limit' => 0, 'return' => ['contact_id']]); $this->assertAPIArrayComparison($result['values'][$id], $case); } @@ -459,14 +459,14 @@ class api_v3_CaseTest extends CiviCaseTestCase { public function testCaseActivityCreate() { $params = $this->_params; $case = $this->callAPISuccess('case', 'create', $params); - $params = array( + $params = [ 'case_id' => $case['id'], // follow up 'activity_type_id' => $this->followup_activity_type_value, 'subject' => 'Test followup 123', 'source_contact_id' => $this->_loggedInUser, 'target_contact_id' => $this->_params['contact_id'], - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals($result['values'][$result['id']]['activity_type_id'], $params['activity_type_id']); @@ -486,12 +486,12 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->assertEquals($dao->find(), 1, 'activity_contact table not populated correctly'); // Check that fetching an activity by case id works, as well as returning case_id - $result = $this->callAPISuccessGetSingle('Activity', array( + $result = $this->callAPISuccessGetSingle('Activity', [ 'case_id' => $case['id'], 'activity_type_id' => $this->followup_activity_type_value, 'subject' => 'Test followup 123', - 'return' => array('case_id'), - )); + 'return' => ['case_id'], + ]); $this->assertContains($case['id'], $result['case_id']); } @@ -504,13 +504,13 @@ class api_v3_CaseTest extends CiviCaseTestCase { // Need to create the case and activity before we can update it $this->testCaseActivityCreate(); - $params = array( + $params = [ 'activity_id' => $this->_caseActivityId, 'case_id' => 1, 'activity_type_id' => 14, 'source_contact_id' => $this->_loggedInUser, 'subject' => 'New subject', - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals($result['values'][$result['id']]['subject'], $params['subject']); @@ -520,9 +520,9 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->assertEquals($result['values'][$result['id']]['original_id'], $this->_caseActivityId); // Check revision is as expected - $revParams = array( + $revParams = [ 'activity_id' => $this->_caseActivityId, - ); + ]; $revActivity = $this->callAPISuccess('activity', 'get', $revParams); $this->assertEquals($revActivity['values'][$this->_caseActivityId]['is_current_revision'], 0); @@ -546,13 +546,13 @@ class api_v3_CaseTest extends CiviCaseTestCase { ->orderBy('id') ->execute()->fetchAll(); - $params = array( + $params = [ 'activity_id' => $this->_caseActivityId, 'case_id' => 1, 'activity_type_id' => 14, 'source_contact_id' => $this->_loggedInUser, 'subject' => 'New subject', - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals($result['values'][$result['id']]['subject'], $params['subject']); @@ -578,7 +578,7 @@ class api_v3_CaseTest extends CiviCaseTestCase { $custom_ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ActivityTest.php'); // create activity - $params = array( + $params = [ 'case_id' => $result['id'], // follow up 'activity_type_id' => 14, @@ -586,26 +586,26 @@ class api_v3_CaseTest extends CiviCaseTestCase { 'source_contact_id' => $this->_loggedInUser, 'target_contact_id' => $this->_params['contact_id'], 'custom_' . $custom_ids['custom_field_id'] => "custom string", - ); + ]; $result = $this->callAPISuccess('activity', 'create', $params); $aid = $result['values'][$result['id']]['id']; // Update activity - $params = array( + $params = [ 'activity_id' => $aid, 'case_id' => 1, 'activity_type_id' => 14, 'source_contact_id' => $this->_loggedInUser, 'subject' => 'New subject', - ); + ]; $this->callAPISuccess('activity', 'create', $params); // Retrieve revision and check custom fields got copied. - $revParams = array( + $revParams = [ 'activity_id' => $aid + 1, 'return.custom_' . $custom_ids['custom_field_id'] => 1, - ); + ]; $revAct = $this->callAPISuccess('activity', 'get', $revParams); $this->assertEquals($revAct['values'][$aid + 1]['custom_' . $custom_ids['custom_field_id']], "custom string", @@ -617,40 +617,40 @@ class api_v3_CaseTest extends CiviCaseTestCase { public function testCaseGetByStatus() { // Create 2 cases with different status ids. - $case1 = $this->callAPISuccess('Case', 'create', array( + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => 17, 'subject' => "Test case 1", 'case_type_id' => $this->caseTypeId, 'status_id' => "Open", 'sequential' => 1, - )); - $this->callAPISuccess('Case', 'create', array( + ]); + $this->callAPISuccess('Case', 'create', [ 'contact_id' => 17, 'subject' => "Test case 2", 'case_type_id' => $this->caseTypeId, 'status_id' => "Urgent", 'sequential' => 1, - )); - $result = $this->callAPISuccessGetSingle('Case', array( + ]); + $result = $this->callAPISuccessGetSingle('Case', [ 'sequential' => 1, 'contact_id' => 17, 'status_id' => "Open", - )); + ]); $this->assertEquals($case1['id'], $result['id']); } public function testCaseGetWithRoles() { - $case1 = $this->callAPISuccess('Case', 'create', array( + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => 17, 'subject' => "Test case with roles", 'case_type_id' => $this->caseTypeId, 'status_id' => "Open", - )); - $result = $this->callAPISuccessGetSingle('Case', array( + ]); + $result = $this->callAPISuccessGetSingle('Case', [ 'id' => $case1['id'], 'status_id' => "Open", - 'return' => array('contacts'), - )); + 'return' => ['contacts'], + ]); foreach ($result['contacts'] as $contact) { if ($contact['role'] == 'Client') { $this->assertEquals(17, $contact['contact_id']); @@ -663,57 +663,57 @@ class api_v3_CaseTest extends CiviCaseTestCase { } public function testCaseGetWithDefinition() { - $case1 = $this->callAPISuccess('Case', 'create', array( + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => 17, 'subject' => "Test case with definition", 'case_type_id' => $this->caseTypeId, 'status_id' => "Open", - )); - $result1 = $this->callAPISuccessGetSingle('Case', array( + ]); + $result1 = $this->callAPISuccessGetSingle('Case', [ 'id' => $case1['id'], 'status_id' => "Open", - 'return' => array('case_type_id.definition'), - )); - $result2 = $this->callAPISuccessGetSingle('Case', array( + 'return' => ['case_type_id.definition'], + ]); + $result2 = $this->callAPISuccessGetSingle('Case', [ 'id' => $case1['id'], 'status_id' => "Open", - 'return' => array('case_type_id', 'case_type_id.definition'), - )); + 'return' => ['case_type_id', 'case_type_id.definition'], + ]); $this->assertEquals($result1['case_type_id.definition'], $result2['case_type_id.definition']); $def = $result1['case_type_id.definition']; - $this->assertEquals(array('name' => 'Open Case', 'max_instances' => 1), $def['activityTypes'][0]); + $this->assertEquals(['name' => 'Open Case', 'max_instances' => 1], $def['activityTypes'][0]); $this->assertNotEmpty($def['activitySets'][0]['activityTypes']); $this->assertNotEmpty($def['caseRoles'][0]['manager']); $this->assertNotEmpty($def['caseRoles'][0]['creator']); } public function testCaseGetTags() { - $case1 = $this->callAPISuccess('Case', 'create', array( + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => 17, 'subject' => "Test case with tags", 'case_type_id' => $this->caseTypeId, 'status_id' => "Open", - )); - $tag1 = $this->tagCreate(array( + ]); + $tag1 = $this->tagCreate([ 'name' => 'CaseTag1', 'used_for' => 'civicrm_case', - )); - $tag2 = $this->tagCreate(array( + ]); + $tag2 = $this->tagCreate([ 'name' => 'CaseTag2', 'used_for' => 'civicrm_case', - )); - $this->callAPISuccess('EntityTag', 'create', array( + ]); + $this->callAPISuccess('EntityTag', 'create', [ 'entity_table' => 'civicrm_case', 'entity_id' => $case1['id'], 'tag_id' => $tag1['id'], - )); - $this->callAPIFailure('Case', 'getsingle', array( + ]); + $this->callAPIFailure('Case', 'getsingle', [ 'tag_id' => $tag2['id'], - )); - $result = $this->callAPISuccessGetSingle('Case', array( + ]); + $result = $this->callAPISuccessGetSingle('Case', [ 'tag_id' => $tag1['id'], 'return' => 'tag_id.name', - )); + ]); $this->assertEquals('CaseTag1', $result['tag_id'][$tag1['id']]['tag_id.name']); } @@ -725,46 +725,46 @@ class api_v3_CaseTest extends CiviCaseTestCase { * @throws \Exception */ public function testCaseGetChainedOp() { - $contact1 = $this->individualCreate(array(), 1); - $contact2 = $this->individualCreate(array(), 2); - $case1 = $this->callAPISuccess('Case', 'create', array( + $contact1 = $this->individualCreate([], 1); + $contact2 = $this->individualCreate([], 2); + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => $contact1, 'subject' => "Test case 1", 'case_type_id' => $this->caseTypeId, - )); - $case2 = $this->callAPISuccess('Case', 'create', array( + ]); + $case2 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => $contact2, 'subject' => "Test case 2", 'case_type_id' => $this->caseTypeId, - )); - $case3 = $this->callAPISuccess('Case', 'create', array( - 'contact_id' => array($contact1, $contact2), + ]); + $case3 = $this->callAPISuccess('Case', 'create', [ + 'contact_id' => [$contact1, $contact2], 'subject' => "Test case 3", 'case_type_id' => $this->caseTypeId, - )); + ]); // Fetch case 1 and all cases with the same client. Chained get should return case 3. - $result = $this->callAPISuccessGetSingle('Case', array( + $result = $this->callAPISuccessGetSingle('Case', [ 'id' => $case1['id'], 'return' => 'contact_id', - 'api.Case.get' => array( - 'contact_id' => array('IN' => "\$value.contact_id"), - 'id' => array('!=' => "\$value.id"), - ), - )); + 'api.Case.get' => [ + 'contact_id' => ['IN' => "\$value.contact_id"], + 'id' => ['!=' => "\$value.id"], + ], + ]); $this->assertEquals($case3['id'], $result['api.Case.get']['id']); // Fetch case 3 and all cases with the same clients. Chained get should return case 1&2. - $result = $this->callAPISuccessGetSingle('Case', array( + $result = $this->callAPISuccessGetSingle('Case', [ 'id' => $case3['id'], - 'return' => array('contact_id'), - 'api.Case.get' => array( + 'return' => ['contact_id'], + 'api.Case.get' => [ 'return' => 'id', - 'contact_id' => array('IN' => "\$value.contact_id"), - 'id' => array('!=' => "\$value.id"), - ), - )); - $this->assertEquals(array($case1['id'], $case2['id']), array_keys(CRM_Utils_Array::rekey($result['api.Case.get']['values'], 'id'))); + 'contact_id' => ['IN' => "\$value.contact_id"], + 'id' => ['!=' => "\$value.id"], + ], + ]); + $this->assertEquals([$case1['id'], $case2['id']], array_keys(CRM_Utils_Array::rekey($result['api.Case.get']['values'], 'id'))); } /** @@ -773,62 +773,62 @@ class api_v3_CaseTest extends CiviCaseTestCase { * For multi-client cases, should order by the first client. */ public function testCaseGetOrderByClient() { - $contact1 = $this->individualCreate(array('first_name' => 'Aa', 'last_name' => 'Zz')); - $contact2 = $this->individualCreate(array('first_name' => 'Bb', 'last_name' => 'Zz')); - $contact3 = $this->individualCreate(array('first_name' => 'Cc', 'last_name' => 'Xx')); + $contact1 = $this->individualCreate(['first_name' => 'Aa', 'last_name' => 'Zz']); + $contact2 = $this->individualCreate(['first_name' => 'Bb', 'last_name' => 'Zz']); + $contact3 = $this->individualCreate(['first_name' => 'Cc', 'last_name' => 'Xx']); - $case1 = $this->callAPISuccess('Case', 'create', array( + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => $contact1, 'subject' => "Test case 1", 'case_type_id' => $this->caseTypeId, - )); - $case2 = $this->callAPISuccess('Case', 'create', array( + ]); + $case2 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => $contact2, 'subject' => "Test case 2", 'case_type_id' => $this->caseTypeId, - )); - $case3 = $this->callAPISuccess('Case', 'create', array( - 'contact_id' => array($contact3, $contact1), + ]); + $case3 = $this->callAPISuccess('Case', 'create', [ + 'contact_id' => [$contact3, $contact1], 'subject' => "Test case 3", 'case_type_id' => $this->caseTypeId, - )); + ]); - $result = $this->callAPISuccess('Case', 'get', array( - 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)), + $result = $this->callAPISuccess('Case', 'get', [ + 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]], 'sequential' => 1, 'return' => 'id', - 'options' => array('sort' => 'contact_id.first_name'), - )); + 'options' => ['sort' => 'contact_id.first_name'], + ]); $this->assertEquals($case3['id'], $result['values'][2]['id']); $this->assertEquals($case2['id'], $result['values'][1]['id']); $this->assertEquals($case1['id'], $result['values'][0]['id']); - $result = $this->callAPISuccess('Case', 'get', array( - 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)), + $result = $this->callAPISuccess('Case', 'get', [ + 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]], 'sequential' => 1, 'return' => 'id', - 'options' => array('sort' => 'contact_id.last_name ASC, contact_id.first_name DESC'), - )); + 'options' => ['sort' => 'contact_id.last_name ASC, contact_id.first_name DESC'], + ]); $this->assertEquals($case1['id'], $result['values'][2]['id']); $this->assertEquals($case2['id'], $result['values'][1]['id']); $this->assertEquals($case3['id'], $result['values'][0]['id']); - $result = $this->callAPISuccess('Case', 'get', array( - 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)), + $result = $this->callAPISuccess('Case', 'get', [ + 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]], 'sequential' => 1, 'return' => 'id', - 'options' => array('sort' => 'contact_id.first_name DESC'), - )); + 'options' => ['sort' => 'contact_id.first_name DESC'], + ]); $this->assertEquals($case1['id'], $result['values'][2]['id']); $this->assertEquals($case2['id'], $result['values'][1]['id']); $this->assertEquals($case3['id'], $result['values'][0]['id']); - $result = $this->callAPISuccess('Case', 'get', array( - 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)), + $result = $this->callAPISuccess('Case', 'get', [ + 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]], 'sequential' => 1, 'return' => 'id', - 'options' => array('sort' => 'case_type_id, contact_id DESC, status_id'), - )); + 'options' => ['sort' => 'case_type_id, contact_id DESC, status_id'], + ]); $this->assertEquals($case1['id'], $result['values'][2]['id']); $this->assertEquals($case2['id'], $result['values'][1]['id']); $this->assertEquals($case3['id'], $result['values'][0]['id']); @@ -849,59 +849,59 @@ class api_v3_CaseTest extends CiviCaseTestCase { public function testCaseAddtimeline($enableRevisions) { $this->settingsStack->push('civicaseActivityRevisions', $enableRevisions); - $caseSpec = array( + $caseSpec = [ 'title' => 'Application with Definition', 'name' => 'Application_with_Definition', 'is_active' => 1, 'weight' => 4, - 'definition' => array( - 'activityTypes' => array( - array('name' => 'Follow up'), - ), - 'activitySets' => array( - array( + 'definition' => [ + 'activityTypes' => [ + ['name' => 'Follow up'], + ], + 'activitySets' => [ + [ 'name' => 'set1', 'label' => 'Label 1', 'timeline' => 1, - 'activityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - ), - ), - array( + 'activityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + ], + ], + [ 'name' => 'set2', 'label' => 'Label 2', 'timeline' => 1, - 'activityTypes' => array( - array('name' => 'Follow up'), - ), - ), - ), - 'caseRoles' => array( - array('name' => 'Homeless Services Coordinator', 'creator' => 1, 'manager' => 1), - ), - ), - ); + 'activityTypes' => [ + ['name' => 'Follow up'], + ], + ], + ], + 'caseRoles' => [ + ['name' => 'Homeless Services Coordinator', 'creator' => 1, 'manager' => 1], + ], + ], + ]; $cid = $this->individualCreate(); $caseType = $this->callAPISuccess('CaseType', 'create', $caseSpec); - $case = $this->callAPISuccess('Case', 'create', array( + $case = $this->callAPISuccess('Case', 'create', [ 'case_type_id' => $caseType['id'], 'contact_id' => $cid, 'subject' => 'Test case with timeline', - )); + ]); // Created case should only have 1 activity per the spec - $result = $this->callAPISuccessGetSingle('Activity', array('case_id' => $case['id'], 'return' => 'activity_type_id.name')); + $result = $this->callAPISuccessGetSingle('Activity', ['case_id' => $case['id'], 'return' => 'activity_type_id.name']); $this->assertEquals('Open Case', $result['activity_type_id.name']); // Add timeline. - $this->callAPISuccess('Case', 'addtimeline', array( + $this->callAPISuccess('Case', 'addtimeline', [ 'case_id' => $case['id'], 'timeline' => 'set2', - )); - $result = $this->callAPISuccess('Activity', 'get', array( + ]); + $result = $this->callAPISuccess('Activity', 'get', [ 'case_id' => $case['id'], 'return' => 'activity_type_id.name', 'sequential' => 1, - 'options' => array('sort' => 'id'), - )); + 'options' => ['sort' => 'id'], + ]); $this->assertEquals(2, $result['count']); $this->assertEquals('Follow up', $result['values'][1]['activity_type_id.name']); } @@ -914,23 +914,23 @@ class api_v3_CaseTest extends CiviCaseTestCase { * @throws \Exception */ public function testCaseMerge() { - $contact1 = $this->individualCreate(array(), 1); - $case1 = $this->callAPISuccess('Case', 'create', array( + $contact1 = $this->individualCreate([], 1); + $case1 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => $contact1, 'subject' => "Test case 1", 'case_type_id' => $this->caseTypeId, - )); - $case2 = $this->callAPISuccess('Case', 'create', array( + ]); + $case2 = $this->callAPISuccess('Case', 'create', [ 'contact_id' => $contact1, 'subject' => "Test case 2", 'case_type_id' => $this->caseTypeId, - )); - $result = $this->callAPISuccess('Case', 'getcount', array('contact_id' => $contact1)); + ]); + $result = $this->callAPISuccess('Case', 'getcount', ['contact_id' => $contact1]); $this->assertEquals(2, $result); - $this->callAPISuccess('Case', 'merge', array('case_id_1' => $case1['id'], 'case_id_2' => $case2['id'])); + $this->callAPISuccess('Case', 'merge', ['case_id_1' => $case1['id'], 'case_id_2' => $case2['id']]); - $result = $this->callAPISuccess('Case', 'getsingle', array('id' => $case2['id'])); + $result = $this->callAPISuccess('Case', 'getsingle', ['id' => $case2['id']]); $this->assertEquals(1, $result['is_deleted']); } @@ -940,9 +940,9 @@ class api_v3_CaseTest extends CiviCaseTestCase { * @return array */ public function caseActivityRevisionExamples() { - $examples = array(); - $examples[] = array(FALSE); - $examples[] = array(TRUE); + $examples = []; + $examples[] = [FALSE]; + $examples[] = [TRUE]; return $examples; } @@ -950,32 +950,32 @@ class api_v3_CaseTest extends CiviCaseTestCase { $params = $this->_params; $case_created = $this->callAPISuccess('case', 'create', $params); - $case_1 = $this->callAPISuccess('Case', 'getsingle', array( + $case_1 = $this->callAPISuccess('Case', 'getsingle', [ 'id' => $case_created['id'], - )); + ]); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_1['created_date']); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_1['modified_date']); $this->assertApproxEquals(strtotime($case_1['created_date']), strtotime($case_1['modified_date']), 2); - $activity_1 = $this->callAPISuccess('activity', 'getsingle', array( + $activity_1 = $this->callAPISuccess('activity', 'getsingle', [ 'case_id' => $case_created['id'], - 'options' => array( + 'options' => [ 'limit' => 1, - ), - )); + ], + ]); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_1['created_date']); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_1['modified_date']); $this->assertApproxEquals(strtotime($activity_1['created_date']), strtotime($activity_1['modified_date']), 2); usleep(1.5 * 1000000); - $this->callAPISuccess('activity', 'create', array( + $this->callAPISuccess('activity', 'create', [ 'id' => $activity_1['id'], 'subject' => 'Make cheese', - )); + ]); - $activity_2 = $this->callAPISuccess('activity', 'getsingle', array( + $activity_2 = $this->callAPISuccess('activity', 'getsingle', [ 'id' => $activity_1['id'], - )); + ]); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_2['created_date']); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_2['modified_date']); $this->assertNotEquals($activity_2['created_date'], $activity_2['modified_date']); @@ -985,9 +985,9 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->assertLessThan($activity_2['modified_date'], $activity_1['modified_date'], sprintf("Original modification time (%s) should predate later modification time (%s)", $activity_1['modified_date'], $activity_2['modified_date'])); - $case_2 = $this->callAPISuccess('Case', 'getsingle', array( + $case_2 = $this->callAPISuccess('Case', 'getsingle', [ 'id' => $case_created['id'], - )); + ]); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_2['created_date']); $this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_2['modified_date']); $this->assertEquals($case_1['created_date'], $case_2['created_date']); diff --git a/tests/phpunit/api/v3/CaseTypeTest.php b/tests/phpunit/api/v3/CaseTypeTest.php index 9a64c1ce91..995d8ae8fe 100644 --- a/tests/phpunit/api/v3/CaseTypeTest.php +++ b/tests/phpunit/api/v3/CaseTypeTest.php @@ -32,36 +32,36 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { public function setUp() { - $this->quickCleanup(array('civicrm_case_type')); + $this->quickCleanup(['civicrm_case_type']); parent::setUp(); - $this->fixtures['Application_with_Definition'] = array( + $this->fixtures['Application_with_Definition'] = [ 'title' => 'Application with Definition', 'name' => 'Application_with_Definition', 'is_active' => 1, 'weight' => 4, - 'definition' => array( - 'activityTypes' => array( - array('name' => 'First act'), - ), - 'activitySets' => array( - array( + 'definition' => [ + 'activityTypes' => [ + ['name' => 'First act'], + ], + 'activitySets' => [ + [ 'name' => 'set1', 'label' => 'Label 1', 'timeline' => 1, - 'activityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - ), - ), - ), - 'timelineActivityTypes' => array( - array('name' => 'Open Case', 'status' => 'Completed'), - ), - 'caseRoles' => array( - array('name' => 'First role', 'creator' => 1, 'manager' => 1), - ), - ), - ); + 'activityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + ], + ], + ], + 'timelineActivityTypes' => [ + ['name' => 'Open Case', 'status' => 'Completed'], + ], + 'caseRoles' => [ + ['name' => 'First role', 'creator' => 1, 'manager' => 1], + ], + ], + ]; } /** @@ -71,29 +71,29 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { */ public function tearDown() { parent::tearDown(); - $this->quickCleanup(array('civicrm_case_type', 'civicrm_uf_match')); + $this->quickCleanup(['civicrm_case_type', 'civicrm_uf_match']); } /** * Check with empty array. */ public function testCaseTypeCreateEmpty() { - $this->callAPIFailure('CaseType', 'create', array()); + $this->callAPIFailure('CaseType', 'create', []); } /** * Check if required fields are not passed. */ public function testCaseTypeCreateWithoutRequired() { - $params = array( + $params = [ 'name' => 'this case should fail', - ); + ]; $this->callAPIFailure('CaseType', 'create', $params); - $params = array( + $params = [ 'name' => 'this case should fail', 'weight' => 4, - ); + ]; $this->callAPIFailure('CaseType', 'create', $params); } @@ -104,18 +104,18 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { */ public function testCaseTypeCreate() { // Create Case Type. - $params = array( + $params = [ 'title' => 'Application', 'name' => 'Application', 'is_active' => 1, 'weight' => 4, - ); + ]; $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; // Check result. - $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); + $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]); $this->assertEquals($result['values'][$id]['id'], $id); $this->assertEquals($result['values'][$id]['title'], $params['title']); } @@ -125,13 +125,13 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { */ public function testCaseTypeCreate_invalidName() { // Create Case Type - $params = array( + $params = [ 'title' => 'Application', // spaces are not allowed 'name' => 'Appl ication', 'is_active' => 1, 'weight' => 4, - ); + ]; $this->callAPIFailure('CaseType', 'create', $params); } @@ -141,24 +141,24 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { */ public function testCaseTypeUpdate() { // Create Case Type - $params = array( + $params = [ 'title' => 'Application', 'name' => 'Application', 'is_active' => 1, 'weight' => 4, - ); + ]; $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; - $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); + $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]); $caseType = $result['values'][$id]; // Update Case Type. - $params = array('id' => $id); + $params = ['id' => $id]; $params['title'] = $caseType['title'] = 'Something Else'; $this->callAPISuccess('CaseType', 'create', $params); // Verify that updated case Type is exactly equal to the original with new title. - $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); + $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]); $this->assertEquals($result['values'][$id], $caseType); } @@ -167,19 +167,19 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { */ public function testCaseTypeDelete_New() { // Create Case Type. - $params = array( + $params = [ 'title' => 'Application', 'name' => 'Application', 'is_active' => 1, 'weight' => 4, - ); + ]; $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; - $this->callAPISuccess('CaseType', 'delete', array('id' => $id)); + $this->callAPISuccess('CaseType', 'delete', ['id' => $id]); // Check result - case type should no longer exist - $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); + $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]); $this->assertEquals(0, $result['count']); } @@ -195,7 +195,7 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { $id = $result['id']; // Check result - $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); + $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]); $this->assertEquals($result['values'][$id]['id'], $id); $this->assertEquals($result['values'][$id]['title'], $params['title']); $this->assertEquals($result['values'][$id]['definition'], $params['definition']); @@ -212,24 +212,24 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { $params = $this->fixtures['Application_with_Definition']; $createCaseType = $this->callAPISuccess('CaseType', 'create', $params); - $createCase = $this->callAPISuccess('Case', 'create', array( + $createCase = $this->callAPISuccess('Case', 'create', [ 'case_type_id' => $createCaseType['id'], 'contact_id' => $this->_loggedInUser, 'subject' => 'Example', - )); + ]); // Deletion fails while case-type is in-use - $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', array('id' => $createCaseType['id'])); + $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', ['id' => $createCaseType['id']]); $this->assertEquals("You can not delete this case type -- it is assigned to 1 existing case record(s). If you do not want this case type to be used going forward, consider disabling it instead.", $deleteCaseType['error_message']); - $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id'])); + $getCaseType = $this->callAPISuccess('CaseType', 'get', ['id' => $createCaseType['id']]); $this->assertEquals(1, $getCaseType['count']); // Deletion succeeds when it's not in-use. - $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id'])); + $this->callAPISuccess('Case', 'delete', ['id' => $createCase['id']]); // Check result - case type should no longer exist. - $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id'])); - $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id'])); + $this->callAPISuccess('CaseType', 'delete', ['id' => $createCaseType['id']]); + $getCaseType = $this->callAPISuccess('CaseType', 'get', ['id' => $createCaseType['id']]); $this->assertEquals(0, $getCaseType['count']); } @@ -243,18 +243,18 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { public function testCaseStatusByCaseType() { $this->markTestIncomplete('Cannot figure out why this passes locally but fails on Jenkins.'); $statusName = md5(mt_rand()); - $template = $this->callAPISuccess('CaseType', 'getsingle', array('id' => $this->caseTypeId)); + $template = $this->callAPISuccess('CaseType', 'getsingle', ['id' => $this->caseTypeId]); unset($template['id']); $template['name'] = $template['title'] = 'test_case_type'; - $template['definition']['statuses'] = array('Closed', $statusName); + $template['definition']['statuses'] = ['Closed', $statusName]; $this->callAPISuccess('CaseType', 'create', $template); - $this->callAPISuccess('OptionValue', 'create', array( + $this->callAPISuccess('OptionValue', 'create', [ 'option_group_id' => 'case_status', 'name' => $statusName, 'label' => $statusName, 'weight' => 99, - )); - $result = $this->callAPISuccess('Case', 'getoptions', array('field' => 'status_id', 'case_type_id' => 'test_case_type', 'context' => 'validate')); + ]); + $result = $this->callAPISuccess('Case', 'getoptions', ['field' => 'status_id', 'case_type_id' => 'test_case_type', 'context' => 'validate']); $this->assertEquals($template['definition']['statuses'], array_values($result['values'])); } diff --git a/tests/phpunit/api/v3/ConstantTest.php b/tests/phpunit/api/v3/ConstantTest.php index 038f448fa8..cc000f719b 100644 --- a/tests/phpunit/api/v3/ConstantTest.php +++ b/tests/phpunit/api/v3/ConstantTest.php @@ -53,9 +53,9 @@ class api_v3_ConstantTest extends CiviUnitTestCase { * Test civicrm_constant_get( ) for unknown constant */ public function testUnknownConstant() { - $result = $this->callAPIFailure('constant', 'get', array( + $result = $this->callAPIFailure('constant', 'get', [ 'name' => 'thisTypeDoesNotExist', - )); + ]); } /** @@ -63,9 +63,9 @@ class api_v3_ConstantTest extends CiviUnitTestCase { */ public function testActivityStatus() { - $result = $this->callAPISuccess('constant', 'get', array( + $result = $this->callAPISuccess('constant', 'get', [ 'name' => 'activityStatus', - )); + ]); $this->assertTrue($result['count'] > 5, "In line " . __LINE__); $this->assertContains('Scheduled', $result['values'], "In line " . __LINE__); @@ -78,9 +78,9 @@ class api_v3_ConstantTest extends CiviUnitTestCase { * Test civicrm_constant_get( 'activityType' ) */ public function testActivityType() { - $result = $this->callAPIAndDocument('constant', 'get', array( + $result = $this->callAPIAndDocument('constant', 'get', [ 'name' => 'activityType', - ), __FUNCTION__, __FILE__, NULL, NULL, 'get'); + ], __FUNCTION__, __FILE__, NULL, NULL, 'get'); $this->assertTrue($result['count'] > 2, "In line " . __LINE__); $this->assertContains('Meeting', $result['values'], "In line " . __LINE__); } @@ -95,9 +95,9 @@ class api_v3_ConstantTest extends CiviUnitTestCase { // needed to get rid of cached values from previous tests CRM_Core_PseudoConstant::flush(); - $params = array( + $params = [ 'field' => 'location_type_id', - ); + ]; $result = $this->callAPIAndDocument('address', 'getoptions', $params, __FUNCTION__, __FILE__); $this->assertTrue($result['count'] > 3, "In line " . __LINE__); $this->assertContains('Home', $result['values'], "In line " . __LINE__); @@ -113,9 +113,9 @@ class api_v3_ConstantTest extends CiviUnitTestCase { */ public function testPhoneType($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'field' => 'phone_type_id', - ); + ]; $result = $this->callAPIAndDocument('phone', 'getoptions', $params, __FUNCTION__, __FILE__); $this->assertEquals(5, $result['count'], "In line " . __LINE__); @@ -133,9 +133,9 @@ class api_v3_ConstantTest extends CiviUnitTestCase { */ public function testmailProtocol($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'field' => 'protocol', - ); + ]; $result = $this->callAPIAndDocument('mail_settings', 'getoptions', $params, __FUNCTION__, __FILE__); $this->assertEquals(4, $result['count'], "In line " . __LINE__); diff --git a/tests/phpunit/api/v3/ContactTypeTest.php b/tests/phpunit/api/v3/ContactTypeTest.php index a7c1ed513e..503cb126a1 100644 --- a/tests/phpunit/api/v3/ContactTypeTest.php +++ b/tests/phpunit/api/v3/ContactTypeTest.php @@ -35,33 +35,33 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->useTransaction(TRUE); - $params = array( + $params = [ 'label' => 'sub_individual', 'name' => 'sub_individual', // Individual 'parent_id' => 1, 'is_active' => 1, - ); + ]; $result = CRM_Contact_BAO_ContactType::add($params); $this->subTypeIndividual = $params['name']; - $params = array( + $params = [ 'label' => 'sub_organization', 'name' => 'sub_organization', // Organization 'parent_id' => 3, 'is_active' => 1, - ); + ]; $result = CRM_Contact_BAO_ContactType::add($params); $this->subTypeOrganization = $params['name']; - $params = array( + $params = [ 'label' => 'sub_household', 'name' => 'sub_household', // Household 'parent_id' => 2, 'is_active' => 1, - ); + ]; $result = CRM_Contact_BAO_ContactType::add($params); $this->subTypeHousehold = $params['name']; } @@ -76,16 +76,16 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->_apiversion = $version; // check for Type:Individual Subtype:sub_individual - $contactParams = array( + $contactParams = [ 'first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals($result['values'][$contact['id']]['first_name'], $contactParams['first_name'], "In line " . __LINE__); $this->assertEquals($result['values'][$contact['id']]['last_name'], $contactParams['last_name'], "In line " . __LINE__); @@ -94,16 +94,16 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->callAPISuccess('contact', 'delete', $params); // check for Type:Organization Subtype:sub_organization - $contactParams = array( + $contactParams = [ 'organization_name' => 'Compumentor', 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeOrganization, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; $this->assertEquals($result['organization_name'], $contactParams['organization_name'], "In line " . __LINE__); @@ -121,20 +121,20 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->_apiversion = $version; // check for Type:Individual Subtype:sub_household - $contactParams = array( + $contactParams = [ 'first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeHousehold, - ); + ]; $contact = $this->callAPIFailure('contact', 'create', $contactParams); // check for Type:Organization Subtype:sub_individual - $contactParams = array( + $contactParams = [ 'organization_name' => 'Compumentor', 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $contact = $this->callAPIFailure('contact', 'create', $contactParams); } @@ -148,26 +148,26 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->_apiversion = $version; // check for Type:Individual - $contactParams = array( + $contactParams = [ 'first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub_individual - $updateParams = array( + $updateParams = [ 'first_name' => 'John', 'last_name' => 'Grant', 'contact_id' => $contact['id'], 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $updateContact = $this->callAPISuccess('contact', 'create', $updateParams); $this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; @@ -178,25 +178,25 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->callAPISuccess('contact', 'delete', $params); // check for Type:Organization - $contactParams = array( + $contactParams = [ 'organization_name' => 'Compumentor', 'contact_type' => 'Organization', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub_organization - $updateParams = array( + $updateParams = [ 'organization_name' => 'Intel Arts', 'contact_id' => $contact['id'], 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeOrganization, - ); + ]; $updateContact = $this->callAPISuccess('contact', 'create', $updateParams); $this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; @@ -215,44 +215,44 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->_apiversion = $version; // check for Type:Individual - $contactParams = array( + $contactParams = [ 'first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub_household - $updateParams = array( + $updateParams = [ 'first_name' => 'John', 'last_name' => 'Grant', 'contact_id' => $contact['id'], 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeHousehold, - ); + ]; $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $this->callAPISuccess('contact', 'delete', $params); // check for Type:Organization - $contactParams = array( + $contactParams = [ 'organization_name' => 'Compumentor', 'contact_type' => 'Organization', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); - $updateParams = array( + $updateParams = [ 'organization_name' => 'Intel Arts', 'contact_id' => $contact['id'], 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $this->callAPISuccess('contact', 'delete', $params); } @@ -265,40 +265,40 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { public function testContactUpdateSubtypeValid($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'label' => 'sub2_individual', 'name' => 'sub2_individual', // Individual 'parent_id' => 1, 'is_active' => 1, - ); + ]; $getSubtype = CRM_Contact_BAO_ContactType::add($params); $subtype = $params['name']; // check for Type:Individual subype:sub_individual - $contactParams = array( + $contactParams = [ 'first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub2_individual - $updateParams = array( + $updateParams = [ 'id' => $contact['id'], 'first_name' => 'John', 'last_name' => 'Grant', 'contact_id' => $contact['id'], 'contact_type' => 'Individual', 'contact_sub_type' => $subtype, - ); + ]; $updateContact = $this->callAPISuccess('contact', 'create', $updateParams); $this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; @@ -308,37 +308,37 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->assertEquals(end($result['contact_sub_type']), $updateParams['contact_sub_type'], "In line " . __LINE__); $this->callAPISuccess('contact', 'delete', $params); - $params = array( + $params = [ 'label' => 'sub2_organization', 'name' => 'sub2_organization', // Organization 'parent_id' => 3, 'is_active' => 1, - ); + ]; $getSubtype = CRM_Contact_BAO_ContactType::add($params); $subtype = $params['name']; // check for Type:Organization subype:sub_organization - $contactParams = array( + $contactParams = [ 'organization_name' => 'Compumentor', 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeOrganization, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub2_organization - $updateParams = array( + $updateParams = [ 'organization_name' => 'Intel Arts', 'contact_id' => $contact['id'], 'contact_type' => 'Organization', 'contact_sub_type' => $subtype, - ); + ]; $updateContact = $this->callAPISuccess('contact', 'create', $updateParams); $this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; @@ -357,45 +357,45 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { $this->_apiversion = $version; // check for Type:Individual subtype:sub_individual - $contactParams = array( + $contactParams = [ 'first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub_household - $updateParams = array( + $updateParams = [ 'first_name' => 'John', 'last_name' => 'Grant', 'contact_id' => $contact['id'], 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeHousehold, - ); + ]; $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $this->callAPISuccess('contact', 'delete', $params); // check for Type:Organization subtype: - $contactParams = array( + $contactParams = [ 'organization_name' => 'Compumentor', 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeOrganization, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $contactParams); - $updateParams = array( + $updateParams = [ 'organization_name' => 'Intel Arts', 'contact_id' => $contact['id'], 'contact_sub_type' => $this->subTypeIndividual, - ); + ]; $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); - $params = array( + $params = [ 'contact_id' => $contact['id'], - ); + ]; $this->callAPISuccess('contact', 'delete', $params); } diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 95fc147494..56a893409d 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -36,16 +36,16 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { protected $testAmount = 34567; protected $params; protected $id = 0; - protected $contactIds = array(); + protected $contactIds = []; protected $_entity = 'contribution_page'; protected $contribution_result = NULL; - protected $_priceSetParams = array(); + protected $_priceSetParams = []; protected $_membershipBlockAmount = 2; /** * Payment processor details. * @var array */ - protected $_paymentProcessor = array(); + protected $_paymentProcessor = []; /** * @var array @@ -54,7 +54,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * - price_field * - price_field_value */ - protected $_ids = array(); + protected $_ids = []; public $DBResetRequired = TRUE; @@ -62,7 +62,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->contactIds[] = $this->individualCreate(); - $this->params = array( + $this->params = [ 'title' => "Test Contribution Page", 'financial_type_id' => 1, 'currency' => 'NZD', @@ -72,19 +72,19 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'is_email_receipt' => TRUE, 'receipt_from_email' => 'yourconscience@donate.com', 'receipt_from_name' => 'Ego Freud', - ); + ]; - $this->_priceSetParams = array( + $this->_priceSetParams = [ 'is_quick_config' => 1, 'extends' => 'CiviContribute', 'financial_type_id' => 'Donation', 'title' => 'my Page', - ); + ]; } public function tearDown() { foreach ($this->contactIds as $id) { - $this->callAPISuccess('contact', 'delete', array('id' => $id)); + $this->callAPISuccess('contact', 'delete', ['id' => $id]); } $this->quickCleanUpFinancialEntities(); parent::tearDown(); @@ -110,10 +110,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->_apiversion = $version; $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); $this->id = $createResult['id']; - $getParams = array( + $getParams = [ 'currency' => 'NZD', 'financial_type_id' => 1, - ); + ]; $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count']); } @@ -121,12 +121,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public function testGetContributionPageByAmount() { $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); $this->id = $createResult['id']; - $getParams = array( + $getParams = [ // 3456 'amount' => '' . $this->testAmount, 'currency' => 'NZD', 'financial_type_id' => 1, - ); + ]; $getResult = $this->callAPISuccess($this->_entity, 'get', $getParams); $this->assertEquals(1, $getResult['count']); } @@ -138,14 +138,14 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public function testDeleteContributionPage($version) { $this->_apiversion = $version; $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $createResult['id']); + $deleteParams = ['id' => $createResult['id']]; $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } public function testGetFieldsContributionPage() { - $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertEquals(12, $result['values']['start_date']['type']); } @@ -157,7 +157,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $submitParams = $this->getBasicSubmitParams(); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); //assert non-deductible amount $this->assertEquals(5.00, $contribution['non_deductible_amount']); } @@ -177,7 +177,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertEquals($this->formatMoneyInput(0), $contribution['non_deductible_amount']); $this->assertEquals($this->formatMoneyInput(0), $contribution['total_amount']); @@ -189,10 +189,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitNewBillingNameData() { $this->setUpContributionPage(); - $contact = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com')); + $contact = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com']); $priceFieldID = reset($this->_ids['price_field']); $priceFieldValueID = reset($this->_ids['price_field_value']); - $submitParams = array( + $submitParams = [ 'price_' . $priceFieldID => $priceFieldValueID, 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -200,26 +200,26 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_last_name' => 'Woman', 'contactID' => $contact['id'], 'email' => 'wonderwoman@amazon.com', - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contact = $this->callAPISuccess('Contact', 'get', array( + $contact = $this->callAPISuccess('Contact', 'get', [ 'id' => $contact['id'], - 'return' => array( + 'return' => [ 'first_name', 'last_name', 'sort_name', 'display_name', - ), - )); - $this->assertEquals(array( + ], + ]); + $this->assertEquals([ 'first_name' => 'Wonder', 'last_name' => 'Woman', 'display_name' => 'Wonder Woman', 'sort_name' => 'Woman, Wonder', 'id' => $contact['id'], 'contact_id' => $contact['id'], - ), $contact['values'][$contact['id']]); + ], $contact['values'][$contact['id']]); } @@ -229,15 +229,15 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitNewBillingNameDoNotOverwrite() { $this->setUpContributionPage(); - $contact = $this->callAPISuccess('Contact', 'create', array( + $contact = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com', 'first_name' => 'Super', 'last_name' => 'Boy', - )); + ]); $priceFieldID = reset($this->_ids['price_field']); $priceFieldValueID = reset($this->_ids['price_field_value']); - $submitParams = array( + $submitParams = [ 'price_' . $priceFieldID => $priceFieldValueID, 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -245,26 +245,26 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_last_name' => 'Woman', 'contactID' => $contact['id'], 'email' => 'wonderwoman@amazon.com', - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contact = $this->callAPISuccess('Contact', 'get', array( + $contact = $this->callAPISuccess('Contact', 'get', [ 'id' => $contact['id'], - 'return' => array( + 'return' => [ 'first_name', 'last_name', 'sort_name', 'display_name', - ), - )); - $this->assertEquals(array( + ], + ]); + $this->assertEquals([ 'first_name' => 'Super', 'last_name' => 'Boy', 'display_name' => 'Super Boy', 'sort_name' => 'Boy, Super', 'id' => $contact['id'], 'contact_id' => $contact['id'], - ), $contact['values'][$contact['id']]); + ], $contact['values'][$contact['id']]); } @@ -276,27 +276,27 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public function testSubmitRecurMultiProcessorInstantPayment() { $this->setUpContributionPage(); $this->setupPaymentProcessor(); - $paymentProcessor2ID = $this->paymentProcessorCreate(array( + $paymentProcessor2ID = $this->paymentProcessorCreate([ 'payment_processor_type_id' => 'Dummy', 'name' => 'processor 2', 'class_name' => 'Payment_Dummy', 'billing_mode' => 1, - )); + ]); $dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID); - $dummyPP->setDoDirectPaymentResult(array( + $dummyPP->setDoDirectPaymentResult([ 'payment_status_id' => 1, 'trxn_id' => 'create_first_success', 'fee_amount' => .85, - )); + ]); $processor = $dummyPP->getPaymentProcessor(); - $this->callAPISuccess('ContributionPage', 'create', array( + $this->callAPISuccess('ContributionPage', 'create', [ 'id' => $this->_ids['contribution_page'], - 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']), - )); + 'payment_processor' => [$paymentProcessor2ID, $this->_ids['payment_processor']], + ]); $priceFieldID = reset($this->_ids['price_field']); $priceFieldValueID = reset($this->_ids['price_field_value']); - $submitParams = array( + $submitParams = [ 'price_' . $priceFieldID => $priceFieldValueID, 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -304,22 +304,22 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'frequency_interval' => 1, 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessor2ID, - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); $this->assertEquals('create_first_success', $contribution['trxn_id']); $this->assertEquals(10, $contribution['total_amount']); $this->assertEquals(.85, $contribution['fee_amount']); $this->assertEquals(9.15, $contribution['net_amount']); - $this->_checkFinancialRecords(array( + $this->_checkFinancialRecords([ 'id' => $contribution['id'], 'total_amount' => $contribution['total_amount'], 'payment_instrument_id' => $processor['payment_instrument_id'], - ), 'online'); + ], 'online'); } /** @@ -327,7 +327,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMembershipBlockNotSeparatePayment() { $this->setUpMembershipContributionPage(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -336,12 +336,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_last_name' => 'Gruff', 'selectMembership' => $this->_ids['membership_type'], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); - $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id'])); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]); + $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]); } /** @@ -350,8 +350,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public function testSubmitMembershipBlockNotSeparatePaymentProcessorInstantRenew() { $this->setUpMembershipContributionPage(); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1)); - $submitParams = array( + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1]); + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -362,29 +362,29 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); - $this->callAPISuccessGetCount('LineItem', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]); + $this->callAPISuccessGetCount('LineItem', [ 'entity_table' => 'civicrm_membership', 'entity_id' => $membershipPayment['id'], - ), 1); + ], 1); $submitParams['contact_id'] = $contribution['contact_id']; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $this->callAPISuccessGetCount('LineItem', array( + $this->callAPISuccessGetCount('LineItem', [ 'entity_table' => 'civicrm_membership', 'entity_id' => $membershipPayment['id'], - ), 2); - $membership = $this->callAPISuccessGetSingle('Membership', array( + ], 2); + $membership = $this->callAPISuccessGetSingle('Membership', [ 'id' => $membershipPayment['membership_id'], - 'return' => array('end_date', 'join_date', 'start_date'), - )); + 'return' => ['end_date', 'join_date', 'start_date'], + ]); $this->assertEquals(date('Y-m-d'), $membership['start_date']); $this->assertEquals(date('Y-m-d'), $membership['join_date']); $this->assertEquals(date('Y-m-d', strtotime('+ 2 year - 1 day')), $membership['end_date']); @@ -398,7 +398,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpMembershipContributionPage(); $this->addProfile('supporter_profile', $this->_ids['contribution_page']); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -410,16 +410,16 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessor['id'], 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); - $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); - $mut->checkMailLog(array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); + $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]); + $mut->checkMailLog([ 'Membership Type: General', - )); + ]); $mut->stop(); $mut->clearMessages(); } @@ -429,11 +429,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() { $mut = new CiviMailUtils($this, TRUE); - $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0))); + $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 0])]; $this->setUpMembershipContributionPage(); $this->addProfile('supporter_profile', $this->_ids['contribution_page']); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 0, @@ -443,21 +443,21 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'selectMembership' => $this->_ids['membership_type'], 'email-Primary' => 'billy-goat@the-new-bridge.net', 'payment_processor_id' => $this->params['payment_processor_id'], - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); - $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); + $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]); //Assert only one mail is being sent. $msgs = $mut->getAllMessages(); $this->assertCount(1, $msgs); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Membership Type: General', 'Gruffier', - ), array( + ], [ 'Amount', - )); + ]); $mut->stop(); $mut->clearMessages(); } @@ -468,7 +468,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail() { $mut = new CiviMailUtils($this, TRUE); $this->setUpMembershipContributionPage(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -478,14 +478,14 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'is_pay_later' => 1, 'selectMembership' => $this->_ids['membership_type'], 'email-Primary' => 'billy-goat@the-bridge.net', - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); - $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); - $mut->checkMailLog(array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]); + $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]); + $mut->checkMailLog([ 'Membership Amount -... $ 2.00', - )); + ]); $mut->stop(); $mut->clearMessages(); } @@ -495,8 +495,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMembershipBlockIsSeparatePayment() { $this->setUpMembershipContributionPage(TRUE); - $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2))); - $submitParams = array( + $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 2])]; + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -504,16 +504,16 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_middle_name' => 'Goat', 'billing_last_name' => 'Gruff', 'selectMembership' => $this->_ids['membership_type'], - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertCount(2, $contributions['values']); - $lines = $this->callAPISuccess('LineItem', 'get', array('sequential' => 1)); + $lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1]); $this->assertEquals(10, $lines['values'][0]['line_total']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); } @@ -522,9 +522,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() { $this->setUpMembershipContributionPage(TRUE); - $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2))); + $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 2])]; //Pay later - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 0, @@ -533,23 +533,23 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_last_name' => 'Gruff', 'is_pay_later' => 1, 'selectMembership' => $this->_ids['membership_type'], - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertCount(2, $contributions['values']); foreach ($contributions['values'] as $val) { $this->assertEquals('Pending', $val['contribution_status']); } //Membership should be in Pending state. - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); - $pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', array( - 'return' => array("id"), + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); + $pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', [ + 'return' => ["id"], 'name' => "Pending", - )); + ]); $this->assertEquals($membership['status_id'], $pendingStatus['id']); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); } @@ -562,7 +562,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpMembershipContributionPage(TRUE); $this->addProfile('supporter_profile', $this->_ids['contribution_page']); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -574,28 +574,28 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessor['id'], 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertCount(2, $contributions['values']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); // We should have two separate email messages, each with their own amount // line and no total line. $mut->checkAllMailLog( - array( + [ 'Amount: $ 2.00', 'Amount: $ 10.00', 'Membership Fee', - ), - array( + ], + [ 'Total: $', - ) + ] ); $mut->stop(); $mut->clearMessages(); @@ -606,11 +606,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() { $mut = new CiviMailUtils($this, TRUE); - $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0))); + $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 0])]; $this->setUpMembershipContributionPage(TRUE); $this->addProfile('supporter_profile', $this->_ids['contribution_page']); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 0, @@ -620,20 +620,20 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'selectMembership' => $this->_ids['membership_type'], 'payment_processor_id' => 0, 'email-Primary' => 'gruffalo@the-bridge.net', - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertCount(2, $contributions['values']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Gruffalo', 'General Membership: $ 0.00', 'Membership Fee', - )); + ]); $mut->stop(); $mut->clearMessages(); } @@ -642,10 +642,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * Test submit with a membership block in place. */ public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() { - $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 6))); - $this->_ids['membership_type'][] = $this->membershipTypeCreate(array('name' => 'Student', 'minimum_fee' => 50)); + $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 6])]; + $this->_ids['membership_type'][] = $this->membershipTypeCreate(['name' => 'Student', 'minimum_fee' => 50]); $this->setUpMembershipContributionPage(TRUE); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1], 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -653,17 +653,17 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_middle_name' => 'Goat', 'billing_last_name' => 'Gruff', 'selectMembership' => $this->_ids['membership_type'][1], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); + $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertCount(2, $contributions['values']); $ids = array_keys($contributions['values']); $this->assertEquals('10.00', $contributions['values'][$ids[0]]['total_amount']); $this->assertEquals('50.00', $contributions['values'][$ids[1]]['total_amount']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); } @@ -676,8 +676,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $this->setUpMembershipContributionPage(TRUE); $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']); - $processor->setDoDirectPaymentResult(array('fee_amount' => .72)); - $submitParams = array( + $processor->setDoDirectPaymentResult(['fee_amount' => .72]); + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -689,21 +689,21 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessor['id'], 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contributions = $this->callAPISuccess('contribution', 'get', array( + $contributions = $this->callAPISuccess('contribution', 'get', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); $this->assertCount(2, $contributions['values']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_table' => 'civicrm_membership')); + $lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_table' => 'civicrm_membership']); $this->assertEquals($lineItem['entity_id'], $membership['id']); $this->assertEquals($lineItem['contribution_id'], $membershipPayment['contribution_id']); $this->assertEquals($lineItem['qty'], 1); @@ -715,7 +715,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { } // The total string is currently absent & it seems worse with - although at some point // it may have been intended - $mut->checkAllMailLog(array('$ 2.00', 'Contribution Amount', '$ 10.00'), array('Total:')); + $mut->checkAllMailLog(['$ 2.00', 'Contribution Amount', '$ 10.00'], ['Total:']); $mut->stop(); $mut->clearMessages(); } @@ -735,10 +735,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setCurrencySeparators($thousandSeparator); $this->setUpMembershipContributionPage(TRUE); $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']); - $processor->setDoDirectPaymentResult(array('fee_amount' => .72)); + $processor->setDoDirectPaymentResult(['fee_amount' => .72]); $test_uniq = uniqid(); $contributionPageAmount = 10; - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => $contributionPageAmount, @@ -750,28 +750,28 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_paymentProcessor['id'], 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'TEST_UNIQ' => $test_uniq, - ); + ]; // set custom hook - $this->hookClass->setHook('civicrm_alterPaymentProcessorParams', array($this, 'hook_civicrm_alterPaymentProcessorParams')); + $this->hookClass->setHook('civicrm_alterPaymentProcessorParams', [$this, 'hook_civicrm_alterPaymentProcessorParams']); $this->callAPISuccess('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contributions = $this->callAPISuccess('contribution', 'get', array( + $contributions = $this->callAPISuccess('contribution', 'get', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); - $result = civicrm_api3('SystemLog', 'get', array( + $result = civicrm_api3('SystemLog', 'get', [ 'sequential' => 1, - 'message' => array('LIKE' => "%{$test_uniq}%"), - )); + 'message' => ['LIKE' => "%{$test_uniq}%"], + ]); $this->assertCount(2, $result['values'], "Expected exactly 2 log entries matching {$test_uniq}."); // Examine logged entries to ensure correct values. - $contribution_ids = array(); + $contribution_ids = []; $found_membership_amount = $found_contribution_amount = FALSE; foreach ($result['values'] as $value) { list($junk, $json) = explode("$test_uniq:", $value['message']); @@ -809,27 +809,27 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->createLoggedInUser(); $priceFieldID = reset($this->_ids['price_field']); $priceFieldValueID = reset($this->_ids['price_field_value']); - $submitParams = array( + $submitParams = [ 'price_' . $priceFieldID => $priceFieldValueID, 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2008), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2008], 'cvv2' => 123, - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccessGetSingle('contribution', array( + $contribution = $this->callAPISuccessGetSingle('contribution', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 'Failed', - )); + ]); - $this->callAPISuccessGetSingle('activity', array( + $this->callAPISuccessGetSingle('activity', [ 'source_record_id' => $contribution['id'], 'activity_type_id' => 'Failed Payment', - )); + ]); } @@ -842,7 +842,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * - create another - end date should be extended */ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentYear() { - $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(array('duration_unit' => 'year', 'recur_frequency_unit' => 'year')); + $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'year', 'recur_frequency_unit' => 'year']); } /** @@ -854,7 +854,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * - create another - end date should be extended */ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentMonth() { - $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(array('duration_unit' => 'month', 'recur_frequency_unit' => 'month')); + $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'month', 'recur_frequency_unit' => 'month']); } /** @@ -876,7 +876,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception * @throws \Exception */ - public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = array()) { + public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = []) { $this->params['is_recur'] = 1; $this->params['recur_frequency_unit'] = $params['recur_frequency_unit']; $membershipTypeParams['duration_unit'] = $params['duration_unit']; @@ -888,7 +888,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { } $this->setUpMembershipContributionPage(FALSE, FALSE, $membershipTypeParams); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']); $processor = $dummyPP->getPaymentProcessor(); if ($params['recur_frequency_unit'] === $params['duration_unit']) { @@ -900,7 +900,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $expectedMembershipStatus = 5; } - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -912,45 +912,45 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'is_recur' => 1, 'frequency_interval' => 1, 'frequency_unit' => $this->params['recur_frequency_unit'], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']); $this->assertEquals('create_first_success', $contribution['trxn_id']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contribution['contact_id']); $this->assertEquals($expectedMembershipStatus, $membership['status_id']); - $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); + $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]); - $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); + $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $contribution['id'], 'entity_id' => $membership['id']]); //renew it with processor setting completed - should extend membership $submitParams['contact_id'] = $contribution['contact_id']; - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_second_success']); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $this->callAPISuccess('contribution', 'getsingle', array( - 'id' => array('NOT IN' => array($contribution['id'])), + $this->callAPISuccess('contribution', 'getsingle', [ + 'id' => ['NOT IN' => [$contribution['id']]], 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); - $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + ]); + $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); if ($durationUnit) { // We only have an end_date if frequency units match, otherwise membership won't be autorenewed and dates won't be calculated. $renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membership['end_date']); $this->assertEquals($renewedMembershipEndDate, $renewedMembership['end_date']); } - $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); + $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]); $this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']); $this->assertEquals(5, $recurringContribution['contribution_status_id']); } @@ -967,13 +967,13 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->params['is_recur'] = 1; $this->params['recur_frequency_unit'] = $membershipTypeParams['duration_unit'] = 'year'; // Add a membership so membership & contribution are not both 1. - $preExistingMembershipID = $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0])); + $preExistingMembershipID = $this->contactMembershipCreate(['contact_id' => $this->contactIds[0]]); $this->setUpMembershipContributionPage(FALSE, FALSE, $membershipTypeParams); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']); $processor = $dummyPP->getPaymentProcessor(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'price_' . $this->_ids['price_field']['cont'] => 88, 'id' => (int) $this->_ids['contribution_page'], @@ -986,55 +986,55 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'is_recur' => 1, 'frequency_interval' => 1, 'frequency_unit' => $this->params['recur_frequency_unit'], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']); $this->assertEquals('create_first_success', $contribution['trxn_id']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contribution['contact_id']); $this->assertEquals(1, $membership['status_id']); - $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); + $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]); - $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $contribution['id'])); + $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $contribution['id']]); $this->assertEquals(2, $lines['count']); $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']); $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']); $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']); $this->assertEquals($contribution['id'], $lines['values'][1]['entity_id']); - $this->callAPISuccessGetSingle('MembershipPayment', array('contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1)); + $this->callAPISuccessGetSingle('MembershipPayment', ['contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1]); //renew it with processor setting completed - should extend membership $submitParams['contact_id'] = $contribution['contact_id']; - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_second_success']); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $renewContribution = $this->callAPISuccess('contribution', 'getsingle', array( - 'id' => array('NOT IN' => array($contribution['id'])), + $renewContribution = $this->callAPISuccess('contribution', 'getsingle', [ + 'id' => ['NOT IN' => [$contribution['id']]], 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); - $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $renewContribution['id'])); + ]); + $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $renewContribution['id']]); $this->assertEquals(2, $lines['count']); $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']); $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']); $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']); $this->assertEquals($renewContribution['id'], $lines['values'][1]['entity_id']); - $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals(date('Y-m-d', strtotime('+ 1 ' . $this->params['recur_frequency_unit'], strtotime($membership['end_date']))), $renewedMembership['end_date']); - $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); + $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]); $this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']); $this->assertEquals(5, $recurringContribution['contribution_status_id']); } @@ -1051,16 +1051,16 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->params['is_recur'] = 1; $this->params['recur_frequency_unit'] = $membershipTypeParams['duration_unit'] = 'year'; // Add a membership so membership & contribution are not both 1. - $preExistingMembershipID = $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0])); + $preExistingMembershipID = $this->contactMembershipCreate(['contact_id' => $this->contactIds[0]]); $this->createPriceSetWithPage(); $this->addSecondOrganizationMembershipToPriceSet(); $this->setupPaymentProcessor(); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']); $processor = $dummyPP->getPaymentProcessor(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value']['cont'], 'price_' . $this->_ids['price_field']['org1'] => $this->_ids['price_field_value']['org1'], 'price_' . $this->_ids['price_field']['org2'] => $this->_ids['price_field_value']['org2'], @@ -1074,26 +1074,26 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'frequency_interval' => 1, 'frequency_unit' => $this->params['recur_frequency_unit'], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']); $this->assertEquals('create_first_success', $contribution['trxn_id']); - $membershipPayments = $this->callAPISuccess('membership_payment', 'get', array( + $membershipPayments = $this->callAPISuccess('membership_payment', 'get', [ 'sequential' => 1, 'contribution_id' => $contribution['id'], - )); + ]); $this->assertEquals(2, $membershipPayments['count']); - $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $contribution['id'])); + $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $contribution['id']]); $this->assertEquals(3, $lines['count']); $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']); $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']); @@ -1102,26 +1102,26 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertEquals('civicrm_membership', $lines['values'][2]['entity_table']); $this->assertEquals($preExistingMembershipID + 2, $lines['values'][2]['entity_id']); - $this->callAPISuccessGetSingle('MembershipPayment', array('contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1)); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $preExistingMembershipID + 1)); + $this->callAPISuccessGetSingle('MembershipPayment', ['contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1]); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $preExistingMembershipID + 1]); //renew it with processor setting completed - should extend membership $submitParams['contact_id'] = $contribution['contact_id']; - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_second_success']); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $renewContribution = $this->callAPISuccess('contribution', 'getsingle', array( - 'id' => array('NOT IN' => array($contribution['id'])), + $renewContribution = $this->callAPISuccess('contribution', 'getsingle', [ + 'id' => ['NOT IN' => [$contribution['id']]], 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); - $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $renewContribution['id'])); + ]); + $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $renewContribution['id']]); $this->assertEquals(3, $lines['count']); $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']); $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']); $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']); $this->assertEquals($renewContribution['id'], $lines['values'][1]['entity_id']); - $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $preExistingMembershipID + 1)); + $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $preExistingMembershipID + 1]); $this->assertEquals(date('Y-m-d', strtotime('+ 1 ' . $this->params['recur_frequency_unit'], strtotime($membership['end_date']))), $renewedMembership['end_date']); } @@ -1130,18 +1130,18 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function addSecondOrganizationMembershipToPriceSet() { $organization2ID = $this->organizationCreate(); - $membershipTypes = $this->callAPISuccess('MembershipType', 'get', array()); + $membershipTypes = $this->callAPISuccess('MembershipType', 'get', []); $this->_ids['membership_type'] = array_keys($membershipTypes['values']); - $this->_ids['membership_type']['org2'] = $this->membershipTypeCreate(array('contact_id' => $organization2ID, 'name' => 'Org 2')); - $priceField = $this->callAPISuccess('PriceField', 'create', array( + $this->_ids['membership_type']['org2'] = $this->membershipTypeCreate(['contact_id' => $organization2ID, 'name' => 'Org 2']); + $priceField = $this->callAPISuccess('PriceField', 'create', [ 'price_set_id' => $this->_ids['price_set'], 'html_type' => 'Radio', 'name' => 'Org1 Price', 'label' => 'Org1Price', - )); + ]); $this->_ids['price_field']['org1'] = $priceField['id']; - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'org1 amount', 'label' => 'org 1 Amount', 'amount' => 2, @@ -1149,18 +1149,18 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'format.only_id' => TRUE, 'membership_type_id' => reset($this->_ids['membership_type']), 'price_field_id' => $priceField['id'], - )); + ]); $this->_ids['price_field_value']['org1'] = $priceFieldValue; - $priceField = $this->callAPISuccess('PriceField', 'create', array( + $priceField = $this->callAPISuccess('PriceField', 'create', [ 'price_set_id' => $this->_ids['price_set'], 'html_type' => 'Radio', 'name' => 'Org2 Price', 'label' => 'Org2Price', - )); + ]); $this->_ids['price_field']['org2'] = $priceField['id']; - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'org2 amount', 'label' => 'org 2 Amount', 'amount' => 200, @@ -1168,7 +1168,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'format.only_id' => TRUE, 'membership_type_id' => $this->_ids['membership_type']['org2'], 'price_field_id' => $priceField['id'], - )); + ]); $this->_ids['price_field_value']['org2'] = $priceFieldValue; } @@ -1185,9 +1185,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpMembershipContributionPage(TRUE); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -1199,25 +1199,25 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'is_recur' => 1, 'auto_renew' => TRUE, 'frequency_interval' => 1, 'frequency_unit' => 'month', - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, - )); + ]); $this->assertEquals(2, $contribution['count']); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); - $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); + $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertNotEmpty($contribution['values'][$membershipPayment['contribution_id']]['contribution_recur_id']); - $this->callAPISuccess('contribution_recur', 'getsingle', array()); + $this->callAPISuccess('contribution_recur', 'getsingle', []); } /** @@ -1233,16 +1233,16 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->params['recur_frequency_unit'] = $membershipTypeParams['duration_unit'] = 'year'; $this->setUpMembershipContributionPage(); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); - $this->membershipTypeCreate(array('name' => 'Student')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 2]); + $this->membershipTypeCreate(['name' => 'Student']); // Add a contribution & a couple of memberships so the id will not be 1 & will differ from membership id. // This saves us from 'accidental success'. - $this->contributionCreate(array('contact_id' => $this->contactIds[0])); - $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0])); - $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student')); + $this->contributionCreate(['contact_id' => $this->contactIds[0]]); + $this->contactMembershipCreate(['contact_id' => $this->contactIds[0]]); + $this->contactMembershipCreate(['contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student']); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -1254,64 +1254,64 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'is_recur' => 1, 'frequency_interval' => 1, 'frequency_unit' => $this->params['recur_frequency_unit'], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 2, - )); + ]); - $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); + $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []); $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); $this->assertEquals($membership['contact_id'], $contribution['contact_id']); $this->assertEquals(5, $membership['status_id']); - $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'])); + $line = $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $contribution['id']]); $this->assertEquals('civicrm_membership', $line['entity_table']); $this->assertEquals($membership['id'], $line['entity_id']); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'trxn_id' => 'ipn_called', 'payment_processor_id' => $this->_paymentProcessor['id'], - )); - $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'])); + ]); + $line = $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $contribution['id']]); $this->assertEquals('civicrm_membership', $line['entity_table']); $this->assertEquals($membership['id'], $line['entity_id']); - $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); //renew it with processor setting completed - should extend membership - $submitParams = array_merge($submitParams, array( + $submitParams = array_merge($submitParams, [ 'contact_id' => $contribution['contact_id'], 'is_recur' => 1, 'frequency_interval' => 1, 'frequency_unit' => $this->params['recur_frequency_unit'], - )); + ]); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 2]); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $newContribution = $this->callAPISuccess('contribution', 'getsingle', array( - 'id' => array( - 'NOT IN' => array($contribution['id']), - ), + $newContribution = $this->callAPISuccess('contribution', 'getsingle', [ + 'id' => [ + 'NOT IN' => [$contribution['id']], + ], 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 2, - )); - $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $newContribution['id'])); + ]); + $line = $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $newContribution['id']]); $this->assertEquals('civicrm_membership', $line['entity_table']); $this->assertEquals($membership['id'], $line['entity_id']); - $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); + $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]); //no renewal as the date hasn't changed $this->assertEquals($membership['end_date'], $renewedMembership['end_date']); - $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id'])); + $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $newContribution['contribution_recur_id']]); $this->assertEquals(2, $recurringContribution['contribution_status_id']); } @@ -1322,10 +1322,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { //Create recur contribution page. $this->setUpMembershipContributionPage(TRUE, TRUE); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']); //Sumbit payment with recur disabled. - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 10, @@ -1339,13 +1339,13 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, - ); + ]; //Assert if recur contribution is created. $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $recur = $this->callAPISuccess('contribution_recur', 'get', array()); + $recur = $this->callAPISuccess('contribution_recur', 'get', []); $this->assertEmpty($recur['count']); } @@ -1355,32 +1355,32 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * @param bool $isRecur * @param array $membershipTypeParams Parameters to pass to membershiptype.create API */ - public function setUpMembershipContributionPage($isSeparatePayment = FALSE, $isRecur = FALSE, $membershipTypeParams = array()) { + public function setUpMembershipContributionPage($isSeparatePayment = FALSE, $isRecur = FALSE, $membershipTypeParams = []) { $this->setUpMembershipBlockPriceSet($membershipTypeParams); $this->setupPaymentProcessor(); $this->setUpContributionPage($isRecur); - $this->callAPISuccess('membership_block', 'create', array( + $this->callAPISuccess('membership_block', 'create', [ 'entity_id' => $this->_ids['contribution_page'], 'entity_table' => 'civicrm_contribution_page', 'is_required' => TRUE, 'is_active' => TRUE, 'is_separate_payment' => $isSeparatePayment, 'membership_type_default' => $this->_ids['membership_type'], - )); + ]); } /** * Set up pledge block. */ public function setUpPledgeBlock() { - $params = array( + $params = [ 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_ids['contribution_page'], 'pledge_frequency_unit' => 'week', 'is_pledge_interval' => 0, - 'pledge_start_date' => json_encode(array('calendar_date' => date('Ymd', strtotime("+1 month")))), - ); + 'pledge_start_date' => json_encode(['calendar_date' => date('Ymd', strtotime("+1 month"))]), + ]; $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); $this->_ids['pledge_block_id'] = $pledgeBlock->id; } @@ -1390,28 +1390,28 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * * This function ensures it exists & populates $this->_ids with it's data */ - public function setUpMembershipBlockPriceSet($membershipTypeParams = array()) { - $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array( + public function setUpMembershipBlockPriceSet($membershipTypeParams = []) { + $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', [ 'name' => 'default_membership_type_amount', 'return' => 'id', - )); + ]); if (empty($this->_ids['membership_type'])) { - $membershipTypeParams = array_merge(array( + $membershipTypeParams = array_merge([ 'minimum_fee' => 2, - ), $membershipTypeParams); - $this->_ids['membership_type'] = array($this->membershipTypeCreate($membershipTypeParams)); + ], $membershipTypeParams); + $this->_ids['membership_type'] = [$this->membershipTypeCreate($membershipTypeParams)]; } - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => reset($this->_ids['price_set']), 'name' => 'membership_amount', 'label' => 'Membership Amount', 'html_type' => 'Radio', 'sequential' => 1, - )); + ]); $this->_ids['price_field'][] = $priceField['id']; foreach ($this->_ids['membership_type'] as $membershipTypeID) { - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'membership_amount', 'label' => 'Membership Amount', 'amount' => $this->_membershipBlockAmount, @@ -1419,20 +1419,20 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'format.only_id' => TRUE, 'membership_type_id' => $membershipTypeID, 'price_field_id' => $priceField['id'], - )); + ]); $this->_ids['price_field_value'][] = $priceFieldValue; } if (!empty($this->_ids['membership_type']['org2'])) { - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => reset($this->_ids['price_set']), 'name' => 'membership_org2', 'label' => 'Membership Org2', 'html_type' => 'Checkbox', 'sequential' => 1, - )); + ]); $this->_ids['price_field']['org2'] = $priceField['id']; - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'membership_org2', 'label' => 'Membership org 2', 'amount' => 55, @@ -1440,26 +1440,26 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'format.only_id' => TRUE, 'membership_type_id' => $this->_ids['membership_type']['org2'], 'price_field_id' => $priceField['id'], - )); + ]); $this->_ids['price_field_value']['org2'] = $priceFieldValue; } - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => reset($this->_ids['price_set']), 'name' => 'Contribution', 'label' => 'Contribution', 'html_type' => 'Text', 'sequential' => 1, 'is_enter_qty' => 1, - )); + ]); $this->_ids['price_field']['cont'] = $priceField['id']; - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'contribution', 'label' => 'Give me money', 'amount' => 88, 'financial_type_id' => 'Donation', 'format.only_id' => TRUE, 'price_field_id' => $priceField['id'], - )); + ]); $this->_ids['price_field_value'][] = $priceFieldValue; } @@ -1467,21 +1467,21 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * Add text field other amount to the price set. */ public function addOtherAmountFieldToMembershipPriceSet() { - $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', array( + $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => reset($this->_ids['price_set']), 'name' => 'other_amount', 'label' => 'Other Amount', 'html_type' => 'Text', 'format.only_id' => TRUE, 'sequential' => 1, - )); - $this->_ids['price_field_value']['other_amount'] = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $this->_ids['price_field_value']['other_amount'] = $this->callAPISuccess('price_field_value', 'create', [ 'financial_type_id' => 'Donation', 'format.only_id' => TRUE, 'label' => 'Other Amount', 'amount' => 1, 'price_field_id' => $this->_ids['price_field']['other_amount'], - )); + ]); } /** @@ -1502,40 +1502,40 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); if (empty($this->_ids['price_field'])) { - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $priceSetID, 'label' => 'Goat Breed', 'html_type' => 'Radio', - )); - $this->_ids['price_field'] = array($priceField['id']); + ]); + $this->_ids['price_field'] = [$priceField['id']]; } if (empty($this->_ids['price_field_value'])) { - $this->callAPISuccess('price_field_value', 'create', array( + $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Long Haired Goat', 'financial_type_id' => 'Donation', 'amount' => 20, 'non_deductible_amount' => 15, - )); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating Goat', 'financial_type_id' => 'Donation', 'amount' => 10, 'non_deductible_amount' => 5, - )); - $this->_ids['price_field_value'] = array($priceFieldValue['id']); + ]); + $this->_ids['price_field_value'] = [$priceFieldValue['id']]; - $this->_ids['price_field_value']['cheapskate'] = $this->callAPISuccess('price_field_value', 'create', array( + $this->_ids['price_field_value']['cheapskate'] = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Stingy Goat', 'financial_type_id' => 'Donation', 'amount' => 0, 'non_deductible_amount' => 0, - ))['id']; + ])['id']; } $this->_ids['contribution_page'] = $contributionPageResult['id']; } @@ -1549,29 +1549,29 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $contributionPage = $this->callAPISuccess($this->_entity, 'create', $this->params); $this->_ids['contribution_page'] = $contributionPage['id']; - $this->_ids['membership_type'] = $this->membershipTypeCreate(array( + $this->_ids['membership_type'] = $this->membershipTypeCreate([ // force auto-renew 'auto_renew' => 2, 'duration_unit' => 'month', - )); + ]); - $priceSet = civicrm_api3('PriceSet', 'create', array( + $priceSet = civicrm_api3('PriceSet', 'create', [ 'is_quick_config' => 0, 'extends' => 'CiviMember', 'financial_type_id' => 'Member Dues', 'title' => 'CRM-21177', - )); + ]); $this->_ids['price_set'] = $priceSet['id']; - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $this->_ids['price_set'], 'name' => 'membership_type', 'label' => 'Membership Type', 'html_type' => 'Radio', - )); + ]); $this->_ids['price_field'] = $priceField['id']; - $priceFieldValueMonthly = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValueMonthly = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'CRM-21177_Monthly', 'label' => 'CRM-21177 - Monthly', 'amount' => 20, @@ -1579,10 +1579,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'membership_type_id' => $this->_ids['membership_type'], 'price_field_id' => $this->_ids['price_field'], 'financial_type_id' => 'Member Dues', - )); + ]); $this->_ids['price_field_value_monthly'] = $priceFieldValueMonthly['id']; - $priceFieldValueYearly = $this->callAPISuccess('price_field_value', 'create', array( + $priceFieldValueYearly = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'CRM-21177_Yearly', 'label' => 'CRM-21177 - Yearly', 'amount' => 200, @@ -1590,19 +1590,19 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'membership_type_id' => $this->_ids['membership_type'], 'price_field_id' => $this->_ids['price_field'], 'financial_type_id' => 'Member Dues', - )); + ]); $this->_ids['price_field_value_yearly'] = $priceFieldValueYearly['id']; CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_ids['contribution_page'], $this->_ids['price_set']); - $this->callAPISuccess('membership_block', 'create', array( + $this->callAPISuccess('membership_block', 'create', [ 'entity_id' => $this->_ids['contribution_page'], 'entity_table' => 'civicrm_contribution_page', 'is_required' => TRUE, 'is_separate_payment' => FALSE, 'is_active' => TRUE, 'membership_type_default' => $this->_ids['membership_type'], - )); + ]); } /** @@ -1610,7 +1610,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMultiIntervalMembershipContributionPage() { $this->setUpMultiIntervalMembershipContributionPage(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'] => $this->_ids['price_field_value_monthly'], 'id' => (int) $this->_ids['contribution_page'], 'amount' => 20, @@ -1620,20 +1620,20 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => $this->_ids['payment_processor'], 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'auto_renew' => 1, - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $submitParams); $submitParams['price_' . $this->_ids['price_field']] = $this->_ids['price_field_value_yearly']; $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccess('Contribution', 'get', array( + $contribution = $this->callAPISuccess('Contribution', 'get', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'sequential' => 1, - 'api.ContributionRecur.getsingle' => array(), - )); + 'api.ContributionRecur.getsingle' => [], + ]); $this->assertEquals(1, $contribution['values'][0]['api.ContributionRecur.getsingle']['frequency_interval']); //$this->assertEquals(12, $contribution['values'][1]['api.ContributionRecur.getsingle']['frequency_interval']); } @@ -1646,12 +1646,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * @throws \Exception */ public static function tearDownAfterClass() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_financial_type', 'civicrm_contribution', 'civicrm_contribution_page', - ); + ]; $unitTest = new CiviUnitTestCase(); $unitTest->quickCleanup($tablesToTruncate); } @@ -1660,12 +1660,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * Create a payment processor instance. */ protected function setupPaymentProcessor() { - $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array( + $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate([ 'payment_processor_type_id' => 'Dummy', 'class_name' => 'Payment_Dummy', 'billing_mode' => 1, - )); - $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id'])); + ]); + $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', ['id' => $this->params['payment_processor_id']]); } /** @@ -1680,9 +1680,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpPledgeBlock(); $this->setupPaymentProcessor(); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']); - $submitParams = array( + $submitParams = [ 'id' => (int) $this->_ids['contribution_page'], 'amount' => 100, 'billing_first_name' => 'Billy', @@ -1692,35 +1692,35 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'pledge_frequency_interval' => 1, 'pledge_frequency_unit' => 'week', 'pledge_installments' => 3, 'is_pledge' => TRUE, 'pledge_block_id' => (int) $this->_ids['pledge_block_id'], - ); + ]; $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); // Check if contribution created. - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $this->_ids['contribution_page'], // Will be pending when actual payment processor is used (dummy processor does not support future payments). 'contribution_status_id' => 'Completed', - )); + ]); $this->assertEquals('create_first_success', $contribution['trxn_id']); // Check if pledge created. - $pledge = $this->callAPISuccess('pledge', 'getsingle', array()); + $pledge = $this->callAPISuccess('pledge', 'getsingle', []); $this->assertEquals(date('Ymd', strtotime($pledge['pledge_start_date'])), date('Ymd', strtotime("+1 month"))); $this->assertEquals($pledge['pledge_amount'], 300.00); // Check if pledge payments created. - $params = array( + $params = [ 'pledge_id' => $pledge['id'], - ); + ]; $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); $this->assertEquals($pledgePayment['count'], 3); $this->assertEquals(date('Ymd', strtotime($pledgePayment['values'][1]['scheduled_date'])), date('Ymd', strtotime("+1 month"))); @@ -1729,7 +1729,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertEquals($pledgePayment['values'][1]['status_id'], 1); // Check contribution recur record. - $recur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); + $recur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]); $this->assertEquals(date('Ymd', strtotime($recur['start_date'])), date('Ymd', strtotime("+1 month"))); $this->assertEquals($recur['amount'], 100.00); // In progress status. @@ -1743,13 +1743,13 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitPledgePayment() { $this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment(); - $pledge = $this->callAPISuccess('pledge', 'getsingle', array()); - $params = array( + $pledge = $this->callAPISuccess('pledge', 'getsingle', []); + $params = [ 'pledge_id' => $pledge['id'], - ); - $submitParams = array( + ]; + $submitParams = [ 'id' => (int) $pledge['pledge_contribution_page_id'], - 'pledge_amount' => array(2 => 1), + 'pledge_amount' => [2 => 1], 'billing_first_name' => 'Billy', 'billing_middle_name' => 'Goat', 'billing_last_name' => 'Gruff', @@ -1757,7 +1757,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040], 'cvv2' => 123, 'pledge_id' => $pledge['id'], 'cid' => $pledge['contact_id'], @@ -1765,19 +1765,19 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'amount' => 100.00, 'is_pledge' => TRUE, 'pledge_block_id' => $this->_ids['pledge_block_id'], - ); + ]; $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); $this->assertEquals($pledgePayment['values'][2]['status_id'], 2); $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); // Check if contribution created. - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'contribution_page_id' => $pledge['pledge_contribution_page_id'], 'contribution_status_id' => 'Completed', 'contact_id' => $pledge['contact_id'], - 'contribution_recur_id' => array('IS NULL' => 1), - )); + 'contribution_recur_id' => ['IS NULL' => 1], + ]); $this->assertEquals(100.00, $contribution['total_amount']); $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); @@ -1797,7 +1797,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setCurrencySeparators($thousandSeparator); $this->_priceSetParams['is_quick_config'] = 0; $this->setUpContributionPage(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 80, @@ -1805,18 +1805,18 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'last_name' => 'Gruff', 'email' => 'billy@goat.gruff', 'is_pay_later' => TRUE, - ); + ]; $this->addPriceFields($submitParams); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccessGetSingle('contribution', array( + $contribution = $this->callAPISuccessGetSingle('contribution', [ 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 'Pending', - )); + ]); $this->assertEquals(80, $contribution['total_amount']); - $lineItems = $this->callAPISuccess('LineItem', 'get', array( + $lineItems = $this->callAPISuccess('LineItem', 'get', [ 'contribution_id' => $contribution['id'], - )); + ]); $this->assertEquals(3, $lineItems['count']); $totalLineAmount = 0; foreach ($lineItems['values'] as $lineItem) { @@ -1831,29 +1831,29 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function addPriceFields(&$params) { $priceSetID = reset($this->_ids['price_set']); - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $priceSetID, 'label' => 'Chicken Breed', 'html_type' => 'CheckBox', - )); - $priceFieldValue1 = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $priceFieldValue1 = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating chicken -1', 'financial_type_id' => 'Donation', 'amount' => 30, - )); - $priceFieldValue2 = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $priceFieldValue2 = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating chicken -2', 'financial_type_id' => 'Donation', 'amount' => 40, - )); - $params['price_' . $priceField['id']] = array( + ]); + $params['price_' . $priceField['id']] = [ $priceFieldValue1['id'] => 1, $priceFieldValue2['id'] => 1, - ); + ]; } /** @@ -1874,7 +1874,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->relationForFinancialTypeWithFinancialAccount($financialType['id'], 5); $this->setUpContributionPage(); - $submitParams = array( + $submitParams = [ 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'first_name' => 'J', @@ -1882,22 +1882,22 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'email' => 'JT@ohcanada.ca', 'is_pay_later' => TRUE, 'receive_date' => date('Y-m-d H:i:s'), - ); + ]; // Create PriceSet/PriceField $priceSetID = reset($this->_ids['price_set']); - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $priceSetID, 'label' => 'Printing Rights', 'html_type' => 'Text', - )); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Printing Rights', 'financial_type_id' => $financialTypeId, 'amount' => '16.95', - )); + ]); $priceFieldId = $priceField['id']; // Set quantity for our test @@ -1909,15 +1909,15 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $submitParams['tax_amount'] = $this->formatMoneyInput(180 * 16.95 * 0.10); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $contribution = $this->callAPISuccessGetSingle('contribution', array( + $contribution = $this->callAPISuccessGetSingle('contribution', [ 'contribution_page_id' => $this->_ids['contribution_page'], - )); + ]); // Retrieve the lineItem that belongs to the Printing Rights and check the tax_amount CiviCRM Core calculated for it - $lineItem = $this->callAPISuccessGetSingle('LineItem', array( + $lineItem = $this->callAPISuccessGetSingle('LineItem', [ 'contribution_id' => $contribution['id'], 'label' => 'Printing Rights', - )); + ]); $lineItem_TaxAmount = round($lineItem['tax_amount'], 2); @@ -1980,11 +1980,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { // Log parameters for later debugging and testing. $message = __FUNCTION__ . ": {$rawParams['TEST_UNIQ']}:"; - $log_params = array_intersect_key($rawParams, array( + $log_params = array_intersect_key($rawParams, [ 'amount' => 1, 'total_amount' => 1, 'contributionID' => 1, - )); + ]); $message .= json_encode($log_params); $log = new CRM_Utils_SystemLogger(); $log->debug($message, $_REQUEST); diff --git a/tests/phpunit/api/v3/ContributionRecurTest.php b/tests/phpunit/api/v3/ContributionRecurTest.php index 7903e0f40d..a02deb03ce 100644 --- a/tests/phpunit/api/v3/ContributionRecurTest.php +++ b/tests/phpunit/api/v3/ContributionRecurTest.php @@ -35,7 +35,7 @@ class api_v3_ContributionRecurTest extends CiviUnitTestCase { protected $_apiversion = 3; protected $params; - protected $ids = array(); + protected $ids = []; protected $_entity = 'contribution_recur'; public $DBResetRequired = FALSE; @@ -44,7 +44,7 @@ class api_v3_ContributionRecurTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); $this->ids['contact'][0] = $this->individualCreate(); - $this->params = array( + $this->params = [ 'contact_id' => $this->ids['contact'][0], 'installments' => '12', 'frequency_interval' => '1', @@ -53,7 +53,7 @@ class api_v3_ContributionRecurTest extends CiviUnitTestCase { 'start_date' => '2012-01-01 00:00:00', 'currency' => 'USD', 'frequency_unit' => 'day', - ); + ]; } public function testCreateContributionRecur() { @@ -65,9 +65,9 @@ class api_v3_ContributionRecurTest extends CiviUnitTestCase { public function testGetContributionRecur() { $this->callAPISuccess($this->_entity, 'create', $this->params); - $getParams = array( + $getParams = [ 'amount' => '500', - ); + ]; $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); } @@ -75,11 +75,11 @@ class api_v3_ContributionRecurTest extends CiviUnitTestCase { public function testCreateContributionRecurWithToken() { // create token $this->createLoggedInUser(); - $token = $this->callAPISuccess('PaymentToken', 'create', array( + $token = $this->callAPISuccess('PaymentToken', 'create', [ 'payment_processor_id' => $this->processorCreate(), 'token' => 'hhh', 'contact_id' => $this->individualCreate(), - )); + ]); $params['payment_token_id'] = $token['id']; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); $this->assertEquals(1, $result['count']); @@ -89,14 +89,14 @@ class api_v3_ContributionRecurTest extends CiviUnitTestCase { public function testDeleteContributionRecur() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); + $deleteParams = ['id' => $result['id']]; $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } public function testGetFieldsContributionRecur() { - $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertEquals(12, $result['values']['start_date']['type']); } diff --git a/tests/phpunit/api/v3/ContributionSoftTest.php b/tests/phpunit/api/v3/ContributionSoftTest.php index fe23a97172..7cea538720 100644 --- a/tests/phpunit/api/v3/ContributionSoftTest.php +++ b/tests/phpunit/api/v3/ContributionSoftTest.php @@ -68,10 +68,10 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { $this->_individualId = $this->individualCreate(); $this->_softIndividual1Id = $this->individualCreate(); $this->_softIndividual2Id = $this->individualCreate(); - $this->_contributionId = $this->contributionCreate(array('contact_id' => $this->_individualId)); + $this->_contributionId = $this->contributionCreate(['contact_id' => $this->_individualId]); $this->processorCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -81,8 +81,8 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { 'net_amount' => 95.00, 'source' => 'SSF', 'contribution_status_id' => 1, - ); - $this->_processorParams = array( + ]; + $this->_processorParams = [ 'domain_id' => 1, 'name' => 'Dummy', 'payment_processor_type_id' => 10, @@ -92,7 +92,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { 'url_site' => 'http://dummy.com', 'url_recur' => 'http://dummy.com', 'billing_mode' => 1, - ); + ]; } /** @@ -102,18 +102,18 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { */ public function testGetContributionSoft() { //We don't test for PCP fields because there's no PCP API, so we can't create campaigns. - $p = array( + $p = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', 'soft_credit_type_id' => 4, - ); + ]; $this->_softcontribution = $this->callAPISuccess('contribution_soft', 'create', $p); - $params = array( + $params = [ 'id' => $this->_softcontribution['id'], - ); + ]; $softcontribution = $this->callAPIAndDocument('contribution_soft', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals(1, $softcontribution['count']); $this->assertEquals($softcontribution['values'][$this->_softcontribution['id']]['contribution_id'], $this->_contributionId); @@ -127,67 +127,67 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { $this->_softcontribution2 = $this->callAPISuccess('contribution_soft', 'create', $p); // now we have 2 - test getcount - $softcontribution = $this->callAPISuccess('contribution_soft', 'getcount', array()); + $softcontribution = $this->callAPISuccess('contribution_soft', 'getcount', []); $this->assertEquals(2, $softcontribution); //check first contribution - $result = $this->callAPISuccess('contribution_soft', 'get', array( + $result = $this->callAPISuccess('contribution_soft', 'get', [ 'id' => $this->_softcontribution['id'], - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals($this->_softcontribution['id'], $result['id']); $this->assertEquals($this->_softcontribution['id'], $result['id'], print_r($softcontribution, TRUE)); //test id only format - second soft credit - $resultID2 = $this->callAPISuccess('contribution_soft', 'get', array( + $resultID2 = $this->callAPISuccess('contribution_soft', 'get', [ 'id' => $this->_softcontribution2['id'], 'format.only_id' => 1, - )); + ]); $this->assertEquals($this->_softcontribution2['id'], $resultID2); //test get by contact id works - $result = $this->callAPISuccess('contribution_soft', 'get', array( + $result = $this->callAPISuccess('contribution_soft', 'get', [ 'contact_id' => $this->_softIndividual2Id, - )); + ]); $this->assertEquals(1, $result['count']); - $this->callAPISuccess('contribution_soft', 'Delete', array( + $this->callAPISuccess('contribution_soft', 'Delete', [ 'id' => $this->_softcontribution['id'], - )); + ]); // check one soft credit remains $expectedCount = 1; - $this->callAPISuccess('contribution_soft', 'getcount', array(), $expectedCount); + $this->callAPISuccess('contribution_soft', 'getcount', [], $expectedCount); //check id is same as 2 - $this->assertEquals($this->_softcontribution2['id'], $this->callAPISuccess('contribution_soft', 'getvalue', array('return' => 'id'))); + $this->assertEquals($this->_softcontribution2['id'], $this->callAPISuccess('contribution_soft', 'getvalue', ['return' => 'id'])); - $this->callAPISuccess('ContributionSoft', 'Delete', array( + $this->callAPISuccess('ContributionSoft', 'Delete', [ 'id' => $this->_softcontribution2['id'], - )); + ]); } /** * civicrm_contribution_soft. */ public function testCreateEmptyParamsContributionSoft() { - $softcontribution = $this->callAPIFailure('contribution_soft', 'create', array(), + $softcontribution = $this->callAPIFailure('contribution_soft', 'create', [], 'Mandatory key(s) missing from params array: contribution_id, amount, contact_id' ); } public function testCreateParamsWithoutRequiredKeysContributionSoft() { - $softcontribution = $this->callAPIFailure('contribution_soft', 'create', array(), + $softcontribution = $this->callAPIFailure('contribution_soft', 'create', [], 'Mandatory key(s) missing from params array: contribution_id, amount, contact_id' ); } public function testCreateContributionSoftInvalidContact() { - $params = array( + $params = [ 'contact_id' => 999, 'contribution_id' => $this->_contributionId, 'amount' => 10.00, 'currency' => 'USD', - ); + ]; $softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params, 'contact_id is not valid : 999' @@ -195,12 +195,12 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { } public function testCreateContributionSoftInvalidContributionId() { - $params = array( + $params = [ 'contribution_id' => 999999, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', - ); + ]; $softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params, 'contribution_id is not valid : 999999' @@ -211,13 +211,13 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { * Function tests that additional financial records are created when fee amount is recorded. */ public function testCreateContributionSoft() { - $params = array( + $params = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', 'soft_credit_type_id' => 5, - ); + ]; $softcontribution = $this->callAPIAndDocument('contribution_soft', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($softcontribution['values'][$softcontribution['id']]['contribution_id'], $this->_contributionId); @@ -233,20 +233,20 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { */ public function testCreateUpdateContributionSoft() { //create a soft credit - $params = array( + $params = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', 'soft_credit_type_id' => 6, - ); + ]; $softcontribution = $this->callAPISuccess('contribution_soft', 'create', $params); $softcontributionID = $softcontribution['id']; - $old_params = array( + $old_params = [ 'contribution_soft_id' => $softcontributionID, - ); + ]; $original = $this->callAPISuccess('contribution_soft', 'get', $old_params); //Make sure it came back $this->assertEquals($original['id'], $softcontributionID); @@ -263,20 +263,20 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { $this->assertEquals($old_amount, 10.00); $this->assertEquals($old_currency, 'USD'); $this->assertEquals($old_soft_credit_type_id, 6); - $params = array( + $params = [ 'id' => $softcontributionID, 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 7.00, 'currency' => 'CAD', 'soft_credit_type_id' => 7, - ); + ]; $softcontribution = $this->callAPISuccess('contribution_soft', 'create', $params); - $new_params = array( + $new_params = [ 'id' => $softcontribution['id'], - ); + ]; $softcontribution = $this->callAPISuccess('contribution_soft', 'get', $new_params); //check against original values $this->assertEquals($softcontribution['values'][$softcontributionID]['contribution_id'], $this->_contributionId); @@ -285,9 +285,9 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { $this->assertEquals($softcontribution['values'][$softcontributionID]['currency'], 'CAD'); $this->assertEquals($softcontribution['values'][$softcontributionID]['soft_credit_type_id'], 7); - $params = array( + $params = [ 'id' => $softcontributionID, - ); + ]; $this->callAPISuccess('contribution_soft', 'delete', $params); } @@ -296,31 +296,31 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { * */ public function testDeleteEmptyParamsContributionSoft() { - $params = array(); + $params = []; $softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params); } public function testDeleteWrongParamContributionSoft() { - $params = array( + $params = [ 'contribution_source' => 'SSF', - ); + ]; $this->callAPIFailure('contribution_soft', 'delete', $params); } public function testDeleteContributionSoft() { //create a soft credit - $params = array( + $params = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', - ); + ]; $softcontribution = $this->callAPISuccess('contribution_soft', 'create', $params); $softcontributionID = $softcontribution['id']; - $params = array( + $params = [ 'id' => $softcontributionID, - ); + ]; $this->callAPIAndDocument('contribution_soft', 'delete', $params, __FUNCTION__, __FILE__); } @@ -331,15 +331,15 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { * All available contributions expected. */ public function testSearchEmptyParams() { - $p = array( + $p = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', - ); + ]; $softcontribution = $this->callAPISuccess('contribution_soft', 'create', $p); - $result = $this->callAPISuccess('contribution_soft', 'get', array()); + $result = $this->callAPISuccess('contribution_soft', 'get', []); // We're taking the first element. $res = $result['values'][$softcontribution['id']]; @@ -353,25 +353,25 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { * Test civicrm_contribution_soft_search. Success expected. */ public function testSearch() { - $p1 = array( + $p1 = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual1Id, 'amount' => 10.00, 'currency' => 'USD', - ); + ]; $softcontribution1 = $this->callAPISuccess('contribution_soft', 'create', $p1); - $p2 = array( + $p2 = [ 'contribution_id' => $this->_contributionId, 'contact_id' => $this->_softIndividual2Id, 'amount' => 25.00, 'currency' => 'CAD', - ); + ]; $softcontribution2 = $this->callAPISuccess('contribution_soft', 'create', $p2); - $params = array( + $params = [ 'id' => $softcontribution2['id'], - ); + ]; $result = $this->callAPISuccess('contribution_soft', 'get', $params); $res = $result['values'][$softcontribution2['id']]; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 19ef5bfdf8..37d375f71b 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -41,8 +41,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { protected $_entity = 'Contribution'; public $debug = 0; protected $_params; - protected $_ids = array(); - protected $_pageParams = array(); + protected $_ids = []; + protected $_pageParams = []; /** * Payment processor ID (dummy processor). * @@ -55,7 +55,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * @var array */ - protected $_processorParams = array(); + protected $_processorParams = []; /** * ID of created event. @@ -77,7 +77,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->_apiversion = 3; $this->_individualId = $this->individualCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -87,8 +87,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'net_amount' => 95.00, 'source' => 'SSF', 'contribution_status_id' => 1, - ); - $this->_processorParams = array( + ]; + $this->_processorParams = [ 'domain_id' => 1, 'name' => 'Dummy', 'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'), @@ -98,9 +98,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'url_site' => 'http://dummy.com', 'url_recur' => 'http://dummy.com', 'billing_mode' => 1, - ); + ]; $this->paymentProcessorID = $this->processorCreate(); - $this->_pageParams = array( + $this->_pageParams = [ 'title' => 'Test Contribution Page', 'financial_type_id' => 1, 'currency' => 'USD', @@ -110,7 +110,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'is_allow_other_amount' => 1, 'min_amount' => 10, 'max_amount' => 1000, - ); + ]; } /** @@ -118,17 +118,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_uf_match')); - $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', array()); + $this->quickCleanup(['civicrm_uf_match']); + $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', []); foreach ($financialAccounts['values'] as $financialAccount) { if ($financialAccount['name'] == 'Test Tax financial account ' || $financialAccount['name'] == 'Test taxable financial Type') { - $entityFinancialTypes = $this->callAPISuccess('EntityFinancialAccount', 'get', array( + $entityFinancialTypes = $this->callAPISuccess('EntityFinancialAccount', 'get', [ 'financial_account_id' => $financialAccount['id'], - )); + ]); foreach ($entityFinancialTypes['values'] as $entityFinancialType) { - $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialType['id'])); + $this->callAPISuccess('EntityFinancialAccount', 'delete', ['id' => $entityFinancialType['id']]); } - $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id'])); + $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]); } } } @@ -139,7 +139,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testGetContribution() { $contributionSettings = $this->enableTaxAndInvoicing(); $invoice_prefix = CRM_Contribute_BAO_Contribution::checkContributeSettings('invoice_prefix', TRUE); - $p = array( + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', 'total_amount' => 100.00, @@ -151,12 +151,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 78910, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $this->_contribution = $this->callAPISuccess('contribution', 'create', $p); - $params = array( + $params = [ 'contribution_id' => $this->_contribution['id'], - ); + ]; $contributions = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__, __FILE__); $financialParams['id'] = $this->_financialTypeId; @@ -186,44 +186,44 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution2 = $this->callAPISuccess('contribution', 'create', $p); // Now we have 2 - test getcount. - $contribution = $this->callAPISuccess('contribution', 'getcount', array()); + $contribution = $this->callAPISuccess('contribution', 'getcount', []); $this->assertEquals(2, $contribution); // Test id only format. - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'id' => $this->_contribution['id'], 'format.only_id' => 1, - )); + ]); $this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE)); // Test id only format. - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'id' => $contribution2['id'], 'format.only_id' => 1, - )); + ]); $this->assertEquals($contribution2['id'], $contribution); // Test id as field. - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'id' => $this->_contribution['id'], - )); + ]); $this->assertEquals(1, $contribution['count']); // Test get by contact id works. - $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId)); + $contribution = $this->callAPISuccess('contribution', 'get', ['contact_id' => $this->_individualId]); $this->assertEquals(2, $contribution['count']); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $this->_contribution['id'], - )); - $this->callAPISuccess('Contribution', 'Delete', array( + ]); + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution2['id'], - )); + ]); } /** * Test that test contributions can be retrieved. */ public function testGetTestContribution() { - $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('is_test' => 1))); - $this->callAPISuccessGetSingle('Contribution', array('is_test' => 1)); + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['is_test' => 1])); + $this->callAPISuccessGetSingle('Contribution', ['is_test' => 1]); } /** @@ -241,19 +241,19 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $params['cancel_reason'] = 'You lose sucker'; $params['creditnote_id'] = 'sudo rm -rf'; $params['tax_amount'] = '1'; - $address = $this->callAPISuccess('Address', 'create', array( + $address = $this->callAPISuccess('Address', 'create', [ 'street_address' => 'Knockturn Alley', 'contact_id' => $this->_individualId, 'location_type_id' => 'Home', - )); + ]); $params['address_id'] = $address['id']; $contributionPage = $this->contributionPageCreate(); $params['contribution_page_id'] = $contributionPage['id']; - $contributionRecur = $this->callAPISuccess('ContributionRecur', 'create', array( + $contributionRecur = $this->callAPISuccess('ContributionRecur', 'create', [ 'contact_id' => $this->_individualId, 'frequency_interval' => 1, 'amount' => 5, - )); + ]); $params['contribution_recur_id'] = $contributionRecur['id']; $params['campaign_id'] = $this->campaignCreate(); @@ -261,15 +261,15 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contributionID = $this->contributionCreate($params); // update contribution with invoice number - $params = array_merge($params, array( + $params = array_merge($params, [ 'id' => $contributionID, 'invoice_number' => CRM_Utils_Array::value('invoice_prefix', Civi::settings()->get('contribution_invoice_settings')) . "" . $contributionID, 'trxn_id' => 12345, 'invoice_id' => 6789, - )); + ]); $contributionID = $this->contributionCreate($params); - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contributionID)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID]); $this->assertEquals('bouncer', $contribution['check_number']); $this->assertEquals('bouncer', $contribution['contribution_check_number']); @@ -279,20 +279,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $fields['address_id'] = $fields['contribution_address_id']; $fields['check_number'] = $fields['contribution_check_number']; - $fieldsLockedIn = array( + $fieldsLockedIn = [ 'contribution_id', 'contribution_contact_id', 'financial_type_id', 'contribution_page_id', 'payment_instrument_id', 'receive_date', 'non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount', 'trxn_id', 'invoice_id', 'currency', 'contribution_cancel_date', 'cancel_reason', 'receipt_date', 'thankyou_date', 'contribution_source', 'amount_level', 'contribution_recur_id', 'is_test', 'is_pay_later', 'contribution_status_id', 'address_id', 'check_number', 'contribution_campaign_id', 'creditnote_id', 'tax_amount', 'revenue_recognition_date', 'decoy', - ); + ]; $missingFields = array_diff($fieldsLockedIn, array_keys($fields)); // If any of the locked in fields disappear from the $fields array we need to make sure it is still // covered as the test contract now guarantees them in the return array. - $this->assertEquals($missingFields, array(29 => 'decoy'), 'A field which was covered by the test contract has changed.'); + $this->assertEquals($missingFields, [29 => 'decoy'], 'A field which was covered by the test contract has changed.'); foreach ($fields as $fieldName => $fieldSpec) { - $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contributionID, 'return' => $fieldName)); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID, 'return' => $fieldName]); $returnField = $fieldName; if ($returnField == 'contribution_contact_id') { $returnField = 'contact_id'; @@ -320,7 +320,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * We need to ensure previous tested behaviour still works as part of the api contract. */ public function testGetContributionLegacyBehaviour() { - $p = array( + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', 'total_amount' => 100.00, @@ -332,12 +332,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 78910, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $this->_contribution = $this->callAPISuccess('Contribution', 'create', $p); - $params = array( + $params = [ 'contribution_id' => $this->_contribution['id'], - ); + ]; $contribution = $this->callAPISuccess('contribution', 'get', $params); $financialParams['id'] = $this->_financialTypeId; $default = NULL; @@ -363,49 +363,49 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution2 = $this->callAPISuccess('contribution', 'create', $p); // now we have 2 - test getcount - $contribution = $this->callAPISuccess('contribution', 'getcount', array()); + $contribution = $this->callAPISuccess('contribution', 'getcount', []); $this->assertEquals(2, $contribution); //test id only format - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'id' => $this->_contribution['id'], 'format.only_id' => 1, - )); + ]); $this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE)); //test id only format - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'id' => $contribution2['id'], 'format.only_id' => 1, - )); + ]); $this->assertEquals($contribution2['id'], $contribution); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'id' => $this->_contribution['id'], - )); + ]); //test id as field $this->assertEquals(1, $contribution['count']); // $this->assertEquals($this->_contribution['id'], $contribution['id'] ) ; //test get by contact id works - $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId)); + $contribution = $this->callAPISuccess('contribution', 'get', ['contact_id' => $this->_individualId]); $this->assertEquals(2, $contribution['count']); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $this->_contribution['id'], - )); - $this->callAPISuccess('Contribution', 'Delete', array( + ]); + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution2['id'], - )); + ]); } /** * Create an contribution_id=FALSE and financial_type_id=Donation. */ public function testCreateEmptyContributionIDUseDonation() { - $params = array( + $params = [ 'contribution_id' => FALSE, 'contact_id' => 1, 'total_amount' => 1, 'check_permissions' => FALSE, 'financial_type_id' => 'Donation', - ); + ]; $this->callAPISuccess('contribution', 'create', $params); } @@ -424,10 +424,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); - $check = $this->callAPISuccess($this->_entity, 'get', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - )); + ]); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); @@ -443,7 +443,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateGetFieldsWithCustom() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTest.php'); - $result = $this->callAPISuccess('Contribution', 'getfields', array()); + $result = $this->callAPISuccess('Contribution', 'getfields', []); $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']); $this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']); $this->customFieldDelete($ids['custom_field_id']); @@ -454,7 +454,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionNoLineItems() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -468,14 +468,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipLineItem' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $lineItems = $this->callAPISuccess('line_item', 'get', array( + $lineItems = $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + ]); $this->assertEquals(0, $lineItems['count']); } @@ -483,7 +483,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test checks that passing in line items suppresses the create mechanism. */ public function testCreateContributionChainedLineItems() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -497,37 +497,37 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipLineItem' => 1, - 'api.line_item.create' => array( - array( + 'api.line_item.create' => [ + [ 'price_field_id' => 1, 'qty' => 2, 'line_total' => '20', 'unit_price' => '10', - ), - array( + ], + [ 'price_field_id' => 1, 'qty' => 1, 'line_total' => '80', 'unit_price' => '80', - ), - ), - ); + ], + ], + ]; $description = "Create Contribution with Nested Line Items."; $subfile = "CreateWithNestedLineItems"; $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $lineItems = $this->callAPISuccess('line_item', 'get', array( + $lineItems = $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'contribution_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + ]); $this->assertEquals(2, $lineItems['count']); } public function testCreateContributionOffline() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -536,7 +536,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); @@ -546,12 +546,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); - $lineItems = $this->callAPISuccess('line_item', 'get', array( + $lineItems = $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'contribution_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + ]); $this->assertEquals(1, $lineItems['count']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']); @@ -563,62 +563,62 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test create with valid payment instrument. */ public function testCreateContributionWithPaymentInstrument() { - $params = $this->_params + array('payment_instrument' => 'EFT'); + $params = $this->_params + ['payment_instrument' => 'EFT']; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'sequential' => 1, 'id' => $contribution['id'], - )); + ]); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); - $this->callAPISuccess('contribution', 'create', array( + $this->callAPISuccess('contribution', 'create', [ 'id' => $contribution['id'], 'payment_instrument' => 'Credit Card', - )); - $contribution = $this->callAPISuccess('contribution', 'get', array( + ]); + $contribution = $this->callAPISuccess('contribution', 'get', [ 'sequential' => 1, 'id' => $contribution['id'], - )); + ]); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']); } public function testGetContributionByPaymentInstrument() { - $params = $this->_params + array('payment_instrument' => 'EFT'); - $params2 = $this->_params + array('payment_instrument' => 'Cash'); + $params = $this->_params + ['payment_instrument' => 'EFT']; + $params2 = $this->_params + ['payment_instrument' => 'Cash']; $this->callAPISuccess('contribution', 'create', $params); $this->callAPISuccess('contribution', 'create', $params2); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'sequential' => 1, 'contribution_payment_instrument' => 'Cash', - )); + ]); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'payment_instrument' => 'Cash')); + $contribution = $this->callAPISuccess('contribution', 'get', ['sequential' => 1, 'payment_instrument' => 'Cash']); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'sequential' => 1, 'payment_instrument_id' => 5, - )); + ]); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'get', array( + $contribution = $this->callAPISuccess('contribution', 'get', [ 'sequential' => 1, 'payment_instrument' => 'EFT', - )); + ]); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'create', array( + $contribution = $this->callAPISuccess('contribution', 'create', [ 'id' => $contribution['id'], 'payment_instrument' => 'Credit Card', - )); - $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id'])); + ]); + $contribution = $this->callAPISuccess('contribution', 'get', ['sequential' => 1, 'id' => $contribution['id']]); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); @@ -628,10 +628,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * CRM-16227 introduces invoice_id as a parameter. */ public function testGetContributionByInvoice() { - $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('invoice_id' => 'curly'))); - $this->callAPISuccess('Contribution', 'create', array_merge($this->_params), array('invoice_id' => 'churlish')); - $this->callAPISuccessGetCount('Contribution', array(), 2); - $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => 'curly')); + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['invoice_id' => 'curly'])); + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params), ['invoice_id' => 'churlish']); + $this->callAPISuccessGetCount('Contribution', [], 2); + $this->callAPISuccessGetSingle('Contribution', ['invoice_id' => 'curly']); // The following don't work. They are the format we are trying to introduce but although the form uses this format // CRM_Contact_BAO_Query::convertFormValues puts them into the other format & the where only supports that. // ideally the where clause would support this format (as it does on contact_BAO_Query) and those lines would @@ -647,9 +647,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Check the credit note retrieval is case insensitive. */ public function testGetCreditNoteCaseInsensitive() { - $this->contributionCreate(array('contact_id' => $this->_individualId)); - $this->contributionCreate(array('creditnote_id' => 'cN1234', 'contact_id' => $this->_individualId, 'invoice_id' => rand(), 'trxn_id' => rand())); - $contribution = $this->callAPISuccess('Contribution', 'getsingle', array('creditnote_id' => 'CN1234')); + $this->contributionCreate(['contact_id' => $this->_individualId]); + $this->contributionCreate(['creditnote_id' => 'cN1234', 'contact_id' => $this->_individualId, 'invoice_id' => rand(), 'trxn_id' => rand()]); + $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['creditnote_id' => 'CN1234']); $this->assertEquals($contribution['creditnote_id'], 'cN1234'); } @@ -659,14 +659,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * @throws Exception */ public function testGetContributionByTotalAmount() { - $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '5'))); - $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '10'))); - $this->callAPISuccessGetCount('Contribution', array('total_amount' => 10), 1); - $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 6)), 1); - $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 0)), 2); - $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => -5)), 2); - $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('<' => 0)), 0); - $this->callAPISuccessGetCount('Contribution', array(), 2); + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['total_amount' => '5'])); + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['total_amount' => '10'])); + $this->callAPISuccessGetCount('Contribution', ['total_amount' => 10], 1); + $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['>' => 6]], 1); + $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['>' => 0]], 2); + $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['>' => -5]], 2); + $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['<' => 0]], 0); + $this->callAPISuccessGetCount('Contribution', [], 2); } /** @@ -674,7 +674,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateContributionSource() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => date('Ymd'), 'total_amount' => 100.00, @@ -687,7 +687,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'contribution_source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); @@ -712,7 +712,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $params['skipCleanMoney'] = FALSE; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id'])); + $contribution = $this->callAPISuccessGetSingle('contribution', ['id' => $contribution['id']]); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date']))); $this->assertEquals(5000.77, $contribution['total_amount'], 'failed to handle ' . $this->formatMoneyInput(5000.77)); $this->assertEquals(.77, $contribution['fee_amount']); @@ -728,7 +728,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $params['thankyou_date'] = 'yesterday'; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id'])); + $contribution = $this->callAPISuccessGetSingle('contribution', ['id' => $contribution['id']]); $this->assertEquals(date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime($contribution['thankyou_date']))); $params['thankyou_date'] = 'null'; @@ -741,7 +741,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateContributionSourceInvalidContact() { - $params = array( + $params = [ 'contact_id' => 999, 'receive_date' => date('Ymd'), 'total_amount' => 100.00, @@ -754,14 +754,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'contribution_source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999'); } public function testCreateContributionSourceInvalidContContact() { - $params = array( + $params = [ 'contribution_contact_id' => 999, 'receive_date' => date('Ymd'), 'total_amount' => 100.00, @@ -774,7 +774,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'contribution_source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $this->callAPIFailure('contribution', 'create', $params); } @@ -785,7 +785,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionWithNote() { $description = "Demonstrates creating contribution with Note Entity."; $subfile = "ContributionCreateWithNote"; - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -799,20 +799,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'note' => 'my contribution note', - ); + ]; $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPISuccess('note', 'get', array( + $result = $this->callAPISuccess('note', 'get', [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], 'sequential' => 1, - )); + ]); $this->assertEquals('my contribution note', $result['values'][0]['note']); - $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); + $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]); } public function testCreateContributionWithNoteUniqueNameAliases() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -826,16 +826,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'contribution_note' => 'my contribution note', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $result = $this->callAPISuccess('note', 'get', array( + $result = $this->callAPISuccess('note', 'get', [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], 'sequential' => 1, - )); + ]); $this->assertEquals('my contribution note', $result['values'][0]['note']); - $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); + $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]); } /** @@ -844,48 +844,48 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionWithSoftCredit() { $description = "Demonstrates creating contribution with SoftCredit."; $subfile = "ContributionCreateWithSoftCredit"; - $contact2 = $this->callAPISuccess('Contact', 'create', array( + $contact2 = $this->callAPISuccess('Contact', 'create', [ 'display_name' => 'superman', 'contact_type' => 'Individual', - )); - $softParams = array( + ]); + $softParams = [ 'contact_id' => $contact2['id'], 'amount' => 50, 'soft_credit_type_id' => 3, - ); + ]; - $params = $this->_params + array('soft_credit' => array(1 => $softParams)); + $params = $this->_params + ['soft_credit' => [1 => $softParams]]; $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); + $result = $this->callAPISuccess('contribution', 'get', ['return' => 'soft_credit', 'sequential' => 1]); $this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']); $this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']); $this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']); - $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); - $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); + $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]); + $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]); } public function testCreateContributionWithSoftCreditDefaults() { $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type."; $subfile = "ContributionCreateWithSoftCreditDefaults"; - $contact2 = $this->callAPISuccess('Contact', 'create', array( + $contact2 = $this->callAPISuccess('Contact', 'create', [ 'display_name' => 'superman', 'contact_type' => 'Individual', - )); - $params = $this->_params + array( + ]); + $params = $this->_params + [ 'soft_credit_to' => $contact2['id'], - ); + ]; $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); + $result = $this->callAPISuccess('contribution', 'get', ['return' => 'soft_credit', 'sequential' => 1]); $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']); // Default soft credit amount = contribution.total_amount $this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']); $this->assertEquals(CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), $result['values'][0]['soft_credit'][1]['soft_credit_type']); - $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); - $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); + $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]); + $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]); } /** @@ -894,15 +894,15 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionWithHonoreeContact() { $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id."; $subfile = "ContributionCreateWithHonoreeContact"; - $contact2 = $this->callAPISuccess('Contact', 'create', array( + $contact2 = $this->callAPISuccess('Contact', 'create', [ 'display_name' => 'superman', 'contact_type' => 'Individual', - )); - $params = $this->_params + array( + ]); + $params = $this->_params + [ 'honor_contact_id' => $contact2['id'], - ); + ]; $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); + $result = $this->callAPISuccess('contribution', 'get', ['return' => 'soft_credit', 'sequential' => 1]); $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']); // Default soft credit amount = contribution.total_amount @@ -911,8 +911,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $softCreditValueTypeID = $result['values'][0]['soft_credit'][1]['soft_credit_type']; $this->assertEquals('in_honor_of', CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $softCreditValueTypeID)); - $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); - $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); + $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]); + $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]); } /** @@ -933,7 +933,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Function tests that additional financial records are created when fee amount is recorded. */ public function testCreateContributionWithFee() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -943,7 +943,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); @@ -956,22 +956,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); - $lineItems = $this->callAPISuccess('line_item', 'get', array( + $lineItems = $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + ]); $this->assertEquals(1, $lineItems['count']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']); - $lineItems = $this->callAPISuccess('line_item', 'get', array( + $lineItems = $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'contribution_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + ]); $this->assertEquals(1, $lineItems['count']); $this->_checkFinancialRecords($contribution, 'feeAmount'); } @@ -983,7 +983,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($contributionPage); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -995,7 +995,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); @@ -1005,10 +1005,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); - $contribution['payment_instrument_id'] = $this->callAPISuccessGetValue('PaymentProcessor', array( + $contribution['payment_instrument_id'] = $this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $this->paymentProcessorID, 'return' => 'payment_instrument_id', - )); + ]); $this->_checkFinancialRecords($contribution, 'online'); } @@ -1046,7 +1046,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->_pageParams['is_pay_later'] = 1; $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($contributionPage); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -1058,7 +1058,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); @@ -1078,7 +1078,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($contributionPage); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -1088,7 +1088,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); @@ -1107,10 +1107,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateBAODefaults() { unset($this->_params['contribution_source_id'], $this->_params['payment_instrument_id']); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'id' => $contribution['id'], 'api.contribution.delete' => 1, - )); + ]); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('Check', $contribution['payment_instrument']); $this->callAPISuccessGetCount('Contribution', ['id' => $contribution['id']], 0); @@ -1121,10 +1121,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testDeleteChainedGetSingle() { $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'id' => $contribution['id'], 'api.contribution.delete' => 1, - )); + ]); $this->callAPISuccessGetCount('Contribution', ['id' => $contribution['id']], 0); } @@ -1133,31 +1133,31 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateUpdateContributionChangeTotal() { $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( + $lineItems = $this->callAPISuccess('line_item', 'getvalue', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, 'return' => 'line_total', - )); + ]); $this->assertEquals('100.00', $lineItems); $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); // Financial trxn SUM = 100 + 5 (fee) $this->assertEquals('105.00', $trxnAmount); - $newParams = array( + $newParams = [ 'id' => $contribution['id'], 'total_amount' => '125', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $newParams); - $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( + $lineItems = $this->callAPISuccess('line_item', 'getvalue', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, 'return' => 'line_total', - )); + ]); $this->assertEquals('125.00', $lineItems); $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); @@ -1171,7 +1171,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Function tests that line items, financial records are updated when pay later contribution is received. */ public function testCreateUpdateContributionPayLater() { - $contribParams = array( + $contribParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1180,13 +1180,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_status_id' => 2, 'is_pay_later' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); - $newParams = array_merge($contribParams, array( + $newParams = array_merge($contribParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 1, - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $contribution = $contribution['values'][$contribution['id']]; $this->assertEquals($contribution['contribution_status_id'], '1'); @@ -1199,20 +1199,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateUpdateContributionPaymentInstrument() { $instrumentId = $this->_addPaymentInstrument(); - $contribParams = array( + $contribParams = [ 'contact_id' => $this->_individualId, 'total_amount' => 100.00, 'financial_type_id' => $this->_financialTypeId, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); - $newParams = array_merge($contribParams, array( + $newParams = array_merge($contribParams, [ 'id' => $contribution['id'], 'payment_instrument_id' => $instrumentId, - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->assertAPISuccess($contribution); $this->checkFinancialTrxnPaymentInstrumentChange($contribution['id'], 4, $instrumentId); @@ -1226,20 +1226,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateUpdateNegativeContributionPaymentInstrument() { $instrumentId = $this->_addPaymentInstrument(); - $contribParams = array( + $contribParams = [ 'contact_id' => $this->_individualId, 'total_amount' => -100.00, 'financial_type_id' => $this->_financialTypeId, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); - $newParams = array_merge($contribParams, array( + $newParams = array_merge($contribParams, [ 'id' => $contribution['id'], 'payment_instrument_id' => $instrumentId, - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->assertAPISuccess($contribution); $this->checkFinancialTrxnPaymentInstrumentChange($contribution['id'], 4, $instrumentId, -100); @@ -1252,7 +1252,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Function tests that financial records are added when Contribution is Refunded. */ public function testCreateUpdateContributionRefund() { - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1260,22 +1260,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'trxn_id' => 'original_payment', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); - $newParams = array_merge($contributionParams, array( + $newParams = array_merge($contributionParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 'Refunded', 'cancel_date' => '2015-01-01 09:00', 'refund_trxn_id' => 'the refund', - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->_checkFinancialTrxn($contribution, 'refund'); $this->_checkFinancialItem($contribution['id'], 'refund'); - $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', array( + $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', [ 'id' => $contribution['id'], 'return' => 'trxn_id', - ))); + ])); } /** @@ -1287,22 +1287,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateUpdateChargebackContributionDefaultAccount() { $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'id' => $contribution['id'], 'contribution_status_id' => 'Chargeback', - )); - $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback')); + ]); + $this->callAPISuccessGetSingle('Contribution', ['contribution_status_id' => 'Chargeback']); - $lineItems = $this->callAPISuccessGetSingle('LineItem', array( + $lineItems = $this->callAPISuccessGetSingle('LineItem', [ 'contribution_id' => $contribution['id'], - 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)), - )); + 'api.FinancialItem.getsingle' => ['amount' => ['<' => 0]], + ]); $this->assertEquals(1, $lineItems['api.FinancialItem.getsingle']['financial_account_id']); - $this->callAPISuccessGetSingle('FinancialTrxn', array( + $this->callAPISuccessGetSingle('FinancialTrxn', [ 'total_amount' => -100, 'status_id' => 'Chargeback', 'to_financial_account_id' => 6, - )); + ]); } /** @@ -1313,34 +1313,34 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * in the financial_trxn & financial_item table if it is. */ public function testCreateUpdateChargebackContributionCustomAccount() { - $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array( + $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', [ 'name' => 'Chargeback Account', 'is_active' => TRUE, - )); + ]); - $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array( + $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', [ 'entity_id' => $this->_financialTypeId, 'entity_table' => 'civicrm_financial_type', 'account_relationship' => 'Chargeback Account is', 'financial_account_id' => 'Chargeback Account', - )); + ]); $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'id' => $contribution['id'], 'contribution_status_id' => 'Chargeback', - )); - $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback')); + ]); + $this->callAPISuccessGetSingle('Contribution', ['contribution_status_id' => 'Chargeback']); - $lineItems = $this->callAPISuccessGetSingle('LineItem', array( + $lineItems = $this->callAPISuccessGetSingle('LineItem', [ 'contribution_id' => $contribution['id'], - 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)), - )); + 'api.FinancialItem.getsingle' => ['amount' => ['<' => 0]], + ]); $this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']); - $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id'])); - $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id'])); - $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id'])); + $this->callAPISuccess('Contribution', 'delete', ['id' => $contribution['id']]); + $this->callAPISuccess('EntityFinancialAccount', 'delete', ['id' => $entityFinancialAccount['id']]); + $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]); } /** @@ -1351,33 +1351,33 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * in the financial_trxn & financial_item table if it is. */ public function testCreateUpdateRefundContributionConfiguredContraAccount() { - $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array( + $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', [ 'name' => 'Refund Account', 'is_active' => TRUE, - )); + ]); - $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array( + $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', [ 'entity_id' => $this->_financialTypeId, 'entity_table' => 'civicrm_financial_type', 'account_relationship' => 'Credit/Contra Revenue Account is', 'financial_account_id' => 'Refund Account', - )); + ]); $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'id' => $contribution['id'], 'contribution_status_id' => 'Refunded', - )); + ]); - $lineItems = $this->callAPISuccessGetSingle('LineItem', array( + $lineItems = $this->callAPISuccessGetSingle('LineItem', [ 'contribution_id' => $contribution['id'], - 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)), - )); + 'api.FinancialItem.getsingle' => ['amount' => ['<' => 0]], + ]); $this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']); - $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id'])); - $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id'])); - $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id'])); + $this->callAPISuccess('Contribution', 'delete', ['id' => $contribution['id']]); + $this->callAPISuccess('EntityFinancialAccount', 'delete', ['id' => $entityFinancialAccount['id']]); + $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]); } /** @@ -1387,7 +1387,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * when trxn_id is passed in. */ public function testCreateUpdateContributionRefundTrxnIDPassedIn() { - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1395,22 +1395,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'trxn_id' => 'original_payment', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); - $newParams = array_merge($contributionParams, array( + $newParams = array_merge($contributionParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 'Refunded', 'cancel_date' => '2015-01-01 09:00', 'trxn_id' => 'the refund', - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->_checkFinancialTrxn($contribution, 'refund'); $this->_checkFinancialItem($contribution['id'], 'refund'); - $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', array( + $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', [ 'id' => $contribution['id'], 'return' => 'trxn_id', - ))); + ])); } /** @@ -1421,7 +1421,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * is kept for the refund transaction. */ public function testCreateUpdateContributionRefundRefundAndTrxnIDPassedIn() { - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1429,23 +1429,23 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'trxn_id' => 'original_payment', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); - $newParams = array_merge($contributionParams, array( + $newParams = array_merge($contributionParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 'Refunded', 'cancel_date' => '2015-01-01 09:00', 'trxn_id' => 'cont id', 'refund_trxn_id' => 'the refund', - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->_checkFinancialTrxn($contribution, 'refund'); $this->_checkFinancialItem($contribution['id'], 'refund'); - $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array( + $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', [ 'id' => $contribution['id'], 'return' => 'trxn_id', - ))); + ])); } /** @@ -1456,7 +1456,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * is kept for the refund transaction. */ public function testCreateUpdateContributionRefundRefundNullTrxnIDPassedIn() { - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1464,42 +1464,42 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'trxn_id' => 'original_payment', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); - $newParams = array_merge($contributionParams, array( + $newParams = array_merge($contributionParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 'Refunded', 'cancel_date' => '2015-01-01 09:00', 'trxn_id' => 'cont id', 'refund_trxn_id' => '', - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); - $this->_checkFinancialTrxn($contribution, 'refund', NULL, array('trxn_id' => NULL)); + $this->_checkFinancialTrxn($contribution, 'refund', NULL, ['trxn_id' => NULL]); $this->_checkFinancialItem($contribution['id'], 'refund'); - $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array( + $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', [ 'id' => $contribution['id'], 'return' => 'trxn_id', - ))); + ])); } /** * Function tests invalid contribution status change. */ public function testCreateUpdateContributionInValidStatusChange() { - $contribParams = array( + $contribParams = [ 'contact_id' => 1, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, 'financial_type_id' => 1, 'payment_instrument_id' => 1, 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); - $newParams = array_merge($contribParams, array( + $newParams = array_merge($contribParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 2, - )); + ]); $this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.')); } @@ -1508,7 +1508,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Function tests that financial records are added when Pending Contribution is Canceled. */ public function testCreateUpdateContributionCancelPending() { - $contribParams = array( + $contribParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1517,17 +1517,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_status_id' => 2, 'is_pay_later' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); - $newParams = array_merge($contribParams, array( + $newParams = array_merge($contribParams, [ 'id' => $contribution['id'], 'contribution_status_id' => 3, 'cancel_date' => '2012-02-02 09:00', - )); + ]); //Check if trxn_date is same as cancel_date. - $checkTrxnDate = array( + $checkTrxnDate = [ 'trxn_date' => '2012-02-02 09:00:00', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->_checkFinancialTrxn($contribution, 'cancelPending', NULL, $checkTrxnDate); $this->_checkFinancialItem($contribution['id'], 'cancelPending'); @@ -1537,7 +1537,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Function tests that financial records are added when Financial Type is Changed. */ public function testCreateUpdateContributionChangeFinancialType() { - $contribParams = array( + $contribParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -1545,12 +1545,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'payment_instrument_id' => 1, 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); - $newParams = array_merge($contribParams, array( + $newParams = array_merge($contribParams, [ 'id' => $contribution['id'], 'financial_type_id' => 3, - )); + ]); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->_checkFinancialTrxn($contribution, 'changeFinancial'); $this->_checkFinancialItem($contribution['id'], 'changeFinancial'); @@ -1560,12 +1560,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test that update does not change status id CRM-15105. */ public function testCreateUpdateWithoutChangingPendingStatus() { - $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array('contribution_status_id' => 2))); - $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source')); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, ['contribution_status_id' => 2])); + $this->callAPISuccess('contribution', 'create', ['id' => $contribution['id'], 'source' => 'new source']); + $contribution = $this->callAPISuccess('contribution', 'getsingle', [ 'id' => $contribution['id'], 'api.contribution.delete' => 1, - )); + ]); $this->assertEquals(2, $contribution['contribution_status_id']); } @@ -1575,15 +1575,15 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * CHANGE: we require the API to do an incremental update */ public function testCreateUpdateContribution() { - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $this->_individualId, 'trxn_id' => 212355, 'financial_type_id' => $this->_financialTypeId, 'invoice_id' => 'old_invoice', - )); - $old_params = array( + ]); + $old_params = [ 'contribution_id' => $contributionID, - ); + ]; $original = $this->callAPISuccess('contribution', 'get', $old_params); $this->assertEquals($original['id'], $contributionID); //set up list of old params, verify @@ -1603,7 +1603,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($old_source, 'SSF'); $this->assertEquals($old_trxn_id, 212355); $this->assertEquals($old_invoice_id, 'old_invoice'); - $params = array( + $params = [ 'id' => $contributionID, 'contact_id' => $this->_individualId, 'total_amount' => 105.00, @@ -1612,13 +1612,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'non_deductible_amount' => 22.00, 'contribution_status_id' => 1, 'note' => 'Donating for Noble Cause', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $new_params = array( + $new_params = [ 'contribution_id' => $contribution['id'], - ); + ]; $contribution = $this->callAPISuccessGetSingle('contribution', $new_params); $this->assertEquals($contribution['contact_id'], $this->_individualId); @@ -1635,9 +1635,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($contribution['net_amount'], $contribution['total_amount'] - $contribution['fee_amount']); - $params = array( + $params = [ 'contribution_id' => $contributionID, - ); + ]; $result = $this->callAPISuccess('contribution', 'delete', $params); $this->assertAPISuccess($result); } @@ -1705,7 +1705,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Attempt (but fail) to delete a contribution without parameters. */ public function testDeleteEmptyParamsContribution() { - $params = array(); + $params = []; $this->callAPIFailure('contribution', 'delete', $params); } @@ -1716,20 +1716,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } public function testDeleteWrongParamContribution() { - $params = array( + $params = [ 'contribution_source' => 'SSF', - ); + ]; $this->callAPIFailure('contribution', 'delete', $params); } public function testDeleteContribution() { - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $this->_individualId, 'financial_type_id' => $this->_financialTypeId, - )); - $params = array( + ]); + $params = [ 'id' => $contributionID, - ); + ]; $this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__, __FILE__); } @@ -1739,9 +1739,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * All available contributions expected. */ public function testSearchEmptyParams() { - $params = array(); + $params = []; - $p = array( + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => date('Ymd'), 'total_amount' => 100.00, @@ -1753,7 +1753,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'invoice_id' => 78910, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $p); $result = $this->callAPISuccess('contribution', 'get', $params); @@ -1779,17 +1779,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test civicrm_contribution_search. Success expected. */ public function testSearch() { - $p1 = array( + $p1 = [ 'contact_id' => $this->_individualId, 'receive_date' => date('Ymd'), 'total_amount' => 100.00, 'financial_type_id' => $this->_financialTypeId, 'non_deductible_amount' => 10.00, 'contribution_status_id' => 1, - ); + ]; $contribution1 = $this->callAPISuccess('contribution', 'create', $p1); - $p2 = array( + $p2 = [ 'contact_id' => $this->_individualId, 'receive_date' => date('Ymd'), 'total_amount' => 200.00, @@ -1800,12 +1800,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'fee_amount' => 50.00, 'net_amount' => 60.00, 'contribution_status_id' => 2, - ); + ]; $contribution2 = $this->callAPISuccess('contribution', 'create', $p2); - $params = array( + $params = [ 'contribution_id' => $contribution2['id'], - ); + ]; $result = $this->callAPISuccess('contribution', 'get', $params); $res = $result['values'][$contribution2['id']]; @@ -1834,16 +1834,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $this->swapMessageTemplateForTestTemplate(); $this->createLoggedInUser(); - $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $params = array_merge($this->_params, ['contribution_status_id' => 2]); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], - )); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'])); + ]); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id']]); $this->assertEquals('SSF', $contribution['contribution_source']); $this->assertEquals('Completed', $contribution['contribution_status']); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date']))); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'email:::anthony_anderson@civicrm.org', 'is_monetary:::1', 'amount:::100.00', @@ -1854,7 +1854,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'title:::Contribution', 'displayName:::Mr. Anthony Anderson II', 'contributionStatus:::Completed', - )); + ]); $mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -1866,24 +1866,24 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $this->swapMessageTemplateForTestTemplate(); $this->createLoggedInUser(); - $params = array_merge($this->_params, array('contribution_status_id' => 2, 'currency' => 'EUR')); + $params = array_merge($this->_params, ['contribution_status_id' => 2, 'currency' => 'EUR']); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], - )); + ]); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'])); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id']]); $this->assertEquals('SSF', $contribution['contribution_source']); $this->assertEquals('Completed', $contribution['contribution_status']); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date']))); $entityFinancialTransactions = $this->getFinancialTransactionsForContribution($contribution['id']); $entityFinancialTransaction = reset($entityFinancialTransactions); - $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', array('id' => $entityFinancialTransaction['financial_trxn_id'])); + $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', ['id' => $entityFinancialTransaction['financial_trxn_id']]); $this->assertEquals('EUR', $financialTrxn['currency']); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'email:::anthony_anderson@civicrm.org', 'is_monetary:::1', 'amount:::100.00', @@ -1894,7 +1894,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'title:::Contribution', 'displayName:::Mr. Anthony Anderson II', 'contributionStatus:::Completed', - )); + ]); $mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -1908,7 +1908,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->createLoggedInUser(); // create contribution page first - $contributionPageParams = array( + $contributionPageParams = [ 'title' => 'Help Support CiviCRM!', 'financial_type_id' => 1, 'is_monetary' => TRUE, @@ -1925,12 +1925,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'amount_block_is_active' => 1, 'currency' => 'USD', 'is_billing_required' => 0, - ); + ]; $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', $contributionPageParams); // submit form values - $priceSet = $this->callAPISuccess('price_set', 'getsingle', array('name' => 'default_contribution_amount')); - $params = array( + $priceSet = $this->callAPISuccess('price_set', 'getsingle', ['name' => 'default_contribution_amount']); + $params = [ 'id' => $contributionPageResult['id'], 'contact_id' => $this->_individualId, 'email-5' => 'anthony_anderson@civicrm.org', @@ -1943,10 +1943,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'is_quick_config' => 1, 'description' => 'Online Contribution: Help Support CiviCRM!', 'price_set_id' => $priceSet['id'], - ); + ]; $this->callAPISuccess('contribution_page', 'submit', $params); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'is_pay_later:::1', 'email:::anthony_anderson@civicrm.org', 'pay_later_receipt:::' . $contributionPageParams['pay_later_receipt'], @@ -1954,7 +1954,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contributionPageId:::' . $contributionPageResult['id'], 'title:::' . $contributionPageParams['title'], 'amount:::' . $params['amount'], - )); + ]); $mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -1968,48 +1968,48 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->createLoggedInUser(); //Scenario 1: When Contact don't have any address - $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $params = array_merge($this->_params, ['contribution_status_id' => 2]); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ 'address:::', - )); + ]); // Scenario 2: Contribution using address - $address = $this->callAPISuccess('address', 'create', array( + $address = $this->callAPISuccess('address', 'create', [ 'street_address' => 'contribution billing st', 'location_type_id' => 2, 'contact_id' => $this->_params['contact_id'], - )); - $params = array_merge($this->_params, array( + ]); + $params = array_merge($this->_params, [ 'contribution_status_id' => 2, 'address_id' => $address['id'], - ) + ] ); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ 'address:::contribution billing st', - )); + ]); // Scenario 3: Contribution wtth no address but contact has a billing address - $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', [ 'id' => $address['id'], 'street_address' => 'is billing st', 'contact_id' => $this->_params['contact_id'], - )); - $params = array_merge($this->_params, array('contribution_status_id' => 2)); + ]); + $params = array_merge($this->_params, ['contribution_status_id' => 2]); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ 'address:::is billing st', - )); + ]); $mut->stop(); $this->revertTemplateToReservedTemplate(); @@ -2023,14 +2023,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCompleteTransactionFeeAmount() { $this->createLoggedInUser(); - $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $params = array_merge($this->_params, ['contribution_status_id' => 2]); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'fee_amount' => '.56', 'trxn_id' => '7778888', - )); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'sequential' => 1)); + ]); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id'], 'sequential' => 1]); $this->assertEquals('Completed', $contribution['contribution_status']); $this->assertEquals('7778888', $contribution['trxn_id']); $this->assertEquals('.56', $contribution['fee_amount']); @@ -2048,12 +2048,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCheckTaxAmount($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); $contact = $this->createLoggedInUser(); - $financialType = $this->callAPISuccess('financial_type', 'create', array( + $financialType = $this->callAPISuccess('financial_type', 'create', [ 'name' => 'Test taxable financial Type', 'is_reserved' => 0, 'is_active' => 1, - )); - $financialAccount = $this->callAPISuccess('financial_account', 'create', array( + ]); + $financialAccount = $this->callAPISuccess('financial_account', 'create', [ 'name' => 'Test Tax financial account ', 'contact_id' => $contact, 'financial_account_type_id' => 2, @@ -2062,26 +2062,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0, - )); + ]); $financialTypeId = $financialType['id']; $financialAccountId = $financialAccount['id']; - $financialAccountParams = array( + $financialAccountParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialTypeId, 'account_relationship' => 10, 'financial_account_id' => $financialAccountId, - ); + ]; CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams); - $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => $financialTypeId)); + $params = array_merge($this->_params, ['contribution_status_id' => 2, 'financial_type_id' => $financialTypeId]); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $contribution1 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1)); - $this->callAPISuccess('contribution', 'completetransaction', array( + $contribution1 = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1]); + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'trxn_id' => '777788888', 'fee_amount' => '6.00', - )); - $contribution2 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => array('tax_amount', 'fee_amount', 'net_amount'), 'sequential' => 1)); + ]); + $contribution2 = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id'], 'return' => ['tax_amount', 'fee_amount', 'net_amount'], 'sequential' => 1]); $this->assertEquals($contribution1['values'][0]['tax_amount'], $contribution2['values'][0]['tax_amount']); $this->assertEquals('6.00', $contribution2['values'][0]['fee_amount']); $this->assertEquals('99.00', $contribution2['values'][0]['net_amount']); @@ -2091,16 +2091,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test repeat contribution successfully creates line item. */ public function testRepeatTransaction() { - $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single'); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $originalContribution = $this->setUpRepeatTransaction($recurParams = [], 'single'); + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); - $lineItemParams = array( + ]); + $lineItemParams = [ 'entity_id' => $originalContribution['id'], 'sequential' => 1, - 'return' => array( + 'return' => [ 'entity_table', 'qty', 'unit_price', @@ -2110,24 +2110,24 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'deductible_amount', 'price_field_value_id', 'price_field_id', - ), - ); - $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ], + ]; + $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'], - ))); - $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ])); + $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'] + 1, - ))); + ])); unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']); unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]); - $this->_checkFinancialRecords(array( + $this->_checkFinancialRecords([ 'id' => $originalContribution['id'] + 1, - 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( + 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ 'id' => $originalContribution['payment_processor_id'], 'return' => 'payment_instrument_id', - )), - ), 'online'); + ]), + ], 'online'); $this->quickCleanUpFinancialEntities(); } @@ -2136,17 +2136,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testRepeatTransactionLineItems() { // CRM-19309 - $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'multiple'); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $originalContribution = $this->setUpRepeatTransaction($recurParams = [], 'multiple'); + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); + ]); - $lineItemParams = array( + $lineItemParams = [ 'entity_id' => $originalContribution['id'], 'sequential' => 1, - 'return' => array( + 'return' => [ 'entity_table', 'qty', 'unit_price', @@ -2156,14 +2156,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'deductible_amount', 'price_field_value_id', 'price_field_id', - ), - ); - $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ], + ]; + $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'], - ))); - $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ])); + $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'] + 1, - ))); + ])); // unset id and entity_id for all of them to be able to compare the lineItems: unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']); @@ -2177,7 +2177,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { // CRM-19309 so in future we also want to: // check that financial_line_items have been created for entity_id 3 and 4; - $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0); + $this->callAPISuccessGetCount('FinancialItem', ['description' => 'Sales Tax', 'amount' => 0], 0); $this->quickCleanUpFinancialEntities(); } @@ -2186,35 +2186,35 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testRepeatTransactionIsTest() { $this->_params['is_test'] = 1; - $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1), 'single'); + $originalContribution = $this->setUpRepeatTransaction(['is_test' => 1], 'single'); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); - $this->callAPISuccessGetCount('Contribution', array('contribution_test' => 1), 2); + ]); + $this->callAPISuccessGetCount('Contribution', ['contribution_test' => 1], 2); } /** * Test repeat contribution passed in status. */ public function testRepeatTransactionPassedInStatus() { - $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single'); + $originalContribution = $this->setUpRepeatTransaction($recurParams = [], 'single'); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Pending', 'trxn_id' => uniqid(), - )); - $this->callAPISuccessGetCount('Contribution', array('contribution_status_id' => 2), 1); + ]); + $this->callAPISuccessGetCount('Contribution', ['contribution_status_id' => 2], 1); } /** * Test repeat contribution accepts recur_id instead of original_contribution_id. */ public function testRepeatTransactionAcceptRecurID() { - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -2224,17 +2224,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $this->paymentProcessorID, - )); + ]); $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array('contribution_recur_id' => $contributionRecur['id'])) + ['contribution_recur_id' => $contributionRecur['id']]) ); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $contributionRecur['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); + ]); $this->quickCleanUpFinancialEntities(); } @@ -2243,7 +2243,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * CRM-19873 Test repattransaction if contribution_recur_id is a test. */ public function testRepeatTransactionTestRecurId() { - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'frequency_interval' => '1', 'amount' => '1.00', @@ -2253,20 +2253,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'frequency_unit' => 'month', 'payment_processor_id' => $this->paymentProcessorID, 'is_test' => 1, - )); + ]); $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'is_test' => 1, - )) + ]) ); - $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', array( + $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $contributionRecur['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); + ]); $this->assertEquals($contributionRecur['values'][1]['is_test'], $repeatedContribution['values'][2]['is_test']); $this->quickCleanUpFinancialEntities(); @@ -2279,40 +2279,40 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testRepeatTransactionMembershipRenewCompletedContribution() { list($originalContribution, $membership) = $this->setUpAutoRenewMembership(); - $this->callAPISuccess('contribution', 'create', array( + $this->callAPISuccess('contribution', 'create', [ 'contact_id' => $originalContribution['values'][1]['contact_id'], 'financial_type_id' => $originalContribution['values'][1]['financial_type_id'], 'total_amount' => $originalContribution['values'][1]['total_amount'], 'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'], 'contribution_status_id' => "Failed", - )); + ]); - $this->callAPISuccess('membership', 'create', array( + $this->callAPISuccess('membership', 'create', [ 'id' => $membership['id'], 'end_date' => 'yesterday', 'status_id' => 'Expired', - )); + ]); - $contribution = $this->callAPISuccess('contribution', 'repeattransaction', array( + $contribution = $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'], 'contribution_status_id' => 'Completed', 'trxn_id' => 'bobsled', - )); + ]); - $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', array( + $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', [ 'id' => $membership['id'], 'return' => 'status_id', - )); + ]); - $membership = $this->callAPISuccess('membership', 'get', array( + $membership = $this->callAPISuccess('membership', 'get', [ 'id' => $membership['id'], - )); + ]); $this->assertEquals('New', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipStatusId)); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'])); + $lineItem = $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id']]); $this->assertEquals('civicrm_membership', $lineItem['entity_table']); - $this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id'])); + $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']]); $this->quickCleanUpFinancialEntities(); $this->contactDelete($originalContribution['values'][1]['contact_id']); } @@ -2330,37 +2330,37 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } list($originalContribution, $membership) = $this->setUpAutoRenewMembership(); - $this->callAPISuccess('contribution', 'create', array( + $this->callAPISuccess('contribution', 'create', [ 'contact_id' => $originalContribution['values'][1]['contact_id'], 'financial_type_id' => $originalContribution['values'][1]['financial_type_id'], 'total_amount' => $originalContribution['values'][1]['total_amount'], 'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'], 'contribution_status_id' => "Completed", - )); + ]); - $this->callAPISuccess('membership', 'create', array( + $this->callAPISuccess('membership', 'create', [ 'id' => $membership['id'], 'end_date' => 'yesterday', 'status_id' => 'Expired', - )); + ]); - $contribution = $this->callAPISuccess('contribution', 'repeattransaction', array( + $contribution = $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'], 'contribution_status_id' => $contributionStatus['name'], 'trxn_id' => 'bobsled', - )); + ]); - $updatedMembership = $this->callAPISuccess('membership', 'getsingle', array( + $updatedMembership = $this->callAPISuccess('membership', 'getsingle', [ 'id' => $membership['id'], - )); + ]); $dateTime = new DateTime('yesterday'); $this->assertEquals($dateTime->format('Y-m-d'), $updatedMembership['end_date']); $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Expired'), $updatedMembership['status_id']); - $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'])); + $lineItem = $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id']]); $this->assertEquals('civicrm_membership', $lineItem['entity_table']); - $this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id'])); + $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']]); $this->quickCleanUpFinancialEntities(); $this->contactDelete($originalContribution['values'][1]['contact_id']); } @@ -2388,7 +2388,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testRepeatTransactionAlteredAmount() { $paymentProcessorID = $this->paymentProcessorCreate(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -2398,26 +2398,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessorID, - )); + ]); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], - )) + ]) ); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'total_amount' => '400', 'fee_amount' => 50, - )); + ]); - $lineItemParams = array( + $lineItemParams = [ 'entity_id' => $originalContribution['id'], 'sequential' => 1, - 'return' => array( + 'return' => [ 'entity_table', 'qty', 'unit_price', @@ -2427,26 +2427,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'deductible_amount', 'price_field_value_id', 'price_field_id', - ), - ); - $this->callAPISuccessGetSingle('contribution', array( + ], + ]; + $this->callAPISuccessGetSingle('contribution', [ 'total_amount' => 400, 'fee_amount' => 50, 'net_amount' => 350, - )); - $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ]); + $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'], - ))); + ])); $expectedLineItem = array_merge( - $lineItem1['values'][0], array( + $lineItem1['values'][0], [ 'line_total' => '400.00', 'unit_price' => '400.00', - ) + ] ); - $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'] + 1, - ))); + ])); unset($expectedLineItem['id'], $expectedLineItem['entity_id']); unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); @@ -2459,16 +2459,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testRepeatTransactionPassedInFinancialType() { $originalContribution = $this->setUpRecurringContribution(); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'financial_type_id' => 2, - )); - $lineItemParams = array( + ]); + $lineItemParams = [ 'entity_id' => $originalContribution['id'], 'sequential' => 1, - 'return' => array( + 'return' => [ 'entity_table', 'qty', 'unit_price', @@ -2478,27 +2478,27 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'deductible_amount', 'price_field_value_id', 'price_field_id', - ), - ); + ], + ]; - $this->callAPISuccessGetSingle('contribution', array( + $this->callAPISuccessGetSingle('contribution', [ 'total_amount' => 100, 'financial_type_id' => 2, - )); - $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ]); + $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'], - ))); + ])); $expectedLineItem = array_merge( - $lineItem1['values'][0], array( + $lineItem1['values'][0], [ 'line_total' => '100.00', 'unit_price' => '100.00', 'financial_type_id' => 2, 'contribution_type_id' => 2, - ) + ] ); - $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'] + 1, - ))); + ])); unset($expectedLineItem['id'], $expectedLineItem['entity_id']); unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); $this->assertEquals($expectedLineItem, $lineItem2['values'][0]); @@ -2508,17 +2508,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * CRM-17718 test appropriate action if financial type has changed for single line items. */ public function testRepeatTransactionUpdatedFinancialType() { - $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2)); + $originalContribution = $this->setUpRecurringContribution([], ['financial_type_id' => 2]); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); - $lineItemParams = array( + ]); + $lineItemParams = [ 'entity_id' => $originalContribution['id'], 'sequential' => 1, - 'return' => array( + 'return' => [ 'entity_table', 'qty', 'unit_price', @@ -2528,28 +2528,28 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'deductible_amount', 'price_field_value_id', 'price_field_id', - ), - ); + ], + ]; - $this->callAPISuccessGetSingle('contribution', array( + $this->callAPISuccessGetSingle('contribution', [ 'total_amount' => 100, 'financial_type_id' => 2, - )); - $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ]); + $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'], - ))); + ])); $expectedLineItem = array_merge( - $lineItem1['values'][0], array( + $lineItem1['values'][0], [ 'line_total' => '100.00', 'unit_price' => '100.00', 'financial_type_id' => 2, 'contribution_type_id' => 2, - ) + ] ); - $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'] + 1, - ))); + ])); unset($expectedLineItem['id'], $expectedLineItem['entity_id']); unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); $this->assertEquals($expectedLineItem, $lineItem2['values'][0]); @@ -2562,7 +2562,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $paymentProcessorID = $this->paymentProcessorCreate(); $campaignID = $this->campaignCreate(); $campaignID2 = $this->campaignCreate(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -2572,26 +2572,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessorID, - )); + ]); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'campaign_id' => $campaignID, - )) + ]) ); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'campaign_id' => $campaignID2, - )); + ]); - $this->callAPISuccessGetSingle('contribution', array( + $this->callAPISuccessGetSingle('contribution', [ 'total_amount' => 100, 'campaign_id' => $campaignID2, - )); + ]); } /** @@ -2603,7 +2603,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $paymentProcessorID = $this->paymentProcessorCreate(); $campaignID = $this->campaignCreate(); $campaignID2 = $this->campaignCreate(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -2614,25 +2614,25 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessorID, 'campaign_id' => $campaignID, - )); + ]); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'campaign_id' => $campaignID2, - )) + ]) ); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); + ]); - $this->callAPISuccessGetSingle('contribution', array( + $this->callAPISuccessGetSingle('contribution', [ 'total_amount' => 100, 'campaign_id' => $campaignID, - )); + ]); } /** @@ -2641,18 +2641,18 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * This case happens when the line item & contribution do not have the same type in his initiating transaction. */ public function testRepeatTransactionUpdatedFinancialTypeAndNotEquals() { - $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2)); + $originalContribution = $this->setUpRecurringContribution([], ['financial_type_id' => 2]); // This will made the trick to get the not equals behaviour. - $this->callAPISuccess('line_item', 'create', array('id' => 1, 'financial_type_id' => 4)); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('line_item', 'create', ['id' => 1, 'financial_type_id' => 4]); + $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); - $lineItemParams = array( + ]); + $lineItemParams = [ 'entity_id' => $originalContribution['id'], 'sequential' => 1, - 'return' => array( + 'return' => [ 'entity_table', 'qty', 'unit_price', @@ -2662,28 +2662,28 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'deductible_amount', 'price_field_value_id', 'price_field_id', - ), - ); - $this->callAPISuccessGetSingle('contribution', array( + ], + ]; + $this->callAPISuccessGetSingle('contribution', [ 'total_amount' => 100, 'financial_type_id' => 2, - )); - $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + ]); + $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'], - ))); + ])); $expectedLineItem = array_merge( - $lineItem1['values'][0], array( + $lineItem1['values'][0], [ 'line_total' => '100.00', 'unit_price' => '100.00', 'financial_type_id' => 4, 'contribution_type_id' => 4, - ) + ] ); - $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( + $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [ 'entity_id' => $originalContribution['id'] + 1, - ))); - $this->callAPISuccess('line_item', 'create', array('id' => 1, 'financial_type_id' => 1)); + ])); + $this->callAPISuccess('line_item', 'create', ['id' => 1, 'financial_type_id' => 1]); unset($expectedLineItem['id'], $expectedLineItem['entity_id']); unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); $this->assertEquals($expectedLineItem, $lineItem2['values'][0]); @@ -2694,13 +2694,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCompleteTransactionNetAmountOK() { $this->createLoggedInUser(); - $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $params = array_merge($this->_params, ['contribution_status_id' => 2]); unset($params['net_amount']); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], - )); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'])); + ]); + $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id']]); $this->assertEquals('Completed', $contribution['contribution_status']); $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']); } @@ -2712,16 +2712,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->swapMessageTemplateForTestTemplate(); $mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); - $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now')); + $params = array_merge($this->_params, ['contribution_status_id' => 2, 'receipt_date' => 'now']); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_date' => date('Y-m-d'))); - $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1)); + $this->callAPISuccess('contribution', 'completetransaction', ['id' => $contribution['id'], 'trxn_date' => date('Y-m-d')]); + $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id'], 'sequential' => 1]); $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][0]['receive_date']))); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Receipt - Contribution', 'receipt_date:::' . date('Ymd'), - )); + ]); $mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -2733,17 +2733,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contributionPage = $this->createReceiptableContributionPage(); $this->_params['contribution_page_id'] = $contributionPage['id']; - $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $params = array_merge($this->_params, ['contribution_status_id' => 2]); $contribution = $this->callAPISuccess('contribution', 'create', $params); // Complete the transaction overriding is_email_receipt to = FALSE - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'trxn_date' => date('2011-04-09'), 'trxn_id' => 'kazam', 'is_email_receipt' => 0, - )); + ]); // Check if a receipt was issued - $receipt_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receipt_date')); + $receipt_date = $this->callAPISuccess('Contribution', 'getvalue', ['id' => $contribution['id'], 'return' => 'receipt_date']); $this->assertEquals('', $receipt_date); } @@ -2754,24 +2754,24 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->swapMessageTemplateForTestTemplate(); $recurring = $this->setUpRecurringContribution(); - $contributionPage = $this->createReceiptableContributionPage(array('is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1)); + $contributionPage = $this->createReceiptableContributionPage(['is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1]); $this->_params['contribution_page_id'] = $contributionPage['id']; $this->_params['contribution_recur_id'] = $recurring['id']; $contribution = $this->setUpForCompleteTransaction(); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'trxn_date' => date('2011-04-09'), 'trxn_id' => 'kazam', 'is_email_receipt' => 1, - )); + ]); - $this->mut->checkMailLog(array( + $this->mut->checkMailLog([ 'is_recur:::1', 'cancelSubscriptionUrl:::' . CIVICRM_UF_BASEURL, - )); + ]); $this->mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -2785,7 +2785,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); // Create a Contribution Page with is_email_receipt = FALSE - $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array( + $contributionPage = $this->callAPISuccess('ContributionPage', 'create', [ 'receipt_from_name' => 'Mickey Mouse', 'receipt_from_email' => 'mickey@mouse.com', 'title' => "Test Contribution Page", @@ -2793,18 +2793,18 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'CAD', 'is_monetary' => TRUE, 'is_email_receipt' => 0, - )); + ]); $this->_params['contribution_page_id'] = $contributionPage['id']; - $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now')); + $params = array_merge($this->_params, ['contribution_status_id' => 2, 'receipt_date' => 'now']); $contribution = $this->callAPISuccess('contribution', 'create', $params); // Complete the transaction overriding is_email_receipt to = TRUE - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'is_email_receipt' => 1, - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ 'Please print this receipt for your records.', - )); + ]); $mut->stop(); } @@ -2814,13 +2814,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCompleteTransactionWithTestTemplate() { $this->swapMessageTemplateForTestTemplate(); $contribution = $this->setUpForCompleteTransaction(); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contribution['id'], 'trxn_date' => date('2011-04-09'), 'trxn_id' => 'kazam', - )); - $receive_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receive_date')); - $this->mut->checkMailLog(array( + ]); + $receive_date = $this->callAPISuccess('Contribution', 'getvalue', ['id' => $contribution['id'], 'return' => 'receive_date']); + $this->mut->checkMailLog([ 'email:::anthony_anderson@civicrm.org', 'is_monetary:::1', 'amount:::100.00', @@ -2835,7 +2835,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contributionID:::' . $contribution['id'], 'financialTypeId:::1', 'financialTypeName:::Donation', - )); + ]); $this->mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -2844,7 +2844,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Complete the transaction using the template with all the possible. */ public function testCompleteTransactionContributionPageFromAddress() { - $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array( + $contributionPage = $this->callAPISuccess('ContributionPage', 'create', [ 'receipt_from_name' => 'Mickey Mouse', 'receipt_from_email' => 'mickey@mouse.com', 'title' => "Test Contribution Page", @@ -2854,14 +2854,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'is_pay_later' => 1, 'is_monetary' => TRUE, 'is_email_receipt' => TRUE, - )); + ]); $this->_params['contribution_page_id'] = $contributionPage['id']; $contribution = $this->setUpForCompleteTransaction(); - $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'])); - $this->mut->checkMailLog(array( + $this->callAPISuccess('contribution', 'completetransaction', ['id' => $contribution['id']]); + $this->mut->checkMailLog([ 'mickey@mouse.com', 'Mickey Mouse <', - )); + ]); $this->mut->stop(); } @@ -2878,7 +2878,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCompleteTransactionSetStatusToInProgress($dataSet) { $paymentProcessorID = $this->paymentProcessorCreate(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([ 'contact_id' => $this->_individualId, 'installments' => '2', 'frequency_interval' => '1', @@ -2888,36 +2888,36 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessorID, - ), $dataSet['data'])); + ], $dataSet['data'])); $contribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'contribution_status_id' => 'Pending', 'receive_date' => $dataSet['receive_date'], - )) + ]) ); - $this->callAPISuccess('Contribution', 'completetransaction', array( + $this->callAPISuccess('Contribution', 'completetransaction', [ 'id' => $contribution, 'receive_date' => $dataSet['receive_date'], - )); - $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array( + ]); + $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', [ 'id' => $contributionRecur['id'], - 'return' => array('next_sched_contribution_date', 'contribution_status_id'), - )); + 'return' => ['next_sched_contribution_date', 'contribution_status_id'], + ]); $this->assertEquals(5, $contributionRecur['contribution_status_id']); $this->assertEquals($dataSet['expected'], $contributionRecur['next_sched_contribution_date']); $this->callAPISuccess('Contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'contribution_status_id' => 'Completed', - ) + ] )); - $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array( + $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', [ 'id' => $contributionRecur['id'], - 'return' => array('contribution_status_id'), - )); + 'return' => ['contribution_status_id'], + ]); $this->assertEquals(1, $contributionRecur['contribution_status_id']); } @@ -2927,44 +2927,44 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * @return array */ public function getScheduledDateData() { - $result = array(); - $result[]['2016-08-31-1-month'] = array( - 'data' => array( + $result = []; + $result[]['2016-08-31-1-month'] = [ + 'data' => [ 'start_date' => '2016-08-31', 'frequency_interval' => 1, 'frequency_unit' => 'month', - ), + ], 'receive_date' => '2016-08-31', 'expected' => '2016-10-01 00:00:00', - ); - $result[]['2012-01-01-1-month'] = array( - 'data' => array( + ]; + $result[]['2012-01-01-1-month'] = [ + 'data' => [ 'start_date' => '2012-01-01', 'frequency_interval' => 1, 'frequency_unit' => 'month', - ), + ], 'receive_date' => '2012-01-01', 'expected' => '2012-02-01 00:00:00', - ); - $result[]['2012-01-01-1-month'] = array( - 'data' => array( + ]; + $result[]['2012-01-01-1-month'] = [ + 'data' => [ 'start_date' => '2012-01-01', 'frequency_interval' => 1, 'frequency_unit' => 'month', - ), + ], 'receive_date' => '2012-02-29', 'expected' => '2012-03-29 00:00:00', - ); - $result['receive_date_includes_time']['2012-01-01-1-month'] = array( - 'data' => array( + ]; + $result['receive_date_includes_time']['2012-01-01-1-month'] = [ + 'data' => [ 'start_date' => '2012-01-01', 'frequency_interval' => 1, 'frequency_unit' => 'month', 'next_sched_contribution_date' => '2012-02-29', - ), + ], 'receive_date' => '2012-02-29 16:00:00', 'expected' => '2012-03-29 00:00:00', - ); + ]; return $result; } @@ -2980,25 +2980,25 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut->clearMessages(); $this->createLoggedInUser(); $contributionID = $this->createPendingPledgeContribution(); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contributionID, 'trxn_date' => '1 Feb 2013', - )); - $pledge = $this->callAPISuccessGetSingle('Pledge', array( + ]); + $pledge = $this->callAPISuccessGetSingle('Pledge', [ 'id' => $this->_ids['pledge'], - )); + ]); $this->assertEquals('Completed', $pledge['pledge_status']); - $status = $this->callAPISuccessGetValue('PledgePayment', array( + $status = $this->callAPISuccessGetValue('PledgePayment', [ 'pledge_id' => $this->_ids['pledge'], 'return' => 'status_id', - )); + ]); $this->assertEquals(1, $status); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'amount:::500.00', 'receive_date:::20130201000000', "receipt_date:::\n", - )); + ]); $mut->stop(); $this->revertTemplateToReservedTemplate(); } @@ -3014,14 +3014,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut->clearMessages(); $this->_individualId = $this->createLoggedInUser(); $contributionID = $this->createPendingParticipantContribution(); - $this->callAPISuccess('contribution', 'completetransaction', array( + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contributionID, - ) + ] ); - $participantStatus = $this->callAPISuccessGetValue('participant', array( + $participantStatus = $this->callAPISuccessGetValue('participant', [ 'id' => $this->_ids['participant'], 'return' => 'participant_status_id', - )); + ]); $this->assertEquals(1, $participantStatus); //Assert only three activities are created. @@ -3033,11 +3033,11 @@ class api_v3_ContributionTest extends CiviUnitTestCase { // update the original 'Contribution' activity created after completing payment $this->assertEquals(1, $activityNames['Contribution']); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Annual CiviCRM meet', 'Event', 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.', - )); + ]); $mut->stop(); } @@ -3046,27 +3046,27 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCompleteTransactionMembershipPriceSet() { $this->createPriceSetWithPage('membership'); - $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array( + $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', [ 'name' => 'Grace', 'return' => 'id', - )); + ]); $this->setUpPendingContribution($this->_ids['price_field_value'][0]); - $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); - $logs = $this->callAPISuccess('MembershipLog', 'get', array( + $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); + $logs = $this->callAPISuccess('MembershipLog', 'get', [ 'membership_id' => $this->_ids['membership'], - )); + ]); $this->assertEquals(1, $logs['count']); $this->assertEquals($stateOfGrace, $membership['status_id']); - $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution'])); - $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); + $this->callAPISuccess('contribution', 'completetransaction', ['id' => $this->_ids['contribution']]); + $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']); - $this->callAPISuccessGetSingle('LineItem', array( + $this->callAPISuccessGetSingle('LineItem', [ 'entity_id' => $this->_ids['membership'], 'entity_table' => 'civicrm_membership', - )); - $logs = $this->callAPISuccess('MembershipLog', 'get', array( + ]); + $logs = $this->callAPISuccess('MembershipLog', 'get', [ 'membership_id' => $this->_ids['membership'], - )); + ]); $this->assertEquals(2, $logs['count']); $this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']); //Assert only three activities are created. @@ -3085,19 +3085,19 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testPendingToCompleteContribution() { $this->createPriceSetWithPage('membership'); $this->setUpPendingContribution($this->_ids['price_field_value'][0]); - $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); + $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); // Case 1: Assert that Membership Signup Activity is created on Pending to Completed Contribution via backoffice - $activity = $this->callAPISuccess('Activity', 'get', array( + $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Membership Signup', 'source_record_id' => $this->_ids['membership'], 'status_id' => 'Scheduled', - )); + ]); $this->assertEquals(1, $activity['count']); // change pending contribution to completed $form = new CRM_Contribute_Form_Contribution(); - $form->_params = array( + $form->_params = [ 'id' => $this->_ids['contribution'], 'total_amount' => 20, 'net_amount' => 20, @@ -3125,37 +3125,37 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_mode' => 'membership', 'source' => 'Membership Signup and Renewal', - ); + ]; $form->testSubmit($form->_params, CRM_Core_Action::UPDATE); // Case 2: After successful payment for Pending backoffice there are three activities created // 2.a Update status of existing Scheduled Membership Signup (created in step 1) to Completed - $activity = $this->callAPISuccess('Activity', 'get', array( + $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Membership Signup', 'source_record_id' => $this->_ids['membership'], 'status_id' => 'Completed', - )); + ]); $this->assertEquals(1, $activity['count']); // 2.b Contribution activity created to record successful payment - $activity = $this->callAPISuccess('Activity', 'get', array( + $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Contribution', 'source_record_id' => $this->_ids['contribution'], 'status_id' => 'Completed', - )); + ]); $this->assertEquals(1, $activity['count']); // 2.c 'Change membership type' activity created to record Membership status change from Grace to Current - $activity = $this->callAPISuccess('Activity', 'get', array( + $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Change Membership Status', 'source_record_id' => $this->_ids['membership'], 'status_id' => 'Completed', - )); + ]); $this->assertEquals(1, $activity['count']); $this->assertEquals('Status changed from Grace to Current', $activity['values'][$activity['id']]['subject']); //Create another pending contribution for renewal - $contribution = $this->callAPISuccess('contribution', 'create', array( + $contribution = $this->callAPISuccess('contribution', 'create', [ 'domain_id' => 1, 'contact_id' => $this->_ids['contact'], 'receive_date' => date('Ymd'), @@ -3170,10 +3170,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_page_id' => $this->_ids['contribution_page'], // We can't rely on contribution api to link line items correctly to membership 'skipLineItem' => TRUE, - 'api.membership_payment.create' => array('membership_id' => $this->_ids['membership']), - )); + 'api.membership_payment.create' => ['membership_id' => $this->_ids['membership']], + ]); - $this->callAPISuccess('line_item', 'create', array( + $this->callAPISuccess('line_item', 'create', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'contribution_id' => $contribution['id'], @@ -3183,8 +3183,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'line_total' => 20, 'financial_type_id' => 1, 'price_field_value_id' => $this->_ids['price_field_value']['cont'], - )); - $this->callAPISuccess('line_item', 'create', array( + ]); + $this->callAPISuccess('line_item', 'create', [ 'entity_id' => $this->_ids['membership'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], @@ -3195,7 +3195,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'price_field_value_id' => $this->_ids['price_field_value'][0], 'membership_type_id' => $this->_ids['membership_type'], - )); + ]); //Update it to Failed. $form->_params['id'] = $contribution['id']; @@ -3203,7 +3203,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $form->testSubmit($form->_params, CRM_Core_Action::UPDATE); //Existing membership should not get updated to expired. - $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); + $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); $this->assertNotEquals($membership['status_id'], 4); } @@ -3213,8 +3213,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCompleteTransactionMembershipPriceSetTwoTerms() { $this->createPriceSetWithPage('membership'); $this->setUpPendingContribution($this->_ids['price_field_value'][1]); - $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution'])); - $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); + $this->callAPISuccess('contribution', 'completetransaction', ['id' => $this->_ids['contribution']]); + $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']); $this->cleanUpAfterPriceSets(); } @@ -3230,16 +3230,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * @param int $priceFieldValueID * @param array $contriParams */ - public function setUpPendingContribution($priceFieldValueID, $contriParams = array()) { + public function setUpPendingContribution($priceFieldValueID, $contriParams = []) { $contactID = $this->individualCreate(); - $membership = $this->callAPISuccess('membership', 'create', array( + $membership = $this->callAPISuccess('membership', 'create', [ 'contact_id' => $contactID, 'membership_type_id' => $this->_ids['membership_type'], 'start_date' => 'yesterday - 1 year', 'end_date' => 'yesterday', 'join_date' => 'yesterday - 1 year', - )); - $contribution = $this->callAPISuccess('contribution', 'create', array_merge(array( + ]); + $contribution = $this->callAPISuccess('contribution', 'create', array_merge([ 'domain_id' => 1, 'contact_id' => $contactID, 'receive_date' => date('Ymd'), @@ -3252,10 +3252,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 2, 'contribution_page_id' => $this->_ids['contribution_page'], - 'api.membership_payment.create' => array('membership_id' => $membership['id']), - ), $contriParams)); + 'api.membership_payment.create' => ['membership_id' => $membership['id']], + ], $contriParams)); - $this->callAPISuccess('line_item', 'create', array( + $this->callAPISuccess('line_item', 'create', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'contribution_id' => $contribution['id'], @@ -3265,7 +3265,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'line_total' => 20, 'financial_type_id' => 1, 'price_field_value_id' => $priceFieldValueID, - )); + ]); $this->_ids['contact'] = $contactID; $this->_ids['contribution'] = $contribution['id']; $this->_ids['membership'] = $membership['id']; @@ -3277,17 +3277,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testSendMail() { $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $this->callAPISuccess('contribution', 'sendconfirmation', array( + $this->callAPISuccess('contribution', 'sendconfirmation', [ 'id' => $contribution['id'], 'receipt_from_email' => 'api@civicrm.org', - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ '$ 100.00', 'Contribution Information', 'Please print this confirmation for your records', - ), array( + ], [ 'Event', - )); + ]); $this->checkCreditCardDetails($mut, $contribution['id']); $mut->stop(); @@ -3301,7 +3301,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); // Create contribution page - $pageParams = array( + $pageParams = [ 'title' => 'Webform Contributions', 'financial_type_id' => 1, 'contribution_type_id' => 1, @@ -3309,22 +3309,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'is_pay_later' => 1, 'pay_later_text' => 'I will send payment by cheque', 'pay_later_receipt' => 'Send your cheque payable to "CiviCRM LLC" to the office', - ); + ]; $contributionPage = $this->callAPISuccess('contribution_page', 'create', $pageParams); // Create pay later contribution - $contribParams = array( + $contribParams = [ 'contact_id' => $this->_individualId, 'financial_type_id' => 1, 'is_pay_later' => 1, 'contribution_status_id' => 2, 'contribution_page_id' => $contributionPage['id'], 'total_amount' => '10.00', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); // Create line item - $lineItemParams = array( + $lineItemParams = [ 'contribution_id' => $contribution['id'], 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', @@ -3332,15 +3332,15 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'qty' => 1, 'unit_price' => "10.00", 'line_total' => "10.00", - ); + ]; $lineItem = $this->callAPISuccess('lineItem', 'create', $lineItemParams); // Create email try { - civicrm_api3('contribution', 'sendconfirmation', array( + civicrm_api3('contribution', 'sendconfirmation', [ 'id' => $contribution['id'], 'receipt_from_email' => 'api@civicrm.org', - )); + ]); } catch (Exception $e) { // Need to figure out how to stop this some other day @@ -3353,12 +3353,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { // Retrieve mail & check it has the pay_later_receipt info $mut->getMostRecentEmail('raw'); - $mut->checkMailLog(array( + $mut->checkMailLog([ (string) $contribParams['total_amount'], $pageParams['pay_later_receipt'], - ), array( + ], [ 'Event', - )); + ]); $mut->stop(); } @@ -3371,21 +3371,21 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function checkCreditCardDetails($mut, $contributionID) { $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $this->callAPISuccess('contribution', 'sendconfirmation', array( + $this->callAPISuccess('contribution', 'sendconfirmation', [ 'id' => $contributionID, 'receipt_from_email' => 'api@civicrm.org', 'payment_processor_id' => $this->paymentProcessorID, - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ // credit card header 'Credit Card Information', // billing header 'Billing Name and Address', // billing name 'anthony_anderson@civicrm.org', - ), array( + ], [ 'Event', - )); + ]); } /** @@ -3394,12 +3394,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testSendMailEvent() { $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $event = $this->eventCreate(array( + $event = $this->eventCreate([ 'is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org', - )); + ]); $this->_eventID = $event['id']; - $participantParams = array( + $participantParams = [ 'contact_id' => $this->_individualId, 'event_id' => $this->_eventID, 'status_id' => 1, @@ -3408,22 +3408,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'register_date' => '2007-07-21 00:00:00', 'source' => 'Online Event Registration: API Testing', - ); + ]; $participant = $this->callAPISuccess('participant', 'create', $participantParams); - $this->callAPISuccess('participant_payment', 'create', array( + $this->callAPISuccess('participant_payment', 'create', [ 'participant_id' => $participant['id'], 'contribution_id' => $contribution['id'], - )); - $this->callAPISuccess('contribution', 'sendconfirmation', array( + ]); + $this->callAPISuccess('contribution', 'sendconfirmation', [ 'id' => $contribution['id'], 'receipt_from_email' => 'api@civicrm.org', - )); + ]); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Annual CiviCRM meet', 'Event', 'To: "Mr. Anthony Anderson II" ', - ), array()); + ], []); $mut->stop(); } @@ -3438,12 +3438,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function contributionGetnCheck($params, $id, $delete = TRUE) { - $contribution = $this->callAPISuccess('Contribution', 'Get', array( + $contribution = $this->callAPISuccess('Contribution', 'Get', [ 'id' => $id, - )); + ]); if ($delete) { - $this->callAPISuccess('contribution', 'delete', array('id' => $id)); + $this->callAPISuccess('contribution', 'delete', ['id' => $id]); } $this->assertAPISuccess($contribution, 0); $values = $contribution['values'][$contribution['id']]; @@ -3462,23 +3462,23 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function createPendingPledgeContribution() { - $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500)); + $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500]); $this->_ids['pledge'] = $pledgeID; - $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array( + $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, [ 'contribution_status_id' => 'Pending', 'total_amount' => 500, - ))); - $paymentID = $this->callAPISuccessGetValue('PledgePayment', array( - 'options' => array('limit' => 1), + ])); + $paymentID = $this->callAPISuccessGetValue('PledgePayment', [ + 'options' => ['limit' => 1], 'return' => 'id', - )); - $this->callAPISuccess('PledgePayment', 'create', array( + ]); + $this->callAPISuccess('PledgePayment', 'create', [ 'id' => $paymentID, 'contribution_id' => $contribution['id'], 'status_id' => 'Pending', 'scheduled_amount' => 500, - )); + ]); return $contribution['id']; } @@ -3487,23 +3487,23 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Create a pending contribution & linked pending participant record (along with an event). */ public function createPendingParticipantContribution() { - $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org')); - $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6, 'contact_id' => $this->_individualId)); + $event = $this->eventCreate(['is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org']); + $participantID = $this->participantCreate(['event_id' => $event['id'], 'status_id' => 6, 'contact_id' => $this->_individualId]); $this->_ids['participant'] = $participantID; - $params = array_merge($this->_params, array('contact_id' => $this->_individualId, 'contribution_status_id' => 2, 'financial_type_id' => 'Event Fee')); + $params = array_merge($this->_params, ['contact_id' => $this->_individualId, 'contribution_status_id' => 2, 'financial_type_id' => 'Event Fee']); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('participant_payment', 'create', array( + $this->callAPISuccess('participant_payment', 'create', [ 'contribution_id' => $contribution['id'], 'participant_id' => $participantID, - )); - $this->callAPISuccess('line_item', 'get', array( + ]); + $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', - 'api.line_item.create' => array( + 'api.line_item.create' => [ 'entity_id' => $participantID, 'entity_table' => 'civicrm_participant', - ), - )); + ], + ]); return $contribution['id']; } @@ -3548,62 +3548,62 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function _checkFinancialItem($contId, $context) { if ($context != 'paylater') { - $params = array( + $params = [ 'entity_id' => $contId, 'entity_table' => 'civicrm_contribution', - ); + ]; $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params, TRUE)); - $entityParams = array( + $entityParams = [ 'financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item', - ); + ]; $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); - $params = array( + $params = [ 'id' => $entityTrxn['entity_id'], - ); + ]; } if ($context == 'paylater') { $lineItems = CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'); foreach ($lineItems as $key => $item) { - $params = array( + $params = [ 'entity_id' => $key, 'entity_table' => 'civicrm_line_item', - ); - $compareParams = array('status_id' => 1); + ]; + $compareParams = ['status_id' => 1]; $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); } } elseif ($context == 'refund') { - $compareParams = array( + $compareParams = [ 'status_id' => 1, 'financial_account_id' => 1, 'amount' => -100, - ); + ]; } elseif ($context == 'cancelPending') { - $compareParams = array( + $compareParams = [ 'status_id' => 3, 'financial_account_id' => 1, 'amount' => -100, - ); + ]; } elseif ($context == 'changeFinancial') { $lineKey = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution')); - $params = array( + $params = [ 'entity_id' => $lineKey, 'amount' => -100, - ); - $compareParams = array( + ]; + $compareParams = [ 'financial_account_id' => 1, - ); + ]; $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); - $params = array( + $params = [ 'financial_account_id' => 3, 'entity_id' => $lineKey, - ); - $compareParams = array( + ]; + $compareParams = [ 'amount' => 100, - ); + ]; } if ($context != 'paylater') { $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); @@ -3622,34 +3622,34 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $entityFinancialTrxns = $this->getFinancialTransactionsForContribution($contributionID); - $originalTrxnParams = array( + $originalTrxnParams = [ 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($originalInstrumentID), 'payment_instrument_id' => $originalInstrumentID, 'amount' => $amount, 'status_id' => 1, - ); + ]; - $reversalTrxnParams = array( + $reversalTrxnParams = [ 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($originalInstrumentID), 'payment_instrument_id' => $originalInstrumentID, 'amount' => -$amount, 'status_id' => 1, - ); + ]; - $newTrxnParams = array( + $newTrxnParams = [ 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($newInstrumentID), 'payment_instrument_id' => $newInstrumentID, 'amount' => $amount, 'status_id' => 1, - ); + ]; - foreach (array($originalTrxnParams, $reversalTrxnParams, $newTrxnParams) as $index => $transaction) { + foreach ([$originalTrxnParams, $reversalTrxnParams, $newTrxnParams] as $index => $transaction) { $entityFinancialTrxn = $entityFinancialTrxns[$index]; $this->assertEquals($entityFinancialTrxn['amount'], $transaction['amount']); - $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', array( + $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', [ 'id' => $entityFinancialTrxn['financial_trxn_id'], - )); + ]); $this->assertEquals($transaction['status_id'], $financialTrxn['status_id']); $this->assertEquals($transaction['amount'], $financialTrxn['total_amount']); $this->assertEquals($transaction['amount'], $financialTrxn['net_amount']); @@ -3674,60 +3674,60 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * @param int $instrumentId * @param array $extraParams */ - public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array()) { + public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = []) { $financialTrxns = $this->getFinancialTransactionsForContribution($contribution['id']); $trxn = array_pop($financialTrxns); - $params = array( + $params = [ 'id' => $trxn['financial_trxn_id'], - ); + ]; if ($context == 'payLater') { - $compareParams = array( + $compareParams = [ 'status_id' => 1, 'from_financial_account_id' => CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['financial_type_id'], 'Accounts Receivable Account is'), - ); + ]; } elseif ($context == 'refund') { - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 6, 'total_amount' => -100, 'status_id' => 7, 'trxn_date' => '2015-01-01 09:00:00', 'trxn_id' => 'the refund', - ); + ]; } elseif ($context == 'cancelPending') { - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 7, 'total_amount' => -100, 'status_id' => 3, - ); + ]; } elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') { // @todo checkFinancialTrxnPaymentInstrumentChange instead for paymentInstrument. // It does the same thing with greater readability. // @todo remove handling for - $entityParams = array( + $entityParams = [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'amount' => -100, - ); + ]; $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); - $trxnParams1 = array( + $trxnParams1 = [ 'id' => $trxn['financial_trxn_id'], - ); + ]; if (empty($extraParams)) { - $compareParams = array( + $compareParams = [ 'total_amount' => -100, 'status_id' => 1, - ); + ]; } else { - $compareParams = array( + $compareParams = [ 'total_amount' => 100, 'status_id' => 1, - ); + ]; } if ($context == 'paymentInstrument') { $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId); @@ -3748,36 +3748,36 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function _addPaymentInstrument() { $gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name'); - $optionParams = array( + $optionParams = [ 'option_group_id' => $gId, 'label' => 'Test Card', 'name' => 'Test Card', 'value' => '6', 'weight' => '6', 'is_active' => 1, - ); + ]; $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); - $financialParams = array( + $financialParams = [ 'entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue['id'], 'account_relationship' => $relationTypeId, 'financial_account_id' => 7, - ); + ]; CRM_Financial_BAO_FinancialTypeAccount::add($financialParams); $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']); return $optionValue['values'][$optionValue['id']]['value']; } public function _deletedAddedPaymentInstrument() { - $result = $this->callAPISuccess('OptionValue', 'get', array( + $result = $this->callAPISuccess('OptionValue', 'get', [ 'option_group_id' => 'payment_instrument', 'name' => 'Test Card', 'value' => '6', 'is_active' => 1, - )); + ]); if ($id = CRM_Utils_Array::value('id', $result)) { - $this->callAPISuccess('OptionValue', 'delete', array('id' => $id)); + $this->callAPISuccess('OptionValue', 'delete', ['id' => $id]); } } @@ -3792,8 +3792,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * @return array|int */ - protected function setUpRecurringContribution($generalParams = array(), $recurParams = array()) { - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( + protected function setUpRecurringContribution($generalParams = [], $recurParams = []) { + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -3803,12 +3803,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $this->paymentProcessorID, - ), $generalParams, $recurParams)); + ], $generalParams, $recurParams)); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], - ), $generalParams) + ], $generalParams) ); return $originalContribution; } @@ -3824,8 +3824,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * @return array|int */ - protected function setUpAutoRenewMembership($generalParams = array(), $recurParams = array()) { - $newContact = $this->callAPISuccess('Contact', 'create', array( + protected function setUpAutoRenewMembership($generalParams = [], $recurParams = []) { + $newContact = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'sort_name' => 'McTesterson, Testy', 'display_name' => 'Testy McTesterson', @@ -3837,8 +3837,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'email_id' => '4', 'email' => 'tmctesterson@example.com', 'on_hold' => '0', - )); - $membershipType = $this->callAPISuccess('MembershipType', 'create', array( + ]); + $membershipType = $this->callAPISuccess('MembershipType', 'create', [ 'domain_id' => "Default Domain Name", 'member_of_contact_id' => 1, 'financial_type_id' => "Member Dues", @@ -3847,8 +3847,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'period_type' => 'rolling', 'name' => "Standard Member", 'minimum_fee' => 100, - )); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( + ]); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([ 'contact_id' => $newContact['id'], 'installments' => '12', 'frequency_interval' => '1', @@ -3858,35 +3858,35 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $this->paymentProcessorID, - ), $generalParams, $recurParams)); + ], $generalParams, $recurParams)); - $membership = $this->callAPISuccess('membership', 'create', array( + $membership = $this->callAPISuccess('membership', 'create', [ 'contact_id' => $newContact['id'], 'contribution_recur_id' => $contributionRecur['id'], 'financial_type_id' => "Member Dues", 'membership_type_id' => $membershipType['id'], 'num_terms' => 1, 'skipLineItem' => TRUE, - )); + ]); CRM_Price_BAO_LineItem::getLineItemArray($this->_params, NULL, 'membership', $membershipType['id']); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contact_id' => $newContact['id'], 'contribution_recur_id' => $contributionRecur['id'], 'financial_type_id' => "Member Dues", 'contribution_status_id' => 1, 'invoice_id' => uniqid(), - ), $generalParams) + ], $generalParams) ); - $lineItem = $this->callAPISuccess('LineItem', 'getsingle', array()); + $lineItem = $this->callAPISuccess('LineItem', 'getsingle', []); $this->assertEquals('civicrm_membership', $lineItem['entity_table']); - $membership = $this->callAPISuccess('Membership', 'getsingle', array('id' => $lineItem['entity_id'])); - $this->callAPISuccess('LineItem', 'getsingle', array()); - $this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id']), 1); + $membership = $this->callAPISuccess('Membership', 'getsingle', ['id' => $lineItem['entity_id']]); + $this->callAPISuccess('LineItem', 'getsingle', []); + $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']], 1); - return array($originalContribution, $membership); + return [$originalContribution, $membership]; } /** @@ -3897,9 +3897,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * @param array $contributionParams * @return array */ - protected function setUpRepeatTransaction($recurParams = array(), $flag, $contributionParams = array()) { + protected function setUpRepeatTransaction($recurParams = [], $flag, $contributionParams = []) { $paymentProcessorID = $this->paymentProcessorCreate(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -3909,7 +3909,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessorID, - ), $recurParams)); + ], $recurParams)); $originalContribution = ''; if ($flag == 'multiple') { @@ -3917,31 +3917,31 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $params = array_merge($this->_params, $contributionParams); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'skipLineItem' => 1, - 'api.line_item.create' => array( - array( + 'api.line_item.create' => [ + [ 'price_field_id' => 1, 'qty' => 2, 'line_total' => '20', 'unit_price' => '10', 'financial_type_id' => 1, - ), - array( + ], + [ 'price_field_id' => 1, 'qty' => 1, 'line_total' => '80', 'unit_price' => '80', 'financial_type_id' => 2, - ), - ), - ) + ], + ], + ] ) ); } elseif ($flag == 'single') { - $params = array_merge($this->_params, array('contribution_recur_id' => $contributionRecur['id'])); + $params = array_merge($this->_params, ['contribution_recur_id' => $contributionRecur['id']]); $params = array_merge($params, $contributionParams); $originalContribution = $this->callAPISuccess('contribution', 'create', $params); } @@ -3957,7 +3957,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { protected function setUpForCompleteTransaction() { $this->mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); - $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now')); + $params = array_merge($this->_params, ['contribution_status_id' => 2, 'receipt_date' => 'now']); $contribution = $this->callAPISuccess('contribution', 'create', $params); return $contribution; } @@ -3966,7 +3966,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test repeat contribution uses the Payment Processor' payment_instrument setting. */ public function testRepeatTransactionWithNonCreditCardDefault() { - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -3976,17 +3976,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $this->paymentProcessorID, - )); + ]); $contribution1 = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array('contribution_recur_id' => $contributionRecur['id'], 'payment_instrument_id' => 2)) + ['contribution_recur_id' => $contributionRecur['id'], 'payment_instrument_id' => 2]) ); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name'); - $contribution2 = $this->callAPISuccess('contribution', 'repeattransaction', array( + $contribution2 = $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'original_contribution_id' => $contribution1, - )); + ]); $this->assertEquals(array_search('Debit Card', $paymentInstruments), $contribution2['values'][$contribution2['id']]['payment_instrument_id']); $this->quickCleanUpFinancialEntities(); } @@ -3996,33 +3996,33 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testRepeatTransactionMembershipCreatePendingContribution() { list($originalContribution, $membership) = $this->setUpAutoRenewMembership(); - $this->callAPISuccess('membership', 'create', array( + $this->callAPISuccess('membership', 'create', [ 'id' => $membership['id'], 'end_date' => 'yesterday', 'status_id' => 'Expired', - )); - $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', array( + ]); + $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'], 'contribution_status_id' => 'Pending', 'trxn_id' => uniqid(), - )); - $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', array( + ]); + $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', [ 'id' => $membership['id'], 'return' => 'status_id', - )); + ]); // Let's see if the membership payments got created while we're at it. - $membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', array( + $membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', [ 'membership_id' => $membership['id'], - )); + ]); $this->assertEquals(2, $membershipPayments['count']); $this->assertEquals('Expired', CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'status_id', $membershipStatusId)); - $this->callAPISuccess('Contribution', 'completetransaction', array('id' => $repeatedContribution['id'])); - $membership = $this->callAPISuccessGetSingle('membership', array( + $this->callAPISuccess('Contribution', 'completetransaction', ['id' => $repeatedContribution['id']]); + $membership = $this->callAPISuccessGetSingle('membership', [ 'id' => $membership['id'], 'return' => 'status_id, end_date', - )); + ]); $this->assertEquals('New', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membership['status_id'])); $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 month')), $membership['end_date']); @@ -4036,18 +4036,18 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testSendMailWithAPISetFromDetails() { $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $this->callAPISuccess('contribution', 'sendconfirmation', array( + $this->callAPISuccess('contribution', 'sendconfirmation', [ 'id' => $contribution['id'], 'receipt_from_email' => 'api@civicrm.org', 'receipt_from_name' => 'CiviCRM LLC', - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ 'From: CiviCRM LLC ', 'Contribution Information', 'Please print this confirmation for your records', - ), array( + ], [ 'Event', - )); + ]); $mut->stop(); } @@ -4058,17 +4058,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->createLoggedInUser(); $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $this->callAPISuccess('contribution', 'sendconfirmation', array( + $this->callAPISuccess('contribution', 'sendconfirmation', [ 'id' => $contribution['id'], - )); - $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => 1)); - $mut->checkMailLog(array( + ]); + $domain = $this->callAPISuccess('domain', 'getsingle', ['id' => 1]); + $mut->checkMailLog([ 'From: ' . $domain['from_name'] . ' <' . $domain['from_email'] . '>', 'Contribution Information', 'Please print this confirmation for your records', - ), array( + ], [ 'Event', - )); + ]); $mut->stop(); } @@ -4078,20 +4078,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testSendMailWithRepeatTransactionAPIFalltoDomain() { $this->createLoggedInUser(); $mut = new CiviMailUtils($this, TRUE); - $contribution = $this->setUpRepeatTransaction(array(), 'single'); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $contribution = $this->setUpRepeatTransaction([], 'single'); + $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'original_contribution_id' => $contribution, - )); - $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => 1)); - $mut->checkMailLog(array( + ]); + $domain = $this->callAPISuccess('domain', 'getsingle', ['id' => 1]); + $mut->checkMailLog([ 'From: ' . $domain['from_name'] . ' <' . $domain['from_email'] . '>', 'Contribution Information', 'Please print this confirmation for your records', - ), array( + ], [ 'Event', - ) + ] ); $mut->stop(); } @@ -4101,9 +4101,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testSendMailWithRepeatTransactionAPIFalltoContributionPage() { $mut = new CiviMailUtils($this, TRUE); - $contributionPage = $this->contributionPageCreate(array('receipt_from_name' => 'CiviCRM LLC', 'receipt_from_email' => 'contributionpage@civicrm.org', 'is_email_receipt' => 1)); + $contributionPage = $this->contributionPageCreate(['receipt_from_name' => 'CiviCRM LLC', 'receipt_from_email' => 'contributionpage@civicrm.org', 'is_email_receipt' => 1]); $paymentProcessorID = $this->paymentProcessorCreate(); - $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ 'contact_id' => $this->_individualId, 'installments' => '12', 'frequency_interval' => '1', @@ -4113,27 +4113,27 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'USD', 'frequency_unit' => 'month', 'payment_processor_id' => $paymentProcessorID, - )); + ]); $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array( + [ 'contribution_recur_id' => $contributionRecur['id'], 'contribution_page_id' => $contributionPage['id'], - )) + ]) ); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'original_contribution_id' => $originalContribution, - ) + ] ); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'From: CiviCRM LLC ', 'Contribution Information', 'Please print this confirmation for your records', - ), array( + ], [ 'Event', - )); + ]); $mut->stop(); } @@ -4142,24 +4142,24 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testSendMailWithRepeatTransactionAPIFalltoSystemFromNoDefaultFrom() { $mut = new CiviMailUtils($this, TRUE); - $originalContribution = $contribution = $this->setUpRepeatTransaction(array(), 'single'); - $fromEmail = $this->CallAPISuccess('optionValue', 'get', array('is_default' => 1, 'option_group_id' => 'from_email_address', 'sequential' => 1)); + $originalContribution = $contribution = $this->setUpRepeatTransaction([], 'single'); + $fromEmail = $this->CallAPISuccess('optionValue', 'get', ['is_default' => 1, 'option_group_id' => 'from_email_address', 'sequential' => 1]); foreach ($fromEmail['values'] as $from) { - $this->callAPISuccess('optionValue', 'create', array('is_default' => 0, 'id' => $from['id'])); + $this->callAPISuccess('optionValue', 'create', ['is_default' => 0, 'id' => $from['id']]); } - $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => CRM_Core_Config::domainID())); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $domain = $this->callAPISuccess('domain', 'getsingle', ['id' => CRM_Core_Config::domainID()]); + $this->callAPISuccess('contribution', 'repeattransaction', [ 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), 'original_contribution_id' => $originalContribution, - )); - $mut->checkMailLog(array( + ]); + $mut->checkMailLog([ 'From: ' . $domain['name'] . ' <' . $domain['domain_email'] . '>', 'Contribution Information', 'Please print this confirmation for your records', - ), array( + ], [ 'Event', - )); + ]); $mut->stop(); } @@ -4171,8 +4171,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * @return array|int */ - protected function createReceiptableContributionPage($params = array()) { - $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array_merge(array( + protected function createReceiptableContributionPage($params = []) { + $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array_merge([ 'receipt_from_name' => 'Mickey Mouse', 'receipt_from_email' => 'mickey@mouse.com', 'title' => "Test Contribution Page", @@ -4180,7 +4180,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'currency' => 'CAD', 'is_monetary' => TRUE, 'is_email_receipt' => TRUE, - ), $params)); + ], $params)); return $contributionPage; } @@ -4190,7 +4190,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCardTypeAndPanTruncation() { $creditCardTypeIDs = array_flip(CRM_Financial_DAO_FinancialTrxn::buildOptions('card_type_id')); $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'receive_date' => '2016-01-20', 'total_amount' => 100, @@ -4198,30 +4198,30 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'payment_instrument' => 'Credit Card', 'card_type_id' => $creditCardTypeIDs['Visa'], 'pan_truncation' => 4567, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), $creditCardTypeIDs['Visa']); $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567); - $params = array( + $params = [ 'id' => $contribution['id'], 'pan_truncation' => 2345, 'card_type_id' => $creditCardTypeIDs['Amex'], - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $financialTrxn = $this->callAPISuccessGetSingle( 'FinancialTrxn', - array( + [ 'id' => $lastFinancialTrxnId['financialTrxnId'], - 'return' => array('card_type_id', 'pan_truncation'), - ) + 'return' => ['card_type_id', 'pan_truncation'], + ] ); $this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), $creditCardTypeIDs['Amex']); $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 2345); @@ -4232,12 +4232,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * @see https://issues.civicrm.org/jira/projects/CRM/issues/CRM-20678 */ public function testRepeatTransactionWithDifferenceCurrency() { - $originalContribution = $this->setUpRepeatTransaction(array('currency' => 'AUD'), 'single', array('currency' => 'AUD')); - $contribution = $this->callAPISuccess('contribution', 'repeattransaction', array( + $originalContribution = $this->setUpRepeatTransaction(['currency' => 'AUD'], 'single', ['currency' => 'AUD']); + $contribution = $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); + ]); $this->assertEquals('AUD', $contribution['values'][$contribution['id']]['currency']); } @@ -4250,24 +4250,24 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Array of associated financial items. */ protected function getFinancialTransactionsForContribution($contributionID) { - $trxnParams = array( + $trxnParams = [ 'entity_id' => $contributionID, 'entity_table' => 'civicrm_contribution', - ); + ]; // @todo the following function has naming errors & has a weird signature & appears to // only be called from test classes. Move into test suite & maybe just use api // from this function. - return array_merge(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, FALSE, array())); + return array_merge(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, FALSE, [])); } /** * Test getunique api call for Contribution entity */ public function testContributionGetUnique() { - $result = $this->callAPIAndDocument($this->_entity, 'getunique', array(), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'getunique', [], __FUNCTION__, __FILE__); $this->assertEquals(2, $result['count']); - $this->assertEquals(array('trxn_id'), $result['values']['UI_contrib_trxn_id']); - $this->assertEquals(array('invoice_id'), $result['values']['UI_contrib_invoice_id']); + $this->assertEquals(['trxn_id'], $result['values']['UI_contrib_trxn_id']); + $this->assertEquals(['invoice_id'], $result['values']['UI_contrib_invoice_id']); } /** @@ -4289,11 +4289,11 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'financial_type_id' => $financialType['id'], ] ); - $this->callAPISuccess('contribution', 'repeattransaction', array( + $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $contribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => uniqid(), - )); + ]); $this->callAPISuccessGetCount('Contribution', [], 2); } diff --git a/tests/phpunit/api/v3/CountryTest.php b/tests/phpunit/api/v3/CountryTest.php index 3e02d38d50..f0af9429de 100644 --- a/tests/phpunit/api/v3/CountryTest.php +++ b/tests/phpunit/api/v3/CountryTest.php @@ -40,11 +40,11 @@ class api_v3_CountryTest extends CiviUnitTestCase { $this->_apiversion = 3; parent::setUp(); $this->useTransaction(TRUE); - $this->_params = array( + $this->_params = [ 'name' => 'Made Up Land', 'iso_code' => 'ZZ', 'region_id' => 1, - ); + ]; } public function testCreateCountry() { @@ -53,18 +53,18 @@ class api_v3_CountryTest extends CiviUnitTestCase { $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('country', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('country', 'delete', ['id' => $result['id']]); } public function testDeleteCountry() { //create one $create = $this->callAPISuccess('country', 'create', $this->_params); - $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('country', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $get = $this->callAPISuccess('country', 'get', array( + $get = $this->callAPISuccess('country', 'get', [ 'id' => $create['id'], - )); + ]); $this->assertEquals(0, $get['count'], 'Country not successfully deleted'); } @@ -72,14 +72,14 @@ class api_v3_CountryTest extends CiviUnitTestCase { * Test civicrm_phone_get with empty params. */ public function testGetEmptyParams() { - $result = $this->callAPISuccess('Country', 'Get', array()); + $result = $this->callAPISuccess('Country', 'Get', []); } /** * Test civicrm_phone_get with wrong params. */ public function testGetWrongParams() { - $this->callAPIFailure('Country', 'Get', array('id' => 'abc')); + $this->callAPIFailure('Country', 'Get', ['id' => 'abc']); } /** @@ -87,9 +87,9 @@ class api_v3_CountryTest extends CiviUnitTestCase { */ public function testGet() { $country = $this->callAPISuccess('Country', 'create', $this->_params); - $params = array( + $params = [ 'iso_code' => $this->_params['iso_code'], - ); + ]; $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__, __FILE__); $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']); $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']); @@ -106,9 +106,9 @@ class api_v3_CountryTest extends CiviUnitTestCase { unset($params['id']); $this->callAPISuccess('country', 'create', $params); $this->callAPIFailure('country', 'create', $params); - $check = $this->callAPISuccess('country', 'getcount', array( + $check = $this->callAPISuccess('country', 'getcount', [ 'iso_code' => $params['iso_code'], - )); + ]); $this->assertEquals(1, $check); } diff --git a/tests/phpunit/api/v3/CustomApiTest.php b/tests/phpunit/api/v3/CustomApiTest.php index a6cd684936..9562fdb1f6 100644 --- a/tests/phpunit/api/v3/CustomApiTest.php +++ b/tests/phpunit/api/v3/CustomApiTest.php @@ -53,20 +53,20 @@ class api_v3_CustomApiTest extends CiviUnitTestCase { */ public function testCustomApi() { $this->installApi(); - $this->callAPISuccess('MailingProviderData', 'create', array( + $this->callAPISuccess('MailingProviderData', 'create', [ 'contact_identifier' => 'xyz', 'mailing_identifier' => 'abx', - )); - $this->callAPISuccess('Mailing', 'create', array('name' => 'CiviMail', 'hash' => 'abx')); - $result = $this->callAPISuccess('MailingProviderData', 'get', array('return' => array('mailing_identifier.name', 'contact_identifier', 'mailing_identifier'))); + ]); + $this->callAPISuccess('Mailing', 'create', ['name' => 'CiviMail', 'hash' => 'abx']); + $result = $this->callAPISuccess('MailingProviderData', 'get', ['return' => ['mailing_identifier.name', 'contact_identifier', 'mailing_identifier']]); $this->assertEquals(1, $result['count']); $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']); $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']); - $this->assertEquals(array( + $this->assertEquals([ 'contact_identifier' => 'xyz', 'mailing_identifier' => 'abx', 'mailing_identifier.name' => 'CiviMail', - ), reset($result['values'])); + ], reset($result['values'])); } /** @@ -75,11 +75,11 @@ class api_v3_CustomApiTest extends CiviUnitTestCase { * @param array $entityTypes */ public function hookEntityTypes(&$entityTypes) { - $entityTypes['CRM_Omnimail_DAO_MailingProviderData'] = array( + $entityTypes['CRM_Omnimail_DAO_MailingProviderData'] = [ 'name' => 'MailingProviderData', 'class' => 'CRM_Omnimail_DAO_MailingProviderData', 'table' => 'civicrm_maiing_provider_data', - ); + ]; } /** @@ -87,7 +87,7 @@ class api_v3_CustomApiTest extends CiviUnitTestCase { */ public function installApi() { require_once __DIR__ . '/custom_api/MailingProviderData.php'; - $this->hookClass->setHook('civicrm_entityTypes', array($this, 'hookEntityTypes')); + $this->hookClass->setHook('civicrm_entityTypes', [$this, 'hookEntityTypes']); CRM_Core_DAO_AllCoreTables::init(TRUE); CRM_Core_DAO::executeQuery( "CREATE TABLE IF NOT EXISTS `civicrm_mailing_provider_data` ( diff --git a/tests/phpunit/api/v3/CustomGroupTest.php b/tests/phpunit/api/v3/CustomGroupTest.php index 12eca924ca..3d48d5de8e 100644 --- a/tests/phpunit/api/v3/CustomGroupTest.php +++ b/tests/phpunit/api/v3/CustomGroupTest.php @@ -41,7 +41,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { public function setUp() { $this->_entity = 'CustomGroup'; - $this->_params = array( + $this->_params = [ 'title' => 'Test_Group_1', 'name' => 'test_group_1', 'extends' => 'Individual', @@ -51,12 +51,12 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - ); + ]; parent::setUp(); } public function tearDown() { - $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field'); + $tablesToTruncate = ['civicrm_custom_group', 'civicrm_custom_field']; // true tells quickCleanup to drop any tables that might have been created in the test $this->quickCleanup($tablesToTruncate, TRUE); } @@ -70,7 +70,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * & delete (& it would be easy to add if not there) */ public function testCustomGroupCreateNoParam() { - $customGroup = $this->callAPIFailure('custom_group', 'create', array(), + $customGroup = $this->callAPIFailure('custom_group', 'create', [], 'Mandatory key(s) missing from params array: title, extends' ); } @@ -79,7 +79,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with empty array. */ public function testCustomGroupCreateNoExtends() { - $params = array( + $params = [ 'domain_id' => 1, 'title' => 'Test_Group_1', 'name' => 'test_group_1', @@ -89,7 +89,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - ); + ]; $customGroup = $this->callAPIFailure('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends'); @@ -100,7 +100,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with empty array. */ public function testCustomGroupCreateInvalidExtends() { - $params = array( + $params = [ 'domain_id' => 1, 'title' => 'Test_Group_1', 'name' => 'test_group_1', @@ -110,8 +110,8 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - 'extends' => array(), - ); + 'extends' => [], + ]; $customGroup = $this->callAPIFailure('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends'); @@ -121,7 +121,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with a string instead of array for extends. */ public function testCustomGroupCreateExtendsString() { - $params = array( + $params = [ 'domain_id' => 1, 'title' => 'Test_Group_1', 'name' => 'test_group_1', @@ -132,7 +132,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, 'extends' => 'Individual', - ); + ]; $customGroup = $this->callAPISuccess('custom_group', 'create', $params); } @@ -141,17 +141,17 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with valid array. */ public function testCustomGroupCreate() { - $params = array( + $params = [ 'title' => 'Test_Group_1', 'name' => 'test_group_1', - 'extends' => array('Individual'), + 'extends' => ['Individual'], 'weight' => 4, 'collapse_display' => 1, 'style' => 'Inline', 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - ); + ]; $result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); @@ -162,16 +162,16 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with valid array. */ public function testCustomGroupGetFields() { - $params = array( - 'options' => array('get_options' => 'style'), - ); + $params = [ + 'options' => ['get_options' => 'style'], + ]; $result = $this->callAPISuccess('custom_group', 'getfields', $params); - $expected = array( + $expected = [ 'Tab' => 'Tab', 'Inline' => 'Inline', 'Tab with table' => 'Tab with table', - ); + ]; $this->assertEquals($expected, $result['values']['style']['options']); } @@ -179,17 +179,17 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with extends array length greater than 1 */ public function testCustomGroupExtendsMultipleCreate() { - $params = array( + $params = [ 'title' => 'Test_Group_1', 'name' => 'test_group_1', - 'extends' => array('Individual', 'Household'), + 'extends' => ['Individual', 'Household'], 'weight' => 4, 'collapse_display' => 1, 'style' => 'Inline', 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - ); + ]; $result = $this->callAPIFailure('custom_group', 'create', $params, 'implode(): Invalid arguments passed'); @@ -199,16 +199,16 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with style missing from params array. */ public function testCustomGroupCreateNoStyle() { - $params = array( + $params = [ 'title' => 'Test_Group_1', 'name' => 'test_group_1', - 'extends' => array('Individual'), + 'extends' => ['Individual'], 'weight' => 4, 'collapse_display' => 1, 'help_pre' => 'This is Pre Help For Test Group 1', 'help_post' => 'This is Post Help For Test Group 1', 'is_active' => 1, - ); + ]; $customGroup = $this->callAPISuccess('custom_group', 'create', $params); $this->assertNotNull($customGroup['id']); @@ -228,14 +228,14 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check without title. */ public function testCustomGroupCreateNoTitle() { - $params = array( - 'extends' => array('Contact'), + $params = [ + 'extends' => ['Contact'], 'weight' => 5, 'collapse_display' => 1, 'style' => 'Tab', 'help_pre' => 'This is Pre Help For Test Group 2', 'help_post' => 'This is Post Help For Test Group 2', - ); + ]; $customGroup = $this->callAPIFailure('custom_group', 'create', $params, 'Mandatory key(s) missing from params array: title'); @@ -245,16 +245,16 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check for household without weight. */ public function testCustomGroupCreateHouseholdNoWeight() { - $params = array( + $params = [ 'title' => 'Test_Group_3', 'name' => 'test_group_3', - 'extends' => array('Household'), + 'extends' => ['Household'], 'collapse_display' => 1, 'style' => 'Tab', 'help_pre' => 'This is Pre Help For Test Group 3', 'help_post' => 'This is Post Help For Test Group 3', 'is_active' => 1, - ); + ]; $customGroup = $this->callAPISuccess('custom_group', 'create', $params); $this->assertNotNull($customGroup['id']); @@ -266,17 +266,17 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check for Contribution Donation. */ public function testCustomGroupCreateContributionDonation() { - $params = array( + $params = [ 'title' => 'Test_Group_6', 'name' => 'test_group_6', - 'extends' => array('Contribution', array(1)), + 'extends' => ['Contribution', [1]], 'weight' => 6, 'collapse_display' => 1, 'style' => 'Inline', 'help_pre' => 'This is Pre Help For Test Group 6', 'help_post' => 'This is Post Help For Test Group 6', 'is_active' => 1, - ); + ]; $customGroup = $this->callAPISuccess('custom_group', 'create', $params); $this->assertNotNull($customGroup['id']); @@ -287,18 +287,18 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with valid array. */ public function testCustomGroupCreateGroup() { - $params = array( + $params = [ 'domain_id' => 1, 'title' => 'Test_Group_8', 'name' => 'test_group_8', - 'extends' => array('Group'), + 'extends' => ['Group'], 'weight' => 7, 'collapse_display' => 1, 'is_active' => 1, 'style' => 'Inline', 'help_pre' => 'This is Pre Help For Test Group 8', 'help_post' => 'This is Post Help For Test Group 8', - ); + ]; $customGroup = $this->callAPISuccess('CustomGroup', 'create', $params); $this->assertNotNull($customGroup['id']); @@ -326,16 +326,16 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with Activity - Meeting Type */ public function testCustomGroupCreateActivityMeeting() { - $params = array( + $params = [ 'title' => 'Test_Group_10', 'name' => 'test_group_10', - 'extends' => array('Activity', array(1)), + 'extends' => ['Activity', [1]], 'weight' => 8, 'collapse_display' => 1, 'style' => 'Inline', 'help_pre' => 'This is Pre Help For Test Group 10', 'help_post' => 'This is Post Help For Test Group 10', - ); + ]; $customGroup = $this->callAPISuccess('custom_group', 'create', $params); $this->assertNotNull($customGroup['id']); @@ -348,7 +348,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check without GroupID. */ public function testCustomGroupDeleteWithoutGroupID() { - $customGroup = $this->callAPIFailure('custom_group', 'delete', array()); + $customGroup = $this->callAPIFailure('custom_group', 'delete', []); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id'); } @@ -365,10 +365,10 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * Check with valid custom group id. */ public function testCustomGroupDelete() { - $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group')); - $params = array( + $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_group']); + $params = [ 'id' => $customGroup['id'], - ); + ]; $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__, __FILE__); $this->assertAPISuccess($result); } @@ -379,7 +379,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { public function testGetCustomGroupSuccess() { $this->callAPISuccess($this->_entity, 'create', $this->_params); - $params = array(); + $params = []; $result = $this->callAPIAndDocument($this->_entity, 'get', $params, __FUNCTION__, __FILE__); $values = $result['values'][$result['id']]; foreach ($this->_params as $key => $value) { diff --git a/tests/phpunit/api/v3/CustomSearchTest.php b/tests/phpunit/api/v3/CustomSearchTest.php index ebf7cc3113..4ac288050b 100644 --- a/tests/phpunit/api/v3/CustomSearchTest.php +++ b/tests/phpunit/api/v3/CustomSearchTest.php @@ -14,11 +14,11 @@ class api_v3_CustomSearchTest extends CiviUnitTestCase { } public function testCustomSearch() { - $result = $this->callAPISuccess('CustomSearch', 'create', array( + $result = $this->callAPISuccess('CustomSearch', 'create', [ 'label' => 'Invalid, overwritten', 'description' => 'Longish description of the example search form', 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez', - )); + ]); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $entityId = $result['id']; @@ -31,10 +31,10 @@ class api_v3_CustomSearchTest extends CiviUnitTestCase { WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"'); // deactivate - $result = $this->callAPISuccess('CustomSearch', 'create', array( + $result = $this->callAPISuccess('CustomSearch', 'create', [ 'id' => $entityId, 'is_active' => 0, - )); + ]); $this->assertEquals(1, $result['count']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value @@ -45,10 +45,10 @@ class api_v3_CustomSearchTest extends CiviUnitTestCase { WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"'); // activate - $result = $this->callAPISuccess('CustomSearch', 'create', array( + $result = $this->callAPISuccess('CustomSearch', 'create', [ 'id' => $entityId, 'is_active' => 1, - )); + ]); $this->assertEquals(1, $result['count']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value @@ -57,11 +57,11 @@ class api_v3_CustomSearchTest extends CiviUnitTestCase { AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") '); $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"'); - $check = $this->callAPISuccess('CustomSearch', 'get', array('id' => $entityId)); + $check = $this->callAPISuccess('CustomSearch', 'get', ['id' => $entityId]); if (!empty($check['count'])) { - $result = $this->callAPISuccess('CustomSearch', 'delete', array( + $result = $this->callAPISuccess('CustomSearch', 'delete', [ 'id' => $entityId, - )); + ]); } $this->assertEquals(1, $result['count']); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value diff --git a/tests/phpunit/api/v3/CustomValueContactTypeTest.php b/tests/phpunit/api/v3/CustomValueContactTypeTest.php index a163eef788..2fd96b5aa1 100644 --- a/tests/phpunit/api/v3/CustomValueContactTypeTest.php +++ b/tests/phpunit/api/v3/CustomValueContactTypeTest.php @@ -41,64 +41,64 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); // Create Group For Individual Contact Type - $groupIndividual = array( + $groupIndividual = [ 'title' => 'TestGroup For Indivi' . substr(sha1(rand()), 0, 5), - 'extends' => array('Individual'), + 'extends' => ['Individual'], 'style' => 'Inline', 'is_active' => 1, - ); + ]; $this->CustomGroupIndividual = $this->customGroupCreate($groupIndividual); - $this->IndividualField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndividual['id'])); + $this->IndividualField = $this->customFieldCreate(['custom_group_id' => $this->CustomGroupIndividual['id']]); // Create Group For Individual-Student Contact Sub Type - $groupIndiStudent = array( + $groupIndiStudent = [ 'title' => 'Student Test' . substr(sha1(rand()), 0, 5), - 'extends' => array('Individual', array('Student')), + 'extends' => ['Individual', ['Student']], 'style' => 'Inline', 'is_active' => 1, - ); + ]; $this->CustomGroupIndiStudent = $this->customGroupCreate($groupIndiStudent); - $this->IndiStudentField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndiStudent['id'])); + $this->IndiStudentField = $this->customFieldCreate(['custom_group_id' => $this->CustomGroupIndiStudent['id']]); - $params = array( + $params = [ 'first_name' => 'Mathev', 'last_name' => 'Adison', 'contact_type' => 'Individual', - ); + ]; $this->individual = $this->individualCreate($params); - $params = array( + $params = [ 'first_name' => 'Steve', 'last_name' => 'Tosun', 'contact_type' => 'Individual', 'contact_sub_type' => 'Student', - ); + ]; $this->individualStudent = $this->individualCreate($params); - $params = array( + $params = [ 'first_name' => 'Mark', 'last_name' => 'Dawson', 'contact_type' => 'Individual', 'contact_sub_type' => 'Parent', - ); + ]; $this->individualParent = $this->individualCreate($params); - $params = array( + $params = [ 'organization_name' => 'Wellspring', 'contact_type' => 'Organization', - ); + ]; $this->organization = $this->organizationCreate($params); - $params = array( + $params = [ 'organization_name' => 'SubUrban', 'contact_type' => 'Organization', 'contact_sub_type' => 'Sponsor', - ); + ]; $this->organizationSponsor = $this->organizationCreate($params); //refresh php cached variables CRM_Core_PseudoConstant::flush(); @@ -107,7 +107,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { } public function tearDown() { - $tablesToTruncate = array('civicrm_contact', 'civicrm_cache'); + $tablesToTruncate = ['civicrm_contact', 'civicrm_cache']; $this->quickCleanup($tablesToTruncate, TRUE); } @@ -115,19 +115,19 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { * Test that custom fields is returned for correct contact type only. */ public function testGetFields() { - $result = $this->callAPISuccess('Contact', 'getfields', array()); + $result = $this->callAPISuccess('Contact', 'getfields', []); $this->assertArrayHasKey("custom_{$this->IndividualField['id']}", $result['values'], 'If This fails there is probably a caching issue - failure in line' . __LINE__ . print_r(array_keys($result['values']), TRUE)); - $result = $this->callAPISuccess('Contact', 'getfields', array( + $result = $this->callAPISuccess('Contact', 'getfields', [ 'action' => 'create', 'contact_type' => 'Individual', - ), 'in line' . __LINE__); + ], 'in line' . __LINE__); $this->assertArrayHasKey("custom_{$this->IndividualField['id']}", $result['values']); - $result = $this->callAPISuccess('Contact', 'getfields', array( + $result = $this->callAPISuccess('Contact', 'getfields', [ 'action' => 'create', 'contact_type' => 'Organization', - )); + ]); $this->assertArrayNotHasKey("custom_{$this->IndividualField['id']}", $result['values'], 'in line' . __LINE__ . print_r(array_keys($result['values']), TRUE)); - $result = $this->callAPISuccess('Relationship', 'getfields', array('action' => 'create'), 'in line' . __LINE__); + $result = $this->callAPISuccess('Relationship', 'getfields', ['action' => 'create'], 'in line' . __LINE__); $this->assertArrayNotHasKey("custom_{$this->IndividualField['id']}", $result['values']); } @@ -136,13 +136,13 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testAddIndividualCustomDataToOrganization() { - $params = array( + $params = [ 'id' => $this->organization, 'contact_type' => 'Organization', "custom_{$this->IndividualField['id']}" => 'Test String', // so that undefined_fields is returned 'debug' => 1, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertTrue(is_array($contact['undefined_fields']), __LINE__); @@ -154,7 +154,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { * note - don't copy & paste this - is of marginal value */ public function testAddCustomDataEmptyToIndividual() { - $contact = $this->callAPIFailure('contact', 'create', array(), + $contact = $this->callAPIFailure('contact', 'create', [], 'Mandatory key(s) missing from params array: contact_type' ); } @@ -164,11 +164,11 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testAddValidCustomDataToIndividual() { - $params = array( + $params = [ 'contact_id' => $this->individual, 'contact_type' => 'Individual', "custom_{$this->IndividualField['id']}" => 'Test String', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertNotNull($contact['id']); @@ -184,13 +184,13 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testAddIndividualStudentCustomDataToOrganizationSponsor() { - $params = array( + $params = [ 'contact_id' => $this->organizationSponsor, 'contact_type' => 'Organization', "custom_{$this->IndiStudentField['id']}" => 'Test String', // so that undefined_fields is returned 'debug' => 1, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertTrue(is_array($contact['undefined_fields']), __LINE__); @@ -202,11 +202,11 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testCreateValidCustomDataToIndividualStudent() { - $params = array( + $params = [ 'contact_id' => $this->individualStudent, 'contact_type' => 'Individual', "custom_{$this->IndiStudentField['id']}" => 'Test String', - ); + ]; $result = $this->callAPISuccess('contact', 'create', $params); @@ -223,13 +223,13 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testAddIndividualStudentCustomDataToIndividualParent() { - $params = array( + $params = [ 'contact_id' => $this->individualParent, 'contact_type' => 'Individual', "custom_{$this->IndiStudentField['id']}" => 'Test String', // so that undefined_fields is returned 'debug' => 1, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertTrue(is_array($contact['undefined_fields']), __LINE__); $this->assertTrue(in_array("custom_{$this->IndiStudentField['id']}", $contact['undefined_fields']), __LINE__); @@ -242,20 +242,20 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testRetrieveValidCustomDataToIndividual() { - $params = array( + $params = [ 'contact_id' => $this->individual, 'contact_type' => 'Individual', "custom_" . $this->IndividualField['id'] => 'Test String', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertAPISuccess($contact); - $params = array( + $params = [ 'contact_id' => $this->individual, 'contact_type' => 'Individual', "return.custom_{$this->IndividualField['id']}" => 1, - ); + ]; $getContact = $this->callAPISuccess('contact', 'get', $params); @@ -267,21 +267,21 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { */ public function testRetrieveValidCustomDataToIndividualStudent() { - $params = array( + $params = [ 'contact_id' => $this->individualStudent, 'contact_type' => 'Individual', 'contact_sub_type' => 'Student', "custom_{$this->IndiStudentField['id']}" => 'Test String', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertAPISuccess($contact); - $params = array( + $params = [ 'contact_id' => $this->individualStudent, 'contact_type' => 'Individual', 'contact_sub_type' => 'Student', "return.custom_{$this->IndiStudentField['id']}" => 1, - ); + ]; $getContact = $this->callAPISuccess('contact', 'get', $params); diff --git a/tests/phpunit/api/v3/CustomValueTest.php b/tests/phpunit/api/v3/CustomValueTest.php index c99b72debb..b037e91f4b 100644 --- a/tests/phpunit/api/v3/CustomValueTest.php +++ b/tests/phpunit/api/v3/CustomValueTest.php @@ -41,36 +41,36 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { } public function _populateOptionAndCustomGroup($type = NULL) { - $dataValues = array( - 'integer' => array(1, 2, 3), - 'number' => array(10.11, 20.22, 30.33), - 'string' => array(substr(sha1(rand()), 0, 4) . '(', substr(sha1(rand()), 0, 3) . '|', substr(sha1(rand()), 0, 2) . ','), + $dataValues = [ + 'integer' => [1, 2, 3], + 'number' => [10.11, 20.22, 30.33], + 'string' => [substr(sha1(rand()), 0, 4) . '(', substr(sha1(rand()), 0, 3) . '|', substr(sha1(rand()), 0, 2) . ','], // 'country' => array_rand(CRM_Core_PseudoConstant::country(FALSE, FALSE), 3), // This does not work in the test at the moment due to caching issues. //'state_province' => array_rand(CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE), 3), 'date' => NULL, 'contact' => NULL, 'boolean' => NULL, - ); + ]; - $dataValues = !empty($type) ? array($type => $dataValues[$type]) : $dataValues; + $dataValues = !empty($type) ? [$type => $dataValues[$type]] : $dataValues; foreach ($dataValues as $dataType => $values) { - $this->optionGroup[$dataType] = array('values' => $values); + $this->optionGroup[$dataType] = ['values' => $values]; if (!empty($values)) { $result = $this->callAPISuccess('OptionGroup', 'create', - array( + [ 'name' => "{$dataType}_group", - 'api.option_value.create' => array('label' => "$dataType 1", 'value' => $values[0]), - 'api.option_value.create.1' => array('label' => "$dataType 2", 'value' => $values[1]), - 'api.option_value.create.2' => array('label' => "$dataType 3", 'value' => $values[2]), - ) + 'api.option_value.create' => ['label' => "$dataType 1", 'value' => $values[0]], + 'api.option_value.create.1' => ['label' => "$dataType 2", 'value' => $values[1]], + 'api.option_value.create.2' => ['label' => "$dataType 3", 'value' => $values[2]], + ] ); $this->optionGroup[$dataType]['id'] = $result['id']; } elseif ($dataType == 'contact') { for ($i = 0; $i < 3; $i++) { - $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com')); + $result = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com']); $this->optionGroup[$dataType]['values'][$i] = $result['id']; } } @@ -80,12 +80,12 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { } public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_email', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact', - ); + ]; // true tells quickCleanup to drop any tables that might have been created in the test $this->quickCleanup($tablesToTruncate, TRUE); @@ -94,9 +94,9 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { if (!empty($this->optionGroup)) { foreach ($this->optionGroup as $type => $value) { if (!empty($value['id'])) { - $count = $this->callAPISuccess('OptionGroup', 'get', array('id' => $value['id'])); + $count = $this->callAPISuccess('OptionGroup', 'get', ['id' => $value['id']]); if ((bool) $count['count']) { - $this->callAPISuccess('OptionGroup', 'delete', array('id' => $value['id'])); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $value['id']]); } } } @@ -105,13 +105,13 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { public function testCreateCustomValue() { $this->_populateOptionAndCustomGroup(); - $this->_customField = $this->customFieldCreate(array('custom_group_id' => $this->ids['string']['custom_group_id'])); + $this->_customField = $this->customFieldCreate(['custom_group_id' => $this->ids['string']['custom_group_id']]); $this->_customFieldID = $this->_customField['id']; $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml(); $count = 0; - $optionSupportingHTMLTypes = array('Select', 'Radio', 'CheckBox', 'Autocomplete-Select', 'Multi-Select'); + $optionSupportingHTMLTypes = ['Select', 'Radio', 'CheckBox', 'Autocomplete-Select', 'Multi-Select']; foreach ($customFieldDataType as $dataType => $label) { switch ($dataType) { @@ -126,12 +126,12 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { case 'Boolean': //Based on the custom field data-type choose desired SQL operators(to test with) and basic $type - if (in_array($dataType, array('String', 'Link'))) { - $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'); + if (in_array($dataType, ['String', 'Link'])) { + $validSQLOperators = ['=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL']; $type = 'string'; } elseif ($dataType == 'Boolean') { - $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL'); + $validSQLOperators = ['=', '!=', 'IS NOT NULL', 'IS NULL']; $type = 'boolean'; } else { @@ -150,7 +150,7 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { else { $type = $dataType == 'Int' ? 'integer' : 'number'; } - $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'); + $validSQLOperators = ['=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL']; } //Create custom field of $dataType and html-type $html @@ -159,17 +159,17 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { // the LIKE operator could potentially bypass ACLs (as could IS NOT NULL) and some thought needs to be given // to it. if (in_array($html, $optionSupportingHTMLTypes)) { - $validSQLOperators = array_diff($validSQLOperators, array('LIKE', 'NOT LIKE')); + $validSQLOperators = array_diff($validSQLOperators, ['LIKE', 'NOT LIKE']); } - $params = array( + $params = [ 'custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "$dataType - $html", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL, - ); - if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) { - $params += array('option_group_id' => $this->optionGroup[$type]['id']); + ]; + if (!in_array($html, ['Text', 'TextArea']) && !in_array($dataType, ['Link', 'Date', 'ContactReference', 'Boolean'])) { + $params += ['option_group_id' => $this->optionGroup[$type]['id']]; } $customField = $this->customFieldCreate($params); //Now test with $validSQLOperator SQL operators against its custom value(s) @@ -189,10 +189,10 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { public function _testCustomValue($customField, $sqlOps, $type) { $isSerialized = CRM_Core_BAO_CustomField::isSerialized($customField); $customId = $customField['id']; - $params = array( + $params = [ 'contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man1@yahoo.com', - ); + ]; $result = $this->callAPISuccess('Contact', 'create', $params); $contactId = $result['id']; @@ -268,12 +268,12 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); switch ($op) { case '=': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => (is_array($selectedValue) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValue) : $selectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => (is_array($selectedValue) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValue) : $selectedValue)]); $this->assertEquals($contactId, $result['id']); break; case '!=': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $notselectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $notselectedValue]]); $this->assertEquals(TRUE, array_key_exists($contactId, $result['values'])); break; @@ -286,24 +286,24 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { } // To be precise in for these operator we can't just rely on one contact, // hence creating multiple contact with custom value less/more then $selectedValue respectively - $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man2@yahoo.com')); + $result = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man2@yahoo.com']); $contactId2 = $result['id']; - $this->callAPISuccess('CustomValue', 'create', array('entity_id' => $contactId2, 'custom_' . $customId => $lesserSelectedValue)); + $this->callAPISuccess('CustomValue', 'create', ['entity_id' => $contactId2, 'custom_' . $customId => $lesserSelectedValue]); if ($op == '>') { - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $lesserSelectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $lesserSelectedValue]]); $this->assertEquals($contactId, $result['id']); } elseif ($op == '<') { - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $selectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $selectedValue]]); $this->assertEquals($contactId2, $result['id']); } else { - $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man3@yahoo.com')); + $result = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man3@yahoo.com']); $contactId3 = $result['id']; - $this->callAPISuccess('CustomValue', 'create', array('entity_id' => $contactId3, 'custom_' . $customId => $greaterSelectedValue)); + $this->callAPISuccess('CustomValue', 'create', ['entity_id' => $contactId3, 'custom_' . $customId => $greaterSelectedValue]); - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $selectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $selectedValue]]); $this->assertEquals($contactId, $result['values'][$contactId]['id']); if ($op == '>=') { @@ -312,46 +312,46 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { else { $this->assertEquals($contactId2, $result['values'][$contactId2]['id']); } - $this->callAPISuccess('contact', 'delete', array('id' => $contactId3)); + $this->callAPISuccess('contact', 'delete', ['id' => $contactId3]); } - $this->callAPISuccess('contact', 'delete', array('id' => $contactId2)); + $this->callAPISuccess('contact', 'delete', ['id' => $contactId2]); break; case 'IN': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => (array) $selectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => (array) $selectedValue]]); $this->assertEquals($contactId, $result['id']); break; case 'NOT IN': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => (array) $notselectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => (array) $notselectedValue]]); $this->assertEquals($contactId, $result['id']); break; case 'LIKE': $selectedValue = is_array($selectedValue) ? $selectedValue[0] : $selectedValue; - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => "%$selectedValue%"))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => "%$selectedValue%"]]); $this->assertEquals($contactId, $result['id']); break; case 'NOT LIKE': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $notselectedValue))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $notselectedValue]]); $this->assertEquals($contactId, $result['id']); break; case 'IS NULL': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => 1))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => 1]]); $this->assertEquals(FALSE, array_key_exists($contactId, $result['values'])); break; case 'IS NOT NULL': - $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => 1))); + $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => 1]]); $this->assertEquals($contactId, $result['id']); break; } } - $this->callAPISuccess('Contact', 'delete', array('id' => $contactId)); + $this->callAPISuccess('Contact', 'delete', ['id' => $contactId]); } /** @@ -364,31 +364,31 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { public function testAlterOptionValue() { $this->_populateOptionAndCustomGroup('string'); - $selectField = $this->customFieldCreate(array( + $selectField = $this->customFieldCreate([ 'custom_group_id' => $this->ids['string']['custom_group_id'], 'label' => 'Custom Select', 'html_type' => 'Select', 'option_group_id' => $this->optionGroup['string']['id'], - )); - $selectField = civicrm_api3('customField', 'getsingle', array('id' => $selectField['id'])); - $radioField = $this->customFieldCreate(array( + ]); + $selectField = civicrm_api3('customField', 'getsingle', ['id' => $selectField['id']]); + $radioField = $this->customFieldCreate([ 'custom_group_id' => $this->ids['string']['custom_group_id'], 'label' => 'Custom Radio', 'html_type' => 'Radio', 'option_group_id' => $selectField['option_group_id'], - )); - $multiSelectField = $this->customFieldCreate(array( + ]); + $multiSelectField = $this->customFieldCreate([ 'custom_group_id' => $this->ids['string']['custom_group_id'], 'label' => 'Custom Multi-Select', 'html_type' => 'Multi-Select', 'option_group_id' => $selectField['option_group_id'], - )); + ]); $selectName = 'custom_' . $selectField['id']; $radioName = 'custom_' . $radioField['id']; $multiSelectName = 'custom_' . $multiSelectField['id']; $controlFieldName = 'custom_' . $this->ids['string']['custom_field_id']; - $params = array( + $params = [ 'first_name' => 'abc4', 'last_name' => 'xyz4', 'contact_type' => 'Individual', @@ -398,109 +398,109 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $radioName => $this->optionGroup['string']['values'][1], // The control group in a science experiment should be unaffected $controlFieldName => $this->optionGroup['string']['values'][2], - ); + ]; $contact = $this->callAPISuccess('Contact', 'create', $params); - $result = $this->callAPISuccess('Contact', 'getsingle', array( + $result = $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $contact['id'], - 'return' => array($selectName, $multiSelectName), - )); + 'return' => [$selectName, $multiSelectName], + ]); $this->assertEquals($params[$selectName], $result[$selectName]); $this->assertEquals($params[$multiSelectName], $result[$multiSelectName]); - $this->callAPISuccess('OptionValue', 'create', array( + $this->callAPISuccess('OptionValue', 'create', [ 'value' => 'one-modified', 'option_group_id' => $selectField['option_group_id'], 'name' => 'string 1', - 'options' => array( - 'match-mandatory' => array('option_group_id', 'name'), - ), - )); + 'options' => [ + 'match-mandatory' => ['option_group_id', 'name'], + ], + ]); - $result = $this->callAPISuccess('Contact', 'getsingle', array( + $result = $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $contact['id'], - 'return' => array($selectName, $multiSelectName, $controlFieldName, $radioName), - )); + 'return' => [$selectName, $multiSelectName, $controlFieldName, $radioName], + ]); // Ensure the relevant fields have been updated $this->assertEquals('one-modified', $result[$selectName]); - $this->assertEquals(array('one-modified', $params[$radioName], $params[$controlFieldName]), $result[$multiSelectName]); + $this->assertEquals(['one-modified', $params[$radioName], $params[$controlFieldName]], $result[$multiSelectName]); // This field should not have changed because we didn't alter this option $this->assertEquals($params[$radioName], $result[$radioName]); // This should not have changed because this field doesn't use the affected option group $this->assertEquals($params[$controlFieldName], $result[$controlFieldName]); // Add test of proof that multivalue fields. - $this->callAPISuccess('CustomValue', 'create', array( + $this->callAPISuccess('CustomValue', 'create', [ 'entity_id' => $contact['id'], - $multiSelectName => array($params[$radioName], $params[$controlFieldName]), - )); - $result = $this->callAPISuccess('Contact', 'getsingle', array( + $multiSelectName => [$params[$radioName], $params[$controlFieldName]], + ]); + $result = $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $contact['id'], - 'return' => array($selectName, $multiSelectName, $controlFieldName, $radioName), - )); + 'return' => [$selectName, $multiSelectName, $controlFieldName, $radioName], + ]); - $this->assertEquals(array($params[$radioName], $params[$controlFieldName]), $result[$multiSelectName]); + $this->assertEquals([$params[$radioName], $params[$controlFieldName]], $result[$multiSelectName]); } public function testGettree() { - $cg = $this->callAPISuccess('CustomGroup', 'create', array( + $cg = $this->callAPISuccess('CustomGroup', 'create', [ 'title' => 'TestGettree', 'extends' => 'Individual', - )); - $cf = $this->callAPISuccess('CustomField', 'create', array( + ]); + $cf = $this->callAPISuccess('CustomField', 'create', [ 'custom_group_id' => $cg['id'], 'label' => 'Got Options', 'name' => 'got_options', "data_type" => "String", "html_type" => "Multi-Select", - 'option_values' => array('1' => 'One', '2' => 'Two', '3' => 'Three'), - )); + 'option_values' => ['1' => 'One', '2' => 'Two', '3' => 'Three'], + ]); $fieldName = 'custom_' . $cf['id']; - $contact = $this->individualCreate(array($fieldName => array('2', '3'))); + $contact = $this->individualCreate([$fieldName => ['2', '3']]); // Verify values are formatted correctly - $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact)); - $this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']); + $tree = $this->callAPISuccess('CustomValue', 'gettree', ['entity_type' => 'Contact', 'entity_id' => $contact]); + $this->assertEquals(['2', '3'], $tree['values']['TestGettree']['fields']['got_options']['value']['data']); $this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']); // Try limiting the return params - $tree = $this->callAPISuccess('CustomValue', 'gettree', array( + $tree = $this->callAPISuccess('CustomValue', 'gettree', [ 'entity_type' => 'Contact', 'entity_id' => $contact, - 'return' => array( + 'return' => [ 'custom_group.id', 'custom_field.id', - ), - )); - $this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']); + ], + ]); + $this->assertEquals(['2', '3'], $tree['values']['TestGettree']['fields']['got_options']['value']['data']); $this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']); - $this->assertEquals(array('id', 'fields'), array_keys($tree['values']['TestGettree'])); + $this->assertEquals(['id', 'fields'], array_keys($tree['values']['TestGettree'])); // Ensure display values are returned even if data is not - $tree = $this->callAPISuccess('CustomValue', 'gettree', array( + $tree = $this->callAPISuccess('CustomValue', 'gettree', [ 'entity_type' => 'Contact', 'entity_id' => $contact, - 'return' => array( + 'return' => [ 'custom_value.display', - ), - )); + ], + ]); $this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']); $this->assertFalse(isset($tree['values']['TestGettree']['fields']['got_options']['value']['data'])); // Verify that custom set appears for individuals even who don't have any custom data $contact2 = $this->individualCreate(); - $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact2)); + $tree = $this->callAPISuccess('CustomValue', 'gettree', ['entity_type' => 'Contact', 'entity_id' => $contact2]); $this->assertArrayHasKey('TestGettree', $tree['values']); // Verify that custom set doesn't appear for other contact types $org = $this->organizationCreate(); - $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $org)); + $tree = $this->callAPISuccess('CustomValue', 'gettree', ['entity_type' => 'Contact', 'entity_id' => $org]); $this->assertArrayNotHasKey('TestGettree', $tree['values']); } public function testGettree_getfields() { - $fields = $this->callAPISuccess('CustomValue', 'getfields', array('api_action' => 'gettree')); + $fields = $this->callAPISuccess('CustomValue', 'getfields', ['api_action' => 'gettree']); $fields = $fields['values']; $this->assertTrue((bool) $fields['entity_id']['api.required']); $this->assertTrue((bool) $fields['entity_type']['api.required']); @@ -514,26 +514,26 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { */ public function testUpdateCustomGreetings() { // Create a custom group with one field. - $customGroupResult = $this->callAPISuccess('CustomGroup', 'create', array( + $customGroupResult = $this->callAPISuccess('CustomGroup', 'create', [ 'sequential' => 1, 'title' => "test custom group", 'extends' => "Individual", - )); - $customFieldResult = $this->callAPISuccess('CustomField', 'create', array( + ]); + $customFieldResult = $this->callAPISuccess('CustomField', 'create', [ 'custom_group_id' => $customGroupResult['id'], 'label' => "greeting test", 'data_type' => "String", 'html_type' => "Text", - )); + ]); $customFieldId = $customFieldResult['id']; // Create a contact with an email greeting format that includes the new custom field. - $contactResult = $this->callAPISuccess('Contact', 'create', array( + $contactResult = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com', 'email_greeting_id' => "Customized", 'email_greeting_custom' => "Dear {contact.custom_{$customFieldId}}", - )); + ]); $cid = $contactResult['id']; // Define testing values. @@ -541,13 +541,13 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $testGreetingValue = "Dear $uniq"; // Update contact's custom field with CustomValue.create - $customValueResult = $this->callAPISuccess('CustomValue', 'create', array( + $customValueResult = $this->callAPISuccess('CustomValue', 'create', [ 'entity_id' => $cid, "custom_{$customFieldId}" => $uniq, 'entity_table' => "civicrm_contact", - )); + ]); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $cid, 'return' => 'email_greeting')); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $cid, 'return' => 'email_greeting']); $this->assertEquals($testGreetingValue, $contact['email_greeting_display']); } diff --git a/tests/phpunit/api/v3/DashboardContactTest.php b/tests/phpunit/api/v3/DashboardContactTest.php index 1d639a81e4..e3331587c5 100644 --- a/tests/phpunit/api/v3/DashboardContactTest.php +++ b/tests/phpunit/api/v3/DashboardContactTest.php @@ -45,27 +45,27 @@ class api_v3_DashboardContactTest extends CiviUnitTestCase { } public function testDashboardContactCreate() { - $dashParams = array( + $dashParams = [ 'version' => 3, 'label' => 'New Dashlet element', 'name' => 'New Dashlet element', 'url' => 'civicrm/report/list&compid=99&reset=1', 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen', - ); + ]; $dashresult = $this->callAPISuccess('dashboard', 'create', $dashParams); - $contact = $this->callAPISuccess('contact', 'create', array( + $contact = $this->callAPISuccess('contact', 'create', [ 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', 'email' => 'abc@abc.com', - )); + ]); $oldCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}"); - $params = array( + $params = [ 'version' => 3, 'contact_id' => $contact['id'], 'dashboard_id' => $dashresult['id'], 'is_active' => 1, - ); + ]; $dashboradContact = $this->callAPISuccess('dashboard_contact', 'create', $params); $newCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}"); $this->assertEquals($oldCount + 1, $newCount); diff --git a/tests/phpunit/api/v3/DashboardTest.php b/tests/phpunit/api/v3/DashboardTest.php index e9f5169fa2..17546619bb 100644 --- a/tests/phpunit/api/v3/DashboardTest.php +++ b/tests/phpunit/api/v3/DashboardTest.php @@ -46,12 +46,12 @@ class api_v3_DashboardTest extends CiviUnitTestCase { public function testDashboardCreate() { $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard'); - $params = array( + $params = [ 'label' => 'New Dashlet element', 'name' => 'New Dashlet element', 'url' => 'civicrm/report/list&reset=1&compid=99', 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen', - ); + ]; $dashboard = $this->callAPISuccess('dashboard', 'create', $params); $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__); $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__); @@ -68,13 +68,13 @@ class api_v3_DashboardTest extends CiviUnitTestCase { */ public function testDashboardCreateByNonAdmins() { $loggedInContactID = $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); - $params = array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; + $params = [ 'label' => 'New Dashlet element', 'name' => 'New Dashlet element', 'url' => 'civicrm/report/list&reset=1&compid=99', 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen', - ); + ]; $dashboard = $this->callAPISuccess('dashboard', 'create', $params); $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__); $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__); @@ -89,13 +89,13 @@ class api_v3_DashboardTest extends CiviUnitTestCase { * Ensure that where is_active is specifically set to 0 is_active returns 0. */ public function testDashboardCreateNotActive() { - $params = array( + $params = [ 'label' => 'New Dashlet element', 'name' => 'New Dashlet element', 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5', 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen', 'is_active' => 0, - ); + ]; $dashboard = $this->callAPISuccess('dashboard', 'create', $params); $this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 0); } @@ -105,9 +105,9 @@ class api_v3_DashboardTest extends CiviUnitTestCase { * @param $oldCount */ public function DashboardDelete($id, $oldCount) { - $params = array( + $params = [ 'id' => $id, - ); + ]; $dashboardget = $this->callAPISuccess('dashboard', 'get', $params); $this->assertEquals($id, $dashboardget['id']); $dashboard = $this->callAPISuccess('dashboard', 'delete', $params); diff --git a/tests/phpunit/api/v3/DomainTest.php b/tests/phpunit/api/v3/DomainTest.php index 1088f176df..7e77774be9 100644 --- a/tests/phpunit/api/v3/DomainTest.php +++ b/tests/phpunit/api/v3/DomainTest.php @@ -56,34 +56,34 @@ class api_v3_DomainTest extends CiviUnitTestCase { $params['entity_id'] = 1; $params['entity_table'] = CRM_Core_BAO_Domain::getTableName(); $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); - $domContact = $this->callAPISuccess('contact', 'create', array( + $domContact = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Organization', 'organization_name' => 'new org', - 'api.phone.create' => array( + 'api.phone.create' => [ 'location_type_id' => $defaultLocationType->id, 'phone_type_id' => 1, 'phone' => '456-456', - ), - 'api.address.create' => array( + ], + 'api.address.create' => [ 'location_type_id' => $defaultLocationType->id, 'street_address' => '45 Penny Lane', - ), - 'api.email.create' => array( + ], + 'api.email.create' => [ 'location_type_id' => $defaultLocationType->id, 'email' => 'my@email.com', - ), - )); + ], + ]); - $this->callAPISuccess('domain', 'create', array( + $this->callAPISuccess('domain', 'create', [ 'id' => 1, 'contact_id' => $domContact['id'], - )); - $this->params = array( + ]); + $this->params = [ 'name' => 'A-team domain', 'description' => 'domain of chaos', 'domain_version' => '4.2', 'contact_id' => $domContact['id'], - ); + ]; } /** @@ -94,7 +94,7 @@ class api_v3_DomainTest extends CiviUnitTestCase { */ public function testGet() { - $params = array('sequential' => 1); + $params = ['sequential' => 1]; $result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__, __FILE__); $this->assertType('array', $result); @@ -107,10 +107,10 @@ class api_v3_DomainTest extends CiviUnitTestCase { $this->assertArrayHasKey('id', $domain); $this->assertArrayHasKey('name', $domain); $this->assertArrayHasKey('domain_email', $domain); - $this->assertEquals(array( + $this->assertEquals([ 'phone_type' => 'Phone', 'phone' => '456-456', - ), $domain['domain_phone']); + ], $domain['domain_phone']); $this->assertArrayHasKey('domain_address', $domain); } @@ -118,7 +118,7 @@ class api_v3_DomainTest extends CiviUnitTestCase { * Test get function with current domain. */ public function testGetCurrentDomain() { - $params = array('current_domain' => 1); + $params = ['current_domain' => 1]; $result = $this->callAPISuccess('domain', 'get', $params); $this->assertType('array', $result); @@ -153,15 +153,15 @@ class api_v3_DomainTest extends CiviUnitTestCase { */ public function testGetCurrentDomainTwice($version) { $this->_apiversion = $version; - $domain = $this->callAPISuccess('domain', 'getvalue', array( + $domain = $this->callAPISuccess('domain', 'getvalue', [ 'current_domain' => 1, 'return' => 'name', - )); + ]); $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE)); - $domain = $this->callAPISuccess('domain', 'getvalue', array( + $domain = $this->callAPISuccess('domain', 'getvalue', [ 'current_domain' => 1, 'return' => 'name', - )); + ]); $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE)); } @@ -187,16 +187,16 @@ class api_v3_DomainTest extends CiviUnitTestCase { $this->_apiversion = $version; // First create a domain. $domain_result = $this->callAPISuccess('domain', 'create', $this->params); - $domain_before = $this->callAPISuccess('Domain', 'getsingle', array('id' => $domain_result['id'])); + $domain_before = $this->callAPISuccess('Domain', 'getsingle', ['id' => $domain_result['id']]); // Change domain name. - $this->callAPISuccess('Domain', 'create', array( + $this->callAPISuccess('Domain', 'create', [ 'id' => $domain_result['id'], 'name' => 'B-Team domain', - )); + ]); // Get domain again. - $domain_after = $this->callAPISuccess('Domain', 'getsingle', array('id' => $domain_result['id'])); + $domain_after = $this->callAPISuccess('Domain', 'getsingle', ['id' => $domain_result['id']]); // Version should still be the same. $this->assertEquals($domain_before['version'], $domain_after['version']); @@ -225,7 +225,7 @@ class api_v3_DomainTest extends CiviUnitTestCase { */ public function testCreateWithEmptyParams($version) { $this->_apiversion = $version; - $this->callAPIFailure('domain', 'create', array()); + $this->callAPIFailure('domain', 'create', []); } } diff --git a/tests/phpunit/api/v3/EmailTest.php b/tests/phpunit/api/v3/EmailTest.php index 3f7719172c..dde6232582 100644 --- a/tests/phpunit/api/v3/EmailTest.php +++ b/tests/phpunit/api/v3/EmailTest.php @@ -42,20 +42,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,16 +66,16 @@ 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']]); } /** @@ -91,7 +91,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { unset($params['location_type_id']); $result = $this->callAPIAndDocument('email', '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'])); + $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]); } /** @@ -108,10 +108,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 ); } @@ -124,10 +124,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); } @@ -137,7 +137,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']); } @@ -151,11 +151,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']]); } /** @@ -164,28 +164,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__); } @@ -196,93 +196,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__); } @@ -294,87 +294,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__); } @@ -385,23 +385,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']); @@ -409,23 +409,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']); @@ -434,13 +434,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']); @@ -450,21 +450,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']]); } } diff --git a/tests/phpunit/api/v3/EntityBatchTest.php b/tests/phpunit/api/v3/EntityBatchTest.php index 3047f957c0..0ac788a7f3 100644 --- a/tests/phpunit/api/v3/EntityBatchTest.php +++ b/tests/phpunit/api/v3/EntityBatchTest.php @@ -44,16 +44,16 @@ class api_v3_EntityBatchTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); - $entityParams = array('contact_id' => 1); + $entityParams = ['contact_id' => 1]; $this->_entity = 'EntityBatch'; $this->_entityID = $this->contributionCreate($entityParams); $this->_batchID = $this->batchCreate(); - $this->params = array( + $this->params = [ 'entity_id' => $this->_entityID, 'batch_id' => $this->_batchID, 'entity_table' => 'civicrm_financial_trxn', - ); + ]; } public function testCreateEntityBatch() { @@ -68,14 +68,14 @@ class api_v3_EntityBatchTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } public function testDeleteEntityBatch() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); + $deleteParams = ['id' => $result['id']]; $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/EntityJoinTest.php b/tests/phpunit/api/v3/EntityJoinTest.php index 5e2173b033..bb217eafb2 100644 --- a/tests/phpunit/api/v3/EntityJoinTest.php +++ b/tests/phpunit/api/v3/EntityJoinTest.php @@ -41,14 +41,14 @@ class api_v3_EntityJoinTest extends CiviUnitTestCase { public function testJoinEmailToContact() { $first = 'firstthisisatest'; $last = 'lastthisisatest'; - $org = $this->organizationCreate(array('organization_name' => 'Employer of one')); - $person1 = $this->individualCreate(array('employer_id' => $org, 'first_name' => $first, 'last_name' => $last, 'gender_id' => 1)); - $person2 = $this->individualCreate(array(), 1); - $result = $this->callAPISuccessGetSingle('Email', array( + $org = $this->organizationCreate(['organization_name' => 'Employer of one']); + $person1 = $this->individualCreate(['employer_id' => $org, 'first_name' => $first, 'last_name' => $last, 'gender_id' => 1]); + $person2 = $this->individualCreate([], 1); + $result = $this->callAPISuccessGetSingle('Email', [ 'return' => 'contact_id.employer_id.display_name,contact_id.gender_id.label', 'contact_id.last_name' => $last, 'contact_id.first_name' => $first, - )); + ]); $this->assertEquals('Employer of one', $result['contact_id.employer_id.display_name']); $this->assertEquals('Female', $result['contact_id.gender_id.label']); } diff --git a/tests/phpunit/api/v3/EntityTagACLTest.php b/tests/phpunit/api/v3/EntityTagACLTest.php index 1102a3ef8e..6e1206f2f9 100644 --- a/tests/phpunit/api/v3/EntityTagACLTest.php +++ b/tests/phpunit/api/v3/EntityTagACLTest.php @@ -66,24 +66,24 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { parent::setUp(); $individualID = $this->individualCreate(); $daoObj = new CRM_Core_DAO(); - $this->callAPISuccess('Attachment', 'create', array( + $this->callAPISuccess('Attachment', 'create', [ 'entity_table' => 'civicrm_contact', 'entity_id' => $individualID, 'mime_type' => 'k', 'name' => 'p', 'content' => 'l', - )); - $daoObj->createTestObject('CRM_Activity_BAO_Activity', array(), 1, 0); - $daoObj->createTestObject('CRM_Case_BAO_Case', array(), 1, 0); + ]); + $daoObj->createTestObject('CRM_Activity_BAO_Activity', [], 1, 0); + $daoObj->createTestObject('CRM_Case_BAO_Case', [], 1, 0); $entities = $this->getTagOptions(); foreach ($entities as $key => $entity) { - $this->callAPISuccess('Tag', 'create', array( + $this->callAPISuccess('Tag', 'create', [ 'used_for' => $key, 'name' => $entity, 'description' => $entity, - )); + ]); } - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; } /** @@ -92,7 +92,7 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { * @return array */ public function getTagOptions() { - $options = $this->callAPISuccess('Tag', 'getoptions', array('field' => 'used_for')); + $options = $this->callAPISuccess('Tag', 'getoptions', ['field' => 'used_for']); return $options['values']; } @@ -112,9 +112,9 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { * Get entities which can be tagged in data provider format. */ public function taggableEntities() { - $return = array(); + $return = []; foreach ($this->getTagOptions() as $entity) { - $return[] = array($entity); + $return[] = [$entity]; } return $return; } @@ -132,17 +132,17 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { */ public function testThatForEntitiesEditAllContactsCanAddTags($entity) { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts', 'access CiviCRM'); - $this->callAPISuccess('EntityTag', 'create', array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts', 'access CiviCRM']; + $this->callAPISuccess('EntityTag', 'create', [ 'entity_id' => 1, 'tag_id' => $entity, 'check_permissions' => TRUE, 'entity_table' => $this->getTableForTag($entity), - )); - $this->callAPISuccessGetCount('EntityTag', array( + ]); + $this->callAPISuccessGetCount('EntityTag', [ 'entity_id' => 1, 'entity_table' => $this->getTableForTag($entity), - ), 1); + ], 1); } /** @@ -152,13 +152,13 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { */ public function testThatForEntityWithoutACLOrEditAllThereIsNoAccess($entity) { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view all contacts'); - $this->callAPIFailure('EntityTag', 'create', array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts']; + $this->callAPIFailure('EntityTag', 'create', [ 'entity_id' => 1, 'tag_id' => $entity, 'check_permissions' => TRUE, 'entity_table' => $this->getTableForTag($entity), - )); + ]); } /** @@ -171,19 +171,19 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { */ public function testCheckPermissionsOffWorks($entity) { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view all contacts'); - $result = $this->callAPISuccess('EntityTag', 'create', array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts']; + $result = $this->callAPISuccess('EntityTag', 'create', [ 'entity_id' => 1, 'tag_id' => $entity, 'check_permissions' => 0, 'entity_table' => $this->getTableForTag($entity), - )); + ]); $this->assertEquals(1, $result['added']); - $this->callAPISuccessGetCount('EntityTag', array( + $this->callAPISuccessGetCount('EntityTag', [ 'entity_id' => 1, 'entity_table' => $this->getTableForTag($entity), 'check_permissions' => 0, - ), 1); + ], 1); } /** @@ -199,19 +199,19 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { */ public function testThatForEntitiesACLApplies($entity) { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view all contacts'); - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults')); - civicrm_api('EntityTag', 'create', array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts']; + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookAllResults']); + civicrm_api('EntityTag', 'create', [ 'version' => 3, 'entity_id' => 1, 'tag_id' => $entity, 'entity_table' => $this->getTableForTag($entity), 'check_permissions' => TRUE, - )); - $this->callAPISuccessGetCount('EntityTag', array( + ]); + $this->callAPISuccessGetCount('EntityTag', [ 'entity_id' => 1, 'entity_table' => $this->getTableForTag($entity), - ), ($entity == 'Contacts' ? 1 : 0)); + ], ($entity == 'Contacts' ? 1 : 0)); } } diff --git a/tests/phpunit/api/v3/EntityTagTest.php b/tests/phpunit/api/v3/EntityTagTest.php index 5bc3fa32af..73cc77fa3c 100644 --- a/tests/phpunit/api/v3/EntityTagTest.php +++ b/tests/phpunit/api/v3/EntityTagTest.php @@ -54,7 +54,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { * * @var array */ - protected $_params = array(); + protected $_params = []; /** * Set up for test. @@ -64,14 +64,14 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $this->useTransaction(TRUE); $this->_individualID = $this->individualCreate(); - $this->_tag = $this->tagCreate(array('name' => 'EntityTagTest')); + $this->_tag = $this->tagCreate(['name' => 'EntityTagTest']); $this->_tagID = $this->_tag['id']; $this->_householdID = $this->houseHoldCreate(); $this->_organizationID = $this->organizationCreate(); - $this->_params = array( + $this->_params = [ 'entity_id' => $this->_individualID, 'tag_id' => $this->_tagID, - ); + ]; } /** @@ -80,10 +80,10 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { * These failure tests are low value and may not be worth putting in v4. */ public function testFailureTests() { - $this->callAPIFailure('entity_tag', 'create', array('contact_id' => $this->_individualID), + $this->callAPIFailure('entity_tag', 'create', ['contact_id' => $this->_individualID], 'tag_id is a required field' ); - $this->callAPIFailure('entity_tag', 'create', array('tag_id' => $this->_tagID), + $this->callAPIFailure('entity_tag', 'create', ['tag_id' => $this->_tagID], 'contact_id is a required field' ); } @@ -108,11 +108,11 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $result = $this->callAPISuccess('entity_tag', 'create', $this->_params); $this->assertEquals($result['added'], 1); - $params = array( + $params = [ 'contact_id_i' => $this->_individualID, 'contact_id_o' => $this->_organizationID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($result['added'], 1); @@ -124,7 +124,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { */ public function testGetNoEntityID() { $this->callAPISuccess('entity_tag', 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $this->_tagID)); + $result = $this->callAPISuccess($this->_entity, 'get', ['sequential' => 1, 'tag_id' => $this->_tagID]); $this->assertEquals($this->_individualID, $result['values'][0]['entity_id']); } @@ -137,9 +137,9 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $this->_apiversion = $version; $individualEntity = $this->callAPISuccess('entity_tag', 'create', $this->_params); - $paramsEntity = array( + $paramsEntity = [ 'contact_id' => $this->_individualID, - ); + ]; $result = $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertEquals($this->_tagID, $result['values'][$result['id']]['tag_id']); @@ -162,10 +162,10 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { * Test tag can be added to a household. */ public function testHouseholdEntityCreate() { - $params = array( + $params = [ 'contact_id' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($householdEntity['added'], 1); @@ -179,14 +179,14 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { public function testOrganizationEntityGet($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'entity_id' => $this->_organizationID, 'tag_id' => $this->_tagID, - ); + ]; $this->callAPISuccess('entity_tag', 'create', $params); - $tag = $this->callAPISuccess('entity_tag', 'getsingle', array('contact_id' => $this->_organizationID)); + $tag = $this->callAPISuccess('entity_tag', 'getsingle', ['contact_id' => $this->_organizationID]); $this->assertEquals($this->_organizationID, $tag['entity_id']); $this->assertEquals($this->_tagID, $tag['tag_id']); } @@ -195,17 +195,17 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { * Civicrm_entity_tag_Delete methods. */ public function testEntityTagDeleteNoTagId() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'delete', $params); @@ -215,18 +215,18 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { } public function testEntityTagDeleteINDHH() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'delete', $params); @@ -234,35 +234,35 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { } public function testEntityTagDeleteHH() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['removed'], 1); } public function testEntityTagDeleteHHORG() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_h' => $this->_householdID, 'contact_id_o' => $this->_organizationID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 1); @@ -270,53 +270,53 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { } public function testEntityTagCommonDeleteINDHH() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 2); } public function testEntityTagCommonDeleteHH() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 1); } public function testEntityTagCommonDeleteHHORG() { - $entityTagParams = array( + $entityTagParams = [ 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, - ); + ]; $this->entityTagAdd($entityTagParams); - $params = array( + $params = [ 'contact_id_h' => $this->_householdID, 'contact_id_o' => $this->_organizationID, 'tag_id' => $this->_tagID, - ); + ]; $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 1); @@ -324,28 +324,28 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { } public function testEntityTagJoin() { - $org = $this->callAPISuccess('Contact', 'create', array( + $org = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Organization', 'organization_name' => 'Org123', - 'api.EntityTag.create' => array( + 'api.EntityTag.create' => [ 'tag_id' => $this->_tagID, - ), - )); + ], + ]); // Fetch contact info via join - $result = $this->callAPISuccessGetSingle('EntityTag', array( - 'return' => array("entity_id.organization_name", "tag_id.name"), + $result = $this->callAPISuccessGetSingle('EntityTag', [ + 'return' => ["entity_id.organization_name", "tag_id.name"], 'entity_id' => $org['id'], 'entity_table' => "civicrm_contact", - )); + ]); $this->assertEquals('Org123', $result['entity_id.organization_name']); $this->assertEquals('EntityTagTest', $result['tag_id.name']); // This should return no results by restricting contact_type - $result = $this->callAPISuccess('EntityTag', 'get', array( - 'return' => array("entity_id.organization_name"), + $result = $this->callAPISuccess('EntityTag', 'get', [ + 'return' => ["entity_id.organization_name"], 'entity_id' => $org['id'], 'entity_table' => "civicrm_contact", 'entity_id.contact_type' => "Individual", - )); + ]); $this->assertEquals(0, $result['count']); } diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index fa81e015f1..5422b5223c 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -38,8 +38,8 @@ class api_v3_EventTest extends CiviUnitTestCase { parent::setUp(); $this->_apiversion = 3; $this->_entity = 'event'; - $this->_params = array( - array( + $this->_params = [ + [ 'title' => 'Annual CiviCRM meet', 'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now', 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', @@ -55,8 +55,8 @@ class api_v3_EventTest extends CiviUnitTestCase { 'is_monetary' => 0, 'is_active' => 1, 'is_show_location' => 0, - ), - array( + ], + [ 'title' => 'Annual CiviCRM meet 2', 'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now', 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', @@ -72,24 +72,24 @@ class api_v3_EventTest extends CiviUnitTestCase { 'is_monetory' => 0, 'is_active' => 1, 'is_show_location' => 0, - ), - ); + ], + ]; - $params = array( - array( + $params = [ + [ 'title' => 'Annual CiviCRM meet', 'event_type_id' => 1, 'start_date' => 20081021, - ), - array( + ], + [ 'title' => 'Annual CiviCRM meet 2', 'event_type_id' => 1, 'start_date' => 20101021, - ), - ); + ], + ]; - $this->events = array(); - $this->eventIds = array(); + $this->events = []; + $this->eventIds = []; foreach ($params as $event) { $result = $this->callAPISuccess('Event', 'Create', $event); $this->_events[] = $result; @@ -101,10 +101,10 @@ class api_v3_EventTest extends CiviUnitTestCase { foreach ($this->eventIds as $eventId) { $this->eventDelete($eventId); } - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_participant', 'civicrm_event', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); } @@ -112,9 +112,9 @@ class api_v3_EventTest extends CiviUnitTestCase { * civicrm_event_get methods. */ public function testGetEventById() { - $params = array( + $params = [ 'id' => $this->_events[1]['id'], - ); + ]; $result = $this->callAPISuccess('event', 'get', $params); $this->assertEquals($result['values'][$this->_eventIds[1]]['event_title'], 'Annual CiviCRM meet 2'); } @@ -123,34 +123,34 @@ class api_v3_EventTest extends CiviUnitTestCase { * Test getLocationEvents() function invokes selectWhereClause() hook */ public function testGetEventWithPermissionHook() { - $address = $this->callAPISuccess('address', 'create', array( + $address = $this->callAPISuccess('address', 'create', [ 'contact_id' => 'null', 'location_type_id' => 1, 'street_address' => '1234567', - )); - $params = array( + ]); + $params = [ 'address_id' => $address['id'], - ); + ]; $result = $this->callAPISuccess('loc_block', 'create', $params); - $params = array( + $params = [ 'id' => $this->_events[1]['id'], 'loc_block_id' => $result['id'], - ); + ]; $this->callAPISuccess('Event', 'create', $params); $result = CRM_Event_BAO_Event::getLocationEvents(); $this->assertEquals(1, count($result)); - $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'selectWhereClauseHook')); + $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'selectWhereClauseHook']); $result = CRM_Event_BAO_Event::getLocationEvents(); $this->assertEquals(0, count($result)); } public function testGetEventByEventTitle() { - $params = array( + $params = [ 'event_title' => 'Annual CiviCRM meet', 'sequential' => TRUE, - ); + ]; $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); @@ -163,9 +163,9 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testGetEventByWrongTitle($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'title' => 'No event with that title', - ); + ]; $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertEquals(0, $result['count']); } @@ -174,28 +174,28 @@ class api_v3_EventTest extends CiviUnitTestCase { * Skip api4 - this api uses deprecated query syntax */ public function testGetEventByIdSort() { - $params = array( + $params = [ 'return.sort' => 'id ASC', 'return.max_results' => 1, - ); + ]; $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertEquals(1, $result['id'], ' in line ' . __LINE__); - $params = array( - 'options' => array( + $params = [ + 'options' => [ 'sort' => 'id DESC', 'limit' => 1, - ), - ); + ], + ]; $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertAPISuccess($result, ' in line ' . __LINE__); $this->assertEquals(2, $result['id'], ' in line ' . __LINE__); - $params = array( - 'options' => array( + $params = [ + 'options' => [ 'sort' => 'id ASC', 'limit' => 1, - ), - ); + ], + ]; $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertEquals(1, $result['id'], ' in line ' . __LINE__); @@ -221,20 +221,20 @@ class api_v3_EventTest extends CiviUnitTestCase { * FIXME: Api4 */ public function testGetIsCurrent() { - $params = array( + $params = [ 'isCurrent' => 1, - ); - $currentEventParams = array( + ]; + $currentEventParams = [ 'start_date' => date('Y-m-d', strtotime('+ 1 day')), 'end_date' => date('Y-m-d', strtotime('+ 1 week')), - ); + ]; $currentEventParams = array_merge($this->_params[1], $currentEventParams); $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams); $description = "Demonstrates use of is.Current option."; $subfile = "IsCurrentOption"; $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $allEvents = $this->callAPISuccess('Event', 'Get', array()); - $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id'])); + $allEvents = $this->callAPISuccess('Event', 'Get', []); + $this->callAPISuccess('Event', 'Delete', ['id' => $currentEvent['id']]); $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__); $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__); $this->assertEquals($currentEvent['id'], $result['id'], ''); @@ -273,28 +273,28 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testGetSingleReturnIsFull() { $contactID = $this->individualCreate(); - $params = array( + $params = [ 'id' => $this->_eventIds[0], 'max_participants' => 1, - ); + ]; $result = $this->callAPISuccess('Event', 'Create', $params); - $getEventParams = array( + $getEventParams = [ 'id' => $this->_eventIds[0], 'return.is_full' => 1, - ); + ]; $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams); $description = "Demonstrates use of return is_full ."; $subfile = "IsFullOption"; $this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__); $this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__); - $participant = $this->callAPISuccess('Participant', 'create', array( + $participant = $this->callAPISuccess('Participant', 'create', [ 'participant_status' => 1, 'role_id' => 1, 'contact_id' => $contactID, 'event_id' => $this->_eventIds[0], - )); + ]); $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__); $this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__); @@ -308,16 +308,16 @@ class api_v3_EventTest extends CiviUnitTestCase { * We need to ensure this is supported as an alias for financial_type_id. */ public function testCreateGetEventLegacyContributionTypeID() { - $contributionTypeArray = array('contribution_type_id' => 3); + $contributionTypeArray = ['contribution_type_id' => 3]; if (isset($this->_params[0]['financial_type_id'])) { //in case someone edits $this->_params & invalidates this test :-) unset($this->_params[0]['financial_type_id']); } $result = $this->callAPISuccess('event', 'create', $this->_params[0] + $contributionTypeArray); - $getresult = $this->callAPISuccess('event', 'get', array() + $contributionTypeArray); + $getresult = $this->callAPISuccess('event', 'get', [] + $contributionTypeArray); $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3); $this->assertEquals($result['id'], $getresult['id']); - $this->callAPISuccess('event', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('event', 'delete', ['id' => $result['id']]); } /** @@ -330,27 +330,27 @@ class api_v3_EventTest extends CiviUnitTestCase { // create a loc block and an event for that loc block. $eventParams = $this->_params[0]; $eventParams['loc_bloc_id'] = '$value.id'; - $locBlockParams = array( - 'address' => array( + $locBlockParams = [ + 'address' => [ 'street_address' => 'Kipdorp 24', 'postal_code' => '2000', 'city' => 'Antwerpen', 'country_id' => '1020', 'location_type_id' => '1', - ), + ], 'api.Event.create' => $eventParams, 'sequential' => 1, - ); + ]; $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams); $locBlockId = $createResult['id']; $eventId = $createResult['values'][0]['api.Event.create']['id']; // request the event with its loc block: - $check = $this->callAPISuccess($this->_entity, 'getsingle', array( + $check = $this->callAPISuccess($this->_entity, 'getsingle', [ 'id' => $eventId, - 'api.LocBlock.get' => array('id' => '$value.loc_block_id'), + 'api.LocBlock.get' => ['id' => '$value.loc_block_id'], 'sequential' => 1, - )); + ]); // assert $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__); @@ -358,7 +358,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__); // cleanup - $this->callAPISuccess($this->_entity, 'delete', array('id' => $eventId)); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $eventId]); } /** @@ -371,14 +371,14 @@ class api_v3_EventTest extends CiviUnitTestCase { $params = $this->_params[0]; $result = $this->callAPISuccess($this->_entity, 'create', $params); - $check = $this->callAPISuccess($this->_entity, 'get', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'id' => $result['id'], // this chaining request should not break things: - 'api.LocBlock.get' => array('id' => '$value.loc_block_id'), - )); + 'api.LocBlock.get' => ['id' => '$value.loc_block_id'], + ]); $this->assertEquals($result['id'], $check['id']); - $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]); } /** @@ -399,15 +399,15 @@ class api_v3_EventTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); - $check = $this->callAPISuccess($this->_entity, 'get', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); - $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]); } /** @@ -424,9 +424,9 @@ class api_v3_EventTest extends CiviUnitTestCase { // Search for events having CRM-16036 as the value for this custom // field. This should not return anything. - $check = $this->callAPISuccess($this->_entity, 'get', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'custom_' . $ids['custom_field_id'] => 'CRM-16036', - )); + ]); $this->assertEquals(0, $check['count']); @@ -448,9 +448,9 @@ class api_v3_EventTest extends CiviUnitTestCase { // Search for events having NULL as the value for this custom // field. This should return all events created in setUp. - $check = $this->callAPISuccess($this->_entity, 'get', array( - 'custom_' . $ids['custom_field_id'] => array('IS NULL' => 1), - )); + $check = $this->callAPISuccess($this->_entity, 'get', [ + 'custom_' . $ids['custom_field_id'] => ['IS NULL' => 1], + ]); $this->assertGreaterThan(0, $check['count']); @@ -467,11 +467,11 @@ class api_v3_EventTest extends CiviUnitTestCase { public function testEventGetCustomContactRefFieldCRM16036() { // Create some contact. $test_contact_name = 'Contact, Test'; - $contact_save_result = $this->callAPISuccess('contact', 'create', array( + $contact_save_result = $this->callAPISuccess('contact', 'create', [ 'sort_name' => $test_contact_name, 'contact_type' => 'Individual', 'display_name' => $test_contact_name, - )); + ]); $contact_id = $contact_save_result['id']; // I have no clue what this $subfile is about. I just copied it from another @@ -481,7 +481,7 @@ class api_v3_EventTest extends CiviUnitTestCase { // Create a custom group, and add a custom contact reference field. $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); - $params = array( + $params = [ 'custom_group_id' => $ids['custom_group_id'], 'name' => 'Worker_Lookup', 'label' => 'Worker Lookup', @@ -490,7 +490,7 @@ class api_v3_EventTest extends CiviUnitTestCase { 'weight' => 4, 'is_searchable' => 1, 'is_active' => 1, - ); + ]; $customField = $this->callAPISuccess('custom_field', 'create', $params); // Create an event, and add the contact as custom value. @@ -504,10 +504,10 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); // Retrieve the activity, search for the contact. - $result = $this->callAPIAndDocument($this->_entity, 'get', array( + $result = $this->callAPIAndDocument($this->_entity, 'get', [ 'return.custom_' . $customField['id'] => 1, 'custom_' . $customField['id'] => $contact_id, - ), __FUNCTION__, __FILE__, $description, $subfile); + ], __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]); $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__); @@ -516,10 +516,10 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); - $this->callAPISuccess('contact', 'delete', array( + $this->callAPISuccess('contact', 'delete', [ 'id' => $contact_id, 'skip_undelete' => TRUE, - )); + ]); } /** @@ -545,15 +545,15 @@ class api_v3_EventTest extends CiviUnitTestCase { $save_result = $this->callApiSuccess($this->_entity, 'create', $params); // Retrieve the activity, search for custom field < 'BBBB' - $get_result = $this->callAPISuccess($this->_entity, 'get', array( + $get_result = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, - 'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'), - )); + 'custom_' . $ids['custom_field_id'] => ['<=' => 'BBBB'], + ]); // Expect that we find the saved event. $this->assertArrayKeyExists($save_result['id'], $get_result['values']); - $this->callAPISuccess($this->_entity, 'Delete', array('id' => $save_result['id'])); + $this->callAPISuccess($this->_entity, 'Delete', ['id' => $save_result['id']]); } /** @@ -582,19 +582,19 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', $params, __FUNCTION__, __FILE__); // Retrieve the activity, and chain loc block using $value. - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'custom_' . $custom_field_id => "12345", - 'api.LocBlock.get' => array("id" => '$value.loc_block_id'), - )); + 'api.LocBlock.get' => ["id" => '$value.loc_block_id'], + ]); $this->assertEquals(1, $result['count']); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); - $this->callAPISuccess('event', 'delete', array( + $this->callAPISuccess('event', 'delete', [ 'id' => $result['id'], 'skip_undelete' => TRUE, - )); + ]); } /** @@ -603,9 +603,9 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testCreatePaidEvent() { //@todo alter API so that an integer is converted to an array - $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1); + $priceSetParams = ['price_set_id' => (array) 1, 'is_monetary' => 1]; $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params[0], $priceSetParams)); - $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id')); + $event = $this->callAPISuccess('Event', 'getsingle', ['id' => $result['id'], 'return' => 'price_set_id']); $this->assertArrayKeyExists('price_set_id', $event); } @@ -615,7 +615,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testCreateEventEmptyParams($version) { $this->_apiversion = $version; - $params = array(); + $params = []; $result = $this->callAPIFailure('event', 'create', $params); } @@ -658,8 +658,8 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->_apiversion = $version; $result = $this->callAPIAndDocument('Event', 'Create', $this->_params[0], __FUNCTION__, __FILE__); $this->assertArrayHasKey('id', $result['values'][$result['id']]); - $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id'])); - $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'Get', ['id' => $result['id']]); + $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]); $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set'); $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set'); $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set'); @@ -678,8 +678,8 @@ class api_v3_EventTest extends CiviUnitTestCase { $result = $this->callAPISuccess('Event', 'Create', $this->_params[0]); $this->assertAPISuccess($result); $this->assertArrayHasKey('id', $result['values'][$result['id']]); - $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id'])); - $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'Get', ['id' => $result['id']]); + $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]); $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__); $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__); @@ -696,15 +696,15 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->_apiversion = $version; $result = $this->callAPISuccess('event', 'create', $this->_params[1]); - $params = array( + $params = [ 'id' => $result['id'], 'max_participants' => 150, - ); + ]; $this->callAPISuccess('Event', 'Create', $params); $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__, __FILE__); $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']); $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']); - $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]); } /** @@ -713,7 +713,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testDeleteEmptyParams($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('Event', 'Delete', array()); + $result = $this->callAPIFailure('Event', 'Delete', []); } /** @@ -722,9 +722,9 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testDelete($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'id' => $this->_eventIds[0], - ); + ]; $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__, __FILE__); } @@ -735,9 +735,9 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testDeleteWithEventId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'event_id' => $this->_eventIds[0], - ); + ]; $result = $this->callAPISuccess('Event', 'Delete', $params); $this->assertAPISuccess($result); } @@ -751,12 +751,12 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->_apiversion = $version; $contactID = $this->individualCreate(); $this->participantCreate( - array( + [ 'contactID' => $contactID, 'eventID' => $this->_eventIds[0], - ) + ] ); - $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0])); + $this->callAPISuccess('Event', 'Delete', ['id' => $this->_eventIds[0]]); } /** @@ -765,10 +765,10 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testDeleteWithWrongEventId($version) { $this->_apiversion = $version; - $params = array('event_id' => $this->_eventIds[0]); + $params = ['event_id' => $this->_eventIds[0]]; $result = $this->callAPISuccess('Event', 'Delete', $params); // try to delete again - there's no such event anymore - $params = array('event_id' => $this->_eventIds[0]); + $params = ['event_id' => $this->_eventIds[0]]; $result = $this->callAPIFailure('Event', 'Delete', $params); } @@ -792,9 +792,9 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->_apiversion = $version; $this->callAPISuccess('event', 'create', $this->_params[1]); - $getParams = array( + $getParams = [ 'sequential' => 1, - ); + ]; $result = $this->callAPISuccess('event', 'get', $getParams); $this->assertEquals($result['count'], 3); $res = $result['values'][0]; @@ -809,12 +809,12 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testSearch($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'event_type_id' => 1, 'return.title' => 1, 'return.id' => 1, 'return.start_date' => 1, - ); + ]; $result = $this->callAPISuccess('event', 'get', $params); $this->assertEquals($result['values'][$this->_eventIds[0]]['id'], $this->_eventIds[0]); @@ -830,24 +830,24 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testSearchWithOffsetAndMaxResults() { $maxEvents = 5; - $events = array(); + $events = []; while ($maxEvents > 0) { - $params = array( + $params = [ 'title' => 'Test Event' . $maxEvents, 'event_type_id' => 2, 'start_date' => 20081021, - ); + ]; $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params); $maxEvents--; } - $params = array( + $params = [ 'event_type_id' => 2, 'return.id' => 1, 'return.title' => 1, 'return.offset' => 2, 'return.max_results' => 2, - ); + ]; $result = $this->callAPISuccess('event', 'get', $params); $this->assertAPISuccess($result); $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__); @@ -859,21 +859,21 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testEventCreationPermissions($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'event_type_id' => 1, 'start_date' => '2010-10-03', 'title' => 'le cake is a tie', 'check_permissions' => TRUE, - ); + ]; $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array('access CiviCRM'); + $config->userPermissionClass->permissions = ['access CiviCRM']; $result = $this->callAPIFailure('event', 'create', $params, 'failed'); - $config->userPermissionClass->permissions = array( + $config->userPermissionClass->permissions = [ 'access CiviEvent', 'edit all events', 'access CiviCRM', - ); + ]; $result = $this->callAPISuccess('event', 'create', $params); } @@ -884,7 +884,7 @@ class api_v3_EventTest extends CiviUnitTestCase { public function testgetfields($version) { $this->_apiversion = $version; $description = "Demonstrate use of getfields to interrogate api."; - $params = array('action' => 'create'); + $params = ['action' => 'create']; $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals('is_active', $result['values']['is_active']['name']); } @@ -894,7 +894,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testgetfieldsRest() { $description = "Demonstrate use of getfields to interrogate api."; - $params = array('api_action' => 'create'); + $params = ['api_action' => 'create']; $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals(1, $result['values']['is_active']['api.default']); } @@ -904,7 +904,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testgetfieldsGet() { $description = "Demonstrate use of getfields to interrogate api."; - $params = array('action' => 'get'); + $params = ['action' => 'get']; $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals('title', $result['values']['event_title']['name']); } @@ -914,7 +914,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testgetfieldsDelete() { $description = "Demonstrate use of getfields to interrogate api."; - $params = array('action' => 'delete'); + $params = ['action' => 'delete']; $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals(1, $result['values']['id']['api.required']); } @@ -925,7 +925,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testCreateFromTemplate($version) { $this->_apiversion = $version; - $templateParams = array( + $templateParams = [ 'summary' => 'Sign up now to learn the results of this unit test', 'description' => 'This event is created from a template, so all the values should be the same as the original ones.', 'event_type_id' => 1, @@ -936,14 +936,14 @@ class api_v3_EventTest extends CiviUnitTestCase { 'registration_end_date' => '2018-06-25 17:00:00', 'max_participants' => 100, 'event_full_text' => 'Sorry! We are already full', - ); - $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') + $templateParams); - $eventResult = $this->callAPISuccess('Event', 'create', array( + ]; + $templateResult = $this->callAPISuccess('Event', 'create', ['is_template' => 1, 'template_title' => 'Test tpl'] + $templateParams); + $eventResult = $this->callAPISuccess('Event', 'create', [ 'template_id' => $templateResult['id'], 'title' => 'Clone1', 'start_date' => '2018-06-25 16:00:00', - )); - $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id'])); + ]); + $eventResult = $this->callAPISuccess('Event', 'getsingle', ['id' => $eventResult['id']]); foreach ($templateParams as $param => $value) { $this->assertEquals($value, $eventResult[$param]); } diff --git a/tests/phpunit/api/v3/ExtensionTest.php b/tests/phpunit/api/v3/ExtensionTest.php index e0480071ee..4a29929510 100644 --- a/tests/phpunit/api/v3/ExtensionTest.php +++ b/tests/phpunit/api/v3/ExtensionTest.php @@ -51,7 +51,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * Test getremote. */ public function testGetremote() { - $result = $this->callAPISuccess('extension', 'getremote', array()); + $result = $this->callAPISuccess('extension', 'getremote', []); $this->assertEquals('org.civicrm.module.cividiscount', $result['values'][0]['key']); $this->assertEquals('module', $result['values'][0]['type']); $this->assertEquals('CiviDiscount', $result['values'][0]['name']); @@ -62,7 +62,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * CRM-20532 */ public function testExtensionGetSingleExtension() { - $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest')); + $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest']); $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']); $this->assertEquals('module', $result['values'][$result['id']]['type']); $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']); @@ -73,7 +73,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * CRM-20532 */ public function testSingleExtensionGetWithReturnFields() { - $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest', 'return' => array('name', 'status', 'key'))); + $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest', 'return' => ['name', 'status', 'key']]); $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']); $this->assertFalse(isset($result['values'][$result['id']]['type'])); $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']); @@ -86,8 +86,8 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * CRM-20532 */ public function testExtensionGet() { - $result = $this->callAPISuccess('extension', 'get', array()); - $testExtensionResult = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.paymenttest')); + $result = $this->callAPISuccess('extension', 'get', []); + $testExtensionResult = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.paymenttest']); $this->assertNotNull($result['values'][$testExtensionResult['id']]['typeInfo']); $this->assertTrue($result['count'] >= 6); } @@ -96,24 +96,24 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * Filtering by status=installed or status=uninstalled should produce different results. */ public function testExtensionGetByStatus() { - $installed = $this->callAPISuccess('extension', 'get', array('status' => 'installed')); - $uninstalled = $this->callAPISuccess('extension', 'get', array('status' => 'uninstalled')); + $installed = $this->callAPISuccess('extension', 'get', ['status' => 'installed']); + $uninstalled = $this->callAPISuccess('extension', 'get', ['status' => 'uninstalled']); // If the filter works, then results should be strictly independent. $this->assertEquals( - array(), + [], array_intersect( CRM_Utils_Array::collect('key', $installed['values']), CRM_Utils_Array::collect('key', $uninstalled['values']) ) ); - $all = $this->callAPISuccess('extension', 'get', array()); + $all = $this->callAPISuccess('extension', 'get', []); $this->assertEquals($all['count'], $installed['count'] + $uninstalled['count']); } public function testGetMultipleExtensions() { - $result = $this->callAPISuccess('extension', 'get', array('key' => array('test.extension.manager.paymenttest', 'test.extension.manager.moduletest'))); + $result = $this->callAPISuccess('extension', 'get', ['key' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]); $this->assertEquals(2, $result['count']); } @@ -121,7 +121,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * Test that extension get works with api request with parameter full_name as build by api explorer. */ public function testGetMultipleExtensionsApiExplorer() { - $result = $this->callAPISuccess('extension', 'get', array('full_name' => array('test.extension.manager.paymenttest', 'test.extension.manager.moduletest'))); + $result = $this->callAPISuccess('extension', 'get', ['full_name' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]); $this->assertEquals(2, $result['count']); } @@ -129,7 +129,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { * Test that extension get can be filtered by id. */ public function testGetExtensionByID() { - $result = $this->callAPISuccess('extension', 'get', array('id' => 2, 'return' => array('label'))); + $result = $this->callAPISuccess('extension', 'get', ['id' => 2, 'return' => ['label']]); $this->assertEquals(1, $result['count']); } diff --git a/tests/phpunit/api/v3/FinancialTypeACLTest.php b/tests/phpunit/api/v3/FinancialTypeACLTest.php index 7c288f7b74..2df88052c9 100644 --- a/tests/phpunit/api/v3/FinancialTypeACLTest.php +++ b/tests/phpunit/api/v3/FinancialTypeACLTest.php @@ -42,15 +42,15 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { protected $_entity = 'Contribution'; public $debug = 0; protected $_params; - protected $_ids = array(); - protected $_pageParams = array(); + protected $_ids = []; + protected $_pageParams = []; /** * Parameters to create payment processor. * * @var array */ - protected $_processorParams = array(); + protected $_processorParams = []; /** * ID of created event. @@ -67,7 +67,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $this->_apiversion = 3; $this->_individualId = $this->individualCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -77,8 +77,8 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { 'net_amount' => 95.00, 'source' => 'SSF', 'contribution_status_id' => 1, - ); - $this->_processorParams = array( + ]; + $this->_processorParams = [ 'domain_id' => 1, 'name' => 'Dummy', 'payment_processor_type_id' => 10, @@ -88,8 +88,8 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { 'url_site' => 'http://dummy.com', 'url_recur' => 'http://dummy.com', 'billing_mode' => 1, - ); - $this->_pageParams = array( + ]; + $this->_pageParams = [ 'title' => 'Test Contribution Page', 'financial_type_id' => 1, 'currency' => 'USD', @@ -99,7 +99,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { 'is_allow_other_amount' => 1, 'min_amount' => 10, 'max_amount' => 1000, - ); + ]; } /** @@ -109,7 +109,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_uf_match')); + $this->quickCleanup(['civicrm_uf_match']); $this->disableFinancialACLs(); parent::tearDown(); } @@ -119,7 +119,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { */ public function testCreateACLContribution() { $this->enableFinancialACLs(); - $p = array( + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', 'total_amount' => 100.00, @@ -132,7 +132,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'check_permissions' => TRUE, - ); + ]; $this->setPermissions([ 'access CiviCRM', @@ -145,9 +145,9 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('contribution', 'create', $p); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], - ); + ]; $this->setPermissions([ 'access CiviCRM', @@ -170,9 +170,9 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910); $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF'); $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed'); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution['id'], - )); + ]); } /** @@ -190,10 +190,10 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['financial_type_id' => 'Member Dues'])); - $params = array( + $params = [ 'id' => $contribution['id'], 'check_permissions' => TRUE, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'get', $params); $this->assertEquals($contribution['count'], 0); @@ -208,7 +208,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { */ public function testCreateACLContributionChainedLineItems() { $this->enableFinancialACLs(); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -220,23 +220,23 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'check_permissions' => TRUE, - 'api.line_item.create' => array( - array( + 'api.line_item.create' => [ + [ 'price_field_id' => 1, 'qty' => 2, 'line_total' => '20', 'unit_price' => '10', 'financial_type_id' => 1, - ), - array( + ], + [ 'price_field_id' => 1, 'qty' => 1, 'line_total' => '80', 'unit_price' => '80', 'financial_type_id' => 2, - ), - ), - ); + ], + ], + ]; $this->setPermissions([ 'access CiviCRM', @@ -249,7 +249,7 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $this->callAPIFailure('contribution', 'create', $params, 'Error in call to LineItem_create : You do not have permission to create this line item'); // Check that the entire contribution has rolled back. - $contribution = $this->callAPISuccess('contribution', 'get', array()); + $contribution = $this->callAPISuccess('contribution', 'get', []); $this->assertEquals(0, $contribution['count']); $this->addFinancialAclPermissions([ @@ -260,10 +260,10 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { ]); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $lineItemParams = array( + $lineItemParams = [ 'contribution_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', - ); + ]; $lineItems = $this->callAPISuccess('LineItem', 'get', $lineItemParams); $this->assertEquals(3, $lineItems['count']); $this->assertEquals(100.00, $lineItems['values'][3]['line_total']); @@ -273,9 +273,9 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $this->assertEquals(1, $lineItems['values'][4]['financial_type_id']); $this->assertEquals(2, $lineItems['values'][5]['financial_type_id']); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution['id'], - )); + ]); } /** @@ -285,11 +285,11 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { $this->enableFinancialACLs(); $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); - $params = array( + $params = [ 'id' => $contribution['id'], 'check_permissions' => TRUE, 'total_amount' => 200.00, - ); + ]; $this->setPermissions([ 'access CiviCRM', @@ -319,10 +319,10 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase { ]); $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], 'check_permissions' => TRUE, - ); + ]; $this->addPermissions(['delete in CiviContribute']); $this->callAPIFailure('Contribution', 'delete', $params); diff --git a/tests/phpunit/api/v3/GrantTest.php b/tests/phpunit/api/v3/GrantTest.php index 9de285880b..0a5463cc23 100644 --- a/tests/phpunit/api/v3/GrantTest.php +++ b/tests/phpunit/api/v3/GrantTest.php @@ -35,7 +35,7 @@ class api_v3_GrantTest extends CiviUnitTestCase { protected $_apiversion = 3; protected $params; - protected $ids = array(); + protected $ids = []; protected $_entity = 'Grant'; public $DBResetRequired = FALSE; @@ -43,7 +43,7 @@ class api_v3_GrantTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->ids['contact'][0] = $this->individualCreate(); - $this->params = array( + $this->params = [ 'contact_id' => $this->ids['contact'][0], 'application_received_date' => 'now', 'decision_date' => 'next Monday', @@ -52,7 +52,7 @@ class api_v3_GrantTest extends CiviUnitTestCase { 'rationale' => 'Just Because', 'currency' => 'USD', 'grant_type_id' => 1, - ); + ]; } /** @@ -63,7 +63,7 @@ class api_v3_GrantTest extends CiviUnitTestCase { public function tearDown() { foreach ($this->ids as $entity => $entities) { foreach ($entities as $id) { - $this->callAPISuccess($entity, 'delete', array('id' => $id)); + $this->callAPISuccess($entity, 'delete', ['id' => $id]); } } $this->quickCleanup(['civicrm_grant']); @@ -83,20 +83,20 @@ class api_v3_GrantTest extends CiviUnitTestCase { * We want to ensure they are saved with separators as appropriate */ public function testCreateCustomCheckboxGrant() { - $ids = array(); - $result = $this->customGroupCreate(array('extends' => 'Grant')); + $ids = []; + $result = $this->customGroupCreate(['extends' => 'Grant']); $ids['custom_group_id'] = $result['id']; $customTable = $result['values'][$result['id']]['table_name']; - $result = $this->customFieldCreate(array( + $result = $this->customFieldCreate([ 'html_type' => 'CheckBox', 'custom_group_id' => $ids['custom_group_id'], - 'option_values' => array( - array('label' => 'my valley', 'value' => 'valley', 'is_active' => TRUE, 'weight' => 1), - array('label' => 'my goat', 'value' => 'goat', 'is_active' => TRUE, 'weight' => 2), - array('label' => 'mohair', 'value' => 'wool', 'is_active' => TRUE, 'weight' => 3), - array('label' => 'hungry', 'value' => '', 'is_active' => TRUE, 'weight' => 3), - ), - )); + 'option_values' => [ + ['label' => 'my valley', 'value' => 'valley', 'is_active' => TRUE, 'weight' => 1], + ['label' => 'my goat', 'value' => 'goat', 'is_active' => TRUE, 'weight' => 2], + ['label' => 'mohair', 'value' => 'wool', 'is_active' => TRUE, 'weight' => 3], + ['label' => 'hungry', 'value' => '', 'is_active' => TRUE, 'weight' => 3], + ], + ]); $columnName = $result['values'][$result['id']]['column_name']; $ids['custom_field_id'] = $result['id']; $customFieldLabel = 'custom_' . $ids['custom_field_id']; @@ -124,7 +124,7 @@ class api_v3_GrantTest extends CiviUnitTestCase { $this->assertEquals($expectedValue, $savedValue); //& an array for good measure - $this->params[$customFieldLabel] = array('valley', 'goat'); + $this->params[$customFieldLabel] = ['valley', 'goat']; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); $savedValue = CRM_Core_DAO::singleValueQuery("SELECT {$columnName} FROM $customTable WHERE entity_id = {$result['id']}"); $this->assertEquals($expectedValue, $savedValue); @@ -136,16 +136,16 @@ class api_v3_GrantTest extends CiviUnitTestCase { public function testGetGrant() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); $this->ids['grant'][0] = $result['id']; - $result = $this->callAPIAndDocument($this->_entity, 'get', array('rationale' => 'Just Because'), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'get', ['rationale' => 'Just Because'], __FUNCTION__, __FILE__); $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); $this->assertEquals(1, $result['count']); } public function testDeleteGrant() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $result = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'delete', ['id' => $result['id']], __FUNCTION__, __FILE__); $this->assertAPISuccess($result); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } @@ -153,22 +153,22 @@ class api_v3_GrantTest extends CiviUnitTestCase { * Test Grant status with `0` value. */ public function testGrantWithZeroStatus() { - $params = array( + $params = [ 'action' => 'create', 'grant_type_id' => "Emergency", 'amount_total' => 100, 'contact_id' => "1", 'status_id' => 0, 'id' => 1, - ); + ]; $validation = $this->callAPISuccess('Grant', 'validate', $params); - $expectedOut = array( - 'status_id' => array( + $expectedOut = [ + 'status_id' => [ 'message' => "'0' is not a valid option for field status_id", 'code' => "incorrect_value", - ), - ); + ], + ]; $this->assertEquals($validation['values'][0], $expectedOut); } diff --git a/tests/phpunit/api/v3/GroupContactTest.php b/tests/phpunit/api/v3/GroupContactTest.php index e4f1775a6d..e235031ded 100644 --- a/tests/phpunit/api/v3/GroupContactTest.php +++ b/tests/phpunit/api/v3/GroupContactTest.php @@ -58,41 +58,41 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { $this->_groupId1 = $this->groupCreate(); - $this->callAPISuccess('group_contact', 'create', array( + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $this->_contactId, 'group_id' => $this->_groupId1, - )); + ]); - $this->_groupId2 = $this->groupCreate(array( + $this->_groupId2 = $this->groupCreate([ 'name' => 'Test Group 2', 'domain_id' => 1, 'title' => 'New Test Group2 Created', 'description' => 'New Test Group2 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only', - )); + ]); - $this->_group = array( - $this->_groupId1 => array( + $this->_group = [ + $this->_groupId1 => [ 'title' => 'New Test Group Created', 'visibility' => 'Public Pages', 'in_method' => 'API', - ), - $this->_groupId2 => array( + ], + $this->_groupId2 => [ 'title' => 'New Test Group2 Created', 'visibility' => 'User and User Admin Only', 'in_method' => 'API', - ), - ); + ], + ]; } /** * Test GroupContact.get by ID. */ public function testGet() { - $params = array( + $params = [ 'contact_id' => $this->_contactId, - ); + ]; $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__); foreach ($result['values'] as $v) { $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']); @@ -104,11 +104,11 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { public function testGetGroupID() { $description = "Get all from group and display contacts."; $subfile = "GetWithGroupID"; - $params = array( + $params = [ 'group_id' => $this->_groupId1, 'api.group.get' => 1, 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); foreach ($result['values'][0]['api.group.get']['values'] as $values) { $key = $values['id']; @@ -118,7 +118,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { } public function testCreateWithEmptyParams() { - $params = array(); + $params = []; $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id, contact_id' @@ -126,24 +126,24 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { } public function testCreateWithoutGroupIdParams() { - $params = array( + $params = [ 'contact_id' => $this->_contactId, - ); + ]; $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); } public function testCreateWithoutContactIdParams() { - $params = array( + $params = [ 'group_id' => $this->_groupId1, - ); + ]; $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); } public function testCreate() { - $cont = array( + $cont = [ 'first_name' => 'Amiteshwar', 'middle_name' => 'L.', 'last_name' => 'Prasad', @@ -151,14 +151,14 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { 'suffix_id' => 3, 'email' => 'amiteshwar.prasad@civicrm.org', 'contact_type' => 'Individual', - ); + ]; $this->_contactId1 = $this->individualCreate($cont); - $params = array( + $params = [ 'contact_id' => $this->_contactId, 'contact_id.2' => $this->_contactId1, 'group_id' => $this->_groupId1, - ); + ]; $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['not_added'], 1); @@ -170,10 +170,10 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { * Test GroupContact.delete by contact+group ID. */ public function testDelete() { - $params = array( + $params = [ 'contact_id' => $this->_contactId, 'group_id' => $this->_groupId1, - ); + ]; $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['removed'], 1); @@ -181,11 +181,11 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { } public function testDeletePermanent() { - $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId)); - $params = array( + $result = $this->callAPISuccess('group_contact', 'get', ['contact_id' => $this->_contactId]); + $params = [ 'id' => $result['id'], 'skip_undelete' => TRUE, - ); + ]; $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); $result = $this->callAPISuccess('group_contact', 'get', $params); $this->assertEquals(0, $result['count']); @@ -197,15 +197,15 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { * */ public function testDeleteWithId() { - $groupContactParams = array( + $groupContactParams = [ 'contact_id' => $this->_contactId, 'group_id' => $this->_groupId1, - ); + ]; $groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams); - $params = array( + $params = [ 'id' => $groupContact['id'], 'status' => 'Removed', - ); + ]; $result = $this->callAPISuccess('group_contact', 'delete', $params); $this->assertEquals($result['removed'], 1); $this->assertEquals($result['total_count'], 1); @@ -216,19 +216,19 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { * */ public function testDeleteAndReAddWithId() { - $groupContactParams = array( + $groupContactParams = [ 'contact_id' => $this->_contactId, 'group_id' => $this->_groupId1, - ); + ]; $groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams); - $params = array( + $params = [ 'id' => $groupContact['id'], 'status' => 'Removed', - ); + ]; $result = $this->callAPISuccess('group_contact', 'delete', $params); $this->assertEquals($result['removed'], 1); $this->assertEquals($result['total_count'], 1); - $params = array_merge($params, array('status' => 'Added')); + $params = array_merge($params, ['status' => 'Added']); $result2 = $this->callAPISuccess('group_contact', 'delete', $params); $this->assertEquals($result2['added'], 1); $this->assertEquals($result2['total_count'], 1); @@ -238,47 +238,47 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { * CRM-19979 test that group cotnact delete action works when contact is in status of pendin. */ public function testDeleteWithPending() { - $groupId3 = $this->groupCreate(array( + $groupId3 = $this->groupCreate([ 'name' => 'Test Group 3', 'domain_id' => 1, 'title' => 'New Test Group3 Created', 'description' => 'New Test Group3 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only', - )); - $groupContactCreateParams = array( + ]); + $groupContactCreateParams = [ 'contact_id' => $this->_contactId, 'group_id' => $groupId3, 'status' => 'Pending', - ); + ]; $groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams); $groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams); - $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'status' => 'Removed')); - $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE)); - $this->callAPISuccess('group', 'delete', array('id' => $groupId3)); + $this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'status' => 'Removed']); + $this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]); + $this->callAPISuccess('group', 'delete', ['id' => $groupId3]); } /** * CRM-19979 test that group cotnact delete action works when contact is in status of pendin and is a permanent delete. */ public function testPermanentDeleteWithPending() { - $groupId3 = $this->groupCreate(array( + $groupId3 = $this->groupCreate([ 'name' => 'Test Group 3', 'domain_id' => 1, 'title' => 'New Test Group3 Created', 'description' => 'New Test Group3 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only', - )); - $groupContactCreateParams = array( + ]); + $groupContactCreateParams = [ 'contact_id' => $this->_contactId, 'group_id' => $groupId3, 'status' => 'Pending', - ); + ]; $groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams); $groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams); - $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE)); - $this->callAPISuccess('group', 'delete', array('id' => $groupId3)); + $this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]); + $this->callAPISuccess('group', 'delete', ['id' => $groupId3]); } /** @@ -289,7 +289,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { * Test illustrates this (& ensures once fixed it will stay fixed). */ public function testAccurateCountWithSmartGroups() { - $childGroupID = $this->groupCreate(array( + $childGroupID = $this->groupCreate([ 'name' => 'Child group', 'domain_id' => 1, 'title' => 'Child group', @@ -297,21 +297,21 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { 'is_active' => 1, 'parents' => $this->_groupId1, 'visibility' => 'User and User Admin Only', - )); + ]); - $params = array( + $params = [ 'name' => 'Individuals', 'title' => 'Individuals', 'is_active' => 1, 'parents' => $this->_groupId1, - 'formValues' => array('contact_type' => 'Goat'), - ); + 'formValues' => ['contact_type' => 'Goat'], + ]; $smartGroup2 = CRM_Contact_BAO_Group::createSmartGroup($params); - $this->callAPISuccess('GroupContact', 'create', array('contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $this->_groupId2)); - $this->callAPISuccess('GroupContact', 'create', array('contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $smartGroup2->id)); - $this->callAPISuccess('GroupContact', 'create', array('contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $childGroupID)); - $groups = $this->callAPISuccess('GroupContact', 'get', array('contact_id' => $this->_contactId)); + $this->callAPISuccess('GroupContact', 'create', ['contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $this->_groupId2]); + $this->callAPISuccess('GroupContact', 'create', ['contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $smartGroup2->id]); + $this->callAPISuccess('GroupContact', 'create', ['contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $childGroupID]); + $groups = $this->callAPISuccess('GroupContact', 'get', ['contact_id' => $this->_contactId]); // Although the contact is actually hard-added to 4 groups the smart groups are conventionally not returned by the api or displayed // on the main part of the groups tab on the contact (which calls the same function. So, 3 groups is an OK number to return. diff --git a/tests/phpunit/api/v3/GroupOrganizationTest.php b/tests/phpunit/api/v3/GroupOrganizationTest.php index 51e8db588f..a3c26cff5f 100644 --- a/tests/phpunit/api/v3/GroupOrganizationTest.php +++ b/tests/phpunit/api/v3/GroupOrganizationTest.php @@ -54,14 +54,14 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { */ public function testGroupOrganizationGet() { - $params = array( + $params = [ 'organization_id' => $this->_orgID, 'group_id' => $this->_groupID, - ); + ]; $result = $this->callAPISuccess('group_organization', 'create', $params); - $paramsGet = array( + $paramsGet = [ 'organization_id' => $result['id'], - ); + ]; $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__); } @@ -69,16 +69,16 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Test civicrm_group_organization_get with group_id. */ public function testGroupOrganizationGetWithGroupId() { - $createParams = array( + $createParams = [ 'organization_id' => $this->_orgID, 'group_id' => $this->_groupID, - ); + ]; $createResult = $this->callAPISuccess('group_organization', 'create', $createParams); - $getParams = array( + $getParams = [ 'group_id' => $this->_groupID, 'sequential' => 1, - ); + ]; $getResult = $this->callAPISuccess('group_organization', 'get', $getParams); $this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]); } @@ -87,7 +87,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Test civicrm_group_organization_get with empty params. */ public function testGroupOrganizationGetWithEmptyParams() { - $params = array(); + $params = []; $result = $this->callAPISuccess('group_organization', 'get', $params); $this->assertAPISuccess($result); @@ -106,9 +106,9 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Test civicrm_group_organization_get invalid keys. */ public function testGroupOrganizationGetWithInvalidKeys() { - $params = array( + $params = [ 'invalid_key' => 1, - ); + ]; $result = $this->callAPISuccess('group_organization', 'get', $params); $this->assertAPISuccess($result); @@ -120,10 +120,10 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Check with valid params. */ public function testGroupOrganizationCreate() { - $params = array( + $params = [ 'organization_id' => $this->_orgID, 'group_id' => $this->_groupID, - ); + ]; $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__); } @@ -131,10 +131,10 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * CRM-13841 - Load Group Org before save */ public function testGroupOrganizationCreateTwice() { - $params = array( + $params = [ 'organization_id' => $this->_orgID, 'group_id' => $this->_groupID, - ); + ]; $result = $this->callAPISuccess('group_organization', 'create', $params); $result2 = $this->callAPISuccess('group_organization', 'create', $params); $this->assertEquals($result['values'], $result2['values']); @@ -144,7 +144,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Check with empty params array. */ public function testGroupOrganizationCreateWithEmptyParams() { - $params = array(); + $params = []; $result = $this->callAPIFailure('group_organization', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); } @@ -162,9 +162,9 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Check with invalid params keys. */ public function testGroupOrganizationCreateWithInvalidKeys() { - $params = array( + $params = [ 'invalid_key' => 1, - ); + ]; $result = $this->callAPIFailure('group_organization', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); } @@ -184,7 +184,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Test civicrm_group_organization_remove with empty params. */ public function testGroupOrganizationDeleteWithEmptyParams() { - $params = array(); + $params = []; $result = $this->callAPIFailure('group_organization', 'delete', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } @@ -193,15 +193,15 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Test civicrm_group_organization_remove with valid params. */ public function testGroupOrganizationDelete() { - $paramsC = array( + $paramsC = [ 'organization_id' => $this->_orgID, 'group_id' => $this->_groupID, - ); + ]; $result = $this->callAPISuccess('group_organization', 'create', $paramsC); - $params = array( + $params = [ 'id' => $result['id'], - ); + ]; $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__); } @@ -209,9 +209,9 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { * Test civicrm_group_organization_remove with invalid params key. */ public function testGroupOrganizationDeleteWithInvalidKey() { - $paramsDelete = array( + $paramsDelete = [ 'invalid_key' => 1, - ); + ]; $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } diff --git a/tests/phpunit/api/v3/JobProcessMailingTest.php b/tests/phpunit/api/v3/JobProcessMailingTest.php index 1f4e1bfdbf..1d8fa22970 100644 --- a/tests/phpunit/api/v3/JobProcessMailingTest.php +++ b/tests/phpunit/api/v3/JobProcessMailingTest.php @@ -46,7 +46,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { public $DBResetRequired = FALSE; public $_entity = 'Job'; - public $_params = array(); + public $_params = []; private $_groupID; private $_email; @@ -64,15 +64,15 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; $this->_groupID = $this->groupCreate(); $this->_email = 'test@test.test'; - $this->_params = array( + $this->_params = [ 'subject' => 'Accidents in cars cause children', 'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.', 'name' => 'mailing name', 'created_id' => 1, - 'groups' => array('include' => array($this->_groupID)), + 'groups' => ['include' => [$this->_groupID]], 'scheduled_date' => 'now', - ); - $this->defaultSettings = array( + ]; + $this->defaultSettings = [ // int, #mailings to send 'mailings' => 1, // int, #contacts to receive mailing @@ -91,9 +91,9 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { 'mailerJobSize' => 0, // int, microseconds separating messages 'mailThrottleTime' => 0, - ); + ]; $this->_mut = new CiviMailUtils($this, TRUE); - $this->callAPISuccess('mail_settings', 'get', array('api.mail_settings.create' => array('domain' => 'chaos.org'))); + $this->callAPISuccess('mail_settings', 'get', ['api.mail_settings.create' => ['domain' => 'chaos.org']]); } /** @@ -110,12 +110,12 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { public function testBasic() { $this->createContactsInGroup(10, $this->_groupID); - Civi::settings()->add(array( + Civi::settings()->add([ 'mailerBatchLimit' => 2, - )); + ]); $this->callAPISuccess('mailing', 'create', $this->_params); - $this->_mut->assertRecipients(array()); - $this->callAPISuccess('job', 'process_mailing', array()); + $this->_mut->assertRecipients([]); + $this->callAPISuccess('job', 'process_mailing', []); $this->_mut->assertRecipients($this->getRecipients(1, 2)); } @@ -124,34 +124,34 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { */ public function testPauseAndResumeMailing() { $this->createContactsInGroup(10, $this->_groupID); - Civi::settings()->add(array( + Civi::settings()->add([ 'mailerBatchLimit' => 2, - )); + ]); $this->_mut->clearMessages(); //Create a test mailing and check if the status is set to Scheduled. $result = $this->callAPISuccess('mailing', 'create', $this->_params); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]); $this->assertEquals('Scheduled', $jobs['values'][$jobs['id']]['status']); //Pause the mailing. CRM_Mailing_BAO_MailingJob::pause($result['id']); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]); $this->assertEquals('Paused', $jobs['values'][$jobs['id']]['status']); //Verify if Paused mailing isn't considered in process_mailing job. - $this->callAPISuccess('job', 'process_mailing', array()); + $this->callAPISuccess('job', 'process_mailing', []); //Check if mail log is empty. $this->_mut->assertMailLogEmpty(); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]); $this->assertEquals('Paused', $jobs['values'][$jobs['id']]['status']); //Resume should set the status back to Scheduled. CRM_Mailing_BAO_MailingJob::resume($result['id']); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]); $this->assertEquals('Scheduled', $jobs['values'][$jobs['id']]['status']); //Execute the job and it should send the mailing to the recipients now. - $this->callAPISuccess('job', 'process_mailing', array()); + $this->callAPISuccess('job', 'process_mailing', []); $this->_mut->assertRecipients($this->getRecipients(1, 2)); } @@ -161,34 +161,34 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { */ public function testMailNonProductionRun() { // Test in non-production mode. - $params = array( + $params = [ 'environment' => 'Staging', - ); + ]; $this->callAPISuccess('Setting', 'create', $params); //Assert if outbound mail is disabled. $mailingBackend = Civi::settings()->get('mailing_backend'); $this->assertEquals($mailingBackend['outBound_option'], CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED); $this->createContactsInGroup(10, $this->_groupID); - Civi::settings()->add(array( + Civi::settings()->add([ 'mailerBatchLimit' => 2, - )); + ]); $this->callAPISuccess('mailing', 'create', $this->_params); - $this->_mut->assertRecipients(array()); + $this->_mut->assertRecipients([]); $this->callAPIFailure('job', 'process_mailing', "Failure in api call for job process_mailing: Job has not been executed as it is a non-production environment."); // Test with runInNonProductionEnvironment param. - $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE)); + $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]); $this->_mut->assertRecipients($this->getRecipients(1, 2)); - $jobId = $this->callAPISuccessGetValue('Job', array( + $jobId = $this->callAPISuccessGetValue('Job', [ 'return' => "id", 'api_action' => "group_rebuild", - )); - $this->callAPISuccess('Job', 'create', array( + ]); + $this->callAPISuccess('Job', 'create', [ 'id' => $jobId, 'parameters' => "runInNonProductionEnvironment=TRUE", - )); + ]); $jobManager = new CRM_Core_JobManager(); $jobManager->executeJobById($jobId); @@ -197,20 +197,20 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { $this->assertEquals($mailingBackend['outBound_option'], CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED); // Test in production mode. - $params = array( + $params = [ 'environment' => 'Production', - ); + ]; $this->callAPISuccess('Setting', 'create', $params); - $this->callAPISuccess('job', 'process_mailing', array()); + $this->callAPISuccess('job', 'process_mailing', []); $this->_mut->assertRecipients($this->getRecipients(1, 2)); } public function concurrencyExamples() { - $es = array(); + $es = []; // Launch 3 workers, but mailerJobsMax limits us to 1 worker. - $es[0] = array( - array( + $es[0] = [ + [ 'recipients' => 20, 'workers' => 3, // FIXME: lockHold is unrealistic/unrepresentative. In reality, this situation fails because @@ -220,20 +220,20 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { 'lockHold' => 10, 'mailerBatchLimit' => 4, 'mailerJobsMax' => 1, - ), - array( + ], + [ // 2 jobs which produce 0 messages 0 => 2, // 1 job which produces 4 messages 4 => 1, - ), + ], 4, - ); + ]; // Launch 3 workers, but mailerJobsMax limits us to 2 workers. - $es[1] = array( + $es[1] = [ // Settings. - array( + [ 'recipients' => 20, 'workers' => 3, // FIXME: lockHold is unrealistic/unrepresentative. In reality, this situation fails because @@ -243,112 +243,112 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { 'lockHold' => 10, 'mailerBatchLimit' => 5, 'mailerJobsMax' => 2, - ), + ], // Tallies. - array( + [ // 1 job which produce 0 messages 0 => 1, // 2 jobs which produce 5 messages 5 => 2, - ), + ], // Total sent. 10, - ); + ]; // Launch 3 workers and saturate them (mailerJobsMax=3) - $es[2] = array( + $es[2] = [ // Settings. - array( + [ 'recipients' => 20, 'workers' => 3, 'mailerBatchLimit' => 6, 'mailerJobsMax' => 3, - ), + ], // Tallies. - array( + [ // 3 jobs which produce 6 messages 6 => 3, - ), + ], // Total sent. 18, - ); + ]; // Launch 4 workers and saturate them (mailerJobsMax=0) - $es[3] = array( + $es[3] = [ // Settings. - array( + [ 'recipients' => 20, 'workers' => 4, 'mailerBatchLimit' => 6, 'mailerJobsMax' => 0, - ), + ], // Tallies. - array( + [ // 3 jobs which produce 6 messages 6 => 3, // 1 job which produces 2 messages 2 => 1, - ), + ], // Total sent. 20, - ); + ]; // Launch 1 worker, 3 times in a row. Deliver everything. - $es[4] = array( + $es[4] = [ // Settings. - array( + [ 'recipients' => 10, 'workers' => 1, 'iterations' => 3, 'mailerBatchLimit' => 7, - ), + ], // Tallies. - array( + [ // 1 job which produces 7 messages 7 => 1, // 1 job which produces 3 messages 3 => 1, // 1 job which produces 0 messages 0 => 1, - ), + ], // Total sent. 10, - ); + ]; // Launch 2 worker, 3 times in a row. Deliver everything. - $es[5] = array( + $es[5] = [ // Settings. - array( + [ 'recipients' => 10, 'workers' => 2, 'iterations' => 3, 'mailerBatchLimit' => 3, - ), + ], // Tallies. - array( + [ // 3 jobs which produce 3 messages 3 => 3, // 1 job which produces 1 messages 1 => 1, // 2 jobs which produce 0 messages 0 => 2, - ), + ], // Total sent. 10, - ); + ]; // For two mailings, launch 1 worker, 5 times in a row. Deliver everything. - $es[6] = array( + $es[6] = [ // Settings. - array( + [ 'mailings' => 2, 'recipients' => 10, 'workers' => 1, 'iterations' => 5, 'mailerBatchLimit' => 6, - ), + ], // Tallies. - array( + [ // x6 => x4+x2 => x6 => x2 => x0 // 3 jobs which produce 6 messages 6 => 3, @@ -356,10 +356,10 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { 2 => 1, // 1 job which produces 0 messages 0 => 1, - ), + ], // Total sent. 20, - ); + ]; return $es; } @@ -387,24 +387,24 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { $settings = array_merge($this->defaultSettings, $settings); $this->createContactsInGroup($settings['recipients'], $this->_groupID); - Civi::settings()->add(CRM_Utils_Array::subset($settings, array( + Civi::settings()->add(CRM_Utils_Array::subset($settings, [ 'mailerBatchLimit', 'mailerJobsMax', 'mailThrottleTime', - ))); + ])); for ($i = 0; $i < $settings['mailings']; $i++) { $this->callAPISuccess('mailing', 'create', $this->_params); } - $this->_mut->assertRecipients(array()); + $this->_mut->assertRecipients([]); - $allApiResults = array(); + $allApiResults = []; for ($iterationId = 0; $iterationId < $settings['iterations']; $iterationId++) { $apiCalls = $this->createExternalAPI(); - $apiCalls->addEnv(array('CIVICRM_CRON_HOLD' => $settings['lockHold'])); + $apiCalls->addEnv(['CIVICRM_CRON_HOLD' => $settings['lockHold']]); for ($workerId = 0; $workerId < $settings['workers']; $workerId++) { - $apiCalls->addCall('job', 'process_mailing', array()); + $apiCalls->addCall('job', 'process_mailing', []); } $apiCalls->start(); $this->assertEquals($settings['workers'], $apiCalls->getRunningCount()); @@ -414,11 +414,11 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { } $actualTallies = $this->tallyApiResults($allApiResults); - $this->assertEquals($expectedTallies, $actualTallies, 'API tallies should match.' . print_r(array( + $this->assertEquals($expectedTallies, $actualTallies, 'API tallies should match.' . print_r([ 'expectedTallies' => $expectedTallies, 'actualTallies' => $actualTallies, 'apiResults' => $allApiResults, - ), TRUE)); + ], TRUE)); $this->_mut->assertRecipients($this->getRecipients(1, $expectedTotal / $settings['mailings'], 'nul.example.com', $settings['mailings'])); $this->assertEquals(0, $apiCalls->getRunningCount()); } @@ -432,12 +432,12 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { */ public function createContactsInGroup($count, $groupID, $domain = 'nul.example.com') { for ($i = 1; $i <= $count; $i++) { - $contactID = $this->individualCreate(array('first_name' => $count, 'email' => 'mail' . $i . '@' . $domain)); - $this->callAPISuccess('group_contact', 'create', array( + $contactID = $this->individualCreate(['first_name' => $count, 'email' => 'mail' . $i . '@' . $domain]); + $this->callAPISuccess('group_contact', 'create', [ 'contact_id' => $contactID, 'group_id' => $groupID, 'status' => 'Added', - )); + ]); } } @@ -452,7 +452,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { * @return array */ public function getRecipients($start, $count, $domain = 'nul.example.com', $mailings = 1) { - $recipients = array(); + $recipients = []; for ($m = 0; $m < $mailings; $m++) { for ($i = $start; $i < ($start + $count); $i++) { $recipients[][0] = 'mail' . $i . '@' . $domain; @@ -462,7 +462,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { } protected function cleanupMailingTest() { - $this->quickCleanup(array( + $this->quickCleanup([ 'civicrm_mailing', 'civicrm_mailing_job', 'civicrm_mailing_spool', @@ -474,7 +474,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { 'civicrm_group', 'civicrm_group_contact', 'civicrm_contact', - )); + ]); } /** @@ -487,7 +487,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { * A separate key for each distinct quantity. */ protected function tallyApiResults($apiResults) { - $ret = array(); + $ret = []; foreach ($apiResults as $apiResult) { $key = !empty($apiResult['is_error']) ? 'error' : $apiResult['values']['processed']; $ret[$key] = !empty($ret[$key]) ? 1 + $ret[$key] : 1; diff --git a/tests/phpunit/api/v3/JobTestCustomDataTest.php b/tests/phpunit/api/v3/JobTestCustomDataTest.php index d7c5e9dedc..ea55f90b73 100644 --- a/tests/phpunit/api/v3/JobTestCustomDataTest.php +++ b/tests/phpunit/api/v3/JobTestCustomDataTest.php @@ -88,37 +88,37 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { parent::setUp(); $customGroup = $this->customGroupCreate(); $this->customGroupID = $customGroup['id']; - $customField = $this->customFieldCreate(array( + $customField = $this->customFieldCreate([ 'custom_group_id' => $this->customGroupID, 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => '', - )); + ]); $this->customFieldID = $customField['id']; - $customField = $this->customFieldCreate(array( + $customField = $this->customFieldCreate([ 'custom_group_id' => $this->customGroupID, 'data_type' => 'Integer', 'html_type' => 'Text', 'default_value' => '', 'label' => 'Int Field', - )); + ]); $this->customIntFieldID = $customField['id']; - $customField = $this->customFieldCreate(array( + $customField = $this->customFieldCreate([ 'custom_group_id' => $this->customGroupID, 'data_type' => 'Boolean', 'html_type' => 'Radio', 'default_value' => '', 'label' => 'Radio Field', - )); + ]); $this->customBoolFieldID = $customField['id']; - $customField = $this->customFieldCreate(array( + $customField = $this->customFieldCreate([ 'custom_group_id' => $this->customGroupID, 'data_type' => 'String', 'html_type' => 'CheckBox', 'default_value' => NULL, 'label' => 'checkbox Field', - 'option_values' => array('black' => 'black', 'white' => 'white'), - )); + 'option_values' => ['black' => 'black', 'white' => 'white'], + ]); $this->customStringCheckboxID = $customField['id']; } @@ -126,7 +126,7 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Cleanup after tests. */ public function tearDown() { - $this->quickCleanup(array('civicrm_contact'), TRUE); + $this->quickCleanup(['civicrm_contact'], TRUE); parent::tearDown(); } @@ -148,14 +148,14 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeCheckboxCustomFieldHandling($dataSet) { $customFieldLabel = 'custom_' . $this->customStringCheckboxID; - $contact1Params = is_array($dataSet['contacts'][0]) ? array($customFieldLabel => $dataSet['contacts'][0]) : array(); - $contact2Params = is_array($dataSet['contacts'][1]) ? array($customFieldLabel => $dataSet['contacts'][1]) : array(); + $contact1Params = is_array($dataSet['contacts'][0]) ? [$customFieldLabel => $dataSet['contacts'][0]] : []; + $contact2Params = is_array($dataSet['contacts'][1]) ? [$customFieldLabel => $dataSet['contacts'][1]] : []; $contactID = $this->individualCreate($contact1Params); $this->individualCreate($contact2Params); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array('mode' => $dataSet['mode'])); + $result = $this->callAPISuccess('Job', 'process_batch_merge', ['mode' => $dataSet['mode']]); $this->assertEquals($dataSet['merged'], count($result['values']['merged'])); $this->assertEquals($dataSet['skipped'], count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals($dataSet['expected'], $contact[$customFieldLabel]); } @@ -165,57 +165,57 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * @return array */ public function getCheckboxData() { - $data = array( - array( - 'null_merges_with_set' => array( + $data = [ + [ + 'null_merges_with_set' => [ 'mode' => 'safe', - 'contacts' => array( + 'contacts' => [ NULL, - array('black'), - ), + ['black'], + ], 'skipped' => 0, 'merged' => 1, - 'expected' => array('black'), - ), - ), - array( - 'null_merges_with_set_reverse' => array( + 'expected' => ['black'], + ], + ], + [ + 'null_merges_with_set_reverse' => [ 'mode' => 'safe', - 'contacts' => array( - array('black'), + 'contacts' => [ + ['black'], NULL, - ), + ], 'skipped' => 0, 'merged' => 1, - 'expected' => array('black'), + 'expected' => ['black'], - ), - ), - array( - 'empty_conflicts_with_set' => array( + ], + ], + [ + 'empty_conflicts_with_set' => [ 'mode' => 'safe', - 'contacts' => array( - array('white'), - array('black'), - ), + 'contacts' => [ + ['white'], + ['black'], + ], 'skipped' => 1, 'merged' => 0, - 'expected' => array('white'), - ), - ), - array( - 'empty_conflicts_with_set' => array( + 'expected' => ['white'], + ], + ], + [ + 'empty_conflicts_with_set' => [ 'mode' => 'aggressive', - 'contacts' => array( - array('white'), - array('black'), - ), + 'contacts' => [ + ['white'], + ['black'], + ], 'skipped' => 0, 'merged' => 1, - 'expected' => array('white'), - ), - ), - ); + 'expected' => ['white'], + ], + ], + ]; return $data; } @@ -227,10 +227,10 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { public function testBatchMergeDateCustomFieldHandling() { $customFieldLabel = 'custom_' . $this->customFieldID; $contactID = $this->individualCreate(); - $this->individualCreate(array($customFieldLabel => '2012-12-03')); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->individualCreate([$customFieldLabel => '2012-12-03']); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(1, count($result['values']['merged'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals('2012-12-03 00:00:00', $contact[$customFieldLabel]); } @@ -240,17 +240,17 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Test CRM-18674 date custom field handling. */ public function testBatchMergeDateCustomFieldHandlingIsView() { - $this->customFieldCreate(array( + $this->customFieldCreate([ 'label' => 'OnlyView', 'custom_group_id' => $this->customGroupID, 'is_view' => 1, - )); + ]); $customFieldLabel = 'custom_' . $this->customFieldID; $contactID = $this->individualCreate(); - $this->individualCreate(array($customFieldLabel => '2012-11-03')); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->individualCreate([$customFieldLabel => '2012-11-03']); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(1, count($result['values']['merged'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); } @@ -259,12 +259,12 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeDateCustomFieldConflict() { $customFieldLabel = 'custom_' . $this->customFieldID; - $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03')); - $this->individualCreate(array($customFieldLabel => '2013-11-03')); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $contactID = $this->individualCreate([$customFieldLabel => '2012-11-03']); + $this->individualCreate([$customFieldLabel => '2013-11-03']); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(0, count($result['values']['merged'])); $this->assertEquals(1, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); } @@ -273,12 +273,12 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeDateCustomFieldNoConflict() { $customFieldLabel = 'custom_' . $this->customFieldID; - $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03')); - $this->individualCreate(array($customFieldLabel => '2012-11-03')); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $contactID = $this->individualCreate([$customFieldLabel => '2012-11-03']); + $this->individualCreate([$customFieldLabel => '2012-11-03']); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(1, count($result['values']['merged'])); $this->assertEquals(0, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); } @@ -287,12 +287,12 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeIntCustomFieldNoConflict() { $customFieldLabel = 'custom_' . $this->customIntFieldID; - $contactID = $this->individualCreate(array()); - $this->individualCreate(array($customFieldLabel => 20)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $contactID = $this->individualCreate([]); + $this->individualCreate([$customFieldLabel => 20]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(1, count($result['values']['merged'])); $this->assertEquals(0, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals(20, $contact[$customFieldLabel]); } @@ -301,12 +301,12 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeIntCustomFieldConflict() { $customFieldLabel = 'custom_' . $this->customIntFieldID; - $contactID = $this->individualCreate(array($customFieldLabel => 20)); - $this->individualCreate(array($customFieldLabel => 1)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $contactID = $this->individualCreate([$customFieldLabel => 20]); + $this->individualCreate([$customFieldLabel => 1]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(0, count($result['values']['merged'])); $this->assertEquals(1, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals(20, $contact[$customFieldLabel]); } @@ -315,12 +315,12 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeIntCustomFieldConflictZero() { $customFieldLabel = 'custom_' . $this->customIntFieldID; - $contactID = $this->individualCreate(array($customFieldLabel => 0)); - $this->individualCreate(array($customFieldLabel => 20)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $contactID = $this->individualCreate([$customFieldLabel => 0]); + $this->individualCreate([$customFieldLabel => 20]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(0, count($result['values']['merged'])); $this->assertEquals(1, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals(0, $contact[$customFieldLabel]); } @@ -330,16 +330,16 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Test CRM-18674 date custom field handling. */ public function testBatchMergeDateCustomFieldConflictAndNoCheckPerms() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact']; CRM_Core_DAO::executeQuery("DELETE FROM civicrm_cache"); CRM_Utils_System::flushCache(); $customFieldLabel = 'custom_' . $this->customFieldID; - $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03')); - $this->individualCreate(array($customFieldLabel => '2013-11-03')); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0)); + $contactID = $this->individualCreate([$customFieldLabel => '2012-11-03']); + $this->individualCreate([$customFieldLabel => '2013-11-03']); + $result = $this->callAPISuccess('Job', 'process_batch_merge', ['check_permissions' => 0]); $this->assertEquals(0, count($result['values']['merged'])); $this->assertEquals(1, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); } @@ -349,16 +349,16 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Test CRM-18674 date custom field handling. */ public function testBatchMergeDateCustomFieldNoConflictAndNoCheckPerms() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact']; CRM_Core_DAO::executeQuery("DELETE FROM civicrm_cache"); CRM_Utils_System::flushCache(); $customFieldLabel = 'custom_' . $this->customFieldID; $contactID = $this->individualCreate(); - $this->individualCreate(array($customFieldLabel => '2013-11-03')); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0)); + $this->individualCreate([$customFieldLabel => '2013-11-03']); + $result = $this->callAPISuccess('Job', 'process_batch_merge', ['check_permissions' => 0]); $this->assertEquals(1, count($result['values']['merged'])); $this->assertEquals(0, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]); $this->assertEquals('2013-11-03 00:00:00', $contact[$customFieldLabel]); } @@ -368,19 +368,19 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Test CRM-19113 custom data lost when permissions in play. */ public function testBatchMergeIntCustomFieldNoConflictAndNoCheckPerms() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact']; CRM_Core_DAO::executeQuery("DELETE FROM civicrm_cache"); CRM_Utils_System::flushCache(); $customFieldLabel = 'custom_' . $this->customIntFieldID; - $contactID = $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1)); - $this->individualCreate(array($customFieldLabel => 1, 'custom_' . $this->customBoolFieldID => 1)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0)); + $contactID = $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]); + $this->individualCreate([$customFieldLabel => 1, 'custom_' . $this->customBoolFieldID => 1]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', ['check_permissions' => 0]); $this->assertEquals(1, count($result['values']['merged'])); $this->assertEquals(0, count($result['values']['skipped'])); - $contact = $this->callAPISuccess('Contact', 'getsingle', array( + $contact = $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $contactID, - 'return' => array($customFieldLabel, 'custom_' . $this->customBoolFieldID), - )); + 'return' => [$customFieldLabel, 'custom_' . $this->customBoolFieldID], + ]); $this->assertEquals(1, $contact[$customFieldLabel]); $this->assertEquals(1, $contact['custom_' . $this->customBoolFieldID]); } @@ -389,9 +389,9 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Check we get a conflict on the customs field when the data conflicts for booleans. */ public function testBatchMergeCustomFieldConflicts() { - $this->individualCreate(array('custom_' . $this->customBoolFieldID => 0)); - $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->individualCreate(['custom_' . $this->customBoolFieldID => 0]); + $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(0, count($result['values']['merged'])); $this->assertEquals(1, count($result['values']['skipped'])); } @@ -400,9 +400,9 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Check we get a conflict on the customs field when the data conflicts for booleans (reverse). */ public function testBatchMergeCustomFieldConflictsReverse() { - $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1)); - $this->individualCreate(array('custom_' . $this->customBoolFieldID => 0)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]); + $this->individualCreate(['custom_' . $this->customBoolFieldID => 0]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(0, count($result['values']['merged'])); $this->assertEquals(1, count($result['values']['skipped'])); } @@ -411,9 +411,9 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { * Check we get a conflict on the customs field when the data conflicts for booleans (reverse). */ public function testBatchMergeCustomFieldConflictsOneBlank() { - $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1)); + $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]); $this->individualCreate(); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(1, count($result['values']['merged'])); $this->assertEquals(0, count($result['values']['skipped'])); } @@ -423,8 +423,8 @@ class api_v3_JobTestCustomDataTest extends CiviUnitTestCase { */ public function testBatchMergeCustomFieldConflictsOneBlankReverse() { $this->individualCreate(); - $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1)); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]); + $result = $this->callAPISuccess('Job', 'process_batch_merge', []); $this->assertEquals(1, count($result['values']['merged'])); $this->assertEquals(0, count($result['values']['skipped'])); } diff --git a/tests/phpunit/api/v3/LineItemTest.php b/tests/phpunit/api/v3/LineItemTest.php index b6c2009821..3313fdef4c 100644 --- a/tests/phpunit/api/v3/LineItemTest.php +++ b/tests/phpunit/api/v3/LineItemTest.php @@ -34,7 +34,7 @@ class api_v3_LineItemTest extends CiviUnitTestCase { protected $testAmount = 34567; protected $params; protected $id = 0; - protected $contactIds = array(); + protected $contactIds = []; protected $_entity = 'line_item'; protected $contribution_result = NULL; @@ -45,7 +45,7 @@ class api_v3_LineItemTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); $this->_individualId = $this->individualCreate(); - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -55,9 +55,9 @@ class api_v3_LineItemTest extends CiviUnitTestCase { 'net_amount' => 91.00, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); - $this->params = array( + $this->params = [ 'price_field_value_id' => 1, 'price_field_id' => 1, 'entity_table' => 'civicrm_contribution', @@ -65,37 +65,37 @@ class api_v3_LineItemTest extends CiviUnitTestCase { 'qty' => 1, 'unit_price' => 50, 'line_total' => 50, - ); + ]; } public function testCreateLineItem() { - $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + array('debug' => 1), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + ['debug' => 1], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); $this->getAndCheck($this->params, $result['id'], $this->_entity); } public function testGetBasicLineItem() { - $getParams = array( + $getParams = [ 'entity_table' => 'civicrm_contribution', - ); + ]; $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count']); } public function testDeleteLineItem() { - $getParams = array( + $getParams = [ 'entity_table' => 'civicrm_contribution', - ); + ]; $getResult = $this->callAPISuccess($this->_entity, 'get', $getParams); - $deleteParams = array('id' => $getResult['id']); + $deleteParams = ['id' => $getResult['id']]; $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } public function testGetFieldsLineItem() { - $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertEquals(1, $result['values']['entity_id']['api.required']); } diff --git a/tests/phpunit/api/v3/LoggingTest.php b/tests/phpunit/api/v3/LoggingTest.php index 79d4f69f65..f092157c3b 100644 --- a/tests/phpunit/api/v3/LoggingTest.php +++ b/tests/phpunit/api/v3/LoggingTest.php @@ -47,9 +47,9 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * Clean up log tables. */ protected function tearDown() { - $this->quickCleanup(array('civicrm_email', 'civicrm_address')); + $this->quickCleanup(['civicrm_email', 'civicrm_address']); parent::tearDown(); - $this->callAPISuccess('Setting', 'create', array('logging' => FALSE)); + $this->callAPISuccess('Setting', 'create', ['logging' => FALSE]); $schema = new CRM_Logging_Schema(); $schema->dropAllLogTables(); CRM_Core_DAO::executeQuery("DELETE FROM civicrm_setting WHERE name LIKE 'logg%'"); @@ -59,24 +59,24 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * Test that logging is successfully enabled and disabled. */ public function testEnableDisableLogging() { - $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging'))); + $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging'])); $this->assertLoggingEnabled(FALSE); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); $this->assertLoggingEnabled(TRUE); $this->checkLogTableCreated(); $this->checkTriggersCreated(TRUE); // Create a contact to make sure they aren't borked. $this->individualCreate(); - $this->assertTrue($this->callAPISuccessGetValue('Setting', array('name' => 'logging'))); - $this->assertEquals(1, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid'))); + $this->assertTrue($this->callAPISuccessGetValue('Setting', ['name' => 'logging'])); + $this->assertEquals(1, $this->callAPISuccessGetValue('Setting', ['name' => 'logging_all_tables_uniquid'])); $this->assertEquals( date('Y-m-d'), - date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date')))) + date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', ['name' => 'logging_uniqueid_date']))) ); - $this->callAPISuccess('Setting', 'create', array('logging' => FALSE)); - $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging'))); + $this->callAPISuccess('Setting', 'create', ['logging' => FALSE]); + $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging'])); $this->assertLoggingEnabled(FALSE); } @@ -84,13 +84,13 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * Test that logging is successfully enabled and disabled. */ public function testEnableDisableLoggingWithTriggerHook() { - $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'innodbLogTableSpec')); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpec']); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); $this->checkINNODBLogTableCreated(); $this->checkTriggersCreated(TRUE); // Create a contact to make sure they aren't borked. $this->individualCreate(); - $this->callAPISuccess('Setting', 'create', array('logging' => FALSE)); + $this->callAPISuccess('Setting', 'create', ['logging' => FALSE]); } /** @@ -105,10 +105,10 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testEnableLoggingLegacyLogTableExists() { $this->createLegacyStyleContactLogTable(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); $this->checkTriggersCreated(FALSE); - $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid'))); - $this->assertEmpty($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date'))); + $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging_all_tables_uniquid'])); + $this->assertEmpty($this->callAPISuccessGetValue('Setting', ['name' => 'logging_uniqueid_date'])); } /** @@ -116,14 +116,14 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testUpdateLegacyLogTable() { $this->createLegacyStyleContactLogTable(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); - $this->callAPISuccess('System', 'updatelogtables', array()); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); + $this->callAPISuccess('System', 'updatelogtables', []); $this->checkLogTableCreated(); $this->checkTriggersCreated(TRUE); - $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid'))); + $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging_all_tables_uniquid'])); $this->assertEquals( date('Y-m-d'), - date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date')))) + date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', ['name' => 'logging_uniqueid_date']))) ); } @@ -131,9 +131,9 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * Check if we can create missing log tables using api. */ public function testCreateMissingLogTables() { - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); CRM_Core_DAO::executeQuery("DROP TABLE log_civicrm_contact"); - $this->callAPISuccess('System', 'createmissinglogtables', array()); + $this->callAPISuccess('System', 'createmissinglogtables', []); //Assert if log_civicrm_contact is created. $this->checkLogTableCreated(); @@ -144,22 +144,22 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testUpdateLogTableHookINNODB() { $this->createLegacyStyleContactLogTable(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); - $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'innodbLogTableSpec')); - $this->callAPISuccess('System', 'updatelogtables', array()); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); + $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpec']); + $this->callAPISuccess('System', 'updatelogtables', []); $this->checkINNODBLogTableCreated(); $this->checkTriggersCreated(TRUE); // Make sure that the absence of a hook specifying INNODB does not cause revert to archive. // Only a positive action, like specifying ARCHIVE in a hook should trigger a change back to archive. - $this->hookClass->setHook('civicrm_alterLogTables', array()); + $this->hookClass->setHook('civicrm_alterLogTables', []); $schema = new CRM_Logging_Schema(); $spec = $schema->getLogTableSpec(); - $this->assertEquals(array(), $spec['civicrm_contact']); - $this->callAPISuccess('System', 'updatelogtables', array()); + $this->assertEquals([], $spec['civicrm_contact']); + $this->callAPISuccess('System', 'updatelogtables', []); $this->checkINNODBLogTableCreated(); // Check if API creates new indexes when they're added by hook $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpecNewIndex']); - $this->callAPISuccess('System', 'updatelogtables', array()); + $this->callAPISuccess('System', 'updatelogtables', []); $this->checkINNODBLogTableCreated(); $this->assertContains('KEY `index_log_user_id` (`log_user_id`)', $this->checkLogTableCreated()); } @@ -168,8 +168,8 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * Check that if a field is added then the trigger is updated on refresh. */ public function testRebuildTriggerAfterSchemaChange() { - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); - $tables = array('civicrm_acl', 'civicrm_website'); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); + $tables = ['civicrm_acl', 'civicrm_website']; foreach ($tables as $table) { CRM_Core_DAO::executeQuery("ALTER TABLE $table ADD column temp_col INT(10)"); } @@ -194,15 +194,15 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * @param array $logTableSpec */ public function innodbLogTableSpec(&$logTableSpec) { - $logTableSpec['civicrm_contact'] = array( + $logTableSpec['civicrm_contact'] = [ 'engine' => 'InnoDB', 'engine_config' => 'ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4', - 'indexes' => array( + 'indexes' => [ 'index_id' => 'id', 'index_log_conn_id' => 'log_conn_id', 'index_log_date' => 'log_date', - ), - ); + ], + ]; } /** @@ -211,17 +211,17 @@ class api_v3_LoggingTest extends CiviUnitTestCase { * @param array $logTableSpec */ public function innodbLogTableSpecNewIndex(&$logTableSpec) { - $logTableSpec['civicrm_contact'] = array( + $logTableSpec['civicrm_contact'] = [ 'engine' => 'InnoDB', 'engine_config' => 'ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4', - 'indexes' => array( + 'indexes' => [ 'index_id' => 'id', 'index_log_conn_id' => 'log_conn_id', 'index_log_date' => 'log_date', // new index 'index_log_user_id' => 'log_user_id', - ), - ); + ], + ]; } /** @@ -296,22 +296,22 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testRevert() { $contactId = $this->individualCreate(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); // Pause for one second here to ensure the timestamps between the first create action // and the second differ. sleep(1); CRM_Core_DAO::executeQuery("SET @uniqueID = 'woot'"); $timeStamp = date('Y-m-d H:i:s'); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'Dopey', - 'api.email.create' => array('email' => 'dopey@mail.com'), - ) + 'api.email.create' => ['email' => 'dopey@mail.com'], + ] ); - $email = $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com')); - $this->callAPIAndDocument('Logging', 'revert', array('log_conn_id' => 'woot', 'log_date' => $timeStamp), __FILE__, 'Revert'); - $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', array('id' => $contactId, 'return' => 'first_name'))); - $this->callAPISuccessGetCount('Email', array('id' => $email['id']), 0); + $email = $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']); + $this->callAPIAndDocument('Logging', 'revert', ['log_conn_id' => 'woot', 'log_date' => $timeStamp], __FILE__, 'Revert'); + $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', ['id' => $contactId, 'return' => 'first_name'])); + $this->callAPISuccessGetCount('Email', ['id' => $email['id']], 0); } /** @@ -319,20 +319,20 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testRevertNoDate() { $contactId = $this->individualCreate(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); // Pause for one second here to ensure the timestamps between the first create action // and the second differ. sleep(1); CRM_Core_DAO::executeQuery("SET @uniqueID = 'Wot woot'"); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'Dopey', - 'api.email.create' => array('email' => 'dopey@mail.com'), - )); - $email = $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com')); - $this->callAPISuccess('Logging', 'revert', array('log_conn_id' => 'Wot woot')); - $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', array('id' => $contactId, 'return' => 'first_name'))); - $this->callAPISuccessGetCount('Email', array('id' => $email['id']), 0); + 'api.email.create' => ['email' => 'dopey@mail.com'], + ]); + $email = $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']); + $this->callAPISuccess('Logging', 'revert', ['log_conn_id' => 'Wot woot']); + $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', ['id' => $contactId, 'return' => 'first_name'])); + $this->callAPISuccessGetCount('Email', ['id' => $email['id']], 0); } /** @@ -346,42 +346,42 @@ class api_v3_LoggingTest extends CiviUnitTestCase { public function testRevertRestrictedTables() { CRM_Core_DAO::executeQuery("SET @uniqueID = 'temp name'"); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); - $contactId = $this->individualCreate(array('address' => array(array('street_address' => '27 Cool way', 'location_type_id' => 1)))); - $contact = $this->callAPISuccessGetSingle('contact', array('id' => $contactId)); + $contactId = $this->individualCreate(['address' => [['street_address' => '27 Cool way', 'location_type_id' => 1]]]); + $contact = $this->callAPISuccessGetSingle('contact', ['id' => $contactId]); $this->assertEquals('Anthony', $contact['first_name']); $this->assertEquals('anthony_anderson@civicrm.org', $contact['email']); $this->assertEquals('27 Cool way', $contact['street_address']); sleep(1); CRM_Core_DAO::executeQuery("SET @uniqueID = 'bitty bot bot'"); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'Dopey', - 'address' => array(array('street_address' => '25 Dorky way', 'location_type_id' => 1)), - 'email' => array('email' => array('email' => 'dopey@mail.com', 'location_type_id' => 1)), - 'api.contribution.create' => array('financial_type_id' => 'Donation', 'receive_date' => 'now', 'total_amount' => 10), - )); - $contact = $this->callAPISuccessGetSingle('contact', array('id' => $contactId, 'return' => array('first_name', 'email', 'modified_date', 'street_address'))); + 'address' => [['street_address' => '25 Dorky way', 'location_type_id' => 1]], + 'email' => ['email' => ['email' => 'dopey@mail.com', 'location_type_id' => 1]], + 'api.contribution.create' => ['financial_type_id' => 'Donation', 'receive_date' => 'now', 'total_amount' => 10], + ]); + $contact = $this->callAPISuccessGetSingle('contact', ['id' => $contactId, 'return' => ['first_name', 'email', 'modified_date', 'street_address']]); $this->assertEquals('Dopey', $contact['first_name']); $this->assertEquals('dopey@mail.com', $contact['email']); $this->assertEquals('25 Dorky way', $contact['street_address']); $modifiedDate = $contact['modified_date']; // To protect against the modified date not changing due to the updates being too close together. sleep(1); - $loggings = $this->callAPISuccess('Logging', 'get', array('log_conn_id' => 'bitty bot bot', 'tables' => array('civicrm_address'))); + $loggings = $this->callAPISuccess('Logging', 'get', ['log_conn_id' => 'bitty bot bot', 'tables' => ['civicrm_address']]); $this->assertEquals('civicrm_address', $loggings['values'][0]['table'], CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray()); $this->assertEquals(1, $loggings['count'], CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray()); $this->assertEquals('27 Cool way', $loggings['values'][0]['from']); $this->assertEquals('25 Dorky way', $loggings['values'][0]['to']); - $this->callAPISuccess('Logging', 'revert', array('log_conn_id' => 'bitty bot bot', 'tables' => array('civicrm_address'))); + $this->callAPISuccess('Logging', 'revert', ['log_conn_id' => 'bitty bot bot', 'tables' => ['civicrm_address']]); - $contact = $this->callAPISuccessGetSingle('contact', array('id' => $contactId, 'return' => array('first_name', 'email', 'modified_date', 'street_address'))); + $contact = $this->callAPISuccessGetSingle('contact', ['id' => $contactId, 'return' => ['first_name', 'email', 'modified_date', 'street_address']]); $this->assertEquals('Dopey', $contact['first_name']); $this->assertEquals('dopey@mail.com', $contact['email']); $this->assertEquals('27 Cool way', $contact['street_address']); - $this->callAPISuccessGetCount('Contribution', array('contact_id' => $contactId), 1); + $this->callAPISuccessGetCount('Contribution', ['contact_id' => $contactId], 1); $this->assertTrue(strtotime($modifiedDate) < strtotime($contact['modified_date'])); } @@ -390,19 +390,19 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testRevertNoDateNotUnique() { $contactId = $this->individualCreate(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); CRM_Core_DAO::executeQuery("SET @uniqueID = 'Wopity woot'"); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'Dopey', - 'api.email.create' => array('email' => 'dopey@mail.com'), - )); - $this->callAPISuccess('Setting', 'create', array('logging_all_tables_uniquid' => FALSE)); - $this->callAPISuccess('Setting', 'create', array('logging_uniqueid_date' => date('Y-m-d H:i:s', strtotime('+ 1 hour')))); + 'api.email.create' => ['email' => 'dopey@mail.com'], + ]); + $this->callAPISuccess('Setting', 'create', ['logging_all_tables_uniquid' => FALSE]); + $this->callAPISuccess('Setting', 'create', ['logging_uniqueid_date' => date('Y-m-d H:i:s', strtotime('+ 1 hour'))]); $this->callAPIFailure( 'Logging', 'revert', - array('log_conn_id' => 'Wopity woot'), + ['log_conn_id' => 'Wopity woot'], 'The connection date must be passed in to disambiguate this logging entry per CRM-18193' ); } @@ -412,22 +412,22 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testGet() { $contactId = $this->individualCreate(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); CRM_Core_DAO::executeQuery("SET @uniqueID = 'wooty woot'"); // Add delay so the update is actually enough after the create that the timestamps differ sleep(1); $timeStamp = date('Y-m-d H:i:s'); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'Dopey', 'last_name' => 'Dwarf', - 'api.email.create' => array('email' => 'dopey@mail.com'), - )); - $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com')); - $diffs = $this->callAPISuccess('Logging', 'get', array('log_conn_id' => 'wooty woot', 'log_date' => $timeStamp), __FUNCTION__, __FILE__); - $this->assertLoggingIncludes($diffs['values'], array('to' => 'Dwarf, Dopey')); - $this->assertLoggingIncludes($diffs['values'], array('to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name')); - $this->assertLoggingIncludes($diffs['values'], array('to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email')); + 'api.email.create' => ['email' => 'dopey@mail.com'], + ]); + $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']); + $diffs = $this->callAPISuccess('Logging', 'get', ['log_conn_id' => 'wooty woot', 'log_date' => $timeStamp], __FUNCTION__, __FILE__); + $this->assertLoggingIncludes($diffs['values'], ['to' => 'Dwarf, Dopey']); + $this->assertLoggingIncludes($diffs['values'], ['to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name']); + $this->assertLoggingIncludes($diffs['values'], ['to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email']); } /** @@ -435,22 +435,22 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ public function testGetNoDate() { $contactId = $this->individualCreate(); - $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]); CRM_Core_DAO::executeQuery("SET @uniqueID = 'wooty wop wop'"); // Perhaps if initialize & create are exactly the same time it can't cope. // 1 second delay sleep(1); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'Dopey', 'last_name' => 'Dwarf', - 'api.email.create' => array('email' => 'dopey@mail.com'), - )); - $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com')); - $diffs = $this->callAPIAndDocument('Logging', 'get', array('log_conn_id' => 'wooty wop wop'), __FUNCTION__, __FILE__); - $this->assertLoggingIncludes($diffs['values'], array('to' => 'Dwarf, Dopey')); - $this->assertLoggingIncludes($diffs['values'], array('to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name')); - $this->assertLoggingIncludes($diffs['values'], array('to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email')); + 'api.email.create' => ['email' => 'dopey@mail.com'], + ]); + $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']); + $diffs = $this->callAPIAndDocument('Logging', 'get', ['log_conn_id' => 'wooty wop wop'], __FUNCTION__, __FILE__); + $this->assertLoggingIncludes($diffs['values'], ['to' => 'Dwarf, Dopey']); + $this->assertLoggingIncludes($diffs['values'], ['to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name']); + $this->assertLoggingIncludes($diffs['values'], ['to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email']); } /** diff --git a/tests/phpunit/api/v3/MailingABTest.php b/tests/phpunit/api/v3/MailingABTest.php index 98e6952ee1..39fc245793 100644 --- a/tests/phpunit/api/v3/MailingABTest.php +++ b/tests/phpunit/api/v3/MailingABTest.php @@ -56,7 +56,7 @@ class api_v3_MailingABTest extends CiviUnitTestCase { ]); $this->_groupID = $this->groupCreate(); - $this->_params = array( + $this->_params = [ 'mailing_id_a' => $this->_mailingID_A, 'mailing_id_b' => $this->_mailingID_B, 'mailing_id_c' => $this->_mailingID_C, @@ -64,7 +64,7 @@ class api_v3_MailingABTest extends CiviUnitTestCase { 'winner_criteria' => 'open', 'declare_winning_time' => '+2 days', 'group_percentage' => 10, - ); + ]; } /** @@ -82,25 +82,25 @@ class api_v3_MailingABTest extends CiviUnitTestCase { public function testMailerDeleteSuccess() { $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $this->assertDBQuery(1, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", array( - 1 => array($result['id'], 'Integer'), - )); - $this->assertDBQuery(3, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", array( - 1 => array($this->_mailingID_A, 'Integer'), - 2 => array($this->_mailingID_B, 'Integer'), - 3 => array($this->_mailingID_C, 'Integer'), - )); + $this->assertDBQuery(1, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", [ + 1 => [$result['id'], 'Integer'], + ]); + $this->assertDBQuery(3, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", [ + 1 => [$this->_mailingID_A, 'Integer'], + 2 => [$this->_mailingID_B, 'Integer'], + 3 => [$this->_mailingID_C, 'Integer'], + ]); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); - $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", array( - 1 => array($result['id'], 'Integer'), - )); - $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", array( - 1 => array($this->_mailingID_A, 'Integer'), - 2 => array($this->_mailingID_B, 'Integer'), - 3 => array($this->_mailingID_C, 'Integer'), - )); + $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", [ + 1 => [$result['id'], 'Integer'], + ]); + $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", [ + 1 => [$this->_mailingID_A, 'Integer'], + 2 => [$this->_mailingID_B, 'Integer'], + 3 => [$this->_mailingID_C, 'Integer'], + ]); } /** @@ -108,14 +108,14 @@ class api_v3_MailingABTest extends CiviUnitTestCase { */ public function groupPctProvider() { // array(int $totalSize, int $groupPct, int $expectedCountA, $expectedCountB, $expectedCountC) - $cases = array(); - $cases[] = array(400, 7, 28, 28, 344); - $cases[] = array(100, 10, 10, 10, 80); - $cases[] = array(50, 20, 10, 10, 30); - $cases[] = array(50, 10, 5, 5, 40); - $cases[] = array(3, 10, 1, 1, 1); - $cases[] = array(2, 10, 1, 1, 0); - $cases[] = array(1, 10, 1, 0, 0); + $cases = []; + $cases[] = [400, 7, 28, 28, 344]; + $cases[] = [100, 10, 10, 10, 80]; + $cases[] = [50, 20, 10, 10, 30]; + $cases[] = [50, 10, 5, 5, 40]; + $cases[] = [3, 10, 1, 1, 1]; + $cases[] = [2, 10, 1, 1, 0]; + $cases[] = [1, 10, 1, 0, 0]; return $cases; } @@ -138,27 +138,27 @@ class api_v3_MailingABTest extends CiviUnitTestCase { $params['group_percentage'] = $groupPct; $result = $this->callAPISuccess($this->_entity, 'create', $params); - $this->callAPISuccess('Mailing', 'create', array( + $this->callAPISuccess('Mailing', 'create', [ 'id' => $this->_mailingID_A, - 'groups' => array('include' => array($this->_groupID)), - )); + 'groups' => ['include' => [$this->_groupID]], + ]); $this->assertJobCounts(0, 0, 0); - $this->callAPISuccess('MailingAB', 'submit', array( + $this->callAPISuccess('MailingAB', 'submit', [ 'id' => $result['id'], 'status' => 'Testing', 'scheduled_date' => date('YmdHis'), 'approval_date' => date('YmdHis'), - )); + ]); $this->assertRecipientCounts($expectedCountA, $expectedCountB, $expectedCountC); $this->assertJobCounts(1, 1, 0); - $this->callAPISuccess('MailingAB', 'submit', array( + $this->callAPISuccess('MailingAB', 'submit', [ 'id' => $result['id'], 'status' => 'Final', 'scheduled_date' => date('YmdHis'), 'approval_date' => date('YmdHis'), - )); + ]); $this->assertRecipientCounts($expectedCountA, $expectedCountB, $expectedCountC); $this->assertJobCounts(1, 1, 1); } @@ -228,9 +228,9 @@ class api_v3_MailingABTest extends CiviUnitTestCase { * @param $expectedCountC */ protected function assertRecipientCounts($expectedCountA, $expectedCountB, $expectedCountC) { - $countA = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_A)); - $countB = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_B)); - $countC = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_C)); + $countA = $this->callAPISuccess('MailingRecipients', 'getcount', ['mailing_id' => $this->_mailingID_A]); + $countB = $this->callAPISuccess('MailingRecipients', 'getcount', ['mailing_id' => $this->_mailingID_B]); + $countC = $this->callAPISuccess('MailingRecipients', 'getcount', ['mailing_id' => $this->_mailingID_C]); $this->assertEquals($expectedCountA, $countA, "check mailing recipients A in line " . __LINE__); $this->assertEquals($expectedCountB, $countB, "check mailing recipients B in line " . __LINE__); $this->assertEquals($expectedCountC, $countC, "check mailing recipients C in line " . __LINE__); @@ -242,24 +242,24 @@ class api_v3_MailingABTest extends CiviUnitTestCase { * @param $expectedC */ protected function assertJobCounts($expectedA, $expectedB, $expectedC) { - $this->assertDBQuery($expectedA, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array( - 1 => array( + $this->assertDBQuery($expectedA, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [ + 1 => [ $this->_mailingID_A, 'Integer', - ), - )); - $this->assertDBQuery($expectedB, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array( - 1 => array( + ], + ]); + $this->assertDBQuery($expectedB, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [ + 1 => [ $this->_mailingID_B, 'Integer', - ), - )); - $this->assertDBQuery($expectedC, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array( - 1 => array( + ], + ]); + $this->assertDBQuery($expectedC, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [ + 1 => [ $this->_mailingID_C, 'Integer', - ), - )); + ], + ]); } } diff --git a/tests/phpunit/api/v3/MailingContactTest.php b/tests/phpunit/api/v3/MailingContactTest.php index 7ec969cac6..4892f933b3 100644 --- a/tests/phpunit/api/v3/MailingContactTest.php +++ b/tests/phpunit/api/v3/MailingContactTest.php @@ -72,9 +72,9 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { } public function testMailingContactGetFields() { - $result = $this->callAPISuccess('MailingContact', 'getfields', array( + $result = $this->callAPISuccess('MailingContact', 'getfields', [ 'action' => 'get', - )); + ]); $this->assertEquals('Delivered', $result['values']['type']['api.default']); } @@ -106,10 +106,10 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { * Test that invalid types are returned with appropriate errors. */ public function testMailingContactInvalidType() { - $params = array( + $params = [ 'contact_id' => 23, 'type' => 'invalid', - ); + ]; $this->callAPIFailure('MailingContact', 'get', $params); } @@ -117,9 +117,9 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { * Test for success result when there are no mailings for a the given contact. */ public function testMailingContactNoMailings() { - $params = array( + $params = [ 'contact_id' => $this->_contact['id'], - ); + ]; $result = $this->callAPISuccess('MailingContact', 'get', $params); $this->assertEquals($result['count'], 0); $this->assertTrue(empty($result['values'])); diff --git a/tests/phpunit/api/v3/MailingGroupTest.php b/tests/phpunit/api/v3/MailingGroupTest.php index 3dc7aec909..8dda19df4a 100644 --- a/tests/phpunit/api/v3/MailingGroupTest.php +++ b/tests/phpunit/api/v3/MailingGroupTest.php @@ -48,13 +48,13 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_subscribe with wrong params. */ public function testMailerGroupSubscribeWrongParams() { - $params = array( + $params = [ 'email' => $this->_email, 'group_id' => 'Wrong Group ID', 'contact_id' => '2121', 'time_stamp' => '20111111010101', 'hash' => 'sasa', - ); + ]; $this->callAPIFailure('mailing_event_subscribe', 'create', $params); } @@ -62,21 +62,21 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_subscribe with given contact ID. */ public function testMailerGroupSubscribeGivenContactId() { - $params = array( + $params = [ 'first_name' => 'Test', 'last_name' => 'Test', 'email' => $this->_email, 'contact_type' => 'Individual', - ); + ]; $contactID = $this->individualCreate($params); - $params = array( + $params = [ 'email' => $this->_email, 'group_id' => $this->_groupID, 'contact_id' => $contactID, 'hash' => 'b15de8b64e2cec34', 'time_stamp' => '20101212121212', - ); + ]; $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); @@ -87,12 +87,12 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_unsubscribe with wrong params. */ public function testMailerGroupUnsubscribeWrongParams() { - $params = array( + $params = [ 'job_id' => 'Wrong ID', 'event_queue_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'time_stamp' => '20101212121212', - ); + ]; $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); } @@ -101,13 +101,13 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params. */ public function testMailerGroupDomainUnsubscribeWrongParams() { - $params = array( + $params = [ 'job_id' => 'Wrong ID', 'event_queue_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'org_unsubscribe' => 1, 'time_stamp' => '20101212121212', - ); + ]; $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); } @@ -120,13 +120,13 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_resubscribe with wrong params. */ public function testMailerGroupResubscribeWrongParams() { - $params = array( + $params = [ 'job_id' => 'Wrong ID', 'event_queue_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'org_unsubscribe' => 'test', 'time_stamp' => '20101212121212', - ); + ]; $this->callAPIFailure('mailing_event_resubscribe', 'create', $params); } @@ -134,32 +134,32 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected. */ public function testMailerProcess() { - $params = array( + $params = [ 'first_name' => 'Test', 'last_name' => 'Test', 'email' => $this->_email, 'contact_type' => 'Individual', - ); + ]; $contactID = $this->individualCreate($params); - $params = array( + $params = [ 'email' => $this->_email, 'group_id' => $this->_groupID, 'contact_id' => $contactID, 'hash' => 'b15de8b64e2cec34', 'time_stamp' => '20101212121212', - ); + ]; $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params); $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); - $params = array( + $params = [ 'contact_id' => $result['values'][$result['id']]['contact_id'], 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'], 'hash' => $result['values'][$result['id']]['hash'], 'time_stamp' => '20101212121212', 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'], - ); + ]; $this->callAPISuccess('mailing_event_confirm', 'create', $params); $this->contactDelete($contactID); diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index e72fc5097e..f8e1d8bc2c 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -34,7 +34,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { protected $_groupID; protected $_email; protected $_apiversion = 3; - protected $_params = array(); + protected $_params = []; protected $_entity = 'Mailing'; protected $_contactID; @@ -52,7 +52,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { $this->_contactID = $this->individualCreate(); $this->_groupID = $this->groupCreate(); $this->_email = 'test@test.test'; - $this->_params = array( + $this->_params = [ 'subject' => 'Hello {contact.display_name}', 'body_text' => "This is {contact.display_name}.\nhttps://civicrm.org\n{domain.address}{action.optOutUrl}", 'body_html' => "

Forward this emailForward this email with no protocolThis is {contact.display_name}.

CiviCRM.org

{domain.address}{action.optOutUrl}

", @@ -60,14 +60,14 @@ class api_v3_MailingTest extends CiviUnitTestCase { 'created_id' => $this->_contactID, 'header_id' => '', 'footer_id' => '', - ); + ]; - $this->footer = civicrm_api3('MailingComponent', 'create', array( + $this->footer = civicrm_api3('MailingComponent', 'create', [ 'name' => 'test domain footer', 'component_type' => 'footer', 'body_html' => '

From {domain.address}. To opt out, go to {action.optOutUrl}.

', 'body_text' => 'From {domain.address}. To opt out, go to {action.optOutUrl}.', - )); + ]); } public function tearDown() { @@ -80,8 +80,8 @@ class api_v3_MailingTest extends CiviUnitTestCase { * Test civicrm_mailing_create. */ public function testMailerCreateSuccess() { - $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); + $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]); $this->assertEquals(1, $jobs['count']); // return isn't working on this in getAndCheck so lets not check it for now unset($this->_params['created_id']); @@ -106,8 +106,8 @@ class api_v3_MailingTest extends CiviUnitTestCase { public function testMailerCreateCompleted() { $this->_params['body_html'] = 'I am completed so it does not matter if there is an opt out link since I have already been sent by another system'; $this->_params['is_completed'] = 1; - $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); + $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]); $this->assertEquals(1, $jobs['count']); $this->assertEquals('Complete', $jobs['values'][$jobs['id']]['status']); // return isn't working on this in getAndCheck so lets not check it for now @@ -120,7 +120,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { */ public function testMailerCreateSuccessNoCreatedID() { unset($this->_params['created_id']); - $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__); $this->getAndCheck($this->_params, $result['id'], 'mailing'); } @@ -128,7 +128,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { * */ public function testTemplateTypeOptions() { - $types = $this->callAPISuccess('Mailing', 'getoptions', array('field' => 'template_type')); + $types = $this->callAPISuccess('Mailing', 'getoptions', ['field' => 'template_type']); $this->assertTrue(isset($types['values']['traditional'])); } @@ -140,33 +140,33 @@ class api_v3_MailingTest extends CiviUnitTestCase { public function testMailerCreateTemplateOptions() { // 1. Create mailing with template_options. $params = $this->_params; - $params['template_options'] = json_encode(array('foo' => 'bar_1')); + $params['template_options'] = json_encode(['foo' => 'bar_1']); $createResult = $this->callAPISuccess('mailing', 'create', $params); $id = $createResult['id']; - $this->assertDBQuery('{"foo":"bar_1"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', array( - 1 => array($id, 'Int'), - )); + $this->assertDBQuery('{"foo":"bar_1"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', [ + 1 => [$id, 'Int'], + ]); $this->assertEquals('bar_1', $createResult['values'][$id]['template_options']['foo']); // 2. Get mailing with template_options. - $getResult = $this->callAPISuccess('mailing', 'get', array( + $getResult = $this->callAPISuccess('mailing', 'get', [ 'id' => $id, - )); + ]); $this->assertEquals('bar_1', $getResult['values'][$id]['template_options']['foo']); - $getValueResult = $this->callAPISuccess('mailing', 'getvalue', array( + $getValueResult = $this->callAPISuccess('mailing', 'getvalue', [ 'id' => $id, 'return' => 'template_options', - )); + ]); $this->assertEquals('bar_1', $getValueResult['foo']); // 3. Update mailing with template_options. - $updateResult = $this->callAPISuccess('mailing', 'create', array( + $updateResult = $this->callAPISuccess('mailing', 'create', [ 'id' => $id, - 'template_options' => array('foo' => 'bar_2'), - )); - $this->assertDBQuery('{"foo":"bar_2"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', array( - 1 => array($id, 'Int'), - )); + 'template_options' => ['foo' => 'bar_2'], + ]); + $this->assertDBQuery('{"foo":"bar_2"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', [ + 1 => [$id, 'Int'], + ]); $this->assertEquals('bar_2', $updateResult['values'][$id]['template_options']['foo']); } @@ -176,25 +176,25 @@ class api_v3_MailingTest extends CiviUnitTestCase { */ public function testMagicGroups_create_update() { // BEGIN SAMPLE DATA - $groupIDs['a'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group')); - $groupIDs['b'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group')); - $contactIDs['a'] = $this->individualCreate(array( + $groupIDs['a'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']); + $groupIDs['b'] = $this->groupCreate(['name' => 'Example exclude group', 'title' => 'Example exclude group']); + $contactIDs['a'] = $this->individualCreate([ 'email' => 'include.me@example.org', 'first_name' => 'Includer', 'last_name' => 'Person', - )); - $contactIDs['b'] = $this->individualCreate(array( + ]); + $contactIDs['b'] = $this->individualCreate([ 'email' => 'exclude.me@example.org', 'last_name' => 'Excluder', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['a'], 'contact_id' => $contactIDs['a'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['b'], 'contact_id' => $contactIDs['b'], - )); + ]); // END SAMPLE DATA // ** Pass 1: Create @@ -205,12 +205,12 @@ class api_v3_MailingTest extends CiviUnitTestCase { $createParams['mailings']['exclude'] = []; $createParams['scheduled_date'] = 'now'; $createResult = $this->callAPISuccess('Mailing', 'create', $createParams); - $getGroup1 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id'])); + $getGroup1 = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $createResult['id']]); $getGroup1_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup1['values'])); - $this->assertEquals(array($groupIDs['a']), $getGroup1_ids); - $getRecipient1 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id'])); + $this->assertEquals([$groupIDs['a']], $getGroup1_ids); + $getRecipient1 = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $createResult['id']]); $getRecipient1_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient1['values'])); - $this->assertEquals(array($contactIDs['a']), $getRecipient1_ids); + $this->assertEquals([$contactIDs['a']], $getRecipient1_ids); // ** Pass 2: Update without any changes to groups[include] $nullOpParams = $createParams; @@ -218,48 +218,48 @@ class api_v3_MailingTest extends CiviUnitTestCase { $updateParams['api.mailing_job.create'] = 1; unset($nullOpParams['groups']['include']); $this->callAPISuccess('Mailing', 'create', $nullOpParams); - $getGroup2 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id'])); + $getGroup2 = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $createResult['id']]); $getGroup2_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup2['values'])); - $this->assertEquals(array($groupIDs['a']), $getGroup2_ids); - $getRecipient2 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id'])); + $this->assertEquals([$groupIDs['a']], $getGroup2_ids); + $getRecipient2 = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $createResult['id']]); $getRecip2_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient2['values'])); - $this->assertEquals(array($contactIDs['a']), $getRecip2_ids); + $this->assertEquals([$contactIDs['a']], $getRecip2_ids); // ** Pass 3: Update with different groups[include] $updateParams = $createParams; $updateParams['id'] = $createResult['id']; - $updateParams['groups']['include'] = array($groupIDs['b']); + $updateParams['groups']['include'] = [$groupIDs['b']]; $updateParams['scheduled_date'] = 'now'; $this->callAPISuccess('Mailing', 'create', $updateParams); - $getGroup3 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id'])); + $getGroup3 = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $createResult['id']]); $getGroup3_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup3['values'])); - $this->assertEquals(array($groupIDs['b']), $getGroup3_ids); - $getRecipient3 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id'])); + $this->assertEquals([$groupIDs['b']], $getGroup3_ids); + $getRecipient3 = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $createResult['id']]); $getRecipient3_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient3['values'])); - $this->assertEquals(array($contactIDs['b']), $getRecipient3_ids); + $this->assertEquals([$contactIDs['b']], $getRecipient3_ids); } public function testMailerPreview() { // BEGIN SAMPLE DATA $contactID = $this->individualCreate(); - $displayName = $this->callAPISuccess('contact', 'get', array('id' => $contactID)); + $displayName = $this->callAPISuccess('contact', 'get', ['id' => $contactID]); $displayName = $displayName['values'][$contactID]['display_name']; $this->assertTrue(!empty($displayName)); $params = $this->_params; - $params['api.Mailing.preview'] = array( + $params['api.Mailing.preview'] = [ 'id' => '$value.id', 'contact_id' => $contactID, - ); + ]; $params['options']['force_rollback'] = 1; // END SAMPLE DATA - $maxIDs = array( + $maxIDs = [ 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'), 'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'), 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'), 'recipient' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_recipients'), - ); + ]; $result = $this->callAPISuccess('mailing', 'create', $params); // 'Preview should not create any mailing records' $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); @@ -280,9 +280,9 @@ class api_v3_MailingTest extends CiviUnitTestCase { public function testMailerPreviewUnknownContact() { $params = $this->_params; - $params['api.Mailing.preview'] = array( + $params['api.Mailing.preview'] = [ 'id' => '$value.id', - ); + ]; $result = $this->callAPISuccess('mailing', 'create', $params); @@ -297,51 +297,51 @@ class api_v3_MailingTest extends CiviUnitTestCase { public function testMailerPreviewRecipients() { // BEGIN SAMPLE DATA - $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group')); - $groupIDs['exc'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group')); - $contactIDs['include_me'] = $this->individualCreate(array( + $groupIDs['inc'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']); + $groupIDs['exc'] = $this->groupCreate(['name' => 'Example exclude group', 'title' => 'Example exclude group']); + $contactIDs['include_me'] = $this->individualCreate([ 'email' => 'include.me@example.org', 'first_name' => 'Includer', 'last_name' => 'Person', - )); - $contactIDs['exclude_me'] = $this->individualCreate(array( + ]); + $contactIDs['exclude_me'] = $this->individualCreate([ 'email' => 'exclude.me@example.org', 'last_name' => 'Excluder', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['inc'], 'contact_id' => $contactIDs['include_me'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['inc'], 'contact_id' => $contactIDs['exclude_me'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['exc'], 'contact_id' => $contactIDs['exclude_me'], - )); + ]); $params = $this->_params; - $params['groups']['include'] = array($groupIDs['inc']); - $params['groups']['exclude'] = array($groupIDs['exc']); - $params['mailings']['include'] = array(); - $params['mailings']['exclude'] = array(); + $params['groups']['include'] = [$groupIDs['inc']]; + $params['groups']['exclude'] = [$groupIDs['exc']]; + $params['mailings']['include'] = []; + $params['mailings']['exclude'] = []; $params['options']['force_rollback'] = 1; - $params['api.MailingRecipients.get'] = array( + $params['api.MailingRecipients.get'] = [ 'mailing_id' => '$value.id', - 'api.contact.getvalue' => array( + 'api.contact.getvalue' => [ 'return' => 'display_name', - ), - 'api.email.getvalue' => array( + ], + 'api.email.getvalue' => [ 'return' => 'email', - ), - ); + ], + ]; // END SAMPLE DATA - $maxIDs = array( + $maxIDs = [ 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'), 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'), - ); + ]; $create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__); // 'Preview should not create any mailing records' $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); @@ -350,9 +350,9 @@ class api_v3_MailingTest extends CiviUnitTestCase { $preview = $create['values'][$create['id']]['api.MailingRecipients.get']; $previewIds = array_values(CRM_Utils_Array::collect('contact_id', $preview['values'])); - $this->assertEquals(array((string) $contactIDs['include_me']), $previewIds); + $this->assertEquals([(string) $contactIDs['include_me']], $previewIds); $previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values'])); - $this->assertEquals(array('include.me@example.org'), $previewEmails); + $this->assertEquals(['include.me@example.org'], $previewEmails); $previewNames = array_values(CRM_Utils_Array::collect('api.contact.getvalue', $preview['values'])); $this->assertTrue((bool) preg_match('/Includer Person/', $previewNames[0]), "Name 'Includer Person' should appear in '" . $previewNames[0] . '"'); } @@ -362,59 +362,59 @@ class api_v3_MailingTest extends CiviUnitTestCase { */ public function testMailerPreviewRecipientsDeduplicateAndOnholdEmails() { // BEGIN SAMPLE DATA - $groupIDs['grp'] = $this->groupCreate(array('name' => 'Example group', 'title' => 'Example group')); - $contactIDs['include_me'] = $this->individualCreate(array( + $groupIDs['grp'] = $this->groupCreate(['name' => 'Example group', 'title' => 'Example group']); + $contactIDs['include_me'] = $this->individualCreate([ 'email' => 'include.me@example.org', 'first_name' => 'Includer', 'last_name' => 'Person', - )); - $contactIDs['include_me_duplicate'] = $this->individualCreate(array( + ]); + $contactIDs['include_me_duplicate'] = $this->individualCreate([ 'email' => 'include.me@example.org', 'first_name' => 'IncluderDuplicate', 'last_name' => 'Person', - )); + ]); - $contactIDs['include_me_onhold'] = $this->individualCreate(array( + $contactIDs['include_me_onhold'] = $this->individualCreate([ 'email' => 'onholdinclude.me@example.org', 'first_name' => 'Onhold', 'last_name' => 'Person', - )); - $emailId = $this->callAPISuccessGetValue('Email', array( + ]); + $emailId = $this->callAPISuccessGetValue('Email', [ 'return' => 'id', 'contact_id' => $contactIDs['include_me_onhold'], - )); - $this->callAPISuccess('Email', 'create', array( + ]); + $this->callAPISuccess('Email', 'create', [ 'id' => $emailId, 'on_hold' => 1, - )); + ]); - $this->callAPISuccess('GroupContact', 'create', array( + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['grp'], 'contact_id' => $contactIDs['include_me'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['grp'], 'contact_id' => $contactIDs['include_me_duplicate'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['grp'], 'contact_id' => $contactIDs['include_me_onhold'], - )); + ]); $params = $this->_params; - $params['groups']['include'] = array($groupIDs['grp']); - $params['mailings']['include'] = array(); + $params['groups']['include'] = [$groupIDs['grp']]; + $params['mailings']['include'] = []; $params['options']['force_rollback'] = 1; $params['dedupe_email'] = 1; - $params['api.MailingRecipients.get'] = array( + $params['api.MailingRecipients.get'] = [ 'mailing_id' => '$value.id', - 'api.contact.getvalue' => array( + 'api.contact.getvalue' => [ 'return' => 'display_name', - ), - 'api.email.getvalue' => array( + ], + 'api.email.getvalue' => [ 'return' => 'email', - ), - ); + ], + ]; // END SAMPLE DATA $create = $this->callAPISuccess('Mailing', 'create', $params); @@ -423,22 +423,22 @@ class api_v3_MailingTest extends CiviUnitTestCase { $preview = $create['values'][$create['id']]['api.MailingRecipients.get']; $this->assertEquals(1, $preview['count']); $previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values'])); - $this->assertEquals(array('include.me@example.org'), $previewEmails); + $this->assertEquals(['include.me@example.org'], $previewEmails); } /** * Test sending a test mailing. */ public function testMailerSendTest_email() { - $contactIDs['alice'] = $this->individualCreate(array( + $contactIDs['alice'] = $this->individualCreate([ 'email' => 'alice@example.org', 'first_name' => 'Alice', 'last_name' => 'Person', - )); + ]); $mail = $this->callAPISuccess('mailing', 'create', $this->_params); - $params = array('mailing_id' => $mail['id'], 'test_email' => 'ALicE@example.org', 'test_group' => NULL); + $params = ['mailing_id' => $mail['id'], 'test_email' => 'ALicE@example.org', 'test_group' => NULL]; // Per https://lab.civicrm.org/dev/core/issues/229 ensure this is not passed through! // Per https://lab.civicrm.org/dev/mail/issues/32 test non-lowercase email $params['id'] = $mail['id']; @@ -447,10 +447,10 @@ class api_v3_MailingTest extends CiviUnitTestCase { $this->assertEquals(1, $deliveredInfo['count']); $deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values'])); - $this->assertEquals(array($contactIDs['alice']), $deliveredContacts); + $this->assertEquals([$contactIDs['alice']], $deliveredContacts); $deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values'])); - $this->assertEquals(array('alice@example.org'), $deliveredEmails); + $this->assertEquals(['alice@example.org'], $deliveredEmails); } /** @@ -458,50 +458,50 @@ class api_v3_MailingTest extends CiviUnitTestCase { */ public function testMailerSendTest_group() { // BEGIN SAMPLE DATA - $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group')); - $contactIDs['alice'] = $this->individualCreate(array( + $groupIDs['inc'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']); + $contactIDs['alice'] = $this->individualCreate([ 'email' => 'alice@example.org', 'first_name' => 'Alice', 'last_name' => 'Person', - )); - $contactIDs['bob'] = $this->individualCreate(array( + ]); + $contactIDs['bob'] = $this->individualCreate([ 'email' => 'bob@example.org', 'first_name' => 'Bob', 'last_name' => 'Person', - )); - $contactIDs['carol'] = $this->individualCreate(array( + ]); + $contactIDs['carol'] = $this->individualCreate([ 'email' => 'carol@example.org', 'first_name' => 'Carol', 'last_name' => 'Person', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['inc'], 'contact_id' => $contactIDs['alice'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['inc'], 'contact_id' => $contactIDs['bob'], - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['inc'], 'contact_id' => $contactIDs['carol'], - )); + ]); // END SAMPLE DATA $mail = $this->callAPISuccess('mailing', 'create', $this->_params); - $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', array( + $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', [ 'mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $groupIDs['inc'], - )); + ]); // verify mail has been sent to user by count $this->assertEquals(3, $deliveredInfo['count'], "in line " . __LINE__); $deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values'])); - $this->assertEquals(array($contactIDs['alice'], $contactIDs['bob'], $contactIDs['carol']), $deliveredContacts); + $this->assertEquals([$contactIDs['alice'], $contactIDs['bob'], $contactIDs['carol']], $deliveredContacts); $deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values'])); - $this->assertEquals(array('alice@example.org', 'bob@example.org', 'carol@example.org'), $deliveredEmails); + $this->assertEquals(['alice@example.org', 'bob@example.org', 'carol@example.org'], $deliveredEmails); } /** @@ -509,117 +509,117 @@ class api_v3_MailingTest extends CiviUnitTestCase { */ public function submitProvider() { // $useLogin, $params, $expectedFailure, $expectedJobCount - $cases = array(); - $cases[] = array( + $cases = []; + $cases[] = [ //useLogin TRUE, // createParams - array(), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + [], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure FALSE, // expectedJobCount 1, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin FALSE, // createParams - array(), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + [], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure "/Failed to determine current user/", // expectedJobCount 0, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array(), - array('scheduled_date' => '2014-12-13 10:00:00'), + [], + ['scheduled_date' => '2014-12-13 10:00:00'], // expectedFailure FALSE, // expectedJobCount 1, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array(), - array(), + [], + [], // expectedFailure "/Missing parameter scheduled_date and.or approval_date/", // expectedJobCount 0, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array('name' => ''), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + ['name' => ''], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure "/Mailing cannot be sent. There are missing or invalid fields \\(name\\)./", // expectedJobCount 0, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array('body_html' => '', 'body_text' => ''), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + ['body_html' => '', 'body_text' => ''], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure "/Mailing cannot be sent. There are missing or invalid fields \\(body\\)./", // expectedJobCount 0, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array('body_html' => 'Oops, did I leave my tokens at home?'), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + ['body_html' => 'Oops, did I leave my tokens at home?'], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure "/Mailing cannot be sent. There are missing or invalid fields \\(.*body_html.*optOut.*\\)./", // expectedJobCount 0, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array('body_text' => 'Oops, did I leave my tokens at home?'), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + ['body_text' => 'Oops, did I leave my tokens at home?'], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure "/Mailing cannot be sent. There are missing or invalid fields \\(.*body_text.*optOut.*\\)./", // expectedJobCount 0, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array('body_text' => 'Look ma, magic tokens in the text!', 'footer_id' => '%FOOTER%'), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + ['body_text' => 'Look ma, magic tokens in the text!', 'footer_id' => '%FOOTER%'], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure FALSE, // expectedJobCount 1, - ); - $cases[] = array( + ]; + $cases[] = [ //useLogin TRUE, // createParams - array('body_html' => '

Look ma, magic tokens in the markup!

', 'footer_id' => '%FOOTER%'), - array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'), + ['body_html' => '

Look ma, magic tokens in the markup!

', 'footer_id' => '%FOOTER%'], + ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'], // expectedFailure FALSE, // expectedJobCount 1, - ); + ]; return $cases; } @@ -653,9 +653,9 @@ class api_v3_MailingTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($submitResult['values'][$id]['scheduled_id'])); $this->assertEquals($submitParams['scheduled_date'], $submitResult['values'][$id]['scheduled_date']); } - $this->assertDBQuery($expectedJobCount, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array( - 1 => array($id, 'Integer'), - )); + $this->assertDBQuery($expectedJobCount, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [ + 1 => [$id, 'Integer'], + ]); } /** @@ -664,44 +664,44 @@ class api_v3_MailingTest extends CiviUnitTestCase { */ public function testUnsubscribeGroupList() { // Create set of groups and add a contact to both of them. - $groupID2 = $this->groupCreate(array('name' => 'Test group 2', 'title' => 'group title 2')); - $groupID3 = $this->groupCreate(array('name' => 'Test group 3', 'title' => 'group title 3')); + $groupID2 = $this->groupCreate(['name' => 'Test group 2', 'title' => 'group title 2']); + $groupID3 = $this->groupCreate(['name' => 'Test group 3', 'title' => 'group title 3']); $contactId = $this->individualCreate(); - foreach (array($groupID2, $groupID3) as $grp) { - $params = array( + foreach ([$groupID2, $groupID3] as $grp) { + $params = [ 'contact_id' => $contactId, 'group_id' => $grp, - ); + ]; $this->callAPISuccess('GroupContact', 'create', $params); } //Send mail to groupID3 $mail = $this->callAPISuccess('mailing', 'create', $this->_params); - $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $groupID3); + $params = ['mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $groupID3]; $this->callAPISuccess($this->_entity, 'send_test', $params); - $mgParams = array( + $mgParams = [ 'mailing_id' => $mail['id'], 'entity_table' => 'civicrm_group', 'entity_id' => $groupID3, 'group_type' => 'Include', - ); + ]; $mailingGroup = $this->callAPISuccess('MailingGroup', 'create', $mgParams); //Include previous mail in the mailing group. $mail2 = $this->callAPISuccess('mailing', 'create', $this->_params); - $params = array('mailing_id' => $mail2['id'], 'test_email' => NULL, 'test_group' => $groupID3); + $params = ['mailing_id' => $mail2['id'], 'test_email' => NULL, 'test_group' => $groupID3]; $this->callAPISuccess($this->_entity, 'send_test', $params); - $mgParams = array( + $mgParams = [ 'mailing_id' => $mail2['id'], 'entity_table' => 'civicrm_mailing', 'entity_id' => $mail['id'], 'group_type' => 'Include', - ); + ]; $mailingGroup = $this->callAPISuccess('MailingGroup', 'create', $mgParams); //CRM-20431 - Delete group id that matches first mailing id. - $this->callAPISuccess('Group', 'delete', array('id' => $this->_groupID)); + $this->callAPISuccess('Group', 'delete', ['id' => $this->_groupID]); $jobId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingJob', $mail2['id'], 'id', 'mailing_id'); $hash = CRM_Core_DAO::getFieldValue('CRM_Mailing_Event_DAO_Queue', $jobId, 'hash', 'job_id'); $queueId = CRM_Core_DAO::getFieldValue('CRM_Mailing_Event_DAO_Queue', $jobId, 'id', 'job_id'); @@ -723,7 +723,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { //Create and send test mail first and change the mail job to live, //because stats api only works on live mail $mail = $this->callAPISuccess('mailing', 'create', $this->_params); - $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $this->_groupID); + $params = ['mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $this->_groupID]; $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params); $deliveredIds = implode(',', array_keys($deliveredInfo['values'])); @@ -731,7 +731,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { $sql = "UPDATE civicrm_mailing_job SET is_test = 0 WHERE mailing_id = {$mail['id']}"; CRM_Core_DAO::executeQuery($sql); - foreach (array('bounce', 'unsubscribe', 'opened') as $type) { + foreach (['bounce', 'unsubscribe', 'opened'] as $type) { $sql = "CREATE TEMPORARY TABLE mail_{$type}_temp (event_queue_id int, time_stamp datetime, delivered_id int) SELECT event_queue_id, time_stamp, id @@ -754,8 +754,8 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; CRM_Core_DAO::executeQuery($sql); } - $result = $this->callAPISuccess('mailing', 'stats', array('mailing_id' => $mail['id'])); - $expectedResult = array( + $result = $this->callAPISuccess('mailing', 'stats', ['mailing_id' => $mail['id']]); + $expectedResult = [ //since among 100 mails 20 has been bounced 'Delivered' => 80, 'Bounces' => 20, @@ -765,7 +765,7 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; 'delivered_rate' => '80%', 'opened_rate' => '25%', 'clickthrough_rate' => '0%', - ); + ]; $this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]); } @@ -774,7 +774,7 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; */ public function testMailerDeleteSuccess() { $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__); + $this->callAPIAndDocument($this->_entity, 'delete', ['id' => $result['id']], __FUNCTION__, __FILE__); $this->assertAPIDeleted($this->_entity, $result['id']); } @@ -784,40 +784,40 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; public function testMailGetTokens() { $description = "Demonstrates fetching tokens for one or more entities (in this case \"Contact\" and \"Mailing\"). Optionally pass sequential=1 to have output ready-formatted for the select2 widget."; - $result = $this->callAPIAndDocument($this->_entity, 'gettokens', array('entity' => array('Contact', 'Mailing')), __FUNCTION__, __FILE__, $description); + $result = $this->callAPIAndDocument($this->_entity, 'gettokens', ['entity' => ['Contact', 'Mailing']], __FUNCTION__, __FILE__, $description); $this->assertContains('Contact Type', $result['values']); // Check that passing "sequential" correctly outputs a hierarchical array - $result = $this->callAPISuccess($this->_entity, 'gettokens', array('entity' => 'contact', 'sequential' => 1)); + $result = $this->callAPISuccess($this->_entity, 'gettokens', ['entity' => 'contact', 'sequential' => 1]); $this->assertArrayHasKey('text', $result['values'][0]); $this->assertArrayHasKey('id', $result['values'][0]['children'][0]); } public function testClone() { // BEGIN SAMPLE DATA - $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group')); - $contactIDs['include_me'] = $this->individualCreate(array( + $groupIDs['inc'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']); + $contactIDs['include_me'] = $this->individualCreate([ 'email' => 'include.me@example.org', 'first_name' => 'Includer', 'last_name' => 'Person', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupIDs['inc'], 'contact_id' => $contactIDs['include_me'], - )); + ]); $params = $this->_params; - $params['groups']['include'] = array($groupIDs['inc']); - $params['groups']['exclude'] = array(); - $params['mailings']['include'] = array(); - $params['mailings']['exclude'] = array(); + $params['groups']['include'] = [$groupIDs['inc']]; + $params['groups']['exclude'] = []; + $params['mailings']['include'] = []; + $params['mailings']['exclude'] = []; // END SAMPLE DATA $create = $this->callAPISuccess('Mailing', 'create', $params); $created = $this->callAPISuccess('Mailing', 'get', []); $createId = $create['id']; $this->createLoggedInUser(); - $clone = $this->callAPIAndDocument('Mailing', 'clone', array('id' => $create['id']), __FUNCTION__, __FILE__); + $clone = $this->callAPIAndDocument('Mailing', 'clone', ['id' => $create['id']], __FUNCTION__, __FILE__); $cloneId = $clone['id']; $this->assertNotEquals($createId, $cloneId, 'Create and clone should return different records'); @@ -831,7 +831,7 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; $this->assertNotEquals($create['values'][$createId]['created_id'], $clone['values'][$cloneId]['created_id'], 'Clone should be created by a different person'); // Target groups+mailings are special. - $cloneGroups = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $cloneId, 'sequential' => 1)); + $cloneGroups = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $cloneId, 'sequential' => 1]); $this->assertEquals(1, $cloneGroups['count']); $this->assertEquals($cloneGroups['values'][0]['group_type'], 'Include'); $this->assertEquals($cloneGroups['values'][0]['entity_table'], 'civicrm_group'); @@ -849,13 +849,13 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * success test */ public function testMailerBounceWrongParams() { - $params = array( + $params = [ 'job_id' => 'Wrong ID', 'event_queue_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'body' => 'Body...', 'time_stamp' => '20111109212100', - ); + ]; $this->callAPIFailure('mailing_event', 'bounce', $params, 'Queue event could not be found' ); @@ -870,13 +870,13 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * success test */ public function testMailerConfirmWrongParams() { - $params = array( + $params = [ 'contact_id' => 'Wrong ID', 'subscribe_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'event_subscribe_id' => '123', 'time_stamp' => '20111111010101', - ); + ]; $this->callAPIFailure('mailing_event', 'confirm', $params, 'contact_id is not a valid integer' ); @@ -892,14 +892,14 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * success test */ public function testMailerReplyWrongParams() { - $params = array( + $params = [ 'job_id' => 'Wrong ID', 'event_queue_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'bodyTxt' => 'Body...', 'replyTo' => $this->_email, 'time_stamp' => '20111111010101', - ); + ]; $this->callAPIFailure('mailing_event', 'reply', $params, 'Queue event could not be found' ); @@ -914,13 +914,13 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * success test */ public function testMailerForwardWrongParams() { - $params = array( + $params = [ 'job_id' => 'Wrong ID', 'event_queue_id' => 'Wrong ID', 'hash' => 'Wrong Hash', 'email' => $this->_email, 'time_stamp' => '20111111010101', - ); + ]; $this->callAPIFailure('mailing_event', 'forward', $params, 'Queue event could not be found' ); @@ -931,13 +931,13 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * Extra parameters for the draft mailing. * @return array|int */ - public function createDraftMailing($params = array()) { + public function createDraftMailing($params = []) { $createParams = array_merge($this->_params, $params); $createResult = $this->callAPISuccess('mailing', 'create', $createParams, __FUNCTION__, __FILE__); $this->assertTrue(is_numeric($createResult['id'])); - $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array( - 1 => array($createResult['id'], 'Integer'), - )); + $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [ + 1 => [$createResult['id'], 'Integer'], + ]); return $createResult['id']; } @@ -946,11 +946,11 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * we can still have working click-trough URLs working (CRM-17959). */ public function testUrlWithMissingTrackingHash() { - $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); - $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $mail['id'])); + $mail = $this->callAPISuccess('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__); + $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $mail['id']]); $this->assertEquals(1, $jobs['count']); - $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL); + $params = ['mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL]; $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params); $sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id @@ -984,9 +984,9 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; $this->_params['body_text'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_text']); $this->_params['body_html'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_html']); - $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now')); + $mail = $this->callAPISuccess('mailing', 'create', $this->_params + ['scheduled_date' => 'now']); - $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL); + $params = ['mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL]; $this->callAPISuccess($this->_entity, 'send_test', $params); $sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id @@ -1013,9 +1013,9 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * if modified_date less then the date when the mail was last updated/created */ public function testModifiedDateMismatchOnMailingUpdate() { - $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('modified_date' => 'now')); + $mail = $this->callAPISuccess('mailing', 'create', $this->_params + ['modified_date' => 'now']); try { - $this->callAPISuccess('mailing', 'create', $this->_params + array('id' => $mail['id'], 'modified_date' => '2 seconds ago')); + $this->callAPISuccess('mailing', 'create', $this->_params + ['id' => $mail['id'], 'modified_date' => '2 seconds ago']); } catch (Exception $e) { $this->assertRegExp("/Failure in api call for mailing create: Mailing has not been saved, Content maybe out of date, please refresh the page and try again/", $e->getMessage()); diff --git a/tests/phpunit/api/v3/MappingFieldTest.php b/tests/phpunit/api/v3/MappingFieldTest.php index 23a1a28dc0..f6d07b5d51 100644 --- a/tests/phpunit/api/v3/MappingFieldTest.php +++ b/tests/phpunit/api/v3/MappingFieldTest.php @@ -47,13 +47,13 @@ class api_v3_MappingFieldTest extends CiviUnitTestCase { $this->_entity = 'mapping_field'; $mappingID = $this->mappingCreate(); - $this->params = array( + $this->params = [ 'mapping_id' => $mappingID->id, 'name' => 'last_name', 'contact_type' => 'Individual', 'column_number' => 2, 'grouping' => 1, - ); + ]; } public function testCreateMappingField() { @@ -68,22 +68,22 @@ class api_v3_MappingFieldTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } public function testDeleteMappingField() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); + $deleteParams = ['id' => $result['id']]; $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } public function testDeleteMappingFieldInvalid() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => 600); + $deleteParams = ['id' => 600]; $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(1, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/MappingTest.php b/tests/phpunit/api/v3/MappingTest.php index eedb794030..22e3ccef16 100644 --- a/tests/phpunit/api/v3/MappingTest.php +++ b/tests/phpunit/api/v3/MappingTest.php @@ -46,12 +46,12 @@ class api_v3_MappingTest extends CiviUnitTestCase { $this->useTransaction(TRUE); $this->_entity = 'mapping'; - $this->params = array( + $this->params = [ 'name' => 'Mapping name', 'description' => 'Mapping description', // 'Export Contact' mapping. 'mapping_type_id' => 7, - ); + ]; } public function testCreateMapping() { @@ -66,22 +66,22 @@ class api_v3_MappingTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } public function testDeleteMapping() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); + $deleteParams = ['id' => $result['id']]; $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } public function testDeleteMappingInvalid() { $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => 600); + $deleteParams = ['id' => 600]; $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(1, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/MembershipPaymentTest.php b/tests/phpunit/api/v3/MembershipPaymentTest.php index 59bea92ed9..5bc11ade1b 100644 --- a/tests/phpunit/api/v3/MembershipPaymentTest.php +++ b/tests/phpunit/api/v3/MembershipPaymentTest.php @@ -38,17 +38,17 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase { protected $_contributionTypeID; protected $_membershipTypeID; protected $_membershipStatusID; - protected $_contribution = array(); + protected $_contribution = []; public function setUp() { parent::setUp(); $this->useTransaction(TRUE); $this->_contactID = $this->organizationCreate(NULL); - $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); + $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); $this->_membershipStatusID = $this->membershipStatusCreate('test status'); $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name'); - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'currency' => 'USD', 'financial_type_id' => 1, @@ -62,7 +62,7 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase { 'trxn_id' => '22ereerwww322323', 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', 'thankyou_date' => '20080522', - ); + ]; $this->_contribution = $this->callAPISuccess('contribution', 'create', $params); } @@ -73,7 +73,7 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase { * Test civicrm_membership_payment_create with empty params. */ public function testCreateEmptyParams() { - $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id'); + $this->callAPIFailure('membership_payment', 'create', [], 'Mandatory key(s) missing from params array: membership_id, contribution_id'); } /** @@ -82,7 +82,7 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase { public function testCreate() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2006-01-21', @@ -91,14 +91,14 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $membership = $this->callAPISuccess('membership', 'create', $params); - $params = array( + $params = [ 'contribution_id' => $this->_contribution['id'], 'membership_id' => $membership['id'], - ); + ]; $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__); $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__); @@ -120,20 +120,20 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase { */ public function testGet() { $contactId = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $membership = $this->callAPISuccess('membership', 'create', $params); - $params = array( + $params = [ 'contribution_id' => $this->_contribution['id'], 'membership_id' => $membership['id'], - ); + ]; $this->callAPISuccess('membership_payment', 'create', $params); $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__); diff --git a/tests/phpunit/api/v3/MembershipStatusTest.php b/tests/phpunit/api/v3/MembershipStatusTest.php index e9f205326d..f7f44eea72 100644 --- a/tests/phpunit/api/v3/MembershipStatusTest.php +++ b/tests/phpunit/api/v3/MembershipStatusTest.php @@ -41,7 +41,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->_contactID = $this->individualCreate(); - $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); + $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); $this->_membershipStatusID = $this->membershipStatusCreate('test status'); CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE); @@ -61,7 +61,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { * Test civicrm_membership_status_get with empty params. */ public function testGetEmptyParams() { - $result = $this->callAPISuccess('membership_status', 'get', array()); + $result = $this->callAPISuccess('membership_status', 'get', []); // It should be 8 statuses, 7 default from mysql_data // plus one test status added in setUp $this->assertEquals(8, $result['count']); @@ -71,9 +71,9 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { * Test civicrm_membership_status_get. Success expected. */ public function testGet() { - $params = array( + $params = [ 'name' => 'test status', - ); + ]; $result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$this->_membershipStatusID]['name'], "test status", "In line " . __LINE__); } @@ -82,7 +82,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { * Test civicrm_membership_status_get. Success expected. */ public function testGetLimit() { - $result = $this->callAPISuccess('membership_status', 'get', array()); + $result = $this->callAPISuccess('membership_status', 'get', []); $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__); $params['option.limit'] = 1; $result = $this->callAPISuccess('membership_status', 'get', $params); @@ -90,7 +90,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { } public function testCreateDuplicateName() { - $params = array('name' => 'name'); + $params = ['name' => 'name']; $result = $this->callAPISuccess('membership_status', 'create', $params); $result = $this->callAPIFailure('membership_status', 'create', $params, 'A membership status with this name already exists.' @@ -98,14 +98,14 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { } public function testCreateWithMissingRequired() { - $params = array('title' => 'Does not make sense'); + $params = ['title' => 'Does not make sense']; $this->callAPIFailure('membership_status', 'create', $params, 'Mandatory key(s) missing from params array: name'); } public function testCreate() { - $params = array( + $params = [ 'name' => 'test membership status', - ); + ]; $result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); @@ -113,19 +113,19 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { } public function testUpdate() { - $params = array( + $params = [ 'name' => 'test membership status', - ); + ]; $result = $this->callAPISuccess('membership_status', 'create', $params); $id = $result['id']; $result = $this->callAPISuccess('membership_status', 'get', $params); $this->assertEquals('test membership status', $result['values'][$id]['name']); - $newParams = array( + $newParams = [ 'id' => $id, 'name' => 'renamed', - ); + ]; $result = $this->callAPISuccess('membership_status', 'create', $newParams); - $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id)); + $result = $this->callAPISuccess('membership_status', 'get', ['id' => $id]); $this->assertEquals('renamed', $result['values'][$id]['name']); $this->membershipStatusDelete($result['id']); } @@ -136,19 +136,19 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { * Attempt (and fail) to delete membership status without an parameters. */ public function testDeleteEmptyParams() { - $result = $this->callAPIFailure('membership_status', 'delete', array()); + $result = $this->callAPIFailure('membership_status', 'delete', []); } public function testDeleteWithMissingRequired() { - $params = array('title' => 'Does not make sense'); + $params = ['title' => 'Does not make sense']; $result = $this->callAPIFailure('membership_status', 'delete', $params); } public function testDelete() { $membershipID = $this->membershipStatusCreate(); - $params = array( + $params = [ 'id' => $membershipID, - ); + ]; $result = $this->callAPISuccess('membership_status', 'delete', $params); } @@ -159,7 +159,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { $membershipStatusID = $this->membershipStatusCreate(); $this->_contactID = $this->individualCreate(); $this->_entity = 'membership'; - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2009-01-21', @@ -168,19 +168,19 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); $membershipID = $result['id']; - $params = array( + $params = [ 'id' => $membershipStatusID, - ); + ]; $result = $this->callAPIFailure('membership_status', 'delete', $params); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $membershipID, - )); + ]); $result = $this->callAPISuccess('membership_status', 'delete', $params); } diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 5d01315c00..8074902f2a 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -55,15 +55,15 @@ class api_v3_MembershipTest extends CiviUnitTestCase { parent::setUp(); $this->_apiversion = 3; $this->_contactID = $this->individualCreate(); - $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); - $this->_membershipTypeID2 = $this->membershipTypeCreate(array( + $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); + $this->_membershipTypeID2 = $this->membershipTypeCreate([ 'period_type' => 'fixed', // Ie. 1 March. 'fixed_period_start_day' => '301', // Ie. 11 Nov. 'fixed_period_rollover_day' => '1111', 'name' => 'Another one', - )); + ]); $this->_membershipStatusID = $this->membershipStatusCreate('test status'); CRM_Member_PseudoConstant::membershipType(NULL, TRUE); @@ -71,7 +71,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name'); $this->_entity = 'Membership'; - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_contactID, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2009-01-21', @@ -80,7 +80,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; } /** @@ -101,19 +101,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testMembershipDelete() { $membershipID = $this->contactMembershipCreate($this->_params); $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID); - $params = array( + $params = [ 'id' => $membershipID, - ); + ]; $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__, __FILE__); $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID); } public function testMembershipDeleteEmpty() { - $this->callAPIFailure('membership', 'delete', array()); + $this->callAPIFailure('membership', 'delete', []); } public function testMembershipDeleteInvalidID() { - $this->callAPIFailure('membership', 'delete', array('id' => 'blah')); + $this->callAPIFailure('membership', 'delete', ['id' => 'blah']); } /** @@ -132,24 +132,24 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $membershipID = $this->contactMembershipCreate($this->_params); //DELETE $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID); - $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array( + $ContributionCreate = $this->callAPISuccess('Contribution', 'create', [ 'sequential' => 1, 'financial_type_id' => "Member Dues", 'total_amount' => 100, 'contact_id' => $this->_params['contact_id'], - )); - $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array( + ]); + $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', [ 'sequential' => 1, 'contribution_id' => $ContributionCreate['values'][0]['id'], 'membership_id' => $membershipID, - )); - $memParams = array( + ]); + $memParams = [ 'id' => $membershipID, 'preserve_contribution' => 1, - ); - $contribParams = array( + ]; + $contribParams = [ 'id' => $ContributionCreate['values'][0]['id'], - ); + ]; $this->callAPIAndDocument('membership', 'delete', $memParams, __FUNCTION__, __FILE__); $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID); $this->assertDBRowExist('CRM_Contribute_DAO_Contribution', $ContributionCreate['values'][0]['id']); @@ -165,34 +165,34 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $membershipID = $this->contactMembershipCreate($this->_params); $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID); - $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array( + $ContributionCreate = $this->callAPISuccess('Contribution', 'create', [ 'financial_type_id' => "Member Dues", 'total_amount' => 100, 'contact_id' => $this->_params['contact_id'], - )); - $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array( + ]); + $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', [ 'sequential' => 1, 'contribution_id' => $ContributionCreate['id'], 'membership_id' => $membershipID, - )); - $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + ]); + $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); $this->paymentInstruments = $instruments['values']; $form = new CRM_Contribute_Form_Contribution(); $form->_id = $ContributionCreate['id']; - $form->testSubmit(array( + $form->testSubmit([ 'total_amount' => 100, 'financial_type_id' => 1, 'contact_id' => $contactId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 3, - ), + ], CRM_Core_Action::UPDATE); - $activity = $this->callAPISuccess('Activity', 'get', array( + $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => "Change Membership Status", 'source_record_id' => $membershipID, - )); + ]); $this->assertNotEmpty($activity['values']); } @@ -201,8 +201,8 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testContactMembershipsGet() { $this->_membershipID = $this->contactMembershipCreate($this->_params); - $this->callAPISuccess('membership', 'get', array()); - $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID)); + $this->callAPISuccess('membership', 'get', []); + $this->callAPISuccess('Membership', 'Delete', ['id' => $this->_membershipID]); } /** @@ -212,15 +212,15 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testGetWithParamsContactId() { $this->_membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'contact_id' => $this->_contactID, - ); + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $result = $membership['values'][$this->_membershipID]; - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $this->_membershipID, - )); + ]); $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__); $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__); @@ -240,18 +240,18 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->_membershipID = $this->contactMembershipCreate($this->_params); $this->_membershipID2 = $this->contactMembershipCreate($this->_params); $this->_membershipID3 = $this->contactMembershipCreate($this->_params); - $params = array( - 'id' => array('IN' => array($this->_membershipID, $this->_membershipID3)), - ); + $params = [ + 'id' => ['IN' => [$this->_membershipID, $this->_membershipID3]], + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(2, $membership['count']); - $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values'])); - $params = array( - 'id' => array('NOT IN' => array($this->_membershipID, $this->_membershipID3)), - ); + $this->assertEquals([$this->_membershipID, $this->_membershipID3], array_keys($membership['values'])); + $params = [ + 'id' => ['NOT IN' => [$this->_membershipID, $this->_membershipID3]], + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $membership['count']); - $this->assertEquals(array($this->_membershipID2), array_keys($membership['values'])); + $this->assertEquals([$this->_membershipID2], array_keys($membership['values'])); } /** @@ -261,21 +261,21 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testGetInSyntaxOnContactID() { $this->_membershipID = $this->contactMembershipCreate($this->_params); $contact2 = $this->individualCreate(); - $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine')); - $this->_membershipID2 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact2))); - $this->_membershipID3 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact3))); - $params = array( - 'contact_id' => array('IN' => array($this->_contactID, $contact3)), - ); + $contact3 = $this->individualCreate(['first_name' => 'Scout', 'last_name' => 'Canine']); + $this->_membershipID2 = $this->contactMembershipCreate(array_merge($this->_params, ['contact_id' => $contact2])); + $this->_membershipID3 = $this->contactMembershipCreate(array_merge($this->_params, ['contact_id' => $contact3])); + $params = [ + 'contact_id' => ['IN' => [$this->_contactID, $contact3]], + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(2, $membership['count']); - $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values'])); - $params = array( - 'contact_id' => array('NOT IN' => array($this->_contactID, $contact3)), - ); + $this->assertEquals([$this->_membershipID, $this->_membershipID3], array_keys($membership['values'])); + $params = [ + 'contact_id' => ['NOT IN' => [$this->_contactID, $contact3]], + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $membership['count']); - $this->assertEquals(array($this->_membershipID2), array_keys($membership['values'])); + $this->assertEquals([$this->_membershipID2], array_keys($membership['values'])); } /** @@ -285,13 +285,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testGetWithParamsMemberShipTypeId() { $this->callAPISuccess($this->_entity, 'create', $this->_params); - $params = array( + $params = [ 'membership_type_id' => $this->_membershipTypeID, - ); + ]; $membership = $this->callAPISuccess('membership', 'get', $params); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $membership['id'], - )); + ]); $result = $membership['values'][$membership['id']]; $this->assertEquals($result['contact_id'], $this->_contactID); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID); @@ -313,19 +313,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', $params); $params['membership_type_id'] = $this->_membershipTypeID2; $this->callAPISuccess($this->_entity, 'create', $params); - $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_contactID), 2); - $params = array( + $this->callAPISuccessGetCount('membership', ['contact_id' => $this->_contactID], 2); + $params = [ 'membership_type_id' => $this->_membershipTypeID, 'contact_id' => $this->_contactID, - ); + ]; $result = $this->callAPISuccess('membership', 'getsingle', $params); $this->assertEquals($result['contact_id'], $this->_contactID); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID); - $params = array( + $params = [ 'membership_type_id' => $this->_membershipTypeID2, 'contact_id' => $this->_contactID, - ); + ]; $result = $this->callAPISuccess('membership', 'getsingle', $params); $this->assertEquals($result['contact_id'], $this->_contactID); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2); @@ -346,13 +346,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $this->callAPISuccess($this->_entity, 'create', $params); - $getParams = array('membership_type_id' => $params['membership_type_id']); + $getParams = ['membership_type_id' => $params['membership_type_id']]; $check = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); } /** @@ -361,15 +361,15 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testGet() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'contact_id' => $this->_contactID, - ); + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $result = $membership['values'][$membershipID]; - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $membership['id'], - )); + ]); $this->assertEquals($result['join_date'], '2009-01-21'); $this->assertEquals($result['contact_id'], $this->_contactID); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID); @@ -387,18 +387,18 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testGetWithId() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'id' => $this->_membershipID, 'return' => 'id', - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals($membershipID, $result['id']); - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'membership_id' => $this->_membershipID, 'return' => 'membership_id', - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals($membershipID, $result['id']); } @@ -410,26 +410,26 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testGetOnlyActive() { $description = "Demonstrates use of 'filter' active_only' param."; $this->_membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'active_only' => 1, - ); + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID); $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID); - $params = array( + $params = [ 'contact_id' => $this->_contactID, - 'filters' => array( + 'filters' => [ 'is_current' => 1, - ), - ); + ], + ]; $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, 'FilterIsCurrent'); $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID); $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID); - $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID)); + $this->callAPISuccess('Membership', 'Delete', ['id' => $this->_membershipID]); } /** @@ -437,9 +437,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * empty Memberships. */ public function testGetNoContactExists() { - $params = array( + $params = [ 'contact_id' => 55555, - ); + ]; $membership = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals($membership['count'], 0); @@ -455,7 +455,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $membershipOrgId = $this->organizationCreate(NULL); $memberContactId = $this->individualCreate(); - $relTypeParams = array( + $relTypeParams = [ 'name_a_b' => 'Relation 1', 'name_b_a' => 'Relation 2', 'description' => 'Testing relationship type', @@ -463,10 +463,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'contact_type_b' => 'Individual', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $relTypeID = $this->relationshipTypeCreate($relTypeParams); - $params = array( + $params = [ 'name' => 'test General', 'duration_unit' => 'year', 'duration_interval' => 1, @@ -477,10 +477,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'relationship_type_id' => $relTypeID, 'relationship_direction' => 'b_a', 'is_active' => 1, - ); + ]; $memType = $this->callAPISuccess('membership_type', 'create', $params); - $params = array( + $params = [ 'contact_id' => $memberContactId, 'membership_type_id' => $memType['id'], 'join_date' => '2009-01-21', @@ -489,22 +489,22 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $membershipID = $this->contactMembershipCreate($params); - $params = array( + $params = [ 'contact_id' => $memberContactId, 'membership_type_id' => $memType['id'], - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $membership = $result['values'][$membershipID]; $this->assertEquals($this->_membershipStatusID, $membership['status_id']); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $membership['id'], - )); - $this->membershipTypeDelete(array('id' => $memType['id'])); + ]); + $this->membershipTypeDelete(['id' => $memType['id']]); $this->relationshipTypeDelete($relTypeID); $this->contactDelete($membershipOrgId); $this->contactDelete($memberContactId); @@ -519,13 +519,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testCreateWithRelationship() { // Create membership type: inherited through employment, max_related = 2 - $params = array( + $params = [ 'name_a_b' => 'Employee of', - ); + ]; $result = $this->callAPISuccess('relationship_type', 'get', $params); $relationshipTypeId = $result['id']; $membershipOrgId = $this->organizationCreate(); - $params = array( + $params = [ 'name' => 'Corporate Membership', 'duration_unit' => 'year', 'duration_interval' => 1, @@ -537,29 +537,29 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'relationship_direction' => 'b_a', 'max_related' => 2, 'is_active' => 1, - ); + ]; $result = $this->callAPISuccess('membership_type', 'create', $params); $membershipTypeId = $result['id']; // Create employer and first employee - $employerId[0] = $this->organizationCreate(array(), 1); - $memberContactId[0] = $this->individualCreate(array('employer_id' => $employerId[0]), 0); + $employerId[0] = $this->organizationCreate([], 1); + $memberContactId[0] = $this->individualCreate(['employer_id' => $employerId[0]], 0); // Create organization's membership - $params = array( + $params = [ 'contact_id' => $employerId[0], 'membership_type_id' => $membershipTypeId, 'source' => 'Test suite', 'start_date' => date('Y-m-d'), 'end_date' => "+1 year", - ); + ]; $OrganizationMembershipID = $this->contactMembershipCreate($params); // Check that the employee inherited the membership - $params = array( + $params = [ 'contact_id' => $memberContactId[0], 'membership_type_id' => $membershipTypeId, - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); @@ -568,13 +568,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']); // Create second employee - $memberContactId[1] = $this->individualCreate(array('employer_id' => $employerId[0]), 1); + $memberContactId[1] = $this->individualCreate(['employer_id' => $employerId[0]], 1); // Check that the employee inherited the membership - $params = array( + $params = [ 'contact_id' => $memberContactId[1], 'membership_type_id' => $membershipTypeId, - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); // If it fails here CRM-14758 is not fixed $this->assertEquals(1, $result['count']); @@ -582,100 +582,100 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']); // Create third employee - $memberContactId[2] = $this->individualCreate(array('employer_id' => $employerId[0]), 2); + $memberContactId[2] = $this->individualCreate(['employer_id' => $employerId[0]], 2); // Check that employee does NOT inherit the membership (max_related = 2) - $params = array( + $params = [ 'contact_id' => $memberContactId[2], 'membership_type_id' => $membershipTypeId, - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); // Increase max_related for the employer's membership - $params = array( + $params = [ 'id' => $OrganizationMembershipID, 'max_related' => 3, - ); + ]; $this->callAPISuccess('Membership', 'create', $params); // Check that the employee inherited the membership - $params = array( + $params = [ 'contact_id' => $memberContactId[2], 'membership_type_id' => $membershipTypeId, - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $result['count']); $result = $result['values'][$result['id']]; $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']); // First employee moves to a new job - $employerId[1] = $this->organizationCreate(array(), 2); - $params = array( + $employerId[1] = $this->organizationCreate([], 2); + $params = [ 'id' => $memberContactId[0], 'employer_id' => $employerId[1], - ); + ]; $this->callAPISuccess('contact', 'create', $params); // Check that employee does NO LONGER inherit the membership - $params = array( + $params = [ 'contact_id' => $memberContactId[0], 'membership_type_id' => $membershipTypeId, - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); //Create pay_later membership for organization. - $employerId[2] = $this->organizationCreate(array(), 1); - $params = array( + $employerId[2] = $this->organizationCreate([], 1); + $params = [ 'contact_id' => $employerId[2], 'membership_type_id' => $membershipTypeId, 'source' => 'Test pay later suite', 'is_pay_later' => 1, 'status_id' => 5, - ); + ]; $organizationMembership = CRM_Member_BAO_Membership::add($params); $organizationMembershipID = $organizationMembership->id; - $memberContactId[3] = $this->individualCreate(array('employer_id' => $employerId[2]), 0); + $memberContactId[3] = $this->individualCreate(['employer_id' => $employerId[2]], 0); // Check that the employee inherited the membership - $params = array( + $params = [ 'contact_id' => $memberContactId[3], 'membership_type_id' => $membershipTypeId, - ); + ]; $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $result['count']); $result = $result['values'][$result['id']]; $this->assertEquals($organizationMembershipID, $result['owner_membership_id']); // Set up params for enable/disable checks - $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1])); - $params = array( + $relationship1 = $this->callAPISuccess('relationship', 'get', ['contact_id_a' => $memberContactId[1]]); + $params = [ 'contact_id' => $memberContactId[1], 'membership_type_id' => $membershipTypeId, - ); + ]; // Deactivate relationship using create and assert membership is not inherited - $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0)); + $this->callAPISuccess('relationship', 'create', ['id' => $relationship1['id'], 'is_active' => 0]); $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); // Re-enable relationship using create and assert membership is inherited - $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1)); + $this->callAPISuccess('relationship', 'create', ['id' => $relationship1['id'], 'is_active' => 1]); $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $result['count']); // Deactivate relationship using setvalue and assert membership is not inherited - $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0)); + $this->callAPISuccess('relationship', 'setvalue', ['id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0]); $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); // Re-enable relationship using setvalue and assert membership is inherited - $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1)); + $this->callAPISuccess('relationship', 'setvalue', ['id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1]); $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $result['count']); // Delete relationship and assert membership is not inherited - $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id'])); + $this->callAPISuccess('relationship', 'delete', ['id' => $relationship1['id']]); $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); @@ -685,7 +685,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->contactDelete($memberContactId[0]); $this->contactDelete($employerId[1]); $this->contactDelete($employerId[0]); - $this->membershipTypeDelete(array('id' => $membershipTypeId)); + $this->membershipTypeDelete(['id' => $membershipTypeId]); $this->contactDelete($membershipOrgId); } @@ -694,9 +694,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipGetWithReturn() { $this->contactMembershipCreate($this->_params); - $result = $this->callAPISuccess('membership', 'get', array('return' => 'end_date')); + $result = $this->callAPISuccess('membership', 'get', ['return' => 'end_date']); foreach ($result['values'] as $membership) { - $this->assertEquals(array('id', 'end_date'), array_keys($membership)); + $this->assertEquals(['id', 'end_date'], array_keys($membership)); } } @@ -707,7 +707,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Error expected. */ public function testCreateWithEmptyParams() { - $params = array(); + $params = []; $this->callAPIFailure('membership', 'create', $params); } @@ -721,20 +721,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase { } public function testMembershipCreateMissingRequired() { - $params = array( + $params = [ 'membership_type_id' => '1', 'join_date' => '2006-01-21', 'start_date' => '2006-01-21', 'end_date' => '2006-12-21', 'source' => 'Payment', 'status_id' => '2', - ); + ]; $this->callAPIFailure('membership', 'create', $params); } public function testMembershipCreate() { - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2006-01-21', @@ -743,7 +743,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__, __FILE__); $this->getAndCheck($params, $result['id'], $this->_entity); @@ -756,7 +756,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Check for useful message if contact doesn't exist */ public function testMembershipCreateWithInvalidContact() { - $params = array( + $params = [ 'contact_id' => 999, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2006-01-21', @@ -765,7 +765,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $this->callAPIFailure('membership', 'create', $params, 'contact_id is not valid : 999' @@ -802,10 +802,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'CreateWithCustomData'); - $check = $this->callAPISuccess($this->_entity, 'get', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'id' => $result['id'], 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); } @@ -830,14 +830,14 @@ class api_v3_MembershipTest extends CiviUnitTestCase { // search memberships with CRM-16036 as custom field value. // Since we did not touch the custom field of any membership, // this should not return any results. - $check = $this->callAPISuccess($this->_entity, 'get', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'custom_' . $ids['custom_field_id'] => "CRM-16036", - )); + ]); // Cleanup. - $this->callAPISuccess($this->_entity, 'delete', array( + $this->callAPISuccess($this->_entity, 'delete', [ 'id' => $result['id'], - )); + ]); // Assert. $this->assertEquals(0, $check['count']); @@ -850,7 +850,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipCreateWithId() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'id' => $membershipID, 'contact_id' => $this->_contactID, 'membership_type_id' => $this->_membershipTypeID, @@ -860,15 +860,15 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); //Update Status and check activities created. - $updateStatus = array( + $updateStatus = [ 'id' => $result['id'], 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Cancelled'), - ); + ]; $this->callAPISuccess('Membership', 'create', $updateStatus); $activities = CRM_Activity_BAO_Activity::getContactActivity($this->_contactID); $this->assertEquals(2, count($activities)); @@ -876,9 +876,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertArrayHasKey('Membership Signup', $activityNames); $this->assertArrayHasKey('Change Membership Status', $activityNames); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); } @@ -889,7 +889,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipCreateUpdateWithIdNoContact() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'id' => $membershipID, 'membership_type_id' => $this->_membershipTypeID, 'contact_id' => $this->_contactID, @@ -899,12 +899,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); } @@ -916,19 +916,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipCreateUpdateWithIdNoDates() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'id' => $membershipID, 'contact_id' => $this->_contactID, 'membership_type_id' => $this->_membershipTypeID, 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); } @@ -939,18 +939,18 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipCreateUpdateWithIdNoDatesNoType() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'id' => $membershipID, 'source' => 'not much here', 'contact_id' => $this->_contactID, 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); } @@ -961,19 +961,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipCreateUpdateWithIDAndSource() { $membershipID = $this->contactMembershipCreate($this->_params); - $params = array( + $params = [ 'id' => $membershipID, 'source' => 'changed', 'contact_id' => $this->_contactID, 'status_id' => $this->_membershipStatusID, 'membership_type_id' => $this->_membershipTypeID, 'skipStatusCal' => 1, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); } /** @@ -985,19 +985,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'UpdateCustomData'); - $result = $this->callAPISuccess($this->_entity, 'create', array( + $result = $this->callAPISuccess($this->_entity, 'create', [ 'id' => $result['id'], 'custom_' . $ids['custom_field_id'] => "new custom", - )); - $check = $this->callAPISuccess($this->_entity, 'get', array( + ]); + $check = $this->callAPISuccess($this->_entity, 'get', [ 'id' => $result['id'], 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $check['id'], - )); + ]); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); @@ -1007,13 +1007,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * per CRM-15746 check that the id can be altered in an update hook */ public function testMembershipUpdateCreateHookCRM15746() { - $this->hookClass->setHook('civicrm_pre', array($this, 'hook_civicrm_pre_update_create_membership')); + $this->hookClass->setHook('civicrm_pre', [$this, 'hook_civicrm_pre_update_create_membership']); $result = $this->callAPISuccess('membership', 'create', $this->_params); - $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago')); - $this->callAPISuccessGetCount('membership', array(), 2); + $this->callAPISuccess('membership', 'create', ['id' => $result['id'], 'end_date' => '1 year ago']); + $this->callAPISuccessGetCount('membership', [], 2); $this->hookClass->reset(); - $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago')); - $this->callAPISuccessGetCount('membership', array(), 2); + $this->callAPISuccess('membership', 'create', ['id' => $result['id'], 'end_date' => '1 year ago']); + $this->callAPISuccessGetCount('membership', [], 2); } /** @@ -1028,7 +1028,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function hook_civicrm_pre_update_create_membership($op, $objectName, $id, &$params) { if ($objectName == 'Membership' && $op == 'edit') { - $existingMembership = $this->callAPISuccessGetSingle('membership', array('id' => $params['id'])); + $existingMembership = $this->callAPISuccessGetSingle('membership', ['id' => $params['id']]); unset($params['id'], $params['membership_id']); $params['join_date'] = $params['membership_start_date'] = $params['start_date'] = date('Ymd000000', strtotime($existingMembership['start_date'])); $params = array_merge($existingMembership, $params); @@ -1042,7 +1042,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testMembershipCreateInvalidMemData() { //membership_contact_id as string - $params = array( + $params = [ 'membership_contact_id' => 'Invalid', 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2011-01-21', @@ -1051,7 +1051,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $this->callAPIFailure('membership', 'create', $params); @@ -1071,7 +1071,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Success expected. */ public function testMembershipCreateWithMemContact() { - $params = array( + $params = [ 'membership_contact_id' => $this->_contactID, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2011-01-21', @@ -1080,13 +1080,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); } /** @@ -1095,7 +1095,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Success expected. */ public function testMembershipCreateValidMembershipTypeString() { - $params = array( + $params = [ 'membership_contact_id' => $this->_contactID, 'membership_type_id' => 'General', 'join_date' => '2011-01-21', @@ -1104,13 +1104,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $result = $this->callAPISuccess('membership', 'create', $params); $this->assertEquals($this->_membershipTypeID, $result['values'][$result['id']]['membership_type_id']); - $this->callAPISuccess('Membership', 'Delete', array( + $this->callAPISuccess('Membership', 'Delete', [ 'id' => $result['id'], - )); + ]); } /** @@ -1119,7 +1119,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Success expected. */ public function testMembershipCreateInValidMembershipTypeString() { - $params = array( + $params = [ 'membership_contact_id' => $this->_contactID, 'membership_type_id' => 'invalid', 'join_date' => '2011-01-21', @@ -1128,7 +1128,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, - ); + ]; $this->callAPIFailure('membership', 'create', $params); } @@ -1139,7 +1139,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testEmptyJoinDate() { unset($this->_params['join_date'], $this->_params['is_override']); $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']); $this->assertEquals('2009-01-21', $result['start_date']); $this->assertEquals('2009-12-21', $result['end_date']); @@ -1153,7 +1153,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { unset($this->_params['start_date'], $this->_params['is_override']); $this->_params['membership_type_id'] = $this->_membershipTypeID2; $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2008-03-01', $result['start_date']); $this->assertEquals('2009-12-21', $result['end_date']); @@ -1165,10 +1165,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testEmptyStartEndDateFixedOneYear() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1)); + $this->callAPISuccess('membership_type', 'create', ['id' => $this->_membershipTypeID2, 'duration_interval' => 1]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2008-03-01', $result['start_date']); $this->assertEquals('2010-02-28', $result['end_date']); @@ -1179,10 +1179,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ public function testEmptyStartEndDateFixedMultiYear() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 5)); + $this->callAPISuccess('membership_type', 'create', ['id' => $this->_membershipTypeID2, 'duration_interval' => 5]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2008-03-01', $result['start_date']); $this->assertEquals('2014-02-28', $result['end_date']); @@ -1194,10 +1194,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testMembershipJoinDateFixed() { $memStatus = CRM_Member_PseudoConstant::membershipStatus(); // Update the fixed membership type to 1 year duration. - $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1)); + $this->callAPISuccess('membership_type', 'create', ['id' => $this->_membershipTypeID2, 'duration_interval' => 1]); $contactId = $this->createLoggedInUser(); // Create membership with 'Pending' status. - $params = array( + $params = [ 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID2, 'source' => 'test membership', @@ -1205,19 +1205,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'status_id' => array_search('Pending', $memStatus), 'skipStatusCal' => 1, 'is_for_organization' => 1, - ); - $ids = array(); + ]; + $ids = []; $membership = CRM_Member_BAO_Membership::create($params, $ids); // Update membership to 'Completed' and check the dates. - $memParams = array( + $memParams = [ 'id' => $membership->id, 'contact_id' => $contactId, 'is_test' => 0, 'membership_type_id' => $this->_membershipTypeID2, 'num_terms' => 1, 'status_id' => array_search('New', $memStatus), - ); + ]; $result = $this->callAPISuccess('Membership', 'create', $memParams); // Extend duration interval if join_date exceeds the rollover period. @@ -1236,11 +1236,11 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $y += 1; } - $expectedDates = array( + $expectedDates = [ 'join_date' => date('Ymd'), 'start_date' => str_replace('-', '', $startDate), 'end_date' => date('Ymd', strtotime(date('Y-03-01') . "+ {$y} year - 1 day")), - ); + ]; foreach ($result['values'] as $values) { foreach ($expectedDates as $date => $val) { $this->assertEquals($val, $values[$date], "Failed asserting {$date} values"); @@ -1260,20 +1260,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedMultiYearDateSetTwoEmptyStartEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 5, // Ie 1 Jan. 'fixed_period_start_day' => '101', // Ie. 1 Nov. 'fixed_period_rollover_day' => '1101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2015-01-01', $result['start_date']); $this->assertEquals('2019-12-31', $result['end_date']); @@ -1289,21 +1289,21 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedMultiYearDateSetTwoEmptyEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 5, // Ie 1 Jan. 'fixed_period_start_day' => '101', // Ie. 1 Nov. 'fixed_period_rollover_day' => '1101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'start_date' => '28-Jan 2015', 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2015-01-28', $result['start_date']); $this->assertEquals('2019-12-31', $result['end_date']); @@ -1321,20 +1321,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedSingleYearDateSetTwoEmptyStartEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 1, // Ie 1 Jan. 'fixed_period_start_day' => '101', // Ie. 1 Nov. 'fixed_period_rollover_day' => '1101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2015-01-01', $result['start_date']); $this->assertEquals('2015-12-31', $result['end_date']); @@ -1350,21 +1350,21 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedSingleYearDateSetTwoEmptyEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 1, // Ie 1 Jan. 'fixed_period_start_day' => '101', // Ie. 1 Nov. 'fixed_period_rollover_day' => '1101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'start_date' => '28-Jan 2015', 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2015-01-28', $result['start_date']); $this->assertEquals('2015-12-31', $result['end_date']); @@ -1380,21 +1380,21 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedSingleYearDateSetThreeEmptyEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 1, // Ie. 1 Nov. 'fixed_period_start_day' => '1101', // Ie 1 Jan. 'fixed_period_rollover_day' => '101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'start_date' => '28-Jan 2015', 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2015-01-28', $result['start_date']); $this->assertEquals('2016-10-31', $result['end_date']); @@ -1412,20 +1412,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedSingleYearDateSetThreeEmptyStartEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 1, // Ie. 1 Nov. 'fixed_period_start_day' => '1101', // Ie 1 Jan. 'fixed_period_rollover_day' => '101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2014-11-01', $result['start_date']); $this->assertEquals('2016-10-31', $result['end_date']); @@ -1441,21 +1441,21 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedMultiYearDateSetThreeEmptyEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 5, // Ie. 1 Nov. 'fixed_period_start_day' => '1101', // Ie 1 Jan. 'fixed_period_rollover_day' => '101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'start_date' => '28-Jan 2015', 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2015-01-28', $result['start_date']); $this->assertEquals('2020-10-31', $result['end_date']); @@ -1474,20 +1474,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testFixedMultiYearDateSetThreeEmptyStartEndDate() { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); - $this->callAPISuccess('membership_type', 'create', array( + $this->callAPISuccess('membership_type', 'create', [ 'id' => $this->_membershipTypeID2, 'duration_interval' => 5, // Ie. 1 Nov. 'fixed_period_start_day' => '1101', // Ie 1 Jan. 'fixed_period_rollover_day' => '101', - )); + ]); $this->_params['membership_type_id'] = $this->_membershipTypeID2; - $dates = array( + $dates = [ 'join_date' => '28-Jan 2015', - ); + ]; $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates)); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2015-01-28', $result['join_date']); $this->assertEquals('2014-11-01', $result['start_date']); $this->assertEquals('2020-10-31', $result['end_date']); @@ -1499,7 +1499,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function testEmptyStartDateRolling() { unset($this->_params['start_date'], $this->_params['is_override']); $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2009-01-21', $result['start_date']); $this->assertEquals('2009-12-21', $result['end_date']); @@ -1513,7 +1513,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']); $this->_params['membership_type_id'] = $this->_membershipTypeID2; $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2008-03-01', $result['start_date']); $this->assertEquals('2010-02-28', $result['end_date']); @@ -1527,7 +1527,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { unset($this->_params['is_override'], $this->_params['end_date']); $this->_params['membership_type_id'] = $this->_membershipTypeID; $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2009-01-21', $result['start_date']); $this->assertEquals('2010-01-20', $result['end_date']); @@ -1541,7 +1541,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { unset($this->_params['end_date'], $this->_params['start_date']); $this->_params['id'] = $result['id']; $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]); $this->assertEquals('2009-01-21', $result['join_date']); $this->assertEquals('2009-01-21', $result['start_date']); $this->assertEquals('2009-12-21', $result['end_date']); @@ -1558,7 +1558,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * See CRM-17075. */ public function testGetOptionsMembershipTypeID() { - $options = $this->callAPISuccess('Membership', 'getoptions', array('field' => 'membership_type_id')); + $options = $this->callAPISuccess('Membership', 'getoptions', ['field' => 'membership_type_id']); $this->assertEquals('Another one', array_pop($options['values'])); $this->assertEquals('General', array_pop($options['values'])); $this->assertEquals(NULL, array_pop($options['values'])); diff --git a/tests/phpunit/api/v3/MembershipTypeTest.php b/tests/phpunit/api/v3/MembershipTypeTest.php index 85698fe736..f8ba5f445c 100644 --- a/tests/phpunit/api/v3/MembershipTypeTest.php +++ b/tests/phpunit/api/v3/MembershipTypeTest.php @@ -51,7 +51,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * This should return an empty array but not an error. */ public function testGetWithoutId() { - $params = array( + $params = [ 'name' => '60+ Membership', 'description' => 'people above 60 are given health instructions', 'financial_type_id' => 1, @@ -59,7 +59,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'duration_unit' => 'month', 'duration_interval' => '10', 'visibility' => 'public', - ); + ]; $membershipType = $this->callAPISuccess('membership_type', 'get', $params); $this->assertEquals($membershipType['count'], 0); @@ -69,11 +69,11 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * Test get works. */ public function testGet() { - $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); + $id = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); - $params = array( + $params = [ 'id' => $id, - ); + ]; $membershipType = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($membershipType['values'][$id]['name'], 'General'); $this->assertEquals($membershipType['values'][$id]['member_of_contact_id'], $this->_contactID); @@ -88,7 +88,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * Test create with missing mandatory field. */ public function testCreateWithoutMemberOfContactId() { - $params = array( + $params = [ 'name' => '60+ Membership', 'description' => 'people above 60 are given health instructions', 'financial_type_id' => 1, @@ -98,7 +98,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'duration_interval' => '10', 'period_type' => 'rolling', 'visibility' => 'public', - ); + ]; $this->callAPIFailure('membership_type', 'create', $params, 'Mandatory key(s) missing from params array: member_of_contact_id'); } @@ -107,7 +107,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * Test successful create. */ public function testCreate() { - $params = array( + $params = [ 'name' => '40+ Membership', 'description' => 'people above 40 are given health instructions', 'member_of_contact_id' => $this->_contactID, @@ -118,11 +118,11 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'duration_interval' => '10', 'period_type' => 'rolling', 'visibility' => 'public', - ); + ]; $membershipType = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($membershipType['values']); - $this->membershipTypeDelete(array('id' => $membershipType['id'])); + $this->membershipTypeDelete(['id' => $membershipType['id']]); } /** @@ -130,7 +130,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * DomainID is now optional on API, check that it gets set correctly and that the domain_id is not overwritten when not specified in create. */ public function testCreateWithoutDomainId() { - $params = array( + $params = [ 'name' => '60+ Membership', 'description' => 'people above 60 are given health instructions', 'member_of_contact_id' => $this->_contactID, @@ -140,7 +140,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'duration_interval' => '10', 'period_type' => 'rolling', 'visibility' => 'public', - ); + ]; $membershipType = $this->callAPISuccess('membership_type', 'create', $params); $domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]); @@ -160,7 +160,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * CRM-20010 Tests period_type is required for MemberType create */ public function testMemberTypePeriodiTypeRequired() { - $this->callAPIFailure('MembershipType', 'create', array( + $this->callAPIFailure('MembershipType', 'create', [ 'domain_id' => "Default Domain Name", 'member_of_contact_id' => 1, 'financial_type_id' => "Member Dues", @@ -168,21 +168,21 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'duration_interval' => 1, 'name' => "Standard Member", 'minimum_fee' => 100, - )); + ]); } /** * Test update. */ public function testUpdate() { - $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2)); - $newMemberOrgParams = array( + $id = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2]); + $newMemberOrgParams = [ 'organization_name' => 'New membership organisation', 'contact_type' => 'Organization', 'visibility' => 1, - ); + ]; - $params = array( + $params = [ 'id' => $id, 'name' => 'Updated General', 'member_of_contact_id' => $this->organizationCreate($newMemberOrgParams), @@ -190,7 +190,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'duration_interval' => '10', 'period_type' => 'fixed', 'domain_id' => 1, - ); + ]; $this->callAPISuccess('membership_type', 'update', $params); @@ -201,10 +201,10 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * Test successful delete. */ public function testDelete() { - $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->organizationCreate())); - $params = array( + $membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->organizationCreate()]); + $params = [ 'id' => $membershipTypeID, - ); + ]; $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__); } @@ -215,36 +215,36 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * I can't skim this & understand it so if anyone does explain it here. */ public function testDeleteRelationshipTypesUsedByMembershipType() { - $rel1 = $this->relationshipTypeCreate(array( + $rel1 = $this->relationshipTypeCreate([ 'name_a_b' => 'abcde', 'name_b_a' => 'abcde', - )); - $rel2 = $this->relationshipTypeCreate(array( + ]); + $rel2 = $this->relationshipTypeCreate([ 'name_a_b' => 'fghij', 'name_b_a' => 'fghij', - )); - $rel3 = $this->relationshipTypeCreate(array( + ]); + $rel3 = $this->relationshipTypeCreate([ 'name_a_b' => 'lkmno', 'name_b_a' => 'lkmno', - )); - $id = $this->membershipTypeCreate(array( + ]); + $id = $this->membershipTypeCreate([ 'member_of_contact_id' => $this->_contactID, - 'relationship_type_id' => array($rel1, $rel2, $rel3), - 'relationship_direction' => array('a_b', 'a_b', 'b_a'), - )); - - $this->callAPISuccess('RelationshipType', 'delete', array('id' => $rel2)); - $newValues = $this->callAPISuccess('MembershipType', 'getsingle', array('id' => $id)); - $this->assertEquals(array($rel1, $rel3), $newValues['relationship_type_id']); - $this->assertEquals(array('a_b', 'b_a'), $newValues['relationship_direction']); - - $this->callAPISuccess('RelationshipType', 'delete', array('id' => $rel1)); - $newValues = $this->callAPISuccess('MembershipType', 'getsingle', array('id' => $id)); - $this->assertEquals(array($rel3), $newValues['relationship_type_id']); - $this->assertEquals(array('b_a'), $newValues['relationship_direction']); - - $this->callAPISuccess('RelationshipType', 'delete', array('id' => $rel3)); - $newValues = $this->callAPISuccess('MembershipType', 'getsingle', array('id' => $id)); + 'relationship_type_id' => [$rel1, $rel2, $rel3], + 'relationship_direction' => ['a_b', 'a_b', 'b_a'], + ]); + + $this->callAPISuccess('RelationshipType', 'delete', ['id' => $rel2]); + $newValues = $this->callAPISuccess('MembershipType', 'getsingle', ['id' => $id]); + $this->assertEquals([$rel1, $rel3], $newValues['relationship_type_id']); + $this->assertEquals(['a_b', 'b_a'], $newValues['relationship_direction']); + + $this->callAPISuccess('RelationshipType', 'delete', ['id' => $rel1]); + $newValues = $this->callAPISuccess('MembershipType', 'getsingle', ['id' => $id]); + $this->assertEquals([$rel3], $newValues['relationship_type_id']); + $this->assertEquals(['b_a'], $newValues['relationship_direction']); + + $this->callAPISuccess('RelationshipType', 'delete', ['id' => $rel3]); + $newValues = $this->callAPISuccess('MembershipType', 'getsingle', ['id' => $id]); $this->assertTrue(empty($newValues['relationship_type_id'])); $this->assertTrue(empty($newValues['relationship_direction'])); } @@ -254,9 +254,9 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { */ public function testMembershipTypeGetList() { $this->membershipTypeCreate(); - $this->membershipTypeCreate(array('name' => 'cheap-skates')); - $this->membershipTypeCreate(array('name' => 'disabled cheap-skates', 'is_active' => 0)); - $result = $this->callAPISuccess('MembershipType', 'getlist', array()); + $this->membershipTypeCreate(['name' => 'cheap-skates']); + $this->membershipTypeCreate(['name' => 'disabled cheap-skates', 'is_active' => 0]); + $result = $this->callAPISuccess('MembershipType', 'getlist', []); $this->assertEquals(2, $result['count']); $this->assertEquals('cheap-skates', $result['values'][0]['label']); $this->assertEquals('General', $result['values'][1]['label']); @@ -267,23 +267,23 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * selected in contribution pages. */ public function testEnableMembershipTypeOnContributionPage() { - $memType = array(); - $memType[1] = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'minimum_fee' => 100)); - $priceSet = $this->callAPISuccess('price_set', 'create', array( + $memType = []; + $memType[1] = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'minimum_fee' => 100]); + $priceSet = $this->callAPISuccess('price_set', 'create', [ 'title' => "test priceset", 'name' => "test_priceset", 'extends' => "CiviMember", 'is_quick_config' => 1, 'financial_type_id' => "Member Dues", - )); + ]); $priceSet = $priceSet['id']; - $field = $this->callAPISuccess('price_field', 'create', array( + $field = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $priceSet, 'name' => 'membership_amount', 'label' => 'Membership Amount', 'html_type' => 'Radio', - )); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'name' => 'membership_amount', 'label' => 'Membership Amount', 'amount' => 100, @@ -291,17 +291,17 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'format.only_id' => TRUE, 'membership_type_id' => $memType[1], 'price_field_id' => $field['id'], - )); + ]); - $memType[2] = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'minimum_fee' => 200)); - $fieldParams = array( + $memType[2] = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'minimum_fee' => 200]); + $fieldParams = [ 'id' => $field['id'], 'label' => 'Membership Amount', 'html_type' => 'Radio', - ); + ]; foreach ($memType as $rowCount => $type) { $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($type); - $fieldParams['option_id'] = array(1 => $priceFieldValue['id']); + $fieldParams['option_id'] = [1 => $priceFieldValue['id']]; $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype); $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0); $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype); @@ -313,22 +313,22 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { $this->assertEquals($priceField->id, $fieldParams['id']); //Update membership type name and visibility - $updateParams = array( + $updateParams = [ 'id' => $memType[1], 'name' => 'General - Edited', 'visibility' => 'Admin', 'financial_type_id' => 1, 'minimum_fee' => 300, 'description' => 'Test edit description', - ); + ]; $this->callAPISuccess('membership_type', 'create', $updateParams); - $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array( + $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', [ 'sequential' => 1, 'membership_type_id' => $memType[1], - )); + ]); //Verify if membership type updates are copied to pricefield value. foreach ($priceFieldValue['values'] as $key => $value) { - $setId = $this->callAPISuccessGetValue('PriceField', array('return' => "price_set_id", 'id' => $value['price_field_id'])); + $setId = $this->callAPISuccessGetValue('PriceField', ['return' => "price_set_id", 'id' => $value['price_field_id']]); if ($setId == $priceSet) { $this->assertEquals($value['label'], $updateParams['name']); $this->assertEquals($value['description'], $updateParams['description']); @@ -339,7 +339,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { } foreach ($memType as $type) { - $this->callAPISuccess('membership_type', 'delete', array('id' => $type)); + $this->callAPISuccess('membership_type', 'delete', ['id' => $type]); } } diff --git a/tests/phpunit/api/v3/MessageTemplateTest.php b/tests/phpunit/api/v3/MessageTemplateTest.php index bb45d30187..41a134033e 100644 --- a/tests/phpunit/api/v3/MessageTemplateTest.php +++ b/tests/phpunit/api/v3/MessageTemplateTest.php @@ -41,7 +41,7 @@ class api_v3_MessageTemplateTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray(); - $this->params = array( + $this->params = [ 'msg_title' => $template['msg_title'], 'msg_subject' => $template['msg_subject'], 'msg_text' => $template['msg_text'], @@ -49,7 +49,7 @@ class api_v3_MessageTemplateTest extends CiviUnitTestCase { 'workflow_id' => $template['workflow_id'], 'is_default' => $template['is_default'], 'is_reserved' => $template['is_reserved'], - ); + ]; } public function tearDown() { @@ -84,18 +84,22 @@ class api_v3_MessageTemplateTest extends CiviUnitTestCase { */ public function testDelete() { $entity = $this->createTestEntity(); - $result = $this->callAPIAndDocument('MessageTemplate', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPIAndDocument('MessageTemplate', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__); + $checkDeleted = $this->callAPISuccess($this->entity, 'get', [ 'id' => $entity['id'], - )); + ]); $this->assertEquals(0, $checkDeleted['count']); } public function testPermissionChecks() { $entity = $this->createTestEntity(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit user-driven message templates'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit user-driven message templates']; // Ensure that it cannot create a system message or update a system message tempalte given current permissions. - $this->callAPIFailure('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject', 'check_permissions' => TRUE]); + $this->callAPIFailure('MessageTemplate', 'create', [ + 'id' => $entity['id'], + 'msg_subject' => 'test msg permission subject', + 'check_permissions' => TRUE, + ]); $testUserEntity = $entity['values'][$entity['id']]; unset($testUserEntity['id']); $testUserEntity['msg_subject'] = 'Test user message template'; @@ -103,16 +107,35 @@ class api_v3_MessageTemplateTest extends CiviUnitTestCase { $testuserEntity['check_permissions'] = TRUE; // ensure that it can create user templates; $userEntity = $this->callAPISuccess('MessageTemplate', 'create', $testUserEntity); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit system workflow message templates'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit system workflow message templates']; // Now check that when its swapped around permissions that the correct reponses are detected. - $this->callAPIFailure('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by system message permission', 'check_permissions' => TRUE]); - $this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject', 'check_permissions' => TRUE]); + $this->callAPIFailure('MessageTemplate', 'create', [ + 'id' => $userEntity['id'], + 'msg_subject' => 'User template updated by system message permission', + 'check_permissions' => TRUE, + ]); + $this->callAPISuccess('MessageTemplate', 'create', [ + 'id' => $entity['id'], + 'msg_subject' => 'test msg permission subject', + 'check_permissions' => TRUE, + ]); // verify with all 3 permissions someone can do everything. - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit system workflow message templates', 'edit user-driven message templates'); - $this->callAPISuccess('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by system message permission', 'check_permissions' => TRUE]); - $this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject', 'check_permissions' => TRUE]); + CRM_Core_Config::singleton()->userPermissionClass->permissions = [ + 'edit system workflow message templates', + 'edit user-driven message templates', + ]; + $this->callAPISuccess('MessageTemplate', 'create', [ + 'id' => $userEntity['id'], + 'msg_subject' => 'User template updated by system message permission', + 'check_permissions' => TRUE, + ]); + $this->callAPISuccess('MessageTemplate', 'create', [ + 'id' => $entity['id'], + 'msg_subject' => 'test msg permission subject', + 'check_permissions' => TRUE, + ]); // Verify that the backwards compatabiltiy still works i.e. having edit message templates allows for editing of both kinds of message templates - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit message templates'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit message templates']; $this->callAPISuccess('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by edit message permission', 'check_permissions' => TRUE]); $this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject backwards compatabilty', 'check_permissions' => TRUE]); } diff --git a/tests/phpunit/api/v3/MultilingualTest.php b/tests/phpunit/api/v3/MultilingualTest.php index 6e1fd156a0..87a9de72b5 100644 --- a/tests/phpunit/api/v3/MultilingualTest.php +++ b/tests/phpunit/api/v3/MultilingualTest.php @@ -68,33 +68,33 @@ class api_v3_MultilingualTest extends CiviUnitTestCase { // Take a semi-random OptionGroup and test manually changing its label // in one language, while making sure it stays the same in English. - $group = $this->callAPISuccess('OptionGroup', 'getsingle', array( + $group = $this->callAPISuccess('OptionGroup', 'getsingle', [ 'name' => 'contact_edit_options', - )); + ]); - $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array( + $english_original = $this->callAPISuccess('OptionValue', 'getsingle', [ 'option_group_id' => $group['id'], 'name' => 'IM', - )); + ]); - $this->callAPISuccess('OptionValue', 'create', array( + $this->callAPISuccess('OptionValue', 'create', [ 'id' => $english_original['id'], 'name' => 'IM', 'label' => 'Messagerie instantanée', 'option.language' => 'fr_CA', - )); + ]); - $french = $this->callAPISuccess('OptionValue', 'getsingle', array( + $french = $this->callAPISuccess('OptionValue', 'getsingle', [ 'option_group_id' => $group['id'], 'name' => 'IM', 'options' => ['language' => 'fr_CA'], - )); + ]); // Ensure that after language is changed in previous call it will go back to the default. - $default = $this->callAPISuccess('OptionValue', 'getsingle', array( + $default = $this->callAPISuccess('OptionValue', 'getsingle', [ 'option_group_id' => $group['id'], 'name' => 'IM', - )); + ]); $this->assertEquals($french['label'], 'Messagerie instantanée'); $this->assertEquals($default['label'], $english_original['label']); @@ -108,15 +108,15 @@ class api_v3_MultilingualTest extends CiviUnitTestCase { $this->enableMultilingual(); // list of entities which has mandatory attributes - $specialEntities = array( - 'Attachment' => array('id' => 13), - 'CustomValue' => array('entity_id' => 13), - 'MailingContact' => array('contact_id' => 13), - 'Profile' => array('profile_id' => 13), - 'MailingGroup' => array('mailing_id' => 13), - ); + $specialEntities = [ + 'Attachment' => ['id' => 13], + 'CustomValue' => ['entity_id' => 13], + 'MailingContact' => ['contact_id' => 13], + 'Profile' => ['profile_id' => 13], + 'MailingGroup' => ['mailing_id' => 13], + ]; // deprecated or API.Get is not supported/implemented - $skippableEntities = array( + $skippableEntities = [ 'Logging', 'MailingEventConfirm', 'MailingEventResubscribe', @@ -131,13 +131,13 @@ class api_v3_MultilingualTest extends CiviUnitTestCase { 'UFGroup', // need loggedIn user id 'User', - ); + ]; // fetch all entities - $entities = $this->callAPISuccess('Entity', 'get', array()); + $entities = $this->callAPISuccess('Entity', 'get', []); $skippableEntities = array_merge($skippableEntities, $entities['deprecated']); foreach ($entities['values'] as $entity) { - $params = array('check_permissions' => 1); + $params = ['check_permissions' => 1]; if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') { continue; } diff --git a/tests/phpunit/api/v3/NavigationTest.php b/tests/phpunit/api/v3/NavigationTest.php index 80b65935e8..cef398e6b8 100644 --- a/tests/phpunit/api/v3/NavigationTest.php +++ b/tests/phpunit/api/v3/NavigationTest.php @@ -42,7 +42,7 @@ class api_v3_NavigationTest extends CiviUnitTestCase { */ public function testGet($version) { $this->_apiversion = $version; - $this->callAPISuccess($this->_entity, 'getsingle', array('label' => 'Manage Groups', 'domain_id' => 1)); + $this->callAPISuccess($this->_entity, 'getsingle', ['label' => 'Manage Groups', 'domain_id' => 1]); } /** @@ -51,16 +51,16 @@ class api_v3_NavigationTest extends CiviUnitTestCase { */ public function testGetByParent() { // get by name - $this->callAPISuccess($this->_entity, 'get', array('parentID' => 'Administer', 'domain_id' => 1)); + $this->callAPISuccess($this->_entity, 'get', ['parentID' => 'Administer', 'domain_id' => 1]); - $params = array( + $params = [ 'name' => 'Administer', 'domain_id' => 1, 'return' => 'id', - ); + ]; $adminId = $this->callAPISuccess($this->_entity, 'getvalue', $params); - $this->callAPISuccess($this->_entity, 'get', array('parentID' => $adminId, 'domain_id' => 1)); + $this->callAPISuccess($this->_entity, 'get', ['parentID' => $adminId, 'domain_id' => 1]); } /** @@ -70,7 +70,7 @@ class api_v3_NavigationTest extends CiviUnitTestCase { */ public function testCreate($version) { $this->_apiversion = $version; - $params = array('label' => 'Feed the Goats', 'domain_id' => 1); + $params = ['label' => 'Feed the Goats', 'domain_id' => 1]; $result = $this->callAPISuccess($this->_entity, 'create', $params); $this->getAndCheck($params, $result['id'], $this->_entity, TRUE); } @@ -82,7 +82,7 @@ class api_v3_NavigationTest extends CiviUnitTestCase { */ public function testDefaultDomain($version) { $this->_apiversion = $version; - $params = array('label' => 'Herd the Cats'); + $params = ['label' => 'Herd the Cats']; $result = $this->callAPISuccess($this->_entity, 'create', $params); // Check domain_id has been set per default $params['domain_id'] = CRM_Core_Config::domainID(); @@ -96,13 +96,13 @@ class api_v3_NavigationTest extends CiviUnitTestCase { */ public function testDelete($version) { $this->_apiversion = $version; - $getParams = array( + $getParams = [ 'return' => 'id', - 'options' => array('limit' => 1), - ); + 'options' => ['limit' => 1], + ]; $result = $this->callAPISuccess('Navigation', 'getvalue', $getParams); - $this->callAPISuccess('Navigation', 'delete', array('id' => $result)); - $this->callAPIFailure('Navigation', 'getvalue', array('id' => $result)); + $this->callAPISuccess('Navigation', 'delete', ['id' => $result]); + $this->callAPIFailure('Navigation', 'getvalue', ['id' => $result]); } } diff --git a/tests/phpunit/api/v3/NoteTest.php b/tests/phpunit/api/v3/NoteTest.php index 3ff660bc65..4887d5f80d 100644 --- a/tests/phpunit/api/v3/NoteTest.php +++ b/tests/phpunit/api/v3/NoteTest.php @@ -44,14 +44,14 @@ class api_v3_NoteTest extends CiviUnitTestCase { $this->_contactID = $this->organizationCreate(NULL); - $this->_params = array( + $this->_params = [ 'entity_table' => 'civicrm_contact', 'entity_id' => $this->_contactID, 'note' => 'Hello!!! m testing Note', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => 'Test Note', - ); + ]; $this->_note = $this->noteCreate($this->_contactID); $this->_noteID = $this->_note['id']; } @@ -67,7 +67,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testGetWithEmptyParams($version) { $this->_apiversion = $version; - $this->callAPISuccess('note', 'get', array()); + $this->callAPISuccess('note', 'get', []); } /** @@ -79,9 +79,9 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testGetWithoutEntityId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'entity_table' => 'civicrm_contact', - ); + ]; $this->callAPISuccess('note', 'get', $params); } @@ -93,10 +93,10 @@ class api_v3_NoteTest extends CiviUnitTestCase { public function testGet($version) { $this->_apiversion = $version; $entityId = $this->_noteID; - $params = array( + $params = [ 'entity_table' => 'civicrm_contact', 'entity_id' => $entityId, - ); + ]; $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__); } @@ -164,7 +164,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testCreateWithApostropheInString($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'entity_table' => 'civicrm_contact', 'entity_id' => $this->_contactID, 'note' => "Hello!!! ' testing Note", @@ -172,7 +172,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { 'modified_date' => '2011-01-31', 'subject' => "With a '", 'sequential' => 1, - ); + ]; $result = $this->callAPISuccess('Note', 'Create', $params); $this->assertAPISuccess($result); $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note"); @@ -203,7 +203,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testUpdateWithEmptyParams($version) { $this->_apiversion = $version; - $this->callAPIFailure('note', 'create', array()); + $this->callAPIFailure('note', 'create', []); } /** @@ -215,10 +215,10 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testUpdateWithoutContactId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'entity_id' => $this->_contactID, 'entity_table' => 'civicrm_contact', - ); + ]; $this->callAPIFailure('note', 'create', $params, 'missing' ); @@ -231,16 +231,16 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testUpdate($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'id' => $this->_noteID, 'contact_id' => $this->_contactID, 'note' => 'Note1', 'subject' => 'Hello World', - ); + ]; // Update Note. $this->callAPISuccess('note', 'create', $params); - $note = $this->callAPISuccess('Note', 'Get', array()); + $note = $this->callAPISuccess('Note', 'Get', []); $this->assertEquals($note['id'], $this->_noteID); $this->assertEquals($note['values'][$this->_noteID]['entity_id'], $this->_contactID); $this->assertEquals($note['values'][$this->_noteID]['entity_table'], 'civicrm_contact'); @@ -254,7 +254,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { * Error expected. */ public function testDeleteWithEmptyParams() { - $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id'); + $this->callAPIFailure('note', 'delete', [], 'Mandatory key(s) missing from params array: id'); } /** @@ -266,9 +266,9 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ public function testDeleteWithWrongID($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'id' => 99999, - ); + ]; $this->callAPIFailure('note', 'delete', $params, 'Note'); } @@ -281,36 +281,36 @@ class api_v3_NoteTest extends CiviUnitTestCase { $this->_apiversion = $version; $additionalNote = $this->noteCreate($this->_contactID); - $params = array( + $params = [ 'id' => $additionalNote['id'], - ); + ]; $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__); } public function testNoteJoin() { - $org = $this->callAPISuccess('Contact', 'create', array( + $org = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Organization', 'organization_name' => 'Org123', - 'api.Note.create' => array( + 'api.Note.create' => [ 'note' => 'Hello join', - ), - )); + ], + ]); // Fetch contact info via join - $result = $this->callAPISuccessGetSingle('Note', array( - 'return' => array("entity_id.organization_name", "note"), + $result = $this->callAPISuccessGetSingle('Note', [ + 'return' => ["entity_id.organization_name", "note"], 'entity_id' => $org['id'], 'entity_table' => "civicrm_contact", - )); + ]); $this->assertEquals('Org123', $result['entity_id.organization_name']); $this->assertEquals('Hello join', $result['note']); // This should return no results by restricting contact_type - $result = $this->callAPISuccess('Note', 'get', array( - 'return' => array("entity_id.organization_name"), + $result = $this->callAPISuccess('Note', 'get', [ + 'return' => ["entity_id.organization_name"], 'entity_id' => $org['id'], 'entity_table' => "civicrm_contact", 'entity_id.contact_type' => "Individual", - )); + ]); $this->assertEquals(0, $result['count']); } diff --git a/tests/phpunit/api/v3/OpenIDTest.php b/tests/phpunit/api/v3/OpenIDTest.php index ae13645094..d3a065aac8 100644 --- a/tests/phpunit/api/v3/OpenIDTest.php +++ b/tests/phpunit/api/v3/OpenIDTest.php @@ -47,11 +47,11 @@ class api_v3_OpenIDTest extends CiviUnitTestCase { $this->_entity = 'OpenID'; $this->_contactID = $this->organizationCreate(); - $this->params = array( + $this->params = [ 'contact_id' => $this->_contactID, 'openid' => 'My OpenID handle', 'location_type_id' => 1, - ); + ]; } /** @@ -76,7 +76,7 @@ class api_v3_OpenIDTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } /** @@ -86,9 +86,9 @@ class api_v3_OpenIDTest extends CiviUnitTestCase { public function testDeleteOpenID($version) { $this->_apiversion = $version; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); + $deleteParams = ['id' => $result['id']]; $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__); } @@ -99,9 +99,9 @@ class api_v3_OpenIDTest extends CiviUnitTestCase { public function testDeleteOpenIDInvalid($version) { $this->_apiversion = $version; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => 600); + $deleteParams = ['id' => 600]; $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/OptionValueTest.php b/tests/phpunit/api/v3/OptionValueTest.php index f2f3720460..681653b4e0 100644 --- a/tests/phpunit/api/v3/OptionValueTest.php +++ b/tests/phpunit/api/v3/OptionValueTest.php @@ -38,18 +38,18 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { } public function testGetCount() { - $result = $this->callAPISuccess('option_value', 'getcount', array()); + $result = $this->callAPISuccess('option_value', 'getcount', []); $this->assertGreaterThan(100, $result); } public function testGetOptionValueByID() { - $result = $this->callAPISuccess('option_value', 'get', array('id' => 1)); + $result = $this->callAPISuccess('option_value', 'get', ['id' => 1]); $this->assertEquals(1, $result['count']); $this->assertEquals(1, $result['id']); } public function testGetOptionValueByValue() { - $result = $this->callAPISuccess('option_value', 'get', array('option_group_id' => 1, 'value' => '1')); + $result = $this->callAPISuccess('option_value', 'get', ['option_group_id' => 1, 'value' => '1']); $this->assertEquals(1, $result['count']); $this->assertEquals(1, $result['id']); } @@ -58,7 +58,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { * Test limit param. */ public function testGetOptionValueLimit() { - $params = array(); + $params = []; $result = $this->callAPISuccess('option_value', 'get', $params); $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__); $params['options']['limit'] = 1; @@ -71,15 +71,15 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testGetOptionValueOffSet() { - $result = $this->callAPISuccess('option_value', 'get', array( + $result = $this->callAPISuccess('option_value', 'get', [ 'option_group_id' => 1, 'value' => '1', - )); - $result2 = $this->callAPISuccess('option_value', 'get', array( + ]); + $result2 = $this->callAPISuccess('option_value', 'get', [ 'option_group_id' => 1, 'value' => '1', - 'options' => array('offset' => 1), - )); + 'options' => ['offset' => 1], + ]); $this->assertGreaterThan($result2['count'], $result['count']); } @@ -89,20 +89,20 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { public function testGetSingleValueOptionValueSort() { $description = "Demonstrates use of Sort param (available in many api functions). Also, getsingle."; $subfile = 'SortOption'; - $result = $this->callAPISuccess('option_value', 'getsingle', array( + $result = $this->callAPISuccess('option_value', 'getsingle', [ 'option_group_id' => 1, - 'options' => array( + 'options' => [ 'sort' => 'label ASC', 'limit' => 1, - ), - )); - $params = array( + ], + ]); + $params = [ 'option_group_id' => 1, - 'options' => array( + 'options' => [ 'sort' => 'label DESC', 'limit' => 1, - ), - ); + ], + ]; $result2 = $this->callAPIAndDocument('option_value', 'getsingle', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertGreaterThan($result['label'], $result2['label']); } @@ -112,14 +112,14 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testGetValueOptionPagination() { $pageSize = 10; - $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize))); - $page2 = $this->callAPISuccess('option_value', 'get', array( - 'options' => array( + $page1 = $this->callAPISuccess('option_value', 'get', ['options' => ['limit' => $pageSize]]); + $page2 = $this->callAPISuccess('option_value', 'get', [ + 'options' => [ 'limit' => $pageSize, // if you use it for pagination, option.offset=pageSize*pageNumber 'offset' => $pageSize - 1, - ), - )); + ], + ]); $this->assertEquals($pageSize, $page1['count'], "Check only 10 retrieved in the 1st page " . __LINE__); $this->assertEquals($pageSize, $page2['count'], "Check only 10 retrieved in the 2nd page " . __LINE__); @@ -130,7 +130,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { } public function testGetOptionGroup() { - $params = array('option_group_id' => 1); + $params = ['option_group_id' => 1]; $result = $this->callAPIAndDocument('option_value', 'get', $params, __FUNCTION__, __FILE__); $this->assertGreaterThan(1, $result['count']); } @@ -139,8 +139,8 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { * Test that using option_group_name returns more than 1 & less than all */ public function testGetOptionGroupByName() { - $activityTypesParams = array('option_group_name' => 'activity_type', 'option.limit' => 100); - $params = array('option.limit' => 100); + $activityTypesParams = ['option_group_name' => 'activity_type', 'option.limit' => 100]; + $params = ['option.limit' => 100]; $activityTypes = $this->callAPISuccess('option_value', 'get', $activityTypesParams); $result = $this->callAPISuccess('option_value', 'get', $params); $this->assertGreaterThan(1, $activityTypes['count']); @@ -148,7 +148,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { } public function testGetOptionDoesNotExist() { - $result = $this->callAPISuccess('option_value', 'get', array('label' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB')); + $result = $this->callAPISuccess('option_value', 'get', ['label' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB']); $this->assertEquals(0, $result['count']); } @@ -156,60 +156,60 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { * Check that domain_id is honoured. */ public function testCreateOptionSpecifyDomain() { - $result = $this->callAPISuccess('option_group', 'get', array( + $result = $this->callAPISuccess('option_group', 'get', [ 'name' => 'from_email_address', 'sequential' => 1, - 'api.option_value.create' => array('domain_id' => 2, 'name' => 'my@y.com', 'value' => '10'), - )); + 'api.option_value.create' => ['domain_id' => 2, 'name' => 'my@y.com', 'value' => '10'], + ]); $optionValueId = $result['values'][0]['api.option_value.create']['id']; - $domain_id = $this->callAPISuccess('option_value', 'getvalue', array( + $domain_id = $this->callAPISuccess('option_value', 'getvalue', [ 'id' => $optionValueId, 'return' => 'domain_id', - )); + ]); $this->assertEquals(2, $domain_id); - $this->callAPISuccess('option_value', 'delete', array('id' => $optionValueId)); + $this->callAPISuccess('option_value', 'delete', ['id' => $optionValueId]); } /** * Check that component_id is honoured. */ public function testCreateOptionSpecifyComponentID() { - $result = $this->callAPISuccess('option_group', 'get', array( + $result = $this->callAPISuccess('option_group', 'get', [ 'name' => 'from_email_address', 'sequential' => 1, - 'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'), - )); + 'api.option_value.create' => ['component_id' => 2, 'name' => 'my@y.com'], + ]); $this->assertAPISuccess($result); $optionValueId = $result['values'][0]['api.option_value.create']['id']; - $component_id = $this->callAPISuccess('option_value', 'getvalue', array( + $component_id = $this->callAPISuccess('option_value', 'getvalue', [ 'id' => $optionValueId, 'return' => 'component_id', - )); + ]); $this->assertEquals(2, $component_id); - $this->callAPISuccess('option_value', 'delete', array('id' => $optionValueId)); + $this->callAPISuccess('option_value', 'delete', ['id' => $optionValueId]); } /** * Check that component string is honoured. */ public function testCreateOptionSpecifyComponentString() { - $result = $this->callAPISuccess('option_group', 'get', array( + $result = $this->callAPISuccess('option_group', 'get', [ 'name' => 'from_email_address', 'sequential' => 1, - 'api.option_value.create' => array( + 'api.option_value.create' => [ 'component_id' => 'CiviContribute', 'name' => 'my@y.com', - ), - )); + ], + ]); $this->assertAPISuccess($result); $optionValueId = $result['values'][0]['api.option_value.create']['id']; - $component_id = $this->callAPISuccess('option_value', 'getvalue', array( + $component_id = $this->callAPISuccess('option_value', 'getvalue', [ 'id' => $optionValueId, 'return' => 'component_id', - )); + ]); $this->assertEquals(2, $component_id); - $this->callAPISuccess('option_value', 'delete', array('id' => $optionValueId)); + $this->callAPISuccess('option_value', 'delete', ['id' => $optionValueId]); } /** @@ -218,44 +218,44 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { public function testGetOptionWithComponent() { $components = Civi::settings()->get('enable_components'); CRM_Core_BAO_ConfigSetting::enableComponent('CiviContribute'); - $this->callAPISuccess('option_group', 'get', array( + $this->callAPISuccess('option_group', 'get', [ 'name' => 'gender', - 'api.option_value.create' => array( + 'api.option_value.create' => [ 'component_id' => 'CiviContribute', 'name' => 'Contrib', - ), - )); + ], + ]); // Verify new option is present - $genders = $this->callAPISuccess('contact', 'getoptions', array( + $genders = $this->callAPISuccess('contact', 'getoptions', [ 'field' => 'gender_id', 'context' => 'create', - )); + ]); $this->assertContains('Contrib', $genders['values']); // Disable relevant component CRM_Core_BAO_ConfigSetting::disableComponent('CiviContribute'); CRM_Core_PseudoConstant::flush(); // New option should now be hidden for "create" context - $genders = $this->callAPISuccess('contact', 'getoptions', array( + $genders = $this->callAPISuccess('contact', 'getoptions', [ 'field' => 'gender_id', 'context' => 'create', - )); + ]); $this->assertNotContains('Contrib', $genders['values']); // New option should be visible for "get" context even with component disabled - $genders = $this->callAPISuccess('contact', 'getoptions', array( + $genders = $this->callAPISuccess('contact', 'getoptions', [ 'field' => 'gender_id', 'context' => 'get', - )); + ]); $this->assertContains('Contrib', $genders['values']); // Now disable all components and ensure we can still fetch options with no errors - CRM_Core_BAO_ConfigSetting::setEnabledComponents(array()); + CRM_Core_BAO_ConfigSetting::setEnabledComponents([]); CRM_Core_PseudoConstant::flush(); // New option should still be hidden for "create" context - $genders = $this->callAPISuccess('contact', 'getoptions', array( + $genders = $this->callAPISuccess('contact', 'getoptions', [ 'field' => 'gender_id', 'context' => 'create', - )); + ]); $this->assertNotContains('Contrib', $genders['values']); // Restore original state @@ -267,40 +267,40 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testCRM12133CreateOptionWeightNoValue() { $optionGroup = $this->callAPISuccess( - 'option_group', 'get', array( + 'option_group', 'get', [ 'name' => 'gender', 'sequential' => 1, - ) + ] ); $this->assertAPISuccess($optionGroup); - $params = array( + $params = [ 'option_group_id' => $optionGroup['id'], 'label' => 'my@y.com', 'weight' => 3, - ); + ]; $optionValue = $this->callAPISuccess('option_value', 'create', $params); $this->assertAPISuccess($optionValue); $params['weight'] = 4; $optionValue2 = $this->callAPISuccess('option_value', 'create', $params); $this->assertAPISuccess($optionValue2); - $options = $this->callAPISuccess('option_value', 'get', array('option_group_id' => $optionGroup['id'])); + $options = $this->callAPISuccess('option_value', 'get', ['option_group_id' => $optionGroup['id']]); $this->assertNotEquals($options['values'][$optionValue['id']]['value'], $options['values'][$optionValue2['id']]['value']); //cleanup - $this->callAPISuccess('option_value', 'delete', array('id' => $optionValue['id'])); - $this->callAPISuccess('option_value', 'delete', array('id' => $optionValue2['id'])); + $this->callAPISuccess('option_value', 'delete', ['id' => $optionValue['id']]); + $this->callAPISuccess('option_value', 'delete', ['id' => $optionValue2['id']]); } /** * Check that domain_id is honoured. */ public function testCreateOptionNoName() { - $optionGroup = $this->callAPISuccess('option_group', 'get', array( + $optionGroup = $this->callAPISuccess('option_group', 'get', [ 'name' => 'gender', 'sequential' => 1, - )); + ]); - $params = array('option_group_id' => $optionGroup['id'], 'label' => 'my@y.com'); + $params = ['option_group_id' => $optionGroup['id'], 'label' => 'my@y.com']; $optionValue = $this->callAPISuccess('option_value', 'create', $params); $this->assertAPISuccess($optionValue); $this->getAndCheck($params, $optionValue['id'], 'option_value'); @@ -310,22 +310,22 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { * Check that pseudoconstant reflects new value added. */ public function testCRM11876CreateOptionPseudoConstantUpdated() { - $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array( + $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', [ 'name' => 'payment_instrument', 'return' => 'id', - )); + ]); $newOption = (string) time(); - $apiResult = $this->callAPISuccess('option_value', 'create', array( + $apiResult = $this->callAPISuccess('option_value', 'create', [ 'option_group_id' => $optionGroupID, 'label' => $newOption, - )); + ]); - $fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $fields = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); $this->assertTrue(in_array($newOption, $fields['values'])); - $this->callAPISuccess('option_value', 'delete', array('id' => $apiResult['id'])); + $this->callAPISuccess('option_value', 'delete', ['id' => $apiResult['id']]); - $fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $fields = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']); $this->assertFalse(in_array($newOption, $fields['values'])); } @@ -335,17 +335,17 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testUpdateOptionValueNoGroupId() { // create a option group - $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group', 'is_active' => 1)); + $og = $this->callAPISuccess('option_group', 'create', ['name' => 'our test Option Group', 'is_active' => 1]); // create a option value $ov = $this->callAPISuccess('option_value', 'create', - array('option_group_id' => $og['id'], 'label' => 'test option value') + ['option_group_id' => $og['id'], 'label' => 'test option value'] ); // update option value without 'option_group_id' - $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0)); - $val = $this->callAPISuccess('option_value', 'getvalue', array( + $res = $this->callAPISuccess('option_value', 'create', ['id' => $ov['id'], 'is_active' => 0]); + $val = $this->callAPISuccess('option_value', 'getvalue', [ 'id' => $ov['id'], 'return' => 'is_active', - )); + ]); $this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__); } @@ -355,24 +355,24 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testUpdateOptionValueWithGroupId() { // create a option group - $og = $this->callAPISuccess('option_group', 'create', array( + $og = $this->callAPISuccess('option_group', 'create', [ 'name' => 'our test Option Group for with group id', 'is_active' => 1, - )); + ]); // create a option value $ov = $this->callAPISuccess('option_value', 'create', - array('option_group_id' => $og['id'], 'label' => 'test option value') + ['option_group_id' => $og['id'], 'label' => 'test option value'] ); // update option value without 'option_group_id' - $this->callAPISuccess('option_value', 'create', array( + $this->callAPISuccess('option_value', 'create', [ 'id' => $ov['id'], 'option_group_id' => $og['id'], 'is_active' => 0, - )); - $val = $this->callAPISuccess('option_value', 'getvalue', array( + ]); + $val = $this->callAPISuccess('option_value', 'getvalue', [ 'id' => $ov['id'], 'return' => 'is_active', - )); + ]); $this->assertEquals($val, 0, "update with group id is not proper " . __LINE__); } @@ -380,17 +380,17 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { * CRM-19346 Ensure that Option Values cannot share same value in the same option value group */ public function testCreateOptionValueWithSameValue() { - $og = $this->callAPISuccess('option_group', 'create', array( + $og = $this->callAPISuccess('option_group', 'create', [ 'name' => 'our test Option Group for with group id', 'is_active' => 1, - )); + ]); // create a option value $ov = $this->callAPISuccess('option_value', 'create', - array('option_group_id' => $og['id'], 'label' => 'test option value') + ['option_group_id' => $og['id'], 'label' => 'test option value'] ); // update option value without 'option_group_id' $this->callAPIFailure('option_value', 'create', - array('option_group_id' => $og['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value']) + ['option_group_id' => $og['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value']] ); } @@ -408,21 +408,21 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { } public function testCreateOptionValueWithSameValueDiffOptionGroup() { - $og = $this->callAPISuccess('option_group', 'create', array( + $og = $this->callAPISuccess('option_group', 'create', [ 'name' => 'our test Option Group for with group id', 'is_active' => 1, - )); + ]); // create a option value $ov = $this->callAPISuccess('option_value', 'create', - array('option_group_id' => $og['id'], 'label' => 'test option value') + ['option_group_id' => $og['id'], 'label' => 'test option value'] ); - $og2 = $this->callAPISuccess('option_group', 'create', array( + $og2 = $this->callAPISuccess('option_group', 'create', [ 'name' => 'our test Option Group for with group id 2', 'is_active' => 1, - )); + ]); // update option value without 'option_group_id' $ov2 = $this->callAPISuccess('option_value', 'create', - array('option_group_id' => $og2['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value']) + ['option_group_id' => $og2['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value']] ); } diff --git a/tests/phpunit/api/v3/OrderTest.php b/tests/phpunit/api/v3/OrderTest.php index f1302a844f..ef53f55493 100644 --- a/tests/phpunit/api/v3/OrderTest.php +++ b/tests/phpunit/api/v3/OrderTest.php @@ -54,7 +54,7 @@ class api_v3_OrderTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_uf_match')); + $this->quickCleanup(['civicrm_uf_match']); } /** @@ -63,33 +63,33 @@ class api_v3_OrderTest extends CiviUnitTestCase { public function testGetOrder() { $contribution = $this->addOrder(FALSE, 100); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], - ); + ]; $order = $this->callAPIAndDocument('Order', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals(1, $order['count']); - $expectedResult = array( - $contribution['id'] => array( + $expectedResult = [ + $contribution['id'] => [ 'total_amount' => 100, 'contribution_id' => $contribution['id'], 'contribution_status' => 'Completed', 'net_amount' => 100, - ), - ); - $lineItems[] = array( + ], + ]; + $lineItems[] = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], 'contribution_id' => $contribution['id'], 'unit_price' => 100, 'line_total' => 100, 'financial_type_id' => 1, - ); + ]; $this->checkPaymentResult($order, $expectedResult, $lineItems); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution['id'], - )); + ]); } /** @@ -99,16 +99,16 @@ class api_v3_OrderTest extends CiviUnitTestCase { $this->addOrder(FALSE, 100); list($items, $contribution) = $this->createParticipantWithContribution(); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], - ); + ]; $order = $this->callAPISuccess('Order', 'get', $params); $this->assertEquals(2, count($order['values'][$contribution['id']]['line_items'])); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution['id'], - )); + ]); } /** @@ -137,19 +137,19 @@ class api_v3_OrderTest extends CiviUnitTestCase { * * @return array */ - public function addOrder($isPriceSet, $amount = 300.00, $extraParams = array()) { - $p = array( + public function addOrder($isPriceSet, $amount = 300.00, $extraParams = []) { + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', 'total_amount' => $amount, 'financial_type_id' => $this->_financialTypeId, 'contribution_status_id' => 1, - ); + ]; if ($isPriceSet) { $priceFields = $this->createPriceSet(); foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[1][$key] = array( + $lineItems[1][$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -158,7 +158,7 @@ class api_v3_OrderTest extends CiviUnitTestCase { 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id'], - ); + ]; } $p['line_item'] = $lineItems; } @@ -171,30 +171,30 @@ class api_v3_OrderTest extends CiviUnitTestCase { */ public function testAddOrder() { $order = $this->addOrder(FALSE, 100); - $params = array( + $params = [ 'contribution_id' => $order['id'], - ); + ]; $order = $this->callAPISuccess('order', 'get', $params); - $expectedResult = array( - $order['id'] => array( + $expectedResult = [ + $order['id'] => [ 'total_amount' => 100, 'contribution_id' => $order['id'], 'contribution_status' => 'Completed', 'net_amount' => 100, - ), - ); - $lineItems[] = array( + ], + ]; + $lineItems[] = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $order['id'], 'contribution_id' => $order['id'], 'unit_price' => 100, 'line_total' => 100, 'financial_type_id' => 1, - ); + ]; $this->checkPaymentResult($order, $expectedResult, $lineItems); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $order['id'], - )); + ]); } /** @@ -203,17 +203,17 @@ class api_v3_OrderTest extends CiviUnitTestCase { public function testAddOrderForMembership() { $membershipType = $this->membershipTypeCreate(); $membershipType1 = $this->membershipTypeCreate(); - $membershipType = $membershipTypes = array($membershipType, $membershipType1); - $p = array( + $membershipType = $membershipTypes = [$membershipType, $membershipType1]; + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', 'total_amount' => 200, 'financial_type_id' => 'Event Fee', 'contribution_status_id' => 1, - ); + ]; $priceFields = $this->createPriceSet(); foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[$key] = array( + $lineItems[$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -224,11 +224,11 @@ class api_v3_OrderTest extends CiviUnitTestCase { 'financial_type_id' => $priceField['financial_type_id'], 'entity_table' => 'civicrm_membership', 'membership_type_id' => array_pop($membershipType), - ); + ]; } - $p['line_items'][] = array( - 'line_item' => array(array_pop($lineItems)), - 'params' => array( + $p['line_items'][] = [ + 'line_item' => [array_pop($lineItems)], + 'params' => [ 'contact_id' => $this->_individualId, 'membership_type_id' => array_pop($membershipTypes), 'join_date' => '2006-01-21', @@ -237,29 +237,29 @@ class api_v3_OrderTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => 1, - ), - ); + ], + ]; $order = $this->callAPIAndDocument('order', 'create', $p, __FUNCTION__, __FILE__); - $params = array( + $params = [ 'contribution_id' => $order['id'], - ); + ]; $order = $this->callAPISuccess('order', 'get', $params); - $expectedResult = array( - $order['id'] => array( + $expectedResult = [ + $order['id'] => [ 'total_amount' => 200, 'contribution_id' => $order['id'], 'contribution_status' => 'Completed', 'net_amount' => 200, - ), - ); + ], + ]; $this->checkPaymentResult($order, $expectedResult); $this->callAPISuccessGetCount('MembershipPayment', $params, 1); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $order['id'], - )); - $p['line_items'][] = array( - 'line_item' => array(array_pop($lineItems)), - 'params' => array( + ]); + $p['line_items'][] = [ + 'line_item' => [array_pop($lineItems)], + 'params' => [ 'contact_id' => $this->_individualId, 'membership_type_id' => array_pop($membershipTypes), 'join_date' => '2006-01-21', @@ -268,26 +268,26 @@ class api_v3_OrderTest extends CiviUnitTestCase { 'source' => 'Payment', 'is_override' => 1, 'status_id' => 1, - ), - ); + ], + ]; $p['total_amount'] = 300; $order = $this->callAPISuccess('order', 'create', $p); - $expectedResult = array( - $order['id'] => array( + $expectedResult = [ + $order['id'] => [ 'total_amount' => 300, 'contribution_status' => 'Completed', 'net_amount' => 300, - ), - ); - $paymentMembership = array( + ], + ]; + $paymentMembership = [ 'contribution_id' => $order['id'], - ); + ]; $order = $this->callAPISuccess('order', 'get', $paymentMembership); $this->checkPaymentResult($order, $expectedResult); $this->callAPISuccessGetCount('MembershipPayment', $paymentMembership, 2); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $order['id'], - )); + ]); } /** @@ -296,16 +296,16 @@ class api_v3_OrderTest extends CiviUnitTestCase { public function testAddOrderForParticipant() { $event = $this->eventCreate(); $this->_eventId = $event['id']; - $p = array( + $p = [ 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', 'total_amount' => 300, 'financial_type_id' => $this->_financialTypeId, 'contribution_status_id' => 1, - ); + ]; $priceFields = $this->createPriceSet(); foreach ($priceFields['values'] as $key => $priceField) { - $lineItems[$key] = array( + $lineItems[$key] = [ 'price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], @@ -315,66 +315,66 @@ class api_v3_OrderTest extends CiviUnitTestCase { 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id'], 'entity_table' => 'civicrm_participant', - ); + ]; } - $p['line_items'][] = array( + $p['line_items'][] = [ 'line_item' => $lineItems, - 'params' => array( + 'params' => [ 'contact_id' => $this->_individualId, 'event_id' => $this->_eventId, 'status_id' => 1, 'role_id' => 1, 'register_date' => '2007-07-21 00:00:00', 'source' => 'Online Event Registration: API Testing', - ), - ); + ], + ]; $order = $this->callAPIAndDocument('order', 'create', $p, __FUNCTION__, __FILE__, 'Create order for participant', 'CreateOrderParticipant'); - $params = array( + $params = [ 'contribution_id' => $order['id'], - ); + ]; $order = $this->callAPISuccess('order', 'get', $params); - $expectedResult = array( - $order['id'] => array( + $expectedResult = [ + $order['id'] => [ 'total_amount' => 300, 'contribution_id' => $order['id'], 'contribution_status' => 'Completed', 'net_amount' => 300, - ), - ); + ], + ]; $this->checkPaymentResult($order, $expectedResult); $this->callAPISuccessGetCount('ParticipantPayment', $params, 1); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $order['id'], - )); - $p['line_items'][] = array( + ]); + $p['line_items'][] = [ 'line_item' => $lineItems, - 'params' => array( + 'params' => [ 'contact_id' => $this->individualCreate(), 'event_id' => $this->_eventId, 'status_id' => 1, 'role_id' => 1, 'register_date' => '2007-07-21 00:00:00', 'source' => 'Online Event Registration: API Testing', - ), - ); + ], + ]; $p['total_amount'] = 600; $order = $this->callAPISuccess('order', 'create', $p); - $expectedResult = array( - $order['id'] => array( + $expectedResult = [ + $order['id'] => [ 'total_amount' => 600, 'contribution_status' => 'Completed', 'net_amount' => 600, - ), - ); - $paymentParticipant = array( + ], + ]; + $paymentParticipant = [ 'contribution_id' => $order['id'], - ); + ]; $order = $this->callAPISuccess('order', 'get', $paymentParticipant); $this->checkPaymentResult($order, $expectedResult); $this->callAPISuccessGetCount('ParticipantPayment', $paymentParticipant, 2); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $order['id'], - )); + ]); } /** @@ -382,51 +382,51 @@ class api_v3_OrderTest extends CiviUnitTestCase { */ public function testAddOrderWithLineItems() { $order = $this->addOrder(TRUE); - $params = array( + $params = [ 'contribution_id' => $order['id'], - ); + ]; $order = $this->callAPISuccess('order', 'get', $params); - $expectedResult = array( - $order['id'] => array( + $expectedResult = [ + $order['id'] => [ 'total_amount' => 300, 'contribution_id' => $order['id'], 'contribution_status' => 'Completed', 'net_amount' => 300, - ), - ); - $items[] = array( + ], + ]; + $items[] = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $order['id'], 'contribution_id' => $order['id'], 'unit_price' => 100, 'line_total' => 100, - ); - $items[] = array( + ]; + $items[] = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $order['id'], 'contribution_id' => $order['id'], 'unit_price' => 200, 'line_total' => 200, - ); + ]; $this->checkPaymentResult($order, $expectedResult, $items); - $params = array( + $params = [ 'entity_table' => 'civicrm_contribution', 'entity_id' => $order['id'], - ); + ]; $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params); $this->assertEquals($eft['values'][$eft['id']]['amount'], 300); - $params = array( + $params = [ 'entity_table' => 'civicrm_financial_item', 'financial_trxn_id' => $eft['values'][$eft['id']]['financial_trxn_id'], - ); + ]; $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params); - $amounts = array(200, 100); + $amounts = [200, 100]; foreach ($eft['values'] as $value) { $this->assertEquals($value['amount'], array_pop($amounts)); } - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $order['id'], - )); + ]); } /** @@ -434,18 +434,18 @@ class api_v3_OrderTest extends CiviUnitTestCase { */ public function testDeleteOrder() { $order = $this->addOrder(FALSE, 100); - $params = array( + $params = [ 'contribution_id' => $order['id'], - ); + ]; try { $this->callAPISuccess('order', 'delete', $params); $this->fail("Missed expected exception"); } catch (Exception $expected) { - $this->callAPISuccess('Contribution', 'create', array( + $this->callAPISuccess('Contribution', 'create', [ 'contribution_id' => $order['id'], 'is_test' => TRUE, - )); + ]); $this->callAPIAndDocument('order', 'delete', $params, __FUNCTION__, __FILE__); $order = $this->callAPISuccess('order', 'get', $params); $this->assertEquals(0, $order['count']); @@ -457,23 +457,23 @@ class api_v3_OrderTest extends CiviUnitTestCase { */ public function testCancelOrder() { $contribution = $this->addOrder(FALSE, 100); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], - ); + ]; $this->callAPIAndDocument('order', 'cancel', $params, __FUNCTION__, __FILE__); $order = $this->callAPISuccess('Order', 'get', $params); - $expectedResult = array( - $contribution['id'] => array( + $expectedResult = [ + $contribution['id'] => [ 'total_amount' => 100, 'contribution_id' => $contribution['id'], 'contribution_status' => 'Cancelled', 'net_amount' => 100, - ), - ); + ], + ]; $this->checkPaymentResult($order, $expectedResult); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution['id'], - )); + ]); } /** @@ -482,51 +482,51 @@ class api_v3_OrderTest extends CiviUnitTestCase { public function testCancelWithParticipant() { $event = $this->eventCreate(); $this->_eventId = $event['id']; - $eventParams = array( + $eventParams = [ 'id' => $this->_eventId, 'financial_type_id' => 4, 'is_monetary' => 1, - ); + ]; $this->callAPISuccess('event', 'create', $eventParams); - $participantParams = array( + $participantParams = [ 'financial_type_id' => 4, 'event_id' => $this->_eventId, 'role_id' => 1, 'status_id' => 1, 'fee_currency' => 'USD', 'contact_id' => $this->_individualId, - ); + ]; $participant = $this->callAPISuccess('Participant', 'create', $participantParams); - $extraParams = array( + $extraParams = [ 'contribution_mode' => 'participant', 'participant_id' => $participant['id'], - ); + ]; $contribution = $this->addOrder(TRUE, 100, $extraParams); - $paymentParticipant = array( + $paymentParticipant = [ 'participant_id' => $participant['id'], 'contribution_id' => $contribution['id'], - ); + ]; $this->callAPISuccess('ParticipantPayment', 'create', $paymentParticipant); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], - ); + ]; $this->callAPISuccess('order', 'cancel', $params); $order = $this->callAPISuccess('Order', 'get', $params); - $expectedResult = array( - $contribution['id'] => array( + $expectedResult = [ + $contribution['id'] => [ 'total_amount' => 100, 'contribution_id' => $contribution['id'], 'contribution_status' => 'Cancelled', 'net_amount' => 100, - ), - ); + ], + ]; $this->checkPaymentResult($order, $expectedResult); $participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $params); - $participant = $this->callAPISuccess('participant', 'get', array('id' => $participantPayment['participant_id'])); + $participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]); $this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Cancelled'); - $this->callAPISuccess('Contribution', 'Delete', array( + $this->callAPISuccess('Contribution', 'Delete', [ 'id' => $contribution['id'], - )); + ]); } /** diff --git a/tests/phpunit/api/v3/ParticipantPaymentTest.php b/tests/phpunit/api/v3/ParticipantPaymentTest.php index df0f3f7585..78842b08e8 100644 --- a/tests/phpunit/api/v3/ParticipantPaymentTest.php +++ b/tests/phpunit/api/v3/ParticipantPaymentTest.php @@ -51,29 +51,29 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $event = $this->eventCreate(NULL); $this->_eventID = $event['id']; $this->_contactID = $this->individualCreate(); - $this->_createdParticipants = array(); + $this->_createdParticipants = []; $this->_individualId = $this->individualCreate(); $this->_financialTypeId = 1; - $this->_participantID = $this->participantCreate(array( + $this->_participantID = $this->participantCreate([ 'contactID' => $this->_contactID, 'eventID' => $this->_eventID, - )); + ]); $this->_contactID2 = $this->individualCreate(); - $this->_participantID2 = $this->participantCreate(array( + $this->_participantID2 = $this->participantCreate([ 'contactID' => $this->_contactID2, 'eventID' => $this->_eventID, - )); - $this->_participantID3 = $this->participantCreate(array( + ]); + $this->_participantID3 = $this->participantCreate([ 'contactID' => $this->_contactID2, 'eventID' => $this->_eventID, - )); + ]); $this->_contactID3 = $this->individualCreate(); - $this->_participantID4 = $this->participantCreate(array( + $this->_participantID4 = $this->participantCreate([ 'contactID' => $this->_contactID3, 'eventID' => $this->_eventID, - )); + ]); } /** @@ -88,7 +88,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Test civicrm_participant_payment_create with empty params. */ public function testPaymentCreateEmptyParams() { - $params = array(); + $params = []; $this->callAPIFailure('participant_payment', 'create', $params); } @@ -97,9 +97,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ public function testPaymentCreateMissingContributionId() { //Without Payment EntityID - $params = array( + $params = [ 'participant_id' => $this->_participantID, - ); + ]; $this->callAPIFailure('participant_payment', 'create', $params); } @@ -108,13 +108,13 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ public function testPaymentCreate() { //Create Contribution & get contribution ID - $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID)); + $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]); //Create Participant Payment record With Values - $params = array( + $params = [ 'participant_id' => $this->_participantID, 'contribution_id' => $contributionID, - ); + ]; $result = $this->callAPIAndDocument('participant_payment', 'create', $params, __FUNCTION__, __FILE__); $this->assertTrue(array_key_exists('id', $result)); @@ -129,13 +129,13 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ public function testPaymentInfoForEvent() { //Create Contribution & get contribution ID - $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID)); + $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]); //Create Participant Payment record With Values - $params = array( + $params = [ 'participant_id' => $this->_participantID4, 'contribution_id' => $contributionID, - ); + ]; $this->callAPISuccess('participant_payment', 'create', $params); //Check if participant payment is correctly retrieved. @@ -159,16 +159,16 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Check with empty array. */ public function testPaymentUpdateEmpty() { - $this->callAPIFailure('participant_payment', 'create', array()); + $this->callAPIFailure('participant_payment', 'create', []); } /** * Check with missing participant_id. */ public function testPaymentUpdateMissingParticipantId() { - $params = array( + $params = [ 'contribution_id' => '3', - ); + ]; $this->callAPIFailure('participant_payment', 'create', $params); } @@ -176,9 +176,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Check with missing contribution_id. */ public function testPaymentUpdateMissingContributionId() { - $params = array( + $params = [ 'participant_id' => $this->_participantID, - ); + ]; $participantPayment = $this->callAPIFailure('participant_payment', 'create', $params); } @@ -188,20 +188,20 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { public function testPaymentOffline() { // create contribution w/o fee - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $this->_contactID, 'financial_type_id' => $this->_financialTypeId, 'payment_instrument_id' => 4, 'fee_amount' => 0, 'net_amount' => 100, - )); + ]); $this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, 'participant_id' => $this->_participantID, 'contribution_id' => $contributionID, - ); + ]; // Update Payment $participantPayment = $this->callAPISuccess('participant_payment', 'create', $params); @@ -209,9 +209,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->assertTrue(array_key_exists('id', $participantPayment)); // check Financial records $this->_checkFinancialRecords($params, 'offline'); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, - ); + ]; $deletePayment = $this->callAPISuccess('participant_payment', 'delete', $params); } @@ -222,20 +222,20 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $pageParams['processor_id'] = $this->processorCreate(); $contributionPage = $this->contributionPageCreate($pageParams); - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_contactID, 'contribution_page_id' => $contributionPage['id'], 'payment_processor' => $pageParams['processor_id'], 'financial_type_id' => 1, - ); + ]; $contributionID = $this->contributionCreate($contributionParams); $this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, 'participant_id' => $this->_participantID, 'contribution_id' => $contributionID, - ); + ]; // Update Payment $participantPayment = $this->callAPISuccess('participant_payment', 'create', $params); @@ -243,9 +243,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->assertTrue(array_key_exists('id', $participantPayment)); // check Financial records $this->_checkFinancialRecords($params, 'online'); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, - ); + ]; $this->callAPISuccess('participant_payment', 'delete', $params); } @@ -256,21 +256,21 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $pageParams['processor_id'] = $this->processorCreate(); $pageParams['is_pay_later'] = 1; $contributionPage = $this->contributionPageCreate($pageParams); - $contributionParams = array( + $contributionParams = [ 'contact_id' => $this->_contactID, 'contribution_page_id' => $contributionPage['id'], 'contribution_status_id' => 2, 'is_pay_later' => 1, 'financial_type_id' => 1, - ); + ]; $contributionID = $this->contributionCreate($contributionParams); $this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, 'participant_id' => $this->_participantID, 'contribution_id' => $contributionID, - ); + ]; // Update Payment $participantPayment = $this->callAPISuccess('participant_payment', 'create', $params); @@ -278,9 +278,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->_checkFinancialRecords($params, 'payLater'); $this->assertEquals($participantPayment['id'], $this->_participantPaymentID); $this->assertTrue(array_key_exists('id', $participantPayment)); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, - ); + ]; $this->callAPISuccess('participant_payment', 'delete', $params); } @@ -296,7 +296,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Check with empty array. */ public function testPaymentDeleteWithEmptyParams() { - $params = array(); + $params = []; $deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params); $this->assertEquals('Mandatory key(s) missing from params array: id', $deletePayment['error_message']); } @@ -305,9 +305,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Check with wrong id. */ public function testPaymentDeleteWithWrongID() { - $params = array( + $params = [ 'id' => 0, - ); + ]; $deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params); $this->assertEquals($deletePayment['error_message'], 'Error while deleting participantPayment'); } @@ -316,15 +316,15 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Check with valid array. */ public function testPaymentDelete() { - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $this->_contactID, - )); + ]); $this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID); - $params = array( + $params = [ 'id' => $this->_participantPaymentID, - ); + ]; $this->callAPIAndDocument('participant_payment', 'delete', $params, __FUNCTION__, __FILE__); } @@ -332,14 +332,14 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * Test civicrm_participantPayment_get - success expected. */ public function testGet() { - $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID3)); + $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID3]); $this->participantPaymentCreate($this->_participantID4, $contributionID); //Create Participant Payment record With Values - $params = array( + $params = [ 'participant_id' => $this->_participantID4, 'contribution_id' => $contributionID, - ); + ]; $result = $this->callAPIAndDocument('participant_payment', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['participant_id'], $this->_participantID4, 'Check Participant Id'); @@ -351,63 +351,63 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * @param $context */ public function _checkFinancialRecords($params, $context) { - $entityParams = array( + $entityParams = [ 'entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution', - ); + ]; $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); - $trxnParams = array( + $trxnParams = [ 'id' => $trxn['financial_trxn_id'], - ); + ]; switch ($context) { case 'online': - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 12, 'total_amount' => 100, 'status_id' => 1, - ); + ]; break; case 'offline': - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 6, 'total_amount' => 100, 'status_id' => 1, - ); + ]; break; case 'payLater': - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 7, 'total_amount' => 100, 'status_id' => 2, - ); + ]; break; } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams); - $entityParams = array( + $entityParams = [ 'financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item', - ); + ]; $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); - $fitemParams = array( + $fitemParams = [ 'id' => $entityTrxn['entity_id'], - ); + ]; if ($context == 'offline' || $context == 'online') { - $compareParams = array( + $compareParams = [ 'amount' => 100, 'status_id' => 1, 'financial_account_id' => 1, - ); + ]; } elseif ($context == 'payLater') { - $compareParams = array( + $compareParams = [ 'amount' => 100, 'status_id' => 3, 'financial_account_id' => 1, - ); + ]; } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams); } @@ -416,15 +416,15 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { * test getParticipantIds() function */ public function testGetParticipantIds() { - $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID)); - $expectedParticipants = array($this->_participantID, $this->_participantID2); + $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]); + $expectedParticipants = [$this->_participantID, $this->_participantID2]; //Create Participant Payment record With Values foreach ($expectedParticipants as $pid) { - $params = array( + $params = [ 'participant_id' => $pid, 'contribution_id' => $contributionID, - ); + ]; $this->callAPISuccess('participant_payment', 'create', $params); } //Check if all participants are listed. diff --git a/tests/phpunit/api/v3/ParticipantStatusTypeTest.php b/tests/phpunit/api/v3/ParticipantStatusTypeTest.php index 20012e627b..dbf37df63c 100644 --- a/tests/phpunit/api/v3/ParticipantStatusTypeTest.php +++ b/tests/phpunit/api/v3/ParticipantStatusTypeTest.php @@ -38,7 +38,7 @@ class api_v3_ParticipantStatusTypeTest extends CiviUnitTestCase { public function setUp() { $this->_apiversion = 3; - $this->params = array( + $this->params = [ 'name' => 'test status', 'label' => 'I am a test', 'class' => 'Positive', @@ -47,7 +47,7 @@ class api_v3_ParticipantStatusTypeTest extends CiviUnitTestCase { 'is_counted' => 1, 'visibility_id' => 1, 'weight' => 10, - ); + ]; parent::setUp(); $this->useTransaction(TRUE); } @@ -71,10 +71,10 @@ class api_v3_ParticipantStatusTypeTest extends CiviUnitTestCase { public function testDeleteParticipantStatusType() { $ParticipantStatusType = $this->callAPISuccess('ParticipantStatusType', 'Create', $this->params); - $entity = $this->callAPISuccess('participant_status_type', 'get', array()); - $result = $this->callAPIAndDocument('participant_status_type', 'delete', array('id' => $ParticipantStatusType['id']), __FUNCTION__, __FILE__); - $getCheck = $this->callAPISuccess('ParticipantStatusType', 'GET', array('id' => $ParticipantStatusType['id'])); - $checkDeleted = $this->callAPISuccess('ParticipantStatusType', 'Get', array()); + $entity = $this->callAPISuccess('participant_status_type', 'get', []); + $result = $this->callAPIAndDocument('participant_status_type', 'delete', ['id' => $ParticipantStatusType['id']], __FUNCTION__, __FILE__); + $getCheck = $this->callAPISuccess('ParticipantStatusType', 'GET', ['id' => $ParticipantStatusType['id']]); + $checkDeleted = $this->callAPISuccess('ParticipantStatusType', 'Get', []); $this->assertEquals($entity['count'] - 1, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/ParticipantTest.php b/tests/phpunit/api/v3/ParticipantTest.php index 2c438ea597..b5654e1cd2 100644 --- a/tests/phpunit/api/v3/ParticipantTest.php +++ b/tests/phpunit/api/v3/ParticipantTest.php @@ -56,24 +56,24 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $this->_contactID = $this->individualCreate(); - $this->_createdParticipants = array(); + $this->_createdParticipants = []; $this->_individualId = $this->individualCreate(); - $this->_participantID = $this->participantCreate(array( + $this->_participantID = $this->participantCreate([ 'contact_id' => $this->_contactID, 'event_id' => $this->_eventID, - )); + ]); $this->_contactID2 = $this->individualCreate(); - $this->_participantID2 = $this->participantCreate(array( + $this->_participantID2 = $this->participantCreate([ 'contact_id' => $this->_contactID2, 'event_id' => $this->_eventID, 'registered_by_id' => $this->_participantID, - )); - $this->_participantID3 = $this->participantCreate(array( + ]); + $this->_participantID3 = $this->participantCreate([ 'contact_id' => $this->_contactID2, 'event_id' => $this->_eventID, - )); - $this->_params = array( + ]); + $this->_params = [ 'contact_id' => $this->_contactID, 'event_id' => $this->_eventID, 'status_id' => 1, @@ -81,17 +81,17 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { // to ensure it matches later on 'register_date' => '2007-07-21 00:00:00', 'source' => 'Online Event Registration: API Testing', - ); + ]; } public function tearDown() { $this->eventDelete($this->_eventID); - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_contact', 'civicrm_participant', - ); + ]; // true tells quickCleanup to drop any tables that might have been created in the test $this->quickCleanup($tablesToTruncate, TRUE); } @@ -117,33 +117,33 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Test get participants with role_id. */ public function testGetParticipantWithRole() { - $roleId = array(1, 2, 3); + $roleId = [1, 2, 3]; foreach ($roleId as $role) { - $this->participantCreate(array( + $this->participantCreate([ 'contact_id' => $this->individualCreate(), 'role_id' => $role, 'event_id' => $this->_eventID, - )); + ]); } - $params = array( + $params = [ 'role_id' => 2, - ); + ]; $result = $this->callAPISuccess('participant', 'get', $params); //Assert all the returned participants has a role_id of 2 foreach ($result['values'] as $pid => $values) { $this->assertEquals($values['participant_role_id'], 2); } - $this->participantCreate(array( + $this->participantCreate([ 'id' => $this->_participantID, 'role_id' => NULL, 'event_id' => $this->_eventID, - )); + ]); - $params['role_id'] = array( + $params['role_id'] = [ 'IS NULL' => 1, - ); + ]; $result = $this->callAPISuccess('participant', 'get', $params); foreach ($result['values'] as $pid => $values) { $this->assertEquals($values['participant_role_id'], NULL); @@ -167,7 +167,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); - $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'])); + $check = $this->callAPISuccess($this->_entity, 'get', ['id' => $result['id']]); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); @@ -178,25 +178,25 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with participant_id. */ public function testGetParticipantIdOnly() { - $params = array( + $params = [ 'participant_id' => $this->_participantID, - 'return' => array( + 'return' => [ 'participant_id', 'event_id', 'participant_register_date', 'participant_source', - ), - ); + ], + ]; $result = $this->callAPISuccess('participant', 'get', $params); $this->assertAPISuccess($result, " in line " . __LINE__); $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); - $params = array( + $params = [ 'id' => $this->_participantID, 'return' => 'id,participant_register_date,event_id', - ); + ]; $result = $this->callAPISuccess('participant', 'get', $params); $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); @@ -208,17 +208,17 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ public function testGetParticipantWithPermission() { $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array(); - $params = array( + $config->userPermissionClass->permissions = []; + $params = [ 'event_id' => $this->_eventID, 'check_permissions' => TRUE, - 'return' => array( + 'return' => [ 'participant_id', 'event_id', 'participant_register_date', 'participant_source', - ), - ); + ], + ]; $this->callAPIFailure('participant', 'get', $params); $params['check_permissions'] = FALSE; @@ -230,9 +230,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with params id. */ public function testGetParamsAsIdOnly() { - $params = array( + $params = [ 'id' => $this->_participantID, - ); + ]; $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); @@ -246,17 +246,17 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { public function testGetNestedEventGet() { //create a second event & add participant to it. $event = $this->eventCreate(NULL); - $this->callAPISuccess('participant', 'create', array( + $this->callAPISuccess('participant', 'create', [ 'event_id' => $event['id'], 'contact_id' => $this->_contactID, - )); + ]); $description = "Demonstrates use of nested get to fetch event data with participant records."; $subfile = "NestedEventGet"; - $params = array( + $params = [ 'id' => $this->_participantID, 'api.event.get' => 1, - ); + ]; $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); @@ -268,12 +268,12 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check Participant Get respects return properties. */ public function testGetWithReturnProperties() { - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'return.status_id' => 1, 'return.participant_status_id' => 1, - 'options' => array('limit' => 1), - ); + 'options' => ['limit' => 1], + ]; $result = $this->callAPISuccess('participant', 'get', $params); $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]); } @@ -282,9 +282,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with contact_id. */ public function testGetContactIdOnly() { - $params = array( + $params = [ 'contact_id' => $this->_contactID, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertEquals($this->_participantID, $participant['id']); @@ -299,10 +299,10 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * fetch first record */ public function testGetMultiMatchReturnFirst() { - $params = array( + $params = [ 'event_id' => $this->_eventID, 'rowCount' => 1, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertNotNull($participant['id']); @@ -313,9 +313,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * in v3 this should return all participants */ public function testGetMultiMatchNoReturnFirst() { - $params = array( + $params = [ 'event_id' => $this->_eventID, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertNotNull($participant['count'], 3); } @@ -327,7 +327,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * In this case all the participant records are returned. */ public function testSearchEmptyParams() { - $result = $this->callAPISuccess('participant', 'get', array()); + $result = $this->callAPISuccess('participant', 'get', []); // expecting 3 participant records $this->assertEquals($result['count'], 3); } @@ -336,9 +336,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with participant_id. */ public function testSearchParticipantIdOnly() { - $params = array( + $params = [ 'participant_id' => $this->_participantID, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertEquals($participant['values'][$this->_participantID]['event_id'], $this->_eventID); $this->assertEquals($participant['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); @@ -350,9 +350,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ public function testSearchContactIdOnly() { // Should get 2 participant records for this contact. - $params = array( + $params = [ 'contact_id' => $this->_contactID2, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertEquals($participant['count'], 2); @@ -363,11 +363,11 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ public function testSearchByEvent() { // Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned. - $params = array( + $params = [ 'event_id' => $this->_eventID, 'return.last_name' => 1, 'return.event_title' => 1, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); if ($participant['count'] < 3) { $this->fail("Event search returned less than expected miniumum of 3 records."); @@ -383,10 +383,10 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ public function testSearchByEventWithLimit() { // Should 2 participant records since we're passing rowCount = 2. - $params = array( + $params = [ 'event_id' => $this->_eventID, 'rowCount' => 2, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertEquals($participant['count'], 2); @@ -396,9 +396,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Test search by lead booker (registered by ID) */ public function testSearchByRegisteredById() { - $params = array( + $params = [ 'registered_by_id' => $this->_participantID, - ); + ]; $participant = $this->callAPISuccess('participant', 'get', $params); $this->assertEquals($participant['count'], 1); @@ -411,7 +411,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Test civicrm_participant_create with empty params. */ public function testCreateEmptyParams() { - $params = array(); + $params = []; $result = $this->callAPIFailure('participant', 'create', $params); } @@ -434,10 +434,10 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with contact_id & event_id */ public function testCreateEventIdOnly() { - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'event_id' => $this->_eventID, - ); + ]; $participant = $this->callAPISuccess('participant', 'create', $params); $this->getAndCheck($params, $participant['id'], 'participant'); } @@ -469,10 +469,10 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ public function testCreateUpdateReceiveDate() { $participant = $this->callAPISuccess('participant', 'create', $this->_params); - $update = array( + $update = [ 'id' => $participant['id'], 'status_id' => 2, - ); + ]; $this->callAPISuccess('participant', 'create', $update); $this->getAndCheck(array_merge($this->_params, $update), $participant['id'], 'participant'); } @@ -481,19 +481,19 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Test to check if participant fee level is being changed per CRM-9781 */ public function testCreateUpdateParticipantFeeLevel() { - $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR); + $myParams = $this->_params + ['participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR]; $participant = $this->callAPISuccess('participant', 'create', $myParams); - $update = array( + $update = [ 'id' => $participant['id'], 'status_id' => 2, - ); + ]; $update = $this->callAPISuccess('participant', 'create', $update); $this->assertEquals($participant['values'][$participant['id']]['fee_level'], $update['values'][$participant['id']]['fee_level'] ); - $this->callAPISuccess('participant', 'delete', array('id' => $participant['id'])); + $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]); } /** @@ -502,25 +502,25 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { public function testCreateParticipantLineItems() { // Create a price set for this event. - $priceset = $this->callAPISuccess('PriceSet', 'create', array( + $priceset = $this->callAPISuccess('PriceSet', 'create', [ 'name' => 'my_price_set', 'title' => 'My Price Set', 'is_active' => 1, 'extends' => 1, 'financial_type_id' => 4, // 'entity' => array('civicrm_event' => array($this->_eventID)), - )); + ]); // Add the price set to the event with another API call. // I tried to do this at once, but it did not work. - $priceset = $this->callAPISuccess('PriceSet', 'create', array( + $priceset = $this->callAPISuccess('PriceSet', 'create', [ 'entity_table' => 'civicrm_event', 'entity_id' => $this->_eventID, 'id' => $priceset['id'], - )); + ]); - $pricefield = $this->callAPISuccess('PriceField', 'create', array( + $pricefield = $this->callAPISuccess('PriceField', 'create', [ 'price_set_id' => $priceset['id'], 'name' => 'mypricefield', 'label' => 'My Price Field', @@ -528,35 +528,35 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'is_enter_qty' => 1, 'is_display_amounts' => 1, 'is_active' => 1, - )); + ]); - $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', array( + $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', [ 'price_field_id' => $pricefield['id'], 'name' => 'pricefieldvalue1', 'label' => 'pricefieldvalue1', 'amount' => 20, 'is_active' => 1, 'financial_type_id' => 4, - )); + ]); - $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', array( + $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', [ 'price_field_id' => $pricefield['id'], 'name' => 'pricefieldvalue2', 'label' => 'pricefieldvalue2', 'amount' => 5, 'is_active' => 1, 'financial_type_id' => 4, - )); + ]); // pay 2 times price field value 1, and 2 times price field value 2. - $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR); + $myParams = $this->_params + ['participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR]; $participant = $this->callAPISuccess('participant', 'create', $myParams); // expect 2 line items. - $lineItems = $this->callAPISuccess('LineItem', 'get', array( + $lineItems = $this->callAPISuccess('LineItem', 'get', [ 'entity_id' => $participant['id'], 'entity_table' => 'civicrm_participant', - )); + ]); $this->assertEquals(2, $lineItems['count']); @@ -575,7 +575,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $this->assertEquals('pricefieldvalue1', $lineItem['label']); // Cleanup - $this->callAPISuccess('participant', 'delete', array('id' => $participant['id'])); + $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]); // TODO: I think the price set should be removed, but I don't know how // to decouple it properly from the event. For the moment, I'll just comment @@ -593,11 +593,11 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with complete array. */ public function testUpdate() { - $participantId = $this->participantCreate(array( + $participantId = $this->participantCreate([ 'contactID' => $this->_individualId, 'eventID' => $this->_eventID, - )); - $params = array( + ]); + $params = [ 'id' => $participantId, 'contact_id' => $this->_individualId, 'event_id' => $this->_eventID, @@ -605,7 +605,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'role_id' => 3, 'register_date' => '2006-01-21', 'source' => 'US Open', - ); + ]; $participant = $this->callAPISuccess('participant', 'create', $params); $this->getAndCheck($params, $participant['id'], 'participant'); $result = $this->participantDelete($params['id']); @@ -618,13 +618,13 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ public function testUpdateCreateParticipantFeeLevelNoSeparator() { - $myParams = $this->_params + array('participant_fee_level' => "fee"); + $myParams = $this->_params + ['participant_fee_level' => "fee"]; $participant = $this->callAPISuccess('participant', 'create', $myParams); $this->assertAPISuccess($participant); - $update = array( + $update = [ 'id' => $participant['id'], 'status_id' => 2, - ); + ]; $this->callAPISuccess('participant', 'create', $update); $this->assertEquals($participant['values'][$participant['id']]['fee_level'], $myParams['participant_fee_level'] @@ -647,7 +647,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with empty array. */ public function testUpdateEmptyParams() { - $params = array(); + $params = []; $participant = $this->callAPIFailure('participant', 'create', $params); $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id'); } @@ -656,15 +656,15 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check without event_id. */ public function testUpdateWithoutEventId() { - $participantId = $this->participantCreate(array('contactID' => $this->_individualId, 'eventID' => $this->_eventID)); - $params = array( + $participantId = $this->participantCreate(['contactID' => $this->_individualId, 'eventID' => $this->_eventID]); + $params = [ 'contact_id' => $this->_individualId, 'status_id' => 3, 'role_id' => 3, 'register_date' => '2006-01-21', 'source' => 'US Open', 'event_level' => 'Donation', - ); + ]; $participant = $this->callAPIFailure('participant', 'create', $params); $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id'); // Cleanup created participant records. @@ -675,14 +675,14 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with Invalid participantId. */ public function testUpdateWithWrongParticipantId() { - $params = array( + $params = [ 'id' => 1234, 'status_id' => 3, 'role_id' => 3, 'register_date' => '2006-01-21', 'source' => 'US Open', 'event_level' => 'Donation', - ); + ]; $participant = $this->callAPIFailure('Participant', 'update', $params); } @@ -690,11 +690,11 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with Invalid ContactId. */ public function testUpdateWithWrongContactId() { - $participantId = $this->participantCreate(array( + $participantId = $this->participantCreate([ 'contactID' => $this->_individualId, 'eventID' => $this->_eventID, - ), $this->_apiversion); - $params = array( + ], $this->_apiversion); + $params = [ 'id' => $participantId, 'contact_id' => 12345, 'status_id' => 3, @@ -702,7 +702,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'register_date' => '2006-01-21', 'source' => 'US Open', 'event_level' => 'Donation', - ); + ]; $participant = $this->callAPIFailure('participant', 'create', $params); $result = $this->participantDelete($participantId); } @@ -721,7 +721,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Test civicrm_participant_delete with empty params. */ public function testDeleteEmptyParams() { - $params = array(); + $params = []; $result = $this->callAPIFailure('participant', 'delete', $params); } @@ -729,9 +729,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * Check with participant_id. */ public function testParticipantDelete() { - $params = array( + $params = [ 'id' => $this->_participantID, - ); + ]; $participant = $this->callAPISuccess('participant', 'delete', $params); $this->assertAPISuccess($participant); $this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID, NULL, TRUE); @@ -743,9 +743,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * This should return an error because required param is missing.. */ public function testParticipantDeleteMissingID() { - $params = array( + $params = [ 'event_id' => $this->_eventID, - ); + ]; $participant = $this->callAPIFailure('participant', 'delete', $params); $this->assertNotNull($participant['error_message']); } @@ -756,11 +756,11 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { public function testNestedDelete() { $description = "Criteria delete by nesting a GET & a DELETE."; $subfile = "NestedDelete"; - $participants = $this->callAPISuccess('Participant', 'Get', array()); + $participants = $this->callAPISuccess('Participant', 'Get', []); $this->assertEquals($participants['count'], 3); - $params = array('contact_id' => $this->_contactID2, 'api.participant.delete' => 1); + $params = ['contact_id' => $this->_contactID2, 'api.participant.delete' => 1]; $this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $check = $this->callAPISuccess('participant', 'getcount', array()); + $check = $this->callAPISuccess('participant', 'getcount', []); $this->assertEquals(1, $check, "only one participant should be left"); } @@ -771,58 +771,58 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $description = "Single function to create contact with partipation & contribution. Note that in the case of 'contribution' the 'create' is implied (api.contribution.create)"; $subfile = "CreateParticipantPayment"; - $params = array( + $params = [ 'contact_type' => 'Individual', 'display_name' => 'dlobo', - 'api.participant' => array( + 'api.participant' => [ 'event_id' => $this->_eventID, 'status_id' => 1, 'role_id' => 1, 'format.only_id' => 1, - ), - 'api.contribution.create' => array( + ], + 'api.contribution.create' => [ 'financial_type_id' => 1, 'total_amount' => 100, 'format.only_id' => 1, - ), - 'api.participant_payment.create' => array( + ], + 'api.participant_payment.create' => [ 'contribution_id' => '$value.api.contribution.create', 'participant_id' => '$value.api.participant', - ), - ); + ], + ]; $result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']); - $this->callAPISuccess('contact', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('contact', 'delete', ['id' => $result['id']]); } /** * Test participant invoke post hook after status update. */ public function testPostHookForAdditionalParticipant() { - $participantID = $this->participantCreate(array( + $participantID = $this->participantCreate([ 'contact_id' => $this->_contactID, 'status_id' => 5, 'event_id' => $this->_eventID, - )); - $participantID2 = $this->participantCreate(array( + ]); + $participantID2 = $this->participantCreate([ 'contact_id' => $this->_contactID2, 'event_id' => $this->_eventID, 'status_id' => 5, 'registered_by_id' => $participantID, - )); + ]); - $this->hookClass->setHook('civicrm_post', array($this, 'onPost')); - $params = array( + $this->hookClass->setHook('civicrm_post', [$this, 'onPost']); + $params = [ 'id' => $participantID, 'status_id' => 1, - ); + ]; $this->callAPISuccess('Participant', 'create', $params); - $result = $this->callAPISuccess('Participant', 'get', array('source' => 'Post Hook Update')); + $result = $this->callAPISuccess('Participant', 'get', ['source' => 'Post Hook Update']); $this->assertEquals(2, $result['count']); - $expected = array($participantID, $participantID2); + $expected = [$participantID, $participantID2]; $actual = array_keys($result['values']); $this->checkArrayEquals($expected, $actual); } diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index c3e16b9a07..27f8e8acad 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -39,31 +39,31 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); // Create dummy processor - $params = array( + $params = [ 'name' => 'API_Test_PP_Type', 'title' => 'API Test Payment Processor Type', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 'form', 'is_recur' => 0, - ); + ]; $result = $this->callAPISuccess('payment_processor_type', 'create', $params); $this->_paymentProcessorType = $result['id']; - $this->_params = array( + $this->_params = [ 'name' => 'API Test PP', 'payment_processor_type_id' => $this->_paymentProcessorType, 'class_name' => 'CRM_Core_Payment_APITest', 'is_recur' => 0, 'domain_id' => 1, - ); + ]; } /** * Check with no name. */ public function testPaymentProcessorCreateWithoutName() { - $payProcParams = array( + $payProcParams = [ 'is_active' => 1, - ); + ]; $this->callAPIFailure('payment_processor', 'create', $payProcParams); } @@ -94,15 +94,15 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { $result = $this->callAPISuccess('payment_processor', 'create', $params); $this->assertNotNull($result['id']); - $updateParams = array( + $updateParams = [ 'id' => $result['id'], 'name' => 'Update API Test', - ); + ]; $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params); $this->callAPISuccess('payment_processor', 'create', $updateParams); - $result = $this->callAPISuccess('payment_processor', 'get', array('id' => $result['id'])); + $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]); - $expectedResult = array( + $expectedResult = [ 'id' => $result['id'], 'domain_id' => $params['domain_id'], 'name' => $updateParams['name'], @@ -115,7 +115,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { 'payment_type' => 1, 'payment_instrument_id' => 1, 'is_active' => 1, - ); + ]; $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]); } @@ -134,9 +134,9 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { */ public function testPaymentProcessorDelete() { $result = $this->callAPISuccess('payment_processor', 'create', $this->_params); - $params = array( + $params = [ 'id' => $result['id'], - ); + ]; $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__); } @@ -149,9 +149,9 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { $params['user_name'] = 'test@test.com'; $this->callAPISuccess('payment_processor', 'create', $params); - $params = array( + $params = [ 'user_name' => 'test@test.com', - ); + ]; $results = $this->callAPISuccess('payment_processor', 'get', $params); $this->assertEquals(1, $results['count']); diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index 1c111296f5..1087ba7397 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -55,9 +55,9 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check with no name. */ public function testPaymentProcessorTypeCreateWithoutName() { - $payProcParams = array( + $payProcParams = [ 'is_active' => 1, - ); + ]; $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode' @@ -68,14 +68,14 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Create payment processor type. */ public function testPaymentProcessorTypeCreate() { - $params = array( + $params = [ 'sequential' => 1, 'name' => 'API_Test_PP', 'title' => 'API Test Payment Processor', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 'form', 'is_recur' => 0, - ); + ]; $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['values'][0]['id']); @@ -102,7 +102,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check with empty array. */ public function testPaymentProcessorTypeDeleteEmpty() { - $params = array(); + $params = []; $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); } @@ -117,11 +117,11 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check if required fields are not passed. */ public function testPaymentProcessorTypeDeleteWithoutRequired() { - $params = array( + $params = [ 'name' => 'API_Test_PP', 'title' => 'API Test Payment Processor', 'class_name' => 'CRM_Core_Payment_APITest', - ); + ]; $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); @@ -131,7 +131,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check with incorrect required fields. */ public function testPaymentProcessorTypeDeleteWithIncorrectData() { - $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd')); + $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']); } /** @@ -139,9 +139,9 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { */ public function testPaymentProcessorTypeDelete() { $payProcType = $this->paymentProcessorTypeCreate(); - $params = array( + $params = [ 'id' => $payProcType, - ); + ]; $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__); } @@ -152,7 +152,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check with empty array. */ public function testPaymentProcessorTypeUpdateEmpty() { - $params = array(); + $params = []; $result = $this->callAPIFailure('payment_processor_type', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'); } @@ -172,7 +172,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { // create sample payment processor type. $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL); - $params = array( + $params = [ 'id' => $this->_ppTypeID, // keep the same 'name' => 'API_Test_PP', @@ -180,7 +180,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'class_name' => 'CRM_Core_Payment_APITest 2', 'billing_mode' => 2, 'is_recur' => 0, - ); + ]; $result = $this->callAPISuccess('payment_processor_type', 'create', $params); $this->assertNotNull($result['id']); @@ -194,28 +194,28 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check with empty array. */ public function testPaymentProcessorTypesGetEmptyParams() { - $results = $this->callAPISuccess('payment_processor_type', 'get', array()); + $results = $this->callAPISuccess('payment_processor_type', 'get', []); $baselineCount = $results['count']; - $firstRelTypeParams = array( + $firstRelTypeParams = [ 'name' => 'API_Test_PP', 'title' => 'API Test Payment Processor', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 1, 'is_recur' => 0, - ); + ]; $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); - $secondRelTypeParams = array( + $secondRelTypeParams = [ 'name' => 'API_Test_PP2', 'title' => 'API Test Payment Processor 2', 'class_name' => 'CRM_Core_Payment_APITest 2', 'billing_mode' => 2, 'is_recur' => 0, - ); + ]; $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); - $result = $this->callAPISuccess('payment_processor_type', 'get', array()); + $result = $this->callAPISuccess('payment_processor_type', 'get', []); $this->assertEquals($baselineCount + 2, $result['count']); $this->assertAPISuccess($result); @@ -225,28 +225,28 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * Check with valid params array. */ public function testPaymentProcessorTypesGet() { - $firstRelTypeParams = array( + $firstRelTypeParams = [ 'name' => 'API_Test_PP_11', 'title' => 'API Test Payment Processor 11', 'class_name' => 'CRM_Core_Payment_APITest_11', 'billing_mode' => 1, 'is_recur' => 0, - ); + ]; $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); - $secondRelTypeParams = array( + $secondRelTypeParams = [ 'name' => 'API_Test_PP_12', 'title' => 'API Test Payment Processor 12', 'class_name' => 'CRM_Core_Payment_APITest_12', 'billing_mode' => 2, 'is_recur' => 0, - ); + ]; $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); - $params = array( + $params = [ 'name' => 'API_Test_PP_12', - ); + ]; $result = $this->callAPISuccess('payment_processor_type', 'get', $params); $this->assertAPISuccess($result); diff --git a/tests/phpunit/api/v3/PaymentTokenTest.php b/tests/phpunit/api/v3/PaymentTokenTest.php index cffcd528c3..8b5c3cb43d 100644 --- a/tests/phpunit/api/v3/PaymentTokenTest.php +++ b/tests/phpunit/api/v3/PaymentTokenTest.php @@ -41,12 +41,12 @@ class api_v3_PaymentTokenTest extends CiviUnitTestCase { $this->useTransaction(TRUE); parent::setUp(); $contactID = $this->individualCreate(); - $this->params = array( + $this->params = [ 'token' => "fancy-token-xxxx", 'contact_id' => $contactID, 'created_id' => $contactID, 'payment_processor_id' => $this->processorCreate(), - ); + ]; } public function testCreatePaymentToken() { @@ -55,7 +55,7 @@ class api_v3_PaymentTokenTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument('payment_token', 'create', $this->params, __FUNCTION__, __FILE__, $description); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->getAndCheck(array_merge($this->params, array($this->params)), $result['id'], 'payment_token', TRUE); + $this->getAndCheck(array_merge($this->params, [$this->params]), $result['id'], 'payment_token', TRUE); } public function testGetPaymentToken() { @@ -68,10 +68,10 @@ class api_v3_PaymentTokenTest extends CiviUnitTestCase { public function testDeletePaymentToken() { $this->callAPISuccess('payment_token', 'create', $this->params); $entity = $this->callAPISuccess('payment_token', 'get', ($this->params)); - $delete = array('id' => $entity['id']); + $delete = ['id' => $entity['id']]; $result = $this->callAPIAndDocument('payment_token', 'delete', $delete, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess('payment_token', 'get', array()); + $checkDeleted = $this->callAPISuccess('payment_token', 'get', []); $this->assertEquals(0, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/PcpTest.php b/tests/phpunit/api/v3/PcpTest.php index 21ac18ac3c..2c87471911 100644 --- a/tests/phpunit/api/v3/PcpTest.php +++ b/tests/phpunit/api/v3/PcpTest.php @@ -51,12 +51,12 @@ class api_v3_PcpTest extends CiviUnitTestCase { public $DBResetRequired = TRUE; public function setUp() { - $this->params = array( + $this->params = [ 'title' => "Pcp title", 'contact_id' => 1, 'page_id' => 1, 'pcp_block_id' => 1, - ); + ]; parent::setUp(); } @@ -74,8 +74,8 @@ class api_v3_PcpTest extends CiviUnitTestCase { */ public function testDisablePcp() { $result = civicrm_api3('Pcp', 'create', $this->params); - civicrm_api3('Pcp', 'create', array('id' => $result['id'], 'is_active' => 0)); - $this->getAndCheck($this->params + array('is_active' => 0), $result['id'], $this->entity); + civicrm_api3('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]); + $this->getAndCheck($this->params + ['is_active' => 0], $result['id'], $this->entity); } /** @@ -99,12 +99,12 @@ class api_v3_PcpTest extends CiviUnitTestCase { public function testDeletePcp() { $entity = $this->createTestEntity(); $checkCreated = $this->callAPISuccess($this->entity, 'get', - array('id' => $entity['id'])); + ['id' => $entity['id']]); $this->assertEquals(1, $checkCreated['count']); $this->callAPIAndDocument('Pcp', 'delete', - array('id' => $entity['id']), __FUNCTION__, __FILE__); + ['id' => $entity['id']], __FUNCTION__, __FILE__); $checkDeleted = $this->callAPISuccess($this->entity, 'get', - array('id' => $entity['id'])); + ['id' => $entity['id']]); $this->assertEquals(0, $checkDeleted['count']); } @@ -118,11 +118,11 @@ class api_v3_PcpTest extends CiviUnitTestCase { public function testGetPcpChainDelete() { $description = "Demonstrates get + delete in the same call."; $subfile = 'ChainedGetDelete'; - $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1); + $params = ['title' => "Pcp title", 'api.Pcp.delete' => 1]; $this->callAPISuccess('Pcp', 'create', $this->params); $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array())); + $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', [])); } } diff --git a/tests/phpunit/api/v3/PhoneTest.php b/tests/phpunit/api/v3/PhoneTest.php index 8969caba25..2cc6fc630b 100644 --- a/tests/phpunit/api/v3/PhoneTest.php +++ b/tests/phpunit/api/v3/PhoneTest.php @@ -45,13 +45,13 @@ class api_v3_PhoneTest extends CiviUnitTestCase { $loc = $this->locationTypeCreate(); $this->_locationType = $loc->id; CRM_Core_PseudoConstant::flush(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType, 'phone' => '(123) 456-7890', 'is_primary' => 1, 'phone_type_id' => 1, - ); + ]; } /** @@ -65,7 +65,7 @@ class api_v3_PhoneTest extends CiviUnitTestCase { $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('phone', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('phone', 'delete', ['id' => $result['id']]); } /** @@ -77,12 +77,12 @@ class api_v3_PhoneTest extends CiviUnitTestCase { //create one $create = $this->callAPISuccess('phone', 'create', $this->_params); - $result = $this->callAPIAndDocument('phone', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('phone', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $get = $this->callAPISuccess('phone', 'get', array( + $get = $this->callAPISuccess('phone', 'get', [ 'id' => $create['id'], 'location_type_id' => $this->_locationType, - )); + ]); $this->assertEquals(0, $get['count'], 'Phone not successfully deleted In line ' . __LINE__); } @@ -93,16 +93,16 @@ class api_v3_PhoneTest extends CiviUnitTestCase { */ public function testGetEmptyParams($version) { $this->_apiversion = $version; - $result = $this->callAPISuccess('Phone', 'Get', array()); + $result = $this->callAPISuccess('Phone', 'Get', []); } /** * Test civicrm_phone_get with wrong params. */ public function testGetWrongParams() { - $this->callAPIFailure('Phone', 'Get', array('contact_id' => 'abc')); - $this->callAPIFailure('Phone', 'Get', array('location_type_id' => 'abc')); - $this->callAPIFailure('Phone', 'Get', array('phone_type_id' => 'abc')); + $this->callAPIFailure('Phone', 'Get', ['contact_id' => 'abc']); + $this->callAPIFailure('Phone', 'Get', ['location_type_id' => 'abc']); + $this->callAPIFailure('Phone', 'Get', ['phone_type_id' => 'abc']); } /** @@ -113,10 +113,10 @@ class api_v3_PhoneTest extends CiviUnitTestCase { public function testGet($version) { $this->_apiversion = $version; $phone = $this->callAPISuccess('phone', 'create', $this->_params); - $params = array( + $params = [ 'contact_id' => $this->_params['contact_id'], 'phone' => $phone['values'][$phone['id']]['phone'], - ); + ]; $result = $this->callAPIAndDocument('Phone', 'Get', $params, __FUNCTION__, __FILE__); $this->assertEquals($phone['values'][$phone['id']]['location_type_id'], $result['values'][$phone['id']]['location_type_id']); $this->assertEquals($phone['values'][$phone['id']]['phone_type_id'], $result['values'][$phone['id']]['phone_type_id']); @@ -135,7 +135,7 @@ class api_v3_PhoneTest extends CiviUnitTestCase { $this->_apiversion = $version; $result = $this->callAPISuccess('phone', 'create', $this->_params); $id = $result['id']; - $params = array('id' => $id, 'return.phone_numeric' => 1); + $params = ['id' => $id, 'return.phone_numeric' => 1]; $result = $this->callAPISuccess('phone', 'get', $params); $this->assertEquals('1234567890', $result['values'][$id]['phone_numeric']); } @@ -153,10 +153,10 @@ class api_v3_PhoneTest extends CiviUnitTestCase { unset($params['is_primary']); $phone1 = $this->callAPISuccess('phone', 'create', $params); //now we check & make sure it has been set to primary - $check = $this->callAPISuccess('phone', 'getcount', array( + $check = $this->callAPISuccess('phone', 'getcount', [ 'is_primary' => 1, 'id' => $phone1['id'], - )); + ]); $this->assertEquals(1, $check); } @@ -168,10 +168,10 @@ class api_v3_PhoneTest extends CiviUnitTestCase { $this->_apiversion = $version; $phone1 = $this->callAPISuccess('phone', 'create', $this->_params); $phone2 = $this->callAPISuccess('phone', 'create', $this->_params); - $check = $this->callAPISuccess('phone', 'getcount', array( + $check = $this->callAPISuccess('phone', 'getcount', [ 'is_primary' => 1, 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(1, $check); } diff --git a/tests/phpunit/api/v3/PledgePaymentTest.php b/tests/phpunit/api/v3/PledgePaymentTest.php index 0a7f7d03d2..5de1670e48 100644 --- a/tests/phpunit/api/v3/PledgePaymentTest.php +++ b/tests/phpunit/api/v3/PledgePaymentTest.php @@ -44,25 +44,25 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->_individualId = $this->individualCreate(); - $this->_pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId)); - $this->_contributionID = $this->contributionCreate(array('contact_id' => $this->_individualId)); + $this->_pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]); + $this->_contributionID = $this->contributionCreate(['contact_id' => $this->_individualId]); } public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contribution', 'civicrm_contact', 'civicrm_pledge', 'civicrm_pledge_payment', 'civicrm_line_item', - ); + ]; $this->quickCleanup($tablesToTruncate); parent::tearDown(); } public function testGetPledgePayment() { - $params = array(); + $params = []; $result = $this->callAPIAndDocument('pledge_payment', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals(5, $result['count'], " in line " . __LINE__); } @@ -71,16 +71,16 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { * Test that passing in a single variable works. */ public function testGetSinglePledgePayment() { - $createparams = array( + $createparams = [ 'contact_id' => $this->_individualId, 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'status_id' => 1, - ); + ]; $createResult = $this->callAPISuccess('pledge_payment', 'create', $createparams); - $params = array( + $params = [ 'contribution_id' => $this->_contributionID, - ); + ]; $result = $this->callAPISuccess('pledge_payment', 'get', $params); $this->assertEquals(1, $result['count'], " in line " . __LINE__); } @@ -93,30 +93,30 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { FALSE, FALSE, FALSE, NULL, 'name' ); //Make first payment. - $paymentParams = array( + $paymentParams = [ 'contact_id' => $this->_individualId, 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'scheduled_date' => date('Ymd', strtotime("-1 days")), 'status_id' => array_search('Pending', $pledgeStatuses), - ); + ]; $firstPayment = $this->callAPISuccess('pledge_payment', 'create', $paymentParams); //Status should be 'Pending' after first incomplete payment. - $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array( + $checkStatus = $this->callAPISuccess('pledge', 'getsingle', [ 'id' => $this->_pledgeID, 'return' => 'pledge_status', - )); + ]); $this->assertEquals('Pending', $checkStatus['pledge_status']); //Execute process_pledge job log. - $result = $this->callAPISuccess('Job', 'process_pledge', array()); + $result = $this->callAPISuccess('Job', 'process_pledge', []); $this->assertEquals("Checking if status update is needed for Pledge Id: {$this->_pledgeID} (current status is Pending)\n\r- status updated to: Overdue\n\r1 records updated.", $result['values']); //Status should be 'Overdue' after processing. - $statusAfterProcessing = $this->callAPISuccess('pledge', 'getsingle', array( + $statusAfterProcessing = $this->callAPISuccess('pledge', 'getsingle', [ 'id' => $this->_pledgeID, 'return' => 'pledge_status', - )); + ]); $this->assertEquals('Overdue', $statusAfterProcessing['pledge_status']); } @@ -125,34 +125,34 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { */ public function testPledgeStatus() { //Status should initially be Pending. - $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array( + $checkStatus = $this->callAPISuccess('pledge', 'getsingle', [ 'id' => $this->_pledgeID, 'return' => 'pledge_status', - )); + ]); $this->assertEquals('Pending', $checkStatus['pledge_status']); //Make first payment. - $paymentParams = array( + $paymentParams = [ 'contact_id' => $this->_individualId, 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'status_id' => 1, - ); + ]; $firstPayment = $this->callAPISuccess('pledge_payment', 'create', $paymentParams); //Status should be 'In Progress' after first payment. - $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array( + $checkStatus = $this->callAPISuccess('pledge', 'getsingle', [ 'id' => $this->_pledgeID, 'return' => 'pledge_status', - )); + ]); $this->assertEquals('In Progress', $checkStatus['pledge_status']); //Cancel the Pledge. $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - $updateParams = array( + $updateParams = [ 'id' => $this->_pledgeID, 'status_id' => array_search('Cancelled', $paymentStatusTypes), - ); + ]; $this->callAPISuccess('pledge', 'create', $updateParams); //Status should be calculated as Cancelled. @@ -160,10 +160,10 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { $this->assertEquals('Cancelled', $paymentStatusTypes[$pledgeStatus]); //Already completed payments should not be cancelled. - $checkPaymentStatus = $this->callAPISuccess('pledge_payment', 'getsingle', array( + $checkPaymentStatus = $this->callAPISuccess('pledge_payment', 'getsingle', [ 'id' => $firstPayment['id'], 'return' => 'status_id', - )); + ]); $this->assertEquals(array_search('Completed', $paymentStatusTypes), $checkPaymentStatus['status_id']); } @@ -171,16 +171,16 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { * Test that passing in a single variable works:: status_id */ public function testGetSinglePledgePaymentByStatusID() { - $createparams = array( + $createparams = [ 'contact_id' => $this->_individualId, 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'status_id' => 1, - ); + ]; $createResult = $this->callAPISuccess('pledge_payment', 'create', $createparams); - $params = array( + $params = [ 'status_id' => 1, - ); + ]; $result = $this->callAPISuccess('pledge_payment', 'get', $params); $this->assertEquals(1, $result['count'], " in line " . __LINE__); @@ -191,21 +191,21 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { */ public function testCreatePledgePayment() { //check that 5 pledge payments exist at the start - $beforeAdd = $this->callAPISuccess('pledge_payment', 'get', array()); + $beforeAdd = $this->callAPISuccess('pledge_payment', 'get', []); $this->assertEquals(5, $beforeAdd['count'], " in line " . __LINE__); //test the pledge_payment_create function - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'status_id' => 1, 'actual_amount' => 20, - ); + ]; $result = $this->callAPIAndDocument('pledge_payment', 'create', $params, __FUNCTION__, __FILE__); //check existing updated not new one created - 'create' means add contribution_id in this context - $afterAdd = $this->callAPISuccess('pledge_payment', 'get', array()); + $afterAdd = $this->callAPISuccess('pledge_payment', 'get', []); $this->assertEquals(5, $afterAdd['count'], " in line " . __LINE__); //get the created payment & check it out @@ -215,11 +215,11 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { $this->assertEquals(20, $getIndPayment['values'][$result['id']]['actual_amount'], " in line " . __LINE__); //create a second pledge payment - need a contribution first &can't use the CiviUnitTest case function as invoice is hard-coded - $contributionParams = array( + $contributionParams = [ 'total_amount' => 20, 'contact_id' => $this->_individualId, 'financial_type_id' => $this->_financialTypeId, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); $params['contribution_id'] = $contribution['id']; @@ -235,29 +235,29 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { * Test checks behaviour when more payments are created than should be possible. */ public function testCreatePledgePaymentAllCreated() { - $params = array( + $params = [ 'pledge_id' => $this->_pledgeID, 'status_id' => 1, - ); + ]; // create one more pledge than there are spaces for $i = 0; while ($i <= 5) { - $contributionParams = array( + $contributionParams = [ 'total_amount' => 20, 'contact_id' => $this->_individualId, 'financial_type_id' => $this->_financialTypeId, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); $params['contribution_id'] = $contribution['id']; - $resultCont2 = civicrm_api('pledge_payment', 'create', $params + array('version' => $this->_apiversion)); + $resultCont2 = civicrm_api('pledge_payment', 'create', $params + ['version' => $this->_apiversion]); $i++; } // check that only 5 exist & we got an error setting the 6th - $result = $this->callAPISuccess('PledgePayment', 'Get', array( + $result = $this->callAPISuccess('PledgePayment', 'Get', [ 'pledge_id' => $this->_pledgeID, - )); + ]); // the last one above should result in an error $this->assertEquals("There are no unmatched payment on this pledge. Pass in the pledge_payment id to specify one or 'option.create_new' to create one", $resultCont2['error_message']); $this->assertEquals(5, $result['count']); @@ -266,9 +266,9 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { $params['scheduled_amount'] = 20; $params['scheduled_date'] = '20131212'; $resultcreatenew = $this->callAPISuccess('pledge_payment', 'create', $params); - $result = $this->callAPISuccess('PledgePayment', 'Get', array( + $result = $this->callAPISuccess('PledgePayment', 'Get', [ 'pledge_id' => $this->_pledgeID, - )); + ]); $this->assertEquals(6, $result['count']); } @@ -277,7 +277,7 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { * Test that creating a payment adds the contribution ID where only one pledge payment is in schedule. */ public function testCreatePledgePaymentWhereOnlyOnePayment() { - $pledgeParams = array( + $pledgeParams = [ 'contact_id' => $this->_individualId, 'pledge_create_date' => date('Ymd'), 'start_date' => date('Ymd'), @@ -291,69 +291,69 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { 'frequency_day' => 15, 'installments' => 1, 'sequential' => 1, - ); + ]; - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $this->_individualId, 'financial_type_id' => $this->_financialTypeId, 'invoice_id' => 45, 'trxn_id' => 45, - )); + ]); $pledge = $this->callAPISuccess('Pledge', 'Create', $pledgeParams); //test the pledge_payment_create function - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'pledge_id' => $pledge['id'], 'contribution_id' => $contributionID, 'status_id' => 1, 'actual_amount' => 20, - ); + ]; $result = $this->callAPISuccess('pledge_payment', 'create', $params); //check existing updated not new one created - 'create' means add contribution_id in this context - $afterAdd = $this->callAPISuccess('pledge_payment', 'get', array( + $afterAdd = $this->callAPISuccess('pledge_payment', 'get', [ 'contribution_id' => $contributionID, - )); + ]); $this->assertEquals(1, $afterAdd['count'], " in line " . __LINE__); } public function testUpdatePledgePayment() { - $params = array( + $params = [ 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'status_id' => 2, 'actual_amount' => 20, - ); + ]; $result = $this->callAPISuccess('pledge_payment', 'create', $params); - $updateparams = array( + $updateparams = [ 'id' => $result['id'], 'status_id' => 1, - ); + ]; $result = $this->callAPIAndDocument('pledge_payment', 'update', $updateparams, __FUNCTION__, __FILE__); $this->getAndCheck(array_merge($params, $updateparams), $result['id'], $this->_entity); } public function testDeletePledgePayment() { - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'pledge_id' => $this->_pledgeID, 'contribution_id' => $this->_contributionID, 'status_id' => 1, 'sequential' => 1, 'actual_amount' => 20, - ); + ]; $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', $params); - $deleteParams = array( + $deleteParams = [ 'id' => $pledgePayment['id'], - ); + ]; $result = $this->callAPIAndDocument('pledge_payment', 'delete', $deleteParams, __FUNCTION__, __FILE__); } public function testGetFields() { - $result = $this->callAPISuccess('PledgePayment', 'GetFields', array()); + $result = $this->callAPISuccess('PledgePayment', 'GetFields', []); $this->assertType('array', $result); } diff --git a/tests/phpunit/api/v3/PledgeTest.php b/tests/phpunit/api/v3/PledgeTest.php index 507987b67b..36eb602b23 100644 --- a/tests/phpunit/api/v3/PledgeTest.php +++ b/tests/phpunit/api/v3/PledgeTest.php @@ -44,13 +44,13 @@ class api_v3_PledgeTest extends CiviUnitTestCase { public function setUp() { $this->_apiversion = 3; parent::setUp(); - $this->quickCleanup(array('civicrm_pledge', 'civicrm_pledge_payment')); + $this->quickCleanup(['civicrm_pledge', 'civicrm_pledge_payment']); //need to set scheduled payment in advance we are running test @ midnight & it becomes unexpectedly overdue //due to timezone issues $this->scheduled_date = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y"))); $this->_entity = 'Pledge'; $this->_individualId = $this->individualCreate(); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_individualId, 'pledge_create_date' => date('Ymd'), 'start_date' => date('Ymd'), @@ -64,7 +64,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'frequency_day' => 15, 'installments' => 5, 'sequential' => 1, - ); + ]; } public function tearDown() { @@ -87,9 +87,9 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $result = $this->callAPISuccess($this->_entity, 'create', $params); $this->assertAPISuccess($result, " testCreateWithCustom "); $this->assertAPISuccess($result); - $getParams = array('id' => $result['id'], 'return.custom_' . $ids['custom_field_id'] => 1); + $getParams = ['id' => $result['id'], 'return.custom_' . $ids['custom_field_id'] => 1]; $check = $this->callAPISuccess($this->_entity, 'get', $getParams); - $this->callAPISuccess('pledge', 'delete', array('id' => $check['id'])); + $this->callAPISuccess('pledge', 'delete', ['id' => $check['id']]); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); $this->customFieldDelete($ids['custom_field_id']); @@ -100,7 +100,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * Test getfields function for pledge. */ public function testGetfieldsPledge() { - $result = $this->callAPISuccess('pledge', 'getfields', array('action' => 'get')); + $result = $this->callAPISuccess('pledge', 'getfields', ['action' => 'get']); $this->assertEquals(1, $result['values']['next_pay_date']['api.return']); } @@ -110,9 +110,9 @@ class api_v3_PledgeTest extends CiviUnitTestCase { public function testGetPledge() { $this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params); - $params = array( + $params = [ 'pledge_id' => $this->_pledge['id'], - ); + ]; $result = $this->callAPIAndDocument('pledge', 'get', $params, __FUNCTION__, __FILE__); $pledge = $result['values'][$this->_pledge['id']]; $this->assertEquals($this->_individualId, $pledge['contact_id']); @@ -125,9 +125,9 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals(date('Y-m-d', strtotime($this->scheduled_date)) . ' 00:00:00', $pledge['pledge_next_pay_date']); $this->assertEquals($pledge['pledge_next_pay_amount'], 20.00); - $params2 = array( + $params2 = [ 'pledge_id' => $this->_pledge['id'], - ); + ]; $pledge = $this->callAPISuccess('pledge', 'delete', $params2); } @@ -137,10 +137,10 @@ class api_v3_PledgeTest extends CiviUnitTestCase { public function testGetPledgeWithReturn() { $this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params); - $params = array( + $params = [ 'pledge_id' => $this->_pledge['id'], 'return.pledge_financial_type' => 1, - ); + ]; $result = $this->callAPISuccess('pledge', 'get', $params); $pledge = $result['values'][$this->_pledge['id']]; $this->callAPISuccess('pledge', 'delete', $pledge); @@ -155,10 +155,10 @@ class api_v3_PledgeTest extends CiviUnitTestCase { public function testGetPledgeWithReturnLegacy() { $this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params); - $params = array( + $params = [ 'pledge_id' => $this->_pledge['id'], 'return.pledge_financial_type' => 1, - ); + ]; $result = $this->callAPISuccess('pledge', 'get', $params); $pledge = $result['values'][$this->_pledge['id']]; $this->callAPISuccess('pledge', 'delete', $pledge); @@ -171,13 +171,13 @@ class api_v3_PledgeTest extends CiviUnitTestCase { public function testPledgeGetReturnFilters() { $this->callAPISuccess('pledge', 'create', $this->_params); - $overdueParams = array( + $overdueParams = [ 'scheduled_date' => 'first saturday of march last year', 'start_date' => 'first saturday of march last year', - ); + ]; $oldPledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); - $pledgeGetParams = array(); + $pledgeGetParams = []; $allPledges = $this->callAPISuccess('pledge', 'getcount', $pledgeGetParams); $this->assertEquals(2, $allPledges, 'Check we have 2 pledges to place with in line ' . __LINE__); @@ -191,16 +191,16 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * Create 2 pledges - see if we can get by status id. */ public function testGetOverduePledge() { - $overdueParams = array( + $overdueParams = [ 'scheduled_date' => 'first saturday of march last year', 'start_date' => 'first saturday of march last year', - ); + ]; $this->_pledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); - $result = $this->callAPISuccess('pledge', 'get', array('status_id' => 'Overdue')); - $emptyResult = $this->callAPISuccess('pledge', 'get', array( + $result = $this->callAPISuccess('pledge', 'get', ['status_id' => 'Overdue']); + $emptyResult = $this->callAPISuccess('pledge', 'get', [ 'pledge_status_id' => '1', - )); + ]); $pledge = $result['values'][$this->_pledge['id']]; $this->callAPISuccess('pledge', 'delete', $pledge); $this->assertEquals(1, $result['count']); @@ -211,18 +211,18 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * Test pledge_status option group */ public function testOptionGroupForPledgeStatus() { - $pledgeOg = $this->callAPISuccess('OptionGroup', 'get', array( + $pledgeOg = $this->callAPISuccess('OptionGroup', 'get', [ 'name' => "pledge_status", - )); + ]); $this->assertEquals(1, $pledgeOg['count']); - $pledgeOv = $this->callAPISuccess('OptionValue', 'get', array( + $pledgeOv = $this->callAPISuccess('OptionValue', 'get', [ 'sequential' => 1, 'option_group_id' => "pledge_status", - )); + ]); $this->assertEquals(5, $pledgeOv['count']); $pledgeStatus = CRM_Utils_Array::collect('name', $pledgeOv['values']); - $expected = array('Completed', 'Pending', 'Cancelled', 'In Progress', 'Overdue'); + $expected = ['Completed', 'Pending', 'Cancelled', 'In Progress', 'Overdue']; $this->assertEquals($expected, $pledgeStatus); } @@ -231,32 +231,32 @@ class api_v3_PledgeTest extends CiviUnitTestCase { */ public function testSortParamPledge() { $pledge1 = $this->callAPISuccess('pledge', 'create', $this->_params); - $overdueParams = array( + $overdueParams = [ 'scheduled_date' => 'first saturday of march last year', 'start_date' => 'first saturday of march last year', 'create_date' => 'first saturday of march last year', - ); + ]; $pledge2 = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); - $params = array( + $params = [ 'pledge_is_test' => 0, 'rowCount' => 1, - ); + ]; $result = $this->callAPISuccess('pledge', 'get', $params); - $resultSortedAsc = $this->callAPISuccess('pledge', 'get', array( + $resultSortedAsc = $this->callAPISuccess('pledge', 'get', [ 'rowCount' => 1, 'sort' => 'start_date ASC', - )); - $resultSortedDesc = $this->callAPISuccess('pledge', 'get', array( + ]); + $resultSortedDesc = $this->callAPISuccess('pledge', 'get', [ 'rowCount' => 1, 'sort' => 'start_date DESC', - )); + ]); $this->assertEquals($pledge1['id'], $result['id'], 'pledge get gets first created pledge in line ' . __LINE__); $this->assertEquals($pledge2['id'], $resultSortedAsc['id'], 'Ascending pledge sort works'); $this->assertEquals($pledge1['id'], $resultSortedDesc['id'], 'Decending pledge sort works'); - $this->callAPISuccess('pledge', 'delete', array('id' => $pledge1['id'])); - $this->callAPISuccess('pledge', 'delete', array('id' => $pledge2['id'])); + $this->callAPISuccess('pledge', 'delete', ['id' => $pledge1['id']]); + $this->callAPISuccess('pledge', 'delete', ['id' => $pledge2['id']]); } public function testCreatePledge() { @@ -272,13 +272,13 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($result['values'][0]['create_date'], date('Ymd') . '000000'); $this->assertEquals($result['values'][0]['start_date'], date('Ymd') . '000000'); $this->assertAPISuccess($result); - $payments = $this->callAPISuccess('PledgePayment', 'Get', array('pledge_id' => $result['id'], 'sequential' => 1)); + $payments = $this->callAPISuccess('PledgePayment', 'Get', ['pledge_id' => $result['id'], 'sequential' => 1]); $this->assertAPISuccess($payments); $this->assertEquals($payments['count'], 5); $shouldBeDate = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd('year', 5 * 4, $this->scheduled_date), "-"); $this->assertEquals(substr($shouldBeDate, 0, 10), substr($payments['values'][4]['scheduled_date'], 0, 10)); - $pledgeID = array('id' => $result['id']); + $pledgeID = ['id' => $result['id']]; $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } @@ -286,35 +286,35 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * Test that pledge with weekly schedule calculates dates correctly. */ public function testCreatePledgeWeeklySchedule() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'week', 'frequency_day' => 3, 'frequency_interval' => 2, - ); + ]; $params = array_merge($this->_params, $params); $pledge = $this->callAPISuccess('Pledge', 'Create', $params); //ensure that correct number of payments created & last payment has the right date - $payments = $this->callAPISuccess('PledgePayment', 'Get', array( + $payments = $this->callAPISuccess('PledgePayment', 'Get', [ 'pledge_id' => $pledge['id'], 'sequential' => 1, - )); + ]); $this->assertEquals($payments['count'], 5); $this->assertEquals('2011-07-06 00:00:00', $payments['values'][4]['scheduled_date']); - $this->callAPISuccess('pledge', 'delete', array('pledge_id' => $pledge['id'])); + $this->callAPISuccess('pledge', 'delete', ['pledge_id' => $pledge['id']]); } /** * Test that pledge with weekly schedule calculates dates correctly. */ public function testCreatePledgeMontlySchedule() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'Month', 'frequency_day' => 3, 'frequency_interval' => 2, - ); + ]; $params = array_merge($this->_params, $params); $apiResult = $this->callAPISuccess('pledge', 'create', $params); } @@ -326,25 +326,25 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * http://issues.civicrm.org/jira/browse/CRM-8551 */ public function testCreatePledgeSinglePayment() { - $params = array( + $params = [ 'scheduled_date' => '20110510', 'frequency_unit' => 'week', 'frequency_day' => 3, 'frequency_interval' => 2, 'installments' => 1, - ); + ]; $params = array_merge($this->_params, $params); unset($params['pledge_status_id']); $pledge = $this->callAPISuccess('Pledge', 'Create', $params); //ensure that correct number of payments created & last payment has the right date - $payments = $this->callAPISuccess('PledgePayment', 'Get', array( + $payments = $this->callAPISuccess('PledgePayment', 'Get', [ 'pledge_id' => $pledge['id'], 'sequential' => 1, - )); + ]); $this->assertEquals(1, $payments['count']); $this->assertEquals(2, $payments['values'][0]['status_id']); - $pledgeID = array('id' => $pledge['id']); + $pledgeID = ['id' => $pledge['id']]; $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } @@ -359,14 +359,14 @@ class api_v3_PledgeTest extends CiviUnitTestCase { unset($params['pledge_original_installment_amount']); $result = $this->callAPISuccess('pledge', 'create', $params); - $pledgeDetails = $this->callAPISuccess('Pledge', 'Get', array('id' => $result['id'], 'sequential' => 1)); + $pledgeDetails = $this->callAPISuccess('Pledge', 'Get', ['id' => $result['id'], 'sequential' => 1]); $pledge = $pledgeDetails['values'][0]; $this->assertEquals(100.00, $pledge['pledge_amount']); $this->assertEquals('year', $pledge['pledge_frequency_unit']); $this->assertEquals(5, $pledge['pledge_frequency_interval']); $this->assertEquals(20, $pledge['pledge_next_pay_amount']); - $pledgeID = array('id' => $result['id']); + $pledgeID = ['id' => $result['id']]; $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } @@ -377,14 +377,14 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $result = $this->callAPISuccess('pledge', 'create', $this->_params); $this->assertEquals(2, $result['values'][0]['status_id']); - $cancelParams = array( + $cancelParams = [ 'sequential' => 1, 'id' => $result['id'], 'pledge_status_id' => 3, - ); + ]; $result = $this->callAPISuccess('pledge', 'create', $cancelParams); $this->assertEquals(3, $result['values'][0]['status_id']); - $pledgeID = array('id' => $result['id']); + $pledgeID = ['id' => $result['id']]; $this->callAPISuccess('pledge', 'delete', $pledgeID); } @@ -399,7 +399,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $result = $this->callAPISuccess('pledge', 'create', $params); $this->assertAPISuccess($result); $this->assertEquals(2, $result['values'][0]['status_id']); - $pledgeID = array('pledge_id' => $result['id']); + $pledgeID = ['pledge_id' => $result['id']]; $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } @@ -408,11 +408,11 @@ class api_v3_PledgeTest extends CiviUnitTestCase { */ public function testCreateUpdatePledge() { // we test 'sequential' param here too - $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId)); - $old_params = array( + $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]); + $old_params = [ 'id' => $pledgeID, 'sequential' => 1, - ); + ]; $original = $this->callAPISuccess('pledge', 'get', $old_params); //Make sure it came back $this->assertEquals($original['values'][0]['pledge_id'], $pledgeID); @@ -427,7 +427,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($old_frequency_unit, 'year'); $this->assertEquals($old_frequency_interval, 5); $this->assertEquals($old_status_id, 'Pending'); - $params = array( + $params = [ 'id' => $pledgeID, 'contact_id' => $this->_individualId, 'pledge_status_id' => 3, @@ -435,12 +435,12 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'start_date' => date('Ymd'), 'installments' => 10, - ); + ]; $pledge = $this->callAPISuccess('pledge', 'create', $params); - $new_params = array( + $new_params = [ 'id' => $pledge['id'], - ); + ]; $pledge = $this->callAPISuccess('pledge', 'get', $new_params); $this->assertEquals($pledge['values'][$pledgeID]['contact_id'], $this->_individualId); $this->assertEquals($pledge['values'][$pledgeID]['pledge_status'], 'Cancelled'); @@ -455,11 +455,11 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * We test 'sequential' param here too. */ public function testCreateUpdatePledgeLegacy() { - $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId)); - $old_params = array( + $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]); + $old_params = [ 'id' => $pledgeID, 'sequential' => 1, - ); + ]; $original = $this->callAPISuccess('pledge', 'get', $old_params); // Make sure it came back. $this->assertEquals($original['values'][0]['pledge_id'], $pledgeID); @@ -474,7 +474,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($old_frequency_unit, 'year'); $this->assertEquals($old_frequency_interval, 5); $this->assertEquals($old_status_id, 'Pending'); - $params = array( + $params = [ 'id' => $pledgeID, 'contact_id' => $this->_individualId, 'pledge_status_id' => 3, @@ -482,12 +482,12 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'contribution_type_id' => 1, 'start_date' => date('Ymd'), 'installments' => 10, - ); + ]; $pledge = $this->callAPISuccess('pledge', 'create', $params); - $new_params = array( + $new_params = [ 'id' => $pledge['id'], - ); + ]; $pledge = $this->callAPISuccess('pledge', 'get', $new_params); $this->assertEquals($pledge['values'][$pledgeID]['contact_id'], $this->_individualId); $this->assertEquals($pledge['values'][$pledgeID]['pledge_status'], 'Cancelled'); @@ -498,16 +498,16 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * Failure test for delete without id. */ public function testDeleteEmptyParamsPledge() { - $this->callAPIFailure('pledge', 'delete', array(), 'Mandatory key(s) missing from params array: id'); + $this->callAPIFailure('pledge', 'delete', [], 'Mandatory key(s) missing from params array: id'); } /** * Failure test for invalid pledge id. */ public function testDeleteWrongParamPledge() { - $params = array( + $params = [ 'pledge_source' => 'SSF', - ); + ]; $this->callAPIFailure('pledge', 'delete', $params, 'Mandatory key(s) missing from params array: id'); } @@ -516,10 +516,10 @@ class api_v3_PledgeTest extends CiviUnitTestCase { */ public function testDeletePledge() { - $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId)); - $params = array( + $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]); + $params = [ 'pledge_id' => $pledgeID, - ); + ]; $this->callAPIAndDocument('pledge', 'delete', $params, __FUNCTION__, __FILE__); } @@ -528,10 +528,10 @@ class api_v3_PledgeTest extends CiviUnitTestCase { */ public function testDeletePledgeUseID() { - $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId)); - $params = array( + $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]); + $params = [ 'id' => $pledgeID, - ); + ]; $this->callAPIAndDocument('pledge', 'delete', $params, __FUNCTION__, __FILE__); } @@ -543,10 +543,10 @@ class api_v3_PledgeTest extends CiviUnitTestCase { */ public function testGetEmpty() { $this->callAPISuccess('pledge', 'create', $this->_params); - $result = $this->callAPISuccess('pledge', 'get', array()); + $result = $this->callAPISuccess('pledge', 'get', []); $this->assertAPISuccess($result, "This test is failing because it's acting like a contact get when no params set. Not sure the fix"); $this->assertEquals(1, $result['count']); - $pledgeID = array('id' => $result['id']); + $pledgeID = ['id' => $result['id']]; $this->callAPISuccess('pledge', 'delete', $pledgeID); } diff --git a/tests/phpunit/api/v3/PriceFieldTest.php b/tests/phpunit/api/v3/PriceFieldTest.php index 5f2d5d89cc..d5b8de6ae8 100644 --- a/tests/phpunit/api/v3/PriceFieldTest.php +++ b/tests/phpunit/api/v3/PriceFieldTest.php @@ -41,7 +41,7 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); // put stuff here that should happen before all tests in this unit - $priceSetparams = array( + $priceSetparams = [ # [domain_id] => 'name' => 'default_goat_priceset', 'title' => 'Goat accomodation', @@ -52,31 +52,31 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'is_quick_config' => 1, 'is_reserved' => 1, - ); + ]; $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams); $this->priceSetID = $price_set['id']; - $this->_params = array( + $this->_params = [ 'price_set_id' => $this->priceSetID, 'name' => 'grassvariety', 'label' => 'Grass Variety', 'html_type' => 'Text', 'is_enter_qty' => 1, 'is_active' => 1, - ); + ]; } public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_contribution', - ); + ]; $this->quickCleanup($tablesToTruncate); - $delete = $this->callAPISuccess('PriceSet', 'delete', array( + $delete = $this->callAPISuccess('PriceSet', 'delete', [ 'id' => $this->priceSetID, - )); + ]); $this->assertAPISuccess($delete); parent::tearDown(); @@ -93,26 +93,26 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); $this->id = $createResult['id']; $this->assertAPISuccess($createResult); - $getParams = array( + $getParams = [ 'name' => 'contribution_amount', - ); + ]; $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count']); - $this->callAPISuccess('price_field', 'delete', array('id' => $createResult['id'])); + $this->callAPISuccess('price_field', 'delete', ['id' => $createResult['id']]); } public function testDeletePriceField() { - $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); + $startCount = $this->callAPISuccess($this->_entity, 'getcount', []); $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $deleteParams = array('id' => $createResult['id']); + $deleteParams = ['id' => $createResult['id']]; $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); $this->assertAPISuccess($deleteResult); - $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); + $endCount = $this->callAPISuccess($this->_entity, 'getcount', []); $this->assertEquals($startCount, $endCount); } public function testGetFieldsPriceField() { - $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertEquals(1, $result['values']['options_per_line']['type']); } @@ -122,18 +122,18 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { */ public function testUpdatePriceFieldLabel() { $field = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $this->callAPISuccess('price_field_value', 'create', array( + $this->callAPISuccess('price_field_value', 'create', [ 'price_field_id' => $field['id'], 'name' => 'rye grass', 'label' => 'juicy and healthy', 'amount' => 1, 'financial_type_id' => 1, - )); - $priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety')); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id'])); + ]); + $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']); + $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]); $this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']); - $this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id'])); + $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]); } /** @@ -141,19 +141,19 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { * Confirm value label only updates if fiedl type is html. */ public function testUpdatePriceFieldLabelNotUpdateField() { - $field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array('html_type' => 'Radio'))); - $this->callAPISuccess('price_field_value', 'create', array( + $field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, ['html_type' => 'Radio'])); + $this->callAPISuccess('price_field_value', 'create', [ 'price_field_id' => $field['id'], 'name' => 'rye grass', 'label' => 'juicy and healthy', 'amount' => 1, 'financial_type_id' => 1, - )); - $priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety')); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id'])); + ]); + $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']); + $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]); $this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']); - $this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id'])); + $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]); } } diff --git a/tests/phpunit/api/v3/PriceFieldValueTest.php b/tests/phpunit/api/v3/PriceFieldValueTest.php index 9f9f91b5c8..da01f84034 100644 --- a/tests/phpunit/api/v3/PriceFieldValueTest.php +++ b/tests/phpunit/api/v3/PriceFieldValueTest.php @@ -49,7 +49,7 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); // Put stuff here that should happen before all tests in this unit. - $priceSetParams = array( + $priceSetParams = [ 'name' => 'default_goat_priceset', 'title' => 'Goat accommodation', 'is_active' => 1, @@ -59,32 +59,32 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'is_quick_config' => 1, 'is_reserved' => 1, - ); + ]; $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams); $this->priceSetID = $price_set['id']; - $priceFieldParams = array( + $priceFieldParams = [ 'price_set_id' => $this->priceSetID, 'name' => 'grassvariety', 'label' => 'Grass Variety', 'html_type' => 'Text', 'is_enter_qty' => 1, 'is_active' => 1, - ); + ]; $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams); $this->priceFieldID = $priceField['id']; - $this->_params = array( + $this->_params = [ 'price_field_id' => $this->priceFieldID, 'name' => 'rye grass', 'label' => 'juicy and healthy', 'amount' => 1, 'financial_type_id' => 1, - ); + ]; $membershipOrgId = $this->organizationCreate(NULL); - $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId)); - $priceSetParams1 = array( + $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $membershipOrgId]); + $priceSetParams1 = [ 'name' => 'priceset', 'title' => 'Priceset with Multiple Terms', 'is_active' => 1, @@ -92,17 +92,17 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { 'financial_type_id' => 2, 'is_quick_config' => 1, 'is_reserved' => 1, - ); + ]; $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1); $this->priceSetID1 = $price_set1['id']; - $priceFieldParams1 = array( + $priceFieldParams1 = [ 'price_set_id' => $this->priceSetID1, 'name' => 'memtype', 'label' => 'memtype', 'html_type' => 'Radio', 'is_enter_qty' => 1, 'is_active' => 1, - ); + ]; $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1); $this->priceFieldID1 = $priceField1['id']; } @@ -113,24 +113,24 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { * @throws \Exception */ public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_contribution', - ); + ]; $this->quickCleanup($tablesToTruncate); - $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); - $this->callAPISuccess('PriceField', 'delete', array( + $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); + $this->callAPISuccess('PriceField', 'delete', [ 'id' => $this->priceFieldID1, - )); - $this->callAPISuccess('PriceSet', 'delete', array( + ]); + $this->callAPISuccess('PriceSet', 'delete', [ 'id' => $this->priceSetID1, - )); - $this->callAPISuccess('PriceField', 'delete', array( + ]); + $this->callAPISuccess('PriceField', 'delete', [ 'id' => $this->priceFieldID, - )); - $delete = $this->callAPISuccess('PriceSet', 'delete', array( + ]); + $delete = $this->callAPISuccess('PriceSet', 'delete', [ 'id' => $this->priceSetID, - )); + ]); $this->assertAPISuccess($delete); } @@ -147,31 +147,31 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); $this->id = $createResult['id']; $this->assertAPISuccess($createResult); - $getParams = array( + $getParams = [ 'name' => 'contribution_amount', - ); + ]; $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count']); - $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id'])); + $this->callAPISuccess('price_field_value', 'delete', ['id' => $createResult['id']]); } public function testDeletePriceFieldValue() { - $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); + $startCount = $this->callAPISuccess($this->_entity, 'getcount', []); $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $deleteParams = array('id' => $createResult['id']); + $deleteParams = ['id' => $createResult['id']]; $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); + $endCount = $this->callAPISuccess($this->_entity, 'getcount', []); $this->assertEquals($startCount, $endCount); } public function testGetFieldsPriceFieldValue() { - $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertEquals(1, $result['values']['max_value']['type']); } public function testCreatePriceFieldValuewithMultipleTerms() { - $params = array( + $params = [ 'price_field_id' => $this->priceFieldID1, 'membership_type_id' => $this->_membershipTypeID, 'name' => 'memType1', @@ -180,15 +180,15 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { 'membership_num_terms' => 2, 'is_active' => 1, 'financial_type_id' => 2, - ); + ]; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2); $this->assertEquals(1, $result['count']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } public function testGetPriceFieldValuewithMultipleTerms() { - $params1 = array( + $params1 = [ 'price_field_id' => $this->priceFieldID1, 'membership_type_id' => $this->_membershipTypeID, 'name' => 'memType1', @@ -197,8 +197,8 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { 'membership_num_terms' => 2, 'is_active' => 1, 'financial_type_id' => 2, - ); - $params2 = array( + ]; + $params2 = [ 'price_field_id' => $this->priceFieldID1, 'membership_type_id' => $this->_membershipTypeID, 'name' => 'memType2', @@ -207,29 +207,29 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase { 'membership_num_terms' => 3, 'is_active' => 1, 'financial_type_id' => 2, - ); + ]; $result1 = $this->callAPISuccess($this->_entity, 'create', $params1); $result2 = $this->callAPISuccess($this->_entity, 'create', $params2); - $result = $this->callAPISuccess($this->_entity, 'get', array('price_field_id' => $this->priceFieldID1)); + $result = $this->callAPISuccess($this->_entity, 'get', ['price_field_id' => $this->priceFieldID1]); $this->assertEquals(2, $result['count']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result1['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result2['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result1['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result2['id']]); } public function testCreatePriceFieldValueWithDisabledFinancialType() { - $financialTypeParams = array( + $financialTypeParams = [ 'is_active' => 0, 'name' => 'Disabled Donations', - ); + ]; $financialType = $this->callAPISuccess('financial_type', 'create', $financialTypeParams); - $params = array( + $params = [ 'price_field_id' => $this->priceFieldID, 'name' => 'DonType1', 'label' => 'DonType1', 'amount' => 90, 'is_active' => 1, 'financial_type_id' => $financialType['id'], - ); + ]; $this->callAPIFailure($this->_entity, 'create', $params); } diff --git a/tests/phpunit/api/v3/PriceSetTest.php b/tests/phpunit/api/v3/PriceSetTest.php index 81a54f6dc6..622abf20d6 100644 --- a/tests/phpunit/api/v3/PriceSetTest.php +++ b/tests/phpunit/api/v3/PriceSetTest.php @@ -33,7 +33,7 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { protected $_apiversion = 3; protected $_params; protected $id = 0; - protected $contactIds = array(); + protected $contactIds = []; protected $_entity = 'price_set'; public $DBResetRequired = TRUE; @@ -43,7 +43,7 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { */ public function setUp() { parent::setUp(); - $this->_params = array( + $this->_params = [ 'name' => 'default_goat_priceset', 'title' => 'Goat accessories', 'is_active' => 1, @@ -53,7 +53,7 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'is_quick_config' => 1, 'is_reserved' => 1, - ); + ]; } /** @@ -71,19 +71,19 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { */ public function testCreatePriceSetForEventAndContribution() { // Create the price set - $createParams = array( + $createParams = [ 'name' => 'some_price_set', 'title' => 'Some Price Set', 'is_active' => 1, 'financial_type_id' => 1, - 'extends' => array(1, 2), - ); + 'extends' => [1, 2], + ]; $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); // Get priceset we just created. - $result = $this->callAPISuccess($this->_entity, 'getSingle', array( + $result = $this->callAPISuccess($this->_entity, 'getSingle', [ 'id' => $createResult['id'], - )); + ]); // Count the number of items in 'extends'. $this->assertEquals(2, count($result['extends'])); @@ -101,47 +101,47 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { /** */ public function testGetBasicPriceSet() { - $getParams = array( + $getParams = [ 'name' => 'default_contribution_amount', - ); + ]; $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count']); } public function testEventPriceSet() { - $event = $this->callAPISuccess('event', 'create', array( + $event = $this->callAPISuccess('event', 'create', [ 'title' => 'Event with Price Set', 'event_type_id' => 1, 'is_public' => 1, 'start_date' => 20151021, 'end_date' => 20151023, 'is_active' => 1, - )); - $createParams = array( + ]); + $createParams = [ 'entity_table' => 'civicrm_event', 'entity_id' => $event['id'], 'name' => 'event price', 'title' => 'event price', 'extends' => 1, - ); + ]; $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'id' => $createResult['id'], - )); - $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']); + ]); + $this->assertEquals(['civicrm_event' => [$event['id']]], $result['values'][$createResult['id']]['entity']); } public function testDeletePriceSet() { - $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); + $startCount = $this->callAPISuccess($this->_entity, 'getcount', []); $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $deleteParams = array('id' => $createResult['id']); + $deleteParams = ['id' => $createResult['id']]; $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); + $endCount = $this->callAPISuccess($this->_entity, 'getcount', []); $this->assertEquals($startCount, $endCount); } public function testGetFieldsPriceSet() { - $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertEquals(16, $result['values']['is_quick_config']['type']); } @@ -150,10 +150,10 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { } public static function tearDownAfterClass() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_contribution', - ); + ]; $unitTest = new CiviUnitTestCase(); $unitTest->quickCleanup($tablesToTruncate); } diff --git a/tests/phpunit/api/v3/ProductTest.php b/tests/phpunit/api/v3/ProductTest.php index e8c854d057..396d7e938d 100644 --- a/tests/phpunit/api/v3/ProductTest.php +++ b/tests/phpunit/api/v3/ProductTest.php @@ -38,18 +38,18 @@ class api_v3_ProductTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->useTransaction(); - $this->_params = array( + $this->_params = [ 'name' => 'my product', - ); + ]; } public function testGetFields() { - $fields = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); + $fields = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $this->assertArrayHasKey('period_type', $fields['values']); } public function testGetOptions() { - $options = $this->callAPISuccess($this->_entity, 'getoptions', array('field' => 'period_type')); + $options = $this->callAPISuccess($this->_entity, 'getoptions', ['field' => 'period_type']); $this->assertArrayHasKey('rolling', $options['values']); } diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index e037d32465..d29fe056de 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -60,16 +60,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->_cId_a = $this->individualCreate(); - $this->_cId_a_2 = $this->individualCreate(array( + $this->_cId_a_2 = $this->individualCreate([ 'last_name' => 'c2', 'email' => 'c@w.com', 'contact_type' => 'Individual', - )); + ]); $this->_cId_b = $this->organizationCreate(); - $this->_cId_b2 = $this->organizationCreate(array('organization_name' => ' Org 2')); + $this->_cId_b2 = $this->organizationCreate(['organization_name' => ' Org 2']); $this->entity = 'Relationship'; //Create a relationship type. - $relTypeParams = array( + $relTypeParams = [ 'name_a_b' => 'Relation 1 for delete', 'name_b_a' => 'Relation 2 for delete', 'description' => 'Testing relationship type', @@ -77,16 +77,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $this->_relTypeID = $this->relationshipTypeCreate($relTypeParams); - $this->_params = array( + $this->_params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, - ); + ]; } @@ -100,7 +100,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->contactDelete($this->_cId_a_2); $this->contactDelete($this->_cId_b); $this->contactDelete($this->_cId_b2); - $this->quickCleanup(array('civicrm_relationship'), TRUE); + $this->quickCleanup(['civicrm_relationship'], TRUE); $this->relationshipTypeDelete($this->_relTypeID); parent::tearDown(); } @@ -112,45 +112,45 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateEmpty($version) { $this->_apiversion = $version; - $this->callAPIFailure('relationship', 'create', array()); + $this->callAPIFailure('relationship', 'create', []); } /** * Test Current Employer is correctly set. */ public function testCurrentEmployerRelationship() { - $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', array( + $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', [ 'return' => "id", 'name_b_a' => "Employer Of", - )); - $employerRelationship = $this->callAPISuccess('Relationship', 'create', array( + ]); + $employerRelationship = $this->callAPISuccess('Relationship', 'create', [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $employerRelationshipID, - )); - $params = array($this->_cId_a => $this->_cId_b); + ]); + $params = [$this->_cId_a => $this->_cId_b]; CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($params); //Check if current employer is correctly set. - $employer = $this->callAPISuccessGetValue('Contact', array( + $employer = $this->callAPISuccessGetValue('Contact', [ 'return' => "current_employer", 'id' => $this->_cId_a, - )); - $organisation = $this->callAPISuccessGetValue('Contact', array( + ]); + $organisation = $this->callAPISuccessGetValue('Contact', [ 'return' => "sort_name", 'id' => $this->_cId_b, - )); + ]); $this->assertEquals($employer, $organisation); //Update relationship type - $update = $this->callAPISuccess('Relationship', 'create', array( + $update = $this->callAPISuccess('Relationship', 'create', [ 'id' => $employerRelationship['id'], 'relationship_type_id' => $this->_relTypeID, - )); - $employeeContact = $this->callAPISuccessGetSingle('Contact', array( - 'return' => array("current_employer"), + ]); + $employeeContact = $this->callAPISuccessGetSingle('Contact', [ + 'return' => ["current_employer"], 'id' => $this->_cId_a, - )); + ]); //current employer should be removed. $this->assertEmpty($employeeContact['current_employer']); } @@ -162,11 +162,11 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateWithoutRequired($version) { $this->_apiversion = $version; - $params = array( - 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'), - 'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'), + $params = [ + 'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'], + 'end_date' => ['d' => '10', 'M' => '1', 'Y' => '2009'], 'is_active' => 1, - ); + ]; $this->callAPIFailure('relationship', 'create', $params); } @@ -179,22 +179,22 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function testRelationshipCreateWithIncorrectData($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => 'Breaking Relationship', - ); + ]; $this->callAPIFailure('relationship', 'create', $params); //contact id is not an integer - $params = array( + $params = [ 'contact_id_a' => 'invalid', 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, - 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'), + 'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'], 'is_active' => 1, - ); + ]; $this->callAPIFailure('relationship', 'create', $params); // Contact id does not exist. @@ -203,7 +203,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { //invalid date $params['contact_id_a'] = $this->_cId_a; - $params['start_date'] = array('d' => '1', 'M' => '1'); + $params['start_date'] = ['d' => '1', 'M' => '1']; $this->callAPIFailure('relationship', 'create', $params); } @@ -215,24 +215,24 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function testRelationshipCreateInvalidRelationship($version) { $this->_apiversion = $version; // Both have the contact type Individual. - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_a, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-01-10', 'is_active' => 1, - ); + ]; $this->callAPIFailure('relationship', 'create', $params); // both the contact of type Organization - $params = array( + $params = [ 'contact_id_a' => $this->_cId_b, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-01-10', 'is_active' => 1, - ); + ]; $this->callAPIFailure('relationship', 'create', $params); } @@ -244,23 +244,23 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateAlreadyExists($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'end_date' => NULL, 'is_active' => 1, - ); + ]; $relationship = $this->callAPISuccess('relationship', 'create', $params); - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, - ); + ]; $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship'); $params['id'] = $relationship['id']; @@ -274,7 +274,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateUpdateAlreadyExists($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, @@ -282,13 +282,13 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'end_date' => NULL, 'is_active' => 1, - ); + ]; $relationship = $this->callAPISuccess('relationship', 'create', $params); - $params = array( + $params = [ 'id' => $relationship['id'], 'is_active' => 0, 'debug' => 1, - ); + ]; $this->callAPISuccess('relationship', 'create', $params); $this->callAPISuccess('relationship', 'get', $params); $params['id'] = $relationship['id']; @@ -302,7 +302,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateUpdateDoesNotMangle($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, @@ -310,13 +310,13 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'is_active' => 1, 'is_permission_a_b' => 1, 'description' => 'my desc', - ); + ]; $relationship = $this->callAPISuccess('relationship', 'create', $params); - $updateParams = array( + $updateParams = [ 'id' => $relationship['id'], 'relationship_type_id' => $this->_relTypeID, - ); + ]; $this->callAPISuccess('relationship', 'create', $updateParams); //make sure the orig params didn't get changed @@ -331,7 +331,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreate($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, @@ -339,17 +339,17 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'end_date' => '2010-12-30', 'is_active' => 1, 'note' => 'note', - ); + ]; $result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); - $relationParams = array( + $relationParams = [ 'id' => $result['id'], - ); + ]; // assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams); - $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id'])); + $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]); $values = $result['values'][$result['id']]; foreach ($params as $key => $value) { if ($key == 'note') { @@ -370,15 +370,15 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->_apiversion = $version; $result = $this->callAPISuccess('relationship', 'create', $this->_params); $relID = $result['id']; - $result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'description' => 'blah')); + $result = $this->callAPISuccess('relationship', 'create', ['id' => $relID, 'description' => 'blah']); $this->assertEquals($relID, $result['id']); $this->assertEquals('blah', $result['values'][$result['id']]['description']); - $result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'is_permission_b_a' => 1)); + $result = $this->callAPISuccess('relationship', 'create', ['id' => $relID, 'is_permission_b_a' => 1]); $this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']); - $result = $this->callAPISuccess('relationship', 'create', array('id' => $result['id'], 'is_active' => 0)); - $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id'])); + $result = $this->callAPISuccess('relationship', 'create', ['id' => $result['id'], 'is_active' => 0]); + $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]); $this->assertEquals(0, $result['values'][$result['id']]['is_active']); $this->assertEquals('blah', $result['values'][$result['id']]['description']); $this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']); @@ -391,7 +391,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateEmptyEndDate($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, @@ -399,17 +399,17 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'end_date' => '', 'is_active' => 1, 'note' => 'note', - ); + ]; $result = $this->callAPISuccess('relationship', 'create', $params); $this->assertNotNull($result['id']); - $relationParams = array( + $relationParams = [ 'id' => $result['id'], - ); + ]; // assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams); - $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id'])); + $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]); $values = $result['values'][$result['id']]; foreach ($params as $key => $value) { if ($key == 'note') { @@ -453,12 +453,12 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams); //Test Edit of custom field from the form. - $getParams = array('id' => $result['id']); - $updateParams = array_merge($getParams, array( + $getParams = ['id' => $result['id']]; + $updateParams = array_merge($getParams, [ $this->getCustomFieldName('text') => 'Edited Text Value', 'relationship_type_id' => $this->_relTypeID . '_b_a', 'related_contact_id' => $this->_cId_a, - )); + ]); $reln = new CRM_Contact_Form_Relationship(); $reln->_action = CRM_Core_Action::UPDATE; $reln->_relationshipId = $result['id']; @@ -488,7 +488,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $result = $this->callAPISuccess($this->entity, 'create', $params); $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); - $getParams = array('id' => $result['id']); + $getParams = ['id' => $result['id']]; $check = $this->callAPIAndDocument($this->entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); @@ -503,11 +503,11 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipDeleteWithoutRequired($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'start_date' => '2008-12-20', 'end_date' => '2009-12-20', 'is_active' => 1, - ); + ]; $this->callAPIFailure('relationship', 'delete', $params); } @@ -516,11 +516,11 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * Check with incorrect required fields. */ public function testRelationshipDeleteWithIncorrectData() { - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => 'Breaking Relationship', - ); + ]; $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id'); @@ -535,16 +535,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipDelete($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, - ); + ]; $result = $this->callAPISuccess('relationship', 'create', $params); - $params = array('id' => $result['id']); + $params = ['id' => $result['id']]; $this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__, __FILE__); $this->relationshipTypeDelete($this->_relTypeID); } @@ -558,7 +558,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipUpdateEmpty($version) { $this->_apiversion = $version; - $this->callAPIFailure('relationship', 'create', array(), + $this->callAPIFailure('relationship', 'create', [], 'contact_id_a, contact_id_b, relationship_type_id'); } @@ -573,31 +573,31 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipCreateDuplicate($version) { $this->_apiversion = $version; - $relParams = array( + $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '20081214', 'end_date' => '20091214', 'is_active' => 1, - ); + ]; $result = $this->callAPISuccess('relationship', 'create', $relParams); $this->assertNotNull($result['id']); - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '20081214', 'end_date' => '20091214', 'is_active' => 0, - ); + ]; $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship'); - $this->callAPISuccess('relationship', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('relationship', 'delete', ['id' => $result['id']]); $this->relationshipTypeDelete($this->_relTypeID); } @@ -609,27 +609,27 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function testRelationshipCreateDuplicateWithCustomFields() { $this->createCustomGroupWithFieldsOfAllTypes(); - $custom_params_1 = array( + $custom_params_1 = [ $this->getCustomFieldName('text') => 'Hello! this is custom data for relationship', $this->getCustomFieldName('select_string') => 'Y', $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00', $this->getCustomFieldName('link') => 'http://example.com', - ); + ]; - $custom_params_2 = array( + $custom_params_2 = [ $this->getCustomFieldName('text') => 'Hello! this is other custom data', $this->getCustomFieldName('select_string') => 'Y', $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00', $this->getCustomFieldName('link') => 'http://example.org', - ); + ]; - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, - ); + ]; $params_1 = array_merge($params, $custom_params_1); $params_2 = array_merge($params, $custom_params_2); @@ -653,12 +653,12 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function testRelationshipCreateDuplicateWithCustomFields2() { $this->createCustomGroupWithFieldsOfAllTypes(); - $custom_params_2 = array( + $custom_params_2 = [ $this->getCustomFieldName('text') => 'Hello! this is other custom data', $this->getCustomFieldName('select_string') => 'Y', $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00', $this->getCustomFieldName('link') => 'http://example.org', - ); + ]; $params_1 = [ 'contact_id_a' => $this->_cId_a, @@ -696,13 +696,13 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->getCustomFieldName('link') => 'http://example.org', ]; - $params_2 = array( + $params_2 = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, - ); + ]; $params_1 = array_merge($params_2, $custom_params_1); @@ -719,32 +719,32 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * Check with valid params array. */ public function testRelationshipsGet() { - $relParams = array( + $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, - ); + ]; $this->callAPISuccess('relationship', 'create', $relParams); //get relationship - $params = array( + $params = [ 'contact_id' => $this->_cId_b, - ); + ]; $result = $this->callAPISuccess('relationship', 'get', $params); $this->assertEquals($result['count'], 1); - $params = array( + $params = [ 'contact_id_a' => $this->_cId_a, - ); + ]; $result = $this->callAPISuccess('relationship', 'get', $params); $this->assertEquals($result['count'], 1); // contact_id_a is wrong so should be no matches - $params = array( + $params = [ 'contact_id_a' => $this->_cId_b, - ); + ]; $result = $this->callAPISuccess('relationship', 'get', $params); $this->assertEquals($result['count'], 0); } @@ -761,13 +761,13 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $id = $createResult['id']; // Try to retrieve it using chaining. - $params = array( + $params = [ 'relationship_type_id' => $this->_relTypeID, 'id' => $id, - 'api.Contact.get' => array( + 'api.Contact.get' => [ 'id' => '$value.contact_id_b', - ), - ); + ], + ]; $result = $this->callAPISuccess('relationship', 'get', $params); @@ -789,16 +789,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->callAPISuccess('relationship', 'create', $this->_params); // Try to retrieve it using chaining. - $params = array( + $params = [ 'id' => $this->_cId_a, - 'api.Relationship.get' => array( + 'api.Relationship.get' => [ 'relationship_type_id' => $this->_relTypeID, 'contact_id_a' => '$value.id', - 'api.Contact.get' => array( + 'api.Contact.get' => [ 'id' => '$value.contact_id_b', - ), - ), - ); + ], + ], + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals(1, $result['count']); @@ -818,21 +818,21 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testRelationshipsGetGeneric($version) { $this->_apiversion = $version; - $relParams = array( + $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, - ); + ]; $this->callAPISuccess('relationship', 'create', $relParams); //get relationship - $params = array( + $params = [ 'contact_id_b' => $this->_cId_b, - ); + ]; $this->callAPISuccess('relationship', 'get', $params); } @@ -843,13 +843,13 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testGetIsCurrent($version) { $this->_apiversion = $version; - $rel2Params = array( + $rel2Params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b2, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 0, - ); + ]; $rel0 = $this->callAPISuccess('relationship', 'create', $rel2Params); $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params); @@ -886,7 +886,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testGetTypeOperators($version) { $this->_apiversion = $version; - $relTypeParams = array( + $relTypeParams = [ 'name_a_b' => 'Relation 3 for delete', 'name_b_a' => 'Relation 6 for delete', 'description' => 'Testing relationship type 2', @@ -894,9 +894,9 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $relationType2 = $this->relationshipTypeCreate($relTypeParams); - $relTypeParams = array( + $relTypeParams = [ 'name_a_b' => 'Relation 8 for delete', 'name_b_a' => 'Relation 9 for delete', 'description' => 'Testing relationship type 7', @@ -904,10 +904,10 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $relationType3 = $this->relationshipTypeCreate($relTypeParams); - $relTypeParams = array( + $relTypeParams = [ 'name_a_b' => 'Relation 6 for delete', 'name_b_a' => 'Relation 88for delete', 'description' => 'Testing relationship type 00', @@ -915,54 +915,54 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $relationType4 = $this->relationshipTypeCreate($relTypeParams); $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params); $rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params, - array('relationship_type_id' => $relationType2))); + ['relationship_type_id' => $relationType2])); $rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params, - array('relationship_type_id' => $relationType3))); + ['relationship_type_id' => $relationType3])); $rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params, - array('relationship_type_id' => $relationType4))); + ['relationship_type_id' => $relationType4])); - $getParams = array( - 'relationship_type_id' => array('IN' => array($relationType2, $relationType3)), - ); + $getParams = [ + 'relationship_type_id' => ['IN' => [$relationType2, $relationType3]], + ]; $description = "Demonstrates use of IN filter."; $subfile = 'INRelationshipType'; $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 2); - $this->AssertEquals(array($rel2['id'], $rel3['id']), array_keys($result['values'])); + $this->AssertEquals([$rel2['id'], $rel3['id']], array_keys($result['values'])); $description = "Demonstrates use of NOT IN filter."; $subfile = 'NotInRelationshipType'; - $getParams = array( - 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3)), - ); + $getParams = [ + 'relationship_type_id' => ['NOT IN' => [$relationType2, $relationType3]], + ]; $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 2); - $this->AssertEquals(array($rel1['id'], $rel4['id']), array_keys($result['values'])); + $this->AssertEquals([$rel1['id'], $rel4['id']], array_keys($result['values'])); $description = "Demonstrates use of BETWEEN filter."; $subfile = 'BetweenRelationshipType'; - $getParams = array( - 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4)), - ); + $getParams = [ + 'relationship_type_id' => ['BETWEEN' => [$relationType2, $relationType4]], + ]; $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 3); - $this->AssertEquals(array($rel2['id'], $rel3['id'], $rel4['id']), array_keys($result['values'])); + $this->AssertEquals([$rel2['id'], $rel3['id'], $rel4['id']], array_keys($result['values'])); $description = "Demonstrates use of Not BETWEEN filter."; $subfile = 'NotBetweenRelationshipType'; - $getParams = array( - 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4)), - ); + $getParams = [ + 'relationship_type_id' => ['NOT BETWEEN' => [$relationType2, $relationType4]], + ]; $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 1); - $this->AssertEquals(array($rel1['id']), array_keys($result['values'])); + $this->AssertEquals([$rel1['id']], array_keys($result['values'])); foreach ([$relationType2, $relationType3, $relationType4] as $id) { $this->callAPISuccess('RelationshipType', 'delete', ['id' => $id]); @@ -973,13 +973,13 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * Check with invalid relationshipType Id. */ public function testRelationshipTypeAddInvalidId() { - $relTypeParams = array( + $relTypeParams = [ 'id' => 'invalid', 'name_a_b' => 'Relation 1 for delete', 'name_b_a' => 'Relation 2 for delete', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', - ); + ]; $this->callAPIFailure('relationship_type', 'create', $relTypeParams, 'id is not a valid integer'); } @@ -988,26 +988,26 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * Check with valid data with contact_b. */ public function testGetRelationshipWithContactB() { - $relParams = array( + $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, - ); + ]; $relationship = $this->callAPISuccess('relationship', 'create', $relParams); - $contacts = array( + $contacts = [ 'contact_id' => $this->_cId_a, - ); + ]; $result = $this->callAPISuccess('relationship', 'get', $contacts); $this->assertGreaterThan(0, $result['count']); - $params = array( + $params = [ 'id' => $relationship['id'], - ); + ]; $this->callAPISuccess('relationship', 'delete', $params); $this->relationshipTypeDelete($this->_relTypeID); } @@ -1016,25 +1016,25 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * Check with valid data with relationshipTypes. */ public function testGetRelationshipWithRelTypes() { - $relParams = array( + $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, - ); + ]; $relationship = $this->callAPISuccess('relationship', 'create', $relParams); - $contact_a = array( + $contact_a = [ 'contact_id' => $this->_cId_a, - ); + ]; $this->callAPISuccess('relationship', 'get', $contact_a); - $params = array( + $params = [ 'id' => $relationship['id'], - ); + ]; $this->callAPISuccess('relationship', 'delete', $params); $this->relationshipTypeDelete($this->_relTypeID); } @@ -1049,17 +1049,17 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testGetRelationshipByTypeReciprocal() { $created = $this->callAPISuccess($this->entity, 'create', $this->_params); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id' => $this->_cId_a, 'relationship_type_id' => $this->_relTypeID, - )); + ]); $this->assertEquals(1, $result['count']); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id' => $this->_cId_a, 'relationship_type_id' => $this->_relTypeID + 1, - )); + ]); $this->assertEquals(0, $result['count']); - $this->callAPISuccess($this->entity, 'delete', array('id' => $created['id'])); + $this->callAPISuccess($this->entity, 'delete', ['id' => $created['id']]); } /** @@ -1073,20 +1073,20 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testGetRelationshipByTypeDAO($version) { $this->_apiversion = $version; - $this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', array('format.only_id' => TRUE) + + $this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', ['format.only_id' => TRUE] + $this->_params); - $this->callAPISuccess($this->entity, 'getcount', array( + $this->callAPISuccess($this->entity, 'getcount', [ 'contact_id_a' => $this->_cId_a, - ), 1); - $result = $this->callAPISuccess($this->entity, 'get', array( + ], 1); + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id_a' => $this->_cId_a, 'relationship_type_id' => $this->_relTypeID, - )); + ]); $this->assertEquals(1, $result['count']); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id_a' => $this->_cId_a, 'relationship_type_id' => $this->_relTypeID + 1, - )); + ]); $this->assertEquals(0, $result['count']); } @@ -1110,28 +1110,28 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { // Relationship 2. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType2, 'contact_id_b' => $this->_cId_b2, - )) + ]) ); // Relationship 3. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType3, 'contact_id_b' => $org3, - )) + ]) ); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id_a' => $this->_cId_a, - 'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)), - )); + 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]], + ]); $this->assertEquals(2, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3))); + $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3])); } } @@ -1151,28 +1151,28 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { // Relationship 2. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType2, 'contact_id_b' => $this->_cId_b2, - )) + ]) ); // Relationship 3. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType3, 'contact_id_b' => $org3, - )) + ]) ); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id' => $this->_cId_a, - 'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)), - )); + 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]], + ]); $this->assertEquals(2, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3))); + $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3])); } } @@ -1197,44 +1197,44 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { // lets just assume built in ones aren't being messed with! $relType3 = 6; $relType1 = 1; - $memberType = $this->membershipTypeCreate(array( + $memberType = $this->membershipTypeCreate([ 'relationship_type_id' => CRM_Core_DAO::VALUE_SEPARATOR . $relType1 . CRM_Core_DAO::VALUE_SEPARATOR . $relType3 . CRM_Core_DAO::VALUE_SEPARATOR, 'relationship_direction' => CRM_Core_DAO::VALUE_SEPARATOR . 'a_b' . CRM_Core_DAO::VALUE_SEPARATOR . 'b_a' . CRM_Core_DAO::VALUE_SEPARATOR, - )); + ]); // Relationship 2. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType2, 'contact_id_b' => $this->_cId_b2, - )) + ]) ); // Relationship 3. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType3, 'contact_id_b' => $org3, - )) + ]) ); // Relationship 4 with reversal. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType1, 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_a_2, - )) + ]) ); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id_a' => $this->_cId_a, 'membership_type_id' => $memberType, - )); + ]); // although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal $this->assertEquals(1, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], array($relType1))); + $this->assertTrue(in_array($value['relationship_type_id'], [$relType1])); } } @@ -1256,45 +1256,45 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $relType2 = 5; $relType3 = 6; $relType1 = 1; - $memberType = $this->membershipTypeCreate(array( + $memberType = $this->membershipTypeCreate([ 'relationship_type_id' => CRM_Core_DAO::VALUE_SEPARATOR . $relType1 . CRM_Core_DAO::VALUE_SEPARATOR . $relType3 . CRM_Core_DAO::VALUE_SEPARATOR, 'relationship_direction' => CRM_Core_DAO::VALUE_SEPARATOR . 'a_b' . CRM_Core_DAO::VALUE_SEPARATOR . 'b_a' . CRM_Core_DAO::VALUE_SEPARATOR, - )); + ]); // Relationship 2. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType2, 'contact_id_b' => $this->_cId_b2, - )) + ]) ); // Relationship 4. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType3, 'contact_id_b' => $org3, - )) + ]) ); // Relationship 4 with reversal. $this->callAPISuccess($this->entity, 'create', - array_merge($this->_params, array( + array_merge($this->_params, [ 'relationship_type_id' => $relType1, 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_a_2, - )) + ]) ); - $result = $this->callAPISuccess($this->entity, 'get', array( + $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id' => $this->_cId_a, 'membership_type_id' => $memberType, - )); + ]); // Although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal $this->assertEquals(2, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], array($relType1, $relType3))); + $this->assertTrue(in_array($value['relationship_type_id'], [$relType1, $relType3])); } } @@ -1306,8 +1306,8 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function testSetActive($version) { $this->_apiversion = $version; $relationship = $this->callAPISuccess($this->entity, 'create', $this->_params); - $this->callAPISuccess($this->entity, 'create', array('id' => $relationship['id'], 'is_active' => 0)); - $this->callAPISuccess($this->entity, 'create', array('id' => $relationship['id'], 'is_active' => 1)); + $this->callAPISuccess($this->entity, 'create', ['id' => $relationship['id'], 'is_active' => 0]); + $this->callAPISuccess($this->entity, 'create', ['id' => $relationship['id'], 'is_active' => 1]); } /** @@ -1317,7 +1317,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ public function testCreateRelatedMembership($version) { $this->_apiversion = $version; - $relatedMembershipType = $this->callAPISuccess('MembershipType', 'create', array( + $relatedMembershipType = $this->callAPISuccess('MembershipType', 'create', [ 'name' => 'Membership with Related', 'member_of_contact_id' => 1, 'financial_type_id' => 1, @@ -1331,31 +1331,31 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'auto_renew' => 0, 'is_active' => 1, 'domain_id' => CRM_Core_Config::domainID(), - )); - $originalMembership = $this->callAPISuccess('Membership', 'create', array( + ]); + $originalMembership = $this->callAPISuccess('Membership', 'create', [ 'membership_type_id' => $relatedMembershipType['id'], 'contact_id' => $this->_cId_b, - )); - $this->callAPISuccess('Relationship', 'create', array( + ]); + $this->callAPISuccess('Relationship', 'create', [ 'relationship_type_id' => $this->_relTypeID, 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - )); - $contactAMembership = $this->callAPISuccessGetSingle('membership', array('contact_id' => $this->_cId_a)); + ]); + $contactAMembership = $this->callAPISuccessGetSingle('membership', ['contact_id' => $this->_cId_a]); $this->assertEquals($originalMembership['id'], $contactAMembership['owner_membership_id']); // Adding a relationship with a future start date should NOT create a membership - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ 'relationship_type_id' => $this->_relTypeID, 'contact_id_a' => $this->_cId_a_2, 'contact_id_b' => $this->_cId_b, 'start_date' => 'now + 1 week', - )); - $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_cId_a_2), 0); + ]); + $this->callAPISuccessGetCount('membership', ['contact_id' => $this->_cId_a_2], 0); // Deleting the organization should cause the related membership to be deleted. - $this->callAPISuccess('contact', 'delete', array('id' => $this->_cId_b)); - $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_cId_a), 0); + $this->callAPISuccess('contact', 'delete', ['id' => $this->_cId_b]); + $this->callAPISuccessGetCount('membership', ['contact_id' => $this->_cId_a], 0); } } diff --git a/tests/phpunit/api/v3/RelationshipTypeTest.php b/tests/phpunit/api/v3/RelationshipTypeTest.php index adb092df8f..c0b18364ab 100644 --- a/tests/phpunit/api/v3/RelationshipTypeTest.php +++ b/tests/phpunit/api/v3/RelationshipTypeTest.php @@ -71,10 +71,10 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { public function tearDown() { - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_relationship_type', - ); + ]; $this->quickCleanup($tablesToTruncate); } @@ -87,10 +87,10 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function testRelationshipTypeCreateWithoutName($version) { $this->_apiversion = $version; - $relTypeParams = array( + $relTypeParams = [ 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', - ); + ]; $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams); } @@ -101,7 +101,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function testRelationshipTypeCreate($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'name_a_b' => 'Relation 1 for relationship type create', 'name_b_a' => 'Relation 2 for relationship type create', 'contact_type_a' => 'Individual', @@ -109,7 +109,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'is_reserved' => 1, 'is_active' => 1, 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['values'][0]['id']); unset($params['sequential']); @@ -137,12 +137,12 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function testRelationshipTypeDeleteWithoutRequired($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'name_b_a' => 'Relation 2 delete without required', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 0, - ); + ]; $result = $this->callAPIFailure('relationship_type', 'delete', $params); if ($version == 3) { @@ -157,7 +157,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { * Check with incorrect required fields. */ public function testRelationshipTypeDeleteWithIncorrectData() { - $params = array( + $params = [ 'id' => 'abcd', 'name_b_a' => 'Relation 2 delete with incorrect', 'description' => 'Testing relationship type', @@ -165,7 +165,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 0, - ); + ]; $result = $this->callAPIFailure('relationship_type', 'delete', $params, 'id is not a valid integer' ); @@ -180,9 +180,9 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { $this->_apiversion = $version; $id = $this->_relationshipTypeCreate(); // create sample relationship type. - $params = array( + $params = [ 'id' => $id, - ); + ]; $result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__, __FILE__); $this->assertAPIDeleted('relationship_type', $id); } @@ -196,7 +196,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function testRelationshipTypeUpdateEmpty($version) { $this->_apiversion = $version; - $params = array(); + $params = []; $result = $this->callAPIFailure('relationship_type', 'create', $params); $this->assertContains('name_a_b', $result['error_message']); $this->assertContains('name_b_a', $result['error_message']); @@ -212,14 +212,14 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { // create sample relationship type. $this->_relTypeID = $this->_relationshipTypeCreate(); - $relTypeParams = array( + $relTypeParams = [ 'id' => $this->_relTypeID, 'name_a_b' => 'Test 1', 'name_b_a' => 'Test 2', 'description' => 'Testing relationship type', 'is_reserved' => 1, 'is_active' => 0, - ); + ]; $result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams); $this->assertNotNull($result['id']); @@ -237,7 +237,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { // create sample relationship type. $this->_relTypeID = $this->_relationshipTypeCreate(); - $params = array( + $params = [ 'id' => $this->_relTypeID, 'name_a_b' => 'Test 1 for update', 'name_b_a' => 'Test 2 for update', @@ -246,7 +246,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 0, - ); + ]; $result = $this->callAPISuccess('relationship_type', 'create', $params); $this->assertNotNull($result['id']); @@ -264,7 +264,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function testRelationshipTypesGetEmptyParams($version) { $this->_apiversion = $version; - $firstRelTypeParams = array( + $firstRelTypeParams = [ 'name_a_b' => 'Relation 27 for create', 'name_b_a' => 'Relation 28 for create', 'description' => 'Testing relationship type', @@ -272,11 +272,11 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams); - $secondRelTypeParams = array( + $secondRelTypeParams = [ 'name_a_b' => 'Relation 25 for create', 'name_b_a' => 'Relation 26 for create', 'description' => 'Testing relationship type second', @@ -284,9 +284,9 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 0, 'is_active' => 1, - ); + ]; $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams); - $results = $this->callAPISuccess('relationship_type', 'get', array()); + $results = $this->callAPISuccess('relationship_type', 'get', []); $this->assertEquals(2, $results['count']); } @@ -309,7 +309,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function testRelationshipTypesGet($version) { $this->_apiversion = $version; - $firstRelTypeParams = array( + $firstRelTypeParams = [ 'name_a_b' => 'Relation 30 for create', 'name_b_a' => 'Relation 31 for create', 'description' => 'Testing relationship type', @@ -317,11 +317,11 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams); - $secondRelTypeParams = array( + $secondRelTypeParams = [ 'name_a_b' => 'Relation 32 for create', 'name_b_a' => 'Relation 33 for create', 'description' => 'Testing relationship type second', @@ -329,14 +329,14 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 0, 'is_active' => 1, - ); + ]; $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams); - $params = array( + $params = [ 'name_a_b' => 'Relation 32 for create', 'name_b_a' => 'Relation 33 for create', 'description' => 'Testing relationship type second', - ); + ]; $results = $this->callAPISuccess('relationship_type', 'get', $params); $this->assertEquals(1, $results['count'], ' in line ' . __LINE__); @@ -350,7 +350,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ public function _relationshipTypeCreate($params = NULL) { if (!is_array($params) || empty($params)) { - $params = array( + $params = [ 'name_a_b' => 'Relation 1 for create', 'name_b_a' => 'Relation 2 for create', 'description' => 'Testing relationship type', @@ -358,7 +358,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; } return $this->relationshipTypeCreate($params); diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 1c110734fa..47b0359bf3 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -52,13 +52,13 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { } public function testReportTemplate() { - $result = $this->callAPISuccess('ReportTemplate', 'create', array( + $result = $this->callAPISuccess('ReportTemplate', 'create', [ 'label' => 'Example Form', 'description' => 'Longish description of the example form', 'class_name' => 'CRM_Report_Form_Examplez', 'report_url' => 'example/path', 'component' => 'CiviCase', - )); + ]); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $entityId = $result['id']; @@ -71,10 +71,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { WHERE name = "CRM_Report_Form_Examplez"'); // change component to null - $result = $this->callAPISuccess('ReportTemplate', 'create', array( + $result = $this->callAPISuccess('ReportTemplate', 'create', [ 'id' => $entityId, 'component' => '', - )); + ]); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value @@ -85,10 +85,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { AND component_id IS NULL'); // deactivate - $result = $this->callAPISuccess('ReportTemplate', 'create', array( + $result = $this->callAPISuccess('ReportTemplate', 'create', [ 'id' => $entityId, 'is_active' => 0, - )); + ]); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value @@ -98,10 +98,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { WHERE name = "CRM_Report_Form_Examplez"'); // activate - $result = $this->callAPISuccess('ReportTemplate', 'create', array( + $result = $this->callAPISuccess('ReportTemplate', 'create', [ 'id' => $entityId, 'is_active' => 1, - )); + ]); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value @@ -110,9 +110,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez"'); - $result = $this->callAPISuccess('ReportTemplate', 'delete', array( + $result = $this->callAPISuccess('ReportTemplate', 'delete', [ 'id' => $entityId, - )); + ]); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value @@ -130,7 +130,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * @throws \PHPUnit\Framework\IncompleteTestError */ public function testReportTemplateSelectWhere($reportID) { - $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'hookSelectWhere')); + $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'hookSelectWhere']); $result = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $reportID, 'options' => ['metadata' => ['sql']], @@ -195,10 +195,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function testReportTemplateGetRowsContactSummary() { $description = "Retrieve rows from a report template (optionally providing the instance_id)."; - $result = $this->callAPISuccess('report_template', 'getrows', array( + $result = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contact/summary', - 'options' => array('metadata' => array('labels', 'title')), - ), __FUNCTION__, __FILE__, $description, 'Getrows'); + 'options' => ['metadata' => ['labels', 'title']], + ], __FUNCTION__, __FILE__, $description, 'Getrows'); $this->assertEquals('Contact Name', $result['metadata']['labels']['civicrm_contact_sort_name']); //the second part of this test has been commented out because it relied on the db being reset to @@ -224,26 +224,26 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { // Check total rows without distinct global $_REQUEST; $_REQUEST['distinct'] = 0; - $result = $this->callAPIAndDocument('report_template', 'getrows', array( + $result = $this->callAPIAndDocument('report_template', 'getrows', [ 'report_id' => 'Mailing/opened', - 'options' => array('metadata' => array('labels', 'title')), - ), __FUNCTION__, __FILE__, $description, 'Getrows'); + 'options' => ['metadata' => ['labels', 'title']], + ], __FUNCTION__, __FILE__, $description, 'Getrows'); $this->assertEquals(14, $result['count']); // Check total rows with distinct $_REQUEST['distinct'] = 1; - $result = $this->callAPIAndDocument('report_template', 'getrows', array( + $result = $this->callAPIAndDocument('report_template', 'getrows', [ 'report_id' => 'Mailing/opened', - 'options' => array('metadata' => array('labels', 'title')), - ), __FUNCTION__, __FILE__, $description, 'Getrows'); + 'options' => ['metadata' => ['labels', 'title']], + ], __FUNCTION__, __FILE__, $description, 'Getrows'); $this->assertEquals(5, $result['count']); // Check total rows with distinct by passing NULL value to distinct parameter $_REQUEST['distinct'] = NULL; - $result = $this->callAPIAndDocument('report_template', 'getrows', array( + $result = $this->callAPIAndDocument('report_template', 'getrows', [ 'report_id' => 'Mailing/opened', - 'options' => array('metadata' => array('labels', 'title')), - ), __FUNCTION__, __FILE__, $description, 'Getrows'); + 'options' => ['metadata' => ['labels', 'title']], + ], __FUNCTION__, __FILE__, $description, 'Getrows'); $this->assertEquals(5, $result['count']); } @@ -265,9 +265,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { Civi::settings()->set('logging', 1); } - $this->callAPISuccess('report_template', 'getrows', array( + $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $reportID, - )); + ]); if (substr($reportID, 0, '7') === 'logging') { Civi::settings()->set('logging', 0); } @@ -282,13 +282,13 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { Civi::settings()->set('logging', 1); $group1 = $this->customGroupCreate(); $group2 = $this->customGroupCreate(['name' => 'second_one', 'title' => 'second one', 'table_name' => 'civicrm_value_second_one']); - $this->customFieldCreate(array('custom_group_id' => $group1['id'], 'label' => 'field one')); - $this->customFieldCreate(array('custom_group_id' => $group2['id'], 'label' => 'field two')); - $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'alterLogTablesRemoveCustom')); + $this->customFieldCreate(['custom_group_id' => $group1['id'], 'label' => 'field one']); + $this->customFieldCreate(['custom_group_id' => $group2['id'], 'label' => 'field two']); + $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'alterLogTablesRemoveCustom']); - $this->callAPISuccess('report_template', 'getrows', array( + $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'logging/contact/summary', - )); + ]); Civi::settings()->set('logging', 0); $this->customGroupDelete($group1['id']); $this->customGroupDelete($group2['id']); @@ -318,10 +318,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { if (stristr($reportID, 'has existing issues')) { $this->markTestIncomplete($reportID); } - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults')); - $this->callAPISuccess('report_template', 'getrows', array( + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookNoResults']); + $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $reportID, - )); + ]); } /** @@ -337,13 +337,13 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { if (stristr($reportID, 'has existing issues')) { $this->markTestIncomplete($reportID); } - if (in_array($reportID, array('contribute/softcredit', 'contribute/bookkeeping'))) { + if (in_array($reportID, ['contribute/softcredit', 'contribute/bookkeeping'])) { $this->markTestIncomplete($reportID . " has non enotices when calling statistics fn"); } $description = "Get Statistics from a report (note there isn't much data to get in the test DB)."; - $result = $this->callAPIAndDocument('report_template', 'getstatistics', array( + $result = $this->callAPIAndDocument('report_template', 'getstatistics', [ 'report_id' => $reportID, - ), __FUNCTION__, __FILE__, $description, 'Getstatistics', 'getstatistics'); + ], __FUNCTION__, __FILE__, $description, 'Getstatistics', 'getstatistics'); } /** @@ -353,18 +353,18 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * be static so cannot use $this->callAPISuccess */ public static function getReportTemplates() { - $reportsToSkip = array( + $reportsToSkip = [ 'event/income' => 'I do no understand why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120', 'contribute/history' => 'Declaration of CRM_Report_Form_Contribute_History::buildRows() should be compatible with CRM_Report_Form::buildRows($sql, &$rows)', - ); + ]; - $reports = civicrm_api3('report_template', 'get', array('return' => 'value', 'options' => array('limit' => 500))); + $reports = civicrm_api3('report_template', 'get', ['return' => 'value', 'options' => ['limit' => 500]]); foreach ($reports['values'] as $report) { if (empty($reportsToSkip[$report['value']])) { - $reportTemplates[] = array($report['value']); + $reportTemplates[] = [$report['value']]; } else { - $reportTemplates[] = array($report['value'] . " has existing issues : " . $reportsToSkip[$report['value']]); + $reportTemplates[] = [$report['value'] . " has existing issues : " . $reportsToSkip[$report['value']]]; } } @@ -377,7 +377,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * These templates require minimal data config. */ public static function getContributionReportTemplates() { - return array(array('contribute/summary'), array('contribute/detail'), array('contribute/repeat'), array('topDonor' => 'contribute/topDonor')); + return [['contribute/summary'], ['contribute/detail'], ['contribute/repeat'], ['topDonor' => 'contribute/topDonor']]; } /** @@ -386,7 +386,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * These templates require minimal data config. */ public static function getMembershipReportTemplates() { - return array(array('member/detail')); + return [['member/detail']]; } /** @@ -412,14 +412,14 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testLybuntReportWithData() { $inInd = $this->individualCreate(); $outInd = $this->individualCreate(); - $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-03-01')); - $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL)); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-03-01']); + $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]); + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/lybunt', 'yid_value' => 2015, 'yid_op' => 'calendar', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertEquals(1, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); } @@ -427,19 +427,19 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * Test Lybunt report applies ACLs. */ public function testLybuntReportWithDataAndACLFilter() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('administer CiviCRM'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM']; $inInd = $this->individualCreate(); $outInd = $this->individualCreate(); - $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-03-01')); - $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL)); - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults')); - $params = array( + $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-03-01']); + $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookNoResults']); + $params = [ 'report_id' => 'contribute/lybunt', 'yid_value' => 2015, 'yid_op' => 'calendar', - 'options' => array('metadata' => array('sql')), + 'options' => ['metadata' => ['sql']], 'check_permissions' => 1, - ); + ]; $rows = $this->callAPISuccess('report_template', 'getrows', $params); $this->assertEquals(0, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); @@ -453,21 +453,21 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testLybuntReportWithFYData() { $inInd = $this->individualCreate(); $outInd = $this->individualCreate(); - $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-10-01')); - $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL)); - $this->callAPISuccess('Setting', 'create', array('fiscalYearStart' => array('M' => 7, 'd' => 1))); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-10-01']); + $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]); + $this->callAPISuccess('Setting', 'create', ['fiscalYearStart' => ['M' => 7, 'd' => 1]]); + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/lybunt', 'yid_value' => 2015, 'yid_op' => 'fiscal', - 'options' => array('metadata' => array('sql')), - 'order_bys' => array( - array( + 'options' => ['metadata' => ['sql']], + 'order_bys' => [ + [ 'column' => 'first_name', 'order' => 'ASC', - ), - ), - )); + ], + ], + ]); $this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); @@ -492,22 +492,22 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testLybuntReportWithFYDataOrderByLastYearAmount() { $inInd = $this->individualCreate(); $outInd = $this->individualCreate(); - $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-10-01')); - $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL)); - $this->callAPISuccess('Setting', 'create', array('fiscalYearStart' => array('M' => 7, 'd' => 1))); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-10-01']); + $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]); + $this->callAPISuccess('Setting', 'create', ['fiscalYearStart' => ['M' => 7, 'd' => 1]]); + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/lybunt', 'yid_value' => 2015, 'yid_op' => 'fiscal', - 'options' => array('metadata' => array('sql')), - 'fields' => array('first_name'), - 'order_bys' => array( - array( + 'options' => ['metadata' => ['sql']], + 'fields' => ['first_name'], + 'order_bys' => [ + [ 'column' => 'last_year_total_amount', 'order' => 'ASC', - ), - ), - )); + ], + ], + ]); $this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); } @@ -522,12 +522,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function testContributionSummaryWithSmartGroupFilter($template) { $groupID = $this->setUpPopulatedSmartGroup(); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, 'gid_value' => $groupID, 'gid_op' => 'in', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertNumberOfContactsInResult(3, $rows, $template); if ($template === 'contribute/summary') { $this->assertEquals(3, $rows['values'][0]['civicrm_contribution_total_amount_count']); @@ -541,12 +541,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function testContributionSummaryWithNotINSmartGroupFilter($template) { $groupID = $this->setUpPopulatedSmartGroup(); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/summary', 'gid_value' => $groupID, 'gid_op' => 'notin', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertEquals(2, $rows['values'][0]['civicrm_contribution_total_amount_count']); } @@ -575,12 +575,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $contactID2 = $this->individualCreate(); $this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]); $template = 'contribute/detail'; - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, 'contribution_or_soft_value' => 'contributions_only', 'fields' => ['soft_credits' => 1, 'contribution_or_soft' => 1, 'sort_name' => 1], - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertEquals( "Anderson, Anthony $ 5.00", $rows['values'][0]['civicrm_contribution_soft_credits'] @@ -595,7 +595,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $contactID2 = $this->individualCreate(); $this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]); $template = 'contribute/detail'; - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, 'contribution_or_soft_value' => 'soft_credits_only', 'fields' => [ @@ -605,8 +605,8 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'receive_date' => '1', 'total_amount' => '1', ], - 'options' => array('metadata' => ['sql', 'labels']), - )); + 'options' => ['metadata' => ['sql', 'labels']], + ]); foreach (array_keys($rows['metadata']['labels']) as $header) { $this->assertTrue(!empty($rows['values'][0][$header])); } @@ -622,12 +622,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function testReportsWithNonSmartGroupFilter($template) { $groupID = $this->setUpPopulatedGroup(); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, - 'gid_value' => array($groupID), + 'gid_value' => [$groupID], 'gid_op' => 'in', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertNumberOfContactsInResult(1, $rows, $template); } @@ -656,12 +656,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testContributionSummaryWithTwoGroups() { $groupID = $this->setUpPopulatedGroup(); $groupID2 = $this->setUpPopulatedSmartGroup(); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/summary', - 'gid_value' => array($groupID, $groupID2), + 'gid_value' => [$groupID, $groupID2], 'gid_op' => 'in', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertEquals(4, $rows['values'][0]['civicrm_contribution_total_amount_count']); } @@ -671,19 +671,19 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testContributionSummaryWithSingleContactsInTwoGroups() { list($groupID1, $individualID) = $this->setUpPopulatedGroup(TRUE); // create second group and add the individual to it. - $groupID2 = $this->groupCreate(array('name' => uniqid(), 'title' => uniqid())); - $this->callAPISuccess('GroupContact', 'create', array( + $groupID2 = $this->groupCreate(['name' => uniqid(), 'title' => uniqid()]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID2, 'contact_id' => $individualID, 'status' => 'Added', - )); + ]); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/summary', - 'gid_value' => array($groupID1, $groupID2), + 'gid_value' => [$groupID1, $groupID2], 'gid_op' => 'in', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertEquals(1, $rows['count']); } @@ -693,12 +693,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testContributionSummaryWithTwoGroupsWithIntersection() { $groups = $this->setUpIntersectingGroups(); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/summary', 'gid_value' => $groups, 'gid_op' => 'in', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertEquals(7, $rows['values'][0]['civicrm_contribution_total_amount_count']); } @@ -721,25 +721,25 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $householdID = $this->householdCreate(); $individualID = $this->individualCreate(); $individualIDRemoved = $this->individualCreate(); - $groupID = $this->smartGroupCreate(array(), array('name' => uniqid(), 'title' => uniqid())); - $this->callAPISuccess('GroupContact', 'create', array( + $groupID = $this->smartGroupCreate([], ['name' => uniqid(), 'title' => uniqid()]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $individualIDRemoved, 'status' => 'Removed', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $individualID, 'status' => 'Added', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $householdID, 'status' => 'Added', - )); - foreach (array($household1ID, $individual1ID, $householdID, $individualID, $individualIDRemoved) as $contactID) { - $this->contributionCreate(array('contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '')); - $this->contactMembershipCreate(array('contact_id' => $contactID)); + ]); + foreach ([$household1ID, $individual1ID, $householdID, $individualID, $individualIDRemoved] as $contactID) { + $this->contributionCreate(['contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '']); + $this->contactMembershipCreate(['contact_id' => $contactID]); } // Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache. @@ -763,28 +763,28 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $individual1ID = $this->individualCreate(); $individualID = $this->individualCreate(); $individualIDRemoved = $this->individualCreate(); - $groupID = $this->groupCreate(array('name' => uniqid(), 'title' => uniqid())); - $this->callAPISuccess('GroupContact', 'create', array( + $groupID = $this->groupCreate(['name' => uniqid(), 'title' => uniqid()]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $individualIDRemoved, 'status' => 'Removed', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $individualID, 'status' => 'Added', - )); + ]); - foreach (array($individual1ID, $individualID, $individualIDRemoved) as $contactID) { - $this->contributionCreate(array('contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '')); - $this->contactMembershipCreate(array('contact_id' => $contactID)); + foreach ([$individual1ID, $individualID, $individualIDRemoved] as $contactID) { + $this->contributionCreate(['contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '']); + $this->contactMembershipCreate(['contact_id' => $contactID]); } // Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache. CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($groupID); if ($returnAddedContact) { - return array($groupID, $individualID); + return [$groupID, $individualID]; } return $groupID; @@ -800,60 +800,60 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $removedFromBothIndividualID = $this->individualCreate(); $addedToSmartGroupRemovedFromOtherIndividualID = $this->individualCreate(); $removedFromSmartGroupAddedToOtherIndividualID = $this->individualCreate(); - $this->callAPISuccess('GroupContact', 'create', array( + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $addedToBothIndividualID, 'status' => 'Added', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID2, 'contact_id' => $addedToBothIndividualID, 'status' => 'Added', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $removedFromBothIndividualID, 'status' => 'Removed', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID2, 'contact_id' => $removedFromBothIndividualID, 'status' => 'Removed', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID2, 'contact_id' => $addedToSmartGroupRemovedFromOtherIndividualID, 'status' => 'Added', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $addedToSmartGroupRemovedFromOtherIndividualID, 'status' => 'Removed', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID, 'contact_id' => $removedFromSmartGroupAddedToOtherIndividualID, 'status' => 'Added', - )); - $this->callAPISuccess('GroupContact', 'create', array( + ]); + $this->callAPISuccess('GroupContact', 'create', [ 'group_id' => $groupID2, 'contact_id' => $removedFromSmartGroupAddedToOtherIndividualID, 'status' => 'Removed', - )); + ]); - foreach (array( + foreach ([ $addedToBothIndividualID, $removedFromBothIndividualID, $addedToSmartGroupRemovedFromOtherIndividualID, $removedFromSmartGroupAddedToOtherIndividualID, - ) as $contactID) { - $this->contributionCreate(array( + ] as $contactID) { + $this->contributionCreate([ 'contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '', - )); + ]); } - return array($groupID, $groupID2); + return [$groupID, $groupID2]; } /** @@ -862,53 +862,53 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { public function testDeferredRevenueReport() { $indv1 = $this->individualCreate(); $indv2 = $this->individualCreate(); - $params = array( - 'contribution_invoice_settings' => array( + $params = [ + 'contribution_invoice_settings' => [ 'deferred_revenue_enabled' => '1', - ), - ); + ], + ]; $this->callAPISuccess('Setting', 'create', $params); $this->contributionCreate( - array( + [ 'contact_id' => $indv1, 'receive_date' => '2016-10-01', 'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+3 month')), 'financial_type_id' => 2, - ) + ] ); $this->contributionCreate( - array( + [ 'contact_id' => $indv1, 'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+22 month')), 'financial_type_id' => 4, 'trxn_id' => NULL, 'invoice_id' => NULL, - ) + ] ); $this->contributionCreate( - array( + [ 'contact_id' => $indv2, 'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+1 month')), 'financial_type_id' => 4, 'trxn_id' => NULL, 'invoice_id' => NULL, - ) + ] ); $this->contributionCreate( - array( + [ 'contact_id' => $indv2, 'receive_date' => '2016-03-01', 'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+4 month')), 'financial_type_id' => 2, 'trxn_id' => NULL, 'invoice_id' => NULL, - ) + ] ); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => 'contribute/deferredrevenue', - )); + ]); $this->assertEquals(2, $rows['count'], "Report failed to get row count"); - $count = array(2, 1); + $count = [2, 1]; foreach ($rows['values'] as $row) { $this->assertEquals(array_pop($count), count($row['rows']), "Report failed to get row count"); } @@ -944,12 +944,12 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function testReportsWithNoTInSmartGroupFilter($template) { $groupID = $this->setUpPopulatedGroup(); - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, - 'gid_value' => array($groupID), + 'gid_value' => [$groupID], 'gid_op' => 'notin', - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); $this->assertNumberOfContactsInResult(2, $rows, $template); } @@ -1077,7 +1077,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'status_id' => 1, 'activity_type_id' => 'Meeting', 'source_contact_id' => $this->contactIDs[2], - 'target_contact_id' => array($this->contactIDs[0], $this->contactIDs[1]), + 'target_contact_id' => [$this->contactIDs[0], $this->contactIDs[1]], 'assignee_contact_id' => $this->contactIDs[1], ]); } @@ -1090,7 +1090,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $contactID2 = $this->individualCreate(); $this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]); $template = 'contribute/detail'; - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, 'contribution_or_soft_value' => 'contributions_only', 'fields' => [ @@ -1103,8 +1103,8 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'total_amount' => '1', ], 'order_bys' => [['column' => 'sort_name', 'order' => 'ASC', 'section' => '1']], - 'options' => array('metadata' => array('sql')), - )); + 'options' => ['metadata' => ['sql']], + ]); } /** @@ -1210,52 +1210,52 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $pcp2 = CRM_PCP_BAO_PCP::create($pcpParams); // Get soft credit types, with the name column as the key. - $soft_credit_types = CRM_Contribute_BAO_ContributionSoft::buildOptions("soft_credit_type_id", NULL, array("flip" => TRUE, 'labelColumn' => 'name')); + $soft_credit_types = CRM_Contribute_BAO_ContributionSoft::buildOptions("soft_credit_type_id", NULL, ["flip" => TRUE, 'labelColumn' => 'name']); $pcp_soft_credit_type_id = $soft_credit_types['pcp']; // Create two contributions assigned to this contribution page and // assign soft credits appropriately. // FIRST... - $contribution1params = array( + $contribution1params = [ 'contact_id' => $donor1ContactId, 'contribution_page_id' => $contribution_page_id, 'total_amount' => '75.00', - ); + ]; $c1 = $this->contributionCreate($contribution1params); // Now the soft contribution. - $p = array( + $p = [ 'contribution_id' => $c1, 'pcp_id' => $pcp1->id, 'contact_id' => $pcpOwnerContact1Id, 'amount' => 75.00, 'currency' => 'USD', 'soft_credit_type_id' => $pcp_soft_credit_type_id, - ); + ]; $this->callAPISuccess('contribution_soft', 'create', $p); // SECOND... - $contribution2params = array( + $contribution2params = [ 'contact_id' => $donor2ContactId, 'contribution_page_id' => $contribution_page_id, 'total_amount' => '25.00', - ); + ]; $c2 = $this->contributionCreate($contribution2params); // Now the soft contribution. - $p = array( + $p = [ 'contribution_id' => $c2, 'pcp_id' => $pcp1->id, 'contact_id' => $pcpOwnerContact1Id, 'amount' => 25.00, 'currency' => 'USD', 'soft_credit_type_id' => $pcp_soft_credit_type_id, - ); + ]; $this->callAPISuccess('contribution_soft', 'create', $p); // Create one contributions assigned to the second PCP page - $contribution3params = array( + $contribution3params = [ 'contact_id' => $donor3ContactId, 'contribution_page_id' => $contribution_page_id, 'total_amount' => '200.00', - ); + ]; $c3 = $this->contributionCreate($contribution3params); // Now the soft contribution. $p = [ @@ -1269,14 +1269,14 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->callAPISuccess('contribution_soft', 'create', $p); $template = 'contribute/pcp'; - $rows = $this->callAPISuccess('report_template', 'getrows', array( + $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, 'title' => 'My PCP', 'fields' => [ 'amount_1' => '1', 'soft_id' => '1', ], - )); + ]); $values = $rows['values'][0]; $this->assertEquals(100.00, $values['civicrm_contribution_soft_amount_1_sum'], "Total commited should be $100"); $this->assertEquals(2, $values['civicrm_contribution_soft_soft_id_count'], "Total donors should be 2"); diff --git a/tests/phpunit/api/v3/SavedSearchTest.php b/tests/phpunit/api/v3/SavedSearchTest.php index 3f3cd92d33..1bf99e4f61 100644 --- a/tests/phpunit/api/v3/SavedSearchTest.php +++ b/tests/phpunit/api/v3/SavedSearchTest.php @@ -59,13 +59,13 @@ class api_v3_SavedSearchTest extends CiviUnitTestCase { // params for saved search that returns all volunteers for the // default organization. - $this->params = array( - 'form_values' => array( + $this->params = [ + 'form_values' => [ // Is volunteer for 'relation_type_id' => '6_a_b', 'relation_target_name' => 'Default Organization', - ), - ); + ], + ]; } /** @@ -101,7 +101,7 @@ class api_v3_SavedSearchTest extends CiviUnitTestCase { // Act: $get_result = $this->callAPIAndDocument( - $this->_entity, 'get', array('id' => $create_result['id']), __FUNCTION__, __FILE__); + $this->_entity, 'get', ['id' => $create_result['id']], __FUNCTION__, __FILE__); // Assert: $this->assertEquals(1, $get_result['count']); @@ -120,24 +120,24 @@ class api_v3_SavedSearchTest extends CiviUnitTestCase { public function testCreateSavedSearchWithSmartGroup() { // First create a volunteer for the default organization - $result = $this->callAPISuccess('Contact', 'create', array( + $result = $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'Joe', 'last_name' => 'Schmoe', 'contact_type' => 'Individual', - 'api.Relationship.create' => array( + 'api.Relationship.create' => [ 'contact_id_a' => '$value.id', // default organization: 'contact_id_b' => 1, // volunteer relationship: 'relationship_type_id' => 6, 'is_active' => 1, - ), - )); + ], + ]); $contact_id = $result['id']; // Now create our saved search, and chain the creation of a smart group. $params = $this->params; - $params['api.Group.create'] = array( + $params['api.Group.create'] = [ 'name' => 'my_smartgroup', 'title' => 'my smartgroup', 'description' => 'Volunteers for the default organization', @@ -146,7 +146,7 @@ class api_v3_SavedSearchTest extends CiviUnitTestCase { 'visibility' => 'User and User Admin Only', 'is_hidden' => 0, 'is_reserved' => 0, - ); + ]; $create_result = $this->callAPIAndDocument( $this->_entity, 'create', $params, __FUNCTION__, __FILE__); @@ -156,7 +156,7 @@ class api_v3_SavedSearchTest extends CiviUnitTestCase { // Search for contacts in our new smart group $get_result = $this->callAPISuccess( - 'Contact', 'get', array('group' => $group_id), __FUNCTION__, __FILE__); + 'Contact', 'get', ['group' => $group_id], __FUNCTION__, __FILE__); // Expect our contact to be there. $this->assertEquals(1, $get_result['count']); @@ -166,10 +166,10 @@ class api_v3_SavedSearchTest extends CiviUnitTestCase { public function testDeleteSavedSearch() { // Create saved search, delete it again, and try to get it $create_result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $delete_params = array('id' => $create_result['id']); + $delete_params = ['id' => $create_result['id']]; $this->callAPIAndDocument( $this->_entity, 'delete', $delete_params, __FUNCTION__, __FILE__); - $get_result = $this->callAPISuccess($this->_entity, 'get', array()); + $get_result = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $get_result['count']); } diff --git a/tests/phpunit/api/v3/SelectQueryTest.php b/tests/phpunit/api/v3/SelectQueryTest.php index 6807d9fcd3..620520709c 100644 --- a/tests/phpunit/api/v3/SelectQueryTest.php +++ b/tests/phpunit/api/v3/SelectQueryTest.php @@ -34,38 +34,38 @@ class api_v3_SelectQueryTest extends CiviUnitTestCase { private $hookEntity; - private $hookCondition = array(); + private $hookCondition = []; public function setUp() { parent::setUp(); $this->useTransaction(TRUE); - CRM_Utils_Hook::singleton()->setHook('civicrm_selectWhereClause', array($this, 'hook_civicrm_selectWhereClause')); + CRM_Utils_Hook::singleton()->setHook('civicrm_selectWhereClause', [$this, 'hook_civicrm_selectWhereClause']); } public function testHookPhoneClause() { - $person1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester')); + $person1 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester']); $cid = $person1['id']; for ($number = 1; $number < 6; ++$number) { - $this->callAPISuccess('Phone', 'create', array( + $this->callAPISuccess('Phone', 'create', [ 'contact_id' => $cid, 'phone' => $number, - )); + ]); } $this->hookEntity = 'Phone'; - $this->hookCondition = array( - 'phone' => array('= 3'), - ); - $phone = $this->callAPISuccessGetSingle('Phone', array('contact_id' => $cid, 'check_permissions' => 1)); + $this->hookCondition = [ + 'phone' => ['= 3'], + ]; + $phone = $this->callAPISuccessGetSingle('Phone', ['contact_id' => $cid, 'check_permissions' => 1]); $this->assertEquals(3, $phone['phone']); } public function testHookContactClause() { - $person1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester', 'email' => 'bob@test.er')); - $person2 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Tom', 'last_name' => 'Tester', 'email' => 'tom@test.er')); - $person3 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Tim', 'last_name' => 'Tester', 'email' => 'tim@test.er')); + $person1 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester', 'email' => 'bob@test.er']); + $person2 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Tom', 'last_name' => 'Tester', 'email' => 'tom@test.er']); + $person3 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Tim', 'last_name' => 'Tester', 'email' => 'tim@test.er']); $this->hookEntity = 'Contact'; - $this->hookCondition = array('id' => array('= ' . $person2['id'])); - $email = $this->callAPISuccessGetSingle('Email', array('check_permissions' => 1)); + $this->hookCondition = ['id' => ['= ' . $person2['id']]]; + $email = $this->callAPISuccessGetSingle('Email', ['check_permissions' => 1]); $this->assertEquals($person2['id'], $email['contact_id']); } @@ -75,7 +75,7 @@ class api_v3_SelectQueryTest extends CiviUnitTestCase { public function hook_civicrm_selectWhereClause($entity, &$clauses) { if ($entity == $this->hookEntity) { foreach ($this->hookCondition as $field => $clause) { - $clauses[$field] = array_merge(CRM_Utils_Array::value($field, $clauses, array()), $clause); + $clauses[$field] = array_merge(CRM_Utils_Array::value($field, $clauses, []), $clause); } } } diff --git a/tests/phpunit/api/v3/SettingTest.php b/tests/phpunit/api/v3/SettingTest.php index 62488e7b4d..6e87e20a8e 100644 --- a/tests/phpunit/api/v3/SettingTest.php +++ b/tests/phpunit/api/v3/SettingTest.php @@ -47,10 +47,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $params = array( + $params = [ 'name' => 'Default Domain Name', 'domain_version' => '4.7', - ); + ]; $result = $this->callAPISuccess('domain', 'get', $params); if (empty($result['id'])) { $result = $this->callAPISuccess('domain', 'create', $params); @@ -75,8 +75,8 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function tearDown() { CRM_Utils_Hook::singleton()->reset(); parent::tearDown(); - $this->callAPISuccess('system', 'flush', array()); - $this->quickCleanup(array('civicrm_domain')); + $this->callAPISuccess('system', 'flush', []); + $this->quickCleanup(['civicrm_domain']); } /** @@ -95,13 +95,13 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function testGetFields($version) { $this->_apiversion = $version; $description = 'Demonstrate return from getfields - see subfolder for variants'; - $result = $this->callAPIAndDocument('setting', 'getfields', array(), __FUNCTION__, __FILE__, $description); + $result = $this->callAPIAndDocument('setting', 'getfields', [], __FUNCTION__, __FILE__, $description); $this->assertArrayHasKey('customCSSURL', $result['values']); $description = 'Demonstrate return from getfields'; - $result = $this->callAPISuccess('setting', 'getfields', array()); + $result = $this->callAPISuccess('setting', 'getfields', []); $this->assertArrayHasKey('customCSSURL', $result['values']); - $this->callAPISuccess('system', 'flush', array()); + $this->callAPISuccess('system', 'flush', []); } /** @@ -111,11 +111,11 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetFieldsCaching($version) { $this->_apiversion = $version; - $settingsMetadata = array(); + $settingsMetadata = []; Civi::cache('settings')->set('settingsMetadata_' . \CRM_Core_Config::domainID() . '_', $settingsMetadata); - $result = $this->callAPISuccess('setting', 'getfields', array()); + $result = $this->callAPISuccess('setting', 'getfields', []); $this->assertArrayNotHasKey('customCSSURL', $result['values']); - $this->quickCleanup(array('civicrm_cache')); + $this->quickCleanup(['civicrm_cache']); Civi::cache('settings')->flush(); } @@ -125,7 +125,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetFieldsFilters($version) { $this->_apiversion = $version; - $params = array('name' => 'advanced_search_options'); + $params = ['name' => 'advanced_search_options']; $result = $this->callAPISuccess('setting', 'getfields', $params); $this->assertArrayNotHasKey('customCSSURL', $result['values']); $this->assertArrayHasKey('advanced_search_options', $result['values']); @@ -138,7 +138,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetFieldsGroupFilters($version) { $this->_apiversion = $version; - $params = array('filters' => array('group' => 'multisite')); + $params = ['filters' => ['group' => 'multisite']]; $result = $this->callAPISuccess('setting', 'getfields', $params); $this->assertArrayNotHasKey('customCSSURL', $result['values']); $this->assertArrayHasKey('domain_group_id', $result['values']); @@ -156,15 +156,15 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function testOnChange($version) { $this->_apiversion = $version; global $_testOnChange_hookCalls; - $this->setMockSettingsMetaData(array( - 'onChangeExample' => array( + $this->setMockSettingsMetaData([ + 'onChangeExample' => [ 'group_name' => 'CiviCRM Preferences', 'group' => 'core', 'name' => 'onChangeExample', 'type' => 'Array', 'quick_form_type' => 'Element', 'html_type' => 'advmultiselect', - 'default' => array('CiviEvent', 'CiviContribute'), + 'default' => ['CiviEvent', 'CiviContribute'], 'add' => '4.4', 'title' => 'List of Components', 'is_domain' => '1', @@ -172,29 +172,29 @@ class api_v3_SettingTest extends CiviUnitTestCase { 'description' => NULL, 'help_text' => NULL, // list of callbacks - 'on_change' => array( - array(__CLASS__, '_testOnChange_onChangeExample'), - ), - ), - )); + 'on_change' => [ + [__CLASS__, '_testOnChange_onChangeExample'], + ], + ], + ]); // set initial value - $_testOnChange_hookCalls = array('count' => 0); - $this->callAPISuccess('setting', 'create', array( - 'onChangeExample' => array('First', 'Value'), - )); + $_testOnChange_hookCalls = ['count' => 0]; + $this->callAPISuccess('setting', 'create', [ + 'onChangeExample' => ['First', 'Value'], + ]); $this->assertEquals(1, $_testOnChange_hookCalls['count']); - $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['newValue']); + $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['newValue']); $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); // change value - $_testOnChange_hookCalls = array('count' => 0); - $this->callAPISuccess('setting', 'create', array( - 'onChangeExample' => array('Second', 'Value'), - )); + $_testOnChange_hookCalls = ['count' => 0]; + $this->callAPISuccess('setting', 'create', [ + 'onChangeExample' => ['Second', 'Value'], + ]); $this->assertEquals(1, $_testOnChange_hookCalls['count']); - $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['oldValue']); - $this->assertEquals(array('Second', 'Value'), $_testOnChange_hookCalls['newValue']); + $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['oldValue']); + $this->assertEquals(['Second', 'Value'], $_testOnChange_hookCalls['newValue']); $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); } @@ -221,13 +221,13 @@ class api_v3_SettingTest extends CiviUnitTestCase { $this->_apiversion = $version; $description = "Shows setting a variable for a given domain - if no domain is set current is assumed."; - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'uniq_email_per_site' => 1, - ); + ]; $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__); - $params = array('uniq_email_per_site' => 1); + $params = ['uniq_email_per_site' => 1]; $description = "Shows setting a variable for a current domain."; $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSettingCurrentDomain'); $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); @@ -239,10 +239,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testCreateInvalidSettings($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'invalid_key' => 1, - ); + ]; $result = $this->callAPIFailure('setting', 'create', $params); } @@ -253,15 +253,15 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testCreateInvalidURLSettings($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'userFrameworkResourceURL' => 'dfhkd hfd', - ); + ]; $result = $this->callAPIFailure('setting', 'create', $params); - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'userFrameworkResourceURL' => 'http://blah.com', - ); + ]; $result = $this->callAPISuccess('setting', 'create', $params); } @@ -271,31 +271,31 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testCreateInvalidBooleanSettings($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'track_civimail_replies' => 'dfhkdhfd', - ); + ]; $result = $this->callAPIFailure('setting', 'create', $params); - $params = array('track_civimail_replies' => '0'); + $params = ['track_civimail_replies' => '0']; $result = $this->callAPISuccess('setting', 'create', $params); $getResult = $this->callAPISuccess('setting', 'get'); $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); $getResult = $this->callAPISuccess('setting', 'get'); $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'track_civimail_replies' => '1', - ); + ]; $result = $this->callAPISuccess('setting', 'create', $params); $getResult = $this->callAPISuccess('setting', 'get', ['domain_id' => $this->_domainID2]); $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies']); - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'track_civimail_replies' => 'TRUE', - ); + ]; $result = $this->callAPISuccess('setting', 'create', $params); $getResult = $this->callAPISuccess('setting', 'get', ['domain_id' => $this->_domainID2]); @@ -310,10 +310,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { $this->_apiversion = $version; $description = "Shows setting a variable for all domains."; - $params = array( + $params = [ 'domain_id' => 'all', 'uniq_email_per_site' => 1, - ); + ]; $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateAllDomains'); $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); @@ -321,10 +321,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { $this->assertArrayHasKey(3, $result['values'], 'Domain create probably failed Debug this IF domain test is passing'); $this->assertEquals(1, $result['values'][3]['uniq_email_per_site'], 'failed to set setting for domain 3.'); - $params = array( + $params = [ 'domain_id' => 'all', 'return' => 'uniq_email_per_site', - ); + ]; // we'll check it with a 'get' $description = "Shows getting a variable for all domains."; $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetAllDomains'); @@ -333,19 +333,19 @@ class api_v3_SettingTest extends CiviUnitTestCase { $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); $this->assertEquals(1, $result['values'][3]['uniq_email_per_site']); - $params = array( - 'domain_id' => array(1, 3), + $params = [ + 'domain_id' => [1, 3], 'uniq_email_per_site' => 0, - ); + ]; $description = "Shows setting a variable for specified domains."; $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSpecifiedDomains'); $this->assertEquals(0, $result['values'][3]['uniq_email_per_site']); $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); - $params = array( - 'domain_id' => array(1, 2), - 'return' => array('uniq_email_per_site'), - ); + $params = [ + 'domain_id' => [1, 2], + 'return' => ['uniq_email_per_site'], + ]; $description = "Shows getting a variable for specified domains."; $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSpecifiedDomains'); $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); @@ -359,17 +359,17 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetSetting($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'domain_id' => $this->_domainID2, 'return' => 'uniq_email_per_site', - ); + ]; $description = "Shows get setting a variable for a given domain - if no domain is set current is assumed."; $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__); - $params = array( + $params = [ 'return' => 'uniq_email_per_site', - ); + ]; $description = "Shows getting a variable for a current domain."; $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain'); $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); @@ -382,14 +382,14 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetExtensionSetting($version) { $this->_apiversion = $version; - $this->hookClass->setHook('civicrm_alterSettingsFolders', array($this, 'setExtensionMetadata')); + $this->hookClass->setHook('civicrm_alterSettingsFolders', [$this, 'setExtensionMetadata']); $data = NULL; Civi::cache('settings')->flush(); - $fields = $this->callAPISuccess('setting', 'getfields', array('filters' => array('group_name' => 'Test Settings'))); + $fields = $this->callAPISuccess('setting', 'getfields', ['filters' => ['group_name' => 'Test Settings']]); $this->assertArrayHasKey('test_key', $fields['values']); - $this->callAPISuccess('setting', 'create', array('test_key' => 'keyset')); + $this->callAPISuccess('setting', 'create', ['test_key' => 'keyset']); $this->assertEquals('keyset', Civi::settings()->get('test_key')); - $result = $this->callAPISuccess('setting', 'getvalue', array('name' => 'test_key', 'group' => 'Test Settings')); + $result = $this->callAPISuccess('setting', 'getvalue', ['name' => 'test_key', 'group' => 'Test Settings']); $this->assertEquals('keyset', $result); } @@ -400,10 +400,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetConfigSetting($version) { $this->_apiversion = $version; - $settings = $this->callAPISuccess('setting', 'get', array( + $settings = $this->callAPISuccess('setting', 'get', [ 'name' => 'defaultCurrency', 'sequential' => 1, - )); + ]); $this->assertEquals('USD', $settings['values'][0]['defaultCurrency']); } @@ -414,18 +414,18 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetSetConfigSettingMultipleDomains($version) { $this->_apiversion = $version; - $settings = $this->callAPISuccess('setting', 'create', array( + $settings = $this->callAPISuccess('setting', 'create', [ 'defaultCurrency' => 'USD', 'domain_id' => $this->_currentDomain, - )); - $settings = $this->callAPISuccess('setting', 'create', array( + ]); + $settings = $this->callAPISuccess('setting', 'create', [ 'defaultCurrency' => 'CAD', 'domain_id' => $this->_domainID2, - )); - $settings = $this->callAPISuccess('setting', 'get', array( + ]); + $settings = $this->callAPISuccess('setting', 'get', [ 'return' => 'defaultCurrency', 'domain_id' => 'all', - )); + ]); $this->assertEquals('USD', $settings['values'][$this->_currentDomain]['defaultCurrency']); $this->assertEquals('CAD', $settings['values'][$this->_domainID2]['defaultCurrency'], "second domain (id {$this->_domainID2} ) should be set to CAD. First dom was {$this->_currentDomain} & was USD"); @@ -439,10 +439,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetValueConfigSetting($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'name' => 'monetaryThousandSeparator', 'group' => 'Localization Setting', - ); + ]; $result = $this->callAPISuccess('setting', 'getvalue', $params); $this->assertEquals(',', $result); } @@ -453,10 +453,10 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetValue($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'name' => 'petition_contacts', 'group' => 'Campaign Preferences', - ); + ]; $description = "Demonstrates getvalue action - intended for runtime use as better caching than get."; $result = $this->callAPIAndDocument('setting', 'getvalue', $params, __FUNCTION__, __FILE__, $description); @@ -469,12 +469,12 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function testGetDefaults() { $description = "Gets defaults setting a variable for a given domain - if no domain is set current is assumed."; - $params = array( + $params = [ 'name' => 'address_format', - ); + ]; $result = $this->callAPIAndDocument('setting', 'getdefaults', $params, __FUNCTION__, __FILE__, $description, 'GetDefaults'); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); - $params = array('name' => 'mailing_format'); + $params = ['name' => 'mailing_format']; $result = $this->callAPISuccess('setting', 'getdefaults', $params); $this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']); $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); @@ -487,15 +487,15 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testRevert($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'address_format' => 'xyz', 'mailing_format' => 'bcs', - ); + ]; $result = $this->callAPISuccess('setting', 'create', $params); $this->assertAPISuccess($result, "in line " . __LINE__); - $revertParams = array( + $revertParams = [ 'name' => 'address_format', - ); + ]; $result = $this->callAPISuccess('setting', 'get'); //make sure it's set $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); @@ -504,9 +504,9 @@ class api_v3_SettingTest extends CiviUnitTestCase { //make sure it's reverted $result = $this->callAPISuccess('setting', 'get'); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); - $params = array( - 'return' => array('mailing_format'), - ); + $params = [ + 'return' => ['mailing_format'], + ]; $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's unchanged $this->assertEquals('bcs', $result['values'][CRM_Core_Config::domainID()]['mailing_format']); @@ -517,19 +517,19 @@ class api_v3_SettingTest extends CiviUnitTestCase { * Api3 only. */ public function testRevertAll() { - $params = array( + $params = [ 'address_format' => 'xyz', 'mailing_format' => 'bcs', - ); + ]; $result = $this->callAPISuccess('setting', 'create', $params); - $revertParams = array(); + $revertParams = []; $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's set $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); $this->callAPISuccess('setting', 'revert', $revertParams); //make sure it's reverted - $result = $this->callAPISuccess('setting', 'get', array('group' => 'core')); + $result = $this->callAPISuccess('setting', 'get', ['group' => 'core']); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); $this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']); } @@ -539,24 +539,24 @@ class api_v3_SettingTest extends CiviUnitTestCase { * V3 only - no fill action in v4 */ public function testDefaults() { - $domparams = array( + $domparams = [ 'name' => 'B Team Domain', 'domain_version' => '4.7', - ); + ]; $dom = $this->callAPISuccess('domain', 'create', $domparams); - $params = array( + $params = [ 'domain_id' => 'all', - ); + ]; $result = $this->callAPISuccess('setting', 'get', $params); - $params = array( + $params = [ 'address_format' => 'xyz', 'mailing_format' => 'bcs', 'domain_id' => $this->_domainID2, - ); + ]; $result = $this->callAPISuccess('setting', 'create', $params); - $params = array( + $params = [ 'domain_id' => $dom['id'], - ); + ]; $result = $this->callAPISuccess('setting', 'get', $params); $this->assertAPISuccess($result, "in line " . __LINE__); $this->assertEquals('Unconfirmed', $result['values'][$dom['id']]['tag_unconfirmed']); @@ -585,14 +585,14 @@ class api_v3_SettingTest extends CiviUnitTestCase { global $civicrm_setting; unset($civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['environment']); Civi::service('settings_manager')->useMandatory(); - $params = array( + $params = [ 'environment' => 'Staging', - ); + ]; $result = $this->callAPISuccess('Setting', 'create', $params); - $params = array( + $params = [ 'name' => 'environment', 'group' => 'Developer Preferences', - ); + ]; $result = $this->callAPISuccess('Setting', 'getvalue', $params); $this->assertEquals('Staging', $result); diff --git a/tests/phpunit/api/v3/StateProvinceTest.php b/tests/phpunit/api/v3/StateProvinceTest.php index 17f3cbc931..366704f0f7 100644 --- a/tests/phpunit/api/v3/StateProvinceTest.php +++ b/tests/phpunit/api/v3/StateProvinceTest.php @@ -40,18 +40,18 @@ class api_v3_StateProvinceTest extends CiviUnitTestCase { $this->_apiversion = 3; parent::setUp(); $this->useTransaction(TRUE); - $this->_params = array( + $this->_params = [ 'name' => 'Wessex', 'abbreviation' => 'WEX', 'country_id' => 1226, - ); + ]; } public function testCreateStateProvince() { $result = $this->callAPIAndDocument('StateProvince', 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('StateProvince', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('StateProvince', 'delete', ['id' => $result['id']]); } public function testDeleteStateProvince() { @@ -59,11 +59,11 @@ class api_v3_StateProvinceTest extends CiviUnitTestCase { $create = $this->callAPISuccess('StateProvince', 'create', $this->_params); // Delete - $result = $this->callAPIAndDocument('StateProvince', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('StateProvince', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $get = $this->callAPISuccess('StateProvince', 'get', array( + $get = $this->callAPISuccess('StateProvince', 'get', [ 'id' => $create['id'], - )); + ]); $this->assertEquals(0, $get['count'], 'State/province not successfully deleted'); } @@ -71,14 +71,14 @@ class api_v3_StateProvinceTest extends CiviUnitTestCase { * Test with empty params */ public function testGetEmptyParams() { - $result = $this->callAPISuccess('StateProvince', 'Get', array()); + $result = $this->callAPISuccess('StateProvince', 'Get', []); } /** * Test with wrong params */ public function testGetWrongParams() { - $this->callAPIFailure('StateProvince', 'Get', array('id' => 'abc')); + $this->callAPIFailure('StateProvince', 'Get', ['id' => 'abc']); } /** @@ -86,9 +86,9 @@ class api_v3_StateProvinceTest extends CiviUnitTestCase { */ public function testGet() { $province = $this->callAPISuccess('StateProvince', 'create', $this->_params); - $params = array( + $params = [ 'name' => $this->_params['name'], - ); + ]; $result = $this->callAPIAndDocument('StateProvince', 'Get', $params, __FUNCTION__, __FILE__); $this->assertEquals($province['values'][$province['id']]['name'], $result['values'][$province['id']]['name']); $this->assertEquals($province['values'][$province['id']]['abbreviation'], $result['values'][$province['id']]['abbreviation']); @@ -102,9 +102,9 @@ class api_v3_StateProvinceTest extends CiviUnitTestCase { unset($params['id']); $this->callAPISuccess('StateProvince', 'create', $params); $this->callAPIFailure('StateProvince', 'create', $params); - $check = $this->callAPISuccess('StateProvince', 'getcount', array( + $check = $this->callAPISuccess('StateProvince', 'getcount', [ 'name' => $params['name'], - )); + ]); $this->assertEquals(1, $check); } diff --git a/tests/phpunit/api/v3/StatusPreferenceTest.php b/tests/phpunit/api/v3/StatusPreferenceTest.php index 994f12f230..f76d4d74a3 100644 --- a/tests/phpunit/api/v3/StatusPreferenceTest.php +++ b/tests/phpunit/api/v3/StatusPreferenceTest.php @@ -41,13 +41,13 @@ class api_v3_StatusPreferenceTest extends CiviUnitTestCase { $this->_apiversion = 3; parent::setUp(); $this->useTransaction(TRUE); - $this->_params = array( + $this->_params = [ 'name' => 'test_check', 'domain_id' => 1, 'hush_until' => '20151212', 'ignore_severity' => 4, 'check_info' => NULL, - ); + ]; } public function testCreateStatusPreference() { @@ -57,19 +57,19 @@ class api_v3_StatusPreferenceTest extends CiviUnitTestCase { $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__); $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); - $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]); } public function testDeleteStatusPreference() { // create one $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); - $get = $this->callAPISuccess('StatusPreference', 'get', array( + $get = $this->callAPISuccess('StatusPreference', 'get', [ 'id' => $create['id'], - )); + ]); $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__); } @@ -77,7 +77,7 @@ class api_v3_StatusPreferenceTest extends CiviUnitTestCase { * Test a get with empty params. */ public function testStatusPreferenceGetEmptyParams() { - $result = $this->callAPISuccess('StatusPreference', 'Get', array()); + $result = $this->callAPISuccess('StatusPreference', 'Get', []); } /** @@ -86,9 +86,9 @@ class api_v3_StatusPreferenceTest extends CiviUnitTestCase { public function testStatusPreferenceGet() { $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); $id = $statusPreference['id']; - $params = array( + $params = [ 'id' => $id, - ); + ]; $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__); $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__); $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__); diff --git a/tests/phpunit/api/v3/SurveyRespondantTest.php b/tests/phpunit/api/v3/SurveyRespondantTest.php index 60bf07e4c7..a459909cdd 100644 --- a/tests/phpunit/api/v3/SurveyRespondantTest.php +++ b/tests/phpunit/api/v3/SurveyRespondantTest.php @@ -36,19 +36,19 @@ class api_v3_SurveyRespondantTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->useTransaction(TRUE); - $phoneBankActivity = $this->callAPISuccess('Option_value', 'Get', array('label' => 'PhoneBank', 'sequential' => 1)); + $phoneBankActivity = $this->callAPISuccess('Option_value', 'Get', ['label' => 'PhoneBank', 'sequential' => 1]); $phoneBankActivityTypeID = $phoneBankActivity['values'][0]['value']; - $surveyParams = array( + $surveyParams = [ 'title' => "survey respondent", 'activity_type_id' => $phoneBankActivityTypeID, 'instructions' => "Call people, ask for money", - ); + ]; $survey = $this->callAPISuccess('survey', 'create', $surveyParams); $surveyID = $survey['id']; - $this->params = array( + $this->params = [ 'sequential' => '1', 'survey_id' => $surveyID, - ); + ]; } /** diff --git a/tests/phpunit/api/v3/SurveyTest.php b/tests/phpunit/api/v3/SurveyTest.php index 9ba7369477..0db820ed51 100644 --- a/tests/phpunit/api/v3/SurveyTest.php +++ b/tests/phpunit/api/v3/SurveyTest.php @@ -50,18 +50,18 @@ class api_v3_SurveyTest extends CiviUnitTestCase { public $DBResetRequired = FALSE; public function setUp() { - $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', array( + $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', [ 'label' => 'PhoneBank', 'return' => 'value', - ), 'integer'); + ], 'integer'); $this->useTransaction(); $this->enableCiviCampaign(); - $this->params = array( + $this->params = [ 'title' => "survey title", 'activity_type_id' => $phoneBankActivityTypeID, 'max_number_of_contacts' => 12, 'instructions' => "Call people, ask for money", - ); + ]; parent::setUp(); } @@ -92,8 +92,8 @@ class api_v3_SurveyTest extends CiviUnitTestCase { */ public function testDeleteSurvey() { $entity = $this->createTestEntity(); - $result = $this->callAPIAndDocument('survey', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->entity, 'get', array()); + $result = $this->callAPIAndDocument('survey', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__); + $checkDeleted = $this->callAPISuccess($this->entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } @@ -107,13 +107,13 @@ class api_v3_SurveyTest extends CiviUnitTestCase { public function testGetSurveyChainDelete() { $description = "Demonstrates get + delete in the same call."; $subfile = 'ChainedGetDelete'; - $params = array( + $params = [ 'title' => "survey title", 'api.survey.delete' => 1, - ); + ]; $result = $this->callAPISuccess('survey', 'create', $this->params); $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array())); + $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', [])); } } diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 2e4a415eef..49c9976d54 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -57,7 +57,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * Map custom group entities to civicrm components. * @var array */ - protected static $componentMap = array( + protected static $componentMap = [ 'Contribution' => 'CiviContribute', 'Membership' => 'CiviMember', 'Participant' => 'CiviEvent', @@ -67,7 +67,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'Grant' => 'CiviGrant', 'Campaign' => 'CiviCampaign', 'Survey' => 'CiviCampaign', - ); + ]; /** * Set up function. @@ -82,7 +82,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->enableCiviCampaign(); - $this->toBeImplemented['get'] = array( + $this->toBeImplemented['get'] = [ // CxnApp.get exists but relies on remote data outside our control; QA w/UtilsTest::testBasicArrayGet 'CxnApp', 'Profile', @@ -95,8 +95,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'Setting', 'Payment', 'Logging', - ); - $this->toBeImplemented['create'] = array( + ]; + $this->toBeImplemented['create'] = [ 'Cxn', 'CxnApp', 'SurveyRespondant', @@ -113,8 +113,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { //work fine in local 'SavedSearch', 'Logging', - ); - $this->toBeImplemented['delete'] = array( + ]; + $this->toBeImplemented['delete'] = [ 'Cxn', 'CxnApp', 'MembershipPayment', @@ -126,22 +126,22 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'System', 'Payment', 'Order', - ); - $this->onlyIDNonZeroCount['get'] = array( + ]; + $this->onlyIDNonZeroCount['get'] = [ 'ActivityType', 'Entity', 'Domain', 'Setting', 'User', - ); - $this->deprecatedAPI = array('Location', 'ActivityType', 'SurveyRespondant'); - $this->deletableTestObjects = array(); + ]; + $this->deprecatedAPI = ['Location', 'ActivityType', 'SurveyRespondant']; + $this->deletableTestObjects = []; } public function tearDown() { foreach ($this->deletableTestObjects as $entityName => $entities) { foreach ($entities as $entityID) { - CRM_Core_DAO::deleteTestObjects($entityName, array('id' => $entityID)); + CRM_Core_DAO::deleteTestObjects($entityName, ['id' => $entityID]); } } } @@ -154,26 +154,26 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * * @return array */ - public static function entities($skip = array()) { + public static function entities($skip = []) { // The order of operations in here is screwy. In the case where SYNTAX_CONFORMANCE_ENTITIES is // defined, we should be able to parse+return it immediately. However, some weird dependency // crept into the system where civicrm_api('Entity','get') must be called as part of entities() // (even if its return value is ignored). - $tmp = civicrm_api('Entity', 'Get', array('version' => 3)); + $tmp = civicrm_api('Entity', 'Get', ['version' => 3]); if (getenv('SYNTAX_CONFORMANCE_ENTITIES')) { - $tmp = array( + $tmp = [ 'values' => explode(' ', getenv('SYNTAX_CONFORMANCE_ENTITIES')), - ); + ]; } if (!is_array($skip)) { - $skip = array(); + $skip = []; } $tmp = array_diff($tmp['values'], $skip); - $entities = array(); + $entities = []; foreach ($tmp as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -247,9 +247,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { public static function custom_data_entities() { $entities = CRM_Core_BAO_CustomQuery::$extendsMap; $enabledComponents = Civi::settings()->get('enable_components'); - $customDataEntities = array(); - $invalidEntities = array('Individual', 'Organization', 'Household'); - $entitiesToFix = array('Case', 'Relationship'); + $customDataEntities = []; + $invalidEntities = ['Individual', 'Organization', 'Household']; + $entitiesToFix = ['Case', 'Relationship']; foreach ($entities as $entityName => $entity) { if (!in_array($entityName, $invalidEntities) && !in_array($entityName, $entitiesToFix) @@ -257,7 +257,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { if (!empty(self::$componentMap[$entityName]) && empty($enabledComponents[self::$componentMap[$entityName]])) { CRM_Core_BAO_ConfigSetting::enableComponent(self::$componentMap[$entityName]); } - $customDataEntities[] = array($entityName); + $customDataEntities[] = [$entityName]; } } return $customDataEntities; @@ -280,19 +280,19 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @return array */ public static function toBeSkipped_get($sequential = FALSE) { - $entitiesWithoutGet = array( + $entitiesWithoutGet = [ 'MailingEventSubscribe', 'MailingEventConfirm', 'MailingEventResubscribe', 'MailingEventUnsubscribe', 'Location', - ); + ]; if ($sequential === TRUE) { return $entitiesWithoutGet; } - $entities = array(); + $entities = []; foreach ($entitiesWithoutGet as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -315,7 +315,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * Entities that cannot be retrieved by ID */ public static function toBeSkipped_getByID($sequential = FALSE) { - return array('MailingContact', 'User', 'Attachment', 'Entity'); + return ['MailingContact', 'User', 'Attachment', 'Entity']; } /** @@ -324,13 +324,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @return array */ public static function toBeSkipped_create($sequential = FALSE) { - $entitiesWithoutCreate = array('Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients'); + $entitiesWithoutCreate = ['Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients']; if ($sequential === TRUE) { return $entitiesWithoutCreate; } - $entities = array(); + $entities = []; foreach ($entitiesWithoutCreate as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -341,7 +341,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @return array */ public static function toBeSkipped_delete($sequential = FALSE) { - $entitiesWithout = array( + $entitiesWithout = [ 'MailingContact', 'MailingEventConfirm', 'MailingEventResubscribe', @@ -357,13 +357,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'Setting', 'User', 'Logging', - ); + ]; if ($sequential === TRUE) { return $entitiesWithout; } - $entities = array(); + $entities = []; foreach ($entitiesWithout as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -374,7 +374,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @return array */ public static function toBeSkipped_custom_data_creatable($sequential = FALSE) { - $entitiesWithout = array( + $entitiesWithout = [ // Ones to fix. 'CaseContact', 'CustomField', @@ -421,13 +421,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'Order', 'MailingGroup', 'Logging', - ); + ]; if ($sequential === TRUE) { return $entitiesWithout; } - $entities = array(); + $entities = []; foreach ($entitiesWithout as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -439,13 +439,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @todo add metadata for ALL these entities */ public static function toBeSkipped_getfields($sequential = FALSE) { - $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch'); + $entitiesWithMetadataNotYetFixed = ['ReportTemplate', 'CustomSearch']; if ($sequential === TRUE) { return $entitiesWithMetadataNotYetFixed; } - $entities = array(); + $entities = []; foreach ($entitiesWithMetadataNotYetFixed as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -457,7 +457,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * Entities to be skipped */ public static function toBeSkipped_automock($sequential = FALSE) { - $entitiesWithoutGet = array( + $entitiesWithoutGet = [ 'MailingContact', 'EntityTag', 'Participant', @@ -469,13 +469,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'ReportTemplate', 'System', 'Logging', - ); + ]; if ($sequential === TRUE) { return $entitiesWithoutGet; } - $entities = array(); + $entities = []; foreach ($entitiesWithoutGet as $e) { - $entities[] = array($e); + $entities[] = [$e]; } return $entities; } @@ -486,7 +486,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @return array */ public static function toBeSkipped_updatesingle($sequential = FALSE) { - $entitiesWithout = array( + $entitiesWithout = [ 'Attachment', // pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields 'Mailing', @@ -530,17 +530,17 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'SystemLog', //skip this because it doesn't make sense to update logs, 'Logging', - ); + ]; if ($sequential === TRUE) { return $entitiesWithout; } - $entities = array(); + $entities = []; foreach ($entitiesWithout as $e) { - $entities[] = array( + $entities[] = [ $e, - ); + ]; } - return array('pledge'); + return ['pledge']; return $entities; } @@ -548,7 +548,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * At this stage exclude the ones that don't pass & add them as we can troubleshoot them */ public static function toBeSkipped_getlimit() { - $entitiesWithout = array( + $entitiesWithout = [ 'Case', //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id) 'EntityTag', @@ -561,7 +561,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // fails on 5 limit - probably a set up problem 'Setting', //a bit of a pseudoapi - keys by domain - ); + ]; return $entitiesWithout; } @@ -569,7 +569,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * At this stage exclude the ones that don't pass & add them as we can troubleshoot them */ public static function toBeSkipped_getSqlOperators() { - $entitiesWithout = array( + $entitiesWithout = [ //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id) 'Case', // on the todo list! @@ -582,7 +582,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'Note', //a bit of a pseudoapi - keys by domain 'Setting', - ); + ]; return $entitiesWithout; } @@ -594,98 +594,98 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { */ public function getKnownUnworkablesUpdateSingle($entity, $key) { // can't update values are values for which updates don't result in the value being changed - $knownFailures = array( - 'ActionSchedule' => array( - 'cant_update' => array( + $knownFailures = [ + 'ActionSchedule' => [ + 'cant_update' => [ 'group_id', - ), - ), - 'ActivityContact' => array( - 'cant_update' => array( + ], + ], + 'ActivityContact' => [ + 'cant_update' => [ 'activity_id', //we have an FK on activity_id + contact_id + record id so if we don't leave this one distinct we get an FK constraint error - ), - ), - 'Address' => array( - 'cant_update' => array( + ], + ], + 'Address' => [ + 'cant_update' => [ //issues with country id - need to ensure same country 'state_province_id', 'world_region', //creates relationship 'master_id', - ), + ], 'cant_return' => ['street_parsing', 'skip_geocode', 'fix_address'], - ), - 'Batch' => array( - 'cant_update' => array( + ], + 'Batch' => [ + 'cant_update' => [ // believe this field is defined in error 'entity_table', - ), - 'cant_return' => array( + ], + 'cant_return' => [ 'entity_table', - ), - ), - 'CaseType' => array( - 'cant_update' => array( + ], + ], + 'CaseType' => [ + 'cant_update' => [ 'definition', - ), - ), + ], + ], 'Domain' => ['cant_update' => ['domain_version']], - 'MembershipBlock' => array( - 'cant_update' => array( + 'MembershipBlock' => [ + 'cant_update' => [ // The fake/auto-generated values leave us unable to properly cleanup fake data 'entity_type', 'entity_id', - ), - ), + ], + ], 'MailingJob' => ['cant_update' => ['parent_id']], - 'ContributionSoft' => array( - 'cant_update' => array( + 'ContributionSoft' => [ + 'cant_update' => [ // can't be changed through api 'pcp_id', - ), - ), - 'Email' => array( - 'cant_update' => array( + ], + ], + 'Email' => [ + 'cant_update' => [ // This is being legitimately manipulated to always have a valid primary - skip. 'is_primary', - ), - ), - 'Navigation' => array( - 'cant_update' => array( + ], + ], + 'Navigation' => [ + 'cant_update' => [ // Weight is deliberately altered when this is changed - skip. 'parent_id', - ), - ), - 'LocationType' => array( - 'cant_update' => array( + ], + ], + 'LocationType' => [ + 'cant_update' => [ // I'm on the fence about whether the test should skip or the behaviour is wrong. // display_name is set to match name if display_name is not provided. It would be more 'normal' // to only calculate a default IF id is not set - but perhaps the current behaviour is kind // of what someone updating the name expects.. 'name', - ), - ), - 'Pledge' => array( - 'cant_update' => array( + ], + ], + 'Pledge' => [ + 'cant_update' => [ 'pledge_original_installment_amount', 'installments', 'original_installment_amount', 'next_pay_date', // can't be changed through API, 'amount', - ), + ], // if these are passed in they are retrieved from the wrong table - 'break_return' => array( + 'break_return' => [ 'honor_contact_id', 'cancel_date', 'contribution_page_id', 'financial_account_id', 'financial_type_id', 'currency', - ), + ], // can't be retrieved from api - 'cant_return' => array( + 'cant_return' => [ //due to uniquename missing 'honor_type_id', 'end_date', @@ -702,41 +702,41 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'pledge_status_id', 'pledge_campaign_id', 'pledge_financial_type_id', - ), - ), - 'PaymentProcessorType' => array( - 'cant_update' => array( + ], + ], + 'PaymentProcessorType' => [ + 'cant_update' => [ 'billing_mode', - ), - 'break_return' => array(), - 'cant_return' => array(), - ), - 'PriceFieldValue' => array( - 'cant_update' => array( + ], + 'break_return' => [], + 'cant_return' => [], + ], + 'PriceFieldValue' => [ + 'cant_update' => [ //won't update as there is no 1 in the same price set 'weight', - ), - ), - 'ReportInstance' => array( + ], + ], + 'ReportInstance' => [ // View mode is part of the navigation which is not retrieved by the api. - 'cant_return' => array('view_mode'), - ), - 'SavedSearch' => array( + 'cant_return' => ['view_mode'], + ], + 'SavedSearch' => [ // I think the fields below are generated based on form_values. - 'cant_update' => array( + 'cant_update' => [ 'search_custom_id', 'where_clause', 'select_tables', 'where_tables', - ), - ), - 'StatusPreference' => array( - 'break_return' => array( + ], + ], + 'StatusPreference' => [ + 'break_return' => [ 'ignore_severity', - ), - ), - 'UFField' => array( - 'cant_update' => array( + ], + ], + 'UFField' => [ + 'cant_update' => [ // These fields get auto-adjusted by the BAO prior to saving 'weight', 'location_type_id', @@ -744,8 +744,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'website_type_id', // Not a real field 'option.autoweight', - ), - 'break_return' => array( + ], + 'break_return' => [ // These fields get auto-adjusted by the BAO prior to saving 'weight', 'field_type', @@ -754,16 +754,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'website_type_id', // Not a real field 'option.autoweight', - ), - ), - 'JobLog' => array( + ], + ], + 'JobLog' => [ // For better or worse triggers override. 'break_return' => ['run_time'], 'cant_update' => ['run_time'], - ), - ); + ], + ]; if (empty($knownFailures[$entity]) || empty($knownFailures[$entity][$key])) { - return array(); + return []; } return $knownFailures[$entity][$key]; } @@ -776,7 +776,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @param $Entity */ public function testNotImplemented_get($Entity) { - $result = civicrm_api($Entity, 'Get', array('version' => 3)); + $result = civicrm_api($Entity, 'Get', ['version' => 3]); $this->assertEquals(1, $result['is_error']); // $this->assertContains("API ($Entity, Get) does not exist", $result['error_message']); $this->assertRegExp('/API (.*) does not exist/', $result['error_message']); @@ -791,7 +791,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { return; } - $result = civicrm_api($Entity, 'getfields', array('version' => 3)); + $result = civicrm_api($Entity, 'getfields', ['version' => 3]); $this->assertTrue(is_array($result['values']), "$Entity ::get fields doesn't return values array in line " . __LINE__); foreach ($result['values'] as $key => $value) { $this->assertTrue(is_array($value), $Entity . "::" . $key . " is not an array in line " . __LINE__); @@ -808,7 +808,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented"); return; } - $result = civicrm_api($Entity, 'Get', array()); + $result = civicrm_api($Entity, 'Get', []); $this->assertEquals(1, $result['is_error']); $this->assertContains("Unknown api version", $result['error_message']); } @@ -838,7 +838,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { if (in_array($Entity, $this->toBeImplemented['get'])) { return; } - $result = civicrm_api($Entity, 'Get', array('version' => 3)); + $result = civicrm_api($Entity, 'Get', ['version' => 3]); // @TODO: list the get that have mandatory params if ($result['is_error']) { $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']); @@ -860,7 +860,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { if ($entityName === 'Note') { $this->markTestIncomplete('Note can not be processed here because of a vagary in the note api, it adds entity_table=contact to the get params when id is not present - which makes sense almost always but kills this test'); } - $this->quickCleanup(array('civicrm_uf_match')); + $this->quickCleanup(['civicrm_uf_match']); // so subsidiary activities are created $this->createLoggedInUser(); @@ -884,16 +884,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { } // We are not passing 'check_permissions' so the the more limited permissions *should* be // ignored but per CRM-17700 there is a history of custom data applying permissions when it shouldn't. - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view my contact'); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view my contact']; $objects = $this->getMockableBAOObjects($entityName, 1); // simple custom field $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $usableName . 'Test.php'); $customFieldName = 'custom_' . $ids['custom_field_id']; - $params = array('id' => $objects[0]->id, 'custom_' . $ids['custom_field_id'] => "custom string"); + $params = ['id' => $objects[0]->id, 'custom_' . $ids['custom_field_id'] => "custom string"]; $result = $this->callAPISuccess($entityName, 'create', $params); $this->assertTrue(isset($result['id']), 'no id on ' . $entityName); - $getParams = array('id' => $result['id'], 'return' => array($customFieldName)); + $getParams = ['id' => $result['id'], 'return' => [$customFieldName]]; $check = $this->callAPISuccess($entityName, 'get', $getParams); $this->assertTrue(!empty($check['values'][$check['id']][$customFieldName]), 'Custom data not present for ' . $entityName); $this->assertEquals("custom string", $check['values'][$check['id']][$customFieldName], 'Custom data not present for ' . $entityName); @@ -914,8 +914,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $this->customFieldDelete($ids2['custom_field_id']); $this->customGroupDelete($ids2['custom_group_id']); - $this->callAPISuccess($entityName, 'delete', array('id' => $result['id'])); - $this->quickCleanup(array('civicrm_uf_match')); + $this->callAPISuccess($entityName, 'delete', ['id' => $result['id']]); + $this->quickCleanup(['civicrm_uf_match']); if (!empty($createdValue)) { $this->callAPISuccess('OptionValue', 'delete', ['id' => $createdValue['id']]); } @@ -939,7 +939,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // we'll fix this once beta1 is released // return; - $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID)); + $result = civicrm_api($Entity, 'Get', ['version' => 3, 'id' => $nonExistantID]); if ($result['is_error']) { // just to get a clearer message in the log @@ -1007,18 +1007,18 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { list($baoObj1, $baoObj2) = $baos; // fetch first by ID - $result = $this->callAPISuccess($entityName, 'get', array( + $result = $this->callAPISuccess($entityName, 'get', [ 'id' => $baoObj1->id, - )); + ]); $this->assertTrue(!empty($result['values'][$baoObj1->id]), 'Should find first object by id'); $this->assertEquals($baoObj1->id, $result['values'][$baoObj1->id]['id'], 'Should find id on first object'); $this->assertEquals(1, count($result['values'])); // fetch second by ID - $result = $this->callAPISuccess($entityName, 'get', array( + $result = $this->callAPISuccess($entityName, 'get', [ 'id' => $baoObj2->id, - )); + ]); $this->assertTrue(!empty($result['values'][$baoObj2->id]), 'Should find second object by id'); $this->assertEquals($baoObj2->id, $result['values'][$baoObj2->id]['id'], 'Should find id on second object'); $this->assertEquals(1, count($result['values'])); @@ -1037,32 +1037,32 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { */ public function testLimit($entityName) { // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount) - $cases = array(); - $cases[] = array( - array('options' => array('limit' => NULL)), + $cases = []; + $cases[] = [ + ['options' => ['limit' => NULL]], 30, 'check that a NULL limit returns unlimited', - ); - $cases[] = array( - array('options' => array('limit' => FALSE)), + ]; + $cases[] = [ + ['options' => ['limit' => FALSE]], 30, 'check that a FALSE limit returns unlimited', - ); - $cases[] = array( - array('options' => array('limit' => 0)), + ]; + $cases[] = [ + ['options' => ['limit' => 0]], 30, 'check that a 0 limit returns unlimited', - ); - $cases[] = array( - array('options' => array('limit' => 5)), + ]; + $cases[] = [ + ['options' => ['limit' => 5]], 5, 'check that a 5 limit returns 5', - ); - $cases[] = array( - array(), + ]; + $cases[] = [ + [], 25, 'check that no limit returns 25', - ); + ]; $baoString = _civicrm_api3_get_BAO($entityName); if (empty($baoString)) { @@ -1071,9 +1071,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { } // make 30 test items -- 30 > 25 (the default limit) - $ids = array(); + $ids = []; for ($i = 0; $i < 30; $i++) { - $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + $baoObj = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']); $ids[] = $baoObj->id; } @@ -1083,13 +1083,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { //non preferred / legacy syntax if (isset($case[0]['options']['limit'])) { - $this->checkLimitAgainstExpected($entityName, array('rowCount' => $case[0]['options']['limit']), $case[1], $case[2]); - $this->checkLimitAgainstExpected($entityName, array('option_limit' => $case[0]['options']['limit']), $case[1], $case[2]); - $this->checkLimitAgainstExpected($entityName, array('option.limit' => $case[0]['options']['limit']), $case[1], $case[2]); + $this->checkLimitAgainstExpected($entityName, ['rowCount' => $case[0]['options']['limit']], $case[1], $case[2]); + $this->checkLimitAgainstExpected($entityName, ['option_limit' => $case[0]['options']['limit']], $case[1], $case[2]); + $this->checkLimitAgainstExpected($entityName, ['option.limit' => $case[0]['options']['limit']], $case[1], $case[2]); } } foreach ($ids as $id) { - CRM_Core_DAO::deleteTestObjects($baoString, array('id' => $id)); + CRM_Core_DAO::deleteTestObjects($baoString, ['id' => $id]); } } @@ -1112,23 +1112,23 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $baoString = _civicrm_api3_get_BAO($entityName); - $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0), 'return' => 'id')); + $entities = $this->callAPISuccess($entityName, 'get', ['options' => ['limit' => 0], 'return' => 'id']); $entities = array_keys($entities['values']); $totalEntities = count($entities); if ($totalEntities < 3) { - $ids = array(); + $ids = []; for ($i = 0; $i < 3 - $totalEntities; $i++) { - $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + $baoObj = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']); $ids[] = $baoObj->id; } $totalEntities = 3; } - $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0))); + $entities = $this->callAPISuccess($entityName, 'get', ['options' => ['limit' => 0]]); $entities = array_keys($entities['values']); $this->assertGreaterThan(2, $totalEntities); - $this->callAPISuccess($entityName, 'getsingle', array('id' => array('IN' => array($entities[0])))); - $this->callAPISuccessGetCount($entityName, array('id' => array('NOT IN' => array($entities[0]))), $totalEntities - 1); - $this->callAPISuccessGetCount($entityName, array('id' => array('>' => $entities[0])), $totalEntities - 1); + $this->callAPISuccess($entityName, 'getsingle', ['id' => ['IN' => [$entities[0]]]]); + $this->callAPISuccessGetCount($entityName, ['id' => ['NOT IN' => [$entities[0]]]], $totalEntities - 1); + $this->callAPISuccessGetCount($entityName, ['id' => ['>' => $entities[0]]], $totalEntities - 1); } /** @@ -1179,28 +1179,28 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $idFieldName = _civicrm_api_get_entity_name_from_camel($entityName) . '_id'; // create entities - $baoObj1 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + $baoObj1 = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']); $this->assertTrue(is_int($baoObj1->id), 'check first id'); $this->deletableTestObjects[$baoString][] = $baoObj1->id; - $baoObj2 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + $baoObj2 = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']); $this->assertTrue(is_int($baoObj2->id), 'check second id'); $this->deletableTestObjects[$baoString][] = $baoObj2->id; // fetch first by ID - $result = civicrm_api($entityName, 'get', array( + $result = civicrm_api($entityName, 'get', [ 'version' => 3, $idFieldName => $baoObj1->id, - )); + ]); $this->assertAPISuccess($result); $this->assertTrue(!empty($result['values'][$baoObj1->id]), 'Should find first object by id'); $this->assertEquals($baoObj1->id, $result['values'][$baoObj1->id]['id'], 'Should find id on first object'); $this->assertEquals(1, count($result['values'])); // fetch second by ID - $result = civicrm_api($entityName, 'get', array( + $result = civicrm_api($entityName, 'get', [ 'version' => 3, $idFieldName => $baoObj2->id, - )); + ]); $this->assertAPISuccess($result); $this->assertTrue(!empty($result['values'][$baoObj2->id]), 'Should find second object by id'); $this->assertEquals($baoObj2->id, $result['values'][$baoObj2->id]['id'], 'Should find id on second object'); @@ -1218,7 +1218,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { return; } - $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID)); + $result = civicrm_api($Entity, 'Get', ['version' => 3, 'id' => $nonExistantID]); // redundant with testAcceptsOnlyID_get if ($result['is_error']) { @@ -1240,7 +1240,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @param $Entity */ public function testNotImplemented_create($Entity) { - $result = civicrm_api($Entity, 'Create', array('version' => 3)); + $result = civicrm_api($Entity, 'Create', ['version' => 3]); $this->assertEquals(1, $result['is_error']); $this->assertContains(strtolower("API ($Entity, Create) does not exist"), strtolower($result['error_message'])); } @@ -1269,11 +1269,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @throws \PHPUnit\Framework\IncompleteTestError */ public function testInvalidSort_get($Entity) { - $invalidEntitys = array('ActivityType', 'Setting', 'System'); + $invalidEntitys = ['ActivityType', 'Setting', 'System']; if (in_array($Entity, $invalidEntitys)) { $this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently sips invalid params'); } - $result = $this->callAPIFailure($Entity, 'get', array('options' => array('sort' => 'sleep(1)'))); + $result = $this->callAPIFailure($Entity, 'get', ['options' => ['sort' => 'sleep(1)']]); } /** @@ -1284,19 +1284,19 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @throws \PHPUnit\Framework\IncompleteTestError */ public function testValidSortSingleArrayById_get($Entity) { - $invalidEntitys = array('ActivityType', 'Setting', 'System'); - $tests = array( + $invalidEntitys = ['ActivityType', 'Setting', 'System']; + $tests = [ 'id' => '_id', 'id desc' => '_id desc', 'id DESC' => '_id DESC', 'id ASC' => '_id ASC', 'id asc' => '_id asc', - ); + ]; foreach ($tests as $test => $expected) { if (in_array($Entity, $invalidEntitys)) { $this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently ignores passed in params'); } - $params = array('sort' => array($test)); + $params = ['sort' => [$test]]; $result = _civicrm_api3_get_options_from_params($params, FALSE, $Entity, 'get'); $lowercase_entity = _civicrm_api_get_entity_name_from_camel($Entity); $this->assertEquals($lowercase_entity . $expected, $result['sort']); @@ -1318,7 +1318,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented"); return; } - $result = $this->callAPIFailure($Entity, 'Create', array('id' => 999)); + $result = $this->callAPIFailure($Entity, 'Create', ['id' => 999]); } /** @@ -1347,9 +1347,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $baoString = _civicrm_api3_get_BAO($entityName); $this->assertNotEmpty($baoString, $entityName); $this->assertNotEmpty($entityName, $entityName); - $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get', 'options' => array('get_options' => 'all'))); + $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', ['action' => 'get', 'options' => ['get_options' => 'all']]); if ($entityName != 'Pledge') { - $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create', 'options' => array('get_options' => 'all'))); + $fields = $this->callAPISuccess($entityName, 'getfields', ['action' => 'create', 'options' => ['get_options' => 'all']]); } $fields = $fields['values']; $return = array_keys($fieldsGet['values']); @@ -1363,16 +1363,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $return = array_diff($return, $valuesNotToReturn); $baoObj = new CRM_Core_DAO(); - $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0); + $baoObj->createTestObject($baoString, ['currency' => 'USD'], 2, 0); - $getEntities = $this->callAPISuccess($entityName, 'get', array( + $getEntities = $this->callAPISuccess($entityName, 'get', [ 'sequential' => 1, 'return' => $return, - 'options' => array( + 'options' => [ 'sort' => 'id DESC', 'limit' => 2, - ), - )); + ], + ]); // lets use first rather than assume only one exists $entity = $getEntities['values'][0]; @@ -1416,7 +1416,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // http://forum.civicrm.org/index.php/topic,33990.0.html // See also my question on the CiviCRM Stack Exchange: // https://civicrm.stackexchange.com/questions/3437 - $entity[$fieldName] = array('sort_name' => "SortName2"); + $entity[$fieldName] = ['sort_name' => "SortName2"]; } else { $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array::Value('maxlength', $specs, 100)); @@ -1424,10 +1424,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $entity[$fieldName] = strtolower($entity[$fieldName]); } // typecast with array to satisfy changes made in CRM-13160 - if ($entityName == 'MembershipType' && in_array($fieldName, array( + if ($entityName == 'MembershipType' && in_array($fieldName, [ 'relationship_type_id', 'relationship_direction', - ))) { + ])) { $entity[$fieldName] = (array) $entity[$fieldName]; } } @@ -1444,7 +1444,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { } else { if (!empty($entity[$fieldName])) { - $resetFKTo = array($fieldName => $entity[$fieldName]); + $resetFKTo = [$fieldName => $entity[$fieldName]]; } $entity[$fieldName] = (string) empty($entity2[$field]) ? '' : $entity2[$field]; //todo - there isn't always something set here - & our checking on unset values is limited @@ -1472,15 +1472,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $entity[$field] = 'warm.beer.com'; } if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) || !empty($specs['options']))) { - $options = CRM_Utils_Array::value('options', $specs, array()); + $options = CRM_Utils_Array::value('options', $specs, []); if (!$options) { //eg. pdf_format id doesn't ship with any if (isset($specs['pseudoconstant']['optionGroupName'])) { - $optionValue = $this->callAPISuccess('option_value', 'create', array( + $optionValue = $this->callAPISuccess('option_value', 'create', [ 'option_group_id' => $specs['pseudoconstant']['optionGroupName'], 'label' => 'new option value', 'sequential' => 1, - )); + ]); $optionValue = $optionValue['values']; $keyColumn = CRM_Utils_Array::value('keyColumn', $specs['pseudoconstant'], 'value'); $options[$optionValue[0][$keyColumn]] = 'new option value'; @@ -1492,17 +1492,17 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // in the weird situation where a field has both an fk and pseudoconstant defined, // e.g. campaign_id field, need to flush caches. // FIXME: Why doesn't creating a campaign clear caches? - civicrm_api3($entityName, 'getfields', array('cache_clear' => 1)); + civicrm_api3($entityName, 'getfields', ['cache_clear' => 1]); } - $updateParams = array( + $updateParams = [ 'id' => $entity['id'], $field => isset($entity[$field]) ? $entity[$field] : NULL, - ); - if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) { + ]; + if (isset($updateParams['financial_type_id']) && in_array($entityName, ['Grant'])) { //api has special handling on these 2 fields for backward compatibility reasons $entity['contribution_type_id'] = $updateParams['financial_type_id']; } - if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) { + if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, ['ContributionRecur'])) { //api has special handling on these 2 fields for backward compatibility reasons $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date']; } @@ -1516,15 +1516,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { } $update = $this->callAPISuccess($entityName, 'create', $updateParams); - $checkParams = array( + $checkParams = [ 'id' => $entity['id'], 'sequential' => 1, 'return' => $return, - 'options' => array( + 'options' => [ 'sort' => 'id DESC', 'limit' => 2, - ), - ); + ], + ]; $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams); if (!empty($specs['serialize']) && !is_array($checkEntity[$field])) { @@ -1532,23 +1532,23 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $entity[$field] = CRM_Core_DAO::serializeField($checkEntity[$field], $specs['serialize']); } - $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array( + $this->assertAPIArrayComparison($entity, $checkEntity, [], "checking if $fieldName was correctly updated\n" . print_r([ 'update-params' => $updateParams, 'update-result' => $update, 'getsingle-params' => $checkParams, 'getsingle-result' => $checkEntity, 'expected entity' => $entity, - ), TRUE)); + ], TRUE)); if ($resetFKTo) { //reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in $entity = array_merge($entity, $resetFKTo); $updateParams = array_merge($updateParams, $resetFKTo); $this->callAPISuccess($entityName, 'create', $updateParams); - if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) { + if (isset($updateParams['financial_type_id']) && in_array($entityName, ['Grant'])) { //api has special handling on these 2 fields for backward compatibility reasons $entity['contribution_type_id'] = $updateParams['financial_type_id']; } - if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) { + if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, ['ContributionRecur'])) { //api has special handling on these 2 fields for backward compatibility reasons $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date']; } @@ -1567,7 +1567,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { */ public function testNotImplemented_delete($Entity) { $nonExistantID = 151416349; - $result = civicrm_api($Entity, 'Delete', array('version' => 3, 'id' => $nonExistantID)); + $result = civicrm_api($Entity, 'Delete', ['version' => 3, 'id' => $nonExistantID]); $this->assertEquals(1, $result['is_error']); $this->assertContains(strtolower("API ($Entity, Delete) does not exist"), strtolower($result['error_message'])); } @@ -1581,7 +1581,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented"); return; } - $result = civicrm_api($Entity, 'Delete', array()); + $result = civicrm_api($Entity, 'Delete', []); $this->assertEquals(1, $result['is_error']); $this->assertContains("Unknown api version", $result['error_message']); } @@ -1592,7 +1592,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @throws \PHPUnit\Framework\IncompleteTestError */ public function testInvalidID_delete($Entity) { - $result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999999)); + $result = $this->callAPIFailure($Entity, 'Delete', ['id' => 999999]); } /** @@ -1624,28 +1624,28 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented"); return; } - $startCount = $this->callAPISuccess($entityName, 'getcount', array()); + $startCount = $this->callAPISuccess($entityName, 'getcount', []); $createcount = 2; $baos = $this->getMockableBAOObjects($entityName, $createcount); list($baoObj1, $baoObj2) = $baos; // make sure exactly 2 exist - $result = $this->callAPISuccess($entityName, 'getcount', array(), + $result = $this->callAPISuccess($entityName, 'getcount', [], $createcount + $startCount ); - $this->callAPISuccess($entityName, 'delete', array('id' => $baoObj2->id)); + $this->callAPISuccess($entityName, 'delete', ['id' => $baoObj2->id]); //make sure 1 less exists now - $result = $this->callAPISuccess($entityName, 'getcount', array(), + $result = $this->callAPISuccess($entityName, 'getcount', [], ($createcount + $startCount) - 1 ); //make sure id #1 exists - $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj1->id), + $result = $this->callAPISuccess($entityName, 'getcount', ['id' => $baoObj1->id], 1 ); //make sure id #2 desn't exist - $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj2->id), + $result = $this->callAPISuccess($entityName, 'getcount', ['id' => $baoObj2->id], 0 ); } @@ -1661,14 +1661,14 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { if (in_array($entity, $entities)) { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $entity . 'Test.php'); } - $actions = $this->callAPISuccess($entity, 'getactions', array()); + $actions = $this->callAPISuccess($entity, 'getactions', []); foreach ($actions['values'] as $action) { if (substr($action, -7) == '_create' || substr($action, -4) == '_get' || substr($action, -7) == '_delete') { //getactions can't distinguish between contribution_page.create & contribution_page.create continue; } - $fields = $this->callAPISuccess($entity, 'getfields', array('action' => $action)); - if (!empty($ids) && in_array($action, array('create', 'get'))) { + $fields = $this->callAPISuccess($entity, 'getfields', ['action' => $action]); + if (!empty($ids) && in_array($action, ['create', 'get'])) { $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $fields['values']); } @@ -1688,7 +1688,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { */ public function getEntitiesSupportingCustomFields() { $entities = self::custom_data_entities_get(); - $returnEntities = array(); + $returnEntities = []; foreach ($entities as $entityArray) { $returnEntities[] = $entityArray[0]; } @@ -1705,13 +1705,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $baoString = _civicrm_api3_get_BAO($entityName); if (empty($baoString)) { $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); - return array(); + return []; } - $baos = array(); + $baos = []; $i = 0; while ($i < $count) { // create entities - $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + $baoObj = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']); $this->assertTrue(is_int($baoObj->id), 'check first id'); $this->deletableTestObjects[$baoString][] = $baoObj->id; $baos[] = $baoObj; @@ -1734,70 +1734,70 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { */ public function testEncodeDecodeConsistency() { // Create example - $createResult = civicrm_api('Event', 'Create', array( + $createResult = civicrm_api('Event', 'Create', [ 'version' => 3, 'title' => 'CiviCRM <> TheRest', 'description' => 'TheRest <> CiviCRM', 'event_type_id' => 1, 'is_public' => 1, 'start_date' => 20081021, - )); + ]); $this->assertAPISuccess($createResult); $eventId = $createResult['id']; $this->assertEquals('CiviCRM <> TheRest', $createResult['values'][$eventId]['title']); $this->assertEquals('TheRest <> CiviCRM', $createResult['values'][$eventId]['description']); // Verify "get" handles decoding in result value - $getByIdResult = civicrm_api('Event', 'Get', array( + $getByIdResult = civicrm_api('Event', 'Get', [ 'version' => 3, 'id' => $eventId, - )); + ]); $this->assertAPISuccess($getByIdResult); $this->assertEquals('CiviCRM <> TheRest', $getByIdResult['values'][$eventId]['title']); $this->assertEquals('TheRest <> CiviCRM', $getByIdResult['values'][$eventId]['description']); // Verify "get" handles encoding in search value - $getByTitleResult = civicrm_api('Event', 'Get', array( + $getByTitleResult = civicrm_api('Event', 'Get', [ 'version' => 3, 'title' => 'CiviCRM <> TheRest', - )); + ]); $this->assertAPISuccess($getByTitleResult); $this->assertEquals('CiviCRM <> TheRest', $getByTitleResult['values'][$eventId]['title']); $this->assertEquals('TheRest <> CiviCRM', $getByTitleResult['values'][$eventId]['description']); // Verify that "getSingle" handles decoding - $getSingleResult = $this->callAPISuccess('Event', 'GetSingle', array( + $getSingleResult = $this->callAPISuccess('Event', 'GetSingle', [ 'id' => $eventId, - )); + ]); $this->assertEquals('CiviCRM <> TheRest', $getSingleResult['title']); $this->assertEquals('TheRest <> CiviCRM', $getSingleResult['description']); // Verify that chaining handles decoding - $chainResult = $this->callAPISuccess('Event', 'Get', array( + $chainResult = $this->callAPISuccess('Event', 'Get', [ 'id' => $eventId, - 'api.event.get' => array(), - )); + 'api.event.get' => [], + ]); $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['title']); $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['description']); $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['api.event.get']['values'][0]['title']); $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['api.event.get']['values'][0]['description']); // Verify that "setvalue" handles encoding for updates - $setValueTitleResult = civicrm_api('Event', 'setvalue', array( + $setValueTitleResult = civicrm_api('Event', 'setvalue', [ 'version' => 3, 'id' => $eventId, 'field' => 'title', 'value' => 'setValueTitle: CiviCRM <> TheRest', - )); + ]); $this->assertAPISuccess($setValueTitleResult); $this->assertEquals('setValueTitle: CiviCRM <> TheRest', $setValueTitleResult['values']['title']); - $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array( + $setValueDescriptionResult = civicrm_api('Event', 'setvalue', [ 'version' => 3, 'id' => $eventId, 'field' => 'description', 'value' => 'setValueDescription: TheRest <> CiviCRM', - )); + ]); //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue $this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']); } @@ -1810,60 +1810,60 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { */ public function testEncodeWrite() { // Create example - $createResult = civicrm_api('Event', 'Create', array( + $createResult = civicrm_api('Event', 'Create', [ 'version' => 3, 'title' => 'createNew: CiviCRM <> TheRest', 'description' => 'createNew: TheRest <> CiviCRM', 'event_type_id' => 1, 'is_public' => 1, 'start_date' => 20081021, - )); + ]); $this->assertAPISuccess($createResult); $eventId = $createResult['id']; - $this->assertDBQuery('createNew: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array( - 1 => array($eventId, 'Integer'), - )); - $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array( - 1 => array($eventId, 'Integer'), - )); + $this->assertDBQuery('createNew: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', [ + 1 => [$eventId, 'Integer'], + ]); + $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', [ + 1 => [$eventId, 'Integer'], + ]); // Verify that "create" handles encoding for updates - $createWithIdResult = civicrm_api('Event', 'Create', array( + $createWithIdResult = civicrm_api('Event', 'Create', [ 'version' => 3, 'id' => $eventId, 'title' => 'createWithId: CiviCRM <> TheRest', 'description' => 'createWithId: TheRest <> CiviCRM', - )); + ]); $this->assertAPISuccess($createWithIdResult); - $this->assertDBQuery('createWithId: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array( - 1 => array($eventId, 'Integer'), - )); - $this->assertDBQuery('createWithId: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array( - 1 => array($eventId, 'Integer'), - )); + $this->assertDBQuery('createWithId: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', [ + 1 => [$eventId, 'Integer'], + ]); + $this->assertDBQuery('createWithId: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', [ + 1 => [$eventId, 'Integer'], + ]); // Verify that "setvalue" handles encoding for updates - $setValueTitleResult = civicrm_api('Event', 'setvalue', array( + $setValueTitleResult = civicrm_api('Event', 'setvalue', [ 'version' => 3, 'id' => $eventId, 'field' => 'title', 'value' => 'setValueTitle: CiviCRM <> TheRest', - )); + ]); $this->assertAPISuccess($setValueTitleResult); - $this->assertDBQuery('setValueTitle: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array( - 1 => array($eventId, 'Integer'), - )); - $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array( + $this->assertDBQuery('setValueTitle: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', [ + 1 => [$eventId, 'Integer'], + ]); + $setValueDescriptionResult = civicrm_api('Event', 'setvalue', [ 'version' => 3, 'id' => $eventId, 'field' => 'description', 'value' => 'setValueDescription: TheRest <> CiviCRM', - )); + ]); //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue $this->assertAPISuccess($setValueDescriptionResult); - $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array( - 1 => array($eventId, 'Integer'), - )); + $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', [ + 1 => [$eventId, 'Integer'], + ]); } } diff --git a/tests/phpunit/api/v3/SystemCheckTest.php b/tests/phpunit/api/v3/SystemCheckTest.php index 7d9efa8639..f2dfc32a81 100644 --- a/tests/phpunit/api/v3/SystemCheckTest.php +++ b/tests/phpunit/api/v3/SystemCheckTest.php @@ -52,7 +52,7 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { */ public function testSystemCheckBasic($version) { $this->_apiversion = $version; - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; @@ -69,19 +69,19 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { */ public function testSystemCheckHushForever($version) { $this->_apiversion = $version; - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 7, - ); + ]; $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__); @@ -95,20 +95,20 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { public function testSystemCheckHushFuture($version) { $this->_apiversion = $version; $tomorrow = new DateTime('tomorrow'); - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 7, 'hush_until' => $tomorrow->format('Y-m-d'), - ); + ]; $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);; @@ -122,20 +122,20 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { public function testSystemCheckHushToday($version) { $this->_apiversion = $version; $today = new DateTime('today'); - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 7, 'hush_until' => $today->format('Y-m-d'), - ); + ]; $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__); @@ -149,20 +149,20 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { public function testSystemCheckHushYesterday($version) { $this->_apiversion = $version; $yesterday = new DateTime('yesterday'); - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 7, 'hush_until' => $yesterday->format('Y-m-d'), - ); + ]; $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__); @@ -175,19 +175,19 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { */ public function testSystemCheckHushAboveSeverity($version) { $this->_apiversion = $version; - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 4, - ); + ]; $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__); @@ -200,10 +200,10 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { */ public function testSystemCheckHushAtSeverity($version) { $this->_apiversion = $version; - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 3, - ); + ]; $this->callAPISuccess('StatusPreference', 'create', $this->_params); $result = $this->callAPISuccess('System', 'check'); foreach ($result['values'] as $check) { @@ -212,7 +212,7 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__); @@ -225,19 +225,19 @@ class api_v3_SystemCheckTest extends CiviUnitTestCase { */ public function testSystemCheckHushBelowSeverity($version) { $this->_apiversion = $version; - $this->_params = array( + $this->_params = [ 'name' => 'checkDefaultMailbox', 'ignore_severity' => 2, - ); + ]; $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); - $result = $this->callAPISuccess('System', 'check', array()); + $result = $this->callAPISuccess('System', 'check', []); foreach ($result['values'] as $check) { if ($check['name'] == 'checkDefaultMailbox') { $testedCheck = $check; break; } else { - $testedCheck = array(); + $testedCheck = []; } } $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__); diff --git a/tests/phpunit/api/v3/SystemTest.php b/tests/phpunit/api/v3/SystemTest.php index 91a12ce2fc..d89af1d913 100644 --- a/tests/phpunit/api/v3/SystemTest.php +++ b/tests/phpunit/api/v3/SystemTest.php @@ -61,7 +61,7 @@ class api_v3_SystemTest extends CiviUnitTestCase { $this->assertEquals('abc', Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH))); - $params = array(); + $params = []; $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush'); $this->assertTrue(NULL === Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH))); @@ -71,11 +71,11 @@ class api_v3_SystemTest extends CiviUnitTestCase { * Test system log function. */ public function testSystemLog() { - $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas')); - $result = $this->callAPISuccess('SystemLog', 'getsingle', array( + $this->callAPISuccess('system', 'log', ['level' => 'info', 'message' => 'We wish you a merry Christmas']); + $result = $this->callAPISuccess('SystemLog', 'getsingle', [ 'sequential' => 1, - 'message' => array('LIKE' => '%Chris%'), - )); + 'message' => ['LIKE' => '%Chris%'], + ]); $this->assertEquals($result['message'], 'We wish you a merry Christmas'); $this->assertEquals($result['level'], 'info'); } @@ -84,17 +84,17 @@ class api_v3_SystemTest extends CiviUnitTestCase { * Test system log function. */ public function testSystemLogNoLevel() { - $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert')); - $result = $this->callAPISuccess('SystemLog', 'getsingle', array( + $this->callAPISuccess('system', 'log', ['message' => 'We wish you a merry Christmas', 'level' => 'alert']); + $result = $this->callAPISuccess('SystemLog', 'getsingle', [ 'sequential' => 1, - 'message' => array('LIKE' => '%Chris%'), - )); + 'message' => ['LIKE' => '%Chris%'], + ]); $this->assertEquals($result['message'], 'We wish you a merry Christmas'); $this->assertEquals($result['level'], 'alert'); } public function testSystemGet() { - $result = $this->callAPISuccess('system', 'get', array()); + $result = $this->callAPISuccess('system', 'get', []); $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']); $this->assertEquals('UnitTests', $result['values'][0]['uf']); } diff --git a/tests/phpunit/api/v3/TagTest.php b/tests/phpunit/api/v3/TagTest.php index b1df9ed2d3..aa1960649f 100644 --- a/tests/phpunit/api/v3/TagTest.php +++ b/tests/phpunit/api/v3/TagTest.php @@ -38,13 +38,13 @@ class api_v3_TagTest extends CiviUnitTestCase { * @var array * @ids array of values to be cleaned up in the tear down */ - protected $ids = array(); + protected $ids = []; /** * Tag id. * * @var int */ - protected $tag = array(); + protected $tag = []; protected $tagID; @@ -64,7 +64,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testGetWrongParams($version) { $this->_apiversion = $version; - $params = array('name' => 'Wrong Tag Name'); + $params = ['name' => 'Wrong Tag Name']; $result = $this->callAPISuccess('tag', 'get', $params); $this->assertEquals(0, $result['count']); } @@ -76,10 +76,10 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testGet($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'id' => $this->tagID, 'name' => $this->tag['name'], - ); + ]; $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($this->tag['description'], $result['values'][$this->tagID]['description']); $this->assertEquals($this->tag['name'], $result['values'][$this->tagID]['name']); @@ -95,11 +95,11 @@ class api_v3_TagTest extends CiviUnitTestCase { $description = "Demonstrates use of Return as an array."; $subfile = "GetReturnArray"; - $params = array( + $params = [ 'id' => $this->tagID, 'name' => $this->tag['name'], - 'return' => array('name'), - ); + 'return' => ['name'], + ]; $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertTrue(empty($result['values'][$this->tagID]['description'])); $this->assertEquals($this->tag['name'], $result['values'][$this->tagID]['name']); @@ -114,7 +114,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testCreateEmptyParams($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('tag', 'create', array(), 'name'); + $result = $this->callAPIFailure('tag', 'create', [], 'name'); } /** @@ -124,11 +124,11 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testCreatePasstagInParams($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'tag' => 10, 'name' => 'New Tag23', 'description' => 'This is description for New Tag 02', - ); + ]; $result = $this->callAPISuccess('tag', 'create', $params); $this->assertEquals(10, $result['id']); } @@ -138,10 +138,10 @@ class api_v3_TagTest extends CiviUnitTestCase { * Skipping v4 because used_for is an array */ public function testCreate() { - $params = array( + $params = [ 'name' => 'Super Heros', 'description' => 'Outside undie-wearers', - ); + ]; $result = $this->callAPIAndDocument('tag', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); $params['used_for'] = 'civicrm_contact'; @@ -156,13 +156,13 @@ class api_v3_TagTest extends CiviUnitTestCase { * Skipping v4 because used_for is an array */ public function testCreateEntitySpecificTag() { - $params = array( + $params = [ 'name' => 'New Tag4', 'description' => 'This is description for New Activity tag', 'used_for' => 'civicrm_activity', - ); + ]; $result = $this->callAPISuccess('tag', 'create', $params); - $this->callAPISuccess('tag', 'get', array()); + $this->callAPISuccess('tag', 'get', []); $this->getAndCheck($params, $result['id'], 'tag', 0, __FUNCTION__ . ' tag first created'); unset($params['used_for']); $params['id'] = $result['id']; @@ -180,7 +180,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testDeleteWithoutTagId($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('tag', 'delete', array()); + $result = $this->callAPIFailure('tag', 'delete', []); } /** @@ -190,9 +190,9 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testTagDeleteOldSyntax($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'tag_id' => $this->tagID, - ); + ]; $result = $this->callAPISuccess('tag', 'delete', $params); unset($this->ids['tag']); } @@ -204,26 +204,26 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testTagDeleteCorrectSyntax($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'id' => $this->tagID, - ); + ]; $result = $this->callAPIAndDocument('tag', 'delete', $params, __FUNCTION__, __FILE__); unset($this->ids['tag']); } public function testTagGetfields() { $description = "Demonstrate use of getfields to interrogate api."; - $params = array('action' => 'create'); + $params = ['action' => 'create']; $result = $this->callAPIAndDocument('tag', 'getfields', $params, __FUNCTION__, __FILE__, $description, NULL); $this->assertEquals('civicrm_contact', $result['values']['used_for']['api.default']); } public function testTagGetList() { $description = "Demonstrates use of api.getlist for autocomplete and quicksearch applications."; - $params = array( + $params = [ 'input' => $this->tag['name'], - 'extra' => array('used_for'), - ); + 'extra' => ['used_for'], + ]; $result = $this->callAPIAndDocument('tag', 'getlist', $params, __FUNCTION__, __FILE__, $description); $this->assertEquals($this->tag['id'], $result['values'][0]['id']); $this->assertEquals($this->tag['description'], $result['values'][0]['description'][0]); diff --git a/tests/phpunit/api/v3/TaxContributionPageTest.php b/tests/phpunit/api/v3/TaxContributionPageTest.php index 80798a2f18..8eb25dc38f 100644 --- a/tests/phpunit/api/v3/TaxContributionPageTest.php +++ b/tests/phpunit/api/v3/TaxContributionPageTest.php @@ -35,13 +35,13 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { protected $financialtypeID; protected $financialAccountId; protected $_entity = 'contribution_page'; - protected $_priceSetParams = array(); + protected $_priceSetParams = []; protected $_paymentProcessorType; - protected $payParams = array(); - protected $paymentProceParams = array(); - protected $settingValue = array(); + protected $payParams = []; + protected $paymentProceParams = []; + protected $settingValue = []; protected $setInvoiceSettings; - protected $_ids = array(); + protected $_ids = []; protected $_individualId; protected $financialAccHalftax; protected $financialtypeHalftax; @@ -55,7 +55,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { $this->_individualId = $this->individualCreate(); $this->_orgId = $this->organizationCreate(NULL); - $this->params = array( + $this->params = [ 'title' => "Test Contribution Page" . substr(sha1(rand()), 0, 7), 'financial_type_id' => 1, 'payment_processor' => 1, @@ -66,9 +66,9 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'pay_later_receipt' => "I will pay later", 'is_monetary' => TRUE, 'is_billing_required' => TRUE, - ); + ]; - $this->_priceSetParams = array( + $this->_priceSetParams = [ 'name' => 'tax_contribution' . substr(sha1(rand()), 0, 7), 'title' => 'contributiontax' . substr(sha1(rand()), 0, 7), 'is_active' => 1, @@ -78,9 +78,9 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'financial_type_id' => 3, 'is_quick_config' => 0, 'is_reserved' => 0, - ); + ]; // Financial Account with 20% tax rate - $financialAccountSetparams = array( + $financialAccountSetparams = [ #[domain_id] => 'name' => 'vat full taxrate account' . substr(sha1(rand()), 0, 7), 'contact_id' => $this->_orgId, @@ -90,29 +90,29 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0, - ); + ]; $financialAccount = $this->callAPISuccess('financial_account', 'create', $financialAccountSetparams); $this->financialAccountId = $financialAccount['id']; // Financial type having 'Sales Tax Account is' with liability financail account - $financialType = array( + $financialType = [ 'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7), 'is_reserved' => 0, 'is_active' => 1, - ); + ]; $priceField = $this->callAPISuccess('financial_type', 'create', $financialType); $this->financialtypeID = $priceField['id']; - $financialRelationParams = array( + $financialRelationParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $this->financialtypeID, 'account_relationship' => 10, 'financial_account_id' => $this->financialAccountId, - ); + ]; $financialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationParams); // Financial type with 5% tax rate - $financialAccHalftax = array( + $financialAccHalftax = [ 'name' => 'vat half taxrate account' . substr(sha1(rand()), 0, 7), 'contact_id' => $this->_orgId, 'financial_account_type_id' => 2, @@ -121,23 +121,23 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0, - ); + ]; $halfFinancialAccount = CRM_Financial_BAO_FinancialAccount::add($financialAccHalftax); $this->halfFinancialAccId = $halfFinancialAccount->id; - $halfFinancialtypeHalftax = array( + $halfFinancialtypeHalftax = [ 'name' => 'grassvariety2' . substr(sha1(rand()), 0, 7), 'is_reserved' => 0, 'is_active' => 1, - ); + ]; $halfFinancialType = CRM_Financial_BAO_FinancialType::add($halfFinancialtypeHalftax); $this->halfFinancialTypeId = $halfFinancialType->id; - $financialRelationHalftax = array( + $financialRelationHalftax = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $this->halfFinancialTypeId, 'account_relationship' => 10, 'financial_account_id' => $this->halfFinancialAccId, - ); + ]; $halfFinancialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax); @@ -145,7 +145,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { $setInvoiceSettings = $this->enableTaxAndInvoicing(); // Payment Processor - $paymentProceParams = array( + $paymentProceParams = [ 'domain_id' => 1, 'name' => 'dummy' . substr(sha1(rand()), 0, 7), 'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'), @@ -159,7 +159,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'billing_mode' => 1, 'is_recur' => 1, 'payment_type' => 1, - ); + ]; $result = $this->callAPISuccess('payment_processor', 'create', $paymentProceParams); $this->_ids['paymentProcessID'] = $result['id']; require_once 'api/v3/examples/PaymentProcessor/Create.php'; @@ -184,29 +184,29 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); if (empty($this->_ids['price_field'])) { - $priceField = $this->callAPISuccess('price_field', 'create', array( + $priceField = $this->callAPISuccess('price_field', 'create', [ 'price_set_id' => $priceSetID, 'label' => 'Goat Breed', 'html_type' => 'Radio', - )); - $this->_ids['price_field'] = array($priceField['id']); + ]); + $this->_ids['price_field'] = [$priceField['id']]; } if (empty($this->_ids['price_field_value'])) { - $this->callAPISuccess('price_field_value', 'create', array( + $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Long Haired Goat', 'amount' => 100, 'financial_type_id' => $this->financialtypeID, - )); - $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( + ]); + $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating Goat', 'amount' => 300, 'financial_type_id' => $this->halfFinancialTypeId, - )); - $this->_ids['price_field_value'] = array($priceFieldValue['id']); + ]); + $this->_ids['price_field_value'] = [$priceFieldValue['id']]; } $this->_ids['contribution_page'] = $contributionPageResult['id']; } @@ -222,7 +222,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { public function testCreateContributionOnline($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); $this->setUpContributionPage(); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => $this->formatMoneyInput(100.00), @@ -233,7 +233,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->_ids['contributionId'] = $contribution['id']; @@ -259,7 +259,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { public function testCreateContributionChainedLineItems($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); $this->setUpContributionPage(); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 400.00, @@ -269,38 +269,38 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipLineItem' => 1, - 'api.line_item.create' => array( - array( + 'api.line_item.create' => [ + [ 'price_field_id' => $this->_ids['price_field'], 'qty' => 1, 'line_total' => '100', 'unit_price' => '100', 'financial_type_id' => $this->financialtypeID, - ), - array( + ], + [ 'price_field_id' => $this->_ids['price_field'], 'qty' => 1, 'line_total' => '300', 'unit_price' => '300', 'financial_type_id' => $this->halfFinancialTypeId, - ), - ), - ); + ], + ], + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params); - $lineItems = $this->callAPISuccess('line_item', 'get', array( + $lineItems = $this->callAPISuccess('line_item', 'get', [ 'entity_id' => $contribution['id'], 'contribution_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + ]); $this->assertEquals(2, $lineItems['count']); } public function testCreateContributionPayLaterOnline() { $this->setUpContributionPage(); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, @@ -311,7 +311,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); @@ -335,7 +335,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { public function testCreateContributionPendingOnline($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); $this->setUpContributionPage(); - $params = array( + $params = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => $this->formatMoneyInput(100.00), @@ -345,7 +345,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 2, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); @@ -367,38 +367,38 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { */ public function testCreateUpdateContributionChangeTotal() { $this->setUpContributionPage(); - $this->contributionParams = array( + $this->contributionParams = [ 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, 'financial_type_id' => $this->financialtypeID, 'source' => 'SSF', 'contribution_status_id' => 1, - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $this->contributionParams); - $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( + $lineItems = $this->callAPISuccess('line_item', 'getvalue', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, 'return' => 'line_total', - )); + ]); $this->assertEquals('100.00', $lineItems); $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); $this->assertEquals('120.00', $trxnAmount); - $newParams = array( + $newParams = [ 'id' => $contribution['id'], // without tax rate i.e Donation 'financial_type_id' => 1, 'total_amount' => '300', - ); + ]; $contribution = $this->callAPISuccess('contribution', 'create', $newParams); - $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( + $lineItems = $this->callAPISuccess('line_item', 'getvalue', [ 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, 'return' => 'line_total', - )); + ]); $this->assertEquals('300.00', $lineItems); $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); @@ -444,60 +444,60 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { * @param $context */ public function _checkFinancialRecords($params, $context) { - $entityParams = array( + $entityParams = [ 'entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution', - ); + ]; if ($context == 'pending') { $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams); $this->assertNull($trxn, 'No Trxn to be created until IPN callback'); return; } $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); - $trxnParams = array( + $trxnParams = [ 'id' => $trxn['financial_trxn_id'], - ); + ]; if ($context != 'online' && $context != 'payLater') { - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 6, 'total_amount' => 120, 'status_id' => 1, - ); + ]; } if ($context == 'online') { - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 12, 'total_amount' => 120, 'status_id' => 1, - ); + ]; } elseif ($context == 'payLater') { - $compareParams = array( + $compareParams = [ 'to_financial_account_id' => 7, 'total_amount' => 120, 'status_id' => 2, - ); + ]; } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams); - $entityParams = array( + $entityParams = [ 'financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item', - ); + ]; $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); - $fitemParams = array( + $fitemParams = [ 'id' => $entityTrxn['entity_id'], - ); - $compareParams = array( + ]; + $compareParams = [ 'amount' => 100, 'status_id' => 1, 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID), - ); + ]; if ($context == 'payLater') { - $compareParams = array( + $compareParams = [ 'amount' => 100, 'status_id' => 3, 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID), - ); + ]; } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams); } @@ -509,13 +509,13 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { public function _getFinancialAccountId($financialTypeId) { $accountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); - $searchParams = array( + $searchParams = [ 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialTypeId, 'account_relationship' => $accountRel, - ); + ]; - $result = array(); + $result = []; CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result); return CRM_Utils_Array::value('financial_account_id', $result); } @@ -527,13 +527,13 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { * on the contribution test class & might be copy and paste....). */ public function testDeleteContribution() { - $contributionID = $this->contributionCreate(array( + $contributionID = $this->contributionCreate([ 'contact_id' => $this->_individualId, 'trxn_id' => 12389, 'financial_type_id' => $this->financialtypeID, 'invoice_id' => 'dfsdf', - )); - $this->callAPISuccess('contribution', 'delete', array('id' => $contributionID)); + ]); + $this->callAPISuccess('contribution', 'delete', ['id' => $contributionID]); } } diff --git a/tests/phpunit/api/v3/UFGroupTest.php b/tests/phpunit/api/v3/UFGroupTest.php index a2f3d0e975..05c8ff7389 100644 --- a/tests/phpunit/api/v3/UFGroupTest.php +++ b/tests/phpunit/api/v3/UFGroupTest.php @@ -48,19 +48,19 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { $this->_groupId = $this->groupCreate(); $this->_contactId = $this->individualCreate(); $this->createLoggedInUser(); - $ufGroup = $this->callAPISuccess('uf_group', 'create', array( + $ufGroup = $this->callAPISuccess('uf_group', 'create', [ 'group_type' => 'Contact', 'help_pre' => 'Profile to Test API', 'title' => 'Test Profile', - )); + ]); $this->_ufGroupId = $ufGroup['id']; - $ufMatch = $this->callAPISuccess('uf_match', 'create', array( + $ufMatch = $this->callAPISuccess('uf_match', 'create', [ 'contact_id' => $this->_contactId, 'uf_id' => 42, 'uf_name' => 'email@mail.com', - )); + ]); $this->_ufMatchId = $ufMatch['id']; - $this->params = array( + $this->params = [ 'add_captcha' => 1, 'add_contact_to_group' => $this->_groupId, 'group' => $this->_groupId, @@ -81,19 +81,19 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { 'notify' => 'admin@example.org', 'post_URL' => 'http://example.org/post', 'title' => 'Test Group', - ); + ]; } public function tearDown() { // Truncate the tables $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); } @@ -103,12 +103,12 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { */ public function testUpdateUFGroup($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'title' => 'Edited Test Profile', 'help_post' => 'Profile Pro help text.', 'is_active' => 1, 'id' => $this->_ufGroupId, - ); + ]; $result = $this->callAPISuccess('uf_group', 'create', $params); foreach ($params as $key => $value) { @@ -143,7 +143,7 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { */ public function testUFGroupCreateWithWrongParams($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group')); + $result = $this->callAPIFailure('uf_group', 'create', ['name' => 'A title-less group']); } /** @@ -152,7 +152,7 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { */ public function testUFGroupUpdate($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'id' => $this->_ufGroupId, 'add_captcha' => 1, 'add_contact_to_group' => $this->_groupId, @@ -174,7 +174,7 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { 'notify' => 'admin@example.org', 'post_URL' => 'http://example.org/post', 'title' => 'Test Group', - ); + ]; $result = $this->callAPISuccess('uf_group', 'create', $params); $params['created_date'] = date('YmdHis', strtotime($params['created_date'])); foreach ($params as $key => $value) { @@ -195,7 +195,7 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { public function testUFGroupGet($version) { $this->_apiversion = $version; $result = $this->callAPISuccess('uf_group', 'create', $this->params); - $params = array('id' => $result['id']); + $params = ['id' => $result['id']]; $result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group']); $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group']); @@ -230,7 +230,7 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { public function testUFGroupDelete($version) { $this->_apiversion = $version; $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params); - $params = array('id' => $ufGroup['id']); + $params = ['id' => $ufGroup['id']]; $this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__); $result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__); diff --git a/tests/phpunit/api/v3/UFJoinTest.php b/tests/phpunit/api/v3/UFJoinTest.php index 712087d00f..3140685fcb 100644 --- a/tests/phpunit/api/v3/UFJoinTest.php +++ b/tests/phpunit/api/v3/UFJoinTest.php @@ -45,13 +45,13 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { parent::setUp(); // Truncate the tables $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml'); } @@ -59,13 +59,13 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { public function tearDown() { // Truncate the tables $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); } @@ -76,20 +76,20 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testFindUFGroupId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, 'weight' => 1, 'uf_group_id' => $this->_ufGroupId, 'is_active' => 1, - ); + ]; $ufJoin = $this->callAPISuccess('uf_join', 'create', $params); - $searchParams = array( + $searchParams = [ 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, - ); + ]; $result = $this->callAPISuccess('uf_join', 'get', $searchParams); foreach ($result['values'] as $key => $value) { @@ -114,13 +114,13 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testUFJoinEditWithoutUFGroupId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, 'weight' => 1, 'is_active' => 1, - ); + ]; $result = $this->callAPIFailure('uf_join', 'create', $params); $this->assertContains('Mandatory', $result['error_message']); $this->assertContains('missing', $result['error_message']); @@ -134,7 +134,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testCreateUFJoin($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, @@ -142,13 +142,13 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'uf_group_id' => $this->_ufGroupId, 'is_active' => 1, 'sequential' => 1, - ); + ]; $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($ufJoin['values'][0]['module'], $params['module']); $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']); $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']); - $params = array( + $params = [ 'id' => $ufJoin['id'], 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', @@ -157,7 +157,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'uf_group_id' => $this->_ufGroupId, 'is_active' => 0, 'sequential' => 1, - ); + ]; $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params); $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']); $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']); @@ -172,7 +172,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testCreateSurveyUFJoin($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => 1, @@ -180,7 +180,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'uf_group_id' => $this->_ufGroupId, 'is_active' => 1, 'sequential' => 1, - ); + ]; $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($ufJoin['values'][0]['module'], $params['module']); $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']); @@ -193,7 +193,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testFindUFJoinEmptyParams($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('uf_join', 'create', array()); + $result = $this->callAPIFailure('uf_join', 'create', []); $this->assertContains('Mandatory', $result['error_message']); $this->assertContains('missing', $result['error_message']); $this->assertContains('module', $result['error_message']); @@ -206,13 +206,13 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testCreateUFJoinWithoutUFGroupId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, 'weight' => 1, 'is_active' => 1, - ); + ]; $result = $this->callAPIFailure('uf_join', 'create', $params); $this->assertContains('Mandatory', $result['error_message']); $this->assertContains('missing', $result['error_message']); @@ -226,21 +226,21 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { */ public function testGetUFJoinId($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, 'weight' => 1, 'uf_group_id' => $this->_ufGroupId, 'is_active' => 1, - ); + ]; $ufJoin = $this->callAPISuccess('uf_join', 'create', $params); - $searchParams = array( + $searchParams = [ 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, 'sequential' => 1, - ); + ]; $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][0]['module'], $params['module']); diff --git a/tests/phpunit/api/v3/UFMatchTest.php b/tests/phpunit/api/v3/UFMatchTest.php index 03e6b820a5..0874df677b 100644 --- a/tests/phpunit/api/v3/UFMatchTest.php +++ b/tests/phpunit/api/v3/UFMatchTest.php @@ -40,40 +40,40 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { protected $_ufGroupId = 11; protected $_ufFieldId; protected $_contactId; - protected $_params = array(); + protected $_params = []; protected function setUp() { parent::setUp(); $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); $this->_contactId = $this->individualCreate(); $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml'); - $this->_params = array( + $this->_params = [ 'contact_id' => $this->_contactId, 'uf_id' => '2', 'uf_name' => 'blahdyblah@gmail.com', 'domain_id' => 1, - ); + ]; } public function tearDown() { // Truncate the tables $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); } @@ -84,9 +84,9 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { */ public function testGetUFMatchID($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'uf_id' => 42, - ); + ]; $result = $this->callAPISuccess('uf_match', 'get', $params); $this->assertEquals($result['values'][$result['id']]['contact_id'], 69); } @@ -108,9 +108,9 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { */ public function testGetUFID($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id' => 69, - ); + ]; $result = $this->callAPIAndDocument('uf_match', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['uf_id'], 42); } @@ -161,28 +161,28 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { // Case A: Enable CMS integration Civi::settings()->set('syncCMSEmail', TRUE); - $this->callAPISuccess('email', 'create', array( + $this->callAPISuccess('email', 'create', [ 'contact_id' => $this->_contactId, 'email' => $email1, 'is_primary' => 1, - )); - $ufName = $this->callAPISuccess('uf_match', 'getvalue', array( + ]); + $ufName = $this->callAPISuccess('uf_match', 'getvalue', [ 'contact_id' => $this->_contactId, 'return' => 'uf_name', - )); + ]); $this->assertEquals($email1, $ufName); // Case B: Disable CMS integration Civi::settings()->set('syncCMSEmail', FALSE); - $this->callAPISuccess('email', 'create', array( + $this->callAPISuccess('email', 'create', [ 'contact_id' => $this->_contactId, 'email' => $email2, 'is_primary' => 1, - )); - $ufName = $this->callAPISuccess('uf_match', 'getvalue', array( + ]); + $ufName = $this->callAPISuccess('uf_match', 'getvalue', [ 'contact_id' => $this->_contactId, 'return' => 'uf_name', - )); + ]); $this->assertNotEquals($email2, $ufName, 'primary email will not match if changed on disabled CMS integration setting'); $this->assertEquals($email1, $ufName); } @@ -194,15 +194,15 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { public function testDelete($version) { $this->_apiversion = $version; $result = $this->callAPISuccess('uf_match', 'create', $this->_params); - $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', array( + $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', [ 'id' => $result['id'], - ))); - $this->callAPISuccess('uf_match', 'delete', array( + ])); + $this->callAPISuccess('uf_match', 'delete', [ 'id' => $result['id'], - )); - $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', array( + ]); + $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', [ 'id' => $result['id'], - ))); + ])); } } diff --git a/tests/phpunit/api/v3/UserTest.php b/tests/phpunit/api/v3/UserTest.php index b8caa31fc9..57be7a3f79 100644 --- a/tests/phpunit/api/v3/UserTest.php +++ b/tests/phpunit/api/v3/UserTest.php @@ -43,10 +43,10 @@ class api_v3_UserTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->contactID = $this->createLoggedInUser(); - $this->params = array( + $this->params = [ 'contact_id' => $this->contactID, 'sequential' => 1, - ); + ]; } public function testUserGet() { @@ -61,7 +61,7 @@ class api_v3_UserTest extends CiviUnitTestCase { * Test retrieval of label metadata. */ public function testGetFields() { - $result = $this->callAPIAndDocument($this->_entity, 'getfields', array('action' => 'get'), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'getfields', ['action' => 'get'], __FUNCTION__, __FILE__); $this->assertArrayKeyExists('name', $result['values']); } diff --git a/tests/phpunit/api/v3/UtilsTest.php b/tests/phpunit/api/v3/UtilsTest.php index 9de6307fb0..e6b3a7947e 100644 --- a/tests/phpunit/api/v3/UtilsTest.php +++ b/tests/phpunit/api/v3/UtilsTest.php @@ -50,34 +50,34 @@ class api_v3_UtilsTest extends CiviUnitTestCase { } public function testAddFormattedParam() { - $values = array('contact_type' => 'Individual'); - $params = array('something' => 1); + $values = ['contact_type' => 'Individual']; + $params = ['something' => 1]; $result = _civicrm_api3_deprecated_add_formatted_param($values, $params); $this->assertTrue($result); } public function testCheckPermissionReturn() { - $check = array('check_permissions' => TRUE); + $check = ['check_permissions' => TRUE]; $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array(); + $config->userPermissionClass->permissions = []; $this->assertFalse($this->runPermissionCheck('contact', 'create', $check), 'empty permissions should not be enough'); - $config->userPermissionClass->permissions = array('access CiviCRM'); + $config->userPermissionClass->permissions = ['access CiviCRM']; $this->assertFalse($this->runPermissionCheck('contact', 'create', $check), 'lacking permissions should not be enough'); - $config->userPermissionClass->permissions = array('add contacts'); + $config->userPermissionClass->permissions = ['add contacts']; $this->assertFalse($this->runPermissionCheck('contact', 'create', $check), 'lacking permissions should not be enough'); - $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts'); + $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts']; $this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'exact permissions should be enough'); - $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts'); + $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts', 'import contacts']; $this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'overfluous permissions should be enough'); } public function testCheckPermissionThrow() { - $check = array('check_permissions' => TRUE); + $check = ['check_permissions' => TRUE]; $config = CRM_Core_Config::singleton(); try { - $config->userPermissionClass->permissions = array('access CiviCRM'); + $config->userPermissionClass->permissions = ['access CiviCRM']; $this->runPermissionCheck('contact', 'create', $check, TRUE); } catch (Exception $e) { @@ -85,16 +85,16 @@ class api_v3_UtilsTest extends CiviUnitTestCase { } $this->assertEquals($message, 'API permission check failed for Contact/create call; insufficient permission: require access CiviCRM and add contacts', 'lacking permissions should throw an exception'); - $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts'); + $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts', 'import contacts']; $this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'overfluous permissions should return true'); } public function testCheckPermissionSkip() { $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array('access CiviCRM'); - $params = array('check_permissions' => TRUE); + $config->userPermissionClass->permissions = ['access CiviCRM']; + $params = ['check_permissions' => TRUE]; $this->assertFalse($this->runPermissionCheck('contact', 'create', $params), 'lacking permissions should not be enough'); - $params = array('check_permissions' => FALSE); + $params = ['check_permissions' => FALSE]; $this->assertTrue($this->runPermissionCheck('contact', 'create', $params), 'permission check should be skippable'); } @@ -135,16 +135,16 @@ class api_v3_UtilsTest extends CiviUnitTestCase { */ public function testVerifyMandatory() { _civicrm_api3_initialize(TRUE); - $params = array( + $params = [ 'entity_table' => 'civicrm_contact', 'note' => '', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => NULL, 'version' => $this->_apiversion, - ); + ]; try { - civicrm_api3_verify_mandatory($params, 'CRM_Core_BAO_Note', array('note', 'subject')); + civicrm_api3_verify_mandatory($params, 'CRM_Core_BAO_Note', ['note', 'subject']); } catch (Exception $expected) { $this->assertEquals('Mandatory key(s) missing from params array: note, subject', $expected->getMessage()); @@ -159,17 +159,17 @@ class api_v3_UtilsTest extends CiviUnitTestCase { */ public function testVerifyOneMandatory() { _civicrm_api3_initialize(TRUE); - $params = array( + $params = [ 'entity_table' => 'civicrm_contact', 'note' => '', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => NULL, 'version' => $this->_apiversion, - ); + ]; try { - civicrm_api3_verify_one_mandatory($params, 'CRM_Core_BAO_Note', array('note', 'subject')); + civicrm_api3_verify_one_mandatory($params, 'CRM_Core_BAO_Note', ['note', 'subject']); } catch (Exception $expected) { $this->assertEquals('Mandatory key(s) missing from params array: one of (note, subject)', $expected->getMessage()); @@ -184,17 +184,17 @@ class api_v3_UtilsTest extends CiviUnitTestCase { */ public function testVerifyOneMandatoryOneSet() { _civicrm_api3_initialize(TRUE); - $params = array( + $params = [ 'version' => 3, 'entity_table' => 'civicrm_contact', 'note' => 'note', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => NULL, - ); + ]; try { - civicrm_api3_verify_one_mandatory($params, NULL, array('note', 'subject')); + civicrm_api3_verify_one_mandatory($params, NULL, ['note', 'subject']); } catch (Exception$expected) { $this->fail('Exception raised when it shouldn\'t have been in line ' . __LINE__); @@ -205,7 +205,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase { * Test GET DAO function returns DAO. */ public function testGetDAO() { - $params = array( + $params = [ 'civicrm_api3_custom_group_get' => 'CRM_Core_DAO_CustomGroup', 'custom_group' => 'CRM_Core_DAO_CustomGroup', 'CustomGroup' => 'CRM_Core_DAO_CustomGroup', @@ -214,7 +214,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase { 'civicrm_api3_pledge_payment_get' => 'CRM_Pledge_DAO_PledgePayment', 'civicrm_api3_website_get' => 'CRM_Core_DAO_Website', 'Membership' => 'CRM_Member_DAO_Membership', - ); + ]; foreach ($params as $input => $expected) { $result = _civicrm_api3_get_DAO($input); $this->assertEquals($expected, $result); @@ -225,7 +225,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase { * Test GET BAO function returns BAO when it exists. */ public function testGetBAO() { - $params = array( + $params = [ 'civicrm_api3_website_get' => 'CRM_Core_BAO_Website', 'civicrm_api3_survey_get' => 'CRM_Campaign_BAO_Survey', 'civicrm_api3_pledge_payment_get' => 'CRM_Pledge_BAO_PledgePayment', @@ -234,7 +234,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase { 'mailing_group' => 'CRM_Mailing_DAO_MailingGroup', // Make sure we get null back with nonexistant entities 'civicrm_this_does_not_exist' => NULL, - ); + ]; foreach ($params as $input => $expected) { $result = _civicrm_api3_get_BAO($input); $this->assertEquals($expected, $result); @@ -242,22 +242,22 @@ class api_v3_UtilsTest extends CiviUnitTestCase { } public function test_civicrm_api3_validate_fields() { - $params = array('start_date' => '2010-12-20', 'end_date' => ''); - $fields = civicrm_api3('relationship', 'getfields', array('action' => 'get')); + $params = ['start_date' => '2010-12-20', 'end_date' => '']; + $fields = civicrm_api3('relationship', 'getfields', ['action' => 'get']); _civicrm_api3_validate_fields('relationship', 'get', $params, $fields['values']); $this->assertEquals('20101220000000', $params['start_date']); $this->assertEquals('', $params['end_date']); } public function test_civicrm_api3_validate_fields_membership() { - $params = array( + $params = [ 'start_date' => '2010-12-20', 'end_date' => '', 'membership_end_date' => '0', 'join_date' => '2010-12-20', 'membership_start_date' => '2010-12-20', - ); - $fields = civicrm_api3('Membership', 'getfields', array('action' => 'get')); + ]; + $fields = civicrm_api3('Membership', 'getfields', ['action' => 'get']); _civicrm_api3_validate_fields('Membership', 'get', $params, $fields['values']); $this->assertEquals('2010-12-20', $params['start_date']); $this->assertEquals('20101220000000', $params['membership_start_date']); @@ -267,13 +267,13 @@ class api_v3_UtilsTest extends CiviUnitTestCase { public function test_civicrm_api3_validate_fields_event() { - $params = array( + $params = [ 'registration_start_date' => 20080601, 'registration_end_date' => '2008-10-15', 'start_date' => '2010-12-20', 'end_date' => '', - ); - $fields = civicrm_api3('Event', 'getfields', array('action' => 'create')); + ]; + $fields = civicrm_api3('Event', 'getfields', ['action' => 'create']); _civicrm_api3_validate_fields('event', 'create', $params, $fields['values']); $this->assertEquals('20101220000000', $params['start_date']); $this->assertEquals('20081015000000', $params['registration_end_date']); @@ -282,11 +282,11 @@ class api_v3_UtilsTest extends CiviUnitTestCase { } public function test_civicrm_api3_validate_fields_exception() { - $params = array( + $params = [ 'join_date' => 'abc', - ); + ]; try { - $fields = civicrm_api3('Membership', 'getfields', array('action' => 'get')); + $fields = civicrm_api3('Membership', 'getfields', ['action' => 'get']); _civicrm_api3_validate_fields('Membership', 'get', $params, $fields['values']); } catch (Exception$expected) { @@ -295,60 +295,60 @@ class api_v3_UtilsTest extends CiviUnitTestCase { } public function testGetFields() { - $result = $this->callAPISuccess('membership', 'getfields', array()); + $result = $this->callAPISuccess('membership', 'getfields', []); $this->assertArrayHasKey('values', $result); - $result = $this->callAPISuccess('relationship', 'getfields', array()); + $result = $this->callAPISuccess('relationship', 'getfields', []); $this->assertArrayHasKey('values', $result); - $result = $this->callAPISuccess('event', 'getfields', array()); + $result = $this->callAPISuccess('event', 'getfields', []); $this->assertArrayHasKey('values', $result); } public function testGetFields_AllOptions() { - $result = $this->callAPISuccess('contact', 'getfields', array( - 'options' => array( + $result = $this->callAPISuccess('contact', 'getfields', [ + 'options' => [ 'get_options' => 'all', - ), - )); + ], + ]); $this->assertEquals('Household', $result['values']['contact_type']['options']['Household']); $this->assertEquals('HTML', $result['values']['preferred_mail_format']['options']['HTML']); } public function basicArrayCases() { - $records = array( - array('snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'), - array('snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'), - array('snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'), - array('snack_id' => 'd', 'fruit' => 'apple', 'cheese' => 'gouda'), - array('snack_id' => 'e', 'fruit' => 'apple', 'cheese' => 'provolone'), - ); - - $cases[] = array( + $records = [ + ['snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'], + ['snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'], + ['snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'], + ['snack_id' => 'd', 'fruit' => 'apple', 'cheese' => 'gouda'], + ['snack_id' => 'e', 'fruit' => 'apple', 'cheese' => 'provolone'], + ]; + + $cases[] = [ $records, // params - array('version' => 3), + ['version' => 3], // expected results - array('a', 'b', 'c', 'd', 'e'), - ); + ['a', 'b', 'c', 'd', 'e'], + ]; - $cases[] = array( + $cases[] = [ $records, // params - array('version' => 3, 'fruit' => 'apple'), + ['version' => 3, 'fruit' => 'apple'], // expected results - array('a', 'c', 'd', 'e'), - ); + ['a', 'c', 'd', 'e'], + ]; - $cases[] = array( + $cases[] = [ $records, - array('version' => 3, 'cheese' => 'cheddar'), - array('b', 'c'), - ); + ['version' => 3, 'cheese' => 'cheddar'], + ['b', 'c'], + ]; - $cases[] = array( + $cases[] = [ $records, - array('version' => 3, 'id' => 'd'), - array('d'), - ); + ['version' => 3, 'id' => 'd'], + ['d'], + ]; return $cases; } @@ -372,7 +372,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase { $provider = new \Civi\API\Provider\AdhocProvider($params['version'], 'Widget'); $provider->addAction('get', 'access CiviCRM', function ($apiRequest) use ($records) { - return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', array('snack_id', 'fruit', 'cheese')); + return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', ['snack_id', 'fruit', 'cheese']); }); $kernel->registerApiProvider($provider); @@ -382,12 +382,12 @@ class api_v3_UtilsTest extends CiviUnitTestCase { $this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('snack_id', $r1['values']))); $this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('id', $r1['values']))); - $r2 = $kernel->run('Widget', 'get', $params + array('sequential' => 1)); + $r2 = $kernel->run('Widget', 'get', $params + ['sequential' => 1]); $this->assertEquals(count($resultIds), $r2['count']); $this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('snack_id', $r2['values']))); $this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('id', $r2['values']))); - $r3 = $kernel->run('Widget', 'get', $params + array('options' => array('offset' => 1, 'limit' => 2))); + $r3 = $kernel->run('Widget', 'get', $params + ['options' => ['offset' => 1, 'limit' => 2]]); $slice = array_slice($resultIds, 1, 2); $this->assertEquals(count($slice), $r3['count']); $this->assertEquals($slice, array_values(CRM_Utils_Array::collect('snack_id', $r3['values']))); @@ -395,45 +395,45 @@ class api_v3_UtilsTest extends CiviUnitTestCase { } public function testBasicArrayGetReturn() { - $records = array( - array('snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'), - array('snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'), - array('snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'), - ); + $records = [ + ['snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'], + ['snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'], + ['snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'], + ]; $kernel = new \Civi\API\Kernel(new \Symfony\Component\EventDispatcher\EventDispatcher()); $provider = new \Civi\API\Provider\AdhocProvider(3, 'Widget'); $provider->addAction('get', 'access CiviCRM', function ($apiRequest) use ($records) { - return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', array('snack_id', 'fruit', 'cheese')); + return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', ['snack_id', 'fruit', 'cheese']); }); $kernel->registerApiProvider($provider); - $r1 = $kernel->run('Widget', 'get', array( + $r1 = $kernel->run('Widget', 'get', [ 'version' => 3, 'snack_id' => 'b', 'return' => 'fruit', - )); + ]); $this->assertAPISuccess($r1); - $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape')), $r1['values']); + $this->assertEquals(['b' => ['id' => 'b', 'fruit' => 'grape']], $r1['values']); - $r2 = $kernel->run('Widget', 'get', array( + $r2 = $kernel->run('Widget', 'get', [ 'version' => 3, 'snack_id' => 'b', - 'return' => array('fruit', 'cheese'), - )); + 'return' => ['fruit', 'cheese'], + ]); $this->assertAPISuccess($r2); - $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar')), $r2['values']); + $this->assertEquals(['b' => ['id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar']], $r2['values']); - $r3 = $kernel->run('Widget', 'get', array( + $r3 = $kernel->run('Widget', 'get', [ 'version' => 3, 'cheese' => 'cheddar', - 'return' => array('fruit'), - )); + 'return' => ['fruit'], + ]); $this->assertAPISuccess($r3); - $this->assertEquals(array( - 'b' => array('id' => 'b', 'fruit' => 'grape'), - 'c' => array('id' => 'c', 'fruit' => 'apple'), - ), $r3['values']); + $this->assertEquals([ + 'b' => ['id' => 'b', 'fruit' => 'grape'], + 'c' => ['id' => 'c', 'fruit' => 'apple'], + ], $r3['values']); } /** @@ -442,9 +442,9 @@ class api_v3_UtilsTest extends CiviUnitTestCase { public function testTimeStampChecking() { CRM_Core_DAO::executeQuery("INSERT INTO civicrm_mailing (id, modified_date) VALUES (25, '2016-06-30 12:52:52')"); $this->assertTrue(_civicrm_api3_compare_timestamps('2017-02-15 16:00:00', 25, 'Mailing')); - $this->callAPISuccess('Mailing', 'create', array('id' => 25, 'subject' => 'Test Subject')); + $this->callAPISuccess('Mailing', 'create', ['id' => 25, 'subject' => 'Test Subject']); $this->assertFalse(_civicrm_api3_compare_timestamps('2017-02-15 16:00:00', 25, 'Mailing')); - $this->callAPISuccess('Mailing', 'delete', array('id' => 25)); + $this->callAPISuccess('Mailing', 'delete', ['id' => 25]); } } diff --git a/tests/phpunit/api/v3/ValidateTest.php b/tests/phpunit/api/v3/ValidateTest.php index 0a25ac6c40..03b19e7a62 100644 --- a/tests/phpunit/api/v3/ValidateTest.php +++ b/tests/phpunit/api/v3/ValidateTest.php @@ -41,48 +41,48 @@ class api_v3_ValidateTest extends CiviUnitTestCase { } public function testEmptyContactValidate() { - $validation = $this->callAPISuccess('Contact', 'validate', array('action' => "create")); - $expectedOut = array( - 'contact_type' => array( + $validation = $this->callAPISuccess('Contact', 'validate', ['action' => "create"]); + $expectedOut = [ + 'contact_type' => [ 'message' => "Mandatory key(s) missing from params array: contact_type", 'code' => "mandatory_missing", - ), - ); + ], + ]; $this->assertEquals($validation['values'][0], $expectedOut); } public function testContributionValidate() { - $validation = $this->callAPISuccess('Contribution', 'validate', array('action' => "create", 'total_amount' => "100w")); - $totalAmountErrors = array( + $validation = $this->callAPISuccess('Contribution', 'validate', ['action' => "create", 'total_amount' => "100w"]); + $totalAmountErrors = [ 'message' => "total_amount is not a valid amount: 100w", 'code' => "incorrect_value", - ); + ]; - $contactIdErrors = array( + $contactIdErrors = [ 'message' => "Mandatory key(s) missing from params array: contact_id", 'code' => "mandatory_missing", - ); + ]; $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors); $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors); } public function testContributionDateValidate() { - $params = array( + $params = [ 'action' => "create", 'financial_type_id' => "1", 'total_amount' => "100", 'contact_id' => "1", 'receive_date' => 'abc', - ); + ]; $validation = $this->callAPISuccess('Contribution', 'validate', $params); - $expectedOut = array( - 'receive_date' => array( + $expectedOut = [ + 'receive_date' => [ 'message' => "receive_date is not a valid date: abc", 'code' => "incorrect_value", - ), - ); + ], + ]; $this->assertEquals($validation['values'][0], $expectedOut); } diff --git a/tests/phpunit/api/v3/WebsiteTest.php b/tests/phpunit/api/v3/WebsiteTest.php index 7dd2e124ad..5422d4bf72 100644 --- a/tests/phpunit/api/v3/WebsiteTest.php +++ b/tests/phpunit/api/v3/WebsiteTest.php @@ -46,11 +46,11 @@ class api_v3_WebsiteTest extends CiviUnitTestCase { $this->_entity = 'website'; $this->_contactID = $this->organizationCreate(); - $this->params = array( + $this->params = [ 'contact_id' => $this->_contactID, 'url' => 'website.com', 'website_type_id' => 1, - ); + ]; } /** @@ -75,7 +75,7 @@ class api_v3_WebsiteTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('website', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('website', 'delete', ['id' => $result['id']]); } /** @@ -85,9 +85,9 @@ class api_v3_WebsiteTest extends CiviUnitTestCase { public function testDeleteWebsite($version) { $this->_apiversion = $version; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); + $deleteParams = ['id' => $result['id']]; $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } @@ -98,9 +98,9 @@ class api_v3_WebsiteTest extends CiviUnitTestCase { public function testDeleteWebsiteInvalid($version) { $this->_apiversion = $version; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => 600); + $deleteParams = ['id' => 600]; $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(1, $checkDeleted['count']); } @@ -108,11 +108,11 @@ class api_v3_WebsiteTest extends CiviUnitTestCase { * Test retrieval of metadata. */ public function testGetMetadata() { - $result = $this->callAPIAndDocument($this->_entity, 'get', array( - 'options' => array( - 'metadata' => array('fields'), - ), - ), __FUNCTION__, __FILE__, 'Demonostrates returning field metadata', 'GetWithMetadata'); + $result = $this->callAPIAndDocument($this->_entity, 'get', [ + 'options' => [ + 'metadata' => ['fields'], + ], + ], __FUNCTION__, __FILE__, 'Demonostrates returning field metadata', 'GetWithMetadata'); $this->assertEquals('Website', $result['metadata']['fields']['url']['title']); } @@ -122,7 +122,7 @@ class api_v3_WebsiteTest extends CiviUnitTestCase { */ public function testGetFields($version) { $this->_apiversion = $version; - $result = $this->callAPIAndDocument($this->_entity, 'getfields', array('action' => 'get'), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'getfields', ['action' => 'get'], __FUNCTION__, __FILE__); $this->assertArrayKeyExists('url', $result['values']); } diff --git a/tests/phpunit/api/v3/custom_api/MailingProviderData.php b/tests/phpunit/api/v3/custom_api/MailingProviderData.php index 8d250cdc67..f3ed47c8f9 100644 --- a/tests/phpunit/api/v3/custom_api/MailingProviderData.php +++ b/tests/phpunit/api/v3/custom_api/MailingProviderData.php @@ -108,8 +108,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { */ public static function &fields() { if (!isset(Civi::$statics[__CLASS__]['fields'])) { - Civi::$statics[__CLASS__]['fields'] = array( - 'contact_identifier' => array( + Civi::$statics[__CLASS__]['fields'] = [ + 'contact_identifier' => [ 'name' => 'contact_identifier', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Contact Identifier') , @@ -120,8 +120,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ) , - 'mailing_identifier' => array( + ] , + 'mailing_identifier' => [ 'name' => 'mailing_identifier', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Mailing Identifier') , @@ -132,8 +132,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ) , - 'email' => array( + ] , + 'email' => [ 'name' => 'email', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Email') , @@ -144,8 +144,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ) , - 'event_type' => array( + ] , + 'event_type' => [ 'name' => 'event_type', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Recipient Action Type') , @@ -156,8 +156,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ) , - 'recipient_action_datetime' => array( + ] , + 'recipient_action_datetime' => [ 'name' => 'recipient_action_datetime', 'type' => CRM_Utils_Type::T_TIMESTAMP, 'title' => ts('Recipient Action Datetime') , @@ -166,8 +166,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ), - 'contact_id' => array( + ], + 'contact_id' => [ 'name' => 'contact_id', 'type' => CRM_Utils_Type::T_INT, 'description' => 'Contact in CiviCRM', @@ -175,8 +175,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ) , - 'is_civicrm_updated' => array( + ] , + 'is_civicrm_updated' => [ 'name' => 'is_civicrm_updated', 'type' => CRM_Utils_Type::T_BOOLEAN, 'description' => 'Has the action been synchronised through to CiviCRM', @@ -184,8 +184,8 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { 'entity' => 'MailingProviderData', 'bao' => 'CRM_Omnimail_DAO_MailingProviderData', 'localizable' => 0, - ) , - ); + ] , + ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } return Civi::$statics[__CLASS__]['fields']; @@ -230,7 +230,7 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { * @return array */ public static function &import($prefix = FALSE) { - $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'mailing_provider_data', $prefix, array()); + $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'mailing_provider_data', $prefix, []); return $r; } @@ -242,7 +242,7 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { * @return array */ public static function &export($prefix = FALSE) { - $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_provider_data', $prefix, array()); + $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_provider_data', $prefix, []); return $r; } @@ -250,7 +250,7 @@ class CRM_Omnimail_DAO_MailingProviderData extends CRM_Core_DAO { * Returns the list of indices */ public static function indices($localize = TRUE) { - $indices = array(); + $indices = []; return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; } diff --git a/tests/phpunit/api/v3/dataset/resolver/api/v3/Contact/ExampleAction2.php b/tests/phpunit/api/v3/dataset/resolver/api/v3/Contact/ExampleAction2.php index e63705affc..3a8ab34a1c 100644 --- a/tests/phpunit/api/v3/dataset/resolver/api/v3/Contact/ExampleAction2.php +++ b/tests/phpunit/api/v3/dataset/resolver/api/v3/Contact/ExampleAction2.php @@ -7,7 +7,7 @@ */ function civicrm_api3_contact_example_action2($params) { return civicrm_api3_create_success( - array('0' => 'civicrm_api3_contact_example_action2 is ok'), + ['0' => 'civicrm_api3_contact_example_action2 is ok'], $params, 'contact', 'example_action2' diff --git a/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction1.php b/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction1.php index 35cb5cc2fa..a715a1d389 100644 --- a/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction1.php +++ b/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction1.php @@ -7,7 +7,7 @@ */ function civicrm_api3_generic_example_action1($apiRequest) { return civicrm_api3_create_success( - array('0' => 'civicrm_api3_generic_example_action1 is ok'), + ['0' => 'civicrm_api3_generic_example_action1 is ok'], $apiRequest['params'], $apiRequest['entity'], $apiRequest['action'] diff --git a/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php b/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php index 84885d255b..986192a719 100644 --- a/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php +++ b/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php @@ -9,7 +9,7 @@ */ function civicrm_api3_generic_example_action2($apiRequest) { return civicrm_api3_create_success( - array('0' => 'civicrm_api3_generic_example_action2 should not be called'), + ['0' => 'civicrm_api3_generic_example_action2 should not be called'], $apiRequest['params'], $apiRequest['entity'], $apiRequest['action'] diff --git a/tests/phpunit/api/v3/dataset/resolver/api/v3/TestEntity.php b/tests/phpunit/api/v3/dataset/resolver/api/v3/TestEntity.php index 51349e8df5..8ec7424908 100644 --- a/tests/phpunit/api/v3/dataset/resolver/api/v3/TestEntity.php +++ b/tests/phpunit/api/v3/dataset/resolver/api/v3/TestEntity.php @@ -9,7 +9,7 @@ */ function civicrm_api3_test_entity_example_action3($params) { return civicrm_api3_create_success( - array('0' => 'civicrm_api3_test_entity_example_action3 is ok'), + ['0' => 'civicrm_api3_test_entity_example_action3 is ok'], $params, 'test_entity', 'example_action3' diff --git a/tests/phpunit/api/v3/settings/test.setting.php b/tests/phpunit/api/v3/settings/test.setting.php index 8df00223a5..2db776a87b 100644 --- a/tests/phpunit/api/v3/settings/test.setting.php +++ b/tests/phpunit/api/v3/settings/test.setting.php @@ -1,6 +1,6 @@ array( +return [ + 'test_key' => [ 'group_name' => 'Test Settings', 'group' => 'test', 'name' => 'test_key', @@ -13,8 +13,8 @@ return array( 'help_text' => '', 'html_type' => 'Text', 'quick_form_type' => 'Element', - ), - 'test_secret' => array( + ], + 'test_secret' => [ 'group_name' => 'Test Settings', 'group' => 'test', 'name' => 'test_secret', @@ -27,8 +27,8 @@ return array( 'help_text' => '', 'html_type' => 'Text', 'quick_form_type' => 'Element', - ), - 'test_public_certificate' => array( + ], + 'test_public_certificate' => [ 'group_name' => 'Test Settings', 'group' => 'test', 'name' => 'test_public_certificate', @@ -40,12 +40,12 @@ return array( 'description' => 'Enter the full path to your public Certificate', 'help_text' => '', 'html_type' => 'Text', - 'html_attributes' => array( + 'html_attributes' => [ 'size' => 50, - ), + ], 'quick_form_type' => 'Element', - ), - 'test_private_key' => array( + ], + 'test_private_key' => [ 'group_name' => 'Test Settings', 'group' => 'test', 'name' => 'test_private_key', @@ -58,5 +58,5 @@ return array( 'help_text' => '', 'html_type' => 'Text', 'quick_form_type' => 'Element', - ), -); + ], +]; -- 2.25.1