Wednesday, December 1, 2010

Web tests: how do they stop when an error occured (e.g. when a behavior file can't be found)?

Hi all

I want to tweak CakePHP's web tests. I find it absolutely not useful
that they continue to run after an assertion failed, because most of
the time when one assertion fails, then the rest of the tests won't
pass, too.

So I wonder where to "hook" into the code. I have already discovered
the skip() method, and I have added some functionality that the rest
of the tests are skipped when there has been a failure somewhere. This
already saves me a lot of time.

But now I noticed that web tests discover some failures of CakePHP
themselves, so they don't seem to be completely decoupled from
CakePHP. I.e. when a behavior can't be loaded, then when running a web
test I get the appropriate error displayed:

---------------------
Missing Behavior File

Error: The Behavior file app/models/behaviors/allowance_checkable2.php
can not be found or does not exist.
Error: Create the class below in file: app/models/behaviors/
allowance_checkable2.php

<?php
class AllowanceCheckable2Behavior extends ModelBehavior {

}
?>

Notice: If you want to customize this error message, create app/views/
errors/missing_behavior_file.ctp
---------------------

So I wonder where the web test and CakePHP so that the web test aborts
in case of such an error of CakePHP and displays the error? Maybe I
could "hook" into this interface to add some functionality of my own?

Thanks for any help
Josh

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Phone Number Validation

You can try to use a virtual field: http://book.cakephp.org/view/1608/Virtual-fields

Or you can validate those fields before you save and errors are found,
use the session flash variable to show the error message.

On Nov 29, 9:18 am, "Dave Maharaj" <m...@davemaharaj.com> wrote:
> I am taking a single Model.phone and breaking the input up into 3 inputs
> (area_code) - (prefix) - (suffix) so my question is how do I validate that?
> I can merge the data to get my Model.phone and run standard validation on
> that but how to get the message on error back to the view since Model.phone
> is not on the page?
>
> My guess is validate each 3 if valid merge the data to get my Model.phone,
> but if any of the 3 are not valid (area_code) - (prefix) - (suffix) I only
> want 1 error message.
>
> I do not want individual error messages for the 3 inputs since everyone
> knows a phone number is NUMBER if they want to waste their time putting in
> letters and junk well then go ahead, I only want to return 1 error message
> for the full Model.phone (wrong length, not empty stuff like that
>
> Any ideas how to do this? Standard submit no js checking.
>
> Thanks,
>
> Dave

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: $_POST is populated with the form data, but $this->data is always empty

Did you try to check for the value of the data attribute from a method
invoked after the beforeFilter method? I would guess that the data
attribute is not set when beforeFilter is being called. Also, are you
calling the parent method on your method before reading the data?

parent::beforeFilter();

On Nov 29, 10:56 am, amfriedman <amfried...@gmail.com> wrote:
> Hey folks
>
> This is a very strange issue indeed, and at its root it is NOT related
> to this post that declares a similar symptom:http://groups.google.com/group/cake-php/browse_thread/thread/840eaa08...
>
> I have a form in /users/view/.  When I submit it and check $_POST and
> $this->data at the very beginning of AppController->beforeFilter(),
> the form data appears in the $_POST array but $this->data does not
> have any data.  In fact, $this->data is not even set by Cake!
>
> The Auth component is removed from the $components list, so I know
> that Auth is not the culprit.  I've also tried to test this form in
> different controllers/views, and I get the same problem.  Pretty
> scary, huh?
>
> --------------------------------------------------------------------------- ------------
> Here is the view code (I've also tried setting the form->create()
> first argument with a model of 'User' and used full Model.field dot
> notation for my inputs):
> --------------------------------------------------------------------------- ------------
>
>     <?php echo $form->create(NULL,
>                         array(
>                                   'default' => true,
>                                   'inputDefaults' => array(
>                                         'label' => false,
>                                         'div' => false
>                                   )
>                         )
>
>                   ); // default => onsubmit true/false  ?>
>
>                          <?php echo $form->input('username', array('size'=> 20, 'maxlength'
> => 50)); ?>
>
>                          <?php echo $form->input('pw', array('type' => 'password',
> 'size'=> 20, 'maxlength' => 50)); ?>
>
>                         <?php echo $form->submit('Log In &raquo;', array('class' =>
> 'submit', 'name' => 'submit',  'title' => 'Enter your username and
> password for access.', 'class' => 'button', 'escape' => false)); ?>
>
>         <?php echo $form->end(); ?>
>
> --------------------------------------------------------------------------- ------------
> Here is the app_controller:
> --------------------------------------------------------------------------- ------------
>         function beforeFilter() {
>
>                 pr(__CLASS__.'::'.__FUNCTION__.'()...');
>
>                 pr('POST data: ');
>                 pr($_POST);
>
>                 if(isset($this->data)) {
>                         pr('this->data: ');
>                         pr($this->data);
>                 } else { pr('this->data not set!'); }
>        // ...
>    }
>
> --------------------------------------------------------------------------- ------------
> Here is the browser output:
> --------------------------------------------------------------------------- ------------
>    AppController::beforeFilter()...
>
> POST data:
>
> Array
> (
>     [_method] => POST
>     [data] => Array
>         (
>             [User] => Array
>                 (
>                     [username] => testuser
>                     [pw] => 12345
>                 )
>
>         )
>
>     [submit] => Log In »
> )
>
> this->data not set!

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Missing Method??

thx! u just rescued a lot of my time :)
so glad to find out this group is so helpful for a beginner like me.

On Wed, Dec 1, 2010 at 2:31 PM, Amit Badkas <amit.sanisoft@gmail.com> wrote:
> Hi,
> Whenever you access URL like /books then it automatically goes to
> /books/index internally. It means if you want to provide parameter in URL
> for 'index' action of controller then your URL should be like /books/index/1
> instead of /books/1. Otherwise you need to use route to point URLs like
> /books/1 to /books/index/1 internally, more help is
> at http://book.cakephp.org/view/945/Routes-Configuration
> Amit Badkas
> PHP Applications for E-Biz: http://www.sanisoft.com
>
>
> On Wed, Dec 1, 2010 at 8:20 AM, Hans Wiriya Tsai <hansw.id@gmail.com> wrote:
>>
>> I m trying to make a controller and a view without model. Here are the
>> code:
>> Controller:
>> <?php
>> class BooksController extends AppController {
>>        var $name = 'Books';
>>        var $uses = array();
>>
>>        function index($id = 0) {
>>                $books = array (
>>                                '0' => array(
>>                                                'book_title' => 'OOP with
>> PHP5',
>>                                                'author' => 'Hasin Hayder',
>>                                                'isbn' => '1847192564',
>>                                                'release_date' => 'December
>> 2007'
>>                                        ),
>>                                '1' => array(
>>                                                'book_title' => 'Building
>> website with Joomla',
>>                                                'author' => 'Hagen Grraf',
>>                                                'isbn' => '1847192577',
>>                                                'release_date' => 'March
>> 2006'
>>                                        )
>>                );
>>                $id = intval($id);
>>                if($id < 0 || $id >= count($books)) {
>>                        $id = 0;
>>                }
>>                $this->set($books[$id]);
>>                $this->set('page_heading', 'Book Store');
>>                $this->pageTitle = 'Welcome to the Packt Book Store!';
>>        }
>> }
>>
>> View:
>>
>> <h2><?php echo $page_heading; ?></h2>
>> <dl>
>>        <lh><?php echo $book_title; ?></lh>
>>        <dt>Author:</dt><dd><?php echo $author; ?></dd>
>>        <dt>ISBN:</dt><dd><?php echo $isbn; ?></dd>
>>        <dt>Release Date:</dt><dd><?php echo $releaseDate; ?></dd>
>> </dl>
>>
>> Those are example from CakePHP Application Development, but
>> unfortunately the book was using Cake 1.2.x while I have 1.3.6
>> version. If I try to open it via
>> http://http://localhost/applogic/books/ looks OK, but if I try
>> http://http://localhost/applogic/books/1 an error occur like:
>>
>> Missing Method in BooksController
>> Error: The action 1 is not defined in controller BooksController
>>
>> Error: Create BooksController::1() in file:
>> app/controllers/books_controller.php.
>>
>> <?php
>> class BooksController extends AppController {
>>
>>        var $name = 'Books';
>>
>>
>>        function 1() {
>>
>>        }
>>
>> }
>> ?>
>>
>> Something not compatible between those 2 version?
>>
>> 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+unsubscribe@googlegroups.com For more options, visit this group
>> at http://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+unsubscribe@googlegroups.com For more options, visit this group at
> http://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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: $_SESSION contains my data but $Session helper is empty.

Come to think of it, I think I had this problem once or twice whilst tinkering around, I assumed it was something to do with my local dev server.

Good job on discovering the source of your session woes.

On 30 November 2010 21:44, amfriedman <amfriedman@gmail.com> wrote:
Actually, after about a day of mucking around in the core, I solved
the problem.  It is just a little "gotcha" with the way Cake loads
start_session(), or so it seems.

I've reproduced the bug with a clean copy of Cake 1.3.6.  The reason
why the Session helper fails is only if you have browser output (like
debug output) in the beforeFilter() function of AppController or
anywhere sooner in the dispatching process.

To test, just type some pr() statement in
AppController::beforeFilter(), and then try to reproduce my original
problem above, and you'll see that the Session helper fails.  BUT, if
you put something like $this->Session->check('blah') (even if 'blah'
is a nonexistent session key) BEFORE your pr() statement in
beforeFilter(), then the Session helper succeeds.

I believe the reason is because session_start() is not called early
enough in the application, but seems to be called on the first
instance of using the Session component (or helper), and if headers
have already been sent to the browser, session_start() fails.  (Though
it is failing silently with my PHP error reporting set to ALL.)

Yuck!  I'm glad I solved it though.  I've reported issue in Lighthouse.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en



--
Kind Regards
 Stephen @ NinjaCoderMonkey

 www.ninjacodermonkey.co.uk


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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: dynamically changing the type in form helper

Thanks for the reply...I was able to resolve it.

I am using cakephp 1.3.5. Looks like form.php was missing some code
since I resolved it by adding the case for 'text' of $input=$this-
>text($fieldName,$options); break; to the form.php file.

Thanks again. Erik

On Nov 30, 11:25 pm, John Andersen <j.andersen...@gmail.com> wrote:
> What is the value of $type1 when you get the error?
> Which version of CakePHP are you using?
> What are the values of the other variables when you get the error?
> Enjoy,
>    John
>
> On 1 Dec., 03:09, mochaman <mochama...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I want to override the input 'type' in my form using the form helper
> > but it is not picking up my values.  Here is a snippet:
>
> > echo $form->input($name,array('type'=>$type1,'label'=>$label));
>
> > I set $name, $type1, and $label as a strings read in from my config
> > xml file, however, I get the following error upon rendering the page:
>
> > Fatal error:  Method name must be a string in form.php on line 878
>
> > It appears to be an issue with $type1 since if I replace it with
> > 'text' (ie, hardcoded), then it works but everything is a text box
> > rather than date or checkbox.  I have also tried putting quotes in the
> > data but no luck...everything just defaults to textarea.
>
> > I am a newbie to php and cake so I know it is probably something
> > simple...
>
> > Any assistance is appreciated.
> > 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Migrating from CakePHP 1.1 - Yikes?!

Going from 1.1 to 1.2 is a bit tricky, but 1.2 to 1.3 is trivial.

For 1.1 to 1.2, just follow this guide:
http://book.cakephp.org/view/411/Migrating-from-CakePHP-1-1-to-1-2

Then once it is running stable under 1.2, follow:
http://book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3

It is certainly worth upgrading.

On Nov 30, 9:03 pm, M4ngoB00M <i...@paintballwarriortactics.com>
wrote:
> Hi,
>
> I have a web-application written in CakePHP 1.1 which is non-trivial
> and where I was not the original developer. I am just getting back
> into this project now and picking it up off the ground.
>
> I am wondering how painful it will be for me to migrate to the latest
> version of CakePHP (1.3) ? I realize its a factor of the code
> (details), my skills and the needs/longevity of the application - but
> whats your gut feeling for a 30000+ LOC typical business app for an
> senior engineer (intermediate php developer)?
>
> Maybe I should just limp it along under 1.1?
>
> 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en