Skip to content

Commit 44c82eb

Browse files
committed
Merge pull request #11 from clue-labs/attic
Support including deleted files (attic) in CVS directory listings
2 parents 258b57c + 4b9259e commit 44c82eb

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

src/Client.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function fetchFile($path, $revision = null)
5656
return $this->fetch($url);
5757
}
5858

59-
public function fetchDirectory($path, $revision = null)
59+
public function fetchDirectory($path, $revision = null, $showAttic = false)
6060
{
6161
if (substr($path, -1) !== '/') {
6262
return $this->reject(new InvalidArgumentException('Directory path MUST end with trailing slash'));
@@ -68,6 +68,11 @@ public function fetchDirectory($path, $revision = null)
6868
$url .= '?pathrev=' . $revision;
6969
}
7070

71+
if ($showAttic) {
72+
$url .= (strpos($url, '?') === false) ? '?' : '&';
73+
$url .= 'hideattic=0';
74+
}
75+
7176
// TODO: path MUST end with trailing slash
7277
// TODO: accessing files will redirect to file with relative location URL (not supported by clue/buzz-react)
7378

tests/ClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ public function testFetchDirectoryRevision()
6767
$this->expectPromiseReject($promise);
6868
}
6969

70+
public function testFetchDirectoryAttic()
71+
{
72+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?hideattic=0'))->will($this->returnValue($this->createPromiseRejected()));
73+
74+
$promise = $this->client->fetchDirectory('/directory/', null, true);
75+
76+
$this->expectPromiseReject($promise);
77+
}
78+
79+
public function testFetchDirectoryRevisionAttic()
80+
{
81+
$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()));
82+
83+
$promise = $this->client->fetchDirectory('/directory/', '1.1', true);
84+
85+
$this->expectPromiseReject($promise);
86+
}
87+
7088
public function testFetchPatch()
7189
{
7290
$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()));

tests/FunctionalClientTest.php renamed to tests/FunctionalApacheClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use React\Promise\PromiseInterface;
77
use Clue\React\Block\Blocker;
88

9-
class FunctionalClientTest extends TestCase
9+
class FunctionalApacheClientTest extends TestCase
1010
{
1111
private $loop;
1212
private $viewvc;

tests/FunctionalGentooClientTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
use Clue\React\ViewVcApi\Client;
4+
use React\EventLoop\Factory as LoopFactory;
5+
use Clue\React\Buzz\Browser;
6+
use React\Promise\PromiseInterface;
7+
use Clue\React\Block\Blocker;
8+
9+
class FunctionalGentooClientTest extends TestCase
10+
{
11+
private $loop;
12+
private $viewvc;
13+
private $blocker;
14+
15+
public function setUp()
16+
{
17+
if (!function_exists('stream_socket_enable_crypto')) {
18+
$this->markTestSkipped('TLS (HTTPS) not supported by your platform (HHVM?)');
19+
}
20+
21+
$url = 'https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/';
22+
23+
$this->loop = LoopFactory::create();
24+
$this->blocker = new Blocker($this->loop);
25+
$browser = new Browser($this->loop);
26+
27+
// check connectivity to given URL only once
28+
static $checked = null;
29+
if ($checked === null) {
30+
try {
31+
$this->waitFor($browser->head($url));
32+
$checked = true;
33+
} catch (Exception $e) {
34+
$checked = false;
35+
}
36+
}
37+
38+
if (!$checked) {
39+
$this->markTestSkipped('Unable to reach Gentoo ViewVC');
40+
}
41+
42+
$this->viewvc = new Client($url, $browser);
43+
}
44+
45+
public function testFetchDirectoryAttic()
46+
{
47+
$path = '/';
48+
49+
$promise = $this->viewvc->fetchDirectory($path, null, true);
50+
$files = $this->waitFor($promise);
51+
52+
$this->assertEquals(array('misc/', 'src/', 'users/', 'xml/', '.frozen'), $files);
53+
}
54+
55+
public function testFetchFileDeletedShowsLastState()
56+
{
57+
$file = '.frozen';
58+
59+
$promise = $this->viewvc->fetchFile($file);
60+
$contents = $this->waitFor($promise);
61+
62+
$this->assertEquals("robbat2\n", $contents);
63+
}
64+
65+
private function waitFor(PromiseInterface $promise)
66+
{
67+
return $this->blocker->awaitOne($promise);
68+
}
69+
}

0 commit comments

Comments
 (0)