class UserControllerTest extends Zend_Test_PHPUnit_ControllerTestCase<br>{<br> public function setUp()<br> {<br> $ this ->bootstrap = array($ this , 'appBootstrap' );<br> parent::setUp();<br> }<br><br> public function appBootstrap()<br> {<br> $ this ->frontController<br> ->registerPlugin( new Bugapp_Plugin_Initialize( 'development' ));<br> }<br><br> public function testCallWithoutActionShouldPullFromIndexAction()<br> {<br> $ this ->dispatch( '/user' );<br> $ this ->assertController( 'user' );<br> $ this ->assertAction( 'index' );<br> }<br><br> public function testIndexActionShouldContainLoginForm()<br> {<br> $ this ->dispatch( '/user' );<br> $ this ->assertAction( 'index' );<br> $ this ->assertQueryCount( 'form#loginForm' , 1);<br> }<br><br> public function testValidLoginShouldGoToProfilePage()<br> {<br> $ this ->request->setMethod( 'POST' )<br> ->setPost(array(<br> 'username' => 'foobar' ,<br> 'password' => 'foobar' <br> ));<br> $ this ->dispatch( '/user/login' );<br> $ this ->assertRedirectTo( '/user/view' );<br><br> $ this ->resetRequest()<br> ->resetResponse();<br><br> $ this ->request->setMethod( 'GET' )<br> ->setPost(array());<br> $ this ->dispatch( '/user/view' );<br> $ this ->assertRoute( 'default' );<br> $ this ->assertModule( 'default' );<br> $ this ->assertController( 'user' );<br> $ this ->assertAction( 'view' );<br> $ this ->assertNotRedirect();<br> $ this ->assertQuery( 'dl' );<br> $ this ->assertQueryContentContains( 'h2' , 'User: foobar' );<br> }<br>} <br><br> * This source code was highlighted with Source Code Highlighter .
class BugsTest extends Zend_Test_PHPUnit_DatabaseTestCase<br>{<br> private $_connectionMock;<br><br> /** <br> * . <br> * <br> * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection <br> */ <br> protected function getConnection()<br> {<br> if ($ this ->_connectionMock == null ) {<br> $connection = Zend_Db::factory(...);<br> $ this ->_connectionMock = $ this ->createZendDbConnection(<br> $connection, 'zfunittests' <br> );<br> Zend_Db_Table_Abstract::setDefaultAdapter($connection);<br> }<br> return $ this ->_connectionMock;<br> }<br><br> /** <br> * @return PHPUnit_Extensions_Database_DataSet_IDataSet <br> */ <br> protected function getDataSet()<br> {<br> return $ this ->createFlatXmlDataSet(<br> dirname(__FILE__) . '/_files/bugsSeed.xml' <br> );<br> }<br>} <br><br> * This source code was highlighted with Source Code Highlighter .
<?php<br>require_once 'PHPUnit/Extensions/SeleniumTestCase.php' ;<br> class seleniumExampleTest extends PHPUnit_Extensions_SeleniumTestCase<br>{<br> protected function setUp()<br> {<br> $ this ->setBrowser( '*firefox' );<br> $ this ->setBrowserUrl( 'http://www.google.com.au/' );<br> }<br> function testMyTestCase()<br> {<br> $ this ->open( 'http://www.google.com.au/' );<br> $ this ->type( 'q' , 'zend framework' );<br> $ this ->click( 'btnG' );<br> $ this ->waitForPageToLoad( '30000' );<br> try {<br> $ this ->assertTrue($ this ->isTextPresent( 'framework.zend.com/' ));<br> } catch (PHPUnit_Framework_AssertionFailedError $e) {<br> array_push($ this ->verificationErrors, $e->toString());<br> }<br> }<br>} <br><br> * This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/87202/
All Articles