2012-08-03 20:21:32 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2016-03-22 14:35:50 +00:00
|
|
|
class HyperlinkTest extends \PHPUnit_Framework_TestCase
|
2012-08-03 20:21:32 +00:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-08-16 14:24:47 +00:00
|
|
|
if (!defined('PHPSPREADSHEET_ROOT')) {
|
|
|
|
define('PHPSPREADSHEET_ROOT', APPLICATION_PATH . '/');
|
2012-08-03 20:21:32 +00:00
|
|
|
}
|
2016-08-16 15:33:57 +00:00
|
|
|
require_once PHPSPREADSHEET_ROOT . '/Bootstrap.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testGetUrl()
|
|
|
|
{
|
|
|
|
$urlValue = 'http://www.phpexcel.net';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$testInstance = new Hyperlink($urlValue);
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->getUrl();
|
2015-05-17 16:34:30 +00:00
|
|
|
$this->assertEquals($urlValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testSetUrl()
|
|
|
|
{
|
|
|
|
$initialUrlValue = 'http://www.phpexcel.net';
|
2016-08-16 14:24:47 +00:00
|
|
|
$newUrlValue = 'http://github.com/PHPOffice/PhpSpreadsheet';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$testInstance = new Hyperlink($initialUrlValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->setUrl($newUrlValue);
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->assertTrue($result instanceof Hyperlink);
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->getUrl();
|
2015-05-17 16:34:30 +00:00
|
|
|
$this->assertEquals($newUrlValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testGetTooltip()
|
|
|
|
{
|
2016-08-16 14:24:47 +00:00
|
|
|
$tooltipValue = 'PhpSpreadsheet Web Site';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$testInstance = new Hyperlink(null, $tooltipValue);
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->getTooltip();
|
2015-05-17 16:34:30 +00:00
|
|
|
$this->assertEquals($tooltipValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testSetTooltip()
|
|
|
|
{
|
2016-08-16 14:24:47 +00:00
|
|
|
$initialTooltipValue = 'PhpSpreadsheet Web Site';
|
|
|
|
$newTooltipValue = 'PhpSpreadsheet Repository on Github';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$testInstance = new Hyperlink(null, $initialTooltipValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->setTooltip($newTooltipValue);
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->assertTrue($result instanceof Hyperlink);
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->getTooltip();
|
2015-05-17 16:34:30 +00:00
|
|
|
$this->assertEquals($newTooltipValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testIsInternal()
|
|
|
|
{
|
|
|
|
$initialUrlValue = 'http://www.phpexcel.net';
|
|
|
|
$newUrlValue = 'sheet://Worksheet1!A1';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$testInstance = new Hyperlink($initialUrlValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->isInternal();
|
|
|
|
$this->assertFalse($result);
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$testInstance->setUrl($newUrlValue);
|
|
|
|
$result = $testInstance->isInternal();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testGetHashCode()
|
|
|
|
{
|
|
|
|
$urlValue = 'http://www.phpexcel.net';
|
2016-08-16 14:24:47 +00:00
|
|
|
$tooltipValue = 'PhpSpreadsheet Web Site';
|
2016-08-31 17:18:12 +00:00
|
|
|
$initialExpectedHash = '6f1d4cbf40034b9ddc3fbf6019506e91';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$testInstance = new Hyperlink($urlValue, $tooltipValue);
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $testInstance->getHashCode();
|
2015-05-17 16:34:30 +00:00
|
|
|
$this->assertEquals($initialExpectedHash, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
}
|