Making WordPress.org

Changeset 11787


Ignore:
Timestamp:
04/25/2022 10:24:42 PM (3 years ago)
Author:
iandunn
Message:

Props: Remove old /props handler and tests.

Location:
sites/trunk/common/includes/slack/props
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/slack/props/lib.php

    r11786 r11787  
    22
    33namespace Dotorg\Slack\Props;
    4 use Dotorg\Slack\Send;
     4use Exception;
    55use function Dotorg\Profiles\{ post as profiles_post };
    6 
    7 function show_error( $user ) {
    8     return "Please use `/props SLACK_USERNAME MESSAGE` to give props.\n";
    9 }
    10 
    11 /**
    12  * Receive `/props` request and send to `#props`.
    13  *
    14  * This is being deprecated in favor of `handle_props_message()`.
    15  *
    16  * @param array $data
    17  * @param bool  $force_test Send to test channel instead of #props
    18  *
    19  * @return string
    20  */
    21 function run( $data, $force_test = false ) {
    22     $sender = $data['user_name'];
    23 
    24     if ( $data['command'] !== '/props' ) {
    25         return "???\n";
    26     }
    27 
    28     if ( empty( $data['text'] ) ) {
    29         return show_error( $sender );
    30     }
    31 
    32     list( $receiver, $message ) = @preg_split( '/\s+/', trim( $data['text'] ), 2 );
    33 
    34     $receiver = ltrim( $receiver, '@' );
    35 
    36     if ( ! strlen( $receiver ) || ! strlen( $message ) ) {
    37         return show_error( $sender );
    38     }
    39 
    40     // TODO: Add WordPress.org username to $text if different than Slack username.
    41     $text = sprintf( "Props to @%s: %s", $receiver, $message );
    42 
    43     $send = new Send( \Dotorg\Slack\Send\WEBHOOK );
    44     $send->set_username( $sender );
    45     $send->set_text( $text );
    46     $send->set_link_names( true ); // We want to the person getting props!
    47 
    48     $get_avatar = __NAMESPACE__ . '\\' . 'get_avatar';
    49 
    50     if ( function_exists( $get_avatar ) ) {
    51         $send->set_icon( call_user_func( $get_avatar, $sender, $data['user_id'], $data['team_id'] ) );
    52     }
    53 
    54     if ( $force_test ) {
    55         $send->testing( true );
    56     }
    57 
    58     $send->send( '#props' );
    59 
    60     return sprintf( "Your props to @%s have been sent.\n", $receiver );
    61 }
    626
    637/**
  • sites/trunk/common/includes/slack/props/tests/test-lib.php

    r11783 r11787  
    44use wpdbStub;
    55use PHPUnit\Framework\TestCase;
    6 use function Dotorg\Slack\Props\{ run, is_valid_props, get_recipient_slack_ids, map_slack_users_to_wporg, prepare_message };
     6use function Dotorg\Slack\Props\{ is_valid_props, get_recipient_slack_ids, map_slack_users_to_wporg, prepare_message };
    77
    88/**
     
    1919
    2020        return json_decode( $json );
    21     }
    22 
    23     /**
    24      * @covers ::run
    25      * @dataProvider data_run
    26      * @group unit
    27      */
    28     public function test_run( array $request, $expected ) : void {
    29         $actual = run( $request, true );
    30 
    31         $this->assertSame( $expected, $actual );
    32     }
    33 
    34     public function data_run() : array {
    35         $valid_request = array(
    36             'user_name' => 'iandunn',
    37             'text'      => 'kimparsell Thanks for being so welcoming at WordCamp Columbus',
    38             'command'   => '/props',
    39             'user_id'   => 'U02QCF502',
    40             'team_id'   => '1',
    41         );
    42 
    43         // Can't call show_error() here since data providers run before `setUp()`.
    44         $usage   = "Please use `/props SLACK_USERNAME MESSAGE` to give props.\n";
    45         $success = "Your props to @kimparsell have been sent.\n";
    46 
    47         $cases = array(
    48             'wrong command' => array(
    49                 'request' => array_merge(
    50                     $valid_request,
    51                     array(
    52                         'command' => '/here',
    53                     )
    54                 ),
    55 
    56                 'expected' => "???\n",
    57             ),
    58 
    59             'empty text' => array(
    60                 'request' => array_merge(
    61                     $valid_request,
    62                     array(
    63                         'text' => '',
    64                     )
    65                 ),
    66 
    67                 'expected' => $usage,
    68             ),
    69 
    70             'username but no message, or vice versa' => array(
    71                 'request' => array_merge(
    72                     $valid_request,
    73                     array(
    74                         'text' => 'kimparsell',
    75                     )
    76                 ),
    77 
    78                 'expected' => $usage,
    79             ),
    80 
    81             'username with @' => array(
    82                 'request' => array_merge(
    83                     $valid_request,
    84                     array(
    85                         'text' => '@' . $valid_request['text'],
    86                     )
    87                 ),
    88                 'expected' => $success,
    89             ),
    90 
    91             'username without @' => array(
    92                 'request'  => $valid_request,
    93                 'expected' => $success,
    94             ),
    95         );
    96 
    97         return $cases;
    9821    }
    9922
Note: See TracChangeset for help on using the changeset viewer.