Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 homework teacher feature be able to add links for other sources #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f55830d
Setup js for developement
Oct 14, 2024
9d66932
full window to add literature to homework module
Oct 15, 2024
aa67cec
CAn
Oct 15, 2024
c47890c
updated db for homework
Oct 16, 2024
eca92c0
Finished add links function(need of testing)
Oct 16, 2024
47261e1
Added tests to issue #9 & #10
Oct 17, 2024
25a6a16
tests for both issue #9 & #10 fully done
Oct 18, 2024
cd6fd29
new code fully documented
Oct 18, 2024
79e5747
Created phpunit.yml
AllanVester Oct 18, 2024
0717eae
Updated phpunit.yml
AllanVester Oct 18, 2024
f1b12d2
Updated phpunit.yml
AllanVester Oct 18, 2024
64d4c10
Created codesniffer.yml
AllanVester Oct 18, 2024
580f66b
Updated codesniffer.yml
AllanVester Oct 18, 2024
ad9c53c
Updated view.php - For Codesniffer
AllanVester Oct 18, 2024
839917a
Updated codesniffer.yml - now running moodle-cs' phpcs.xml
AllanVester Oct 18, 2024
837e472
Updated codesniffer.yml - added php-compatibility
AllanVester Oct 18, 2024
db11110
Updated codesniffer.yml - now creates a .phpcs.xml file
AllanVester Oct 18, 2024
46133ed
Updated codesniffer.yml
AllanVester Oct 18, 2024
b272cb5
Reverted view.php
AllanVester Oct 18, 2024
4f8a82e
Merge remote-tracking branch 'origin/10-homework-teacher-feature-be-a…
AllanVester Oct 18, 2024
9d1f85b
codesniffer almost complete
Oct 21, 2024
b127240
fully done codesniffer changes
Oct 21, 2024
45eac1b
Merge branch '10-homework-teacher-feature-be-able-to-add-links-for-ot…
Oct 21, 2024
11292b6
trying again v5
Oct 21, 2024
93da1bd
v6
Oct 21, 2024
4019be4
Merge branch 'main' of github.com:AAU-P5-Moodle/moodle-2 into 10-home…
Verdoner Oct 23, 2024
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
38 changes: 38 additions & 0 deletions .github/workflows/codesniffer.yml
SimonSkywalker marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Codesniffer for Moodle Homework Plugin

on:
push:
branches: [ "10-homework-teacher-feature-be-able-to-add-links-for-other-sources" ]
pull_request:
branches: [ "10-homework-teacher-feature-be-able-to-add-links-for-other-sources" ]

jobs:
homework-plugin-codesniffer:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# Set up Composer
- name: Set up Composer
run: |
composer global config minimum-stability dev
composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require moodlehq/moodle-cs
# Add Composer global bin to PATH
- name: Add Composer global bin to PATH
run: echo "PATH=$HOME/.composer/vendor/bin:$PATH" >> $GITHUB_ENV

# Create .phpcs.xml file with required content
- name: Create .phpcs.xml file
run: |
cat <<EOT >> ./.phpcs.xml
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="MoodleCore">
<rule ref="moodle-extra"/>
</ruleset>
EOT

# Run PHP_CodeSniffer
- name: Run Code Sniffer
run: phpcs server/moodle/mod/homework/
282 changes: 282 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
name: PHPUnit Tests for Moodle Homework Plugin

on:
push:
branches: [ "10-homework-teacher-feature-be-able-to-add-links-for-other-sources" ]
pull_request:
branches: [ "10-homework-teacher-feature-be-able-to-add-links-for-other-sources" ]

jobs:
homework-plugin-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: install mariadb
run: |
sudo apt install mariadb-server
sudo systemctl disable mariadb
sudo systemctl stop mariadb
# uses: getong/[email protected]

- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
extensions: phar, iconv, mbstring, gd, intl, sodium, zip
tools: composer


