6 * Tests for field.drush.inc
10 class fieldCase extends CommandUnishTestCase {
12 public function testField() {
13 if (UNISH_DRUPAL_MAJOR_VERSION == 6) {
14 $this->markTestSkipped("Field API not available in Drupal 6.");
17 if (UNISH_DRUPAL_MAJOR_VERSION == 8) {
18 $this->markTestSkipped("Field commands are not yet ported to D8.");
21 $sites = $this->setUpDrupal(1, TRUE);
24 'root' => $this->webroot(),
28 $expected_url = '/admin/config/people/accounts/fields/subtitle';
29 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
30 // Prepend for D8. We might want to change setUpDrupal() to add clean url.
31 $expected_url = '/index.php' . $expected_url;
33 // Create two field instances on article content type.
34 $this->drush('field-create', array('user', 'city,text,text_textfield', 'subtitle,text,text_textfield'), $options + array('entity_type' => 'user'));
35 $output = $this->getOutput();
36 list($city, $subtitle) = explode(' ', $output);
37 $url = parse_url($subtitle);
38 $this->assertEquals($expected_url, $url['path']);
40 // Assure that the second field instance was created correctly (subtitle).
41 $this->verifyInstance('subtitle', $options);
43 // Assure that field update URL looks correct.
44 $this->drush('field-update', array('subtitle'), $options);
45 $output = $this->getOutput();
46 $url = parse_url($this->getOutput());
47 $this->assertEquals($expected_url, $url['path']);
49 // Assure that field-clone actually clones.
50 $this->drush('field-clone', array('subtitle', 'subtitlecloned'), $options);
51 $this->verifyInstance('subtitlecloned', $options);
53 // Assure that delete works.
54 $this->drush('field-delete', array('subtitlecloned'), $options);
55 $this->verifyInstance('subtitlecloned', $options, FALSE);
58 function verifyInstance($name, $options, $expected = TRUE) {
59 $this->drush('field-info', array('fields'), $options + array('format' => 'json'));
60 $output = $this->getOutputFromJSON();
62 foreach($output as $key => $field) {
64 $this->assertEquals('text', $field->type, $name . ' field is of type=text.');
65 $this->assertEquals('user', current($field->bundle), $name . ' field was added to user bundle.');
71 $this->assertTrue($found, $name . ' field was created.');
74 $this->assertFalse($found, $name . ' field was not present.');