class-wp-unittest-factory-for-bookmark.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Factory for creating fixtures for the deprecated Links/Bookmarks API.
  4. *
  5. * Note: The below @method notations are defined solely for the benefit of IDEs,
  6. * as a way to indicate expected return values from the given factory methods.
  7. *
  8. * @since 4.6.0
  9. *
  10. * @method int create( $args = array(), $generation_definitions = null )
  11. * @method object create_and_get( $args = array(), $generation_definitions = null )
  12. * @method int[] create_many( $count, $args = array(), $generation_definitions = null )
  13. */
  14. class WP_UnitTest_Factory_For_Bookmark extends WP_UnitTest_Factory_For_Thing {
  15. public function __construct( $factory = null ) {
  16. parent::__construct( $factory );
  17. $this->default_generation_definitions = array(
  18. 'link_name' => new WP_UnitTest_Generator_Sequence( 'Bookmark name %s' ),
  19. 'link_url' => new WP_UnitTest_Generator_Sequence( 'Bookmark URL %s' ),
  20. );
  21. }
  22. public function create_object( $args ) {
  23. return wp_insert_link( $args );
  24. }
  25. public function update_object( $link_id, $fields ) {
  26. $fields['link_id'] = $link_id;
  27. return wp_update_link( $fields );
  28. }
  29. public function get_object_by_id( $link_id ) {
  30. return get_bookmark( $link_id );
  31. }
  32. }