LinkDefaultProtocolTest.test in Link 7
File
tests/LinkDefaultProtocolTest.test
View source
<?php
class LinkDefaultProtocolTest extends LinkBaseTestClass {
public static function getInfo() {
return array(
'name' => 'Set default link protocol',
'description' => 'Test that an url with a default protocol set.',
'group' => 'Link',
);
}
public function testHttpDefaultProtocolOnUrlWithoutDefinedProtocol() {
$user = $this
->drupalCreateUser($this->permissions);
$this
->drupalLogin($user);
$this
->createNodeWithLink('www.example.com');
$this
->drupalGet('node/1');
$this
->assertRaw('http://www.example.com');
}
public function testHttpDefaultProtocolFromVariableConf() {
variable_set('link_default_protocol', 'banana');
try {
link_ensure_valid_default_protocol();
} catch (Exception $e) {
}
$protocol = variable_get('link_default_protocol');
$this
->assertEqual($protocol, LINK_HTTP_PROTOCOL);
}
public function testHttpsDefaultProtocolOnUrlWithoutDefinedProtocol() {
$this
->setupDefaultProtocol(LINK_HTTPS_PROTOCOL);
$this
->createNodeWithLink('www.example.com');
$this
->drupalGet('node/1');
$this
->assertRaw('https://www.example.com');
}
public function testHttpDefaultProtocolOnUrlWithDefinedHttpsProtocol() {
$this
->setupDefaultProtocol(LINK_HTTP_PROTOCOL);
$this
->createNodeWithLink('https://www.example.com');
$this
->drupalGet('node/1');
$this
->assertRaw('https://www.example.com');
}
public function testHttpsDefaultProtocolOnUrlWithDefinedHttpProtocol() {
$this
->setupDefaultProtocol(LINK_HTTPS_PROTOCOL);
$this
->createNodeWithLink('http://www.example.com');
$this
->drupalGet('node/1');
$this
->assertRaw('http://www.example.com');
}
private function setupDefaultProtocol($protocol) {
$user = $this
->drupalCreateUser($this->permissions);
$this
->drupalLogin($user);
$this
->drupalPost('admin/config/content/link', array(
'link_default_protocol' => $protocol,
), 'Save configuration');
}
private function createNodeWithLink($url) {
$link_field = $this
->createLinkField('page');
$settings = array(
'title' => 'Basic page link test',
$link_field => array(
LANGUAGE_NONE => array(
array(
'title' => 'Field protocol link Test',
'url' => $url,
),
),
),
);
return $this
->drupalCreateNode($settings);
}
}