forked from Zverik/Level0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
355 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
// https://php-webdriver.github.io/php-webdriver/latest/Facebook/WebDriver.html | ||
// https://gist.github.com/aczietlow/7c4834f79a7afd920d8f | ||
|
||
use Facebook\WebDriver\Chrome\ChromeDriver; | ||
use Facebook\WebDriver\Chrome\ChromeOptions; | ||
use Facebook\WebDriver\Remote\DesiredCapabilities; | ||
use Facebook\WebDriver\WebDriverBy; | ||
use Facebook\WebDriver\WebDriverKeys; | ||
use Facebook\WebDriver\WebDriverExpectedCondition; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
require_once 'WebServerHelper.php'; | ||
|
||
|
||
class WebPageTest extends TestCase | ||
{ | ||
protected $webDriver; | ||
|
||
// Runs once | ||
public static function setUpBeforeClass(): void | ||
{ | ||
WebServerHelper::start(); | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
WebServerHelper::stop(); | ||
} | ||
|
||
// Runs before each test | ||
public function setUp(): void | ||
{ | ||
// https://github.com/php-webdriver/php-webdriver/wiki/Chrome#start-chromedriver | ||
// putenv('WEBDRIVER_CHROME_DRIVER=/path/to/chromedriver'); | ||
|
||
// https://github.com/php-webdriver/php-webdriver/wiki/Chrome#general-usage | ||
$chromeOptions = new ChromeOptions(); | ||
// $chromeOptions->setBinary('/home/user/Downloads/my_chrome_binary'); | ||
$chromeOptions->addArguments(['--headless']); | ||
|
||
$capabilities = DesiredCapabilities::chrome(); | ||
$capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions); | ||
|
||
$this->webDriver = ChromeDriver::start($capabilities); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
$this->webDriver->quit(); | ||
} | ||
|
||
private function elementByCSS($query) | ||
{ | ||
return $this->webDriver->findElement(WebDriverBy::cssSelector($query)); | ||
} | ||
|
||
public function testPage() | ||
{ | ||
$this->webDriver->get(WebServerHelper::url()); | ||
|
||
sleep(2); | ||
// Wait for map (Javacript) to load | ||
$this->webDriver->wait()->until( | ||
WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('.leaflet-map-pane')) | ||
); | ||
|
||
|
||
$h2 = $this->elementByCSS('h2'); | ||
$this->assertEquals($h2->getText(), 'Level0 OpenStreetMap Editor'); | ||
|
||
|
||
$input = $this->elementByCSS('input[name="url"]'); | ||
$input->sendKeys(array('w105957600', WebDriverKeys::ENTER)); | ||
|
||
sleep(2); | ||
|
||
$textarea = $this->elementByCSS('textarea'); | ||
$this->assertStringContainsString("way 105957600\n", $textarea->getText()); | ||
$this->assertStringContainsString(" addr:street = Downing Street\n", $textarea->getText()); | ||
|
||
|
||
// Button "Add to Editor" | ||
$input = $this->elementByCSS('input[name="url"]'); | ||
$input->sendKeys('n3815077900'); | ||
$this->elementByCSS('input[type="submit"][name="add"]')->click(); | ||
sleep(2); | ||
$textarea = $this->elementByCSS('textarea'); | ||
$this->assertStringContainsString("way 105957600\n", $textarea->getText()); | ||
$this->assertStringContainsString("node 3815077900: ", $textarea->getText()); | ||
|
||
|
||
// Button "Check for conflicts" | ||
$this->elementByCSS('input[name="check"]')->click(); | ||
$this->assertStringContainsString('Nothing is modified', $this->webDriver->getPageSource()); | ||
|
||
|
||
// Button "Show osmChange" | ||
$this->elementByCSS('input[name="showosc"]')->click(); | ||
$this->assertStringContainsString('this will be uploaded to the server', $this->webDriver->getPageSource()); | ||
$this->assertMatchesRegularExpression('/<osmChange [^&]+>\s*<\/osmChange>/', $this->webDriver->getPageSource()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
class WebServerHelper | ||
{ | ||
private static $pid; | ||
private static $host = 'localhost'; | ||
private static $port = 8000; | ||
private static $docRoot = __DIR__ . '/../www'; | ||
|
||
public static function url() | ||
{ | ||
return 'http://' . self::$host . ':' . self::$port; | ||
} | ||
|
||
public static function start() | ||
{ | ||
$command = sprintf( | ||
'php -S %s:%d -t %s > /dev/null 2>&1 & echo $!', | ||
self::$host, | ||
self::$port, | ||
escapeshellarg(self::$docRoot) | ||
); | ||
|
||
$output = []; | ||
exec($command, $output); | ||
self::$pid = (int) $output[0]; | ||
|
||
file_put_contents(__DIR__ . '/server.pid', self::$pid); | ||
sleep(1); | ||
} | ||
|
||
public static function stop() | ||
{ | ||
$pid = (int) @file_get_contents(__DIR__ . '/server.pid'); | ||
if ($pid) { | ||
exec('kill ' . $pid); | ||
unlink(__DIR__ . '/server.pid'); | ||
} | ||
} | ||
} |