Re: CakePHP 3 Unit Testing: posting data does not seem to be refactored by request object

2015-05-11 Thread HVan
Maybe I'm also doing something wrong with the Request object.

In the Integration Controller Test, when I $this->cookie('x',y');

And in the controller when I $this->loadComponent('Cookie'); 
print_r($this->Cookie->read('x'));

Nothing displays. Am I doing it the right way or is something missing?

On Monday, May 11, 2015 at 9:53:23 PM UTC-7, HVan wrote:
>
> I wrote a test that posts data like this:
>
> $data = [ 'Clients[username]'=>'asdf' ];
> $this->post('/url',$data);
>
>
> In the controller method, when I print_r $this->request->data, it displays 
> as this:
>
> [ 'Clients[username]'=>'asdf' ]
>
> However, if I go through a browser instead of phpunit, it is formed as 
> such:
>
> [ ['Clients'=>['username'=>'asdf'] ] ] which allows me to patchEntity or 
> use newEntity with that data.
>
>
> So my question is, what is the proper way to post data when Integration 
> Testing a controller?
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


CakePHP 3 Unit Testing: posting data does not seem to be refactored by request object

2015-05-11 Thread HVan
I wrote a test that posts data like this:

$data = [ 'Clients[username]'=>'asdf' ];
$this->post('/url',$data);


In the controller method, when I print_r $this->request->data, it displays 
as this:

[ 'Clients[username]'=>'asdf' ]

However, if I go through a browser instead of phpunit, it is formed as such:

[ ['Clients'=>['username'=>'asdf'] ] ] which allows me to patchEntity or 
use newEntity with that data.


So my question is, what is the proper way to post data when Integration 
Testing a controller?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Fixtures for Models that use another Model's table

2015-05-11 Thread HVan
Nevermind - I think I found the problem. I forgot to reference the proper 
namespace because both models are in 2 separate plugins.

On Monday, May 11, 2015 at 8:46:49 PM UTC-7, HVan wrote:
>
> I have a Model, say ClientsTable, and another Model called UsersTable.
>
> ClientsTable also uses the users table, so I set useTable = users
>
> Everything works fine, until I'm creating tests. One of the tests says the 
> clients table is not found. So if I create a clients fixture and import the 
> users table, there's no way I can re-use the users table or it says the 
> users table already exists.
>
> What should I do besides generating another table for clients that is 
> identical to users?
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Fixtures for Models that use another Model's table

2015-05-11 Thread HVan
I have a Model, say ClientsTable, and another Model called UsersTable.

ClientsTable also uses the users table, so I set useTable = users

Everything works fine, until I'm creating tests. One of the tests says the 
clients table is not found. So if I create a clients fixture and import the 
users table, there's no way I can re-use the users table or it says the 
users table already exists.

What should I do besides generating another table for clients that is 
identical to users?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Custom helpers not available on error pages

2015-05-11 Thread LDSign
Ok, thanks :)

How can I do this (overriding a core helper on these error pages)?

Regards,
Frank

Am Montag, 11. Mai 2015 18:25:25 UTC+2 schrieb LDSign:
>
> Hi
>
> Ive set up some custom error pages which include the main layout 
> (including navigation) for e.g. "page not found" errors. In the 
> header-element included I make use of a custom helper (MyTextHelper extends 
> TextHelper).
>
> Unfortunatley this custom helper is not used in the error page resulting 
> in a warning "call_user_func_array() expects parameter 1 to be a valid 
> callback".
>
> How can I make this custom helper available on error pages?
>
> CakePHP 2.6.4
>
> Thanks,
> Frank
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Custom helpers not available on error pages

2015-05-11 Thread José Lorenzo
If I remember correctly (some) Error pages do not load from app controller, 
so it is safer if for the error pages you explicitly load the helpers you 
need.

On Monday, May 11, 2015 at 6:25:25 PM UTC+2, LDSign wrote:
>
> Hi
>
> Ive set up some custom error pages which include the main layout 
> (including navigation) for e.g. "page not found" errors. In the 
> header-element included I make use of a custom helper (MyTextHelper extends 
> TextHelper).
>
> Unfortunatley this custom helper is not used in the error page resulting 
> in a warning "call_user_func_array() expects parameter 1 to be a valid 
> callback".
>
> How can I make this custom helper available on error pages?
>
> CakePHP 2.6.4
>
> Thanks,
> Frank
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Custom helpers not available on error pages

2015-05-11 Thread LDSign
Hi

Ive set up some custom error pages which include the main layout (including 
navigation) for e.g. "page not found" errors. In the header-element 
included I make use of a custom helper (MyTextHelper extends TextHelper).

Unfortunatley this custom helper is not used in the error page resulting in 
a warning "call_user_func_array() expects parameter 1 to be a valid 
callback".

How can I make this custom helper available on error pages?

CakePHP 2.6.4

Thanks,
Frank

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Cake 3.0 to save with different date format ?

2015-05-11 Thread Joe T.
Here's a pastebin  (paid for it, might as 
well use it).

It occurred to me there was something i hadn't tried. i've been using an 
accessor function in the Entity to format the field to m/d/Y for screen. 
Without it, i get the time (12:00 AM), and the date digits don't have 
leading 0's. So the accessor was helping solve that. i commented that 
function and the setter works. The date goes into the SQL statement the way 
it's expected to (also without the extra format() call, just a Time object).

i've also tried commenting the setter, but end up with the original POST 
string in my UPDATE statement. So i need the setter. 

