Merge pull request #21554 from eileenmcnaughton/loop
[civicrm-core.git] / tests / phpunit / CRM / Core / FormTest.php
1 <?php
2
3 /**
4 * @group headless
5 */
6 class CRM_Core_FormTest extends CiviUnitTestCase {
7
8 /**
9 * Simulate opening various forms. All we're looking to do here is
10 * see if any warnings or notices come up, the equivalent of red boxes
11 * on the screen, but which are hidden when using popup forms.
12 * So no assertions required.
13 *
14 * @param string $url
15 *
16 * @dataProvider formList
17 */
18 public function testOpeningForms(string $url) {
19 $this->createLoggedInUser();
20
21 $_SERVER['REQUEST_URI'] = $url;
22 $urlParts = explode('?', $url);
23 $_GET['q'] = $urlParts[0];
24
25 $parsed = [];
26 parse_str($urlParts[1], $parsed);
27 foreach ($parsed as $param => $value) {
28 $_REQUEST[$param] = $value;
29 }
30
31 $item = CRM_Core_Invoke::getItem([$_GET['q']]);
32 ob_start();
33 CRM_Core_Invoke::runItem($item);
34 ob_end_clean();
35
36 foreach ($parsed as $param => $dontcare) {
37 unset($_REQUEST[$param]);
38 }
39 }
40
41 /**
42 * Dataprovider for testOpeningForms().
43 * TODO: Add more forms!
44 *
45 * @return array
46 */
47 public function formList(): array {
48 return [
49 // Array key is descriptive term to make it clearer which form it is when it fails.
50 'Add New Tag' => [
51 'civicrm/tag/edit?action=add&parent_id=',
52 ],
53 'Assign Account to Financial Type' => [
54 'civicrm/admin/financial/financialType/accounts?action=add&reset=1&aid=1',
55 ],
56 'Find Contacts' => [
57 'civicrm/contact/search?reset=1',
58 ],
59 'Fulltext search' => [
60 'civicrm/contact/search/custom?csid=15&reset=1',
61 ],
62 ];
63 }
64
65 public function testNewPriceField(): void {
66 $this->createLoggedInUser();
67
68 $priceSetId = $this->callAPISuccess('PriceSet', 'create', [
69 'is_active' => 1,
70 // extends contribution
71 'extends' => 2,
72 'is_quick_config' => 0,
73 // donation
74 'financial_type_id' => 1,
75 'name' => 'priciest',
76 'title' => 'Priciest Price Set',
77 ])['id'];
78
79 $_SERVER['REQUEST_URI'] = "civicrm/admin/price/field?reset=1&action=add&sid={$priceSetId}";
80 $_GET['q'] = 'civicrm/admin/price/field';
81 $_REQUEST['reset'] = 1;
82 $_REQUEST['action'] = 'add';
83 $_REQUEST['sid'] = $priceSetId;
84
85 $item = CRM_Core_Invoke::getItem([$_GET['q']]);
86 ob_start();
87 CRM_Core_Invoke::runItem($item);
88 ob_end_clean();
89
90 unset($_REQUEST['reset']);
91 unset($_REQUEST['action']);
92 unset($_REQUEST['sid']);
93
94 $this->callAPISuccess('PriceSet', 'delete', ['id' => $priceSetId]);
95 }
96
97 }