Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-10-07-19-33-29
[civicrm-core.git] / tests / phpunit / WebTest / Admin / RelationshipTypeAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Admin_RelationshipTypeAddTest
31 */
32 class WebTest_Admin_RelationshipTypeAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testRelationshipTypeAdd() {
39
40 $this->webtestLogin();
41 $this->waitForPageToLoad($this->getTimeoutMsec());
42
43 $this->click('link=CiviCRM');
44 $this->waitForPageToLoad($this->getTimeoutMsec());
45
46 //jump directly to relationship type selector.
47 $this->openCiviPage('admin/reltype', 'reset=1&action=browse');
48
49 //load the form to add new relationship type.
50 $this->click('link=Add Relationship Type');
51 $this->waitForElementPresent('_qf_RelationshipType_next-bottom');
52
53 //enter the relationship type values.
54 $labelAB = 'Test Relationship Type A - B -' . rand();
55 $labelBA = 'Test Relationship Type B - A -' . rand();
56 $this->type('label_a_b', $labelAB);
57 $this->type('label_b_a', $labelBA);
58 $this->select('contact_types_a', "value=Individual");
59 $this->select('contact_types_b', "value=Individual");
60 $this->type('description', 'Test Relationship Type Description');
61
62 //save the data.
63 $this->click('_qf_RelationshipType_next-bottom');
64
65 //does data saved.
66 $this->waitForText('crm-notification-container', 'The Relationship Type has been saved.');
67
68 $this->waitForElementPresent('link=Add Relationship Type');
69 //validate data.
70 $data = array(
71 'Relationship A to B' => $labelAB,
72 'Relationship B to A' => $labelBA,
73 'Contact Type A' => 'Individual',
74 'Contact Type B' => 'Individual',
75 );
76 foreach ($data as $param => $val) {
77 $this->assertElementContainsText("xpath=//table[@class='display dataTable no-footer']", $val, "Could not able to save $param");
78 }
79 }
80
81 function testRelationshipTypeAddValidateFormRules() {
82
83 $this->webtestLogin();
84 $this->waitForPageToLoad($this->getTimeoutMsec());
85
86 $this->click('link=CiviCRM');
87 $this->waitForPageToLoad($this->getTimeoutMsec());
88
89 //jump directly to relationship type selector.
90 $this->openCiviPage('admin/reltype', 'reset=1&action=browse');
91
92 //validate form rules.
93 $this->click('link=Add Relationship Type');
94 $this->waitForElementPresent('_qf_RelationshipType_next-bottom');
95
96 $this->select('contact_types_a', 'value=Individual');
97 $this->select('contact_types_b', 'value=Individual');
98 $description = 'Test Relationship Type Description';
99 $this->type('description', $description);
100
101 $this->click('_qf_RelationshipType_next-bottom');
102 $this->waitForText("xpath=//*[@id='RelationshipType']/div[2]/table/tbody/tr[1]/td[2]/label[@class='crm-inline-error']", 'This field is required.');
103
104 //enter the relationship type values.
105 $labelAB = 'Test Relationship Type A - B - DUPLICATE TO BE' . rand();
106 $labelBA = 'Test Relationship Type B - A - DUPLICATE TO BE' . rand();
107 $this->type('label_a_b', $labelAB);
108 $this->type('label_b_a', $labelBA);
109 $this->select('contact_types_a', "value=Individual");
110 $this->select('contact_types_b', "value=Individual");
111 $this->type('description', 'Test Relationship Type Description');
112 $this->click('_qf_RelationshipType_next-bottom');
113 $this->waitForElementPresent('link=Add Relationship Type');
114
115 $this->openCiviPage('admin/reltype', 'reset=1&action=browse');
116 $this->click('link=Add Relationship Type');
117 $this->waitForElementPresent('_qf_RelationshipType_next-bottom');
118
119 $this->type('label_a_b', $labelAB);
120 $this->type('label_b_a', $labelBA);
121 $this->click('_qf_RelationshipType_next-bottom');
122
123 $this->waitForText('crm-notification-container', 'Label already exists in Database.');
124 }
125 }
126