Skip to content

Support including deleted files (attic) in CVS directory listings #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
69 changes: 69 additions & 0 deletions tests/FunctionalGentooClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

use Clue\React\ViewVcApi\Client;
use React\EventLoop\Factory as LoopFactory;
use Clue\React\Buzz\Browser;
use React\Promise\PromiseInterface;
use Clue\React\Block\Blocker;

class FunctionalGentooClientTest extends TestCase
{
private $loop;
private $viewvc;
private $blocker;

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();
$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);
}
}