But i feel i need a getter to format it the way i want for output. i've 
been using getters to provide the individual formats i need, which feels 
like function pollution. i guess i could just use the setter to make a Time 
object & when i access the field, call ->format() on it with the format i 
need...

Suggestions for a more clever/elegant approach?

Thanks for the help.
-joe


On Monday, 11 May 2015 03:42:42 UTC-4, José Lorenzo wrote:
>
> This line means that you are storing in the entity an string, why do you 
> that? Also, how are you saving the data, can you use gist to show all your 
> code?
>
> return $this->_properties['ready_date']->format('Y-m-d');
>
> On Monday, May 11, 2015 at 7:18:50 AM UTC+2, Joe T. wrote:
>>
>> i found this topic here and on Stack Overflow: 
>> https://stackoverflow.com/questions/29336852/how-to-format-date-fields-before-save-in-cakephp-3
>> The hash on the linked Doc page is no longer valid.
>>
>> Like the original post, i don't want to use the default select-based date 
>> inputs. i'm formatting my date in US format for output ('m/d/Y') and using 
>> the 'mdy' Validator. i've also written a mutator in the Entity to convert 
>> the date string to a Time object:
>> protected function _setReadyDate($readyDate)
>> {
>> $this->_properties['ready_date'] = new Time($readyDate);
>> return $this->_properties['ready_date']->format('Y-m-d');
>> }
>>
>> i added the lines from the Stack answer to my bootstrap.php, but that 
>> didn't work either:
>> I18n::locale('en-US');
>> Type::build('datetime')->useLocaleParser();
>>
>> No matter what i do, the MySql UPDATE uses the 'm/d/Y' string instead of 
>> the date object:
>> UPDATE listings SET ready_date = '06/01/2015' , modified = '2015-05-11 
>> 05:00:54' WHERE id = 20
>>
>> What do i try next?
>>
>> Thanks,
>> joe t.
>>
>>
>>
>>
>>
>>
>> On Thursday, 2 April 2015 14:56:29 UTC-4, José Lorenzo wrote:
>>>
>>> Read this:
>>>
>>>
>>> http://book.cakephp.org/3.0/en/orm/database-basics.html#parsing-localized-datetime-data
>>>
>>> On Thursday, April 2, 2015 at 6:10:58 PM UTC+2, Celso wrote:

 Hi guys I have a table in Mysql with a date field,  and I need to allow 
 my user writes something like *31/12/2015*.


 echo $this->Form->input('data_nascimento', ['type' => 'text', 
 'maxlength'=> '10']);

 I've tried 
 Time::$defaultLocale = 'pt-BR';

 in *AppController* but the problem persists... and 
 'timezone' => 'BRT'
 in *app.php* does not works

 If I update the value directly in MySQL and use the 
 Time::setToStringFormat('dd/MM/'); 
 in AppController the date is showed in a nice format however my real 
 problem is how to save() because I don't know how change the locale of 
 Cake 
 3.0.




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Cake 3.0 to save with different date format ?

2015-05-11 Thread José Lorenzo
This line means that you are storing in the entity an string, why do you 
that? Also, how are you saving the data, can you use gist to show all your 
code?

return $this->_properties['ready_date']->format('Y-m-d');

On Monday, May 11, 2015 at 7:18:50 AM UTC+2, Joe T. wrote:
>
> i found this topic here and on Stack Overflow: 
> https://stackoverflow.com/questions/29336852/how-to-format-date-fields-before-save-in-cakephp-3
> The hash on the linked Doc page is no longer valid.
>
> Like the original post, i don't want to use the default select-based date 
> inputs. i'm formatting my date in US format for output ('m/d/Y') and using 
> the 'mdy' Validator. i've also written a mutator in the Entity to convert 
> the date string to a Time object:
> protected function _setReadyDate($readyDate)
> {
> $this->_properties['ready_date'] = new Time($readyDate);
> return $this->_properties['ready_date']->format('Y-m-d');
> }
>
> i added the lines from the Stack answer to my bootstrap.php, but that 
> didn't work either:
> I18n::locale('en-US');
> Type::build('datetime')->useLocaleParser();
>
> No matter what i do, the MySql UPDATE uses the 'm/d/Y' string instead of 
> the date object:
> UPDATE listings SET ready_date = '06/01/2015' , modified = '2015-05-11 
> 05:00:54' WHERE id = 20
>
> What do i try next?
>
> Thanks,
> joe t.
>
>
>
>
>
>
> On Thursday, 2 April 2015 14:56:29 UTC-4, José Lorenzo wrote:
>>
>> Read this:
>>
>>
>> http://book.cakephp.org/3.0/en/orm/database-basics.html#parsing-localized-datetime-data
>>
>> On Thursday, April 2, 2015 at 6:10:58 PM UTC+2, Celso wrote:
>>>
>>> Hi guys I have a table in Mysql with a date field,  and I need to allow 
>>> my user writes something like *31/12/2015*.
>>>
>>>
>>> echo $this->Form->input('data_nascimento', ['type' => 'text', 
>>> 'maxlength'=> '10']);
>>>
>>> I've tried 
>>> Time::$defaultLocale = 'pt-BR';
>>>
>>> in *AppController* but the problem persists... and 
>>> 'timezone' => 'BRT'
>>> in *app.php* does not works
>>>
>>> If I update the value directly in MySQL and use the 
>>> Time::setToStringFormat('dd/MM/'); 
>>> in AppController the date is showed in a nice format however my real 
>>> problem is how to save() because I don't know how change the locale of Cake 
>>> 3.0.
>>>
>>>
>>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.