54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
namespace MailPoet\Test\WP;
|
|
|
|
use MailPoet\Config\Env;
|
|
use MailPoet\WP\Emoji;
|
|
|
|
class EmojiTest extends \MailPoetTest {
|
|
function _before() {
|
|
parent::_before();
|
|
$this->data_encoded = "Emojis: 😃😵💪, not emojis: .Ž";
|
|
$this->data_decoded = "Emojis: 😃😵💪, not emojis: .Ž";
|
|
|
|
$this->column = 'dummycol';
|
|
$this->emoji = new Emoji();
|
|
}
|
|
|
|
function testItCanEncodeForUTF8Column() {
|
|
$table = Env::$db_prefix . 'dummytable_utf8';
|
|
$this->createTable($table, 'utf8');
|
|
|
|
$result = $this->emoji->encodeForUTF8Column($table, $this->column, $this->data_decoded);
|
|
expect($result)->equals($this->data_encoded);
|
|
|
|
$this->dropTable($table);
|
|
}
|
|
|
|
function testItDoesNotEncodeForUTF8MB4Column() {
|
|
$table = Env::$db_prefix . 'dummytable_utf8mb4';
|
|
$this->createTable($table, 'utf8mb4');
|
|
|
|
$result = $this->emoji->encodeForUTF8Column($table, $this->column, $this->data_decoded);
|
|
expect($result)->equals($this->data_decoded);
|
|
|
|
$this->dropTable($table);
|
|
}
|
|
|
|
function testItCanDecodeEntities() {
|
|
$result = $this->emoji->decodeEntities($this->data_encoded);
|
|
expect($result)->equals($this->data_decoded);
|
|
}
|
|
|
|
private function createTable($table, $charset) {
|
|
\ORM::raw_execute(
|
|
'CREATE TABLE IF NOT EXISTS ' . $table
|
|
. ' (' . $this->column . ' TEXT) '
|
|
. 'DEFAULT CHARSET=' . $charset . ';'
|
|
);
|
|
}
|
|
|
|
private function dropTable($table) {
|
|
\ORM::raw_execute('DROP TABLE IF EXISTS ' . $table);
|
|
}
|
|
}
|