Skip to content

Commit

Permalink
Merge branch 'fix-selenium' of github.com:Shadow243/cypht into fix-se…
Browse files Browse the repository at this point in the history
…lenium
  • Loading branch information
Shadow243 committed Jul 17, 2024
2 parents 3ef02bd + ae9b6ff commit 5662526
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .github/tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,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"
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"
36 changes: 0 additions & 36 deletions .github/tests/scripts/nginx.sh

This file was deleted.

12 changes: 11 additions & 1 deletion .github/tests/selenium/creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.BinaryLocation = "/usr/bin/google-chrome"
chrome_options.add_argument("--window-size=2200,2800")
chrome_options.add_argument("--window-size=3200,3800")

chrome_options.headless = False
chrome_options.add_argument("start-maximized")
# options.add_experimental_option("detach", True)
chrome_options.add_argument("--no-sandbox")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_argument('--disable-blink-features=AutomationControlled')

RECIP='[email protected]'
IMAP_ID='0'
Expand All @@ -23,3 +32,4 @@ def get_driver(cap):

def success(driver):
pass

1 change: 0 additions & 1 deletion .github/tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ setup_site() {
STATUS_ERROR
exit 1
fi
sudo php scripts/create_account.php test133 test331
}

##### UI END #####
Expand Down
134 changes: 67 additions & 67 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
6 changes: 3 additions & 3 deletions .travis/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ setup_all_tests() {
BUILD="$DB$TRAVIS_PHP_VERSION"
case "$BUILD" in
postgresql8.1)
setup_all_tests
# setup_unit_tests
#setup_all_tests
setup_unit_tests
;;
*)
setup_all_tests
setup_unit_tests
;;
esac
sys_info
9 changes: 1 addition & 8 deletions lib/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ public function change_pass($user, $pass) {
*/
public function create($user, $pass) {
$this->connect();

$result = 0;
try {
$res = Hm_DB::execute($this->dbh, 'select username from hm_user where username = ?', [$user]);

if (!empty($res)) {
//this var will prevent showing print in phpuni tests
if(!defined('CYPHT_PHPUNIT_TEST_MODE')) {
Expand All @@ -147,11 +144,7 @@ public function create($user, $pass) {
$result = 2;
}
}

} catch (Exception $e) {
Hm_Debug::add($e->getMessage());
}
return $result;
return $result;
}
}

Expand Down
1 change: 0 additions & 1 deletion modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ class Hm_Output_server_content_start extends Hm_Output_Module {
*/
protected function output() {
return '<div class="content_title">'.$this->trans('Servers').
// '<div class="list_controls"></div>'.
'</div><div class="server_content">';
}
}
Expand Down
17 changes: 1 addition & 16 deletions scripts/create_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,5 @@
$auth = new Hm_Auth_DB($config);

if ($user && $pass) {
try {
if ($auth->create($user, $pass) === 2) {
die("User '" . $user . "' created\n\n");
}
} catch(Exception $e) {
print_r(Hm_Debug::get());
print_r(Hm_Msgs::get());
print("An error occured when creating user '" . $user . "'\n\n");
exit(2); # TODO: since php cant die with an error code ??
}
// if ($auth->create($user, $pass) === 2) {
// die("User '" . $user . "' created\n\n");
// }
// else {

// }
$auth->create($user, $pass);
}
26 changes: 10 additions & 16 deletions tests/selenium/inline_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from base import WebTest, USER, PASS
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from runner import test_runner
from settings import SettingsHelpers

Expand All @@ -18,21 +17,16 @@ def set_inline_message_test(self):
self.dropdown_test('email_setting', 'all_email_since', '-1 week', '-5 years')

def navigate_msg_test(self):
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')
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
2 changes: 1 addition & 1 deletion tests/selenium/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def profiles(self):
'save',
'profiles',
'servers_page',
'site',
# 'site',
'password',
'logout',
])
16 changes: 10 additions & 6 deletions tests/selenium/profiles.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from base import WebTest, USER, PASS
from selenium.webdriver.common.by import By
from runner import test_runner
from settings import SettingsHelpers

class ProfileTest(WebTest):
class ProfileTest(SettingsHelpers):

def __init__(self):
WebTest.__init__(self)
self.login(USER, PASS)
self.wait_with_folder_list()

def load_profile_page(self):
self.load()
self.by_css('[data-source=".settings"]').click()
list_item = self.by_class('menu_profiles')
list_item.find_element_by_tag_name('a').click()
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
assert self.by_class('content_title').text == 'Profiles'
assert self.by_class('profile_content_title').text == 'Profiles'

def add_profile(self):
self.by_class('add_profile').click()
Expand All @@ -23,6 +26,7 @@ def add_profile(self):
addr.send_keys('[email protected]')
reply = self.by_name('profile_replyto')
reply.send_keys('[email protected]')
self.dropdown_test('profile_imap', 'all_email_since', '-1 week', '-5 years')
sig = self.by_name('profile_sig')
sig.send_keys('foo')
self.by_name('profile_default').click()
Expand Down Expand Up @@ -55,7 +59,7 @@ def del_profile(self):
print("PROFIILE TEST")
test_runner(ProfileTest, [
'load_profile_page',
'add_profile',
'edit_profile',
'del_profile'
# 'add_profile',
# 'edit_profile',
# 'del_profile'
])
3 changes: 2 additions & 1 deletion tests/selenium/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ 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
for suite in pages.py servers.py settings.py send.py inline_msg.py search.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
do
export TEST_SUITE="$suite"
"$PYTHON" -u ./$suite
Expand Down
Loading

0 comments on commit 5662526

Please sign in to comment.