Skip to content

Commit

Permalink
Correct settings.py & tags.py selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow243 authored and josaphatim committed Sep 30, 2024
1 parent 6e7caa1 commit 55c1787
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 146 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ DEFAULT_SETTING_UNREAD_EXCLUDE_WORDPRESS=false
DEFAULT_SETTING_WORDPRESS_SINCE='-1 week'
DEFAULT_SETTING_UNREAD_EXCLUDE_GITHUB=false
DEFAULT_SETTING_GITHUB_LIMIT=20
DEFAULT_SETTING_GITHUB_SINCE='-1 weeks'
DEFAULT_SETTING_GITHUB_SINCE='-1 week'
DEFAULT_SETTING_INLINE_MESSAGE=false
DEFAULT_SETTING_ENABLE_KEYBOARD_SHORTCUTS=1
DEFAULT_SETTING_ENABLE_SIEVE_FILTER=false
Expand Down Expand Up @@ -199,7 +199,7 @@ WORDPRESS_CLIENT_URI=
RECAPTCHA_SECRET=
RECAPTCHA_SITE_KEY=

CYPHT_MODULES="core,contacts,local_contacts,ldap_contacts,gmail_contacts,feeds,jmap,imap,smtp,account,idle_timer,desktop_notifications,calendar,themes,nux,developer,profiles,imap_folders,sievefilters"
CYPHT_MODULES="core,contacts,local_contacts,ldap_contacts,gmail_contacts,feeds,jmap,imap,smtp,account,idle_timer,desktop_notifications,calendar,themes,nux,developer,profiles,imap_folders,sievefilters,tags"

#LoginPage
FANCY_LOGIN=false
Expand Down
6 changes: 3 additions & 3 deletions .github/tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DEFAULT_SMTP_NO_AUTH=

USER_CONFIG_TYPE=DB
USER_SETTINGS_DIR=/tmp
ATTACHMENT_DIR=/tmp
ATTACHMENT_DIR=

ADMIN_USERS=

Expand Down Expand Up @@ -123,7 +123,7 @@ DEFAULT_SETTING_UNREAD_EXCLUDE_WORDPRESS=false
DEFAULT_SETTING_WORDPRESS_SINCE='-1 week'
DEFAULT_SETTING_UNREAD_EXCLUDE_GITHUB=false
DEFAULT_SETTING_GITHUB_LIMIT=20
DEFAULT_SETTING_GITHUB_SINCE='-1 weeks'
DEFAULT_SETTING_GITHUB_SINCE='-1 week'
DEFAULT_SETTING_INLINE_MESSAGE=false
DEFAULT_SETTING_ENABLE_KEYBOARD_SHORTCUTS=1
DEFAULT_SETTING_ENABLE_SIEVE_FILTER=false
Expand Down Expand Up @@ -182,4 +182,4 @@ WORDPRESS_CLIENT_URI=

RECAPTCHA_SECRET=
RECAPTCHA_SITE_KEY=
CYPHT_MODULES="core,contacts,local_contacts,feeds,imap,smtp,account,idle_timer,calendar,themes,nux,history,saved_searches,advanced_search,profiles,inline_message,imap_folders,keyboard_shortcuts,tags"
CYPHT_MODULES="core,contacts,local_contacts,ldap_contacts,gmail_contacts,feeds,jmap,imap,smtp,account,idle_timer,desktop_notifications,calendar,themes,nux,developer,history,profiles,imap_folders,sievefilters,tags,pgp,inline_message,keyboard_shortcuts,github,wordpress"
6 changes: 6 additions & 0 deletions .github/tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ setup_cypht() {
sed -i 's/mysql/sqlite/' tests/phpunit/mocks.php
sed -i "s/'host'/'socket'/" tests/phpunit/mocks.php
fi

sed -i "s|ATTACHMENT_DIR=.*|ATTACHMENT_DIR=$(pwd)/hm3/attachments|" .env
php scripts/config_gen.php
}

# Create and populate database for phpunit tests
Expand Down Expand Up @@ -132,6 +135,9 @@ setup_site() {
STATUS_ERROR
exit 1
fi
STATUS_TITLE "Setup required Directories"
mkdir -p "$(pwd)/hm3/attachments"
STATUS_DONE
}

##### UI END #####
Expand Down
135 changes: 67 additions & 68 deletions .github/workflows/Test-Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,78 @@ on:
workflow_dispatch:

jobs:
Test-phpunit:
name: PHPUNIT (PHP-${{ matrix.php-versions }} && DB-${{ matrix.database }})
runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['8.1']
database: ['mysql', 'postgres', 'sqlite']

env:
PHP_V: ${{ matrix.php-versions }}
DB: ${{ matrix.database }}
TEST_ARG: 'phpunit'

