I want to test user login and logout.

I created a test file(Uofloggingtest.php) in user module test.
It has following code.

 class Uofloggingtest extends UnitTest {
  private User user; 
    void setUp(){  	
  	this.user=user.GetSampleUser();
  	}  	
  	void testUserSetName(){
  		this.user.setName('admin');
  		this.assertTrue(this.user.name.length)>0);
  		this.assertFlase(this.user.name=='anonym');
  		this.asserEquals('admin',this.user.getName);  
  	}  		
 }

but it shows the following error.
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /xxx/core/modules/user/lib/Drupal/user/Tests/Uofloggingtest.php on line 16

what mistake I have done?, how to rectify it?

Comments

albert volkman’s picture

PHP doesn't use dot notation to access its properties and methods. See- http://php.net/manual/en/language.oop5.basic.php

Umayal’s picture

Thanks for replay,

how to get login/logout user in a variable(using $this) for testing.

Umayal’s picture

class Uofloggingtest extends DrupalWebTestCase {
  public static function getInfo() {
    return array (
      'name' => t('UserloginTest'),
      'description' => t('User tests for my module.'),
      'group' => t('My module'),
    );
}
function testUser() { 
  // Create user and login
  $user = $this->drupalCreateUser(); 
   $this->drupalLogin($user);
  }
}