- name: Set up php.ini
run: >
REPO_ROOT="`pwd`"
sed -i
-e 's/;extension=gd/extension=gd/'
-e 's/;extension=intl/extension=intl/'
-e 's/;extension=sodium/extension=sodium/'
-e 's/;extension=zip/extension=zip/'
-e "s|curl\.cainfo.*|curl.cainfo=\"$REPO_ROOT/cacert.pem\"|"
-e "s|openssl\.cafile.*|openssl.cafile=\"$REPO_ROOT\"/server/apache/bin/curl-ca-bundle.crt|"
-e '$a\\max_input_vars=5000'
-e '$a\\memory_limit_256M'
-e '$a\\post_max_size=50M'
-e '$a\\upload_max_filesize=50M'
-e '$a\\extension=phar.so'
server/php/php.ini

# - name: Install composer
# run: |
# cd server/moodle
# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# php composer-setup.php

- name: Check enabled PHP extensions
run: |
php -m | grep -E 'gd|intl|zip'
php -r "echo phpversion('phar');"
php -r "echo ini_get('max_input_vars');"
more php.ini
realpath php.ini

# - name: Copy php.ini to PHP-CLI directory
# run: |
# sudo cp server/php/php.ini /etc/php/8.2/cli/php.ini

# - uses: "ramsey/composer-install@v3"
# with:
# working-directory: "/etc/php/8.2/cli/php.ini"

- name: install composer
run: |
cd server/moodle
sudo apt-get update
sudo apt-get install curl
sudo apt-get install php php-curl
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo composer self-update
composer -v

- name: Check enabled PHP extensions
run: |
php -m
php --ini

- name: Install the curl certificate
run: curl https://curl.se/ca/cacert.pem >cacert.pem

- name: Set up the database and start mariadb
run: |
set -x
mariadb_data_dir="./mariadb_data"
mariadb_socket="/run/mysqld/mysqld.sock"
moodle_db_name="moodle"
moodle_sql_file="./MoodleSQL.sql"
root_username="root"
root_password="root"

# Function to check and kill existing processes
kill_existing() {
local process=$1
if pgrep -x "$process" > /dev/null; then
echo "Killing existing $process process..."
sudo pkill -x "$process"
sleep 2
fi
}

# Function to kill process using a specific port
kill_port_user() {
local port=$1
local pid=$(lsof -ti:$port)
if [ ! -z "$pid" ]; then
echo "Killing process using port $port..."
sudo kill -9 $pid
sleep 2
fi
}

# Ensure MariaDB data directory exists
mkdir -p ${mariadb_data_dir}
ls -l

# Ensure MariaDB data directory exists
mkdir -p ${mariadb_data_dir}
ls -l

# Initialize MariaDB if not already done
if [ ! -d "${mariadb_data_dir}/mysql" ]; then
mysql_install_db --datadir=${mariadb_data_dir}
# Start MariaDB temporarily to set up the database
# sudo touch ${mariadb_socket}
sudo chmod -R 2777 `dirname ${mariadb_socket}`
mysqld --datadir=${mariadb_data_dir} --socket=${mariadb_socket} --skip-grant-tables &
TEMP_MYSQL_PID=$!
sleep 15 # Increased wait time to ensure MariaDB is ready

mysqld --verbose --help | grep "socket"
ps aux | grep mysqld
# Set root password and authentication method
echo "Setting root password..."
mysql -uroot -S${mariadb_socket} <<EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '${root_password}';
FLUSH PRIVILEGES;
EOF

# Verify root password
echo "Verifying root password..."
mysql -uroot -p${root_password} -S${mariadb_socket} -e "SELECT 1;" || {
echo "Error: Root password verification failed."
kill $TEMP_MYSQL_PID
wait $TEMP_MYSQL_PID
exit 1
}

mysql -uroot -p${root_password} -S${mariadb_socket} -e "CREATE DATABASE IF NOT EXISTS ${moodle_db_name}" || {
echo "Error: Failed to create database ${moodle_db_name}."
kill $TEMP_MYSQL_PID
wait $TEMP_MYSQL_PID
exit 1
}

