various comment fixes
[civicrm-core.git] / tests / phpunit / WebTest / Activity / AddRecurringActivityTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 /**
28 * Description of AddRecurringActivityTest
29 *
30 * @author Priyanka
31 */
32
33 require_once 'CiviTest/CiviSeleniumTestCase.php';
34
35 /**
36 * Class WebTest_Activity_AddRecurringActivityTest
37 */
38 class WebTest_Activity_AddRecurringActivityTest extends CiviSeleniumTestCase {
39
40 protected function setUp() {
41 parent::setUp();
42 }
43
44 public function testRecurringActivity() {
45 $this->webtestLogin();
46
47 //Adding new contact
48 $contact1 = substr(sha1(rand()), 0, 7);
49 $this->webtestAddContact("$contact1", "Karan", $contact1 . "@exampleone.com");
50 $contact2 = substr(sha1(rand()), 0, 7);
51 $this->webtestAddContact("$contact2", "Jane", $contact2 . "@exampletwo.com");
52
53 //Lets create an activity and add repeat configuration
54 $this->openCiviPage("activity", "?reset=1&action=add&context=standalone", '_qf_Activity_cancel-bottom');
55 $this->select("activity_type_id", "value=1");
56
57 //Add a new contact
58 $this->click("xpath=//div[@id='s2id_target_contact_id']/ul/li/input");
59 $this->keyDown("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", " ");
60 $this->type("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $contact1);
61 $this->typeKeys("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $contact1);
62
63 // ...waiting for drop down with results to show up...
64 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
65
66 // ...need to use mouseDownAt on first result (which is a li element), click does not work
67 $this->clickAt("xpath=//div[@class='select2-result-label']");
68 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", "$contact1");
69 $this->assertElementContainsText("xpath=//div[@id='s2id_target_contact_id']", "Karan, $contact1", 'Contact not found in line ' . __LINE__);
70
71 //Assigned To field
72 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
73 $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " ");
74 $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $contact2);
75 $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $contact2);
76
77 // ...waiting for drop down with results to show up...
78 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
79
80 //..need to use mouseDownAt on first result (which is a li element), click does not work
81 $this->clickAt("xpath=//div[@class='select2-result-label']");
82
83 // ...again, waiting for the box with contact name to show up...
84 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "$contact2");
85
86 // ...and verifying if the page contains properly formatted display name for chosen contact.
87 $this->assertElementContainsText("xpath=//div[@id='s2id_assignee_contact_id']", "Jane, $contact2", 'Contact not found in line ' . __LINE__);
88
89 $subject = "Test activity recursion";
90 $this->type("subject", $subject);
91 $this->type("duration", "30");
92
93 //Lets configure recursion for activity
94 $this->click("css=.crm-activity-form-block-recurring_activity div.crm-accordion-header");
95 $this->click('repetition_frequency_unit');
96 $this->select('repetition_frequency_unit', 'label=monthly');
97 $this->click('repetition_frequency_interval');
98 $this->select('repetition_frequency_interval', 'label=1');
99 $this->click('CIVICRM_QFID_1_repeats_by');
100 $this->click('limit_to');
101 $this->select('limit_to', 'label=26');
102 $this->click('CIVICRM_QFID_1_ends');
103
104 $occurrences = rand(3, 5);
105 if (!$occurrences) {
106 $occurrences = 3;
107 }
108 $this->type('start_action_offset', $occurrences);
109 $this->click('_qf_Activity_upload-bottom');
110 $this->waitForTextPresent('Based on your repeat configuration, here is the list of dates. Do you wish to create a recurring set with these dates?');
111 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Ok']");
112 $this->waitForPageToLoad();
113
114 //Lets go to search screen and see if the records new activities are created()
115 $this->openCiviPage("activity/search", "?reset=1", '_qf_Search_refresh');
116 $search_subject = 'Test activity recursion';
117 $this->type('activity_subject', $search_subject);
118 $this->click('_qf_Search_refresh');
119 $this->waitForPageToLoad();
120
121 //Minus tr having th and parent activity
122 $countOfActivities = $this->getXpathCount("//div[@class='crm-search-results']/table/tbody/tr");
123 $countOfActivities = $countOfActivities - 2;
124 $this->assertEquals($occurrences, $countOfActivities);
125 $this->assertTrue($this->isTextPresent("Recurring Activity - (Child)"));
126 $this->assertTrue($this->isTextPresent("Recurring Activity - (Parent)"));
127
128 //Cascade changes
129 $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td/span/a[text()='Edit']");
130 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Cancel']");
131 $this->type('subject', 'Test activity recursion modified');
132 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']");
133 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Cancel']");
134 $this->click("xpath=//div[@id='recurring-dialog']/div[@class='show-block']/div[@class='recurring-dialog-inner-wrapper']/div[@class='recurring-dialog-inner-left']/button[text()='This and Following entities']");
135 $this->waitForAjaxContent();
136 $this->type('activity_subject', 'Test activity recursion modified');
137 $this->click('_qf_Search_refresh');
138 $this->waitForPageToLoad();
139 $countOfActivities = $this->getXpathCount("xpath=//div[@class='crm-search-results']/table/tbody/tr");
140 if ($countOfActivities) {
141 for ($i = 0; $i <= $countOfActivities; $i++) {
142 $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[3]", 'Test activity recursion modified');
143 }
144 }
145 }
146
147 }