Re: error message on select box validation
I'm having a similar problem as you two and I found this thread after a quick search: http://groups.google.de/group/cake-php/browse_thread/thread/58c30b3c249dca19/501031b9492346ee?lnk=gst&q=validation+message#501031b9492346ee It says you should use $form->input with type=select instead of the $form->select. (Alternatively you'd have to create labels and error messages for your select tag yourself.) I could not try this out yet but it seems to do what you want to be done. On 26 Okt., 10:38, ilozka <[EMAIL PROTECTED]> wrote: > Don't use $form->select, use $form->input with type=select: > > echo $form->input('answer', array('type' => 'select', 'options' => > array('0'=>'No', '1' => 'Yes'))); > > On Oct 20, 4:35 pm, clrockwell <[EMAIL PROTECTED]> wrote: > > > Thank you David, I was hoping to avoid that and simply thought I was > > doing something wrong. Thanks! > > > On Oct 19, 10:27 pm, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote: > > > > If you use $form->input(), it will create everything for an input > > > field, including label and error messages. > > > If you use the more specialized select() you'll have to create labels > > > and error messages yourself. See FormHelper::error(). > > > >http://api.cakephp.org/class_form_helper.html > > > > On 20 Oct 2008, at 07:49, clrockwell wrote: > > > > > I'm using 1.2 and this is driving me crazy. I have a form with > > > > several fields that usevalidation. When I submit an empty form for > > > > testing all fields *except* the select have the appropriate html > > > > generated and the errormessageis displayed. > > > > > The html for the select box begins with: > > > > > Occupation* > > > > > On submitting without selecting anything, the html is this (class > > > > ="form-error" now present): > > > > > Occupation* > > > > > But there is no html generated below it. Dumping Model- > > > >> invalidFields() shows: > > > > [occupation_id] => Please select the most appropriate occupation > > > > > So it is definitely there. This happens on all select boxes. The > > > > code using to generate this one: > > > > Occupation* > > >> select('Vip.occupation_id', $this->requestAction('/occupations/ > > > > occSelect', array('cache' => '1 week', 'label' => false, 'div' => > > > > false))); ?> > > > > > Thanks for any thoughts, I'm thinking this may be a bug. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Radio buttons for HABTM
It could be related, however the problem also was present when I had values for my radio buttons... --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how can i set one controller to render actions from another controller in cakephp 1.2
Passing parameters via URL: / Parameters are added with slashes into the URL after the action name, so if you have an action autocard in your controller: (let's assume it is called PostsController) function autocard ($param1, $param2) { echo $param1; echo $param2; } Now you can call this function with the URL /posts/autocard/hello/ world and it would print you in the view: hello world --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Radio buttons for HABTM
Hello, I am trying to make groups of radio buttons for a hasAndBelongsToMany relation. The background: In my application I have following relations in for my models: User hasAndBelongsToMany Workshop Workshop belongsTo Event (Event hasMany Workshop) Event belongsTo EventDay (EventDay hasMany Event) A User should be able to select exactly 1 Workshop in every EventDay, therefore I want to use a group of radio buttons for each EventDay. I don't think there is a "cake automagic" way to get this done so I'm doing this in my View to get the HTML code for the radio buttons: http://bin.cakephp.org/view/1474966345 Which generates radio buttons like this: http://bin.cakephp.org/view/680986107 The data array which comes from the View's form basically looks okay, however the IDs of the Workshops selected via the radio buttons are not always stored properly in the array. [data] => Array ( [Workshop] => Array ( [Workshop] => Array ( [0] => [1] => 3 [2] => 5 ) ) ) I don't know why certain Workshops are not saved properly in the data array; I thought it had something to do with the order of the Workshops' IDs - like if the radio button for Workshop with ID 4 comes before the Workshop with ID 2 it is not saved in the data array. However I was not able to verify this and have no clue how I should work around this as the Workshops are sorted by their starting time and not their IDs. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Validation error messages are not displayed
Bump. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Validation error messages are not displayed
I have a big problem with data validation in cakePHP 1.1 My tagErrorMsg() validation messages do not show up in the view, here is an overview over the situation: I have a User model and a Pupil model. Associations exist between User and Pupil: User hasOne Pupil; Pupil belongsTo User In addition to these associations the 'User' is also present in the AppController's $uses array (see code snippet in the appendix at the end of this post). It is needed somewhere else for getting the data to send emails. Validation rules are set inside the models (see appendix). There is a page pupils/add which has a form with fields for user data and fields for pupil data. Now the problem is that when entering invalid data into the user fields the error messages (tagErrorMsg) in the view are not displayed although the respective fields are marked as invalid in the validationErrors array. I know that the above mentioned 'User' entry in the AppController's $uses array is to blame for this because everything works fine without this entry. However the 'User' is needed in the AppController - I cannot leave it out there (it is of vital importance for my Email component). Can anyone help me fixing this problem, please? I have absolutely no idea what causes this problem. Appendix: The involved files are (code snippets): The uses array in the AppController has to contain the 'User' entry because it is needed for sending emails. AppController app_controller.php: class AppController extends Controller { var $uses = array('Logging','Email','Configuration', 'Confirmation','User'); ... } User model user.php class User extends AppModel { var $validate = array( 'username' => '/([^\d\s_]+)[a-zA-Z\d_]+$/', 'passwort' => VALID_NOT_EMPTY, 'email' => VALID_NOT_EMPTY, ); var $hasOne = array( 'Pupil' => array('className' => 'Pupil', 'foreignKey' => 'user_id', 'dependent' => true,), ); ... } Pupil model pupil.php class Pupil extends AppModel { var $validate = array( 'plz' => '^\d{5}$^', 'vorname' => VALID_NOT_EMPTY, 'nachname' => VALID_NOT_EMPTY, 'ort' => VALID_NOT_EMPTY, 'strasse' => VALID_NOT_EMPTY, 'geschlecht' => VALID_NOT_EMPTY, 'geburtsdatum' => VALID_NOT_EMPTY, 'last_class' => VALID_NOT_EMPTY, ); var $belongsTo = array( 'User' => array('className' => 'User', 'foreignKey' => 'user_id', 'dependent' => true), ); ... } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
I have found a way here in the google group (don't memorize the exact source though): input('player.vorname', array('div' => false, 'label' => false));?> The options in the secon parameter prevent the input function to automatically wrap a div tag and the column name as label around the input tag itsself. So you can for example use: input('player.vorname', array('div' => false, 'label' => false));?> -- Another issue: Do you know how to change the error message on a failed validation in a view? If I have for example VALID_NOT_EMPTY defined for my title column in the Post model, and I leave the input field for title empty in the add view a standard message is echoed. How can I alter the error message in cake 1.2? With cake 1.1 you could use the HtmlHelper and its "tagErrorMsg" function for that, but how to do this in cake 1.2? I have tried "error" function from FormHelper but it did not work. On Jul 20, 12:46 pm, oleonav <[EMAIL PROTECTED]> wrote: > If we could use something like $form->input('TransTitle.fra.content') > that would be nice. Using this produces a form input but the value is > lost. > > We can write some logic (like I have shown in my recent posts about > this topic) to loop through the TransTitle & TransContent array, but > this seems not to be the most elegant solution. Not very 'Cake' like. > Also in the controller function we have to parse things back again. > > On Jul 19, 9:37 am, zwobot <[EMAIL PROTECTED]> wrote: > > > Good question oleonav. I wondered how this works too. > > In general I want to use any label for an input field, seems like > > there is missing a parameter for an input label and you cannot use the > > second 'options' parameter to define a label as it seems. > > > On Jul 17, 4:29 am, oleonav <[EMAIL PROTECTED]> wrote: > > > > Presenting a formtag for [Article][active] is simple: > > > $form->input('Article.active'). How to output a tag for the French title > > > is > > > > a mystery to me. > > > $form->input('TransTitle.??? ') ?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
Good question oleonav. I wondered how this works too. In general I want to use any label for an input field, seems like there is missing a parameter for an input label and you cannot use the second 'options' parameter to define a label as it seems. On Jul 17, 4:29 am, oleonav <[EMAIL PROTECTED]> wrote: > > Presenting a formtag for [Article][active] is simple: > $form->input('Article.active'). How to output a tag for the French title is > > a mystery to me. > $form->input('TransTitle.??? ') ?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
> Ok this works. Some issues: > - When a translation for a language is not already in the i18n / > i18n_content tables, a errors occurs when saving. Cake tries to insert > a new record in the article table for each language not already > present. Expected behaviour would be to only create the i18n & > i18n_content records. Exactly, this is the problem I have. How to get the translations for an article into the i18n tables "simultaneously" when adding an Article/Post or whatever? I wonder how you got this data into your database: > INSERT INTO `i18n_content` (`id`, `content`) VALUES > (107, 'English title'), > (108, 'English content'), > (109, 'French titel'), > (110, 'French content'), > (111, 'Dutch title'), > (112, 'Dutch content'); > INSERT INTO `i18n` (`id`, `locale`, `i18n_content_id`, `model`, > `row_id`, `field`) VALUES > (91, 'eng', 107, 'Article', 1, 'title'), > (92, 'eng', 108, 'Article', 1, 'content'), > (93, 'fra', 109, 'Article', 1, 'title'), > (94, 'fra', 110, 'Article', 1, 'content'), > (95, 'dut', 111, 'Article', 1, 'title'), > (96, 'dut', 112, 'Article', 1, 'content'); INSERTed manually by yourself I suppose. There are some tings in your edit function I do not understand oleonav. In my edit function I just use $this->Post->save($this->data) and maybe setting the locale beforehand to tell cake which translation to edit. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
I got excited too early. I should have thought more before posting. The TranslateIt behaviour does not work as I thought it would. To be honest I don't know at all where the difference to the normal behavior is. I am going mad because of that subject... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
On Jul 11, 9:15 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Same problem here > > I have created a behavior extending from default TranslateBehavior, > decoupling content creation and translation.. > > you don't need to have existing translation entry ini18n/i18_content > anymore, it behave the same way as you use translateBehavior. > > it creates on the fly.. > > Code/Example/Description here, (first release, so feel free to correct > me ) > > http://cakeforge.org/snippet/detail.php?type=snippet&id=195 The TranslateIt Behaviour you posted seems to do exactly what I wanted. It copies a translation of an object and builds up the relationships beween the i18n tables in the database once an action is called in a language that has no translation for the objects, right? Thank you for that piece of code. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
I have done everything you said but I still did not manage to add a different language to an existing Post or Article. I have setup a completely new cake app with just the i18n tables and posts table in the database, baked the model, controllers and views. I did not change anything regarding i18n stuff in controllers or views, only added the $actsAs behaviour in the Post model. When I add a new post the locale of it is "de_de" - because of the language settings of my browser. I switched the locale of my browser with a firefox plugin to "en_us" and of course I don't see the post with the "de_de" locale I had added right before. Maybe you could send me a working code example and a dump of your database? I'm really curious about this, is this i18n stuff supposed to do what I want to do it in the first place? I begin to doubt that. On Jul 10, 10:41 pm, oleonav <[EMAIL PROTECTED]> wrote: > Two tips: > 1. Output the variables like this in your view data); ?> > it then should look more like the example I gave you. > > 2. Try using 'eng' instead of 'en' or don't set it at all. The array > would be empty if data is there I guess, haven't tried this yet > Also population of the translationsXXX arrays do not depend on setting > the locale config or something like this. They will always be > populated with all translations. I think??? > > Success. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
Thanks for your answer oleonav, unfortunately my arrays look a little bit different from yours. I have made the behaviour names unique but my array lacks the [Content] array in the TransContent (TransTitle or whatever) array: This is $this->data handed over to the edit view after setting locale to 'deu'. array(3) { ["Post"]=> array(6) { ["id"]=> string(2) "11" ["created"]=> string(19) "2007-07-10 22:02:18" ["modified"]=> string(19) "2007-07-10 22:02:18" ["locale"]=> string(3) "deu" ["title"]=> string(8) "Testtitel auf deutsch" ["body"]=> string(8) "Testbody auf deutsch" } ["TransTitle"]=> array(1) { [0]=> array(6) { ["id"]=> string(2) "25" ["locale"]=> string(3) "deu" ["i18n_content_id"]=> string(2) "25" ["model"]=> string(4) "Post" ["row_id"]=> string(2) "11" ["field"]=> string(5) "title" } } ["TransBody"]=> array(1) { [0]=> array(6) { ["id"]=> string(2) "26" ["locale"]=> string(3) "deu" ["i18n_content_id"]=> string(2) "26" ["model"]=> string(4) "Post" ["row_id"]=> string(2) "11" ["field"]=> string(4) "body" } } } setting locale to 'en' produces an empty data array. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
On 10 Jul., 12:34, "jitka (poLK)" <[EMAIL PROTECTED]> wrote: > > I tried to set ['Article']=>['locale'] in my form in the view and in > > $this->data but it did not work. > > You have to change (in controller) $this->Article->locale property. It > defaults to null (autodetection), but you can set it to any locale > string - see L10n::$__l10nMap ($locale => $language) I still don't get it. I'll post some code I have: My Model: array('title' => 'TranslationsAbstract', 'body' => 'TranslationsAbstract')); } ?> What are the differences between 'TranslationsText', 'TanslationsAbstract' and 'Translations' by the way? index, edit and add action of my PostsController: Post->locale = $locale; $this->Post->recursive = 0; $this->set('posts', $this->Post->findAll()); } function add() { $this->Post->locale = 'deu'; if (!empty($this->data)) { $this->cleanUpFields(); $this->Post->create(); if ($this->Post->save($this->data)) { $this->flash('Post saved.', array('action'=>'index')); exit(); } else { } } } function edit($id = null) { $this->Post->locale = 'en'; if (!$id && empty($this->data)) { exit(); } if (!empty($this->data)) { $this->cleanUpFields(); if ($this->Post->save($this->data)) { $this->flash('The Post saved.', array('action'=>'index')); exit(); } else { } } if (empty($this->data)) { $this->data = $this->Post->read(null, $id); } } I have "hardcoded" the $this->Post->locale = ... in the add and edit actions intentionally for test purposes. Also not that the $locale parameter in the index action is just for test purposes only to switch fast between english and german versions for the posts/index action via url Then I went to the edit action for the just added post, what I got was the edit page with an empty form. I typed the english title and body for the post and saved it, but cake did not do an UPDATE on the german post I added previously but INSERTed a completely new Post which shows only on the /posts/index/ deu page but not on /posts/index/en. So I have 2 different posts on the german index page and none on the english. What have I done wrong? Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n translation in db tables - how to do this like Symfony?
On Jun 8, 3:36 pm, trickal <[EMAIL PROTECTED]> wrote: > Hi, > > as a cake newbe I'am also playing around with the translation > behaviour. This thread helped my much to get it working. > > Right now I'm stucked with creating localized model records. This > works smoothly if i create a model record for each locale (lets say > article 1 for locale de_de, article 2 for locale en). But it fails if > I try to create 1 to n translations for a model record (article 1 for > locale de_de und locale en). This what I'm trying to do: > > // create new article record > function create() { > if (isset ($this->data['Article']['locale'])) { > $this->Article->locale = $this->data['Article']['locale']; > } > if (!empty($this->data)) { > if ($this->Article>save($this->data)) { > $this->flash('Article been saved.', '/articles'); > } > } > > } > > // update article record, this may mean that a new translation is > added or an old one is updated > function update($id = null) { > if (empty ($this->data)) { > $this->Article->id = $id; > $this->data = $this->Article->read(); > } else { > // set locale > if (isset ($this->data['Article']['locale'])) { > $this->Article->locale = > $this->data['Article']['locale']; > } > if ($this->Article->save($this->data['Article'])) { > $this->flash('Article has been updated.', > '/articles'); > } > } > > } > > There is a way to accomplish this by changig the beforeFind and > afterSave methods of the TranslateBehavior class but fear that I may > have overlooked something. Any suggestions on that? > > Thanks, This is something I really want to know too! All works fine when I INSERT the Articles and their translations manually into MySQL - I can edit and delete the Article. But how can you INSERT for example an Article in german and then save the english version of the article without creating a complete new one which has no relation to the german one?? I tried to set ['Article']=>['locale'] in my form in the view and in $this->data but it did not work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Mock "non cakey" objects, how to?
Has anyoby ever mocked classes with cake 1.1 test suite and can me give a hint how to do it? I want to mock a class that is neither a controller nor a model or any other cakey object, it just should simulate a single function that returns an array (to simulate access to the file system). I have done the following in my TestCase: When I run the test case, I get the error "Bad GroupTest [...import.test.php] with error [Non-static method Mock::generate() should not be called statically, assuming $this from incompatible context]" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Testing models with cakePHP 1.1 and TestSuite
Doesn't anyone want to help me here? zwobot wrote: > Hi everyone, > > I have cakePHP 1.1.13.4450 and installed the test suite into my app > folder. > SimpleTest is installed to app/vendors folder. > > I have a test case for my interpret model (see APPENDIX for code) > which is correctly shown in the App Test Cases I acces with the > browser (example.org/tests/) > Everytime I run the test it fails. As far as I can recreate the issue > the save method of the model does not work it returns null everytime > (see APPENDIX too). > Generic SQL queries I run with the model's query() method are executed > correctly thoguh. > > Can anybody give me hint on what is going wrong? Is my code incorrect? > The interpret model has "hasMany" associations to two other models, > could that be the problem? > > > APPENDIX: > > This is the output of the test case: > > CakePHP Test Suite v 1.0.0.0 > Individual test case: models\\interpret.test.php > Fail: C:\Programme\xampp\htdocs\musikportal_backup\app\tests\app\cases > \models\\interpret.test.php -> InterpretTest -> test_save -> Equal > expectation fails as [NULL] does not match [String: Musikgruppe] at [C: > \Programme\xampp\htdocs\musikportal_backup\app\tests\app\cases\models > \interpret.test.php line 30] > Exception: C:\Programme\xampp\htdocs\musikportal_backup\app\tests\app > \cases\models\\interpret.test.php -> InterpretTest -> test_save -> > Unexpected PHP error [Undefined property: InterpretTest::$model_data] > severity [E_NOTICE] in [C:\Programme\xampp\htdocs\musikportal_backup > \app\tests\app\cases\models\interpret.test.php] line [30] > Exception: C:\Programme\xampp\htdocs\musikportal_backup\app\tests\app > \cases\models\\interpret.test.php -> InterpretTest -> test_save -> > Unexpected PHP error [Undefined property: InterpretTest::$model_data] > severity [E_NOTICE] in [C:\Programme\xampp\htdocs\musikportal_backup > \app\tests\app\cases\models\interpret.test.php] line [31] > 1/1 test cases complete: 1 passes, 1 fails and 2 exceptions. > > > This is the code of the test class: > > class InterpretTest extends UnitTestCase > { > > var $model; > var $valid_name = 'Musikgruppe'; > var $valid_freigegeben = 0; > > function setUp() > { > > $this->model =& new Interpret(); > > } > > > function test_save() > { > > $this->model->data = array( > 'name' => $this->valid_name, > 'freigegeben' => $this->valid_freigegeben); > > $this->assertTrue($this->model->save()); > > $name = $this->model->getLastInsertId(); > $model_data = $this->model->find(array('name' => $name)); > > $this->assertEqual($this->model_data['Interpret']['name'], > $this- > >valid_name); > > $this->assertEqual($this->model_data['Interpret']['freigegeben'], > $this->valid_freigegeben); > > } > > } > > > Code of interpret model: > > class Interpret extends AppModel > { > > var $name = 'Interpret'; > > var $primaryKey = 'name'; > > var $validate = array( > 'freigegeben' => '[0-1] {1}' > ); > > var $hasMany = array('Track', 'Album'); > > } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Simpletest in cakephp
You need to install the test suite, too. You can download it there: http://cakeforge.org/projects/testsuite/ There is little documentation on the whole testing stuff in cakePHP, but afaik you just to extract the app folder of the test suite download into your app folder. You then have to write test cases/classes, the bakery has an article about testing models with cake 1.2. You cannot apply that 1:1 to prior cake versions but it gives you a general hint on how to test stuff with cakePHP. Although I'd highly prefered a decent tutorial aobut test suite in cakePHP. I have started a discussion about testing with cakePHP 1.1 here: http://groups.google.com/group/cake-php/browse_thread/thread/50745614e4717266 (anybody feel encouraged to answer to that, please). The test suite seems to be integrated in cake 1.2 but I cannot use it right now as the changes to the current stable version are not well documented (yet). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Testing models with cakePHP 1.1 and TestSuite
Hi everyone, I have cakePHP 1.1.13.4450 and installed the test suite into my app folder. SimpleTest is installed to app/vendors folder. I have a test case for my interpret model (see APPENDIX for code) which is correctly shown in the App Test Cases I acces with the browser (example.org/tests/) Everytime I run the test it fails. As far as I can recreate the issue the save method of the model does not work it returns null everytime (see APPENDIX too). Generic SQL queries I run with the model's query() method are executed correctly thoguh. Can anybody give me hint on what is going wrong? Is my code incorrect? The interpret model has "hasMany" associations to two other models, could that be the problem? APPENDIX: This is the output of the test case: CakePHP Test Suite v 1.0.0.0 Individual test case: models\\interpret.test.php Fail: C:\Programme\xampp\htdocs\musikportal_backup\app\tests\app\cases \models\\interpret.test.php -> InterpretTest -> test_save -> Equal expectation fails as [NULL] does not match [String: Musikgruppe] at [C: \Programme\xampp\htdocs\musikportal_backup\app\tests\app\cases\models \interpret.test.php line 30] Exception: C:\Programme\xampp\htdocs\musikportal_backup\app\tests\app \cases\models\\interpret.test.php -> InterpretTest -> test_save -> Unexpected PHP error [Undefined property: InterpretTest::$model_data] severity [E_NOTICE] in [C:\Programme\xampp\htdocs\musikportal_backup \app\tests\app\cases\models\interpret.test.php] line [30] Exception: C:\Programme\xampp\htdocs\musikportal_backup\app\tests\app \cases\models\\interpret.test.php -> InterpretTest -> test_save -> Unexpected PHP error [Undefined property: InterpretTest::$model_data] severity [E_NOTICE] in [C:\Programme\xampp\htdocs\musikportal_backup \app\tests\app\cases\models\interpret.test.php] line [31] 1/1 test cases complete: 1 passes, 1 fails and 2 exceptions. This is the code of the test class: class InterpretTest extends UnitTestCase { var $model; var $valid_name = 'Musikgruppe'; var $valid_freigegeben = 0; function setUp() { $this->model =& new Interpret(); } function test_save() { $this->model->data = array( 'name' => $this->valid_name, 'freigegeben' => $this->valid_freigegeben); $this->assertTrue($this->model->save()); $name = $this->model->getLastInsertId(); $model_data = $this->model->find(array('name' => $name)); $this->assertEqual($this->model_data['Interpret']['name'], $this- >valid_name); $this->assertEqual($this->model_data['Interpret']['freigegeben'], $this->valid_freigegeben); } } Code of interpret model: class Interpret extends AppModel { var $name = 'Interpret'; var $primaryKey = 'name'; var $validate = array( 'freigegeben' => '[0-1] {1}' ); var $hasMany = array('Track', 'Album'); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---