4 ## Setup a Drupal site with CiviCRM configured for unit-testing.
5 ## If a site already exists, destroy and recreate it.
6 ## Usage: mk-drupal-test-site <domain.name> <db_name> </path/to/drupal> </path/to/civi>
9 ## - MySQL admin credentials in ~/.my.cnf
10 ## - Apache vhost with mod_rewrite, etc
11 ## - DNS or /etc/hosts entries for "url"
12 ## - Drupal source tree
13 ## - CiviCRM source tree (outside the drupal root)
16 ## - (strongly recommended) filesystem with "acl" support
21 DB_PASS
=$
(makepasswd
--chars=12)
25 FACL_USERS
="www-data $(whoami)"
27 SITE_KEY
=$
(makepasswd
--chars=16)
29 ADMIN_PASS
=$
(makepasswd
--chars=12)
31 if [ -z "$CIVI_ROOT" -o ! -d "$CIVI_ROOT/bin" ]; then
32 echo "Failed to locate civi root: $CIVI_ROOT"
36 if [ -z "$DB_NAME" ]; then
37 echo "Missing database name"
42 echo "DROP DATABASE IF EXISTS $DB_NAME" | mysql
43 echo "CREATE DATABASE $DB_NAME" | mysql
44 echo "GRANT ALL ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}'" | mysql
45 echo "GRANT SUPER ON *.* TO '${DB_USER}'@'localhost'" | mysql
49 if [ -d "sites/$SITE_URL" ]; then
50 chmod u
+w
"sites/$SITE_URL"
51 rm -rf "sites/$SITE_URL"
53 drush site-install
-y \
54 --db-url="mysql://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_NAME}" \
55 --account-name="$ADMIN_USER" \
56 --account-pass="$ADMIN_PASS" \
57 --sites-subdir="$SITE_URL"
58 chmod u
+w
"sites/$SITE_URL"
60 ## Allow shell and WWW users to both manipulate "files" directory
61 if which setfacl
; then
62 for FACL_USER
in $FACL_USERS ; do
63 find "$DRUPAL_ROOT/sites/${SITE_URL}/files" -type d | xargs setfacl -m u:${FACL_USER}:rwx -m d:u:${FACL_USER}:rwx
67 ## Create Drupal-CiviCRM dirs and config
68 for SUBDIR in modules files files/civicrm files/civicrm/templates_c ; do
69 if [ ! -d "sites
/${SITE_URL}/${SUBDIR}" ]; then
70 mkdir "sites
/${SITE_URL}/${SUBDIR}"
74 ln -s "$CIVI_ROOT" "sites
/$SITE_URL/modules
/"
76 cat "$CIVI_ROOT/templates
/CRM
/common
/civicrm.settings.php.tpl
" \
77 | sed "s
;%%baseURL
%%;http
://${SITE_URL};" \
78 | sed "s
;%%cms
%%;Drupal
;" \
79 | sed "s
;%%CMSdbHost
%%;${DB_HOST};" \
80 | sed "s
;%%CMSdbName
%%;${DB_NAME};" \
81 | sed "s
;%%CMSdbPass
%%;${DB_PASS};" \
82 | sed "s
;%%CMSdbUser
%%;${DB_USER};" \
83 | sed "s
;%%crmRoot
%%;${DRUPAL_ROOT}/sites
/${SITE_URL}/modules
/civicrm
;" \
84 | sed "s
;%%dbHost
%%;${DB_HOST};" \
85 | sed "s
;%%dbName
%%;${DB_NAME};" \
86 | sed "s
;%%dbPass
%%;${DB_PASS};" \
87 | sed "s
;%%dbUser
%%;${DB_USER};" \
88 | sed "s
;%%siteKey
%%;${SITE_KEY};" \
89 | sed "s
;%%templateCompileDir
%%;${DRUPAL_ROOT}/sites
/${SITE_URL}/files
/civicrm
/templates_c
;" \
90 > "sites
/$SITE_URL/civicrm.settings.php
"
94 ## Create CiviCRM config
95 cat > "$CIVI_ROOT/bin
/setup.conf
" << EOF
97 SCHEMA=schema/Schema.xml
107 cat > "$CIVI_ROOT/tests
/phpunit
/CiviTest
/civicrm.settings.
local.php
" << EOF
109 define('CIVICRM_DSN', "mysql
://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_NAME}");
110 define('CIVICRM_TEMPLATE_COMPILEDIR', '${DRUPAL_ROOT}/sites/${SITE_URL}/files/civicrm/templates_c');
111 define('DONT_DOCUMENT_TEST_CONFIG', TRUE);
114 cat > "$CIVI_ROOT/tests
/phpunit
/CiviTest
/CiviSeleniumSettings.php
" << EOF
116 class CiviSeleniumSettings {
117 var \$publicSandbox = false;
118 var \$browser = '*firefox';
119 var \$sandboxURL = 'http://${SITE_URL}';
120 var \$sandboxPATH = '';
121 var \$username = 'demo';
122 var \$password = 'demo';
123 var \$adminUsername = '${ADMIN_USER}';
124 var \$adminPassword = '${ADMIN_PASS}';
125 var \$UFemail = 'noreply@civicrm.org';
126 function __construct() {
127 \$this->fullSandboxPath = \$this->sandboxURL . \$this->sandboxPATH;
138 drush -l "${SITE_URL}" -y pm-enable civicrm
139 drush -l "${SITE_URL}" -y pm-enable civicrm_webtest
140 drush -l "${SITE_URL}" -y user-create --password=demo --mail='demo@example.com' demo
141 drush -l "${SITE_URL}" -y user-add-role civicrm_webtest_user demo