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?
public function testEditProduct() {
$request = $this->getRequest();
$request->setMethod('POST');
$request->setPost(array(
'id'=>'1',
'title'=>'Test Product 1a'
));
$this->dispatch('/product/edit/id/1');
$this->assertRedirectTo('/');
$this->assertQueryContentContains('a', 'Test Product 1a');
}
public function testAddProduct() {
$request = $this->getRequest();
$request->setMethod('POST');
$request->setPost(array(
'title'=>'Test Product 3'
));
$this->dispatch('/product/add/');
$this->assertRedirectTo('/');
$this->assertQueryContentContains('a', 'Test Product 3');
}
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.
public function testIndexPageListsProducts() {
$this->dispatch('/product/index/id/1');
$this->assertQueryContentContains('h1', 'Test Product 1');
}
public function testDeleteProduct() {
$request = $this->getRequest();
$request->setMethod('POST');
$this->dispatch('/product/delete/id/2');
$this->assertRedirectTo('/');
$this->assertNotQueryContentContains('a', 'Test Product 2');
}