isProtectedMeta.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @group meta
  4. * @covers ::is_protected_meta
  5. */
  6. class Tests_Meta_isProtectedMeta extends WP_UnitTestCase {
  7. /**
  8. * @dataProvider protected_data
  9. */
  10. public function test_protected( $key ) {
  11. $this->assertTrue( is_protected_meta( $key ) );
  12. }
  13. public function protected_data() {
  14. $protected_keys = array(
  15. array( '_wp_attachment' ),
  16. );
  17. for ( $i = 0, $max = 31; $i < $max; $i ++ ) {
  18. $protected_keys[] = array( chr( $i ) . '_wp_attachment' );
  19. }
  20. for ( $i = 127, $max = 159; $i <= $max; $i ++ ) {
  21. $protected_keys[] = array( chr( $i ) . '_wp_attachment' );
  22. }
  23. $protected_keys[] = array( chr( 95 ) . '_wp_attachment' );
  24. return $protected_keys;
  25. }
  26. /**
  27. * @dataProvider unprotected_data
  28. */
  29. public function test_unprotected( $key ) {
  30. $this->assertFalse( is_protected_meta( $key ) );
  31. }
  32. public function unprotected_data() {
  33. $unprotected_keys = array(
  34. array( 'singleword' ),
  35. array( 'two_words' ),
  36. array( 'ąŌ_not_so_protected_meta' ),
  37. );
  38. for ( $i = 32, $max = 94; $i <= $max; $i ++ ) {
  39. $unprotected_keys[] = array( chr( $i ) . '_wp_attachment' );
  40. }
  41. for ( $i = 96, $max = 126; $i <= $max; $i ++ ) {
  42. $unprotected_keys[] = array( chr( $i ) . '_wp_attachment' );
  43. }
  44. return $unprotected_keys;
  45. }
  46. }