old_url_suffix = Config::get('url_suffix');
$this->old_index_file = Config::get('index_file');
$this->old_base_url = Config::get('base_url');
}
public function tearDown()
{
Config::set('url_suffix', $this->old_url_suffix);
Config::set('index_file', $this->old_index_file);
Config::set('base_url', $this->old_base_url);
}
/**
* Tests Html::meta()
*
* @test
*/
public function test_meta()
{
$output = Html::meta('description', 'Meta Example!');
$expected = '';
$this->assertEquals($expected, $output);
$output = Html::meta('robots', 'no-cache');
$expected = '';
$this->assertEquals($expected, $output);
$meta = array(
array('name' => 'robots', 'content' => 'no-cache'),
array('name' => 'description', 'content' => 'Meta Example'),
array('name' => 'keywords', 'content' => 'fuel, rocks'),
);
$output = Html::meta($meta);
$expected = '
';
$this->assertEquals($expected, $output);
}
/**
* Tests Html::anchor()
*
* @test
*/
public function test_anchor()
{
// Query string tests
Config::set('url_suffix', null);
Config::set('index_file', null);
Config::set('base_url', null);
// External uri
$output = Html::anchor('http://google.com', 'Go to Google');
$expected = 'Go to Google';
$this->assertEquals($expected, $output);
$output = Html::anchor('javascript:do();', 'Do()');
$expected = 'Do()';
$this->assertEquals($expected, $output);
$output = Html::anchor('http://google.com', 'Go to Google', array('rel' => 'example', 'class' => 'sample', 'style' => 'color:red;'));
$expected = 'Go to Google';
$this->assertEquals($expected, $output);
// External secure uri
$output = Html::anchor('http://google.com', 'Go to Google', array('rel' => 'example', 'class' => 'sample', 'style' => 'color:red;'), true);
$expected = 'Go to Google';
$this->assertEquals($expected, $output);
// Internal uri
$output = Html::anchor('controller/method', 'Method');
$expected = 'Method';
$this->assertEquals($expected, $output);
// Internal secure uri
$host = \Input::server('http_host');
$_SERVER['HTTP_HOST'] = 'fuelphp.com';
$output = Html::anchor('controller/method', 'Method', array(), true);
$expected = 'Method';
$this->assertEquals($expected, $output);
$_SERVER['HTTP_HOST'] = $host;
$output = Html::anchor('search?q=query', 'Search');
$expected = 'Search';
$this->assertEquals($expected, $output);
Config::set('url_suffix', '.html');
$output = Html::anchor('search?q=query', 'Search');
$expected = 'Search';
$this->assertEquals($expected, $output);
}
/**
* Tests Html::img()
*
* This test does not account for the image file existing in
* the filesystem. There are no images bundled with the framework
* by default, so no reliable test can be run on an actual image.
*
* @test
*/
public function test_img()
{
$image_path = 'image.png';
// Internal uri
$output = Html::img('image.png');
$expected = '';
$this->assertEquals($expected, $output);
$output = Html::img('image.png', array('alt' => 'Image'));
$expected = '
';
$this->assertEquals($expected, $output);
// External uri
$output = Html::img('http://google.com/image.png');
$expected = '
';
}
/**
* Tests Html::prep_url()
*
* @test
*/
public function test_prep_url()
{
$output = Html::prep_url('google.com');
$expected = 'http://google.com';
$this->assertEquals($expected, $output);
$output = Html::prep_url('google.com', 'https');
$expected = 'https://google.com';
$this->assertEquals($expected, $output);
}
/**
* Tests Html::mail_to()
*
* @test
*/
public function test_mail_to()
{
$output = Html::mail_to('test@test.com');
$expected = 'test@test.com';
$this->assertEquals($expected, $output);
$output = Html::mail_to('test@test.com', 'Email');
$expected = 'Email';
$this->assertEquals($expected, $output);
$output = Html::mail_to('test@test.com', NULL, 'Test');
$expected = 'test@test.com';
$this->assertEquals($expected, $output);
$output = Html::mail_to('test@test.com', 'Test', 'Test');
$expected = 'Test';
$this->assertEquals($expected, $output);
}
/**
* Tests Html::doctype()
*
* @test
*/
public function test_doctype()
{
$output = Html::doctype();
$expected = '';
$this->assertEquals($expected, $output);
$output = Html::doctype('html5');
$expected = '';
$this->assertEquals($expected, $output);
// Ensure static::$html5 is set
$doctype = Html::doctype('html5');
$this->assertTrue(Html::$html5);
// Ensure === false if doctype is invalid
$this->assertFalse(Html::doctype('shouldfail'));
}
/**
* Tests Html::ul() & Html::ol()
*
* @test
*/
public function test_lists()
{
$list = array('one', 'two');
$output = Html::ul($list);
$expected = '