mirror of
https://github.com/Ekokumppanit/ystavakylaecard.git
synced 2026-02-21 22:50:00 +00:00
49
tools/test/install_test.php
Normal file
49
tools/test/install_test.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class Install_test extends Spark_test_case {
|
||||
|
||||
function test_install_with_version()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('-v1.0', 'example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;36m[ SPARK ]' .
|
||||
chr(27) . '[0m Spark installed') === 0);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
$this->assertEquals(true, $success);
|
||||
}
|
||||
|
||||
function test_install_without_version()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;36m[ SPARK ]' .
|
||||
chr(27) . '[0m Spark installed') === 0);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
$this->assertEquals(true, $success);
|
||||
}
|
||||
|
||||
function test_install_with_invalid_spark()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('jjks7878erHjhsjdkksj'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;31m[ ERROR ]' .
|
||||
chr(27) . '[0m Unable to find spark') === 0);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
$this->assertEquals(true, $success);
|
||||
}
|
||||
|
||||
function test_install_with_invalid_spark_version()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('v9.4', 'example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(reset($clines), chr(27) . '[1;31m[ ERROR ]' .
|
||||
chr(27) . '[0m Uh-oh!') === 0);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
$this->assertEquals(true, $success);
|
||||
}
|
||||
|
||||
}
|
||||
34
tools/test/lib/bootstrap.php
Normal file
34
tools/test/lib/bootstrap.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
define('SPARK_PATH', __DIR__ . '/test-sparks');
|
||||
|
||||
require __DIR__ . '/../../lib/spark/spark_cli.php';
|
||||
|
||||
class Spark_test_case extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$this->source_names[] = 'getsparks.org';
|
||||
$this->sources = array_map(function($n) {
|
||||
return new Spark_source($n);
|
||||
}, $this->source_names);
|
||||
$this->cli = new Spark_CLI($this->sources);
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
if (is_dir(SPARK_PATH . '/example-spark'))
|
||||
{
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
}
|
||||
}
|
||||
|
||||
protected function capture_buffer_lines($func) {
|
||||
ob_start();
|
||||
$func($this->cli);
|
||||
$t = ob_get_contents();
|
||||
ob_end_clean();
|
||||
if ($t == '') return array(); // empty
|
||||
return explode("\n", substr($t, 0, count($t) - 2));
|
||||
}
|
||||
}
|
||||
0
tools/test/lib/test-sparks/.gitkeep
Normal file
0
tools/test/lib/test-sparks/.gitkeep
Normal file
9
tools/test/phpunit.xml
Normal file
9
tools/test/phpunit.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit colors="true" stopOnFailure="false" bootstrap="lib/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="SparkTests">
|
||||
<directory suffix="_test.php">./</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
50
tools/test/remove_test.php
Normal file
50
tools/test/remove_test.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class Remove_test extends Spark_test_case {
|
||||
|
||||
function test_remove_with_version()
|
||||
{
|
||||
// Test install with a version specified
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('-v1.0', 'example-spark')); // Spark needs installed first
|
||||
$cli->execute('remove', array('-v1.0', 'example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;36m[ SPARK ]' . chr(27) . '[0m Spark removed') === 0 && ! is_dir(SPARK_PATH.'/example-spark'));
|
||||
$this->assertEquals(true, $success);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
}
|
||||
|
||||
function test_remove_without_flags()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('-v1.0', 'example-spark')); // Spark needs installed first
|
||||
$cli->execute('remove', array('example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;31m[ ERROR ]' . chr(27) . '[0m Please specify') === 0 && is_dir(SPARK_PATH.'/example-spark'));
|
||||
$this->assertEquals(true, $success);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
}
|
||||
|
||||
function test_remove_with_f_flag()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('-v1.0', 'example-spark')); // Spark needs installed first
|
||||
$cli->execute('remove', array('-f', 'example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;36m[ SPARK ]' . chr(27) . '[0m Spark removed') === 0 && ! is_dir(SPARK_PATH.'/example-spark'));
|
||||
$this->assertEquals(true, $success);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
}
|
||||
|
||||
function test_remove_with_invalid_version()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('install', array('-v1.0', 'example-spark')); // Spark needs installed first
|
||||
$cli->execute('remove', array('-v9.4', 'example-spark'));
|
||||
});
|
||||
$success = (bool) (strpos(end($clines), chr(27) . '[1;36m[ SPARK ]' . chr(27) . '[0m Looks like that spark isn\'t installed') === 0 && is_dir(SPARK_PATH.'/example-spark'));
|
||||
$this->assertEquals(true, $success);
|
||||
Spark_utils::remove_full_directory(SPARK_PATH . '/example-spark');
|
||||
}
|
||||
|
||||
}
|
||||
14
tools/test/search_test.php
Normal file
14
tools/test/search_test.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Search_test extends Spark_test_case {
|
||||
|
||||
function test_search()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('search', array('markdown'));
|
||||
});
|
||||
// Less than ideal, I know
|
||||
$this->assertEquals(array("\033[33mmarkdown\033[0m - A markdown helper for easy parsing of markdown"), $clines);
|
||||
}
|
||||
|
||||
}
|
||||
37
tools/test/version_test.php
Normal file
37
tools/test/version_test.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class Version_test extends Spark_test_case {
|
||||
|
||||
function test_version()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('version');
|
||||
});
|
||||
$this->assertEquals(array(SPARK_VERSION), $clines);
|
||||
}
|
||||
|
||||
function test_sources()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('sources');
|
||||
});
|
||||
$this->assertEquals($this->source_names, $clines);
|
||||
}
|
||||
|
||||
function test_bad_command()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('fake');
|
||||
});
|
||||
$this->assertEquals(array(chr(27) . '[1;31m[ ERROR ]' . chr(27) . '[0m Uh-oh!', chr(27) . '[1;31m[ ERROR ]' . chr(27) . '[0m Unknown action: fake'), $clines);
|
||||
}
|
||||
|
||||
function test_search_empty()
|
||||
{
|
||||
$clines = $this->capture_buffer_lines(function($cli) {
|
||||
$cli->execute('search', array('nothing_found_here'));
|
||||
});
|
||||
$this->assertEquals(array(), $clines);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user