Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does one unit test the addition of a row to a database with Zend Framework & PHPUnit?
    text
    copied!<p>To test inserting/update of a row, I've written a test to simulate a post, to check that it redirects, and to check that the newly inserted/updated text is on the page. The code works, but not the test - can you tell me why it's wrong?</p> <pre><code>public function testEditProduct() { $request = $this-&gt;getRequest(); $request-&gt;setMethod('POST'); $request-&gt;setPost(array( 'id'=&gt;'1', 'title'=&gt;'Test Product 1a' )); $this-&gt;dispatch('/product/edit/id/1'); $this-&gt;assertRedirectTo('/'); $this-&gt;assertQueryContentContains('a', 'Test Product 1a'); } public function testAddProduct() { $request = $this-&gt;getRequest(); $request-&gt;setMethod('POST'); $request-&gt;setPost(array( 'title'=&gt;'Test Product 3' )); $this-&gt;dispatch('/product/add/'); $this-&gt;assertRedirectTo('/'); $this-&gt;assertQueryContentContains('a', 'Test Product 3'); } </code></pre> <p>The following tests both work, asserting that the index page with an ID parameter contains the appropriate text, and that after deleting a product that product's title is no longer displayed on the page.</p> <pre><code>public function testIndexPageListsProducts() { $this-&gt;dispatch('/product/index/id/1'); $this-&gt;assertQueryContentContains('h1', 'Test Product 1'); } public function testDeleteProduct() { $request = $this-&gt;getRequest(); $request-&gt;setMethod('POST'); $this-&gt;dispatch('/product/delete/id/2'); $this-&gt;assertRedirectTo('/'); $this-&gt;assertNotQueryContentContains('a', 'Test Product 2'); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload