Further modules included.
[yaffs-website] / web / modules / contrib / filefield_sources / src / Tests / EmptyValuesTest.php
1 <?php
2
3 /**
4  * @file
5  * Definition of Drupal\filefield_sources\Tests\EmptyValuesTest.
6  */
7
8 namespace Drupal\filefield_sources\Tests;
9
10 use Drupal\Core\Field\FieldStorageDefinitionInterface;
11
12 /**
13  * Tests empty values.
14  *
15  * @group filefield_sources
16  */
17 class EmptyValuesTest extends FileFieldSourcesTestBase {
18
19   /**
20    * Modules to enable.
21    *
22    * @var array
23    */
24   public static $modules = array('imce');
25
26   /**
27    * Sets up for empty values test case.
28    */
29   protected function setUp() {
30     parent::setUp();
31     $this->setUpImce();
32   }
33
34   /**
35    * Tests all sources enabled.
36    */
37   public function testAllSourcesEnabled() {
38     // Change allowed number of values.
39     $this->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/fields/node.' . $this->typeName . '.' . $this->fieldName . '/storage', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
40
41     $this->enableSources(array(
42       'upload' => TRUE,
43       'remote' => TRUE,
44       'clipboard' => TRUE,
45       'reference' => TRUE,
46       'attach' => TRUE,
47       'imce' => TRUE,
48     ));
49
50     // Upload a file by 'Remote' source.
51     $this->uploadFileByRemoteSource();
52
53     // Upload a file by 'Reference' source.
54     $this->uploadFileByReferenceSource();
55
56     // Upload a file by 'Clipboard' source.
57     $this->uploadFileByClipboardSource();
58
59     // Upload a file by 'Attach' source.
60     $this->uploadFileByAttachSource();
61
62     // Upload a file by 'Upload' source.
63     $this->uploadFileByUploadSource('', '', 0, TRUE);
64
65     // Upload a file by 'Imce' source.
66     $this->uploadFileByImceSource();
67
68     $this->assertUniqueSubmitButtons();
69   }
70
71   /**
72    * Check that there is only one submit button of a source.
73    */
74   protected function assertUniqueSubmitButtons() {
75     $buttons = array(
76       $this->fieldName . '_0_attach' => t('Attach'),
77       $this->fieldName . '_0_clipboard_upload_button' => t('Upload'),
78       $this->fieldName . '_0_autocomplete_select' => t('Select'),
79       $this->fieldName . '_0_transfer' => t('Transfer'),
80       $this->fieldName . '_0_upload_button' => t('Upload'),
81       $this->fieldName . '_0_imce_select' => t('Select'),
82     );
83     foreach ($buttons as $button_name => $button_label) {
84       // Ensure that there is only one button with name.
85       $buttons = $this->xpath('//input[@name="' . $button_name . '" and @value="' . $button_label . '"]');
86       $this->assertEqual(count($buttons), 1, format_string('There is only one button with name %name and label %label', array('%name' => $button_name, '%label' => $button_label)));
87     }
88   }
89
90 }