Location: PHPKode > projects > Moc10 PHP Library > tests/Moc10/ImageTest.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_Image
 * @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_ImageTest extends PHPUnit_Framework_TestCase
{

    public function testImageConstructor()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.jpg');
        $class = 'Moc10_Image';
        $this->assertTrue($i instanceof $class);
    }

    public function testImageResize()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.jpg');
        $i->copy('../../public/examples/assets/images/test2.jpg');

        $i = new Moc10_Image('../../public/examples/assets/images/test2.jpg');
        $i->resize(120);

        $size = getimagesize('../../public/examples/assets/images/test2.jpg');

        $this->assertEquals(120, $i->width);
        $this->assertEquals(120, $size[0]);

        $i->delete();
    }

    public function testImageScale()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.jpg');
        $i->copy('../../public/examples/assets/images/test2.jpg');

        $i = new Moc10_Image('../../public/examples/assets/images/test2.jpg');
        $i->scale(0.5);

        $size = getimagesize('../../public/examples/assets/images/test2.jpg');

        $this->assertEquals(320, $i->width);
        $this->assertEquals(320, $size[0]);

        $i->delete();
    }

    public function testImageCrop()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.jpg');
        $i->copy('../../public/examples/assets/images/test2.jpg');

        $i = new Moc10_Image('../../public/examples/assets/images/test2.jpg');
        $i->crop(50);

        $size = getimagesize('../../public/examples/assets/images/test2.jpg');

        $this->assertEquals(50, $i->width);
        $this->assertEquals(50, $size[0]);

        $i->delete();
    }

    public function testImageConvert()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.jpg');
        $i->copy('../../public/examples/assets/images/test2.jpg');

        $i = new Moc10_Image('../../public/examples/assets/images/test2.jpg');
        $i->convert('png');

        $this->assertTrue(file_exists('../../public/examples/assets/images/test2.png'));

        $i->delete();
        unlink('../../public/examples/assets/images/test2.jpg');
    }

    public function testImageColorTotal()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.gif');
        $this->assertEquals(16, $i->colorTotal());
    }

    public function testImageGetColors()
    {
        $i = new Moc10_Image('../../public/examples/assets/images/test.gif');
        $this->assertEquals(16, count($i->getColors()));
    }

}

?>
Return current item: Moc10 PHP Library