[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/t/tests_routes/ -> test_route_translation_set.php (source)

   1  <?php
   2  require_once( dirname( __FILE__ ) . '/../init.php');
   3  
   4  class GP_Test_Route_Translation_Set extends GP_UnitTestCase_Route {
   5      var $route_class = 'GP_Route_Translation_Set';
   6  
   7  	function setUp() {
   8          parent::setUp();
   9          $this->set = $this->factory->translation_set->create_with_project_and_locale();
  10      }
  11  
  12  	function test_single_with_a_non_existent_set_gives_404() {
  13          $this->route->single( 11 );
  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_forbidden_redirect_if_not_logged_in() {
  41          $this->route->new_post();
  42          $this->assertNotAllowedRedirect();
  43      }
  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  
  51  	function test_new_post_invalid_redirect_if_empty_set() {
  52          $this->set_admin_user_as_current();
  53          $this->route->new_post();
  54          $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' );
  71      }
  72  
  73      function test_edit_get_forbidden_redirect_if_not_logged_in() {
  74          $this->route->edit_get( $this->set->id );
  75          $this->assertNotAllowedRedirect();
  76      }
  77  
  78      function test_edit_get_forbidden_redirect_if_logged_in_but_without_sufficient_permissions() {
  79          $this->set_normal_user_as_current();
  80          $this->route->edit_get( $this->set->id );
  81          $this->assertNotAllowedRedirect();
  82      }
  83  
  84  	function test_edit_get_admin_can_view_the_form() {
  85          $this->set_admin_user_as_current();
  86          $this->route->edit_get( $this->set->id );
  87          $this->assertTemplateLoadedIs( 'translation-set-edit' );
  88          $this->assertTemplateOutputNotEmpty();
  89      }
  90  
  91      function test_edit_post_with_a_non_existent_set_gives_404() {
  92          $this->route->edit_post( 11 );
  93      }
  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      }
 142  }


Generated: Thu May 23 03:59:56 2013 Hosted by follow the white rabbit.