@@ -68,6 +68,56 @@ public function testPaths_getVariable() {
68
68
}
69
69
}
70
70
71
+ /**
72
+ * Get URLs through Civi::url().
73
+ */
74
+ public function testUrl (): void {
75
+ // Make some reqeusts for actual URLs
76
+ $ this ->assertUrlContentRegex (';crm-section event_date_time-section; ' , \Civi::url ('frontend://civicrm/event/info?id=1 ' , 'a ' ));
77
+ $ this ->assertUrlContentRegex (';MIT-LICENSE.txt; ' , \Civi::url ('asset://[civicrm.packages]/jquery/plugins/jquery.timeentry.js ' ));
78
+ $ this ->assertUrlContentRegex (';Please enter a valid email address; ' , \Civi::url ('assetBuilder://crm-l10n.js?locale=en_US ' ));
79
+ $ this ->assertUrlContentRegex (';.module..crmSearchAdmin; ' , \Civi::url ('ext://org.civicrm.search_kit/ang/crmSearchAdmin.module.js ' ));
80
+ $ this ->assertUrlContentRegex (';MIT-LICENSE.txt; ' , \Civi::url ('[civicrm.packages]/jquery/plugins/jquery.timeentry.js ' ));
81
+
82
+ // Check for well-formedness of some URLs
83
+ $ urlPats = [];
84
+ switch (CIVICRM_UF ) {
85
+ case 'Drupal ' :
86
+ case 'Drupal8 ' :
87
+ case 'Backdrop ' :
88
+ $ urlPats [] = [';/civicrm/event/info\?reset=1&id=9; ' , \Civi::url ('frontend://civicrm/event/info?reset=1 ' )->addQuery ('id=9 ' )];
89
+ $ urlPats [] = [';/civicrm/admin\?reset=1; ' , \Civi::url ('backend://civicrm/admin ' )->addQuery (['reset ' => 1 ])];
90
+ $ this ->assertNotEmpty ($ _SERVER ['HTTP_HOST ' ]);
91
+ break ;
92
+
93
+ case 'WordPress ' :
94
+ $ urlPats [] = [';civiwp=CiviCRM.*civicrm.*event.*info.*reset=1&id=9; ' , \Civi::url ('frontend://civicrm/event/info?reset=1 ' )->addQuery ('id=9 ' )];
95
+ $ urlPats [] = [';/wp-admin.*civicrm.*admin.*reset=1; ' , \Civi::url ('backend://civicrm/admin?reset=1 ' )];
96
+ break ;
97
+
98
+ case 'Joomla ' :
99
+ $ urlPats [] = [';/index.php\?.*task=civicrm/event/info&reset=1&id=9; ' , \Civi::url ('frontend://civicrm/event/inof?reset=1 ' )->addQuery ('id=9 ' )];
100
+ $ urlPats [] = [';/administrator/.*task=civicrm/admin/reset=1; ' , \Civi::url ('backend://civicrm/admin ' )->addQuery ('reset=1 ' )];
101
+ break ;
102
+
103
+ default :
104
+ $ this ->fail ('Unrecognized UF: ' . CIVICRM_UF );
105
+ }
106
+
107
+ $ urlPats [] = [';^https?://.*civicrm; ' , \Civi::url ('frontend://civicrm/event/info?reset=1 ' , 'a ' )];
108
+ $ urlPats [] = [';^https://.*civicrm; ' , \Civi::url ('frontend://civicrm/event/info?reset=1 ' , 'as ' )];
109
+
110
+ // Some test-harnesses have HTTP_HOST. Some don't. It's pre-req for truly relative URLs.
111
+ if (!empty ($ _SERVER ['HTTP_HOST ' ])) {
112
+ $ urlPats [] = [';^/.*civicrm.*ajax.*api4.*Contact.*get; ' , \Civi::url ('backend://civicrm/ajax/api4/Contact/get ' , 'r ' )];
113
+ }
114
+
115
+ $ this ->assertNotEmpty ($ urlPats );
116
+ foreach ($ urlPats as $ urlPat ) {
117
+ $ this ->assertRegExp ($ urlPat [0 ], $ urlPat [1 ]);
118
+ }
119
+ }
120
+
71
121
/**
72
122
* @param string $expectContentRegex
73
123
* @param string $url
0 commit comments