Skip to content
This repository was archived by the owner on Apr 28, 2024. It is now read-only.
Open
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
50 changes: 50 additions & 0 deletions tests/Escaper/ArgumentEscaperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace GitList\Test\Escaper;

use GitList\Escaper\ArgumentEscaper;

class ArgumentEscaperTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ArgumentEscaper
*/
private $argumentEscaper;

/**
* Setup unit test
*/
protected function setUp()
{
$this->argumentEscaper = new ArgumentEscaper();
}

/**
* Test escape function escapes commandline arguments
* @covers \GitList\Escaper\ArgumentEscaper::escape()
* @dataProvider argumentDataProvider
* @param $argument The unescaped argument
* @param $escaped The escaped variant of the argument
*/
public function testEscape($argument, $escaped)
{
$this->assertSame($escaped, $this->argumentEscaper->escape($argument));
}

/**
* A data provider based on the commandline arguments that need escaping
* @return array
* @see http://php.net/manual/en/function.escapeshellcmd.php
*/
public function argumentDataProvider()
{
return [
'Null' => [null, null],
'Ampersand' => ['Tom&Jerry', 'Tom\&Jerry'],
'Dollar sign' => ['$value', '\$value'],
'Single quote sign' => ["'Open single quote", "\'Open single quote"],
'Double quote sign' => ['"Another quote', '\"Another quote']

];
}
}
104 changes: 104 additions & 0 deletions tests/Util/RepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace GitList\Test\Util;


use GitList\Application;
use GitList\Config;
use GitList\Util\Repository;

class RepositoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Repository
*/
private $repository;

/**
* @var Application
*/
private $application;

/**
* Setup unit test
*/
protected function setUp()
{
$this->application = new Application(new Config());
$this->repository = new Repository($this->application);
}

/**
* Test the get file type with extension
* @covers \GitList\Util\Repository::getFileType()
*/
public function testGetFileTypeWithoutExtension()
{
$this->assertSame('text', $this->repository->getFileType('file-without-extension'));
}

/**
* Test the get file type with extension
* @covers \GitList\Util\Repository::getFileType()
*/
public function testGetFileTypeForDefaultFileType()
{
$this->assertSame('clike', $this->repository->getFileType('main.cpp'));
}

/**
* Test the get file type with extension from app specific config
* @covers \GitList\Util\Repository::getFileType()
*/
public function testGetFileTypeForAppSpecificFileType()
{
$this->application['filetypes'] = ['php3'=> 'php', 'php4' => 'php'];
$this->assertSame('php', $this->repository->getFileType('legacy.php4'));
}

/**
* Test the get file type with extension for default path
* @covers \GitList\Util\Repository::getFileType()
*/
public function testGetFileTypeDefault()
{
$this->assertSame('text', $this->repository->getFileType('nl_NL.po'));
}

/**
* Test if the file type is binary for without extension
* @covers \GitList\Util\Repository::isBinary()
*/
public function testIsBinaryWithoutExtension()
{
$this->assertFalse($this->repository->isBinary('README'));
}

/**
* Test if the file type is binary for with extension
* @covers \GitList\Util\Repository::isBinary()
*/
public function testIsBinaryForDefaultFileType()
{
$this->assertTrue($this->repository->isBinary('invoice.pdf'));
}

/**
* Test if the file type is binary from app specific config
* @covers \GitList\Util\Repository::isBinary()
*/
public function testIsBinaryForAppSpecificFileType()
{
$this->application['binary_filetypes'] = ['php3'=> false, 'php4' => false];
$this->assertFalse($this->repository->isBinary('legacy.php4'));
}

/**
* Test if the file type is binary for the default path
* @covers \GitList\Util\Repository::isBinary()
*/
public function testIsBinaryDefault()
{
$this->assertFalse($this->repository->isBinary('nl_NL.po'));
}
}