Making WordPress.org

Changeset 11975


Ignore:
Timestamp:
07/18/2022 08:08:49 PM (3 years ago)
Author:
iandunn
Message:

GP Profile: Update tests for bulk reviewing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/tests/e2e.php

    r11950 r11975  
    2323}
    2424
    25 const TEST_USERNAME = 'iandunn-test';
     25const TRANSLATOR_ID      = 12824495; // iandunn-test
     26const REVIEWER_ID        = 20508422; // metatestaccount
     27const TRANSLATION_SET_ID = 3;
    2628
    2729/** @var array $args */
     
    2931
    3032function main( $case ) {
    31     $user = get_user_by( 'slug', TEST_USERNAME );
     33    $translator = get_user_by( 'id', TRANSLATOR_ID );
    3234
    3335    try {
    34         call_user_func( __NAMESPACE__ . "\\test_$case", $user );
     36        add_action( 'gp_pre_can_user', __NAMESPACE__ . '\grant_editor_capabilities', 10, 2 );
     37        call_user_func( __NAMESPACE__ . "\\test_$case", $translator );
     38        echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$translator->user_nicename/, and/or the reviewer. \n";
    3539
    3640    } catch ( Exception $exception ) {
    3741        echo $exception->getMessage();
    38 
    3942    }
    4043}
    4144
    42 function test_add( WP_User $user ) {
     45function grant_editor_capabilities( $preliminary, $filter_args ) {
     46    if ( REVIEWER_ID === $filter_args['user_id'] ) {
     47        return true;
     48    } else {
     49        return $preliminary;
     50    }
     51}
     52
     53function test_suggest( WP_User $user ) {
     54    wp_set_current_user( TRANSLATOR_ID );
     55
    4356    $translation = new GP_Translation( array(
    44         'user_id' => $user->ID,
    45         'status'  => 'waiting',
     57        'user_id'            => $user->ID,
     58        'status'             => 'waiting',
     59        'translation_set_id' => TRANSLATION_SET_ID,
    4660    ) );
    4761    GlotPress_Profiles\add_single_translation_activity( $translation );
     62}
     63
     64function test_approve( WP_User $translator ) {
     65    wp_set_current_user( REVIEWER_ID );
     66
     67    $_POST['status'] = 'current';
    4868
    4969    $previous_translation = new GP_Translation( array(
    50         'user_id' => $user->ID,
    51         'status'  => 'waiting',
     70        'user_id'            => $translator->ID,
     71        'status'             => 'waiting',
     72        'translation_set_id' => TRANSLATION_SET_ID,
    5273    ) );
    5374    $translation = new GP_Translation( array(
    54         'user_id' => $user->ID,
     75        'user_id' => $translator->ID,
    5576        'status'  => 'current',
    5677    ) );
    5778    GlotPress_Profiles\add_single_translation_activity( $translation, $previous_translation );
    58 
    59     echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$user->user_nicename/ \n";
    6079}
    6180
    62 function test_bulk_approve( WP_User $user ) {
     81function test_bulk_approve( WP_User $translator ) {
     82    wp_set_current_user( REVIEWER_ID );
     83
    6384    $bulk = array(
    6485        'action'  => 'approve',
     
    6687    );
    6788    GlotPress_Profiles\add_bulk_translation_activity( new GP_Project(), new GP_Locale(), new GP_Translation_Set(), $bulk );
     89}
    6890
    69     echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$user->user_nicename/ \n";
     91function test_bulk_reject( WP_User $translator ) {
     92    wp_set_current_user( REVIEWER_ID );
     93
     94    $bulk = array(
     95        'action'  => 'reject',
     96        'row-ids' => array( '512-43', '514-44' ),
     97    );
     98    GlotPress_Profiles\add_bulk_translation_activity( new GP_Project(), new GP_Locale(), new GP_Translation_Set(), $bulk );
    7099}
Note: See TracChangeset for help on using the changeset viewer.