Changeset 12604
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/classes/class-bp-activity-activity.php
r12586 r12604 269 269 } else { 270 270 if ( empty( $this->component ) ) { 271 $this->errors->add( 'bp_activity_missing_component' );271 $this->errors->add( 'bp_activity_missing_component', __( 'You need to define a component parameter to insert activity.', 'buddypress' ) ); 272 272 } else { 273 $this->errors->add( 'bp_activity_missing_type' );273 $this->errors->add( 'bp_activity_missing_type', __( 'You need to define a type parameter to insert activity.', 'buddypress' ) ); 274 274 } 275 276 return $this->errors; 277 } 278 } 279 280 /** 281 * Use this filter to make the content of your activity required. 282 * 283 * @since 6.0.0 284 * 285 * @param bool $value True if the content of the activity type is required. 286 * False otherwise. 287 * @param string $type The type of the activity we are about to insert. 288 */ 289 $type_requires_content = (bool) apply_filters( 'bp_activity_type_requires_content', $this->type === 'activity_update', $this->type ); 290 if ( $type_requires_content && ! $this->content ) { 291 if ( 'bool' === $this->error_type ) { 292 return false; 293 } else { 294 $this->errors->add( 'bp_activity_missing_content', __( 'Please enter some content to post.', 'buddypress' ) ); 275 295 276 296 return $this->errors; -
trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php
r12598 r12604 786 786 return 'Woo Hoo!'; 787 787 } 788 789 /** 790 * @ticket BP8236 791 */ 792 public function test_save_activity_requires_component() { 793 $a = bp_activity_add( 794 array( 795 'component' => '', 796 'content' => 'Activity without component content %s', 797 'type' => 'activity_update', 798 'error_type' => 'wp_error', 799 ) 800 ); 801 802 $this->assertInstanceOf( 'WP_Error', $a ); 803 $this->assertEquals( 'bp_activity_missing_component', $a->get_error_code() ); 804 } 805 806 /** 807 * @ticket BP8236 808 */ 809 public function test_save_activity_requires_type() { 810 $a = bp_activity_add( 811 array( 812 'component' => 'foobar', 813 'content' => 'Activity without type content %s', 814 'type' => '', 815 'error_type' => 'wp_error', 816 ) 817 ); 818 819 $this->assertInstanceOf( 'WP_Error', $a ); 820 $this->assertEquals( 'bp_activity_missing_type', $a->get_error_code() ); 821 } 822 823 /** 824 * @ticket BP8236 825 */ 826 public function test_save_activity_requires_content() { 827 $a = bp_activity_add( 828 array( 829 'component' => buddypress()->activity->id, 830 'content' => '', 831 'type' => 'activity_update', 832 'error_type' => 'wp_error', 833 ) 834 ); 835 836 $this->assertInstanceOf( 'WP_Error', $a ); 837 $this->assertEquals( 'bp_activity_missing_content', $a->get_error_code() ); 838 } 839 840 /** 841 * @ticket BP8236 842 */ 843 public function test_save_activity_does_not_require_content() { 844 $a = bp_activity_add( 845 array( 846 'component' => buddypress()->members->id, 847 'content' => '', 848 'type' => 'new_member', 849 'error_type' => 'wp_error', 850 ) 851 ); 852 853 $this->assertFalse( is_wp_error( $a ) ); 854 } 855 856 /** 857 * @ticket BP8236 858 */ 859 public function test_save_activity_custom_type_requires_content() { 860 add_filter( 'bp_activity_type_requires_content', '__return_true' ); 861 862 $a = bp_activity_add( 863 array( 864 'component' => 'foo', 865 'content' => '', 866 'type' => 'bar', 867 'error_type' => 'wp_error', 868 ) 869 ); 870 871 remove_filter( 'bp_activity_type_requires_content', '__return_true' ); 872 873 $this->assertInstanceOf( 'WP_Error', $a ); 874 $this->assertEquals( 'bp_activity_missing_content', $a->get_error_code() ); 875 } 788 876 }
Note: See TracChangeset
for help on using the changeset viewer.