What is the quickest way to dump a node to insert into a test case?

Solutions

You can use drush:

drush ev "var_export(\Drupal\node\Entity\Node::load(123)->toArray());"

and delete stuff you don't need like uuid, revision_*, ...

By the way if you are wondering why does this output old style array syntax, see https://stackoverflow.com/questions/24316347/how-to-format-var-export-to-php5-4-array-syntax

... or paste the output into your IDE and configure it to autocorrect the format.

Tags: Testing

Similar questions

The test case is not recognized by the Simpletest module
I am using Drupal 7, and the latest version of the Simpletest module. I have written a test case like the following one: This does not get recognized by the Simpletest module. Is there anything wrong in this test case?
How to write a simple test case for users by using drupal_mail() function?
I have written a custom module for sending email to registered users. And I want simple test case for that users email module. In this module I am taking a user from database and selected users preferred language and sending emails. Same as I want .test file, I don't know how to write .test file for this module. I am using the SimpleTest module, ve...
How to insert multiple tables into their respective backup tables using insert sql?
For the purpose of backup and restore i want few tables to be just backup while performing a restore process. I have created backup tables but now whenever i do restore process it shows: Actually both tables have same schema and same primary key so whenever it try to update it there is conflict. Can anyone please tell me how to do it ? One more thi...
Migrating SQL dump from Drupal 5 into Drupal 7
My site went recently down, and all the data were lost (PHP installation of Drupal 5). What I am left is simple SQL dump from PHPMyAdmin. I would like to "use" this disaster and finally migrate to Drupal 7. Because of this, I do not know how to continue. Should I install Drupal 5 first, import SQL dump, and then upgrade? Is there any way how to sav...
Using custom test helpers in your test cases
I'm trying to write test cases for my custom module and in order to speed things along for current and future testing I defined a garbage class that can spit out random data. However the testing module cannot seem to locate my Garbage class. After some debugging I realize that Drupal looks in the registry table to find the class and while my class ...
How to test Mollom - want to test mollom_form_moderation?
I have a custom form that I'm protecting with Mollom. Once validated, the form results in an entity being created and some emails being sent. If the form is valid, but Mollom says it should be moderated, I need the entity to be created with its "Held in moderation" field set, but no emails to be sent (I'll do this once an admin has said it's OK). I...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.