From 7e643f8831bc39cf21768a5b129cd9a4dbfbc487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 8 Apr 2015 12:19:47 +0200 Subject: [PATCH 1/3] Support including deleted files (attic) in CVS directory listings --- src/Client.php | 7 ++++++- tests/ClientTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5ceaf49..f24a645 100644 --- a/src/Client.php +++ b/src/Client.php @@ -56,7 +56,7 @@ public function fetchFile($path, $revision = null) return $this->fetch($url); } - public function fetchDirectory($path, $revision = null) + public function fetchDirectory($path, $revision = null, $showAttic = false) { if (substr($path, -1) !== '/') { return $this->reject(new InvalidArgumentException('Directory path MUST end with trailing slash')); @@ -68,6 +68,11 @@ public function fetchDirectory($path, $revision = null) $url .= '?pathrev=' . $revision; } + if ($showAttic) { + $url .= (strpos($url, '?') === false) ? '?' : '&'; + $url .= 'hideattic=0'; + } + // TODO: path MUST end with trailing slash // TODO: accessing files will redirect to file with relative location URL (not supported by clue/buzz-react) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index aa442ca..8d9cefe 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -67,6 +67,24 @@ public function testFetchDirectoryRevision() $this->expectPromiseReject($promise); } + public function testFetchDirectoryAttic() + { + $this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?hideattic=0'))->will($this->returnValue($this->createPromiseRejected())); + + $promise = $this->client->fetchDirectory('/directory/', null, true); + + $this->expectPromiseReject($promise); + } + + public function testFetchDirectoryRevisionAttic() + { + $this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?pathrev=1.1&hideattic=0'))->will($this->returnValue($this->createPromiseRejected())); + + $promise = $this->client->fetchDirectory('/directory/', '1.1', true); + + $this->expectPromiseReject($promise); + } + public function testFetchPatch() { $this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=patch&r1=1.0&r2=1.1'))->will($this->returnValue($this->createPromiseRejected())); From 6ac30cec003037f078988cae4195437169151fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 8 Apr 2015 12:21:42 +0200 Subject: [PATCH 2/3] Add functional tests for attic from Gentoo's CVS --- ...est.php => FunctionalApacheClientTest.php} | 2 +- tests/FunctionalGentooClientTest.php | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) rename tests/{FunctionalClientTest.php => FunctionalApacheClientTest.php} (98%) create mode 100644 tests/FunctionalGentooClientTest.php diff --git a/tests/FunctionalClientTest.php b/tests/FunctionalApacheClientTest.php similarity index 98% rename from tests/FunctionalClientTest.php rename to tests/FunctionalApacheClientTest.php index ba4c582..2556b0f 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalApacheClientTest.php @@ -6,7 +6,7 @@ use React\Promise\PromiseInterface; use Clue\React\Block\Blocker; -class FunctionalClientTest extends TestCase +class FunctionalApacheClientTest extends TestCase { private $loop; private $viewvc; diff --git a/tests/FunctionalGentooClientTest.php b/tests/FunctionalGentooClientTest.php new file mode 100644 index 0000000..9302143 --- /dev/null +++ b/tests/FunctionalGentooClientTest.php @@ -0,0 +1,65 @@ +loop = LoopFactory::create(); + $this->blocker = new Blocker($this->loop); + $browser = new Browser($this->loop); + + // check connectivity to given URL only once + static $checked = null; + if ($checked === null) { + try { + $this->waitFor($browser->head($url)); + $checked = true; + } catch (Exception $e) { + $checked = false; + } + } + + if (!$checked) { + $this->markTestSkipped('Unable to reach Gentoo ViewVC'); + } + + $this->viewvc = new Client($url, $browser); + } + + public function testFetchDirectoryAttic() + { + $path = '/'; + + $promise = $this->viewvc->fetchDirectory($path, null, true); + $files = $this->waitFor($promise); + + $this->assertEquals(array('misc/', 'src/', 'users/', 'xml/', '.frozen'), $files); + } + + public function testFetchFileDeletedShowsLastState() + { + $file = '.frozen'; + + $promise = $this->viewvc->fetchFile($file); + $contents = $this->waitFor($promise); + + $this->assertEquals("robbat2\n", $contents); + } + + private function waitFor(PromiseInterface $promise) + { + return $this->blocker->awaitOne($promise); + } +} From 4b9259ed11ceea89b3bc41cf7ff522df6ce6d5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 8 Apr 2015 12:38:31 +0200 Subject: [PATCH 3/3] Skip HTTPS tests for HHVM --- tests/FunctionalGentooClientTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/FunctionalGentooClientTest.php b/tests/FunctionalGentooClientTest.php index 9302143..802b15f 100644 --- a/tests/FunctionalGentooClientTest.php +++ b/tests/FunctionalGentooClientTest.php @@ -14,6 +14,10 @@ class FunctionalGentooClientTest extends TestCase public function setUp() { + if (!function_exists('stream_socket_enable_crypto')) { + $this->markTestSkipped('TLS (HTTPS) not supported by your platform (HHVM?)'); + } + $url = 'https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/'; $this->loop = LoopFactory::create();