Re: How can I test controllers with Auth component?

2010-08-10 Thread jharris
I wrote a replacement for testAction that does it the Mark Story way.
You can find info here:
http://42pixels.com/blog/testing-controllers-the-slightly-less-hard-way

It uses what I learned from Mark and Matt and kind of combines that
information into something a little more DRY. It also allows you to
use Mocks and read directly from the models after testing the action.

hth,
jeremy


On Aug 10, 12:37 pm, Hugo M ham1...@gmail.com wrote:
 I found a pseudo-nice way in this 
 page:http://www.scribd.com/doc/19344870/Super-Awesome-Advanced-CakePHP-Tips

 2010/8/10 Hugo M ham1...@gmail.com



  I've seen tutorials about using mock objects but I want to use the function
  testAction, and the tutorials I've seen don't use that funcion.

  They create its own functions and instanciate controllers and I think
  that's not the cakephp way. (sorry for my bad english)

  2010/8/10 Hugo M ham1...@gmail.com

  How can I set Auth-user object in a controller when I'm testing it?
  Because I need logged in user id { $this-Auth-user('id') } in some
  functions :S

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Adding special characters to link text

2010-08-10 Thread jharris
The reason that it prints it out as the HTML is because you don't
escape it. Like Vivi Vivi said, if you look at the manual you'll see
you need array('escape' = false) in your options.

echo $html-link('Copyright copy;', '/',array('escape'=false));

On Aug 10, 11:54 am, WhyNotSmile sharongilmor...@gmail.com wrote:
 Hi there,

 I have a link on my page, generated by $html-link('Company Name',
 '/');

 I want to add a copyright symbol to the Company name - is there any
 way to do this?  I've changed it to the raw HTML for the time being,
 so I can use a href=/Company Name copy;/a, but I'm curious as
 to whether it can be done via the html helper.

 If I insert copy; in the link text part, it prints it out as that!

 Thanks.

 Sharon

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Operation syntax

2010-08-05 Thread jharris
The technical term, in case you're interested, is called a ternary
operator.

http://php.net/manual/en/language.operators.comparison.php


On Aug 5, 12:30 pm, Dave Maharaj m...@davemaharaj.com wrote:
 Can someone explain what the ? and the : mean?

 return ($this-meta['head_title'] ? $this-meta['page_header'] : NULL);

 Does it mean

 return $this-meta['head_title'] IF $this-meta['page_header'] IS NULL / NOT
 SET?

 I googled it and looked thru php code but cannot seem to find an explanation
 anywhere.

 Thanks

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Using test cases with model relationships throws error

2010-08-05 Thread jharris
My best guess, without seeing your test case or fixtures, is that you
need to add the fixture to your $fixtures var in your test case.

i.e.,

class MenuItemTestCase extends CakeTestCase {
  var $fixtures = array('app.menu_item', 'app.alias');
}

After doing that, they should load into the test DB. Whether or not
you choose to load them manually or automatically (default) is up to
you. I'm fairly new to unit testing but it's been my experience so far
that if a fixture model is related in any way to another model, you'll
need to include that in your $fixtures var as well. In my case, I have
to include every model into the $fixtures var.

hth,
jeremy


On Aug 4, 7:43 am, generaltao general...@gmail.com wrote:
 Hi all,

 Having a strange problem with test cases here. We have two tables in
 question in this one example - Alias and MenuItem.

 - Alias belongsTo MenuItem
 - MenuItem hasMany Alias

 I am running model test cases on Alias itself. Problem is that if I
 define the MenuItem hasMany Alias relationship in the MenuItem
 itself I get a full-stop error saying

 Database table aliases for model Alias was not found.

 This is quite obviously bizarre, especially because the prob seems to
 come from MenuItem model itself. Specific points that are bizarre
 about this

 1) For some reason it seems to outright forget to use
 test_suite_aliases instead of Alias (I have no tables defined for
 Alias, hence using fixtures!)

 2) I never say in my fixtures to import the model! I was under the
 impression you needed to do var $import in the fixture to tell it to
 import model, records, etc. but I'm not doing so in either fixture
 here. The only thing I have in my fixtures is the standard $name,
 $records, and $fields.

 Can anyone shed some light on this situation? Why is it forgetting
 to use test_suite_alias if the hasMany is defined in the model? Why is
 it using model stuff to begin with?

 Cheers!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: virtual fields in conditions

