BlastDBNodeSeeder.php 1.8 KB

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