BlastDBNodeSeeder.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Tests\DatabaseSeeders;
  3. use StatonLab\TripalTestSuite\Database\Seeder;
  4. use Faker\Factory;
  5. /**
  6. * Creates test blast database nodes.
  7. *
  8. * See the code block below for an example of how to use this database seeder.
  9. * Note: the getNode() method is specific to this seeder and not standard TripalTestSuite.
  10. * @code
  11. * // Creates a test blastdb node using the Drupal Node API.
  12. * $seeder = DatabaseSeeders\BlastDBNodeSeeder::seed();
  13. * // Retrieves the node created by the seeder for use in your test.
  14. * $node = $seeder->getNode();
  15. * @endcode
  16. */
  17. class BlastDBNodeSeeder extends Seeder {
  18. var $node;
  19. /**
  20. * Seeds the database with a test blast database node.
  21. *
  22. * @return void
  23. */
  24. public function up() {
  25. // Log in the god user.
  26. global $user;
  27. $user = user_load(1);
  28. $node = new \stdClass();
  29. if (!isset($node->title)) $node->title = 'Test Blast Database';
  30. $node->type = 'blastdb';
  31. node_object_prepare($node);
  32. $node->language = LANGUAGE_NONE;
  33. $node->uid = $user->uid;
  34. $node->status = 1; // published.
  35. $node->promote = 0; // not promoted.
  36. $node->comment = 0; // disabled.
  37. $faker = Factory::create();
  38. $node->db_name = $faker->words(3, TRUE);
  39. $node->db_path = '/fake/path/here';
  40. $node->db_dbtype = 'nucleotide';
  41. $node->dbxref_linkout_type = 'none';
  42. $node->cvitjs_enabled = 0;
  43. $node = node_submit($node);
  44. node_save($node);
  45. // log out the god user.
  46. $user = drupal_anonymous_user();
  47. $this->node = $node;
  48. }
  49. /**
  50. * Returns the node created by up().
  51. */
  52. public function getNode() {
  53. return $this->node;
  54. }
  55. }