end to end testing

这个提交包含在:
Patrick Burns 2024-04-05 15:36:16 -05:00
父节点 36f05bdef3
当前提交 238f1e66fa
共有 20 个文件被更改,包括 2393 次插入13 次删除

9
.env.sample 普通文件
查看文件

@ -0,0 +1,9 @@
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=cloudlog
MYSQL_USER=cloudlog
MYSQL_PASSWORD=cloudlogpassword
MYSQL_HOST=db
MYSQL_PORT=3306
BASE_LOCATOR=IO91WM
WEBSITE_URL=http://localhost
DIRECTORY=/var/www/html

20
.github/workflows/main.yml vendored 普通文件
查看文件

@ -0,0 +1,20 @@
name: Cypress Tests
on: [pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup .env
run: cp .env.sample .env
- name: Build Docker services
run: docker-compose up -d
- name: Install Cypress
run: npm install cypress
- name: Run Cypress tests
run: npx cypress run

3
.gitignore vendored
查看文件

@ -13,8 +13,11 @@
/assets/qslcard/*
/assets/sstvimages/*
/assets/js/sections/custom.js
/cypress/screenshots
/node_modules
.idea/*
.DS_Store
sync.sh
*.p12
*.swp
.env

44
Dockerfile 普通文件
查看文件

@ -0,0 +1,44 @@
# Use the official image for PHP and Apache
FROM php:7.4-apache
# Set the working directory to /var/www/html
WORKDIR /var/www/html
# Install system dependencies, including git and libxml2
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libxml2-dev \
libzip-dev \
zlib1g-dev \
libpng-dev \
libonig-dev \
default-mysql-client \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install gd \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install zip \
&& docker-php-ext-install xml \
&& a2enmod rewrite
# # Copy .env, config.php, and database.php into the docker image
# COPY .env ./
# COPY install/config/config.php install/config/
# COPY install/config/database.php install/config/
# # Add a script that reads the .env file and replaces the variables in the config.php and database.php files
# ADD script.sh ./
# RUN chmod +x script.sh
# # Run the script at build time
# RUN ./script.sh
# # Create the application/config directory
# RUN mkdir -p application/config
# Expose port 80
EXPOSE 80

8
Dockerfile-db 普通文件
查看文件

@ -0,0 +1,8 @@
# Dockerfile-db
FROM mariadb:latest
# Add the install.sql file to the docker image
ADD install/assets/install.sql /docker-entrypoint-initdb.d
# Expose port 3306
EXPOSE 3306

查看文件

@ -11,24 +11,58 @@ Core Contributors: 2M0SQL ([@magicbug](https://github.com/magicbug)), LA8AJA ([@
Website: [http://www.cloudlog.co.uk](http://www.cloudlog.co.uk)
## Requirements
* Linux based Operating System
* Apache (Nginx should work)
* PHP Version 7.4 (PHP 8.2 works)
* MySQL (MySQL 5.7 or higher)
- Linux based Operating System
- Apache (Nginx should work)
- PHP Version 7.4 (PHP 8.2 works)
- MySQL (MySQL 5.7 or higher)
Notes
* If you want to log microwave QSOs you will need to use a 64bit operating system.
* We do not provide Docker support, however you are free to use it if you wish but we will not handle support.
- If you want to log microwave QSOs you will need to use a 64bit operating system.
- We do not provide Docker support, however you are free to use it if you wish but we will not handle support.
## Setup
Installation information can be found on the [wiki](https://github.com/magicbug/Cloudlog/wiki).
# Docker Development Environment
This guide provides instructions for setting up a local development environment using Docker and Docker Compose. Please note that this setup is not recommended for production use.
## Prerequisites
Before you begin, you need to install Docker and Docker Compose. You can download them using the following links:
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)
## Configuration
1. Copy the `.env.sample` file to `.env`:
```bash
cp .env.sample .env
```
2. Open the `.env` file and update the values to match your setup. The values from the `.env` file will be used to populate the database connection details on the install page. You should not need to change these unless your setup requires different values.
**Note:** Docker Compose creates a network for your application, and each service (container) in the Docker Compose file can reach each other via the service name. This is why the `DB_HOST` value in the `.env` file and on the install page should match the service name of the database in the `docker-compose.yml` file. For example, if the database service in `docker-compose.yml` is defined as `db`, then `DB_HOST` should be set as 'db'. This allows the application to communicate with the database service on its internal docker network.
## Starting the Development Environment
To start the development environment, run the following command in your terminal:
```bash
docker-compose up
```
## Support
Cloudlog has two support systems for code issues use Github issues, however if you have general issues with setting up your server please use our general discussion forum [https://github.com/magicbug/Cloudlog/discussions](https://github.com/magicbug/Cloudlog/discussions).
## Security Vulnerabilities
If you discover a security vulnerability within Cloudlog, please send an e-mail to Peter Goodhall, 2M0SQL via [peter@magicbug.co.uk](mailto:peter@magicbug.co.uk). All security vulnerabilities will be promptly addressed.
## Want Cloudlog Hosting?
@ -53,4 +87,4 @@ Cloudlog is supported by Patreon and donations via PayPal, thanks to the followi
Paul (M0TZO), Tim (G4VXE), Paul (N8HM), Michelle (W5NYV), Mitchell (AD0HJ), Dan (M0TCB), Martin (DK3ML), Juan Carlos (EA5WA), Iain (M0PCB), Charlie (GM1TGY), Ondrej (OK1CDJ), Trystan (G0KAY), Oliver (DL6KBG), Volkmar Schirmer, Jordan (M0PIR), Thomas Ziegler, Mathis (DB9MAT), Ken (VE3HLS), Tyler (WL7T), Jeremy Taylor, Ben Kuhn, Eric Thresher, Michael Cullen, Juuso (OH1JW), Anthony Castiglia, Fernando Ramirez-Ferrer, Robert Dixon, Mark Percival, Julia (KV1V), Timo Tomasini, Ant (NU1U), Christopher Williams, Danny Barnes, Vic, Tom (M0LTE), smurphboy, Lars (SM0TGU), Theo (PD9DP), Stefan (SM0RGM). Peter (G0ABI), Lou (KI5FTY), Michael (DG3NAB), Dragan (4O4A), minorsecond, Emily (W7AYQ), Steve (M0SKM), Rob (M0VFC), Doug (WA6L), Petr (OK1PKR), Fabian (HB9HIL), Daniel (OK2VLK), John (M5JFS).
If you'd like to donate to Cloudlog to help allow @magicbug spend less time doing commercial work and more time coding Cloudlog then you can donate via [PayPal](https://paypal.me/PGoodhall), [Github Sponsor](https://github.com/sponsors/magicbug) or become a [Patreon](https://www.patreon.com/2m0sql)
If you'd like to donate to Cloudlog to help allow @magicbug spend less time doing commercial work and more time coding Cloudlog then you can donate via [PayPal](https://paypal.me/PGoodhall), [Github Sponsor](https://github.com/sponsors/magicbug) or become a [Patreon](https://www.patreon.com/2m0sql)

查看文件

@ -59,6 +59,10 @@ class User_Options extends CI_Controller {
echo json_encode($jsonout);
}
public function enableVersionDialog() {
$this->user_options_model->set_option('version_dialog', 'confirmed', array('boolean' => 'false'));
}
public function dismissVersionDialog() {
$this->user_options_model->set_option('version_dialog', 'confirmed', array('boolean' => 'true'));
}

查看文件

@ -153,7 +153,7 @@
<?php } ?>
</div>
<a class="dropdown-item" href="javascript:qso_delete(<?php echo $row->COL_PRIMARY_KEY; ?>, '<?php echo $row->COL_CALL; ?>')"><i class="fas fa-trash-alt"></i> <?php echo lang('general_delete_qso'); ?></a>
<a class="dropdown-item" id="qso_delete" href="javascript:qso_delete(<?php echo $row->COL_PRIMARY_KEY; ?>, '<?php echo $row->COL_CALL; ?>')"><i class="fas fa-trash-alt"></i> <?php echo lang('general_delete_qso'); ?></a>
</div>
</td>
<?php } ?>

查看文件

@ -422,7 +422,7 @@
<?php if(($this->config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) { ?>
<br>
<div style="display: inline-block;"><p class="editButton"><a class="btn btn-primary" href="<?php echo site_url('qso/edit'); ?>/<?php echo $row->COL_PRIMARY_KEY; ?>" href="javascript:;"><i class="fas fa-edit"></i> <?php echo lang('qso_btn_edit_qso'); ?></a></p></div>
<div style="display: inline-block;"><p class="editButton"><a class="btn btn-primary" href="javascript:qso_edit(<?php echo $row->COL_PRIMARY_KEY; ?>)"><i class="fas fa-edit"></i> <?php echo lang('qso_btn_edit_qso'); ?></a></p></div>
<div style="display: inline-block;"><form method="POST" action="<?php echo site_url('search'); ?>"><input type="hidden" value="<?php echo strtoupper($row->COL_CALL); ?>" name="callsign"><button class="btn btn-primary" type="submit"><i class="fas fa-eye"></i> <?php echo lang('general_more_qso'); ?></button></form></div>
<?php } ?>

11
cypress.config.js 普通文件
查看文件

@ -0,0 +1,11 @@
const { defineConfig } = require("cypress");
module.exports = defineConfig({
projectId: 'gm8wco',
e2e: {
baseUrl: "http://localhost/",
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});

22
cypress/e2e/1-login.cy.js 普通文件
查看文件

@ -0,0 +1,22 @@
describe("Login Test", () => {
it("Should log in successfully", () => {
// Define the username and password
const username = "m0abc";
const password = "demo";
// Visit the login page
cy.visit("/index.php/user/login");
// Type the username and password into the input fields
cy.get('input[name="user_name"]').type(username);
cy.get('input[name="user_password"]').type(password);
// Click the login button
cy.get('button[type="submit"]').click();
// Check if the login was successful
// This could be checking/ for a URL change, looking for a log out button, etc.
cy.url().should("include", "/dashboard");
cy.contains("Logout");
});
});

查看文件

@ -0,0 +1,46 @@
describe("Version Info Modal", () => {
beforeEach(() => {
cy.login();
cy.request(
"POST",
"http://localhost/index.php/user_options/enableVersionDialog"
).wait(1000);
});
it("should open after login", () => {
// check if the modal is visible
cy.get(".modal-title").contains("Version Info").should("be.visible");
});
it("should close after clicking 'Close' button", () => {
// check if the modal is visible
cy.get(".modal-title").contains("Version Info").should("be.visible");
// click the 'Close' button
cy.get("button")
.contains("Close")
.should("be.visible")
.wait(500)
.click();
// check if the modal is not visible
cy.get(".modal-title")
.contains("Version Info")
.should("not.be.visible");
});
it("should not show again after clicking 'Don't show again' button", () => {
// check if the modal is visible
cy.get(".modal-title").contains("Version Info").should("be.visible");
// click the 'Close' button
cy.get("button")
.contains("Don't show again")
.should("be.visible")
.wait(500)
.click();
// check if the modal is not visible
cy.get(".modal-title")
.contains("Version Info")
.should("not.be.visible");
});
});

47
cypress/e2e/3-qso.cy.js 普通文件
查看文件

@ -0,0 +1,47 @@
// describe("Post QSO Input Form", () => {
// beforeEach(() => {
// cy.login();
// });
// it("Submits a QSO", () => {
// cy.visit("index.php/qso?manual=1");
// cy.get('select[name="mode"]').select("USB");
// cy.get('select[name="band"]').select("20m");
// cy.get('#qso_input input[name="callsign"]').first().type("KS3CKC");
// // Submit the QSO
// cy.get("#qso_input").submit();
// // Check if the QSO was added to the log
// cy.visit("index.php/dashboard");
// cy.get("table > tbody > tr:first").within(() => {
// cy.get("td").eq(2).should("contain", "KS3CKC");
// cy.get("td").eq(3).should("contain", "USB");
// cy.get("td").eq(6).should("contain", "20m");
// });
// });
// it("Delete a QSO", () => {
// cy.visit("index.php/dashboard");
// // Click the link in the first row of the table to open the modal
// cy.get("table > tbody > tr:first").within(() => {
// cy.get("a").first().click();
// });
// // Click the "Edit QSO" button
// cy.get("a").contains("Edit QSO").should("be.visible").click();
// // Click the delete button
// cy.get("a")
// .contains("Delete QSO")
// .scrollIntoView()
// .should("be.visible")
// .click();
// // Click the confirm delete button
// cy.get("button").contains("OK").should("be.visible").click();
// });
// });

查看文件

@ -0,0 +1,8 @@
Cypress.Commands.add("login", () => {
const username = "m0abc";
const password = "demo";
cy.visit("/index.php/user/login");
cy.get('input[name="user_name"]').type(username);
cy.get('input[name="user_password"]').type(password);
cy.get('button[type="submit"]').click();
});

20
cypress/support/e2e.js 普通文件
查看文件

@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')

25
docker-compose.yml 普通文件
查看文件

@ -0,0 +1,25 @@
version: "3.8"
services:
web:
build: .
env_file:
- .env
ports:
- "80:80"
volumes:
- ./:/var/www/html:rw
command: ["./script.sh"]
depends_on:
- db
db:
build:
context: .
dockerfile: Dockerfile-db
env_file:
- .env
volumes:
- db_data:/var/lib/mysql
volumes:
db_data: {}

查看文件

@ -148,10 +148,10 @@ if($_POST) {
<fieldset>
<legend>Database settings</legend>
<label for="hostname">Hostname</label><input type="text" id="hostname" value="localhost" class="input_text" name="hostname" />
<label for="username">Username</label><input type="text" id="username" class="input_text" name="username" />
<label for="password">Password</label><input type="password" id="password" class="input_text" name="password" />
<label for="database">Database Name</label><input type="text" id="database" class="input_text" name="database" />
<label for="hostname">Hostname</label><input type="text" id="hostname" value="<?php echo getenv('MYSQL_HOST') ?: 'localhost'; ?>" class="input_text" name="hostname" />
<label for="username">Username</label><input type="text" id="username" value="<?php echo getenv('MYSQL_USER'); ?>" class="input_text" name="username" />
<label for="password">Password</label><input type="password" id="password" value="<?php echo getenv('MYSQL_PASSWORD'); ?>" class="input_text" name="password" />
<label for="database">Database Name</label><input type="text" id="database" value="<?php echo getenv('MYSQL_DATABASE'); ?>" class="input_text" name="database" />
<input type="submit" value="Install" id="submit" />
</fieldset>
</form>

1981
package-lock.json 自动生成的 普通文件

文件差异内容过多而无法显示 加载差异

15
package.json 普通文件
查看文件

@ -0,0 +1,15 @@
{
"name": "cloudlog",
"version": "1.0.0",
"description": "> Important: Only accepting PRs on the \"dev\" branch.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"cypress": "^13.7.2"
}
}

83
script.sh 可执行文件
查看文件

@ -0,0 +1,83 @@
#!/bin/bash
# Define the file path for .env and the file to modify
if [ -f "./.env" ]; then
ENV_FILE="./.env"
else
ENV_FILE="./.env.sample"
fi
CONFIG_FILE="install/config/config.php"
DATABASE_FILE="install/config/database.php"
DEST_DIR="application/config"
# Check if .env file exists
if [ ! -f "$ENV_FILE" ]; then
echo ".env file not found!"
exit 1
fi
# Read the .env file
source $ENV_FILE
# Check if MYSQL_DATABASE is set
if [ -z "${MYSQL_DATABASE}" ]; then
echo "MYSQL_DATABASE is not set in .env file!"
exit 1
fi
# Check if MYSQL_USER is set
if [ -z "${MYSQL_USER}" ]; then
echo "MYSQL_USER is not set in .env file!"
exit 1
fi
# Check if MYSQL_PASSWORD is set
if [ -z "${MYSQL_PASSWORD}" ]; then
echo "MYSQL_PASSWORD is not set in .env file!"
exit 1
fi
# Check if MYSQL_HOST is set
if [ -z "${MYSQL_HOST}" ]; then
echo "MYSQL_HOST is not set in .env file!"
exit 1
fi
# Check if BASE_LOCATOR is set
if [ -z "${BASE_LOCATOR}" ]; then
echo "BASE_LOCATOR is not set in .env file!"
exit 1
fi
# Check if WEBSITE_URL is set
if [ -z "${WEBSITE_URL}" ]; then
echo "WEBSITE_URL is not set in .env file!"
exit 1
fi
# Check if DIRECTORY is set
if [ -z "${DIRECTORY}" ]; then
echo "DIRECTORY is not set in .env file!"
exit 1
fi
# Check if destination directory exists, if not create it
if [ ! -d "$DEST_DIR" ]; then
mkdir -p $DEST_DIR
fi
# Use sed with a different delimiter (`|`) to avoid conflicts with special characters
sed -i "s|%DATABASE%|${MYSQL_DATABASE}|g" $DATABASE_FILE
sed -i "s|%USERNAME%|${MYSQL_USER}|g" $DATABASE_FILE
sed -i "s|%PASSWORD%|${MYSQL_PASSWORD}|g" $DATABASE_FILE
sed -i "s|%HOSTNAME%|${MYSQL_HOST}|g" $DATABASE_FILE
sed -i "s|%baselocator%|${BASE_LOCATOR}|g" $CONFIG_FILE
sed -i "s|%websiteurl%|${WEBSITE_URL}|g" $CONFIG_FILE
sed -i "s|%directory%|${DIRECTORY}|g" $CONFIG_FILE
# Move the files to the destination directory
mv $CONFIG_FILE $DEST_DIR
mv $DATABASE_FILE $DEST_DIR
# Delete the /install directory
rm -rf /install
echo "Replacement complete."
# Start Apache in the foreground
exec apache2-foreground