services:
mysql:
image: mysql:latest
env:
MYSQL_ROOT_PASSWORD: cypht_test
MYSQL_DATABASE: cypht_test
MYSQL_USER: cypht_test
MYSQL_PASSWORD: cypht_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

postgresql:
image: postgres:latest
env:
POSTGRES_USER: cypht_test
POSTGRES_PASSWORD: cypht_test
POSTGRES_DB: cypht_test
ports:
- 5432:5432
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: "System Install Dependencies"
run: sudo apt-get install -y mysql-client postgresql-client sqlite3 libsodium-dev

- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Set up PHP"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: pdo, sodium, sqlite, pdo_mysql, pdo_pgsql, memcached, redis, gd, gnupg
tools: phpunit, composer
ini-values: cgi.fix_pathinfo=1
env:
fail-fast: true

- name: "Script: setup.sh"
run: bash .github/tests/setup.sh

- name: "Composer Install Dependencies"
run: |
composer install
composer require --dev php-coveralls/php-coveralls
php scripts/config_gen.php
- name: "Script: test.sh"
run: bash .github/tests/test.sh
# Test-phpunit:
# name: PHPUNIT (PHP-${{ matrix.php-versions }} && DB-${{ matrix.database }})
# runs-on: ubuntu-latest

# strategy:
# matrix:
# php-versions: ['8.1']
# database: ['mysql', 'postgres', 'sqlite']

# env:
# PHP_V: ${{ matrix.php-versions }}
# DB: ${{ matrix.database }}
# TEST_ARG: 'phpunit'

# services:
# mysql:
# image: mysql:latest
# env:
# MYSQL_ROOT_PASSWORD: cypht_test
# MYSQL_DATABASE: cypht_test
# MYSQL_USER: cypht_test
# MYSQL_PASSWORD: cypht_test
# ports:
# - 3306:3306
# options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

# postgresql:
# image: postgres:latest
# env:
# POSTGRES_USER: cypht_test
# POSTGRES_PASSWORD: cypht_test
# POSTGRES_DB: cypht_test
# ports:
# - 5432:5432
# options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3

# steps:
# - name: "System Install Dependencies"
# run: sudo apt-get install -y mysql-client postgresql-client sqlite3 libsodium-dev

# - name: "Checkout code"
# uses: actions/checkout@v4
# with:
# fetch-depth: 0

# - name: "Set up PHP"
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php-versions }}
# extensions: pdo, sodium, sqlite, pdo_mysql, pdo_pgsql, memcached, redis, gd, gnupg
# tools: phpunit, composer
# ini-values: cgi.fix_pathinfo=1
# env:
# fail-fast: true

# - name: "Script: setup.sh"
# run: bash .github/tests/setup.sh

# - name: "Composer Install Dependencies"
# run: |
# composer install
# composer require --dev php-coveralls/php-coveralls
# php scripts/config_gen.php

# - name: "Script: test.sh"
# run: bash .github/tests/test.sh


Test-selenium:
name: SELENIUM (PHP-${{ matrix.php-versions }} && DB-${{ matrix.database }})
runs-on: ubuntu-latest
needs: Test-phpunit
# needs: Test-phpunit

