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

Namespace

Unish

Classes

Namesort descending Description
fieldCase Tests for field.drush.inc

File

tests/fieldTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Tests for field.drush.inc
  5. *
  6. * @group commands
  7. */
  8. class fieldCase extends CommandUnishTestCase {
  9. public function testField() {
  10. if (UNISH_DRUPAL_MAJOR_VERSION == 6) {
  11. $this->markTestSkipped("Field API not available in Drupal 6.");
  12. }
  13. if (UNISH_DRUPAL_MAJOR_VERSION == 8) {
  14. $this->markTestSkipped("Field commands are not yet ported to D8.");
  15. }
  16. $sites = $this->setUpDrupal(1, TRUE);
  17. $options = array(
  18. 'yes' => NULL,
  19. 'root' => $this->webroot(),
  20. 'uri' => key($sites),
  21. );
  22. $expected_url = '/admin/config/people/accounts/fields/subtitle';
  23. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  24. // Prepend for D8. We might want to change setUpDrupal() to add clean url.
  25. $expected_url = '/index.php' . $expected_url;
  26. }
  27. // Create two field instances on article content type.
  28. $this->drush('field-create', array('user', 'city,text,text_textfield', 'subtitle,text,text_textfield'), $options + array('entity_type' => 'user'));
  29. $output = $this->getOutput();
  30. list($city, $subtitle) = explode(' ', $output);
  31. $url = parse_url($subtitle);
  32. $this->assertEquals($expected_url, $url['path']);
  33. // Assure that the second field instance was created correctly (subtitle).
  34. $this->verifyInstance('subtitle', $options);
  35. // Assure that field update URL looks correct.
  36. $this->drush('field-update', array('subtitle'), $options);
  37. $output = $this->getOutput();
  38. $url = parse_url($this->getOutput());
  39. $this->assertEquals($expected_url, $url['path']);
  40. // Assure that field-clone actually clones.
  41. $this->drush('field-clone', array('subtitle', 'subtitlecloned'), $options);
  42. $this->verifyInstance('subtitlecloned', $options);
  43. // Assure that delete works.
  44. $this->drush('field-delete', array('subtitlecloned'), $options);
  45. $this->verifyInstance('subtitlecloned', $options, FALSE);
  46. }
  47. function verifyInstance($name, $options, $expected = TRUE) {
  48. $this->drush('field-info', array('fields'), $options + array('format' => 'json'));
  49. $output = $this->getOutputFromJSON();
  50. $found = FALSE;
  51. foreach($output as $key => $field) {
  52. if ($key == $name) {
  53. $this->assertEquals('text', $field->type, $name . ' field is of type=text.');
  54. $this->assertEquals('user', current($field->bundle), $name . ' field was added to user bundle.');
  55. $found = TRUE;
  56. break;
  57. }
  58. }
  59. if ($expected) {
  60. $this->assertTrue($found, $name . ' field was created.');
  61. }
  62. else {
  63. $this->assertFalse($found, $name . ' field was not present.');
  64. }
  65. }
  66. }