Location: PHPKode > projects > Moc10 PHP Library > tests/Moc10/FileTest.php
<?php
/**
 * Moc10 Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.TXT.
 * It is also available through the world-wide-web at this URL:
 * http://www.moc10phplibrary.com/LICENSE.TXT
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to hide@address.com so we can send you a copy immediately.
 *
 * @category   Moc10
 * @package    Moc10_File
 * @author     Nick Sagona, III <hide@address.com>
 * @copyright  Copyright (c) 2009-2011 Moc 10 Media, LLC. (http://www.moc10media.com)
 * @license    http://www.moc10phplibrary.com/LICENSE.TXT     New BSD License
 */

require_once dirname(__FILE__) . '/../../library/Moc10/Autoloader.php';
Moc10_Autoloader::bootstrap();

class Moc10_FileTest extends PHPUnit_Framework_TestCase
{

    public function testFileConstructor()
    {
        $f = new Moc10_File('new_file.txt');
        $class = 'Moc10_File';
        $this->assertTrue($f instanceof $class);
    }

    public function testFileRead()
    {
        $f = new Moc10_File('../../public/examples/assets/files/test.txt');
        $this->assertEquals('Test Text File.', $f->read());
    }

    public function testFileWrite()
    {
        $f = new Moc10_File('../../public/examples/assets/files/new_test.txt');
        $data = 'This is a write test.';

        $f->write($data);
        $this->assertEquals($data, $f->read());

        $f->delete();
    }

    public function testFileCopy()
    {
        $f = new Moc10_File('../../public/examples/assets/files/test.txt');
        $f->copy('../../public/examples/assets/files/copy_test.txt');

        $this->assertTrue(file_exists('../../public/examples/assets/files/copy_test.txt'));
        
        unlink('../../public/examples/assets/files/copy_test.txt');
    }

    public function testFileMove()
    {
        $f = new Moc10_File('../../public/examples/assets/files/test.txt');
        $f->move('../../public/examples/assets/files/move_test.txt');

        $this->assertFalse(file_exists('../../public/examples/assets/files/test.txt'));
        $this->assertTrue(file_exists('../../public/examples/assets/files/move_test.txt'));

        $f = new Moc10_File('../../public/examples/assets/files/move_test.txt');
        $f->move('../../public/examples/assets/files/test.txt');
    }

    public function testFileDelete()
    {
        $f = new Moc10_File('../../public/examples/assets/files/test.txt');
        $f->copy('../../public/examples/assets/files/delete_test.txt');

        $f = new Moc10_File('../../public/examples/assets/files/delete_test.txt');
        $f->delete();

        $this->assertFalse(file_exists('../../public/examples/assets/files/delete_test.txt'));
    }

}

?>
Return current item: Moc10 PHP Library