postmeta.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @group import
  4. */
  5. class Tests_Import_Postmeta extends WP_Import_UnitTestCase {
  6. function setUp() {
  7. parent::setUp();
  8. if ( ! defined( 'WP_IMPORTING' ) )
  9. define( 'WP_IMPORTING', true );
  10. if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
  11. define( 'WP_LOAD_IMPORTERS', true );
  12. require_once DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php';
  13. }
  14. function test_serialized_postmeta_no_cdata() {
  15. $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-no-cdata.xml', array( 'johncoswell' => 'john' ) );
  16. $expected['special_post_title'] = 'A special title';
  17. $expected['is_calendar'] = '';
  18. $this->assertEquals( $expected, get_post_meta( 122, 'post-options', true ) );
  19. }
  20. function test_utw_postmeta() {
  21. $this->_import_wp( DIR_TESTDATA . '/export/test-utw-post-meta-import.xml', array( 'johncoswell' => 'john' ) );
  22. $classy = new StdClass();
  23. $classy->tag = "album";
  24. $expected[] = $classy;
  25. $classy = new StdClass();
  26. $classy->tag = "apple";
  27. $expected[] = $classy;
  28. $classy = new StdClass();
  29. $classy->tag = "art";
  30. $expected[] = $classy;
  31. $classy = new StdClass();
  32. $classy->tag = "artwork";
  33. $expected[] = $classy;
  34. $classy = new StdClass();
  35. $classy->tag = "dead-tracks";
  36. $expected[] = $classy;
  37. $classy = new StdClass();
  38. $classy->tag = "ipod";
  39. $expected[] = $classy;
  40. $classy = new StdClass();
  41. $classy->tag = "itunes";
  42. $expected[] = $classy;
  43. $classy = new StdClass();
  44. $classy->tag = "javascript";
  45. $expected[] = $classy;
  46. $classy = new StdClass();
  47. $classy->tag = "lyrics";
  48. $expected[] = $classy;
  49. $classy = new StdClass();
  50. $classy->tag = "script";
  51. $expected[] = $classy;
  52. $classy = new StdClass();
  53. $classy->tag = "tracks";
  54. $expected[] = $classy;
  55. $classy = new StdClass();
  56. $classy->tag = "windows-scripting-host";
  57. $expected[] = $classy;
  58. $classy = new StdClass();
  59. $classy->tag = "wscript";
  60. $expected[] = $classy;
  61. $this->assertEquals( $expected, get_post_meta( 150, 'test', true ) );
  62. }
  63. /**
  64. * @ticket 9633
  65. */
  66. function test_serialized_postmeta_with_cdata() {
  67. $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );
  68. //HTML in the CDATA should work with old WordPress version
  69. $this->assertEquals( '<pre>some html</pre>', get_post_meta( 10, 'contains-html', true ) );
  70. //Serialised will only work with 3.0 onwards.
  71. $expected["special_post_title"] = "A special title";
  72. $expected["is_calendar"] = "";
  73. $this->assertEquals( $expected, get_post_meta( 10, 'post-options', true ) );
  74. }
  75. /**
  76. * @ticket 11574
  77. */
  78. function test_serialized_postmeta_with_evil_stuff_in_cdata() {
  79. $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );
  80. // evil content in the CDATA
  81. $this->assertEquals( '<wp:meta_value>evil</wp:meta_value>', get_post_meta( 10, 'evil', true ) );
  82. }
  83. }