diff --git a/.gitignore b/.gitignore index 953682c1b73708d0a4a17503fd0cb2b5c30e8cce..b60d09df8b79d309890161b60d209ee3421343f4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ npm-debug.log /.project composer.lock +local.log \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f2d9f6dd5691388e2c041fa95ce08db7d4184614..54cdae77206c0a4de689ff246c7c362edd4bb269 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -215,5 +215,4 @@ integrationtest: - sed -i "s#^APP_URL=.*#APP_URL=$URL#g" .env - sed -i "s#^BRANCH_NAME=.*#BRANCH_NAME=$CI_COMMIT_REF_NAME#g" .env - sed -i "s#^COMMIT_NAME=.*#COMMIT_NAME=$CI_COMMIT_REF_SLUG#g" .env - - ./vendor/phpunit/phpunit/phpunit - + - php artisan dusk \ No newline at end of file diff --git a/app/Browserstack.php b/app/Browserstack.php deleted file mode 100644 index 6c9423a2864e385591b14a55ced59b28bef62220..0000000000000000000000000000000000000000 --- a/app/Browserstack.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php - -namespace App; - -use BrowserStack\Local; -use Facebook\WebDriver\Remote\RemoteWebDriver; - -class Browserstack -{ - private $webdriver, $bs_local = null; - private $LOCALCAPABILITIES = array(); - private $CAPABILITIES = array(); - - public function __construct() - { - $this->setCapabilities(); - $caps = null; - if ($this->isLocal()) { - $caps = $this->LOCALCAPABILITIES; - $this->bs_local = new Local(); - $bs_local_args = array("key" => env("WEBDRIVER_KEY", "")); - $this->bs_local->start($bs_local_args); - } else { - $caps = $this->CAPABILITIES; - } - $this->webdriver = RemoteWebDriver::create( - getenv("WEBDRIVER_URL"), - $caps - ); - } - - private function setCapabilities() - { - $this->LOCALCAPABILITIES = array( - "os" => "Windows", - "os_version" => "10", - "browser" => "Firefox", - "browser_version" => "79.0 beta", - "resolution" => "1920x1080", - "project" => env("PROJECT_NAME", "Not Set"), - "build" => env("BRANCH_NAME", "Not Set"), - "name" => env("COMMIT_NAME", "Not Set"), - "browserstack.local" => "true", - "browserstack.console" => "verbose", - "browserstack.networkLogs" => "true", - "browserstack.timezone" => "Europe/Berlin", - "browserstack.selenium_version" => "3.5.2", - ); - $this->CAPABILITIES = array( - "os" => "Windows", - "os_version" => "10", - "browser" => "Firefox", - "browser_version" => "79.0 beta", - "resolution" => "1920x1080", - "project" => env("PROJECT_NAME", "Not Set"), - "build" => env("BRANCH_NAME", "Not Set"), - "name" => env("COMMIT_NAME", "Not Set"), - "browserstack.local" => "false", - "browserstack.console" => "verbose", - "browserstack.networkLogs" => "true", - "browserstack.timezone" => "Europe/Berlin", - "browserstack.selenium_version" => "3.5.2", - ); - } - - public function getWebdriver() - { - return $this->webdriver; - } - - public function shutdown() - { - $this->webdriver->quit(); - if ($this->bs_local != null) { - $this->bs_local->stop(); - } - } - - private function isLocal() - { - return env("APP_URL", "") === "http://nginx"; - } - -} diff --git a/app/Http/Controllers/HumanVerification.php b/app/Http/Controllers/HumanVerification.php index fcf6e183d9d38bce7bc72426605c1efd39090bf2..6b979855358f80b1bd2b195417e9a3d8f0e8899b 100644 --- a/app/Http/Controllers/HumanVerification.php +++ b/app/Http/Controllers/HumanVerification.php @@ -39,6 +39,7 @@ class HumanVerification extends Controller $key = strtolower($key); if (!$hasher->check($key, $lockedKey)) { + sleep(\random_int(1, 8)); $captcha = Captcha::create("default", true); $user["lockedKey"] = $captcha["key"]; HumanVerification::saveUser($user); @@ -65,6 +66,7 @@ class HumanVerification extends Controller } } } + sleep(\random_int(1, 8)); $captcha = Captcha::create("default", true); $user["lockedKey"] = $captcha["key"]; HumanVerification::saveUser($user); @@ -105,7 +107,7 @@ class HumanVerification extends Controller private static function saveUser($user) { $userList = Cache::get(HumanVerification::PREFIX . "." . $user["id"], []); - + if ($user["whitelist"]) { $user["expiration"] = now()->addWeeks(2); } else { @@ -204,13 +206,16 @@ class HumanVerification extends Controller return true; } else if (\preg_match("/^\s*site:\"linkedin\.com[^\"]*\"\s+/si", $eingabe)) { return true; + } else if (\preg_match("/^\d+.(php|asp)\s+\?.*=.*/si", $eingabe)) { + return true; } return $possibleSpammer; } - public function botOverview(Request $request){ + public function botOverview(Request $request) + { $id = ""; $uid = ""; $ip = $request->ip(); @@ -232,7 +237,8 @@ class HumanVerification extends Controller ->with('user', $user); } - public function botOverviewChange(Request $request) { + public function botOverviewChange(Request $request) + { $id = ""; $uid = ""; $ip = $request->ip(); @@ -247,11 +253,11 @@ class HumanVerification extends Controller $userList = Cache::get(HumanVerification::PREFIX . "." . $id); $user = $userList[$uid]; - if($request->filled("locked")){ + if ($request->filled("locked")) { $user["locked"] = boolval($request->input('locked')); - }elseif($request->filled("whitelist")) { + } elseif ($request->filled("whitelist")) { $user["whitelist"] = boolval($request->input('whitelist')); - }elseif($request->filled("unusedResultPages")) { + } elseif ($request->filled("unusedResultPages")) { $user["unusedResultPages"] = intval($request->input('unusedResultPages')); } diff --git a/app/Http/Middleware/HumanVerification.php b/app/Http/Middleware/HumanVerification.php index 1ce6b38a2a8ab00f0f7d0db9e3fdbca1352f81d2..a39debc384ccfb8a86bbc3f7a3c99311431f4054 100644 --- a/app/Http/Middleware/HumanVerification.php +++ b/app/Http/Middleware/HumanVerification.php @@ -80,7 +80,7 @@ class HumanVerification } } } - + # A lot of automated requests are from websites that redirect users to our result page. # We will detect those requests and put a captcha $referer = URL::previous(); @@ -98,9 +98,10 @@ class HumanVerification if ((!$alone && $sum >= 50 && !$user["whitelist"]) || $refererLock) { $user["locked"] = true; } - + # If the user is locked we will force a Captcha validation if ($user["locked"]) { + sleep(\random_int(1, 8)); $captcha = Captcha::create("default", true); $user["lockedKey"] = $captcha["key"]; \App\PrometheusExporter::CaptchaShown(); diff --git a/app/Traits/SupportsBrowserStack.php b/app/Traits/SupportsBrowserStack.php new file mode 100644 index 0000000000000000000000000000000000000000..33a3187ce91e98577685437797a6568366438a07 --- /dev/null +++ b/app/Traits/SupportsBrowserStack.php @@ -0,0 +1,42 @@ +<?php +namespace App\Traits; + +use BrowserStack\Local; +use Facebook\WebDriver\Remote\RemoteWebDriver; + +/** + * Run BrowserStack from your tests. + */ +trait SupportsBrowserStack +{ + protected static $bs_local; + /** + * Create the BrowserStack WebDriver instance. + */ + public function createBrowserStackDriver(array $config = null): RemoteWebDriver + { + if ($config["capabilities"]["browserstack.local"] === "true") { + $this->bs_local = new Local(); + $bs_local_args = [ + "key" => $config["key"], + ]; + $this->bs_local->start($bs_local_args); + } + + return RemoteWebDriver::create( + "https://$config[username]:$config[key]@hub-cloud.browserstack.com/wd/hub", + $config["capabilities"] + ); + } + + /** + * @afterClass + */ + public static function shutdown() + { + if (static::$bs_local && static::$bs_local->isRunning()) { + static::$bs_local->stop(); + } + } + +} diff --git a/composer.json b/composer.json index afaeda31728ab51fa3aa9fba6dd49b78fe3fd400..9355e6fc34eaa29601f2daeac6f4da7c30793eea 100644 --- a/composer.json +++ b/composer.json @@ -23,12 +23,13 @@ }, "require-dev": { "beyondcode/laravel-dump-server": "^1.0", - "php-webdriver/webdriver": "^1.6", "browserstack/browserstack-local": "^1.1", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", + "laravel/dusk": "^5.0", "mockery/mockery": "^1.0", "nunomaduro/collision": "^3.0", + "php-webdriver/webdriver": "^1.6", "phpunit/phpunit": "^7.5" }, "config": { diff --git a/docker-compose.yml b/docker-compose.yml index aac33500354b36cc53afa114fe5089287df3fe67..86f67380c09364af43322a4efa01b536faf09119 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -75,4 +75,4 @@ services: working_dir: /html volumes: - .:/html - command: "./vendor/phpunit/phpunit/phpunit" + command: "php artisan dusk" diff --git a/local.log b/local.log deleted file mode 100644 index 5a4e92611a6e4aedccb0fde0950962fae5cd1d21..0000000000000000000000000000000000000000 --- a/local.log +++ /dev/null @@ -1,10 +0,0 @@ - - -/bin/sh: 1: ps: not found -/bin/sh: 1: ps: not found -Thu Jul 09 2020 11:17:18 GMT+0000 (UTC) -- [INFO] Started the BrowserStack Binary server on 45691, PID: 22 -Thu Jul 09 2020 11:17:19 GMT+0000 (UTC) -- [SUCCESS] You can now access your local server(s) in our remote browser - -Thu Jul 09 2020 11:17:19 GMT+0000 (UTC) -- Press Ctrl-C to exit - - diff --git a/tests/Browser/Pages/About.php b/tests/Browser/Pages/About.php new file mode 100644 index 0000000000000000000000000000000000000000..046879d9a9acd59938cab1800d31e6f33c2d96ba --- /dev/null +++ b/tests/Browser/Pages/About.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class About extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/about'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Was MetaGer auszeichnet") + ->assertTitle("Ãœber Uns - MetaGer") + ->switchLanguage("English") + ->waitForText("MetaGer - Characteristic qualities") + ->assertTitle("About Us - MetaGer") + ->switchLanguage("Español") + ->waitForText("Was MetaGer auszeichnet") + ->assertTitle("Sobre nosotros - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/App.php b/tests/Browser/Pages/App.php new file mode 100644 index 0000000000000000000000000000000000000000..c28c9a7039fed75cb5955bc0af2f1457df1e7a05 --- /dev/null +++ b/tests/Browser/Pages/App.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class App extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/app'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Diese App bringt die volle Power unserer Suchmaschine auf ihr Smartphone.") + ->assertTitle("Apps - MetaGer") + ->switchLanguage("English") + ->waitForText("This App brings the full Metager power to your smartphone.") + ->assertTitle("Apps - MetaGer") + ->switchLanguage("Español") + ->waitForText("Diese App bringt die volle Power unserer Suchmaschine auf ihr Smartphone.") + ->assertTitle("Aplicaciones - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Datenschutz.php b/tests/Browser/Pages/Datenschutz.php new file mode 100644 index 0000000000000000000000000000000000000000..00ad16475a4e5aa4fda9aa2c074cf93b80bd35bd --- /dev/null +++ b/tests/Browser/Pages/Datenschutz.php @@ -0,0 +1,50 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Datenschutz extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/datenschutz'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Datenschutz bei MetaGer/SUMA-EV") + ->assertTitle("Datenschutz und Privatsphäre - MetaGer") + ->switchLanguage("English") + ->waitForText("Data protection at MetaGer/SUMA-EV") + ->assertTitle("Privacy - MetaGer") + ->switchLanguage("Español") + ->waitForText("Data protection at MetaGer/SUMA-EV") + ->assertTitle("Protección de datos y privacidad - MetaGer") + ->switchLanguage("Deutsch"); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Hilfe.php b/tests/Browser/Pages/Hilfe.php new file mode 100644 index 0000000000000000000000000000000000000000..343c6433f813ba47ceb1d81d1118cb68bcddea2e --- /dev/null +++ b/tests/Browser/Pages/Hilfe.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Hilfe extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/hilfe'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("MetaGer - Hilfe") + ->assertTitle("Hilfe - MetaGer") + ->switchLanguage("English") + ->waitForText("MetaGer Help") + ->assertTitle("Help - MetaGer") + ->switchLanguage("Español") + ->waitForText("MetaGer - Hilfe") + ->assertTitle("Ayuda - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php new file mode 100644 index 0000000000000000000000000000000000000000..3ceecbff78ddc96186640287b178bc26aa3ac79d --- /dev/null +++ b/tests/Browser/Pages/HomePage.php @@ -0,0 +1,60 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class HomePage extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/'; + } + + /** + * Assert that the browser is on the page. + * + * @param \Laravel\Dusk\Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + # German + $browser->assertPathIs($this->url()) + ->waitForText("Garantierte Privatsphäre", 1) + ->assertTitle('MetaGer - Mehr als eine Suchmaschine') + ->assertSee("Vielfältig & Frei") + ->assertSee("100% Ökostrom") + ->assertSee("Gemeinnütziger Verein") + ->switchLanguage("English") + ->waitForText("Guaranteed Privacy", 1) + ->assertTitle('MetaGer: Privacy Protected Search & Find') + ->assertSee("Diverse & free") + ->assertSee("100 % renewable energy") + ->assertSee("Nonprofit organization") + ->switchLanguage("Español") + ->waitForText("Privacidad garantizada", 1) + ->assertTitle('MetaGer: Buscar & encontrar seguro, proteger la privacidad') + ->assertSee("Diversa y libre") + ->assertSee("EnergÃa 100% renovable") + ->assertSee("Organización sin ánimo de lucro") + ->switchLanguage("Deutsch"); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@sidebarToggle' => 'label.sidebar-opener[for=sidebarToggle]', + ]; + } +} diff --git a/tests/Browser/Pages/Impress.php b/tests/Browser/Pages/Impress.php new file mode 100644 index 0000000000000000000000000000000000000000..a54c0a0f6c82a80c7d38d2743997acf82649ee44 --- /dev/null +++ b/tests/Browser/Pages/Impress.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Impress extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/impressum'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Haftungshinweis:") + ->assertTitle("Impressum - MetaGer") + ->switchLanguage("English") + ->waitForText("Liability Note:") + ->assertTitle("Site Notice - MetaGer") + ->switchLanguage("Español") + ->waitForText("Exención de responsabilidad") + ->assertTitle("Aviso legal - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Kontakt.php b/tests/Browser/Pages/Kontakt.php new file mode 100644 index 0000000000000000000000000000000000000000..02ed0ab07dee8066219f22296aa1f81d891963c9 --- /dev/null +++ b/tests/Browser/Pages/Kontakt.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Kontakt extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/kontakt'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Sicheres Kontaktformular") + ->assertTitle("Kontakt - MetaGer") + ->switchLanguage("English") + ->waitForText("Secure Contact Form") + ->assertTitle("Contact - MetaGer") + ->switchLanguage("Español") + ->waitForText("Formulario de contacto seguro") + ->assertTitle("Contacto - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 0000000000000000000000000000000000000000..d569e1c3e58db3d83025164058a89b986d30d6d6 --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,30 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; +use Laravel\Dusk\Page as BasePage; + +abstract class Page extends BasePage +{ + /** + * Get the global element shortcuts for the site. + * + * @return array + */ + public static function siteElements() + { + return [ + '@sidebarToggle' => 'label.sidebar-opener[for=sidebarToggle]', + '@languageDropdown' => '#navigationSprache', + ]; + } + + public function switchLanguage(Browser $browser, $language) + { + $browser->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("@languageDropdown") + ->clickLink($language); + } +} diff --git a/tests/Browser/Pages/Plugin.php b/tests/Browser/Pages/Plugin.php new file mode 100644 index 0000000000000000000000000000000000000000..e47cea91d3efb62ec460b346cb9ad3c45e9862a8 --- /dev/null +++ b/tests/Browser/Pages/Plugin.php @@ -0,0 +1,50 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Plugin extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/plugin'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("MetaGer zum Firefox hinzufügen") + ->assertTitle("Plugin - MetaGer") + ->switchLanguage("English") + ->waitForText("Add MetaGer to your Firefox") + ->assertTitle("Plugin - MetaGer") + ->switchLanguage("Español") + ->waitForText("Añadir MetaGer a Firefox") + ->assertTitle("Plugin - MetaGer") + ->switchLanguage("Deutsch"); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/SitesearchWidget.php b/tests/Browser/Pages/SitesearchWidget.php new file mode 100644 index 0000000000000000000000000000000000000000..5ed902bc197670b18fcac7eb73288a4247a8cadf --- /dev/null +++ b/tests/Browser/Pages/SitesearchWidget.php @@ -0,0 +1,76 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class SitesearchWidget extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/sitesearch/'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Hier finden Sie ein Metager-Widget für Ihre Webseite.") + ->assertTitle("Sitesearch-Widget - MetaGer") + ->type("site", "https://metager.de") + ->press("Generieren") + ->waitForLocation("/sitesearch") + ->waitForText("Hier finden Sie ein Metager-Widget für Ihre Webseite.") + ->assertTitle("Sitesearch-Widget - MetaGer") + ->visit($this->url()) + ->switchLanguage("English") + ->waitForText("Here you find a Metager-Widget for your website.") + ->assertTitle("Sitesearch-Widget - MetaGer") + ->type("site", "https://metager.de") + ->press("Generate"); + $location = "/en/sitesearch"; + if (env("APP_ENV", "") === "production") { + $location = "/sitesearch"; + } + $browser->waitForLocation($location) + ->waitForText("Here you find a Metager-Widget for your website.") + ->assertTitle("Sitesearch-Widget - MetaGer") + ->visit($this->url()) + ->switchLanguage("Español") + ->waitForText("Aquà encuentra el Metger-Widget para su sitio web") + ->assertTitle("Widget para búsquedas dentro de tu página - MetaGer") + ->type("site", "https://metager.de") + ->press("Generar"); + $location = "/es/sitesearch"; + if (env("APP_ENV", "") === "production") { + $location = "/sitesearch"; + } + $browser->waitForLocation($location) + ->waitForText("Aquà encuentra el Metger-Widget para su sitio web") + ->assertTitle("Widget para búsquedas dentro de tu página - MetaGer") + ->visit($this->url()) + ->switchLanguage("Deutsch"); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Spende.php b/tests/Browser/Pages/Spende.php new file mode 100644 index 0000000000000000000000000000000000000000..ef37b7191451fcd8eb2b034985c81e5ce8ff681b --- /dev/null +++ b/tests/Browser/Pages/Spende.php @@ -0,0 +1,50 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Spende extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/spende'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Ihre Spende für SUMA-EV und MetaGer") + ->assertTitle("Spenden - MetaGer") + ->switchLanguage("English") + ->waitForText("Your Donation for MetaGer to SUMA-EV") + ->assertTitle("Donation - MetaGer") + ->switchLanguage("Español") + ->waitForText("Su donación para SUME-EV y MetaGer") + ->assertTitle("Donaciones - MetaGer") + ->switchLanguage("Deutsch"); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Team.php b/tests/Browser/Pages/Team.php new file mode 100644 index 0000000000000000000000000000000000000000..8077b875bdfa4135875044eec344df756d04e0ea --- /dev/null +++ b/tests/Browser/Pages/Team.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Team extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/team'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("geschäftsführender Vorstand") + ->assertTitle("Team - MetaGer") + ->switchLanguage("English") + ->waitForText("CEO") + ->assertTitle("Team - MetaGer") + ->switchLanguage("Español") + ->waitForText("Director ejecutivo [CEO]") + ->assertTitle("Nuestra gente - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/WebsearchWidget.php b/tests/Browser/Pages/WebsearchWidget.php new file mode 100644 index 0000000000000000000000000000000000000000..d6c78492e021220aead9a7b7d80cceca96004ce7 --- /dev/null +++ b/tests/Browser/Pages/WebsearchWidget.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class WebsearchWidget extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return "/websearch/"; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("Hier finden Sie ein Metager-Widget für Ihre Webseite.") + ->assertTitle("Websuche-Widget - MetaGer") + ->switchLanguage("English") + ->waitForText("Here you find a Metager-Widget for your website.") + ->assertTitle("Websearch-Widget - MetaGer") + ->switchLanguage("Español") + ->waitForText("Aquà encuentra el MetaGer-widget para su sitio web") + ->assertTitle("Widget para buscar la web - MetaGer") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Widget.php b/tests/Browser/Pages/Widget.php new file mode 100644 index 0000000000000000000000000000000000000000..4a3d927a0f53b3c1288eb37c2a64d58e75ce197f --- /dev/null +++ b/tests/Browser/Pages/Widget.php @@ -0,0 +1,51 @@ +<?php + +namespace Tests\Browser\Pages; + +use Laravel\Dusk\Browser; + +class Widget extends Page +{ + /** + * Get the URL for the page. + * + * @return string + */ + public function url() + { + return '/widget'; + } + + /** + * Assert that the browser is on the page. + * + * @param Browser $browser + * @return void + */ + public function assert(Browser $browser) + { + $browser->assertPathIs($this->url()) + ->waitForText("MetaGer zum Einbau in Ihre Webseite. Wählen Sie dafür aus, wo gesucht werden soll:") + ->assertTitle("MetaGer Widget") + ->switchLanguage("English") + ->waitForText("MetaGer for usage on your website. Please choose the scope of your widget:") + ->assertTitle("MetaGer Widget") + ->switchLanguage("Español") + ->waitForText("MetaGer: un motor de búsqueda for suyo sitio web. Selecciona por favor:") + ->assertTitle("MetaGer Widget") + ->switchLanguage("Deutsch"); + + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/StaticPagesTest.php b/tests/Browser/StaticPagesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d1a710f0b3a2371819c51db52dd91e4c4a92e899 --- /dev/null +++ b/tests/Browser/StaticPagesTest.php @@ -0,0 +1,191 @@ +<?php + +namespace Tests\Browser; + +use Laravel\Dusk\Browser; +use Tests\Browser\Pages\About; +use Tests\Browser\Pages\App; +use Tests\Browser\Pages\Datenschutz; +use Tests\Browser\Pages\Hilfe; +use Tests\Browser\Pages\HomePage; +use Tests\Browser\Pages\Impress; +use Tests\Browser\Pages\Kontakt; +use Tests\Browser\Pages\Plugin; +use Tests\Browser\Pages\SitesearchWidget; +use Tests\Browser\Pages\Spende; +use Tests\Browser\Pages\Team; +use Tests\Browser\Pages\WebsearchWidget; +use Tests\Browser\Pages\Widget; +use Tests\DuskTestCase; + +class StaticPagesTest extends DuskTestCase +{ + private $bs = null; + /** + * Tests for each static page on MetaGers website whether it can be reached by navigation + * + * @return void + */ + public function testStartpage() + { + $this->browse(function (Browser $browser) { + $browser->visit(new HomePage); + }); + } + + public function testDatenschutz() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->clickLink("Datenschutz") + ->waitForLocation("/datenschutz") + ->on(new Datenschutz); + }); + } + + public function testHilfe() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->clickLink("Hilfe") + ->waitForLocation("/hilfe") + ->on(new Hilfe); + }); + } + + public function testSpenden() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->clickLink("Spenden") + ->waitForLocation("/spende") + ->on(new Spende); + }); + } + + public function testApp() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->clickLink("MetaGer App") + ->waitForLocation("/app") + ->on(new App); + }); + } + + public function testKontakt() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label#navigationKontakt") + ->clickLink("Kontakt") + ->waitForLocation("/kontakt") + ->on(new Kontakt); + }); + } + + public function testTeam() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label#navigationKontakt") + ->clickLink("Team") + ->waitForLocation("/team") + ->on(new Team); + }); + } + + public function testAbout() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label#navigationKontakt") + ->clickLink("Ãœber uns") + ->waitForLocation("/about") + ->on(new About); + }); + } + + public function testImpress() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label#navigationKontakt") + ->clickLink("Impressum") + ->waitForLocation("/impressum") + ->on(new Impress); + }); + } + + public function testPlugin() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label[for=servicesToggle]") + ->clickLink("MetaGer Plugin") + ->waitForLocation("/plugin") + ->on(new Plugin); + }); + } + + public function testWidget() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label[for=servicesToggle]") + ->clickLink("Widget") + ->waitForLocation("/widget") + ->on(new Widget); + }); + } + + public function testWebsearchWidget() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label[for=servicesToggle]") + ->clickLink("Widget") + ->waitForLocation("/widget") + ->clickLink("Suche im Web") + ->waitForLocation("\/websearch\/") + ->on(new WebsearchWidget); + }); + } + + public function testSitesearchWidget() + { + $this->browse(function (Browser $browser) { + $browser->visit("/") + ->waitFor("@sidebarToggle") + ->click("@sidebarToggle") + ->click("label[for=servicesToggle]") + ->clickLink("Widget") + ->waitForLocation("/widget") + ->clickLink("Suche nur auf einer Domain") + ->waitForLocation("/sitesearch/") + ->on(new SitesearchWidget); + }); + } +} diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 0000000000000000000000000000000000000000..e22536cbfd9e21df44a3184d6f8550d0db90bbde --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,56 @@ +<?php + +namespace Tests; + +use Facebook\WebDriver\Remote\RemoteWebDriver; +use Laravel\Dusk\TestCase as BaseTestCase; +use \App\Traits\SupportsBrowserStack; + +abstract class DuskTestCase extends BaseTestCase +{ + use CreatesApplication; + use SupportsBrowserStack; + + /** + * Prepare for Dusk test execution. + * + * @beforeClass + * @return void + */ + public static function prepare() + { + } + + /** + * Create the RemoteWebDriver instance. + * + * @return \Facebook\WebDriver\Remote\RemoteWebDriver + */ + protected function driver() + { + $capabilities = [ + "os" => "Windows", + "os_version" => "10", + "browser" => "Firefox", + "browser_version" => "79.0 beta", + "resolution" => "1920x1080", + "project" => env("PROJECT_NAME", "Not Set"), + "build" => env("BRANCH_NAME", "Not Set"), + "name" => env("COMMIT_NAME", "Not Set"), + "browserstack.local" => "true", + "browserstack.console" => "verbose", + "browserstack.networkLogs" => "true", + "browserstack.timezone" => "Europe/Berlin", + "browserstack.selenium_version" => "3.5.2", + ]; + if (env("APP_URL", "") !== "http://nginx") { + # Not local Testing + $capabilities["browserstack.local"] = "false"; + } + return $this->createBrowserStackDriver([ + "username" => env("WEBDRIVER_USER", ""), + "key" => env("WEBDRIVER_KEY", ""), + "capabilities" => $capabilities, + ]); + } +}