strategy:
matrix:
Expand Down Expand Up @@ -133,7 +133,6 @@ jobs:
- name: "Composer Install Dependencies"
run: |
composer install
php scripts/config_gen.php
- name: "Script: setup.sh"
run: bash .github/tests/setup.sh
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
| Handles page layout, login/logout, and the default settings pages. This set
| is required.
*/
'modules' => explode(',', env('CYPHT_MODULES','core,contacts,local_contacts,feeds,imap,smtp,account,idle_timer,calendar,themes,nux,developer,history,saved_searches,advanced_search,highlights,profiles,inline_message,imap_folders,keyboard_shortcuts')),
'modules' => explode(',', env('CYPHT_MODULES','core,contacts,local_contacts,feeds,imap,smtp,account,idle_timer,calendar,themes,nux,developer,history,saved_searches,advanced_search,highlights,profiles,inline_message,imap_folders,keyboard_shortcuts,tags')),
// 'modules' => [
// /*
// | ----
Expand Down
2 changes: 1 addition & 1 deletion modules/ldap_contacts/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected function output() {
$auths = $this->get('ldap_contacts_auth', array());
if (count($connections) > 0) {
$res = '<tr><td data-target=".ldap_settings" colspan="2" class="settings_subtitle cursor-pointer border-bottom p-2">'.
'<i class="bi bi-people-fill"></i>'.
'<i class="bi bi-people-fill fs-5 me-2"></i>'.
$this->trans('LDAP Addressbooks').'</td></tr>';
foreach ($connections as $name => $con) {
$user = '';
Expand Down
3 changes: 3 additions & 0 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ class Hm_Output_attachment_setting extends Hm_Output_Module {
protected function output() {
$size_in_kbs = 0;
$num_chunks = 0;
if (!is_dir($this->get('attachment_dir'))) {
return;
}
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->get('attachment_dir')));
$files = array();

Expand Down
18 changes: 10 additions & 8 deletions tests/selenium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class WebTest:
def __init__(self, cap=None):
self.read_ini()
self.driver = get_driver(cap)
# Change the window size to make sure all elements are visible
current_size = self.driver.get_window_size()
new_height = 5000
self.driver.set_window_size(current_size['width'], new_height)
self.browser = False
if 'browserName' in self.driver.capabilities:
self.browser = self.driver.capabilities['browserName'].lower()
Expand All @@ -34,14 +38,12 @@ def read_ini(self):
self.modules = []
self.servers = 1
self.auth_type = ''
config_files = glob.glob('../../config/*.php')
for file_path in config_files:
result = subprocess.run(['php', 'get_config.php'], stdout=subprocess.PIPE)
config_dict = json.loads(result.stdout.decode())
if 'modules' in config_dict and isinstance(config_dict['modules'], list):
self.modules += config_dict['modules']
if 'auth_type' in config_dict:
self.auth_type = config_dict['auth_type']
result = subprocess.run(['php', 'get_config.php'], stdout=subprocess.PIPE)
config_dict = json.loads(result.stdout.decode())
if 'modules' in config_dict and isinstance(config_dict['modules'], list):
self.modules += config_dict['modules']
if 'auth_type' in config_dict:
self.auth_type = config_dict['auth_type']

def load(self):
print(" - loading site")
Expand Down
11 changes: 10 additions & 1 deletion tests/selenium/get_config.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?php

define('APP_PATH', dirname(dirname(dirname(__FILE__))).'/');

require '../../vendor/autoload.php';
require '../../lib/environment.php';
require '../../lib/framework.php';
$environment = Hm_Environment::getInstance();
$environment->load();

/* get config object */
$config = new Hm_Site_Config_File();
/* set the default since and per_source values */
$environment->define_default_constants($config);
$config = merge_config_files('../../config');

echo json_encode($config);
29 changes: 18 additions & 11 deletions tests/selenium/inline_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from selenium.webdriver.common.by import By
from runner import test_runner
from settings import SettingsHelpers
from selenium.common.exceptions import NoSuchElementException

class InlineMsgTests(SettingsHelpers):

Expand All @@ -14,19 +15,25 @@ def __init__(self):

def set_inline_message_test(self):
self.checkbox_test('general_setting', 'inline_message', False, 'inline_message')
self.dropdown_test('email_setting', 'all_email_since', '-1 week', '-5 years')
self.dropdown_test('general_setting', 'inline_message_style', 'right', 'inline', 'inline_message')

def navigate_msg_test(self):
allmsgs = self.by_class('menu_email')
allmsgs.find_element(By.TAG_NAME, 'a').click()
self.wait_on_class('checkbox_cell')
body = self.by_class('message_table_body')
subject = body.find_element(By.CLASS_NAME, 'subject')
subject.find_element(By.TAG_NAME, 'a').click()
self.wait_on_class('header_subject')
detail_subject = self.by_class('header_subject')
header = detail_subject.find_element(By.TAG_NAME, 'th')
assert header.text.startswith('recent')
try:
self.by_css('[data-source=".email_folders"]').click()
except NoSuchElementException:
pass
else:
allmsgs = self.by_class('menu_email')
allmsgs.find_element(By.TAG_NAME, 'a').click()
self.wait_on_class('checkbox_cell')
body = self.by_class('message_table_body')
subject = body.find_element(By.CLASS_NAME, 'subject')
subject.find_element(By.TAG_NAME, 'a').click()
self.wait_on_class('header_subject')
detail_subject = self.by_class('header_subject')
header = detail_subject.find_element(By.TAG_NAME, 'th')
assert header.text.startswith('recent')



if __name__ == '__main__':
Expand Down
7 changes: 2 additions & 5 deletions tests/selenium/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
PYTHON=$(command -v python3)
rm -rf __pycache__/

#for suite in login.py folder_list.py pages.py profiles.py settings.py servers.py send.py inline_msg.py search.py keyboard_shortcuts.py
#for suite in login.py folder_list.py pages.py profiles.py settings.py servers.py send.py inline_msg.py search.py
# for suite in login.py folder_list.py pages.py servers.py settings.py send.py inline_msg.py search.py tags.py
for suite in login.py folder_list.py pages.py servers.py profiles.py send.py search.py
# for suite in pages.py servers.py settings.py send.py inline_msg.py search.py
#inline_msg.py keyboard_shortcuts.py
for suite in keyboard_shortcuts.py
do
export TEST_SUITE="$suite"
"$PYTHON" -u ./$suite
Expand Down
Loading

0 comments on commit 55c1787

Please sign in to comment.