aa[em/]test',
],
[
'[strong]test[/strong][strong]test[/strong]',
'testtest',
],
[
'[code]test[/code][code]test[/code]',
'test
test
',
],
[
'[kbd]test[/kbd][br][sup]test[/sup]',
'test
test',
],
[
'[a@https://example.com/@Documentation]link[/a]',
'link',
],
[
'[a@./non-existing@Documentation]link[/a]',
'[a@./non-existing@Documentation]link',
],
[
'[doc@foo]link[/doc]',
'link',
],
[
'[doc@page@anchor]link[/doc]',
'link',
],
[
'[doc@faqmysql]link[/doc]',
'link',
],
];
}
/**
* testing decodeBB method
*
* @param string $actual BB code string
* @param string $expected Expected decoded string
*
* @dataProvider decodeBBDataProvider
*/
public function testDecodeBB(string $actual, string $expected): void
{
unset($GLOBALS['server']);
$this->assertEquals($expected, Message::decodeBB($actual));
}
/**
* testing format method
*/
public function testFormat(): void
{
$this->assertEquals(
'test string',
Message::format('test string')
);
$this->assertEquals(
'test string',
Message::format('test string', 'a')
);
$this->assertEquals(
'test string',
Message::format('test string', [])
);
$this->assertEquals(
'test string',
Message::format('%s string', ['test'])
);
}
/**
* testing getHash method
*/
public function testGetHash(): void
{
$this->object->setString('<&>test', false);
$this->object->setMessage('<&>test', false);
$this->assertEquals(
md5(Message::NOTICE . '<&>test<&>test'),
$this->object->getHash()
);
}
/**
* getMessage test - with empty message and with non-empty string -
* not key in globals additional params are defined
*/
public function testGetMessageWithoutMessageWithStringWithParams(): void
{
$this->object->setMessage('');
$this->object->setString('test string %s %s');
$this->object->addParam('test param 1');
$this->object->addParam('test param 2');
$this->assertEquals(
'test string test param 1 test param 2',
$this->object->getMessage()
);
}
/**
* getMessage test - with empty message and with empty string
*/
public function testGetMessageWithoutMessageWithEmptyString(): void
{
$this->object->setMessage('');
$this->object->setString('');
$this->assertEquals('', $this->object->getMessage());
}
/**
* getMessage test - message is defined
* message with BBCode defined
*/
public function testGetMessageWithMessageWithBBCode(): void
{
$this->object->setMessage('[kbd]test[/kbd] [doc@cfg_Example]test[/doc]');
$this->assertEquals(
'test test',
$this->object->getMessage()
);
}
/**
* getLevel test
*/
public function testGetLevel(): void
{
$this->assertEquals('notice', $this->object->getLevel());
$this->object->setNumber(Message::SUCCESS);
$this->assertEquals('success', $this->object->getLevel());
$this->object->setNumber(Message::ERROR);
$this->assertEquals('error', $this->object->getLevel());
}
/**
* getDisplay test
*/
public function testGetDisplay(): void
{
$this->assertFalse($this->object->isDisplayed());
$this->object->setMessage('Test Message');
$this->assertEquals(
'' . "\n"
. '

Test Message' . "\n"
. '
' . "\n",
$this->object->getDisplay()
);
$this->assertTrue($this->object->isDisplayed());
}
/**
* isDisplayed test
*/
public function testIsDisplayed(): void
{
$this->assertFalse($this->object->isDisplayed(false));
$this->assertTrue($this->object->isDisplayed(true));
$this->assertTrue($this->object->isDisplayed(false));
}
/**
* Data provider for testAffectedRows
*
* @return array Test-data
*/
public function providerAffectedRows(): array
{
return [
[
1,
'' . "\n"
. '

1 row affected.' . "\n"
. '
' . "\n",
],
[
2,
'' . "\n"
. '

2 rows affected.' . "\n"
. '
' . "\n",
],
[
10000,
'' . "\n"
. '

10000 rows affected.' . "\n"
. '
' . "\n",
],
];
}
/**
* Test for getMessageForAffectedRows() method
*
* @param int $rows Number of rows
* @param string $output Expected string
*
* @dataProvider providerAffectedRows
*/
public function testAffectedRows(int $rows, string $output): void
{
$this->object = new Message();
$msg = $this->object->getMessageForAffectedRows($rows);
$this->object->addMessage($msg);
$this->assertEquals($output, $this->object->getDisplay());
}
/**
* Data provider for testInsertedRows
*
* @return array Test-data
*/
public function providerInsertedRows(): array
{
return [
[
1,
'' . "\n"
. '

1 row inserted.' . "\n"
. '
' . "\n",
],
[
2,
'' . "\n"
. '

2 rows inserted.' . "\n"
. '
' . "\n",
],
[
100000,
'' . "\n"
. '

100000 rows inserted.' . "\n"
. '
' . "\n",
],
];
}
/**
* Test for getMessageForInsertedRows() method
*
* @param int $rows Number of rows
* @param string $output Expected string
*
* @dataProvider providerInsertedRows
*/
public function testInsertedRows(int $rows, string $output): void
{
$this->object = new Message();
$msg = $this->object->getMessageForInsertedRows($rows);
$this->object->addMessage($msg);
$this->assertEquals($output, $this->object->getDisplay());
}
/**
* Data provider for testDeletedRows
*
* @return array Test-data
*/
public function providerDeletedRows(): array
{
return [
[
1,
'' . "\n"
. '

1 row deleted.' . "\n"
. '
' . "\n",
],
[
2,
'' . "\n"
. '

2 rows deleted.' . "\n"
. '
' . "\n",
],
[
500000,
'' . "\n"
. '

500000 rows deleted.' . "\n"
. '
' . "\n",
],
];
}
/**
* Test for getMessageForDeletedRows() method
*
* @param int $rows Number of rows
* @param string $output Expected string
*
* @dataProvider providerDeletedRows
*/
public function testDeletedRows(int $rows, string $output): void
{
$this->object = new Message();
$msg = $this->object->getMessageForDeletedRows($rows);
$this->object->addMessage($msg);
$this->assertEquals($output, $this->object->getDisplay());
}
}