summaryrefslogtreecommitdiffstats
path: root/build/prepareTests.sh
blob: 84bbfd40f6d49fe47cb83d6e3e3b24d89466e2b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
#
# ownCloud
#
# @author Thomas Müller
# @author Morris Jobke
# @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu
# @copyright 2014 Morris Jobke hey@morrisjobke.de
#

DATABASENAME=oc_autotest
DATABASEUSER=oc_autotest
ADMINLOGIN=admin
BASEDIR=$PWD

# check for database parameter
if [ $1 ]; then
	DBCONFIGS="sqlite mysql pgsql oracle"
	FOUND=0
	for DBCONFIG in $DBCONFIGS; do
		if [ $1 = $DBCONFIG ]; then
			FOUND=1
			break
		fi
	done
	if [ $FOUND = 0 ]; then
		echo -e "Unknown database config name \"$1\"\n" >&2
		exit 2
	fi
else
	echo "Please pass in a database to use as first parameter" >&2
	exit 1
fi

# check if config dir and file is writable
if ! [[ -w config && ( !( -e config/config.php ) || -w config/config.php ) ]]; then
	echo "Please enable write permissions on config and config/config.php" >&2
	exit 1
fi

# use tmpfs for datadir - should speedup unit test execution
if [ -d /dev/shm ]; then
	DATADIR=/dev/shm/data-autotest
else
	DATADIR=$BASEDIR/data-autotest
fi

echo "Setup environment for $1 testing ..."
# revert changes to tests/data
git checkout tests/data/*

# reset data directory
rm -rf $DATADIR
mkdir $DATADIR

cp tests/preseed-config.php config/config.php

# # # # # #
# SQLite  #
# # # # # #
if [ "$1" == "sqlite" ] ; then
	cat > ./config/autoconfig.php <<DELIM
<?php
\$AUTOCONFIG = array (
	'installed' => false,
	'dbtype' => 'sqlite',
	'dbtableprefix' => 'oc_',
	'adminlogin' => '$ADMINLOGIN',
	'adminpass' => 'admin',
	'directory' => '$DATADIR',
);
DELIM
fi

# # # # #
# MySQL #
# # # # #
if [ "$1" == "mysql" ] ; then
	cat > ./config/autoconfig.php <<DELIM
<?php
\$AUTOCONFIG = array (
	'installed' => false,
	'dbtype' => 'mysql',
	'dbtableprefix' => 'oc_',
	'adminlogin' => '$ADMINLOGIN',
	'adminpass' => 'admin',
	'directory' => '$DATADIR',
	'dbuser' => '$DATABASEUSER',
	'dbname' => '$DATABASENAME',
	'dbhost' => 'localhost',
	'dbpass' => 'owncloud',
);
DELIM
fi

# # # # # # # #
# PostgreSQL  #
# # # # # # # #
if [ "$1" == "pgsql" ] ; then
	cat > ./config/autoconfig.php <<DELIM
<?php
\$AUTOCONFIG = array (
	'installed' => false,
	'dbtype' => 'pgsql',
	'dbtableprefix' => 'oc_',
	'adminlogin' => '$ADMINLOGIN',
	'adminpass' => 'admin',
	'directory' => '$DATADIR',
	'dbuser' => '$DATABASEUSER',
	'dbname' => '$DATABASENAME',
	'dbhost' => 'localhost',
	'dbpass' => 'owncloud',
);
DELIM

fi

# # # # # #
# Oracle  #
# # # # # #
if [ "$1" == "oracle" ] ; then
	build/prepareTestsOracle.sh $DATABASENAME $DATABASEUSER $ADMINLOGIN $DATADIR
fi

echo "Trigger ownCloud installation"
php -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101

echo "Enable apps ..."
cd tests
php -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101
cd $BASEDIR

# show environment
echo "ownCloud configuration:"
cat $BASEDIR/config/config.php

echo "ownCloud data directory:"
ls -ll $DATADIR

echo "owncloud.log:"
cat $DATADIR/owncloud.log