在 Qunit 测试中使用 Zend 部分视图帮助程序


Using a Zend partial view helper in Qunit tests

我对Zend和QUnit都很陌生,在设置QUnit测试来测试我的JavaScript时,我有点卡住了。

我正在尝试测试一些 DOM 操作,我知道我必须将我正在测试的 html 放在我的 Qunit 测试文件中的 #qunit 固定装置div 中。但是,我在我的主Zend应用程序中使用了一个部分视图助手(在我的视图脚本中工作正常),我只想回显出来,而不必重写助手本身中使用的html(以避免重复)。我尝试测试的 JavaScript 用于部分视图帮助程序,因此想要使用它。

这是我的应用程序的文件夹结构,只剩下重要文件和其他一些文件:

├── application
│   ├── Bootstrap.php
│   ├── configs
│   ├── controllers
│   ├── layouts
│   │   └── scripts
│   ├── models
│   ├── plugins
│   └── views
│       ├── helpers
│       └── scripts
│           ├── error
│           ├── index
│           └── partials
│               └── partialViewHelperIWantToUse.phtml
├── docs
├── features
├── Gemfile
├── Gemfile.lock
├── js-tests
│   ├── qunitTestFile.html
│   └── vendor
│       └── qunit
│           ├── qunit.css
│           └── qunit.js
├── library
│   ├── Custom
├── public
│   ├── css
│   ├── img
│   ├── index.php
│   └── js
│       ├── jquery
│       │   └── jquery-1.7.2.min.js
│       └── javaScriptIWantToTest.js
├── Rakefile
├── tasks
└── tests
    ├── application
    │   ├── controllers
    │   └── models
    ├── bootstrap.php
    ├── library
    │   └── Custom
    └── phpunit.xml

我想在我的 qunitTestFile 中做这样的事情.html(在 js-tests 中找到)

<div id="qunit-fixture">
    <?php echo $view->partial('partialViewHelperIWantToUse.phtml') ?>
</div>

但它目前不起作用。将 qunitTestFile 重命名为具有 .phtml 扩展名不会导致任何内容回显,但错误"在非对象上调用成员函数 partial()"出现在 apache 错误日志中(我预料到了这一点,但这是一件简单的事情尝试!我有一种预感,我可能需要创建另一个引导文件或其他东西,但 Zend 和 Qunit 对我来说都是新的,所以我有点迷茫。=)

我希望这是清楚的,我已经提供了足够的信息,但如果不是,请告诉我。

谢谢!

由于我不完全知道您使用哪个Zend版本,因此我不确定这是否对您有所帮助:

partial()-函数是视图的帮助程序。由于视图 .phtml 文件是在Zend_View上下文中调用的(如果使用控制器操作来显示视图),因此您应该使用

$this->partial('...');

您可以为自己设置一个Zend_View,但根据您的目录结构,我假设您使用MVC模式。