if [ -f "${moodle_sql_file}" ]; then
mysql -uroot -p${root_password} -S${mariadb_socket} ${moodle_db_name} < ${moodle_sql_file} && {
echo "SQL file imported successfully."
} || {
echo "Error: Failed to import SQL file."
}
else
echo "Warning: ${moodle_sql_file} not found. Database created but not populated."
fi

kill $TEMP_MYSQL_PID
wait $TEMP_MYSQL_PID
fi

# Kill existing MariaDB and PHP processes
kill_existing "mysqld"
kill_existing "php"

# Start MariaDB
start_mariadb() {
echo "Starting MariaDB..."
mysqld --datadir=${mariadb_data_dir} --socket=${mariadb_socket} &
MARIADB_PID=$!
sleep 10 # Increased wait time to ensure MariaDB is ready

# Check if MariaDB socket file is created
if [ ! -S ${mariadb_socket} ]; then
echo "Error: MariaDB socket file not found at ${mariadb_socket}. Exiting..."
exit 1
fi
}

# I do not install adminer because I'm lazy

# Start PHP built-in server for Moodle
start_php_server() {
echo "Starting PHP built-in server for Moodle..."
php -S 0.0.0.0:8000 -t ./server/moodle -c ./server/php/php.ini &
PHP_SERVER_PID=$!
}

# Function to stop services
stop_services() {
echo "Stopping services..."
kill $MARIADB_PID $PHP_SERVER_PID 2>/dev/null
rm -f ${mariadb_socket}
}

# Start services
start_mariadb
start_php_server

echo "MariaDB and PHP server are now running."
echo "Moodle is available at http://localhost:8000"
echo "To connect to MariaDB, use:"
echo " Host: 127.0.0.1 or localhost"
echo " Username: root"
echo " Password: ${root_password}"
echo " Database: ${moodle_db_name}"
echo "Press Ctrl+C to stop the services and exit."

- name: Install and initialise phpunit
run: |
echo en_AU.UTF-8 UTF-8 | sudo tee -a /etc/locale.gen
sudo locale-gen

if [ "$(php -r "echo ini_get('max_input_vars');")" -lt 5000 ]; then
echo "max_input_vars = 5000" >> /etc/php/8.3/cli/php.ini
fi
export LANG="en_AU.UTF-8"
export LC_ALL="en_AU.UTF-8"
export PHPRC=`realpath /etc/php/8.3/cli/php.ini`
# server/php/php.ini`

REPO_ROOT="`pwd`"
cd "$REPO_ROOT"/server/moodle
composer require --dev phpunit/phpunit

if [ ! -d "$REPO_ROOT/server/moodledata/phpunit" ]; then
mkdir "$REPO_ROOT/server/moodledata/phpunit"
fi

php admin/cli/install.php \
--lang=en \
--wwwroot="http://localhost:8000/" \
--dataroot="$REPO_ROOT/server/moodledata" \
--dbpass=root \
--dbport=3306 \
--dbsocket=/run/mysqld/mysqld.sock \
--skip-database \
--non-interactive \
--agree-license \
--allow-unstable \
--fullname="Tests for Moodle Homework Plugin" \
--shortname="mhp" \
--adminpass="Admin.123"

echo "This is the path: $(realpath config.php)"

if [ -f "$REPO_ROOT/server/moodle/config.php" ]; then
echo "File $("$REPO_ROOT/server/moodle/config.php") exist."
else
echo "Can not find $("$REPO_ROOT/server/moodle/config.php") file"
fi

echo "\$CFG->phpunit_prefix = 'phpu_';" >>"$REPO_ROOT/server/moodle/config.php"
echo "\$CFG->phpunit_dataroot = '$(realpath "$REPO_ROOT/server/moodledata/phpunit")';">>"$REPO_ROOT/server/moodle/config.php"

php admin/tool/phpunit/cli/init.php

- name: Run tests
run: |
pwd
cd server/moodle
vendor/bin/phpunit --testsuite mod_homework_testsuite



3 changes: 3 additions & 0 deletions server/moodle/mod/homework/amd/build/homeworkchooser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading