Make WordPress Core

Changeset 34901


Ignore:
Timestamp:
10/07/2015 07:20:45 AM (9 years ago)
Author:
jeremyfelt
Message:

Tests: Improve tests for upload_is_user_over_quota().

  • Move all tests to a new 'multisite/uploadIsUserOverQuota.php'
  • Use get_space_allowed and pre_get_space_used filters to help avoid test pollution.

See #34037.

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

Legend:

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

    r34899 r34901  
    907907
    908908    /**
    909      * Provide a hardcoded amount for space used when testing upload quota,
    910      * allowed space, and available space.
    911      *
    912      * @return int
    913      */
    914     function _filter_space_used() {
    915         return 300;
    916     }
    917 
    918     function test_upload_is_user_over_quota_default() {
    919         $this->assertFalse( upload_is_user_over_quota( false ) );
    920     }
    921 
    922     function test_upload_is_user_over_quota_check_enabled() {
    923         update_site_option( 'upload_space_check_disabled', false );
    924         // will be set to ''
    925         $this->assertEmpty( get_site_option( 'upload_space_check_disabled' ) );
    926 
    927         $this->assertEquals(
    928             upload_is_user_over_quota( false ),
    929             self::$space_used > self::$space_allowed
    930         );
    931     }
    932 
    933     /**
    934      * When the upload space check is disabled, using more than the available
    935      * quota is allowed.
    936      */
    937     function test_upload_is_user_over_check_disabled() {
    938         update_site_option( 'upload_space_check_disabled', true );
    939         update_site_option( 'blog_upload_space', 100 );
    940         add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    941         $quota = upload_is_user_over_quota( false );
    942         remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    943 
    944         $this->assertFalse( $quota );
    945     }
    946 
    947     /**
    948      * If 0 is set for `blog_upload_space`, a fallback of 100 is used.
    949      */
    950     function test_upload_is_user_over_quota_upload_space_0() {
    951         update_site_option( 'upload_space_check_disabled', false );
    952         update_site_option( 'blog_upload_space', 0 );
    953 
    954         $this->assertEquals(
    955             upload_is_user_over_quota( false ),
    956             self::$space_used > self::$space_allowed
    957         );
    958     }
    959 
    960     /**
    961      * Filter the space space used as 300 to trigger a true upload quota
    962      * without requiring actual files.
    963      */
    964     function test_upload_is_user_over_quota_upload_space_0_filter_space_used() {
    965         update_site_option( 'upload_space_check_disabled', false );
    966         update_site_option( 'blog_upload_space', 0 );
    967         add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    968         $quota = upload_is_user_over_quota( false );
    969         remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    970 
    971         $this->assertTrue( $quota );
    972     }
    973 
    974     function test_upload_is_user_over_quota_upload_space_200() {
    975         update_site_option( 'upload_space_check_disabled', false );
    976         update_site_option( 'blog_upload_space', 200 );
    977         $this->assertEquals(
    978             upload_is_user_over_quota( false ),
    979             self::$space_used > 200
    980         );
    981     }
    982 
    983     function test_upload_is_user_over_quota_upload_space_200_filter_space_used() {
    984         update_site_option( 'upload_space_check_disabled', false );
    985         update_site_option( 'blog_upload_space', 200 );
    986         add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    987         $quota = upload_is_user_over_quota( false );
    988         remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    989 
    990         $this->assertTrue( $quota );
    991     }
    992 
    993     /**
    994      * If the space used is exactly the same as the available quota, an over
    995      * quota response is not expected.
    996      *
    997      * @group woo
    998      */
    999     function test_upload_is_user_over_quota_upload_space_exact() {
    1000         update_site_option( 'upload_space_check_disabled', false );
    1001         update_site_option( 'blog_upload_space', 300 );
    1002         add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    1003         $quota = upload_is_user_over_quota( false );
    1004         $used = get_space_used();
    1005         remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
    1006 
    1007         $this->assertEquals(
    1008             $quota,
    1009             $used > 300
    1010         );
    1011     }
    1012 
    1013     function test_upload_is_user_over_quota_upload_space_negative() {
    1014         update_site_option( 'upload_space_check_disabled', false );
    1015         update_site_option( 'blog_upload_space', -1 );
    1016         $this->assertTrue( upload_is_user_over_quota( false ) );
    1017     }
    1018 
    1019     /**
    1020909     * Test the primary purpose of get_blog_post(), to retrieve a post from
    1021910     * another site on the network.
Note: See TracChangeset for help on using the changeset viewer.