fieldTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * @file
  4. * Tests for field.drush.inc
  5. */
  6. class fieldCase extends Drush_TestCase {
  7. public function testField() {
  8. $this->setUpDrupal('dev', TRUE);
  9. $options = array(
  10. 'yes' => NULL,
  11. 'root' => $this->sites['dev']['root'],
  12. 'uri' => 'dev',
  13. );
  14. // Create two field instances on article content type.
  15. $this->drush('field-create', array('user', 'city,text,text_textfield', 'subtitle,text,text_textfield'), $options + array('entity_type' => 'user'));
  16. $output = $this->getOutput();
  17. list($city, $subtitle) = explode(' ', $output);
  18. $url = parse_url($subtitle);
  19. $this->assertEquals('/admin/config/people/accounts/fields/subtitle', $url['path']);
  20. // Assure that the second field instance was created correctly (subtitle).
  21. $this->verifyInstance('subtitle', $options);
  22. // Assure that field update URL looks correct.
  23. $this->drush('field-update', array('subtitle'), $options);
  24. $output = $this->getOutput();
  25. $url = parse_url($this->getOutput());
  26. $this->assertEquals('/admin/config/people/accounts/fields/subtitle', $url['path']);
  27. // Assure that field-clone actually clones.
  28. $this->drush('field-clone', array('subtitle', 'subtitlecloned'), $options);
  29. $this->verifyInstance('subtitlecloned', $options);
  30. // Assure that delete works.
  31. $this->drush('field-delete', array('subtitlecloned'), $options);
  32. $this->verifyInstance('subtitlecloned', $options, FALSE);
  33. }
  34. function verifyInstance($name, $options, $expected = TRUE) {
  35. $this->drush('field-info', array('fields'), $options + array('pipe' => NULL));
  36. $output = $this->getOutputAsList();
  37. $found = FALSE;
  38. foreach($output as $row) {
  39. $columns = explode(',', $row);
  40. if ($columns[0] == $name) {
  41. $this->assertEquals('text', $columns[1], $name . ' field is of type=text.');
  42. $this->assertEquals('user', $columns[2], $name . ' field was added to user bundle.');
  43. $found = TRUE;
  44. break;
  45. }
  46. }
  47. if ($expected) {
  48. $this->assertTrue($found, $name . ' field was created.');
  49. }
  50. else {
  51. $this->assertFalse($found, $name . ' field was not present.');
  52. }
  53. }
  54. }