[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 class GP_Test_Route_Translation_Set extends GP_UnitTestCase_Route { 4 var $route_class = 'GP_Route_Translation_Set'; 5 6 function setUp() { 7 parent::setUp(); 8 $this->set = $this->factory->translation_set->create_with_project_and_locale(); 9 } 10 11 function test_single_with_a_non_existent_set_gives_404() { 12 $this->route->single( 11123123 ); 13 $this->assert404(); 14 } 15 16 function test_single_redirects_to_existing_set() { 17 $set = $this->factory->translation_set->create_with_project_and_locale( array( 'slug' => 'baba' ) ); 18 $this->route->single( $set->id ); 19 $this->assertRedirectURLContains( 'baba' ); 20 } 21 22 function test_new_get_forbidden_redirect_if_not_logged_in() { 23 $this->route->new_get(); 24 $this->assertNotAllowedRedirect(); 25 } 26 27 function test_new_get_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 28 $this->set_normal_user_as_current(); 29 $this->route->new_get(); 30 $this->assertNotAllowedRedirect(); 31 } 32 33 function test_new_get_admin_can_view_the_form() { 34 $this->set_admin_user_as_current(); 35 $this->route->new_get(); 36 $this->assertTemplateLoadedIs( 'translation-set-new' ); 37 $this->assertTemplateOutputNotEmpty(); 38 } 39 40 function test_new_post_invalid_nonce_redirect_if_not_logged_in() { 41 $this->route->new_post(); 42 $this->assertInvalidNonceRedirect(); 43 } 44 45 function test_new_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 46 $this->set_normal_user_as_current(); 47 $_POST['set'] = $this->factory->translation_set->generate_args(); 48 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); 49 $this->route->new_post(); 50 $this->assertNotAllowedRedirect(); 51 } 52 53 function test_new_post_invalid_redirect_if_empty_set() { 54 $this->set_admin_user_as_current(); 55 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); 56 $this->route->new_post(); 57 $this->assertInvalidRedirect(); 58 } 59 60 function test_new_post_error_redirect_if_create_was_unsuccessful() { 61 $this->set_admin_user_as_current(); 62 GP::$translation_set = $this->getMockBuilder('GP_Translation_Set')->setMethods(array('create_and_select'))->getMock(); 63 GP::$translation_set->expects( $this->any() )->method( 'create_and_select' ); 64 $_POST['set'] = $this->factory->translation_set->generate_args(); 65 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); 66 $this->route->new_post(); 67 $this->assertErrorRedirect(); 68 } 69 70 function test_new_post_should_add_notice_if_create_was_successful() { 71 $this->set_admin_user_as_current(); 72 $_POST['set'] = $this->factory->translation_set->generate_args(); 73 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); 74 $this->route->new_post(); 75 $this->assertThereIsANoticeContaining( 'created' ); 76 } 77 78 function test_edit_get_forbidden_redirect_if_not_logged_in() { 79 $this->route->edit_get( $this->set->id ); 80 $this->assertNotAllowedRedirect(); 81 } 82 83 function test_edit_get_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 84 $this->set_normal_user_as_current(); 85 $this->route->edit_get( $this->set->id ); 86 $this->assertNotAllowedRedirect(); 87 } 88 89 function test_edit_get_admin_can_view_the_form() { 90 $this->set_admin_user_as_current(); 91 $this->route->edit_get( $this->set->id ); 92 $this->assertTemplateLoadedIs( 'translation-set-edit' ); 93 $this->assertTemplateOutputNotEmpty(); 94 } 95 96 function test_edit_post_with_a_non_existent_set_gives_404() { 97 $this->set_admin_user_as_current(); 98 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_11' ); 99 $this->route->edit_post( 11 ); 100 $this->assert404(); 101 } 102 103 function test_edit_post_invalid_nonce_redirect_if_not_logged_in() { 104 $this->route->edit_post( $this->set->id ); 105 $this->assertInvalidNonceRedirect(); 106 } 107 108 function test_edit_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 109 $this->set_normal_user_as_current(); 110 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); 111 $this->route->edit_post( $this->set->id ); 112 $this->assertNotAllowedRedirect(); 113 } 114 115 function test_edit_post_invalid_redirect_if_empty_set() { 116 $this->set_admin_user_as_current(); 117 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); 118 $this->route->edit_post( $this->set->id ); 119 $this->assertInvalidRedirect(); 120 } 121 122 function test_edit_post_invalid_redirect_if_missing_name() { 123 $this->set_admin_user_as_current(); 124 $_POST['set'] = $this->factory->translation_set->generate_args(); 125 unset( $_POST['set']['name'] ); 126 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); 127 $this->route->edit_post( $this->set->id ); 128 $this->assertInvalidRedirect(); 129 } 130 131 function test_edit_post_should_add_notice_if_update_was_successful() { 132 $this->set_admin_user_as_current(); 133 $_POST['set'] = $this->factory->translation_set->generate_args(); 134 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); 135 $this->route->edit_post( $this->set->id ); 136 $this->assertThereIsANoticeContaining( 'updated' ); 137 } 138 139 function test_edit_post_error_redirect_if_create_was_unsuccessful() { 140 $this->set_admin_user_as_current(); 141 GP::$translation_set = $this->getMockBuilder( 'GP_Translation_Set' )->setMethods( array( 'update' ) )->getMock(); 142 $_POST['set'] = $this->factory->translation_set->generate_args(); 143 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); 144 $this->route->edit_post( $this->set->id ); 145 $this->assertErrorRedirect(); 146 } 147 148 function test_edit_post_the_set_name_should_be_updated() { 149 $this->set_admin_user_as_current(); 150 $_POST['set'] = $this->factory->translation_set->generate_args(); 151 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); 152 $this->route->edit_post( $this->set->id ); 153 $this->set->reload(); 154 $this->assertEquals( $_POST['set']['name'], $this->set->name ); 155 } 156 157 function test_delete_post_with_a_non_existent_set_gives_404() { 158 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'delete-translation-set_11' ); 159 $this->route->delete_post( 11 ); 160 $this->assert404(); 161 } 162 163 function test_delete_post_forbidden_redirect_if_not_logged_in() { 164 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'delete-translation-set_' . $this->set->id ); 165 $this->route->delete_post( $this->set->id ); 166 $this->assertNotAllowedRedirect(); 167 } 168 169 function test_delete_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { 170 $this->set_normal_user_as_current(); 171 $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'delete-translation-set_' . $this->set->id ); 172 $this->route->delete_post( $this->set->id ); 173 $this->assertNotAllowedRedirect(); 174 } 175 176 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 15 01:01:03 2024 | Cross-referenced by PHPXref 0.7.1 |