From 3b31b112a7c56685be0e055de79d90ebab964b94 Mon Sep 17 00:00:00 2001 From: marko Date: Thu, 14 Nov 2024 18:17:25 +0100 Subject: [PATCH] added checks for php errors/warnings --- .../www/participo/attendance.php | 6 +-- .../www/participo/config/participo.php | 2 +- .../www/participo/infoZettel.php | 53 ++++++++++--------- .../cwsvjudo@bplaced/www/participo/user.php | 4 +- .../cwsvJudo/participo/docker-compose.yml | 6 +++ homepage/cwsvJudo/participo/test/helper.py | 46 ++++++++++------ homepage/cwsvJudo/participo/test/test_main.py | 19 +++++++ 7 files changed, 90 insertions(+), 46 deletions(-) diff --git a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/attendance.php b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/attendance.php index 3a0143c..546b4e9 100644 --- a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/attendance.php +++ b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/attendance.php @@ -11,8 +11,8 @@ setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); require_once './lib/participoLib/participo.php'; require_once './lib/participoLib/user.php'; - require_once $config['basePath'] . '/config/cwsvJudo.config.php'; - require_once $config['basePath'] . '/config/phpcount.config.php'; + require_once $config["home"] . "/.local/cwsvJudo.config.php"; + // require_once $config['basePath'] . '/.local/phpcount.config.php'; dbConnector::connect( $cwsvJudoConfig['db']['host'], @@ -123,7 +123,7 @@ setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); private static $Types = [ AttendanceType::Training => 'Training', AttendanceType::Excused => 'Entschuldigt', AttendanceType::Ill => 'Krank', AttendanceType::SpecialTraining => 'SonderTraining', AttendanceType::Competition => 'Wettkampf' ]; - private static $NameOfMonth = [1 => 'Januar', 2 => 'Februar', 3 => 'März', 4 => 'April', 4 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember']; + private static $NameOfMonth = [1 => 'Januar', 2 => 'Februar', 3 => 'März', 4 => 'April', 5 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember']; /** * constructor diff --git a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/config/participo.php b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/config/participo.php index 37e75b6..8017058 100644 --- a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/config/participo.php +++ b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/config/participo.php @@ -7,7 +7,7 @@ if (!isset($config)) { } $config["home"] = "/home/cwsvjudo"; -$config["basePath"] = "/home/cwsvjudo/www"; +$config["basePath"] = "/home/cwsvjudo/httpdocs"; $config["baseUrl"] = "http://cwsvjudo.bplaced.net"; $config["ressourceUrl"] = "http://cwsvjudo.bplaced.net/ressourcen"; diff --git a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/infoZettel.php b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/infoZettel.php index 3df4d80..2078e0a 100644 --- a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/infoZettel.php +++ b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/infoZettel.php @@ -10,7 +10,7 @@ require_once './lib/api.php'; $basePath = $config['basePath']; - require_once $basePath . '/config/cwsvJudo.config.php'; + require_once $config["home"] . "/.local/cwsvJudo.config.php"; require_once $basePath . '/ressourcen/phpLib/parsedown/Parsedown.php'; require_once $basePath . '/ressourcen/phpLib/Spyc/Spyc.php'; @@ -84,19 +84,9 @@ foreach ($years as $year) {?>
' . $currentYear . ''); - -foreach ($fileList as $file) { - $thisYear = (int)substr(basename($file), 0, 4); - if ($thisYear != $currentYear) { - $currentYear = $thisYear; - echo('

' . $currentYear . '

