I'm quite new to both Zend and QUnit and I've got a bit stuck when it comes to setting up my QUnit tests to test my JavaScript.
I'm trying to test to some DOM manipulation and I understand that I have to put the html I'm testing against inside a #qunit-fixture div in my Qunit test file. However I've got a partial view helper used in my main Zend application (works fine in my view scripts) which I just want to echo out rather than having to rewrite the html used in the helper itself (to avoid duplication). The JavaScript I am attempting to test is used in the partial view helper hence wanting to use it.
Here's the folder structure for my application with just the important files and a few others remaining:
├── 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
I want to do something like this in my qunitTestFile.html (found in js-tests)
<div id="qunit-fixture">
<?php echo $view->partial('partialViewHelperIWantToUse.phtml') ?>
</div>
but it currently doesn't work. Renaming the qunitTestFile to have a .phtml extension causes nothing to echo out but the error "call to a member function partial() on a non-object" appears in the apache error log (I expected that but it was a simple thing to try!). I have a hunch that I might need to create another bootstrap file or something but both and Zend and Qunit are new to me so I'm a bit lost. =)
I hope that's clear and I've given enough information but let me know if it isn't.
Thanks!
Since I do not exactly know which Zend version you use, I am not sure if this helps you:
The partial()-Function is a helper of your view. Since a View .phtml File is called in a Zend_View-Context (if you use an Controller-Action to show the View) you should use
$this->partial('...');
You can setup a Zend_View for yourself, but according your directory structure, I assume you use an MVC-Pattern.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.