fieldTest.php

  1. 8.0.x tests/fieldTest.php
  2. 6.x tests/fieldTest.php
  3. 7.x tests/fieldTest.php
  4. 4.x tests/fieldTest.php
  5. 5.x tests/fieldTest.php

Classes

Namesort descending Description
fieldCase

File

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