From d4980932821fadc0ec97eea14fc7216a398a42ec Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sat, 19 Aug 2017 21:51:05 +0200 Subject: [PATCH] Add more unit test --- tests/Escaper/ArgumentEscaperTest.php | 50 +++++++++++++ tests/Util/RepositoryTest.php | 104 ++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 tests/Escaper/ArgumentEscaperTest.php create mode 100644 tests/Util/RepositoryTest.php diff --git a/tests/Escaper/ArgumentEscaperTest.php b/tests/Escaper/ArgumentEscaperTest.php new file mode 100644 index 00000000..5f60752c --- /dev/null +++ b/tests/Escaper/ArgumentEscaperTest.php @@ -0,0 +1,50 @@ +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'] + + ]; + } +} diff --git a/tests/Util/RepositoryTest.php b/tests/Util/RepositoryTest.php new file mode 100644 index 00000000..d8a800bc --- /dev/null +++ b/tests/Util/RepositoryTest.php @@ -0,0 +1,104 @@ +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')); + } +} \ No newline at end of file