set = $this->factory->translation_set->create_with_project_and_locale(); } function test_single_with_a_non_existent_set_gives_404() { $this->route->single( 11123123 ); $this->assert404(); } function test_single_redirects_to_existing_set() { $set = $this->factory->translation_set->create_with_project_and_locale( array( 'slug' => 'baba' ) ); $this->route->single( $set->id ); $this->assertRedirectURLContains( 'baba' ); } function test_new_get_forbidden_redirect_if_not_logged_in() { $this->route->new_get(); $this->assertNotAllowedRedirect(); } function test_new_get_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { $this->set_normal_user_as_current(); $this->route->new_get(); $this->assertNotAllowedRedirect(); } function test_new_get_admin_can_view_the_form() { $this->set_admin_user_as_current(); $this->route->new_get(); $this->assertTemplateLoadedIs( 'translation-set-new' ); $this->assertTemplateOutputNotEmpty(); } function test_new_post_invalid_nonce_redirect_if_not_logged_in() { $this->route->new_post(); $this->assertInvalidNonceRedirect(); } function test_new_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { $this->set_normal_user_as_current(); $_POST['set'] = $this->factory->translation_set->generate_args(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); $this->route->new_post(); $this->assertNotAllowedRedirect(); } function test_new_post_invalid_redirect_if_empty_set() { $this->set_admin_user_as_current(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); $this->route->new_post(); $this->assertInvalidRedirect(); } function test_new_post_error_redirect_if_create_was_unsuccessful() { $this->set_admin_user_as_current(); GP::$translation_set = $this->getMockBuilder('GP_Translation_Set')->setMethods(array('create_and_select'))->getMock(); GP::$translation_set->expects( $this->any() )->method( 'create_and_select' ); $_POST['set'] = $this->factory->translation_set->generate_args(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); $this->route->new_post(); $this->assertErrorRedirect(); } function test_new_post_should_add_notice_if_create_was_successful() { $this->set_admin_user_as_current(); $_POST['set'] = $this->factory->translation_set->generate_args(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'add-translation-set' ); $this->route->new_post(); $this->assertThereIsANoticeContaining( 'created' ); } function test_edit_get_forbidden_redirect_if_not_logged_in() { $this->route->edit_get( $this->set->id ); $this->assertNotAllowedRedirect(); } function test_edit_get_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { $this->set_normal_user_as_current(); $this->route->edit_get( $this->set->id ); $this->assertNotAllowedRedirect(); } function test_edit_get_admin_can_view_the_form() { $this->set_admin_user_as_current(); $this->route->edit_get( $this->set->id ); $this->assertTemplateLoadedIs( 'translation-set-edit' ); $this->assertTemplateOutputNotEmpty(); } function test_edit_post_with_a_non_existent_set_gives_404() { $this->set_admin_user_as_current(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_11' ); $this->route->edit_post( 11 ); $this->assert404(); } function test_edit_post_invalid_nonce_redirect_if_not_logged_in() { $this->route->edit_post( $this->set->id ); $this->assertInvalidNonceRedirect(); } function test_edit_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { $this->set_normal_user_as_current(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); $this->route->edit_post( $this->set->id ); $this->assertNotAllowedRedirect(); } function test_edit_post_invalid_redirect_if_empty_set() { $this->set_admin_user_as_current(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); $this->route->edit_post( $this->set->id ); $this->assertInvalidRedirect(); } function test_edit_post_invalid_redirect_if_missing_name() { $this->set_admin_user_as_current(); $_POST['set'] = $this->factory->translation_set->generate_args(); unset( $_POST['set']['name'] ); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); $this->route->edit_post( $this->set->id ); $this->assertInvalidRedirect(); } function test_edit_post_should_add_notice_if_update_was_successful() { $this->set_admin_user_as_current(); $_POST['set'] = $this->factory->translation_set->generate_args(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); $this->route->edit_post( $this->set->id ); $this->assertThereIsANoticeContaining( 'updated' ); } function test_edit_post_error_redirect_if_create_was_unsuccessful() { $this->set_admin_user_as_current(); GP::$translation_set = $this->getMockBuilder( 'GP_Translation_Set' )->setMethods( array( 'update' ) )->getMock(); $_POST['set'] = $this->factory->translation_set->generate_args(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); $this->route->edit_post( $this->set->id ); $this->assertErrorRedirect(); } function test_edit_post_the_set_name_should_be_updated() { $this->set_admin_user_as_current(); $_POST['set'] = $this->factory->translation_set->generate_args(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'edit-translation-set_' . $this->set->id ); $this->route->edit_post( $this->set->id ); $this->set->reload(); $this->assertEquals( $_POST['set']['name'], $this->set->name ); } function test_delete_post_with_a_non_existent_set_gives_404() { $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'delete-translation-set_11' ); $this->route->delete_post( 11 ); $this->assert404(); } function test_delete_post_forbidden_redirect_if_not_logged_in() { $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'delete-translation-set_' . $this->set->id ); $this->route->delete_post( $this->set->id ); $this->assertNotAllowedRedirect(); } function test_delete_post_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() { $this->set_normal_user_as_current(); $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'delete-translation-set_' . $this->set->id ); $this->route->delete_post( $this->set->id ); $this->assertNotAllowedRedirect(); } }