3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CiviTestCase
extends PHPUnit_Framework_Testcase
{
36 function __construct() {
37 parent
::__construct();
39 require_once 'CRM/Core/Config.php';
40 $config = CRM_Core_Config
::singleton();
43 function civiGet($path, $params, $abort = FALSE) {
44 $url = CRM_Utils_System
::url($path, $params, TRUE, NULL, FALSE);
46 return $this->civiGetURL($url, $abort);
49 function civiGetURL($url, $abort = FALSE) {
50 $html = $this->_browser
->get($url);
52 if ($this->drupalCheckAuth(TRUE)) {
53 $html .= $this->drupalCheckAuth();
56 $this->_content
= $this->_browser
->getContent();
66 function getUrlsByLabel($label, $fuzzy = FALSE) {
68 return $this->_browser
->_page
->getUrlsByLabel($label);
72 foreach ($this->_browser
->_page
->_links
as $link) {
73 $text = $link->getText();
74 if ($text == $label ||
75 strpos($text, $label) !== FALSE
77 $matches[] = $this->_browser
->_page
->_getUrlFromLink($link);
83 function isCiviURL($url, $ignoreVariations = TRUE) {
84 static $config = NULL;
86 $config = CRM_Core_Config
::singleton();
89 if (strpos($url, $config->userFrameworkBaseURL
. 'civicrm/') === FALSE) {
93 // ignore all urls with snippet, force, crmSID
94 if ($ignoreVariations &&
95 (strpos($url, 'snippet=') ||
96 strpos($url, 'force=') ||
97 strpos($url, 'crmSID=')
106 function getUrlsByToken($token, $path = NULL) {
108 foreach ($this->_browser
->_page
->_links
as $link) {
109 $text = $link->getText();
110 $url = $this->_browser
->_page
->_getUrlFromLink($link)->asString();
111 if ($this->isCiviURL($url) &&
112 (strpos($url, $token) !== FALSE)
115 strpos($url, $path) !== FALSE
117 $matches[$text] = $url;
124 function clickLink($label, $index = 0, $fuzzy = FALSE) {
126 return parent
::clickLink($label, $index);
129 $url_before = str_replace('%', '%%', $this->getUrl());
130 $urls = $this->getUrlsByLabel($label, TRUE);
131 if (count($urls) < $index +
1) {
132 $url_target = 'URL NOT FOUND!';
135 $url_target = str_replace('%', '%%', $urls[$index]->asString());
138 $this->_browser
->_load($urls[$index], new SimpleGetEncoding());
139 $ret = $this->_failOnError($this->_browser
->getContent());
141 $this->assertTrue($ret, ' [browser] clicked link ' . t($label) . " ($url_target) from $url_before");
146 function allPermissions() {
149 2 => 'view all contacts',
150 3 => 'edit all contacts',
151 4 => 'import contacts',
153 6 => 'administer CiviCRM',
154 7 => 'access uploaded files',
155 8 => 'profile listings and forms',
156 9 => 'access all custom data',
157 10 => 'view all activities',
158 11 => 'access CiviCRM',
159 12 => 'access Contact Dashboard',
163 function errorPage(&$ret, &$url) {
164 // check if there is a civicrm error or warning message on the page
165 // at a later stage, we should also check for CMS based errors
166 $this->assertTrue($ret, ts(' [browser] GET %1"', array('%1' => $url)));
168 $this->assertNoText('Sorry. A non-recoverable error has occurred', '[browser] fatal error page?');
169 $this->assertNoText('The requested page could not be found', '[browser] page not found?');
170 $this->assertNoText('You are not authorized to access this page', '[browser] permission denied?');