From 71603fe34830c6b7e65cb59ef116611544a18d1a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 May 2016 08:50:14 +0200 Subject: Fix namespace in log/ and mail/ --- tests/lib/log/OwncloudTest.php | 80 ++++++++++++++++++ tests/lib/log/owncloud.php | 80 ------------------ tests/lib/mail/MailerTest.php | 123 +++++++++++++++++++++++++++ tests/lib/mail/MessageTest.php | 183 +++++++++++++++++++++++++++++++++++++++++ tests/lib/mail/mailer.php | 121 --------------------------- tests/lib/mail/message.php | 182 ---------------------------------------- 6 files changed, 386 insertions(+), 383 deletions(-) create mode 100644 tests/lib/log/OwncloudTest.php delete mode 100644 tests/lib/log/owncloud.php create mode 100644 tests/lib/mail/MailerTest.php create mode 100644 tests/lib/mail/MessageTest.php delete mode 100644 tests/lib/mail/mailer.php delete mode 100644 tests/lib/mail/message.php diff --git a/tests/lib/log/OwncloudTest.php b/tests/lib/log/OwncloudTest.php new file mode 100644 index 00000000000..e19063a83f5 --- /dev/null +++ b/tests/lib/log/OwncloudTest.php @@ -0,0 +1,80 @@ +. + */ + +namespace Test\Log; + +use OC\Log\Owncloud; +use Test\TestCase; + +/** + * Class OwncloudTest + * + * @group DB + */ +class OwncloudTest extends TestCase +{ + private $restore_logfile; + private $restore_logdateformat; + + protected function setUp() { + parent::setUp(); + $config = \OC::$server->getConfig(); + $this->restore_logfile = $config->getSystemValue("logfile"); + $this->restore_logdateformat = $config->getSystemValue('logdateformat'); + + $config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest"); + Owncloud::init(); + } + protected function tearDown() { + $config = \OC::$server->getConfig(); + if (isset($this->restore_logfile)) { + $config->getSystemValue("logfile", $this->restore_logfile); + } else { + $config->deleteSystemValue("logfile"); + } + if (isset($this->restore_logdateformat)) { + $config->getSystemValue("logdateformat", $this->restore_logdateformat); + } else { + $config->deleteSystemValue("restore_logdateformat"); + } + Owncloud::init(); + parent::tearDown(); + } + + public function testMicrosecondsLogTimestamp() { + $config = \OC::$server->getConfig(); + # delete old logfile + unlink($config->getSystemValue('logfile')); + + # set format & write log line + $config->setSystemValue('logdateformat', 'u'); + Owncloud::write('test', 'message', \OCP\Util::ERROR); + + # read log line + $handle = @fopen($config->getSystemValue('logfile'), 'r'); + $line = fread($handle, 1000); + fclose($handle); + + # check timestamp has microseconds part + $values = (array) json_decode($line); + $microseconds = $values['time']; + $this->assertNotEquals(0, $microseconds); + + } + + +} diff --git a/tests/lib/log/owncloud.php b/tests/lib/log/owncloud.php deleted file mode 100644 index e19063a83f5..00000000000 --- a/tests/lib/log/owncloud.php +++ /dev/null @@ -1,80 +0,0 @@ -. - */ - -namespace Test\Log; - -use OC\Log\Owncloud; -use Test\TestCase; - -/** - * Class OwncloudTest - * - * @group DB - */ -class OwncloudTest extends TestCase -{ - private $restore_logfile; - private $restore_logdateformat; - - protected function setUp() { - parent::setUp(); - $config = \OC::$server->getConfig(); - $this->restore_logfile = $config->getSystemValue("logfile"); - $this->restore_logdateformat = $config->getSystemValue('logdateformat'); - - $config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest"); - Owncloud::init(); - } - protected function tearDown() { - $config = \OC::$server->getConfig(); - if (isset($this->restore_logfile)) { - $config->getSystemValue("logfile", $this->restore_logfile); - } else { - $config->deleteSystemValue("logfile"); - } - if (isset($this->restore_logdateformat)) { - $config->getSystemValue("logdateformat", $this->restore_logdateformat); - } else { - $config->deleteSystemValue("restore_logdateformat"); - } - Owncloud::init(); - parent::tearDown(); - } - - public function testMicrosecondsLogTimestamp() { - $config = \OC::$server->getConfig(); - # delete old logfile - unlink($config->getSystemValue('logfile')); - - # set format & write log line - $config->setSystemValue('logdateformat', 'u'); - Owncloud::write('test', 'message', \OCP\Util::ERROR); - - # read log line - $handle = @fopen($config->getSystemValue('logfile'), 'r'); - $line = fread($handle, 1000); - fclose($handle); - - # check timestamp has microseconds part - $values = (array) json_decode($line); - $microseconds = $values['time']; - $this->assertNotEquals(0, $microseconds); - - } - - -} diff --git a/tests/lib/mail/MailerTest.php b/tests/lib/mail/MailerTest.php new file mode 100644 index 00000000000..c63ceb5982a --- /dev/null +++ b/tests/lib/mail/MailerTest.php @@ -0,0 +1,123 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Mail; + +use OC\Mail\Mailer; +use OCP\IConfig; +use OC_Defaults; +use OCP\ILogger; +use Test\TestCase; + +class MailerTest extends TestCase { + /** @var IConfig */ + private $config; + /** @var OC_Defaults */ + private $defaults; + /** @var ILogger */ + private $logger; + /** @var Mailer */ + private $mailer; + + function setUp() { + parent::setUp(); + + $this->config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->defaults = $this->getMockBuilder('\OC_Defaults') + ->disableOriginalConstructor()->getMock(); + $this->logger = $this->getMockBuilder('\OCP\ILogger') + ->disableOriginalConstructor()->getMock(); + $this->mailer = new Mailer($this->config, $this->logger, $this->defaults); + } + + public function testGetMailInstance() { + $this->assertEquals(\Swift_MailTransport::newInstance(), self::invokePrivate($this->mailer, 'getMailinstance')); + } + + public function testGetSendMailInstanceSendMail() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('mail_smtpmode', 'sendmail') + ->will($this->returnValue('sendmail')); + + $this->assertEquals(\Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); + } + + public function testGetSendMailInstanceSendMailQmail() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('mail_smtpmode', 'sendmail') + ->will($this->returnValue('qmail')); + + $this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); + } + + public function testGetInstanceDefault() { + $this->assertInstanceOf('\Swift_MailTransport', self::invokePrivate($this->mailer, 'getInstance')); + } + + public function testGetInstancePhp() { + $this->config + ->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue('php')); + + $this->assertInstanceOf('\Swift_MailTransport', self::invokePrivate($this->mailer, 'getInstance')); + } + + public function testGetInstanceSendmail() { + $this->config + ->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue('sendmail')); + + $this->assertInstanceOf('\Swift_Mailer', self::invokePrivate($this->mailer, 'getInstance')); + } + + public function testCreateMessage() { + $this->assertInstanceOf('\OC\Mail\Message', $this->mailer->createMessage()); + } + + /** + * @expectedException \Exception + */ + public function testSendInvalidMailException() { + $message = $this->getMockBuilder('\OC\Mail\Message') + ->disableOriginalConstructor()->getMock(); + $message->expects($this->once()) + ->method('getSwiftMessage') + ->will($this->returnValue(new \Swift_Message())); + + $this->mailer->send($message); + } + + /** + * @return array + */ + public function mailAddressProvider() { + return [ + ['lukas@owncloud.com', true], + ['lukas@localhost', true], + ['lukas@192.168.1.1', true], + ['lukas@éxämplè.com', true], + ['asdf', false], + ['lukas@owncloud.org@owncloud.com', false], + ]; + } + + /** + * @dataProvider mailAddressProvider + */ + public function testValidateMailAddress($email, $expected) { + $this->assertSame($expected, $this->mailer->validateMailAddress($email)); + } + +} diff --git a/tests/lib/mail/MessageTest.php b/tests/lib/mail/MessageTest.php new file mode 100644 index 00000000000..691168ce24c --- /dev/null +++ b/tests/lib/mail/MessageTest.php @@ -0,0 +1,183 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Mail; + +use OC\Mail\Message; +use Swift_Message; +use Test\TestCase; + +class MessageTest extends TestCase { + /** @var Swift_Message */ + private $swiftMessage; + /** @var Message */ + private $message; + + /** + * @return array + */ + public function mailAddressProvider() { + return array( + array(array('lukas@owncloud.com' => 'Lukas Reschke'), array('lukas@owncloud.com' => 'Lukas Reschke')), + array(array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@öwnclöüd.com', 'lukäs@owncloud.örg' => 'Lükäs Réschke'), + array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@xn--wncld-iuae2c.com', 'lukäs@owncloud.xn--rg-eka' => 'Lükäs Réschke')), + array(array('lukas@öwnclöüd.com'), array('lukas@xn--wncld-iuae2c.com')) + ); + } + + function setUp() { + parent::setUp(); + + $this->swiftMessage = $this->getMockBuilder('\Swift_Message') + ->disableOriginalConstructor()->getMock(); + + $this->message = new Message($this->swiftMessage); + } + + /** + * @requires function idn_to_ascii + * @dataProvider mailAddressProvider + * + * @param string $unconverted + * @param string $expected + */ + public function testConvertAddresses($unconverted, $expected) { + $this->assertSame($expected, self::invokePrivate($this->message, 'convertAddresses', array($unconverted))); + } + + public function testSetFrom() { + $this->swiftMessage + ->expects($this->once()) + ->method('setFrom') + ->with(array('lukas@owncloud.com')); + $this->message->setFrom(array('lukas@owncloud.com')); + } + + public function testGetFrom() { + $this->swiftMessage + ->expects($this->once()) + ->method('getFrom') + ->will($this->returnValue(array('lukas@owncloud.com'))); + + $this->assertSame(array('lukas@owncloud.com'), $this->message->getFrom()); + } + + public function testSetReplyTo() { + $this->swiftMessage + ->expects($this->once()) + ->method('setReplyTo') + ->with(['lukas@owncloud.com']); + $this->message->setReplyTo(['lukas@owncloud.com']); + } + + public function testGetReplyTo() { + $this->swiftMessage + ->expects($this->once()) + ->method('getReplyTo') + ->will($this->returnValue(['lukas@owncloud.com'])); + + $this->assertSame(['lukas@owncloud.com'], $this->message->getReplyTo()); + } + + public function testSetTo() { + $this->swiftMessage + ->expects($this->once()) + ->method('setTo') + ->with(array('lukas@owncloud.com')); + $this->message->setTo(array('lukas@owncloud.com')); + } + + public function testGetTo() { + $this->swiftMessage + ->expects($this->once()) + ->method('getTo') + ->will($this->returnValue(array('lukas@owncloud.com'))); + + $this->assertSame(array('lukas@owncloud.com'), $this->message->getTo()); + } + + public function testSetCc() { + $this->swiftMessage + ->expects($this->once()) + ->method('setCc') + ->with(array('lukas@owncloud.com')); + $this->message->setCc(array('lukas@owncloud.com')); + } + + public function testGetCc() { + $this->swiftMessage + ->expects($this->once()) + ->method('getCc') + ->will($this->returnValue(array('lukas@owncloud.com'))); + + $this->assertSame(array('lukas@owncloud.com'), $this->message->getCc()); + } + + public function testSetBcc() { + $this->swiftMessage + ->expects($this->once()) + ->method('setBcc') + ->with(array('lukas@owncloud.com')); + $this->message->setBcc(array('lukas@owncloud.com')); + } + + public function testGetBcc() { + $this->swiftMessage + ->expects($this->once()) + ->method('getBcc') + ->will($this->returnValue(array('lukas@owncloud.com'))); + + $this->assertSame(array('lukas@owncloud.com'), $this->message->getBcc()); + } + + public function testSetSubject() { + $this->swiftMessage + ->expects($this->once()) + ->method('setSubject') + ->with('Fancy Subject'); + + $this->message->setSubject('Fancy Subject'); + } + + public function testGetSubject() { + $this->swiftMessage + ->expects($this->once()) + ->method('getSubject') + ->will($this->returnValue('Fancy Subject')); + + $this->assertSame('Fancy Subject', $this->message->getSubject()); + } + + public function testSetPlainBody() { + $this->swiftMessage + ->expects($this->once()) + ->method('setBody') + ->with('Fancy Body'); + + $this->message->setPlainBody('Fancy Body'); + } + + public function testGetPlainBody() { + $this->swiftMessage + ->expects($this->once()) + ->method('getBody') + ->will($this->returnValue('Fancy Body')); + + $this->assertSame('Fancy Body', $this->message->getPlainBody()); + } + + public function testSetHtmlBody() { + $this->swiftMessage + ->expects($this->once()) + ->method('addPart') + ->with('Fancy Body', 'text/html'); + + $this->message->setHtmlBody('Fancy Body'); + } + +} diff --git a/tests/lib/mail/mailer.php b/tests/lib/mail/mailer.php deleted file mode 100644 index 8023cda820e..00000000000 --- a/tests/lib/mail/mailer.php +++ /dev/null @@ -1,121 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test; -use OC\Mail\Mailer; -use OCP\IConfig; -use OC_Defaults; -use OCP\ILogger; - -class MailerTest extends TestCase { - /** @var IConfig */ - private $config; - /** @var OC_Defaults */ - private $defaults; - /** @var ILogger */ - private $logger; - /** @var Mailer */ - private $mailer; - - function setUp() { - parent::setUp(); - - $this->config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor()->getMock(); - $this->defaults = $this->getMockBuilder('\OC_Defaults') - ->disableOriginalConstructor()->getMock(); - $this->logger = $this->getMockBuilder('\OCP\ILogger') - ->disableOriginalConstructor()->getMock(); - $this->mailer = new Mailer($this->config, $this->logger, $this->defaults); - } - - public function testGetMailInstance() { - $this->assertEquals(\Swift_MailTransport::newInstance(), self::invokePrivate($this->mailer, 'getMailinstance')); - } - - public function testGetSendMailInstanceSendMail() { - $this->config - ->expects($this->once()) - ->method('getSystemValue') - ->with('mail_smtpmode', 'sendmail') - ->will($this->returnValue('sendmail')); - - $this->assertEquals(\Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); - } - - public function testGetSendMailInstanceSendMailQmail() { - $this->config - ->expects($this->once()) - ->method('getSystemValue') - ->with('mail_smtpmode', 'sendmail') - ->will($this->returnValue('qmail')); - - $this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); - } - - public function testGetInstanceDefault() { - $this->assertInstanceOf('\Swift_MailTransport', self::invokePrivate($this->mailer, 'getInstance')); - } - - public function testGetInstancePhp() { - $this->config - ->expects($this->any()) - ->method('getSystemValue') - ->will($this->returnValue('php')); - - $this->assertInstanceOf('\Swift_MailTransport', self::invokePrivate($this->mailer, 'getInstance')); - } - - public function testGetInstanceSendmail() { - $this->config - ->expects($this->any()) - ->method('getSystemValue') - ->will($this->returnValue('sendmail')); - - $this->assertInstanceOf('\Swift_Mailer', self::invokePrivate($this->mailer, 'getInstance')); - } - - public function testCreateMessage() { - $this->assertInstanceOf('\OC\Mail\Message', $this->mailer->createMessage()); - } - - /** - * @expectedException \Exception - */ - public function testSendInvalidMailException() { - $message = $this->getMockBuilder('\OC\Mail\Message') - ->disableOriginalConstructor()->getMock(); - $message->expects($this->once()) - ->method('getSwiftMessage') - ->will($this->returnValue(new \Swift_Message())); - - $this->mailer->send($message); - } - - /** - * @return array - */ - public function mailAddressProvider() { - return [ - ['lukas@owncloud.com', true], - ['lukas@localhost', true], - ['lukas@192.168.1.1', true], - ['lukas@éxämplè.com', true], - ['asdf', false], - ['lukas@owncloud.org@owncloud.com', false], - ]; - } - - /** - * @dataProvider mailAddressProvider - */ - public function testValidateMailAddress($email, $expected) { - $this->assertSame($expected, $this->mailer->validateMailAddress($email)); - } - -} diff --git a/tests/lib/mail/message.php b/tests/lib/mail/message.php deleted file mode 100644 index 339677c0a7c..00000000000 --- a/tests/lib/mail/message.php +++ /dev/null @@ -1,182 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test; - -use OC\Mail\Message; -use Swift_Message; - -class MessageTest extends TestCase { - /** @var Swift_Message */ - private $swiftMessage; - /** @var Message */ - private $message; - - /** - * @return array - */ - public function mailAddressProvider() { - return array( - array(array('lukas@owncloud.com' => 'Lukas Reschke'), array('lukas@owncloud.com' => 'Lukas Reschke')), - array(array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@öwnclöüd.com', 'lukäs@owncloud.örg' => 'Lükäs Réschke'), - array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@xn--wncld-iuae2c.com', 'lukäs@owncloud.xn--rg-eka' => 'Lükäs Réschke')), - array(array('lukas@öwnclöüd.com'), array('lukas@xn--wncld-iuae2c.com')) - ); - } - - function setUp() { - parent::setUp(); - - $this->swiftMessage = $this->getMockBuilder('\Swift_Message') - ->disableOriginalConstructor()->getMock(); - - $this->message = new Message($this->swiftMessage); - } - - /** - * @requires function idn_to_ascii - * @dataProvider mailAddressProvider - * - * @param string $unconverted - * @param string $expected - */ - public function testConvertAddresses($unconverted, $expected) { - $this->assertSame($expected, self::invokePrivate($this->message, 'convertAddresses', array($unconverted))); - } - - public function testSetFrom() { - $this->swiftMessage - ->expects($this->once()) - ->method('setFrom') - ->with(array('lukas@owncloud.com')); - $this->message->setFrom(array('lukas@owncloud.com')); - } - - public function testGetFrom() { - $this->swiftMessage - ->expects($this->once()) - ->method('getFrom') - ->will($this->returnValue(array('lukas@owncloud.com'))); - - $this->assertSame(array('lukas@owncloud.com'), $this->message->getFrom()); - } - - public function testSetReplyTo() { - $this->swiftMessage - ->expects($this->once()) - ->method('setReplyTo') - ->with(['lukas@owncloud.com']); - $this->message->setReplyTo(['lukas@owncloud.com']); - } - - public function testGetReplyTo() { - $this->swiftMessage - ->expects($this->once()) - ->method('getReplyTo') - ->will($this->returnValue(['lukas@owncloud.com'])); - - $this->assertSame(['lukas@owncloud.com'], $this->message->getReplyTo()); - } - - public function testSetTo() { - $this->swiftMessage - ->expects($this->once()) - ->method('setTo') - ->with(array('lukas@owncloud.com')); - $this->message->setTo(array('lukas@owncloud.com')); - } - - public function testGetTo() { - $this->swiftMessage - ->expects($this->once()) - ->method('getTo') - ->will($this->returnValue(array('lukas@owncloud.com'))); - - $this->assertSame(array('lukas@owncloud.com'), $this->message->getTo()); - } - - public function testSetCc() { - $this->swiftMessage - ->expects($this->once()) - ->method('setCc') - ->with(array('lukas@owncloud.com')); - $this->message->setCc(array('lukas@owncloud.com')); - } - - public function testGetCc() { - $this->swiftMessage - ->expects($this->once()) - ->method('getCc') - ->will($this->returnValue(array('lukas@owncloud.com'))); - - $this->assertSame(array('lukas@owncloud.com'), $this->message->getCc()); - } - - public function testSetBcc() { - $this->swiftMessage - ->expects($this->once()) - ->method('setBcc') - ->with(array('lukas@owncloud.com')); - $this->message->setBcc(array('lukas@owncloud.com')); - } - - public function testGetBcc() { - $this->swiftMessage - ->expects($this->once()) - ->method('getBcc') - ->will($this->returnValue(array('lukas@owncloud.com'))); - - $this->assertSame(array('lukas@owncloud.com'), $this->message->getBcc()); - } - - public function testSetSubject() { - $this->swiftMessage - ->expects($this->once()) - ->method('setSubject') - ->with('Fancy Subject'); - - $this->message->setSubject('Fancy Subject'); - } - - public function testGetSubject() { - $this->swiftMessage - ->expects($this->once()) - ->method('getSubject') - ->will($this->returnValue('Fancy Subject')); - - $this->assertSame('Fancy Subject', $this->message->getSubject()); - } - - public function testSetPlainBody() { - $this->swiftMessage - ->expects($this->once()) - ->method('setBody') - ->with('Fancy Body'); - - $this->message->setPlainBody('Fancy Body'); - } - - public function testGetPlainBody() { - $this->swiftMessage - ->expects($this->once()) - ->method('getBody') - ->will($this->returnValue('Fancy Body')); - - $this->assertSame('Fancy Body', $this->message->getPlainBody()); - } - - public function testSetHtmlBody() { - $this->swiftMessage - ->expects($this->once()) - ->method('addPart') - ->with('Fancy Body', 'text/html'); - - $this->message->setHtmlBody('Fancy Body'); - } - -} -- cgit v1.2.3