Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ RUN apt-get update \
# Install extensions (optional)
&& docker-php-ext-install pdo_mysql \

# Install composer
&& curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \
# Enable URL rewriting using .htaccess
&& a2enmod rewrite \

# Install Node and Angular
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get -y install nodejs \
&& npm install -g @angular/cli \

# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
Expand All @@ -55,4 +66,4 @@ USER vscode
# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
COPY docker-entrypoint.sh /usr/local/bin
ENTRYPOINT [ "docker-entrypoint.sh" ]
ENTRYPOINT [ "docker-entrypoint.sh" ]
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"service": "hashtopolis",
"runServices": ["db"],

"appPort": [8080],
"appPort": [8080, 4200],

"workspaceMount": "src=${localWorkspaceFolder},dst=/var/www/html,type=bind,consistency=cached",
"workspaceFolder": "/var/www/html",
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
- db
ports:
- "8080:80"
- "4200:4200"
volumes:
# This is where VS Code should expect to find your project's source code
# and the value of "workspaceFolder" in .devcontainer/devcontainer.json
Expand Down
15 changes: 15 additions & 0 deletions .devcontainer/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#!/bin/sh

echo "Install dependencies"
if [ ! -d /var/www/html/vendor ];
then
composer install --working-dir=/var/www/html
fi
composer update --working-dir=/var/www/html

if [ ! -d /var/www/html/ui/node_modules ];
then
cd /var/www/html/ui/ && npm install
fi

cd /var/www/html/ui/ && ng build
ng serve --host 0.0.0.0 &

echo "Testing database."
MYSQL="mysql -uhashtopolis -phashtopolis -hdb"
$MYSQL -e "SELECT 1"
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/sites-enabled/000-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
DocumentRoot /var/www/html/src
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/src/api/v2>
AllowOverride All
</Directory>
</VirtualHost>
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ src/files/*
*.sln
*.phpproj.user
*.lock
vendor/
/ci/apiv2/behat-guzzle-cookie-data.json

# for docker stuff
.env

# for Angular stuff
dist/
node_modules/
.angular
9 changes: 9 additions & 0 deletions ci/apiv2/behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
default:
formatters:
pretty: true
suites:
default:
contexts:
- FeatureContext
- RestContext:
baseUrl: http://localhost:80/
77 changes: 77 additions & 0 deletions ci/apiv2/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

require_once __DIR__ . '/../../../../src/inc/conf.php';
require_once __DIR__ . '/../../../../src/dba/init.php';
require_once __DIR__ . '/../../../../src/inc/defines/config.php';
require_once __DIR__ . '/../../../../src/inc/info.php';
require_once __DIR__ . '/../../../../src/inc/Util.class.php';
require_once __DIR__ . '/../../../../src/inc/Encryption.class.php';
require_once __DIR__ . '/../../../../src/inc/utils/AccessUtils.class.php';
require_once __DIR__ . '/../../../HashtopolisTest.class.php';
require_once __DIR__ . '/../../../HashtopolisTestFramework.class.php';

use DBA\Factory;

// TODO: refactor to clean implementation when kept!
class FeatureContext implements Behat\Behat\Context\Context {

private static $dbBackupFile;

/**
* @BeforeSuite
*/
public static function backupDatabase() {
self::backup();
}

/**
* @BeforeFeature @requiresDB
*/
public static function setupTestDatabase() {
// TODO: hack, should be implemented in clean way!
$test = new DummyTestForInitialization();
$test->init('master');
}

/**
* @AfterSuite
*/
public static function restoreDatabase() {
self::restore();
}

private static function backup() {
global $CONN;

if (!file_exists(__DIR__ . '/../../../../ci/db-backups')) {
mkdir(__DIR__ . '/../../../../ci/db-backups');
}

self::$dbBackupFile = __DIR__ . '/../../../../ci/db-backups/database_backup_' . date('Y_m_d-H_i_s'). '.sql';

// Note that the '-y' option avoids requirement on 'PROCESS' privilege for the 'hashtopolis' user!
exec('mysqldump hashtopolis -y -h'.$CONN['server'] . ' -P'.$CONN['port'] . ' -u'.$CONN['user'] . ' -p'.$CONN['pass'] .' > ' . self::$dbBackupFile, $output, $status);
if ($status != 0) {
self::$dbBackupFile = '';
die('test aborted!\n');
}
}

private static function restore() {
if (!empty(self::$dbBackupFile)) {

// drop old data
Factory::getAgentFactory()->getDB()->query('DROP DATABASE IF EXISTS hashtopolis');
Factory::getAgentFactory()->getDB()->query('CREATE DATABASE hashtopolis');
Factory::getAgentFactory()->getDB()->query('USE hashtopolis');

// restore original DB
Factory::getAgentFactory()->getDB()->query(file_get_contents(self::$dbBackupFile));
}
}
}

class DummyTestForInitialization extends HashtopolisTest {
function run() {}
function getTestName() {}
}
Loading