0

我想在我的drupal 7 模块中做一些测试。所以我遵循了drupal的SimpleTest Api并实施了一些测试

例如,我正在测试登录过程。

   public function  testLogin() {
    $user = $this->drupalCreateUser(array());
    $this->drupalLogin($user);
   }

当我尝试登录时,我总是遇到这个异常:

Undefined property: MyModuleTest::$public_files_directory drupal_web_test_case.php  1692 DrupalWebTestCase->curlInitialize()

之后异常登录失败。

详细信息是这样的:

User created with name zPUkpgzN and pass 6NXRDGWy5k Pass
GET http://www.example.com/user returned 200 (1 byte). Pass
Valid HTML found on "http://www.example.com/user" Pass
Failed to set field name to zPUkpgzN Pass
Failed to set field pass to 6NXRDGWy5k Fail
Found the Log in button Fail
Found the requested form fields at user Fail
User zPUkpgzN successfully logged in.   Fail

我发现这篇文章http://drupal.org/node/1789942,我遵循了一些建议,但我唯一成功的是:

User created with name zPUkpgzN and pass 6NXRDGWy5k Pass
GET http://www.example.com/user returned 200 (1 byte). Pass
Valid HTML found on "http://www.example.com/user" Pass
Failed to set field name to zPUkpgzN Pass
Failed to set field pass to 6NXRDGWy5k Pass
Found the Log in button Fail
Found the requested form fields at user Pass
User zPUkpgzN successfully logged in.   Fail

有什么建议么?

谢谢。

桑登姆。

4

2 回答 2

0

如果你不调用 parent::setUp(),$public_files_directory 不会被定义。

于 2013-12-18T21:38:33.907 回答
0

我在一分钟前修好了。异常仍然存在,但测试已成功。

I followed this approach:

  public function  testLogin() {
    $user = $this->drupalCreateUser(array());
    $user->roles[] = 'authenticated user'; //Defining user role
    user_save( $user ); //Save user in testing database

    $this->drupalLogin($user);//success!!!!
  }
于 2013-01-04T08:57:37.333 回答