I'm currently developer a set of test cases for an app I'm working on.
I've read though the docs on creating tests, and have created a set of
unit tests for my model, allowing me to make confirm that my model can
save, find, update, count data and confirm relationships between
tables work.
Now I'm moving onto my controllers. Some of my controller functions
gather data and then use the $this->set method to set variable and
then I've got a simple thing to turn those into json. Those functions
are easy to test as I can just use something like:
$data = array('query' => 'Test');
$result = $this->testAction('/accounts/accountDropDown', array(
'return' => 'vars',
'method' => 'get',
'url' => $data)
);
$this->assertEqual($result['accounts'][0]['name'], 'Test
Account');
But I'm a little stuck on some of the more common things, like the
edit function. In edit I will need to test that it retrieves the
correct data as well as saving it. For the retrieving data I figured 2
sets of tests. One to confirm that the function gets the correct ID
from the URL and gathers the correct record from the model. The second
one I kinda want to test that the page rendered is correct but that
could be a big job.
So 2 questions:
1. I want to test that my function gets the correct data, but it
doesn't use $this->('key',value), it uses something more like $this-
>data = $this->Account->findById($id); , so how do I get the $this-
>data value from within my test case so I can run an assert on it? it
I just use the return=vars method and debug($result) then result is an
empty array.
2. Any advice on how to test the rendered html? I've use JSUnitTest in
the past and my website uses YUI so I'm going to investigate YUI's
unit testing for the client side code, is there something that maybe
lets me do asserts to see if html elements exist, and to also get the
value for fields? Should I be trying to write the unit tests for this
on the server or client side?
I know this may all seem a little OTT writing so much testing , but
I've started using a TDD approach for some other projects I'm working
on and found it to be very effective.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---