WordPress.org

Make WordPress Core

Changeset 34899


Ignore:
Timestamp:
10/07/2015 06:14:14 AM (6 years ago)
Author:
jeremyfelt
Message:

Tests: Improve tests for is_upload_space_available().

  • Move all tests to a new 'multisite/isUploadSpaceAvailable.php'
  • Store original blog_upload_space values before the class is loaded.
  • Restore these values after each test tear down to avoid pollution.

Commit to testing is_upload_space_available() itself by always filtering the amount of space used through pre_get_space_used. This allows us to sanely test without worrying about the local environment. In the future, we may be able to remove some of these tests as get_upload_space_available() tests are built out and reliable.

See #34037.

Location:
trunk/tests/phpunit/tests/multisite
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/site.php

    r34898 r34899  
    10171017    }
    10181018
    1019     function test_is_upload_space_available_default() {
    1020         $this->assertTrue( is_upload_space_available() );
    1021     }
    1022 
    1023     function test_is_upload_space_available_check_disabled() {
    1024         update_site_option( 'upload_space_check_disabled', true );
    1025         $this->assertTrue( is_upload_space_available() );
    1026     }
    1027 
    1028     function test_is_upload_space_available_space_used_is_less() {
    1029         update_site_option( 'upload_space_check_disabled', false );
    1030         update_site_option( 'blog_upload_space', 350 );
    1031         add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    1032         $available = is_upload_space_available();
    1033         remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    1034 
    1035         $this->assertTrue( is_upload_space_available() );
    1036         $this->assertEquals(
    1037             $available,
    1038             self::$space_used < 350
    1039         );
    1040     }
    1041 
    1042     function test_is_upload_space_available_space_used_is_more() {
    1043         update_site_option( 'upload_space_check_disabled', false );
    1044         update_site_option( 'blog_upload_space', 250 );
    1045         add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    1046         $available = is_upload_space_available();
    1047         $used = get_space_used();
    1048         remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    1049 
    1050         $this->assertEquals(
    1051             $available,
    1052             $used < 250
    1053         );
    1054     }
    1055 
    1056     function test_is_upload_space_available_upload_space_0() {
    1057         update_site_option( 'upload_space_check_disabled', false );
    1058         update_site_option( 'blog_upload_space', 0 );
    1059         $this->assertTrue( is_upload_space_available() );
    1060     }
    1061 
    1062     function test_is_upload_space_available_upload_space_negative() {
    1063         update_site_option( 'upload_space_check_disabled', false );
    1064         update_site_option( 'blog_upload_space', -1 );
    1065         $this->assertFalse( is_upload_space_available() );
    1066     }
    1067 
    10681019    /**
    10691020     * Test the primary purpose of get_blog_post(), to retrieve a post from
Note: See TracChangeset for help on using the changeset viewer.