| 1380 | * Test that a site's upload space used is actually being counted |
| 1381 | */ |
| 1382 | function test_get_space_used() { |
| 1383 | $blog_id = $this->factory->blog->create(); |
| 1384 | switch_to_blog( $blog_id ); |
| 1385 | |
| 1386 | $this->assertEquals( 0, get_space_used() ); |
| 1387 | |
| 1388 | // Upload a file to the new site. |
| 1389 | $filename = rand_str().'.jpg'; |
| 1390 | $contents = rand_str(); |
| 1391 | $file = wp_upload_bits( $filename, null, $contents ); |
| 1392 | |
| 1393 | // get_space_used() is measures in MB, get size of new file in MB |
| 1394 | $size = filesize( $file['file'] ) / 1024 / 1024; |
| 1395 | |
| 1396 | delete_transient( 'dirsize_cache' ); |
| 1397 | |
| 1398 | $this->assertEquals( $size, get_space_used() ); |
| 1399 | |
| 1400 | restore_current_blog(); |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * Test that uploads for other sites are excluded from counting towards the space used by the main site |
| 1405 | */ |
| 1406 | function test_get_space_used_exclude() { |
| 1407 | |
| 1408 | $space_used = get_space_used(); |
| 1409 | |
| 1410 | $blog_id = $this->factory->blog->create(); |
| 1411 | switch_to_blog( $blog_id ); |
| 1412 | |
| 1413 | // Upload a file to the new site. |
| 1414 | $filename = rand_str().'.jpg'; |
| 1415 | $contents = rand_str(); |
| 1416 | $file = wp_upload_bits( $filename, null, $contents ); |
| 1417 | |
| 1418 | restore_current_blog(); |
| 1419 | |
| 1420 | delete_transient( 'dirsize_cache' ); |
| 1421 | |
| 1422 | $this->assertEquals( $space_used, get_space_used() ); |
| 1423 | } |
| 1424 | |
| 1425 | /** |