<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Testing with CakePHP 1.2 &#8211; A preview</title>
	<atom:link href="http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Sat, 13 Mar 2010 15:19:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Doug Kulak</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-125220</link>
		<dc:creator>Doug Kulak</dc:creator>
		<pubDate>Fri, 10 Apr 2009 15:01:11 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-125220</guid>
		<description>@cakebaker: Thanks for the quick response!  I&#039;m relieved to hear that the CakePHP community is on top of things :)</description>
		<content:encoded><![CDATA[<p>@cakebaker: Thanks for the quick response!  I&#8217;m relieved to hear that the CakePHP community is on top of things :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-125219</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 10 Apr 2009 14:48:28 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-125219</guid>
		<description>@Doug: Thanks for your comment!

No, this test suite is outdated, and so I recommend to use the official test suite which is bundled with CakePHP. 

Hope that helps, and happy testing :)</description>
		<content:encoded><![CDATA[<p>@Doug: Thanks for your comment!</p>
<p>No, this test suite is outdated, and so I recommend to use the official test suite which is bundled with CakePHP. </p>
<p>Hope that helps, and happy testing :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Kulak</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-125169</link>
		<dc:creator>Doug Kulak</dc:creator>
		<pubDate>Fri, 10 Apr 2009 03:55:23 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-125169</guid>
		<description>Is this still the best way to test CakePHP?  I&#039;m brand new to unit testing and want to be sure I&#039;m off on the right track!</description>
		<content:encoded><![CDATA[<p>Is this still the best way to test CakePHP?  I&#8217;m brand new to unit testing and want to be sure I&#8217;m off on the right track!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-105629</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sat, 06 Sep 2008 17:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-105629</guid>
		<description>@Richard: Well, you can replace the render() method in testable_controller.php with:
&lt;code&gt;
function render($action = null, $layout = null, $file = null) {
    $this-&gt;viewContent = parent::render($action, $layout, $file);
}
&lt;/code&gt;
In your test method you can then access the view content with:
&lt;pre&gt;
&lt;code&gt;
$this-&gt;controller-&gt;viewContent;
&lt;/code&gt;
&lt;/pre&gt;
Hope that helps!</description>
		<content:encoded><![CDATA[<p>@Richard: Well, you can replace the render() method in testable_controller.php with:<br />
<pre><code>function render($action = null, $layout = null, $file = null) {
    $this-&gt;viewContent = parent::render($action, $layout, $file);
}</code></pre><br />
In your test method you can then access the view content with:</p>
<pre>
<code>$this-&gt;controller-&gt;viewContent;</code>
</pre>
<p>Hope that helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Yumul</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-105420</link>
		<dc:creator>Richard Yumul</dc:creator>
		<pubDate>Fri, 05 Sep 2008 04:44:04 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-105420</guid>
		<description>Is there a way to make cake produce the same resulting HTML when run under the testsuite versus what cake produces when an action is hit thru the web server? 

I&#039;d like to be able to capture the output.  In other words, I&#039;d like to be able to be able to capture the output when an action is executed from the testsuite, and that ideally should be the same HTML returned when the action is executed when hit thru the web server.  Does that make sense?

&lt;code&gt;
class FooTest extends CakeTestCase {
  function testBar() {
    $this-&gt;get(&#039;/foo/bar&#039;);
    // how do I get the HTML output now?
  }
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Is there a way to make cake produce the same resulting HTML when run under the testsuite versus what cake produces when an action is hit thru the web server? </p>
<p>I&#8217;d like to be able to capture the output.  In other words, I&#8217;d like to be able to be able to capture the output when an action is executed from the testsuite, and that ideally should be the same HTML returned when the action is executed when hit thru the web server.  Does that make sense?</p>
<pre><code>class FooTest extends CakeTestCase {
  function testBar() {
    $this-&gt;get('/foo/bar');
    // how do I get the HTML output now?
  }
}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noi @ Dream Production &#187; Blog Archive &#187; Lista.lu - de la start la private beta</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-96324</link>
		<dc:creator>Noi @ Dream Production &#187; Blog Archive &#187; Lista.lu - de la start la private beta</dc:creator>
		<pubDate>Thu, 26 Jun 2008 09:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-96324</guid>
		<description>[...] facut teste (adica, facem TDD - Test Driven Development), trecem pe cararea mai putin oficiala a modulului cu simpleTest pentru ca cel oficial si inca in beta are un caz pe care nu merge si nu reusim sa gasim cauza in [...]</description>
		<content:encoded><![CDATA[<p>[...] facut teste (adica, facem TDD &#8211; Test Driven Development), trecem pe cararea mai putin oficiala a modulului cu simpleTest pentru ca cel oficial si inca in beta are un caz pe care nu merge si nu reusim sa gasim cauza in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-82283</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sun, 13 Apr 2008 16:48:34 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-82283</guid>
		<description>@Richard: You have to instantiate the component and set it as property of your component, for example:
&lt;pre&gt;
public function setUp() {
    $this-&gt;myComponent = new MyComponent();
    $this-&gt;myComponent-&gt;Session = new SessionComponent();
}
&lt;/pre&gt;

@Irina: Thanks for your explanations! I will add the snippet to the code as it makes sense to show the errors. 

Regarding the post and get methods, do you think it would be better if the data have to be passed in the form &quot;data[Model][field]&quot;?</description>
		<content:encoded><![CDATA[<p>@Richard: You have to instantiate the component and set it as property of your component, for example:</p>
<pre>
public function setUp() {
    $this-&gt;myComponent = new MyComponent();
    $this-&gt;myComponent-&gt;Session = new SessionComponent();
}
</pre>
<p>@Irina: Thanks for your explanations! I will add the snippet to the code as it makes sense to show the errors. </p>
<p>Regarding the post and get methods, do you think it would be better if the data have to be passed in the form &#8220;data[Model][field]&#8220;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Irina Dumitrascu</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-2/#comment-82089</link>
		<dc:creator>Irina Dumitrascu</dc:creator>
		<pubDate>Sat, 12 Apr 2008 14:05:32 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-82089</guid>
		<description>How we mocked our components (would qualify as a slightly-soiled hack :) )

Another thing we needed for testing was to mock some components. We wanted to bypass the authentication and use a simple, fake authentication component that would pass as authenticated the user we wanted.

In order to do that we:
- hijacked cake&#039;s dispatcher class, separating the fragment that initializes the controller and starts it in a function
- in testsuite&#039;s test_dispatcher class the function was overridden, and we: 
	- added the FakeAuth component to the set of components of the controller
	- started the controller 
	- modified the pointer to the Auth component to point to our FakeAuth object, that was created when the controller was started

Please let me know if there is any less intrusive way to do this.

http://www.geocities.com/irina2000d/dispatcher.patch.txt
http://www.geocities.com/irina2000d/test_dispatcher.patch.txt</description>
		<content:encoded><![CDATA[<p>How we mocked our components (would qualify as a slightly-soiled hack :) )</p>
<p>Another thing we needed for testing was to mock some components. We wanted to bypass the authentication and use a simple, fake authentication component that would pass as authenticated the user we wanted.</p>
<p>In order to do that we:<br />
- hijacked cake&#8217;s dispatcher class, separating the fragment that initializes the controller and starts it in a function<br />
- in testsuite&#8217;s test_dispatcher class the function was overridden, and we:<br />
	- added the FakeAuth component to the set of components of the controller<br />
	- started the controller<br />
	- modified the pointer to the Auth component to point to our FakeAuth object, that was created when the controller was started</p>
<p>Please let me know if there is any less intrusive way to do this.</p>
<p><a href="http://www.geocities.com/irina2000d/dispatcher.patch.txt" rel="nofollow">http://www.geocities.com/irina2000d/dispatcher.patch.txt</a><br />
<a href="http://www.geocities.com/irina2000d/test_dispatcher.patch.txt" rel="nofollow">http://www.geocities.com/irina2000d/test_dispatcher.patch.txt</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Irina Dumitrascu</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-1/#comment-82071</link>
		<dc:creator>Irina Dumitrascu</dc:creator>
		<pubDate>Sat, 12 Apr 2008 12:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-82071</guid>
		<description>Hi,

we&#039;ve updated the code in order to be able to put more than one record/fixture in the db. Here is the patch, if you would like to integrate it:
http://www.geocities.com/irina2000d/cake_test_case.patch.txt

It contains also the &#039;cry and die&#039; fix from the previous post :)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>we&#8217;ve updated the code in order to be able to put more than one record/fixture in the db. Here is the patch, if you would like to integrate it:<br />
<a href="http://www.geocities.com/irina2000d/cake_test_case.patch.txt" rel="nofollow">http://www.geocities.com/irina2000d/cake_test_case.patch.txt</a></p>
<p>It contains also the &#8216;cry and die&#8217; fix from the previous post :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Irina Dumitrascu</title>
		<link>http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/comment-page-1/#comment-82067</link>
		<dc:creator>Irina Dumitrascu</dc:creator>
		<pubDate>Sat, 12 Apr 2008 12:01:47 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/#comment-82067</guid>
		<description>Hi,

thanks for providing this library, we use it happily in our current projects as we encountered a blocking problem with the beta official one (http://bakery.cakephp.org/articles/view/testing-models-with-cakephp-1-2-test-suite#comment-2166)

For those using the library for the first time, here are some things that we found through practice (and debugging :D):
- the order of the fixtures that you add in test_model, test_controller matters - put first the ones that do not depend on others, and last the ones that depend on others (foreign keys).
Example: if you have tags, posts, and posts_tags (that is a has and belongs to many relation between posts and tags - HABTM), import first the fixtures for posts and tags, and put posts_tags in the end, something like:
    var $fixtures = array(&#039;Posts&#039;,&#039;Tags&#039;,&#039;PostsTags&#039;);

- obvious one (but not easy to spot in the beginning): the conditions (not-nulls,bad type,uniques, foreign keys) defined in the DB must be respected (of course :D) in the data set in the fixtures. If your data does not respect it, it will not be inserted (silently).

In order to make it &quot;cry and die&quot; if the data cannot be inserted, go to vendors/testsuite/cake_test_case.php and add in the function loadFixtures, in the end after 
$sql = &#039;INSERT INTO &#039;.Inflector::underscore($fixture). ....

$ok = $db-&gt;execute($sql);
if (!$ok) {
	print(&quot;\n&quot; . &#039;There have been some errors while &#039;.
&#039;loading fixtures, aborting as the tests will &#039;.
&quot;not work.\n\n The error is: &quot; . $db-&gt;error . &quot;\n&quot;);
	die();
}

- when you create a test for a controller, and use the methods get and post with data to send, the array that you pass to the function is that one that you want to have in the controller as $this-&gt;data, not in http post form 
correct:
array(
   &#039;Post&#039;=&gt;array(&#039;title&#039; =&gt; &#039;x&#039;, &#039;contents&#039; =&gt; &#039;y&#039;)
)
while in the beginning we tried passing the data like
array( &#039;data[Post][title] =&gt; &#039;x&#039;, &#039;data[Post][contents]&#039; =&gt; &#039;y&#039;),
that mimicked the way variables are sent through HTTP for real life usage.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>thanks for providing this library, we use it happily in our current projects as we encountered a blocking problem with the beta official one (<a href="http://bakery.cakephp.org/articles/view/testing-models-with-cakephp-1-2-test-suite#comment-2166" rel="nofollow">http://bakery.cakephp.org/articles/view/testing-models-with-cakephp-1-2-test-suite#comment-2166</a>)</p>
<p>For those using the library for the first time, here are some things that we found through practice (and debugging :D):<br />
- the order of the fixtures that you add in test_model, test_controller matters &#8211; put first the ones that do not depend on others, and last the ones that depend on others (foreign keys).<br />
Example: if you have tags, posts, and posts_tags (that is a has and belongs to many relation between posts and tags &#8211; HABTM), import first the fixtures for posts and tags, and put posts_tags in the end, something like:<br />
    var $fixtures = array(&#8216;Posts&#8217;,'Tags&#8217;,'PostsTags&#8217;);</p>
<p>- obvious one (but not easy to spot in the beginning): the conditions (not-nulls,bad type,uniques, foreign keys) defined in the DB must be respected (of course :D) in the data set in the fixtures. If your data does not respect it, it will not be inserted (silently).</p>
<p>In order to make it &#8220;cry and die&#8221; if the data cannot be inserted, go to vendors/testsuite/cake_test_case.php and add in the function loadFixtures, in the end after<br />
$sql = &#8216;INSERT INTO &#8216;.Inflector::underscore($fixture). &#8230;.</p>
<p>$ok = $db-&gt;execute($sql);<br />
if (!$ok) {<br />
	print(&#8220;\n&#8221; . &#8216;There have been some errors while &#8216;.<br />
&#8216;loading fixtures, aborting as the tests will &#8216;.<br />
&#8220;not work.\n\n The error is: &#8221; . $db-&gt;error . &#8220;\n&#8221;);<br />
	die();<br />
}</p>
<p>- when you create a test for a controller, and use the methods get and post with data to send, the array that you pass to the function is that one that you want to have in the controller as $this-&gt;data, not in http post form<br />
correct:<br />
array(<br />
   &#8216;Post&#8217;=&gt;array(&#8216;title&#8217; =&gt; &#8216;x&#8217;, &#8216;contents&#8217; =&gt; &#8216;y&#8217;)<br />
)<br />
while in the beginning we tried passing the data like<br />
array( &#8216;data[Post][title] =&gt; &#8216;x&#8217;, &#8216;data[Post][contents]&#8216; =&gt; &#8216;y&#8217;),<br />
that mimicked the way variables are sent through HTTP for real life usage.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