'); - } - - // get a list of all infoZettel - $fileList = glob($basePath . '/infoZettel/*.md'); - rsort($fileList); +if (!empty($fileList)){ + $currentYear = (int)substr(basename($fileList[0]), 0, 4); + echo('

' . $currentYear . '

'); foreach ($fileList as $file) { $thisYear = (int)substr(basename($file), 0, 4); @@ -105,18 +95,31 @@ foreach ($fileList as $file) { echo('

' . $currentYear . '

'); } - $infoZettel = loadMarkdownFile($file); - echo( - AppCard::fromArray([ - 'title' => $infoZettel['yaml']['title'], - 'description' => Parsedown::instance()->text($infoZettel['mdText']), - ])->htmlCode(['extraClass' => 'parsedownCard']) - ); - } ?> + // get a list of all infoZettel + $fileList = glob($basePath . '/infoZettel/*.md'); + rsort($fileList); + + foreach ($fileList as $file) { + $thisYear = (int)substr(basename($file), 0, 4); + if ($thisYear != $currentYear) { + $currentYear = $thisYear; + echo('

' . $currentYear . '

'); + } + + $infoZettel = loadMarkdownFile($file); + echo( + AppCard::fromArray([ + 'title' => $infoZettel['yaml']['title'], + 'description' => Parsedown::instance()->text($infoZettel['mdText']), + ])->htmlCode(['extraClass' => 'parsedownCard']) + ); + } + } +} +else{ + echo("Keine Infos gefunden!"); +} ?>
- \ No newline at end of file diff --git a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/user.php b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/user.php index 4711630..3e3db73 100644 --- a/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/user.php +++ b/homepage/cwsvJudo/participo/cwsvjudo@bplaced/www/participo/user.php @@ -9,8 +9,8 @@ require_once './lib/participoLib/participo.php'; require_once './lib/db.php'; require_once './lib/api.php'; -require_once $config['basePath'] . '/config/cwsvJudo.config.php'; -require_once $config['basePath'] . '/config/phpcount.config.php'; +require_once $config["home"] . "/.local/cwsvJudo.config.php"; +// require_once $config['basePath'] . '/config/phpcount.config.php'; dbConnector::connect( $cwsvJudoConfig['db']['host'], diff --git a/homepage/cwsvJudo/participo/docker-compose.yml b/homepage/cwsvJudo/participo/docker-compose.yml index 87af021..adb77ba 100644 --- a/homepage/cwsvJudo/participo/docker-compose.yml +++ b/homepage/cwsvJudo/participo/docker-compose.yml @@ -22,6 +22,9 @@ services: # ressourcen - /home/marko/cwsvJudo/submodules/materialize/dist:/home/cwsvjudo/httpdocs/ressourcen/materializeCss - /home/marko/cwsvJudo/homepage/cwsvJudo/build/graphiken:/home/cwsvjudo/httpdocs/ressourcen/graphiken + # libs + - /home/marko/cwsvJudo/submodules/parsedown:/home/cwsvjudo/httpdocs/ressourcen/phpLib/parsedown + - /home/marko/cwsvJudo/submodules/spyc:/home/cwsvjudo/httpdocs/ressourcen/phpLib/Spyc # php and extensions php: # use pre-build image from docker.. @@ -37,6 +40,9 @@ services: - ./cwsvjudo@bplaced/www/participo:/home/cwsvjudo/httpdocs/participo # the apps config files - ./config-heliohost/cwsvJudo.config.php:/home/cwsvjudo/.local/cwsvJudo.config.php + # libs + - /home/marko/cwsvJudo/submodules/parsedown/Parsedown.php:/home/cwsvjudo/httpdocs/ressourcen/phpLib/parsedown/Parsedown.php + - /home/marko/cwsvJudo/submodules/spyc/Spyc.php:/home/cwsvjudo/httpdocs/ressourcen/phpLib/Spyc/Spyc.php # @todo Maybe use postgre instead? database: image: mariadb:latest diff --git a/homepage/cwsvJudo/participo/test/helper.py b/homepage/cwsvJudo/participo/test/helper.py index 86f4913..9166149 100644 --- a/homepage/cwsvJudo/participo/test/helper.py +++ b/homepage/cwsvJudo/participo/test/helper.py @@ -1,6 +1,6 @@ -from selenium import webdriver +import logging + from selenium.webdriver.common.by import By -from selenium.webdriver.remote.webdriver import WebDriver def load_config(config_path: str = "config.toml"): @@ -9,20 +9,16 @@ def load_config(config_path: str = "config.toml"): with open(file=config_path, mode="rb") as config_file: return load(config_file) -def login(driver: WebDriver, username: str, password:str): - driver.find_element(by=By.ID, value="username").send_keys(username) - driver.find_element(by=By.ID, value="password").send_keys(password) - driver.find_element(by=By.TAG_NAME, value="form").submit() class Participo: def __init__(self) -> None: - from selenium.webdriver import FirefoxOptions + from selenium.webdriver import Firefox, FirefoxOptions options = FirefoxOptions() - # options.add_argument("-headless") + options.add_argument("-headless") self.config = load_config() - self.driver = webdriver.Firefox(options=options) + self.driver = Firefox(options=options) self.delay = 5 @@ -36,21 +32,41 @@ class Participo: def get_home(self): self.driver.get(url=self.config["url"]["home"]) + def load_section(self, section: str): + section_url = "/".join((self.config["url"]["home"], section)) + self.driver.get(url=section_url) + def login(self): credentials = self.config["credentials"] - login(driver=self.driver, username=credentials["username"], password=credentials["password"]) + + self.driver.find_element(by=By.ID, value="username").send_keys( + credentials["username"] + ) + self.driver.find_element(by=By.ID, value="password").send_keys( + credentials["password"] + ) + self.driver.find_element(by=By.TAG_NAME, value="form").submit() def check_login(self): - from selenium.common.exceptions import NoSuchElementException + return self.check_for(By.LINK_TEXT, "Logout") + + def check_for_xdebug_msgs(self): + classes = ("xdebug-error", "xe-warning") + + return any((self.check_for(By.CLASS_NAME, c) for c in classes)) + + def check_for(self, selector: str, value: str) -> bool: + from selenium.common.exceptions import NoSuchElementException, TimeoutException from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait try: - logoutButton = WebDriverWait(driver=self.driver, timeout=self.delay).until( - EC.presence_of_element_located( - locator=(By.LINK_TEXT, "Logout") - ) + _ = WebDriverWait(driver=self.driver, timeout=self.delay).until( + EC.presence_of_element_located(locator=(selector, value)) ) return True except NoSuchElementException: + logging.info(f"No such element ({selector}, {value})") + return False + except TimeoutException: return False diff --git a/homepage/cwsvJudo/participo/test/test_main.py b/homepage/cwsvJudo/participo/test/test_main.py index 4d94f52..6502e8c 100644 --- a/homepage/cwsvJudo/participo/test/test_main.py +++ b/homepage/cwsvJudo/participo/test/test_main.py @@ -2,14 +2,33 @@ # testing the participo app import unittest +import logging from helper import Participo + class TestParticipo(unittest.TestCase): def test_login(self): + with Participo() as participo: + participo.login() + self.assertTrue(participo.check_login(), "Login failed") + + def test_sub_pages(self): with Participo() as participo: participo.login() self.assertTrue(participo.check_login()) + sections = ("events", "infoZettel", "attendance", "user") + for section in sections: + with self.subTest(msg=f"- {section}"): + participo.load_section(section=section) + + self.assertFalse( + expr=participo.check_for_xdebug_msgs(), + msg=f"php errors on section {section}", + ) + + if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) unittest.main()