| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 require_once ('init.php'); 3 4 class GP_Test_User extends GP_UnitTestCase { 5 6 function test_can() { 7 $user = $this->factory->user->create(); 8 $set_1_permission = array( 'user_id' => $user->id, 'action' => 'write', 'object_type' => 'translation-set', 'object_id' => 1 ); 9 GP::$permission->create( $set_1_permission ); 10 $this->assertTrue( $user->can( 'write', 'translation-set', 1 ) ); 11 $this->assertFalse( $user->can( 'write', 'translation-set', 2 ) ); 12 $this->assertFalse( $user->can( 'write', 'translation-set' ) ); 13 $this->assertFalse( $user->can( 'write' ) ); 14 } 15 16 function test_admin_should_be_admin() { 17 $admin_user = $this->factory->user->create_admin(); 18 $this->assertTrue( $admin_user->admin() ); 19 } 20 21 function test_non_admin_user_should_not_be_admin() { 22 $nonadmin_user = $this->factory->user->create(); 23 $this->assertFalse( $nonadmin_user->admin() ); 24 } 25 26 function test_admin_should_be_able_to_do_random_actions() { 27 $admin_user = $this->factory->user->create_admin(); 28 $this->assertTrue( $admin_user->can( 'milk', 'a cow' ) ); 29 $this->assertTrue( $admin_user->can( 'milk', 'a cow', 5 ) ); 30 } 31 32 function test_non_admin_should_not_be_able_to_do_random_actions() { 33 $nonadmin_user = $this->factory->user->create(); 34 $this->assertFalse( $nonadmin_user->can( 'milk', 'a cow' ) ); 35 $this->assertFalse( $nonadmin_user->can( 'milk', 'a cow', 5 ) ); 36 } 37 38 function test_select_by_login() { 39 $user = $this->factory->user->create( array( 'user_login' => 'pijo' ) ); 40 $from_db = GP::$user->by_login( 'pijo' ); 41 $this->assertEquals( $user->id, $from_db->id ); 42 } 43 44 function test_get() { 45 $user = $this->factory->user->create(); 46 $from_db = GP::$user->get( $user ); 47 $this->assertEquals( $user->id, $from_db->id ); 48 } 49 50 function test_set_meta_should_set_meta() { 51 $user = $this->factory->user->create(); 52 $user->set_meta( 'int', 5 ); 53 $this->assertEquals( 5, $user->get_meta( 'int') ); 54 } 55 56 function test_delete_meta_should_delete_the_meta() { 57 $user = $this->factory->user->create(); 58 $user->set_meta( 'int', 5 ); 59 $user->delete_meta( 'int' ); 60 $this->assertEquals( null, $user->get_meta( 'int') ); 61 } 62 63 function test_setting_array_value_as_meta_should_come_out_as_an_array() { 64 $user = $this->factory->user->create(); 65 $user->set_meta( 'mixed', array(1, 2, 3) ); 66 $this->assertEquals( array(1, 2, 3), $user->get_meta( 'mixed' ) ); 67 } 68 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:59:35 2012 | Hosted by follow the white rabbit. |