Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
language: php

dist: xenial

group: edge

addons:
apt:
packages:
- language-pack-cs

php:
- '7.0'
- '7.1'
- nightly

matrix:

allow_failures:
- php: nightly

install:
- composer self-update
- |
if [[ "${TRAVIS_PHP_VERSION:0:7}" == "nightly" ]]; then
composer install --ignore-platform-reqs
else
composer install
fi

script:
bin/phpunit tests --exclude-group=integration

notifications:
email:
on_success: change
on_failure: always
2 changes: 1 addition & 1 deletion Jyxo/Beholder/Output/TextOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __toString(): string

$return .= sprintf("%-9s %10s %-10s %-7s %-35s %s\n",
'Run Order', 'Duration', 'Ident', 'Status', 'Test Name', 'Description');
foreach ($this->testsData as $data) {
foreach ($this->result->getTestsData() as $data) {
$return .= sprintf("%9d %9.2fs %-10s %-7s %-35s %s\n",
$data['order'],
$data['duration'],
Expand Down
5 changes: 5 additions & 0 deletions Jyxo/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static function repair(string $html): string
// 'drop-proprietary-attributes' => true, // Removes proprietary attributes (it would remove e.g. the background attribute)
// 'drop-font-tags' => true // Removes <FONT> and <CENTER> tags
];

if (!function_exists('\tidy_repair_string')) {
throw new \Jyxo\Exception('Missing "tidy" extension.');
}

$html = tidy_repair_string($html, $config, 'utf8');

// Removes namespace <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /? > generated by MS Word
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
"ext-curl": "To use Jyxo\\Rpc client/server or Jyxo\\Webdav client",
"ext-json": "To use Jyxo\\Rpc\\Json client/server or Jyxo\\FirePHP logger",
"ext-xmlrpc": "To use Jyxo\\Rpc\\Xml client/server",
"ext-imap": "To use Jyxo\\Mail\\Parser"
"ext-imap": "To use Jyxo\\Mail\\Parser",
"ext-tidy": "To use Jyxo\\Html extended capabilities"
},
"autoload": {
"psr-4": { "Jyxo\\": ["Jyxo/"] }
},
"autoload-dev": {
"psr-4": { "Jyxo\\": ["tests/Jyxo"] }
},
"config": {
"bin-dir": "bin",
"optimize-autoloader": true,
Expand Down
8 changes: 2 additions & 6 deletions tests/Jyxo/Beholder/TestCase/MemcachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ public function setUp()
*/
public function testConnectionFailure()
{
if (!class_exists('Memcached')) {
$this->markTestSkipped('Memcached not set');
}

$ip = '127.0.0.1';
$port = '12345';
$port = 12345;

$test = new Memcached('Memcached', $ip, $port);
// @ on purpose
$result = @$test->run();
$this->assertEquals(\Jyxo\Beholder\Result::FAILURE, $result->getStatus());
$this->assertEquals(sprintf('Connection error %s:%s', gethostbyaddr($ip), $port), $result->getDescription());
$this->assertEquals(sprintf('Write error %s:%s', gethostbyaddr($ip), $port), $result->getDescription());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Jyxo/CharsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testFixUtf()
$this->assertEquals('žluťoučký kůň pěl ďábelské ódy', Charset::fixUtf('žluťoučký kůň pěl ďábelské ódy'));
$this->assertEquals('Государственный гимн Российской Федерации', Charset::fixUtf('Государственный гимн Российской Федерации'));

$this->assertEquals('', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/cp1250.txt')));
$this->assertEquals('', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/iso-8859-2.txt')));
$this->assertEquals('luouk k pern pl belsk dy', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/cp1250.txt')));
$this->assertEquals('luouk k pern pl belsk dy', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/iso-8859-2.txt')));
}
}
4 changes: 4 additions & 0 deletions tests/Jyxo/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function testIs()
*/
public function testRepair()
{
if (!function_exists('\tidy_repair_string')) {
$this->markTestSkipped('Skipping, missing "tidy" extension.');
}

$this->assertStringEqualsFile(
$this->filePath . '/repair-expected.html',
Html::repair(file_get_contents($this->filePath . '/repair.html'))
Expand Down
43 changes: 43 additions & 0 deletions tests/Jyxo/Mail/EmailTestHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace Jyxo\Mail;

trait EmailTestHelpers
{

/**
* Creates a basic email.
*
* @return \Jyxo\Mail\Email
*/
private function getEmail(): \Jyxo\Mail\Email
{
$email = new Email();
$email->setSubject('Novinky září 2009 ... a kreslící soutěž')
->setFrom(new Email\Address('blog-noreply@blog.cz', 'Blog.cz'))
->addTo(new Email\Address('test@blog.cz', 'Test Test'))
->setBody(new Email\Body(\Jyxo\Html::toText($this->content)));

return $email;
}

/**
* Compares the actual and expected result.
*
* @param string $file FileAttachment with the expected result
* @param \Jyxo\Mail\Sender\Result $result
*/
private function assertResult(string $file, \Jyxo\Mail\Sender\Result $result)
{
$expected = file_get_contents($this->filePath . '/' . $file);

// Replacing some headers that are created dynamically
$expected = preg_replace('~====b1[a-z0-9]{32}====~', '====b1' . substr($result->messageId, 0, 32) . '====', $expected);
$expected = preg_replace('~====b2[a-z0-9]{32}====~', '====b2' . substr($result->messageId, 0, 32) . '====', $expected);
$expected = preg_replace("~Date: [^\n]+~", 'Date: ' . $result->datetime->email, $expected);
$expected = preg_replace('~Message-ID: <[^>]+>~', 'Message-ID: <' . $result->messageId . '>', $expected);

$this->assertEquals($expected, $result->source, sprintf('Failed test for file %s.', $file));
}

}
84 changes: 84 additions & 0 deletions tests/Jyxo/Mail/SenderIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php declare(strict_types = 1);

/**
* Jyxo PHP Library
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file license.txt.
* It is also available through the world-wide-web at this URL:
* https://github.com/jyxo/php/blob/master/license.txt
*/

namespace Jyxo\Mail;

/**
* \Jyxo\Mail\Sender class test.
*
* @see \Jyxo\Mail\Sender
* @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
* @license https://github.com/jyxo/php/blob/master/license.txt
* @author Jaroslav Hanslík
* @group integration
*/
class SenderIntegrationTest extends \PHPUnit_Framework_TestCase
{
use EmailTestHelpers;

/**
* FileAttachment path.
*
* @var string
*/
private $filePath;

/**
* Testing mail contents.
*
* @var string
*/
private $content;

/**
* Prepares the testing environment.
*/
protected function setUp()
{
$this->filePath = DIR_FILES . '/mail';
$this->content = file_get_contents($this->filePath . '/email.html');
}

/**
* Tests sending using the mail() function.
*/
public function testSendMail()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestSkipped('Skipped on Windows');
}

$sender = new Sender();
$sender->setEmail($this->getEmail());
$result = $sender->send(Sender::MODE_MAIL);
$this->assertResult('sender-type-simple-text.eml', $result);
}

/**
* Tests sending using a SMTP server.
*/
public function testSendSmtp()
{
// Skips the test if no smtp connection is set
if (empty($GLOBALS['smtp'])) {
$this->markTestSkipped('Smtp host not set');
}

$sender = new Sender();
$sender->setEmail($this->getEmail())
->setSmtp($GLOBALS['smtp']);
$result = $sender->send(Sender::MODE_SMTP);
$this->assertResult('sender-type-simple-text.eml', $result);
}

}
34 changes: 2 additions & 32 deletions tests/Jyxo/Mail/SenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
class SenderTest extends \PHPUnit_Framework_TestCase
{
use EmailTestHelpers;

/**
* FileAttachment path.
*
Expand All @@ -46,38 +48,6 @@ protected function setUp()
$this->content = file_get_contents($this->filePath . '/email.html');
}

/**
* Tests sending using the mail() function.
*/
public function testSendMail()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestSkipped('Skipped on Windows');
}

$sender = new Sender();
$sender->setEmail($this->getEmail());
$result = $sender->send(Sender::MODE_MAIL);
$this->assertResult('sender-type-simple-text.eml', $result);
}

/**
* Tests sending using a SMTP server.
*/
public function testSendSmtp()
{
// Skips the test if no smtp connection is set
if (empty($GLOBALS['smtp'])) {
$this->markTestSkipped('Smtp host not set');
}

$sender = new Sender();
$sender->setEmail($this->getEmail())
->setSmtp($GLOBALS['smtp']);
$result = $sender->send(Sender::MODE_SMTP);
$this->assertResult('sender-type-simple-text.eml', $result);
}

/**
* Tests possible sending errors.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Jyxo/Time/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testMagicGet()
$this->assertEquals('2009-10-10T00:00:00+0700', $time->sql);
$this->assertEquals('Sat, 10 Oct 09 00:00:00 +0700', $time->email);
$this->assertEquals('2009-10-10T00:00:00+07:00', $time->web);
$this->assertEquals('Saturday, 10-Oct-2009 00:00:00 GMT-7', $time->cookie);
$this->assertEquals('Saturday, 10-Oct-2009 00:00:00 +07', $time->cookie);
$this->assertEquals('Sat, 10 Oct 2009 00:00:00 +0700', $time->rss);
$this->assertEquals('1255107600', $time->unix);
$this->assertEquals('Fri, 09 Oct 2009 17:00:00 GMT', $time->http);
Expand Down
18 changes: 2 additions & 16 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@
* https://github.com/jyxo/php/blob/master/license.txt
*/

// Because of SessionTest
session_start();
require __DIR__ . '/../vendor/autoload.php';

// Autoload
spl_autoload_register(function($className) {
if (strpos($className, 'Jyxo') !== 0) {
return;
}

$file = str_replace('\\', '/', $className) . '.php';
foreach ([realpath(__DIR__ . '/..'), __DIR__] as $dir) {
$filePath = $dir . '/' . $file;
if (false !== stream_resolve_include_path($filePath)) {
require_once $filePath;
}
}
});
date_default_timezone_set('Europe/Prague');

// File path
define('DIR_FILES', __DIR__ . '/files');