public function testEnablePluginsByArrayWithPaths()
 {
     Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://mysite.com/subdir');
     $c = new TinyMCEConfig();
     $c->setTheme('modern');
     $c->setOption('language', 'es');
     $c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss');
     $c->enablePlugins(array('plugin1' => 'mypath/plugin1.js', 'plugin2' => '/anotherbase/mypath/plugin2.js', 'plugin3' => 'https://www.google.com/plugin.js', 'plugin4' => null, 'plugin5' => null));
     $attributes = $c->getAttributes();
     $config = Convert::json2array($attributes['data-config']);
     $plugins = $config['external_plugins'];
     $this->assertNotEmpty($plugins);
     // Plugin specified via relative url
     $this->assertContains('plugin1', array_keys($plugins));
     $this->assertEquals('http://mysite.com/subdir/mypath/plugin1.js', $plugins['plugin1']);
     // Plugin specified via root-relative url
     $this->assertContains('plugin2', array_keys($plugins));
     $this->assertEquals('http://mysite.com/anotherbase/mypath/plugin2.js', $plugins['plugin2']);
     // Plugin specified with absolute url
     $this->assertContains('plugin3', array_keys($plugins));
     $this->assertEquals('https://www.google.com/plugin.js', $plugins['plugin3']);
     // Plugin specified with standard location
     $this->assertContains('plugin4', array_keys($plugins));
     $this->assertEquals('http://mysite.com/subdir/' . ADMIN_THIRDPARTY_DIR . '/tinymce/plugins/plugin4/plugin.min.js', $plugins['plugin4']);
     // Check that internal plugins are extractable separately
     $this->assertEquals(['plugin4', 'plugin5'], $c->getInternalPlugins());
     // Test plugins included via gzip compresser
     HTMLEditorField::config()->update('use_gzip', true);
     $this->assertEquals(ADMIN_THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php?js=1&plugins=plugin4,plugin5&themes=modern&languages=es&diskcache=true&src=true', $c->getScriptURL());
     // If gzip is disabled only the core plugin is loaded
     HTMLEditorField::config()->remove('use_gzip');
     $this->assertEquals(ADMIN_THIRDPARTY_DIR . '/tinymce/tinymce.min.js', $c->getScriptURL());
 }
 function testSearch()
 {
     $team1 = $this->objFromFixture('GridFieldTest_Team', 'team1');
     $team2 = $this->objFromFixture('GridFieldTest_Team', 'team2');
     $response = $this->get('GridFieldAddExistingAutocompleterTest_Controller');
     $this->assertFalse($response->isError());
     $parser = new CSSContentParser($response->getBody());
     $btns = $parser->getBySelector('.grid-field .action_gridfield_relationfind');
     $response = $this->post('GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search' . '/?gridfield_relationsearch=Team 2', array((string) $btns[0]['name'] => 1));
     $this->assertFalse($response->isError());
     $result = Convert::json2array($response->getBody());
     $this->assertEquals(1, count($result));
     $this->assertEquals(array(array('label' => 'Team 2', 'value' => 'Team 2', 'id' => $team2->ID)), $result);
     $response = $this->post('GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/' . 'search/?gridfield_relationsearch=Heather', array((string) $btns[0]['name'] => 1));
     $this->assertFalse($response->isError());
     $result = Convert::json2array($response->getBody());
     $this->assertEquals(1, count($result), "The relational filter did not work");
     $response = $this->post('GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search' . '/?gridfield_relationsearch=Unknown', array((string) $btns[0]['name'] => 1));
     $this->assertFalse($response->isError());
     $result = Convert::json2array($response->getBody());
     $this->assertEmpty($result, 'The output is either an empty array or boolean FALSE');
 }
 /**
  * Test that UploadField:overwriteWarning cannot overwrite Upload:replaceFile
  */
 public function testConfigOverwriteWarningCannotRelaceFiles()
 {
     Upload::config()->replaceFile = false;
     UploadField::config()->defaultConfig = array_merge(UploadField::config()->defaultConfig, array('overwriteWarning' => true));
     $tmpFileName = 'testUploadBasic.txt';
     $response = $this->mockFileUpload('NoRelationField', $tmpFileName);
     $this->assertFalse($response->isError());
     $responseData = Convert::json2array($response->getBody());
     $uploadedFile = DataObject::get_by_id('SilverStripe\\Assets\\File', (int) $responseData[0]['id']);
     $this->assertTrue(is_object($uploadedFile), 'The file object is created');
     $this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($uploadedFile));
     $tmpFileName = 'testUploadBasic.txt';
     $response = $this->mockFileUpload('NoRelationField', $tmpFileName);
     $this->assertFalse($response->isError());
     $responseData = Convert::json2array($response->getBody());
     $uploadedFile2 = DataObject::get_by_id('SilverStripe\\Assets\\File', (int) $responseData[0]['id']);
     $this->assertTrue(is_object($uploadedFile2), 'The file object is created');
     $this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($uploadedFile2));
     $this->assertTrue($uploadedFile->Filename !== $uploadedFile2->Filename, 'Filename is not the same');
     $this->assertTrue($uploadedFile->ID !== $uploadedFile2->ID, 'File database record is not the same');
 }
 /**
  * Tests {@link Convert::json2array()}
  */
 public function testJSON2Array()
 {
     $val = '{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}';
     $decoded = Convert::json2array($val);
     $this->assertEquals(3, count($decoded), '3 items in the decoded array');
     $this->assertContains('Bloggs', $decoded, 'Contains "Bloggs" value in decoded array');
     $this->assertContains('Jones', $decoded, 'Contains "Jones" value in decoded array');
     $this->assertContains('Structure', $decoded['My']['Complicated']);
 }