Drupal-TDD-如何测试块标题字符串


Drupal - TDD - How to test block title string

我的drupal块模块代码在这里

<?php
/**
 * Description: This is santa claus block module
 */
function santaclaus_block_info() {
  $blocks = array();
  $blocks['santaclaus'] = array(
    'info' => t('Santa Claus'),
  );
  return $blocks;
}
/**
* Implements hook_block_view().
*/
function santaclaus_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'santaclaus':
      $block['subject'] = 'This is santa claus block';
      $block['content'] = santaclaus_sayhi();
      break;
  }
  return $block;
}
function santaclaus_sayhi() {
  $output = t('Hello world, happy merry christmas');
  return $output;
}

我的TDD php文件

<?php
/**
 * TDD Code for santa claus block module
 */
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Bootstrap Drupal.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
class TddTests extends PHPUnit_Framework_TestCase {
    /**
     * check block title is santa
     */
    public function testCheckTitleRtnTrue() {
        "what code i want to write here"
    }
}

我想检查$block[主题]是否是"圣诞老人"?

如何在"testCheckTitleRtTrue"TDD文件中实现这一点。

请建议

我的做法如下,请分享你的想法,这样我就可以更改TDD代码

<?php
/**
 * TDD Code for santa claus block module
 */
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Bootstrap Drupal.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
class santaclaus extends PHPUnit_Framework_TestCase {
    /**
     * check block title is santa
     */
    public function testCheckTitleRtnTrue() {
        $result = module_invoke('santaclaus', 'block_view', 'santaclaus');
        $subject = $result['subject'];
        $subjectIs = 'santa';
        $this->assertEquals($subject, $subjectIs);
    }
}