WordPress.org

GlotPress

Changeset 551


Ignore:
Timestamp:
07/27/10 09:56:09 (4 years ago)
Author:
nbachiyski
Message:

Edit translation set + tests

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gp-includes/routes/translation-set.php

    r544 r551  
    1919        } else { 
    2020            $this->notices[] = __('The translation set was created!'); 
    21             $this->redirect( gp_url_project_locale( $project, $created_set->locale, $created_set->slug ) ); 
     21            $this->redirect( gp_url_project_locale( GP::$project->get( $created_set->project_id ), $created_set->locale, $created_set->slug ) ); 
    2222        } 
    2323    } 
     
    4444        list( $set, $project, $locale ) = $items; 
    4545        $new_set = new GP_Translation_Set( gp_post( 'set', array() ) ); 
     46        if ( $this->cannot_edit_set_and_redirect( $new_set ) ) return; 
    4647        if ( $this->invalid_and_redirect( $new_set, gp_url( '/sets/-new' ) ) ) return; 
    47         $updated_set = GP::$translation_set->update( $new_set ); 
    48         if ( $updated_set ) $project = GP::$project->get( $updated_set->project_id ); 
    49         if ( !$updated_set ) { 
     48        if ( !$set->update( $new_set ) ) { 
    5049            $this->errors[] = __('Error in updating translation set!'); 
    5150            $this->redirect(); 
    52         } else { 
    53             $this->notices[] = __('The translation set was updated!'); 
    54             $this->redirect( gp_url_project_locale( $project, $created_set->locale, $created_set->slug ) ); 
     51            return; 
    5552        } 
    56          
     53        $project = GP::$project->get( $new_set->project_id ); 
     54        $this->notices[] = __( 'The translation set was updated!' ); 
     55        $this->redirect( gp_url_project_locale( $project, $new_set->locale, $new_set->slug ) ); 
    5756    } 
    5857 
  • trunk/gp-templates/project.php

    r466 r551  
    1717<?php foreach($sub_projects as $sub_project): ?> 
    1818    <li> 
    19         <?php gp_link_project( $sub_project, esc_html( $sub_project->name )); ?>             
     19        <?php gp_link_project( $sub_project, esc_html( $sub_project->name )); ?> 
    2020        <?php gp_link_project_edit( $sub_project ); ?>           
    2121        <?php gp_link_project_delete( $sub_project ); ?> 
     
    3030        <li> 
    3131            <?php gp_link( gp_url_project( $project, gp_url_join( $set->locale, $set->slug ) ), $set->name_with_locale() ); ?> 
     32            <?php gp_link_set_edit( $set, $project ); ?> 
    3233            <span class="stats secondary"> 
    3334                <!-- 
  • trunk/t/lib/testcase-route.php

    r542 r551  
    1010        $this->route->fake_request = true; 
    1111        $this->cookies = array(); 
     12        $this->route->errors = array(); 
     13        $this->route->notices = array(); 
    1214        add_filter( 'backpress_set_cookie', array( &$this, 'filter_do_not_set_cookie' ) );       
    1315    } 
     
    4042    } 
    4143 
    42     function assertThereIsAnNoticeContaining( $text ) { 
     44    function assertThereIsANoticeContaining( $text ) { 
    4345        $this->assertThereIsAnArrayElementContaining( $text, $this->route->notices, "No notice contains '$text'" ); 
    4446    } 
    4547     
    4648    function assertThereIsAnArrayElementContaining( $text, $array, $message = null ) { 
    47         $this->assertGreaterThan( 0, count( $array ) ); 
     49        $this->assertGreaterThan( 0, count( $array ), 'The array is empty.' ); 
    4850        $message = $message? $message : "No array element contains '$text'"; 
    4951        $this->assertTrue( gp_array_any( lambda( '$e', 'gp_in( $text, $e ); ', compact('text') ), $array ), $message ); 
     
    5961        $this->assertRedirected(); 
    6062        $this->assertThereIsAnErrorContaining( 'invalid' ); 
     63    } 
     64 
     65    function assertErrorRedirect() { 
     66        $this->assertRedirected(); 
     67        $this->assertThereIsAnErrorContaining( 'Error' ); 
    6168    } 
    6269     
  • trunk/t/tests_routes/test_route_translation_set.php

    r546 r551  
    2727    function test_new_get_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 
    2828        $this->set_normal_user_as_current(); 
    29         $this->route->new_get( $this->set->id ); 
     29        $this->route->new_get(); 
    3030        $this->assertNotAllowedRedirect(); 
    3131    } 
     
    3333    function test_new_get_admin_can_view_the_form() { 
    3434        $this->set_admin_user_as_current(); 
    35         $this->route->new_get( $this->set->id ); 
     35        $this->route->new_get(); 
    3636        $this->assertTemplateLoadedIs( 'translation-set-new' ); 
    3737        $this->assertTemplateOutputNotEmpty(); 
     
    4242        $this->assertNotAllowedRedirect(); 
    4343    } 
    44  
     44     
     45    function test_new_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 
     46        $this->set_normal_user_as_current(); 
     47        $this->route->new_post(); 
     48        $this->assertNotAllowedRedirect(); 
     49    } 
     50     
    4551    function test_new_post_invalid_redirect_if_empty_set() { 
    4652        $this->set_admin_user_as_current(); 
    4753        $this->route->new_post(); 
    4854        $this->assertInvalidRedirect(); 
     55    } 
     56 
     57    function test_new_post_error_redirect_if_create_was_unsuccessful() { 
     58        $this->set_admin_user_as_current(); 
     59        GP::$translation_set = $this->getMock( 'GP_Translation_Set', array( 'create_and_select' ) ); 
     60        GP::$translation_set->expects( $this->any() )->method( 'create_and_select' ); 
     61        $_POST['set'] = $this->factory->translation_set->generate_args(); 
     62        $this->route->new_post(); 
     63        $this->assertErrorRedirect(); 
     64    } 
     65     
     66    function test_new_post_should_add_notice_if_create_was_successful() { 
     67        $this->set_admin_user_as_current();      
     68        $_POST['set'] = $this->factory->translation_set->generate_args(); 
     69        $this->route->new_post(); 
     70        $this->assertThereIsANoticeContaining( 'created' ); 
    4971    } 
    5072         
     
    7092        $this->route->edit_post( 11 ); 
    7193    } 
     94     
     95    function test_edit_post_forbidden_redirect_if_not_logged_in() { 
     96        $this->route->edit_post( $this->set->id ); 
     97        $this->assertNotAllowedRedirect(); 
     98    } 
     99     
     100    function test_edit_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 
     101        $this->set_normal_user_as_current(); 
     102        $this->route->edit_post( $this->set->id ); 
     103        $this->assertNotAllowedRedirect(); 
     104    } 
     105     
     106    function test_edit_post_invalid_redirect_if_empty_set() { 
     107        $this->set_admin_user_as_current(); 
     108        $this->route->edit_post( $this->set->id ); 
     109        $this->assertInvalidRedirect(); 
     110    } 
     111     
     112    function test_edit_post_invalid_redirect_if_missing_name() { 
     113        $this->set_admin_user_as_current(); 
     114        $_POST['set'] = $this->factory->translation_set->generate_args(); 
     115        unset( $_POST['set']['name'] ); 
     116        $this->route->edit_post( $this->set->id ); 
     117        $this->assertInvalidRedirect(); 
     118    } 
     119 
     120    function test_edit_post_should_add_notice_if_update_was_successful() { 
     121        $this->set_admin_user_as_current(); 
     122        $_POST['set'] = $this->factory->translation_set->generate_args(); 
     123        $this->route->edit_post( $this->set->id ); 
     124        $this->assertThereIsANoticeContaining( 'updated' ); 
     125    } 
     126     
     127    function test_edit_post_error_redirect_if_create_was_unsuccessful() { 
     128        $this->set_admin_user_as_current(); 
     129        GP::$translation_set = $this->getMock( 'GP_Translation_Set', array( 'update' ) ); 
     130        $_POST['set'] = $this->factory->translation_set->generate_args(); 
     131        $this->route->edit_post( $this->set->id ); 
     132        $this->assertErrorRedirect(); 
     133    } 
     134 
     135    function test_edit_post_the_set_name_should_be_updated() { 
     136        $this->set_admin_user_as_current(); 
     137        $_POST['set'] = $this->factory->translation_set->generate_args(); 
     138        $this->route->edit_post( $this->set->id ); 
     139        $this->set->reload(); 
     140        $this->assertEquals( $_POST['set']['name'], $this->set->name ); 
     141    } 
    72142} 
Note: See TracChangeset for help on using the changeset viewer.