Make WordPress Core

Changeset 184 in tests


Ignore:
Timestamp:
03/23/2008 04:24:59 AM (18 years ago)
Author:
tellyworth
Message:

new and improved image tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_image.php

    r161 r184  
    226226    function test_constrain_size_for_editor_thumb() {
    227227        $out = image_constrain_size_for_editor(600, 400, 'thumb');
    228         $this->assertEquals(array(128, 85), $out);
     228        $this->assertEquals(array(150, 100), $out);
    229229       
    230230        $out = image_constrain_size_for_editor(64, 64, 'thumb');
     
    236236        global $content_width;
    237237        $content_width = 0;
     238        update_option('medium_size_w', 500);
    238239       
    239240        $out = image_constrain_size_for_editor(600, 400, 'medium');
     
    246247        $this->assertEquals(array(64, 64), $out);
    247248       
     249        // content_width should be ignored
    248250        $content_width = 350;
    249251        $out = image_constrain_size_for_editor(600, 400, 'medium');
    250         $this->assertEquals(array(350, 233), $out);
     252        $this->assertEquals(array(500, 333), $out);
    251253
    252254    }
     
    254256    function test_constrain_size_for_editor_full() {
    255257        global $content_width;
    256         $content_width = 500;
     258        $content_width = 400;
    257259        $out = image_constrain_size_for_editor(600, 400, 'full');
    258         $this->assertEquals(array(600, 400), $out);
     260        $this->assertEquals(array(400, 266), $out);
    259261       
    260262        $out = image_constrain_size_for_editor(64, 64, 'full');
    261263        $this->assertEquals(array(64, 64), $out);
    262     }
    263 
    264    
    265 }
    266 
    267 class TestIsImageFunctions extends WPTestCase {
    268     function test_is_image_positive() {
    269     }
     264       
     265        // content_width default is 500
     266        $content_width = 0;
     267
     268        $out = image_constrain_size_for_editor(600, 400, 'full');
     269        $this->assertEquals(array(500, 333), $out);
     270       
     271        $out = image_constrain_size_for_editor(64, 64, 'full');
     272        $this->assertEquals(array(64, 64), $out);
     273       
     274    }
     275
     276   
    270277}
    271278
     
    508515}
    509516
     517class TestIsImageFunctions extends WPTestCase {
     518    function test_is_image_positive() {
     519        // these are all image files recognized by php
     520        $files = array(
     521            'test-image-cmyk.jpg',
     522            'test-image.bmp',
     523            'test-image-grayscale.jpg',
     524            'test-image.gif',
     525            'test-image.png',
     526            'test-image.tiff',
     527            'test-image-lzw.tiff',
     528            'test-image.jp2',
     529            'test-image.psd',
     530            'test-image-zip.tiff',
     531            'test-image.jpg',
     532            );
     533           
     534        foreach ($files as $file) {
     535            $this->assertTrue( file_is_valid_image( DIR_TESTDATA.'/images/'.$file ), "file_is_valid_image($file) should return true" );
     536        }
     537    }
     538   
     539    function test_is_image_negative() {
     540        // these are actually image files but aren't recognized or usable by php
     541        $files = array(
     542            'test-image.pct',
     543            'test-image.tga',
     544            'test-image.sgi',
     545            );
     546           
     547        foreach ($files as $file) {
     548            $this->assertFalse( file_is_valid_image( DIR_TESTDATA.'/images/'.$file ), "file_is_valid_image($file) should return false" );
     549        }
     550    }
     551   
     552    function test_is_displayable_image_positive() {
     553        // these are all usable in typical web browsers
     554        $files = array(
     555            'test-image.gif',
     556            'test-image.png',
     557            'test-image.jpg',
     558            );
     559           
     560        foreach ($files as $file) {
     561            $this->assertTrue( file_is_displayable_image( DIR_TESTDATA.'/images/'.$file ), "file_is_valid_image($file) should return true" );
     562        }
     563    }
     564   
     565    function test_is_displayable_image_negative() {
     566        // these are image files but aren't suitable for web pages because of compatibility or size issues
     567        $files = array(
     568            'test-image-cmyk.jpg',
     569            'test-image.bmp',
     570            'test-image-grayscale.jpg',
     571            'test-image.pct',
     572            'test-image.tga',
     573            'test-image.sgi',
     574            'test-image.tiff',
     575            'test-image-lzw.tiff',
     576            'test-image.jp2',
     577            'test-image.psd',
     578            'test-image-zip.tiff',
     579            );
     580           
     581        foreach ($files as $file) {
     582            $this->assertFalse( file_is_displayable_image( DIR_TESTDATA.'/images/'.$file ), "file_is_valid_image($file) should return false" );
     583        }
     584    }
     585   
     586   
     587   
     588}
     589
     590
     591
    510592?>
Note: See TracChangeset for help on using the changeset viewer.