2010-04-26 Thread jharris
Okay, so I figured out why I can't reference the alias in the WHERE
conditions: it's just a MySQL restriction.

As for using virtual fields in conditions, I've come to the conclusion
that the current version of Cake does not handle them.

Hope this information is helpful to someone.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: modelClass value changing - bug of feature?

2010-04-20 Thread jharris
Since you're using multiple models in your controller (the $uses var),
I think Cake is just getting confused. On construct, it probably pulls
the model name from the controller name (like how you used
Inflector::singularize()) before it loads models. Then, in the actions
it probably pulls the first model in the $uses array because the
models have been loaded. In this case, Log.

I would recommend against the $uses array unless absolutely necessary.
Use App::import() to bring it in, or ClassRegistry::init() to load it
when needed. Or bind the Log model to your Ship one, if appropriate.

In any case, try moving 'Ship' to the first item of the $uses array
and see if that works. I'd say this method is still unreliable.

hth



On Apr 20, 3:54 am, Leonid Mamchenkov leo...@mamchenkov.net wrote:
 Hello,

 I came across a weird behaviour that I cannot figure out.  The API
 documentation for Controller class (http://api.cakephp.org/class/
 controller) describes the modelClass property in the following way:

 This controller's primary model class name, the
 Inflector::classify()'ed version of the controller's $name property.
 Example: For a controller named 'Comments', the modelClass would be
 'Comment'

 This sounds exactly like what I need.  However, when I try to use, it
 doesn't always work this way.  Maybe because my controller is using
 several models, and the primary model is not the first one in the
 list.

 class ShipsController extends AppController {
   var $name = 'Ships';
   var $uses = array('Log', 'Ship');

   function __construct() {
     parent::__construct();
     # die($this-modelClass); # prints out 'Ship' and dies, as
 expected
   }

   function index() {
     die($this-modelClass); # prints out 'Log' and dies. Why Log?
   }

 }

 I first noticed the problem using CakePHP 1.2.4.  I upgraded to
 CakePHP 1.2.6, but the problem is still there.  I checked and re-
 checked all my ShipsController and AppController code to make sure I
 don't modify the modelClass or any related logic.

 Can anyone shed some light on this issue?

 I can avoid this issue altogether by always putting the primary model
 of the controller as first item of the $uses list, or call
 Inflector::singularize($this-name), but it doesn't sound elegant,
 since the functionality is there and should work.

 Thanks.

 Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
 their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com For more options, visit this group 
 athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


virtual fields in conditions

2010-04-19 Thread jharris
Hi everyone,

I've searched long and hard to find an answer to this but haven't had
luck. Tried IRC but didn't ever get a response from anyone.

Using the 1.3 branch, Is it possible to use a virtual field in a find
condition? Using the classic example,

var $virtualFields = array(
  'name' = 'CONCAT(Profile.first_name,  , Profile.last_name)'
);

$this-Profile-find('all', array(
  'conditions' = array(
'Profile.name LIKE' = 'har'
  )
));

You get the idea. The closest I've found is a forked cakephp version
on Git that supports this sort of thing (at least, it has commits that
say so). I've also done a little work where when parsing conditions I
use something like:
$conditions[$this-Profile-getVirtualField('name')] = 'har';

I don't like that above workaround for a ton of reasons. I've also
tried to directly refer to the generated alias (Profile__name) to no
avail. I'm no MySQL expert, so maybe there's a quirk with the double
underscore I'm not aware of.

If it's simply not supported as of yet, that's fine. I'll stop beating
myself up trying to figure out what I'm doing wrong ;)

-jharris

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en