Ticket #50666: 50666.diff
File 50666.diff, 4.9 KB (added by , 4 years ago) |
---|
-
src/wp-includes/sitemaps/class-wp-sitemaps-index.php
diff --git src/wp-includes/sitemaps/class-wp-sitemaps-index.php src/wp-includes/sitemaps/class-wp-sitemaps-index.php index 4ec1b07d92..4c93d18031 100644
class WP_Sitemaps_Index { 24 24 */ 25 25 protected $registry; 26 26 27 /** 28 * Maximum number of sitemaps to include in an index. 29 * 30 * @sincee 5.5.0 31 * 32 * @var int Maximum number of sitemaps. 33 */ 34 private $max_sitemaps = 50000; 35 27 36 /** 28 37 * WP_Sitemaps_Index constructor. 29 38 * … … class WP_Sitemaps_Index { 59 68 array_push( $sitemaps, ...$sitemap_entries ); 60 69 } 61 70 62 return $sitemaps;71 return array_slice( $sitemaps, 0, $this->max_sitemaps, true ); 63 72 } 64 73 65 74 /** -
src/wp-includes/sitemaps/class-wp-sitemaps-registry.php
diff --git src/wp-includes/sitemaps/class-wp-sitemaps-registry.php src/wp-includes/sitemaps/class-wp-sitemaps-registry.php index c232764924..c95f04c77f 100644
class WP_Sitemaps_Registry { 24 24 */ 25 25 private $sitemaps = array(); 26 26 27 /**28 * Maximum number of sitemaps to include in an index.29 *30 * @sincee 5.5.031 *32 * @var int Maximum number of sitemaps.33 */34 private $max_sitemaps = 50000;35 36 27 /** 37 28 * Adds a sitemap with route to the registry. 38 29 * … … class WP_Sitemaps_Registry { 69 60 } 70 61 71 62 /** 72 * Lists all registered sitemaps.63 * Returns all registered sitemap providers. 73 64 * 74 65 * @since 5.5.0 75 66 * 76 67 * @return WP_Sitemaps_Provider[] Array of sitemap providers. 77 68 */ 78 69 public function get_sitemaps() { 79 $total_sitemaps = count( $this->sitemaps );80 81 if ( $total_sitemaps > $this->max_sitemaps ) {82 return array_slice( $this->sitemaps, 0, $this->max_sitemaps, true );83 }84 85 70 return $this->sitemaps; 86 71 } 87 72 } -
tests/phpunit/includes/bootstrap.php
diff --git tests/phpunit/includes/bootstrap.php tests/phpunit/includes/bootstrap.php index 817aea3bbe..8c88fc45e2 100644
require __DIR__ . '/class-wp-rest-test-configurable-controller.php'; 162 162 require __DIR__ . '/class-wp-fake-block-type.php'; 163 163 require __DIR__ . '/class-wp-sitemaps-test-provider.php'; 164 164 require __DIR__ . '/class-wp-sitemaps-empty-test-provider.php'; 165 require __DIR__ . '/class-wp-sitemaps-large-test-provider.php'; 165 166 166 167 /** 167 168 * A class to handle additional command line arguments passed to the script. -
new file tests/phpunit/includes/class-wp-sitemaps-large-test-provider.php
diff --git tests/phpunit/includes/class-wp-sitemaps-large-test-provider.php tests/phpunit/includes/class-wp-sitemaps-large-test-provider.php new file mode 100644 index 0000000000..c2fbb11192
- + 1 <?php 2 3 /** 4 * Class WP_Sitemaps_Large_Test_Provider. 5 * 6 * Provides test data for additional registered providers. 7 */ 8 class WP_Sitemaps_Large_Test_Provider extends WP_Sitemaps_Provider { 9 /** 10 * WP_Sitemaps_Large_Test_Provider constructor. 11 * 12 * @param string $object_type Optional. Object type name to use. Default 'test'. 13 */ 14 public function __construct( $object_type = 'test' ) { 15 $this->object_type = $object_type; 16 } 17 18 /** 19 * Gets a URL list for a sitemap. 20 * 21 * @param int $page_num Page of results. 22 * @param string $object_subtype Optional. Object subtype name. Default empty. 23 * @return array List of URLs for a sitemap. 24 */ 25 public function get_url_list( $page_num, $object_subtype = '' ) { 26 return array_fill(0, 1000000, array( 'loc' => home_url( '/' ) ) ); 27 } 28 29 /** 30 * Lists sitemap pages exposed by this provider. 31 * 32 * The returned data is used to populate the sitemap entries of the index. 33 * 34 * @return array[] Array of sitemap entries. 35 */ 36 public function get_sitemap_entries() { 37 return array_fill(0, 1000000, array( 'loc' => home_url( '/' ) ) ); 38 } 39 40 /** 41 * Query for determining the number of pages. 42 * 43 * @param string $object_subtype Optional. Object subtype. Default empty. 44 * @return int Total number of pages. 45 */ 46 public function get_max_num_pages( $object_subtype = '' ) { 47 return 1000000; 48 } 49 } -
tests/phpunit/tests/sitemaps/sitemaps-index.php
diff --git tests/phpunit/tests/sitemaps/sitemaps-index.php tests/phpunit/tests/sitemaps/sitemaps-index.php index 5df604af8a..88b9294509 100644
class Test_WP_Sitemaps_Index extends WP_UnitTestCase { 20 20 $this->assertCount( 24, $sitemap_index->get_sitemap_list() ); 21 21 } 22 22 23 /** 24 * @ticket 50666 25 */ 26 public function test_get_sitemap_list_limit() { 27 $registry = new WP_Sitemaps_Registry(); 28 $registry->add_sitemap( 'foo', new WP_Sitemaps_Large_Test_Provider() ); 29 $sitemap_index = new WP_Sitemaps_Index( $registry ); 30 $this->assertCount( 50000, $sitemap_index->get_sitemap_list() ); 31 } 32 23 33 public function test_get_sitemap_list_no_entries() { 24 34 $registry = new WP_Sitemaps_Registry(); 25 35