Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / devel / devel_generate / drush / DevelGenerateUnishTest.php
1 <?php
2
3 namespace Unish;
4
5 if (class_exists('Unish\CommandUnishTestCase')) {
6
7   /**
8    * Tests for devel_generate drush commands.
9    *
10    * @group devel_generate
11    */
12   class DevelGenerateUnishTest extends CommandUnishTestCase {
13
14     /**
15      * {@inheritdoc}
16      */
17     public function setUp() {
18       if (UNISH_DRUPAL_MAJOR_VERSION < 8) {
19         $this->markTestSkipped('Devel Generate Tests only available on D8+.');
20       }
21
22       if (!$this->getSites()) {
23         $this->setUpDrupal(1, TRUE, UNISH_DRUPAL_MAJOR_VERSION, 'standard');
24
25         // Symlink the devel module into the sandbox.
26         $devel_directory = dirname(dirname(__DIR__));
27         symlink($devel_directory, $this->webroot() . '/modules/devel');
28
29         // Enable the devel_generate modules.
30         $this->drush('pm-enable', ['devel_generate'], $this->getOptions());
31       }
32
33     }
34
35     /**
36      * Tests devel generate terms.
37      */
38     public function testDevelGenerateTerms() {
39       $this->drush('pm-enable', ['taxonomy'], $this->getOptions());
40
41       $this->drush('generate-terms', [], $this->getOptions(), NULL, NULL, static::EXIT_ERROR);
42       $this->assertContains('Please provide a vocabulary machine name.', $this->getErrorOutput());
43
44       $this->drush('generate-terms', ['unknown'], $this->getOptions(), NULL, NULL, static::EXIT_ERROR);
45       $this->assertContains('Invalid vocabulary name: unknown', $this->getErrorOutput());
46
47       $this->drush('generate-terms', ['tags', 'NaN'], $this->getOptions(), NULL, NULL, static::EXIT_ERROR);
48       $this->assertContains('Invalid number of terms: NaN', $this->getErrorOutput());
49
50       $eval_term_count = "return \\Drupal::entityQuery('taxonomy_term')->count()->execute();";
51       $eval_options = $this->getOptions() + ['format' => 'string'];
52
53       $this->drush('generate-terms', ['tags'], $this->getOptions());
54       $this->assertContains('Created the following new terms:', $this->getErrorOutput());
55       $this->drush('php-eval', [$eval_term_count], $eval_options);
56       $this->assertEquals(10, $this->getOutput());
57
58       $this->drush('generate-terms', ['tags', '1'], $this->getOptions());
59       $this->assertContains('Created the following new terms:', $this->getErrorOutput());
60       $this->drush('php-eval', [$eval_term_count], $eval_options);
61       $this->assertEquals(11, $this->getOutput());
62
63       $this->drush('generate-terms', ['tags', '1'], $this->getOptions(TRUE));
64       $this->assertContains('Deleted existing terms.', $this->getErrorOutput());
65       $this->assertContains('Created the following new terms:', $this->getErrorOutput());
66       $this->drush('php-eval', [$eval_term_count], $eval_options);
67       $this->assertEquals(1, $this->getOutput());
68
69       $this->drush('gent', ['tags', '1'], $this->getOptions());
70       $this->assertContains('Created the following new terms:', $this->getErrorOutput());
71     }
72
73     /**
74      * Tests devel generate contents.
75      */
76     public function testDevelGenerateContents() {
77       $this->drush('pm-enable', ['node'], $this->getOptions());
78
79       $eval_content_count = "return \\Drupal::entityQuery('node')->count()->execute();";
80       $eval_options = $this->getOptions() + ['format' => 'string'];
81
82       // Try to generate 10 content of type "page" or "article"
83       $this->drush('generate-content', [10], $this->getOptions(), NULL, NULL, static::EXIT_SUCCESS);
84       $this->assertContains('Finished creating 10 nodes', $this->getErrorOutput());
85       $this->drush('php-eval', [$eval_content_count], $eval_options);
86       $this->assertEquals(10, $this->getOutput());
87
88       // Try to generate 1 content of type "page" or "article"
89       $this->drush('generate-content', [1], $this->getOptions(), NULL, NULL, static::EXIT_SUCCESS);
90       $this->assertContains('1 node created.', $this->getErrorOutput());
91       $this->drush('php-eval', [$eval_content_count], $eval_options);
92       $this->assertEquals(11, $this->getOutput());
93
94       // Try to generate 5 content of type "page" or "article", removing all
95       // previous contents.
96       $this->drush('generate-content', [5], $this->getOptions(TRUE), NULL, NULL, static::EXIT_SUCCESS);
97       $this->assertContains('Finished creating 5 nodes', $this->getErrorOutput());
98       $this->drush('php-eval', [$eval_content_count], $eval_options);
99       $this->assertEquals(5, $this->getOutput());
100
101       // Try to generate other 5 content with "crappy" type. Output should
102       // remains 5.
103       $generate_content_wrong_ct = $this->getOptions(TRUE) + ['types' => 'crappy'];
104       $this->drush('generate-content', [5], $generate_content_wrong_ct, NULL, NULL, static::EXIT_ERROR);
105       $this->assertContains('One or more content types have been entered that don', $this->getErrorOutput());
106       $this->drush('php-eval', [$eval_content_count], $eval_options);
107       $this->assertEquals(5, $this->getOutput());
108
109       // Try to generate other 5 content with empty types. Output should
110       // remains 5.
111       $generate_content_no_types = $this->getOptions(TRUE) + ['types' => ''];
112       $this->drush('generate-content', [5], $generate_content_no_types, NULL, NULL, static::EXIT_ERROR);
113       $this->assertContains('No content types available', $this->getErrorOutput());
114       $this->drush('php-eval', [$eval_content_count], $eval_options);
115       $this->assertEquals(5, $this->getOutput());
116
117       // Try to generate other 5 content without any types. Output should
118       // remains 5.
119       $generate_content_no_types = $this->getOptions(TRUE) + ['types' => NULL];
120       $this->drush('generate-content', [5], $generate_content_no_types, NULL, NULL, static::EXIT_ERROR);
121       $this->assertContains('Wrong syntax or no content type selected. The correct syntax uses', $this->getErrorOutput());
122       $this->drush('php-eval', [$eval_content_count], $eval_options);
123       $this->assertEquals(5, $this->getOutput());
124     }
125
126     /**
127      * Default drush options.
128      *
129      * @param bool $kill
130      *   Whether add kill option.
131      *
132      * @return array
133      *   An array containing the default options for drush commands.
134      */
135     protected function getOptions($kill = FALSE) {
136       $options = [
137         'yes' => NULL,
138         'root' => $this->webroot(),
139         'uri' => key($this->getSites()),
140       ];
141
142       if($kill) {
143         $options['kill'] = NULL;
144       }
145
146       return $options;
147     }
148
149   }
150
151 }