Permalink
Browse files

Reorganizing unit tests

  • Loading branch information...
1 parent 5cd9838 commit dd674215b8c36e161ba71f3db0d7bf4f3a0a4223 @chdemko committed Mar 28, 2012
@@ -511,6 +511,22 @@ public static function getDate($time = 'now', $tzOffset = null)
}
/**
+ * Return a JFilesystem object
+ *
+ * @param string $prefix The file system prefix.
+ * @param array $options The stream context options.
+ * @param array $params The stream context params.
+ *
+ * @return JFilesystem The file system instance.
+ *
+ * @since 12.1
+ */
+ public static function getFilesystem($prefix = '', array $options = array(), array $params = array())
+ {
+ return JFilesystem::getInstance($prefix, $options, $params);
+ }
+
+ /**
* Create a configuration object
*
* @param string $file The path to the configuration file.
@@ -17,12 +17,14 @@
abstract class TestCaseFilesystem extends TestCase
{
protected static $system = null;
+ protected static $path = null;
public static function setupBeforeClass()
{
$parts = JString::splitCamelCase(get_called_class());
$class = 'TestCaseFilesystemSystem' . $parts[count($parts) - 2];
static::$system = $class::getSystem();
+ static::$path = $class::getPath();
}
/**
@@ -36,13 +38,13 @@ public static function setupBeforeClass()
*/
protected function setUp()
{
- if (empty(static::$system))
+ if (empty(static::$system) || empty(static::$path))
{
$this->markTestSkipped('There is no file system.');
}
// Create a temporary directory
- JFilesystemElementDirectory::getInstance(JPATH_TESTS . '/tmp/filesystem', static::$system)->create();
+ JFilesystemElementDirectory::getInstance(static::$path, static::$system)->create();
parent::setUp();
}
@@ -58,10 +60,10 @@ protected function setUp()
*/
protected function tearDown()
{
- if (!empty(static::$system))
+ if (!empty(static::$system) && !empty(static::$path))
{
// Make sure previous test files are cleaned up
- $directory = JFilesystemElementDirectory::getInstance(JPATH_TESTS . '/tmp/filesystem', static::$system);
+ $directory = JFilesystemElementDirectory::getInstance(static::$path, static::$system);
if ($directory->exists)
{
$directory->delete();
@@ -31,11 +31,11 @@ public function testRead()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessor::write('Contents', array($file, $message));
$file->close();
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('r');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('r');
$this->assertThat(
JFilesystemAccessor::read('Contents', array($file, 20)),
$this->equalTo($message),
@@ -55,7 +55,7 @@ public function testWrite()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessor::write('Contents', array($file, $message));
$file->close();
@@ -77,7 +77,7 @@ public function testPull()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessor::write('Contents', array($file, $message));
$file->close();
@@ -99,7 +99,7 @@ public function testPush()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system);
JFilesystemAccessor::push('Contents', array($file, $message));
$this->assertThat(
@@ -134,15 +134,15 @@ public function testAccessor()
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
$this->assertThat(
JFilesystemAccessor::write('TestContents', array($file, $message)),
$this->equalTo(strlen($message)),
'The content is not correct.'
);
$file->close();
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('r');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('r');
$this->assertThat(
JFilesystemAccessor::read('TestContents', array($file, $message)),
$this->equalTo($message),
@@ -160,7 +160,7 @@ public function testAccessor()
try
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessor::write('Unknown', array($file, $message));
$this->fail('An expected exception has not been raised.');
}
@@ -171,7 +171,7 @@ public function testAccessor()
try
{
JFilesystemAccessor::registerWriter('Unknown', 'unknown_writer');
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessor::write('Unknown', array($file, $message));
$this->fail('An expected exception has not been raised.');
}
@@ -182,7 +182,7 @@ public function testAccessor()
try
{
JFilesystemAccessor::registerWriter('Unknown', array(new TestFilesystemAccessorContents, 'unknown_writer'));
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessor::write('Unknown', array($file, $message));
$this->fail('An expected exception has not been raised.');
}
@@ -214,7 +214,7 @@ public function testReader()
'TestContents is not the reader test_reader_contents.'
);
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w')->open('r');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w')->open('r');
$this->assertThat(
JFilesystemAccessor::read('TestContents', array($file)),
$this->equalTo('Hello'),
@@ -256,7 +256,7 @@ public function testWriter()
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
$this->assertThat(
JFilesystemAccessor::write('TestContents', array($file, $message)),
$this->equalTo(strlen($message)),
@@ -296,7 +296,7 @@ public function testPuller()
'TestContents is not the puller test_puller_contents.'
);
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w')->open('r');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w')->open('r');
$this->assertThat(
JFilesystemAccessor::pull('TestContents', array($file)),
$this->equalTo('Hello'),
@@ -338,7 +338,7 @@ public function testPusher()
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
$this->assertThat(
JFilesystemAccessor::write('TestContents', array($file, $message)),
$this->equalTo(strlen($message)),
@@ -366,15 +366,15 @@ public function testExtractKey()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
$this->assertThat(
JFilesystemAccessor::write('TestContents', array($file, $message)),
$this->equalTo(strlen($message)),
'The content is not correct.'
);
$file->close();
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('r');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('r');
$this->assertThat(
JFilesystemAccessor::read('TestContents', array($file, $message)),
$this->equalTo($message),
@@ -29,7 +29,7 @@ public function testRead()
{
$message = 'H';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system);
$file->contents = $message;
$file->open('r');
@@ -52,7 +52,7 @@ public function testWrite()
{
$message = 'H';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessorCharacter::write($file, $message);
$file->close();
@@ -29,7 +29,7 @@ public function testRead()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system);
$file->contents = $message;
$file->open('r');
@@ -52,7 +52,7 @@ public function testWrite()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessorContents::write($file, $message);
$file->close();
@@ -62,7 +62,7 @@ public function testWrite()
'The content is not correct.'
);
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessorContents::write($file, $message, 5);
$file->close();
@@ -84,7 +84,7 @@ public function testPull()
{
$message = 'Hello world!';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system);
$file->contents = $message;
$this->assertThat(
@@ -29,7 +29,7 @@ public function testRead()
{
$line = 'Joomla!,"Content Management System"' . "\n";
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.csv', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.csv', static::$system);
$file->contents = $line;
$file->open('r');
@@ -50,7 +50,7 @@ public function testRead()
*/
public function testWrite()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.csv', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.csv', static::$system)->open('w');
JFilesystemAccessorCsv::write($file, array('Joomla!', 'Content Management System'));
$file->close();
@@ -73,7 +73,7 @@ public function testPull()
$lines[] = 'Joomla!,"Content Management System"' . "\n";
$lines[] = 'PHP,"Web programming language"' . "\n";
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.csv', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.csv', static::$system);
$file->contents = $lines;
$results = array(
@@ -99,7 +99,7 @@ public function testPull()
*/
public function testPush()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.csv', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.csv', static::$system);
$csv = array(
array('Joomla!', 'Content Management System'),
array('PHP', 'Web programming language')
@@ -29,7 +29,7 @@ public function testRead()
{
$message = '3.14159';
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system);
$file->contents = $message;
$file->open('r');
@@ -50,7 +50,7 @@ public function testRead()
*/
public function testWrite()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.txt', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.txt', static::$system)->open('w');
JFilesystemAccessorFormatted::write($file, "%f", 3.14159);
$file->close();
@@ -27,7 +27,7 @@
*/
public function testPull()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.ini', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.ini', static::$system);
$file->contents =
'KEY1=yes
KEY2="yes"
@@ -65,7 +65,7 @@ public function testPull()
*/
public function testPush()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.ini', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.ini', static::$system);
$file->pushIni(array(
'KEY1' => true,
'KEY12' => false,
@@ -29,7 +29,7 @@ public function testRead()
{
$message = '{"cms":"Joomla!"}' . "\n";
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.json', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.json', static::$system);
$file->contents = $message;
$file->open('r');
@@ -50,7 +50,7 @@ public function testRead()
*/
public function testWrite()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.json', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.json', static::$system)->open('w');
JFilesystemAccessorJson::write($file, (object) array('cms' => 'Joomla!'));
$file->close();
@@ -70,7 +70,7 @@ public function testWrite()
*/
public function testPull()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.json', static::$system)->open('w');
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.json', static::$system)->open('w');
JFilesystemAccessorJson::write($file, (object) array('cms' => 'Joomla!'));
$file->close();
@@ -90,7 +90,7 @@ public function testPull()
*/
public function testPush()
{
- $file = JFilesystemElementFile::getInstance(JPATH_TESTS . '/tmp/filesystem/test.json', static::$system);
+ $file = JFilesystemElementFile::getInstance(static::$path . '/test.json', static::$system);
JFilesystemAccessorJson::push($file, array((object) array('cms' => 'Joomla!')));
$this->assertThat(
Oops, something went wrong.

0 comments on commit dd67421

Please sign in to comment.