diff --git a/EtherpadTest.php b/EtherpadTest.php new file mode 100644 index 0000000..a3172d0 --- /dev/null +++ b/EtherpadTest.php @@ -0,0 +1,26 @@ +<?php + +require 'traits/assertHttp.php'; + +class EtherpadTest extends PHPUnit_Framework_TestCase { + use assertHttp; + + public function testEtherpadIsLive () { + $this->assertHttpResponseCode(200, 'http://pad.nasqueron.org', 'Etherpad looks down.'); + $this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/', "Etherpad HTTPS issue."); + $this->assertHttpResponseCode(200, 'http://pad.wolfplex.be', "Etherpad doesn't reply to pad.wolfplex.be vhost."); + $this->assertHttpResponseCode(404, 'http://pad.nasqueron.org/notexisting', 'A 404 code were expected for a not existing Etherpad page.'); + $this->assertHttpResponseCode(200, 'http://pad.nasqueron.org/metrics', "ep_ether-o-meter plugin doesn't seem installed."); + } + + public function testWolfplexApiWorks () { + //Reported by philectro - 09:42 < philectro> hey tous les pad ont disparu :o + + $url = "http://www.wolfplex.be/pad/"; + $this->assertHttpResponseCode(200, $url); + + $stringOnlyAvailableWhenApiWorks = '<li><a href="/pad/'; + $currentContent = file_get_contents($url); + $this->assertContains($stringOnlyAvailableWhenApiWorks, $currentContent, "On Ysul, /home/wolfplex.org/logs/api.log could help. But more probably, you reinstalled the Etherpad container without restoring the API key. Move the former APIKEY.txt file to /opt/etherpad-lite or, if lost, update Wolfplex API credentials with the new API key."); + } +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c9a153f --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +### +### Nasqueron ops tests +### We use PHPUnit to test several parts of our infrastructure. +### + +test: + phpunit . diff --git a/traits/assertHttp.php b/traits/assertHttp.php new file mode 100644 index 0000000..11a5087 --- /dev/null +++ b/traits/assertHttp.php @@ -0,0 +1,31 @@ +<?php + +trait assertHttp { + /** + * Asserts the HTTP response code of an URL matches the expected code + * + * @param int $expectedCode the expected HTTP response code + * @param string $url the URL to check + * @param string $comment the comment to output if the test fails [facultative] + */ + private function assertHttpResponseCode ($expectedCode, $url, $comment = '') { + $actualCode = $this->getHttpResponseCode($url); + return $this->assertEquals($expectedCode, $actualCode, $comment); + } + + /** + * Gets the HTTP response code of the specified URL + * + * @param string $url + * @return int the HTTP response code + */ + private function getHttpResponseCode ($url) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_USERAGENT, "Nasqueron-Ops-Tests"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + return $code; + } +}