Merge pull request #199 from colemanw/webtest
[civicrm-core.git] / tests / phpunit / WebTest / Admin / RelationshipTypeAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Admin_RelationshipTypeAddTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testRelationshipTypeAdd() {
36
37 $this->webtestLogin();
38 $this->waitForPageToLoad($this->getTimeoutMsec());
39
40 $this->click('link=CiviCRM');
41 $this->waitForPageToLoad($this->getTimeoutMsec());
42
43 //jump directly to relationship type selector.
44 $this->openCiviPage('admin/reltype', 'reset=1&action=browse');
45
46 //load the form to add new relationship type.
47 $this->click('link=Add Relationship Type');
48 $this->waitForPageToLoad($this->getTimeoutMsec());
49
50 //enter the relationship type values.
51 $labelAB = 'Test Relationship Type A - B -' . rand();
52 $labelBA = 'Test Relationship Type B - A -' . rand();
53 $this->type('label_a_b', $labelAB);
54 $this->type('label_b_a', $labelBA);
55 $this->select('contact_types_a', "value=Individual");
56 $this->select('contact_types_b', "value=Individual");
57 $this->type('description', 'Test Relationship Type Description');
58
59 //save the data.
60 $this->click('_qf_RelationshipType_next-bottom');
61 $this->waitForPageToLoad($this->getTimeoutMsec());
62
63 //does data saved.
64 $this->assertElementContainsText('crm-notification-container', 'The Relationship Type has been saved.',
65 "Status message didn't show up after saving!"
66 );
67
68 //validate data.
69 $data = array(
70 'Relationship A to B' => $labelAB,
71 'Relationship B to A' => $labelBA,
72 'Contact Type A' => 'Individual',
73 'Contact Type B' => 'Individual',
74 );
75 foreach ($data as $param => $val) {
76 $this->assertElementContainsText('option11', $val, "Could not able to save $param");
77 }
78 }
79
80 function testRelationshipTypeAddValidateFormRules() {
81
82 $this->webtestLogin();
83 $this->waitForPageToLoad($this->getTimeoutMsec());
84
85 $this->click('link=CiviCRM');
86 $this->waitForPageToLoad($this->getTimeoutMsec());
87
88 //jump directly to relationship type selector.
89 $this->openCiviPage('admin/reltype', 'reset=1&action=browse');
90
91 //validate form rules.
92 $this->click('link=Add Relationship Type');
93 $this->waitForPageToLoad($this->getTimeoutMsec());
94
95 $this->select('contact_types_a', 'value=Individual');
96 $this->select('contact_types_b', 'value=Individual');
97 $description = 'Test Relationship Type Description';
98 $this->type('description', $description);
99
100 $this->click('_qf_RelationshipType_next-bottom');
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102 $this->assertElementContainsText('crm-notification-container', 'Relationship Label-A to B is a required field.',
103 'Required form rule for Label A - B seems to be broken.'
104 );
105
106 //enter the relationship type values.
107 $labelAB = 'Test Relationship Type A - B - DUPLICATE TO BE' . rand();
108 $labelBA = 'Test Relationship Type B - A - DUPLICATE TO BE' . rand();
109 $this->type('label_a_b', $labelAB);
110 $this->type('label_b_a', $labelBA);
111 $this->select('contact_types_a', "value=Individual");
112 $this->select('contact_types_b', "value=Individual");
113 $this->type('description', 'Test Relationship Type Description');
114 $this->click('_qf_RelationshipType_next-bottom');
115 $this->waitForPageToLoad($this->getTimeoutMsec());
116
117 $this->openCiviPage('admin/reltype', 'reset=1&action=browse');
118 $this->click('link=Add Relationship Type');
119 $this->waitForPageToLoad($this->getTimeoutMsec());
120
121 $this->type('label_a_b', $labelAB);
122 $this->type('label_b_a', $labelBA);
123 $this->click('_qf_RelationshipType_next-bottom');
124
125 $this->waitForPageToLoad($this->getTimeoutMsec());
126 $this->assertElementContainsText('crm-notification-container', 'Label already exists in Database.',
127 'Unique relationship type label form rule seems to be broken.'
128 );
129 }
130 }
131