8c3c5002c9ef35436b2e208eba97a24ca9db98a8
[yaffs-website] / vendor / drush / drush / tests / fieldTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6  * Tests for field.drush.inc
7  *
8  * @group commands
9  */
10 class fieldCase extends CommandUnishTestCase {
11
12   public function testField() {
13     if (UNISH_DRUPAL_MAJOR_VERSION == 6) {
14       $this->markTestSkipped("Field API not available in Drupal 6.");
15     }
16
17     if (UNISH_DRUPAL_MAJOR_VERSION == 8) {
18       $this->markTestSkipped("Field commands are not yet ported to D8.");
19     }
20
21     $sites = $this->setUpDrupal(1, TRUE);
22     $options = array(
23       'yes' => NULL,
24       'root' => $this->webroot(),
25       'uri' => key($sites),
26     );
27
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;
32     }
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']);
39
40     // Assure that the second field instance was created correctly (subtitle).
41     $this->verifyInstance('subtitle', $options);
42
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']);
48
49     // Assure that field-clone actually clones.
50     $this->drush('field-clone', array('subtitle', 'subtitlecloned'), $options);
51     $this->verifyInstance('subtitlecloned', $options);
52
53     // Assure that delete works.
54     $this->drush('field-delete', array('subtitlecloned'), $options);
55     $this->verifyInstance('subtitlecloned', $options, FALSE);
56   }
57
58   function verifyInstance($name, $options, $expected = TRUE) {
59     $this->drush('field-info', array('fields'), $options + array('format' => 'json'));
60     $output = $this->getOutputFromJSON();
61     $found = FALSE;
62     foreach($output as $key => $field) {
63       if ($key == $name) {
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.');
66         $found = TRUE;
67         break;
68       }
69     }
70     if ($expected) {
71       $this->assertTrue($found, $name . ' field was created.');
72     }
73     else {
74       $this->assertFalse($found, $name . ' field was not present.');
75     }
76   }
77 }