<?php

Mock::Generate('Csv_Dialect', 'Mock_Dialect');
Mock::Generate('Csv_Dialect', 'Mock_Dialect_Two');
/**
 * Csv Writer unit tests
 */
class Test_Of_Csv_Writer extends UnitTestCase
{
    public function setUp()
    {
        $this->dialect = new Mock_Dialect();
        $this->dialect->delimiter = ",";
        $this->dialect->quotechar = '"';
        $this->dialect->escapechar = "\\";
        $this->dialect->skipblanklines = true;
        $this->dialect->lineterminator = "\r\n";
        $this->file = realpath('../') . '/tests/data/writer1.csv';
        $this->file2 = realpath('../') . '/tests/data/writer2.csv';
        $this->file3 = realpath('../') . '/tests/data/writer3.csv';
        $this->testdata = array(array('This contains the quote "character" because it\'s cool like that', 1, 2), array("This one contains some commas, and some \t\t tabs and stuff", 45, 2009), array('I have "several" different kinds of \'quotes\'', 133, 2234234), array("I am regular\n\r text but with a line break in me", 21, "Num123412342"));
    }
    public function tearDown()
    {
        if (file_exists($this->file)) {
            unlink($this->file);
        }
        if (file_exists($this->file2)) {
            unlink($this->file2);
        }
        if (file_exists($this->file3)) {
<?php

if (!class_exists("FullMockConnection")) {
    Mock::Generate("DummyConnection", "FullMockConnection");
}
class TestOfMultiConnection extends UnitTestCase
{
    public function testConnectionChoosesOnlyOneWorkingConnection()
    {
        $mock1 = new FullMockConnection();
        $mock1->setReturnValue("isAlive", false);
        $mock1->expectOnce("start");
        $mock1->expectNever("read");
        $mock1->expectNever("write");
        $mock2 = new FullMockConnection();
        $mock2->setReturnValue("isAlive", true);
        $mock2->expectOnce("start");
        $mock2->expectOnce("read");
        $mock2->expectCallCount("write", 3);
        $mock2->expectAt(0, "write", array("foo", "*"));
        $mock2->expectAt(1, "write", array("bar", "*"));
        $mock2->expectAt(2, "write", array("zip", "*"));
        $mock3 = new FullMockConnection();
        $mock3->setReturnValue("isAlive", true);
        $mock3->expectNever("start");
        $mock3->expectNever("read");
        $mock3->expectNever("write");
        $multi = new Swift_Connection_Multi();
        $multi->addConnection($mock1, "mock1");
        $multi->addConnection($mock2, "mock2");
        $multi->addConnection($mock3, "mock3");
Beispiel #3
0
Swift_ClassLoader::load("Swift_Events_BeforeCommandListener");
Swift_ClassLoader::load("Swift_Events_CommandListener");
Swift_ClassLoader::load("Swift_Events_ResponseListener");
Swift_ClassLoader::load("Swift_Events_ConnectListener");
Swift_ClassLoader::load("Swift_Events_DisconnectListener");
Swift_ClassLoader::load("Swift_Plugin_AntiFlood");
Swift_ClassLoader::load("Swift_Plugin_BandwidthMonitor");
Swift_ClassLoader::load("Swift_Plugin_Throttler");
Swift_ClassLoader::load("Swift_Plugin_VerboseSending");
Swift_ClassLoader::load("Swift_Plugin_ConnectionRotator");
Swift_ClassLoader::load("Swift_Plugin_Decorator");
Swift_ClassLoader::load("Swift_Message_Headers");
Swift_ClassLoader::load("Swift_CacheFactory");
Swift_ClassLoader::load("Swift_Log_DefaultLog");
Swift_ClassLoader::load("Swift_Message_Encoder");
Swift_ClassLoader::load("Swift_Cache_JointOutputStream");
require_once TestConfiguration::SWIFT_LIBRARY_PATH . "/Swift/Authenticator/@PopB4Smtp.php";
Swift_ClassLoader::load("Swift_Authenticator_PopB4Smtp_Pop3Connection");
require_once dirname(__FILE__) . "/AbstractTestWithSend.php";
require_once dirname(__FILE__) . "/AbstractTestOfCache.php";
require_once dirname(__FILE__) . "/AbstractTestOfAuthenticator.php";
require_once dirname(__FILE__) . "/stubs/MimeExtension.php";
require_once dirname(__FILE__) . "/stubs/DummyConnection.php";
Mock::Generate("DummyConnection", "FullMockConnection");
Mock::Generate("Swift_Connection_Rotator", "MockRotatorConnection");
Mock::Generate("Swift_Message", "MockMessage");
Mock::Generate("Swift_Events_SendListener", "MockSendListener");
Mock::Generate("Swift_Connection_SMTP", "MockSMTPConnection");
Mock::GeneratePartial("Swift_Connection_SMTP", "MockSMTPConnectionAuth", array("read", "write", "isAlive", "start", "stop"));
Mock::Generate("Swift_Message_Headers", "MockHeaders");
<?php

/**
 * Swift Mailer Unit Test for the Swift_Authenticator Interface.
 * @package Swift
 * @subpackage Tests
 * @author Chris Corbyn <*****@*****.**>
 */
Mock::Generate("Swift_Authenticator", "MockAuthenticator");
Mock::GeneratePartial("Swift_Connection_SMTP", "PartialSmtpConnection", array("read"));
/**
 * Swift Mailer Unit Test for the Swift_Authenticator Interface.
 * @package Swift
 * @subpackage Tests
 * @author Chris Corbyn <*****@*****.**>
 */
class TestOfAuthenticator extends UnitTestCase
{
    /**
     * Checks that the interface is actually invoked when needed.
     */
    public function testAuthenticatorIsInvokedIfSMTPUsernameAndPasswordSet()
    {
        try {
            $auth = new MockAuthenticator();
            $auth->setReturnValue("getAuthExtensionName", "FOO");
            $auth->expectOnce("isAuthenticated", array("foo", "bar", "*"));
            $smtp = new PartialSmtpConnection();
            $smtp->setExtension("AUTH", array("FOO"));
            $smtp->setUsername("foo");
            $smtp->setPassword("bar");
<?php

if (!class_exists("FullMockConnection")) {
    Mock::Generate("DummyConnection", "FullMockConnection");
}
Mock::Generate("Swift_Events_SendListener", "MockSendListener");
Mock::Generate("Swift_Events_BeforeSendListener", "MockBeforeSendListener");
Mock::Generate("Swift_Events_CommandListener", "MockCommandListener");
Mock::Generate("Swift_Events_BeforeCommandListener", "MockBeforeCommandListener");
Mock::Generate("Swift_Events_ResponseListener", "MockResponseListener");
Mock::Generate("Swift_Events_ConnectListener", "MockConnectListener");
Mock::Generate("Swift_Events_DisconnectListener", "MockDisconnectListener");
class TestOfPluginAPI extends UnitTestCase
{
    /** Get a mock connection for testing
     * @param int The number emails you expect to send
     * @return FullMockConnection
     */
    protected function getWorkingMockConnection($send = 1)
    {
        $count = 0;
        $conn = new FullMockConnection();
        $conn->setReturnValueAt($count++, "read", "220 xxx ESMTP");
        $conn->setReturnValueAt($count++, "read", "250-Hello xxx\r\n250 HELP");
        for ($i = 0; $i < $send; $i++) {
            $conn->setReturnValueAt($count++, "read", "250 Ok");
            $conn->setReturnValueAt($count++, "read", "250 Ok");
            $conn->setReturnValueAt($count++, "read", "354 Go ahead");
            $conn->setReturnValueAt($count++, "read", "250 Ok");
        }
        $conn->setReturnValueAt($count++, "read", "221 Bye");
Beispiel #6
0
<?php

class Orm_DataMapper_Mapping_Object
{
    public $item;
    function setItem($item)
    {
    }
    function set()
    {
    }
    function get()
    {
    }
}
Mock::Generate('Orm_DataMapper_Mapping_Object', 'Orm_DataMapper_Mapping_MockObject');
class Orm_DataMapper_Mapping_Test extends UnitTestCase
{
    public function setUp()
    {
        $this->object = new Orm_DataMapper_Mapping_MockObject();
        $this->setMethod = 'setDescription';
        $this->getMethod = 'getDescription';
        $this->property = 'description';
        $this->column = 'table.description';
        $this->alias = 'description';
        $this->table = 'items';
        #		public function __construct ($getMethod='', $setMethod='', $property='', $column='', $table='', $key = false, $callback = array(), $param = false)	{
        $this->mapping = new A_Orm_DataMapper_Mapping($this->getMethod, $this->setMethod, $this->property, array($this->alias => $this->column), $this->table, true);
    }
    public function testGetSetMethod()
Beispiel #7
0
<?php

/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
require_once 'limb/wact/src/compiler/templatecompiler.inc.php';
Mock::Generate('WactCompileTreeNode', 'MockWactCompileTreeNode');
Mock::Generate('WactCompilerProperty', 'MockWactCompilerProperty');
Mock::Generate('WactCodeWriter', 'MockWactCodeWriter');
class WactCompilerPropertyDBETestVersion extends WactCompilerProperty
{
    function generateScopeEntry($code_writer)
    {
        $code_writer->writePHP('generateScopeEntryOutput');
    }
    function generatePreStatement($code_writer)
    {
        $code_writer->writePHP('generatePreStatementOutput');
    }
    function generateExpression($code_writer)
    {
        $code_writer->writePHP('generateExpressionOutput');
    }
    function generatePostStatement($code_writer)
    {
        $code_writer->writePHP('generatePostStatementOutput');
    }
<?php

/**
 * SwiftMailer Unit Testing Component.
 * Provides a testcase with functionality to get a Working Mock Connection.
 * @package Swift
 * @subpackage Tests
 * @author Chris Corbyn <*****@*****.**>
 */
Mock::Generate("Swift_Connection", "FullMockConnection");
/**
 * SwiftMailer Abstract test with sending capabilities.
 * Provides a testcase with functionality to get a Working Mock Connection.
 * @package Swift
 * @subpackage Tests
 * @author Chris Corbyn <*****@*****.**>
 */
abstract class AbstractTestWithSend extends UnitTestCase
{
    /**
     * Get a mock connection for testing.
     * The mock will be set up to send to X addresses (sccuessfully).
     * The mock can also be configured to reconnect after X emails have been sent.
     * @param int The number emails you expect to send
     * @param Swift_Connection A mocked object which has not been setup yet, optional
     * @param int The number of emails to send before reconnecting, optional
     * @param int The maximum number of times the connection will re-connect, optional
     * @param boolean True if the same email is copied to all recipients
     * @return FullMockConnection
     */
    protected function getWorkingMockConnection($send = 1, $conn = null, $reconnect_at = 0, $max_reconnect = 0, $duplicate = false)
Beispiel #9
0
<?php

/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com 
 * @copyright  Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
 */
require_once 'limb/wact/src/compiler/templatecompiler.inc.php';
require_once 'limb/wact/src/compiler/attribute/WactAttribute.class.php';
Mock::Generate('WactAttributeExpressionFragment', 'MockWactAttributeFragment');
class WactAttributeTest extends UnitTestCase
{
    protected $fragment1;
    protected $fragment2;
    protected $attribute;
    function setUp()
    {
        $this->fragment1 = new MockWactAttributeFragment();
        $this->fragment2 = new MockWactAttributeFragment();
        $this->attribute = new WactAttribute('test');
        $this->attribute->addFragment($this->fragment1);
        $this->attribute->addFragment($this->fragment2);
    }
    function testIsConstantAllTrue()
    {
        $this->fragment1->setReturnValue('IsConstant', TRUE);
        $this->fragment1->expectOnce('IsConstant');
        $this->fragment2->setReturnValue('IsConstant', TRUE);
        $this->fragment2->expectOnce('IsConstant');
Beispiel #10
0
<?php

Mock::Generate('A_Db_Mysql', 'Pagination_Adapter_MockDb');
Mock::Generate('A_Db_Recordset_Mysql', 'Pagination_Adapter_MockResult');
class Pagination_Adapter_DbTest extends UnitTestCase
{
    public function setUp()
    {
        $this->db = new Pagination_Adapter_MockDb();
        $this->result = new Pagination_Adapter_MockResult();
        $this->db->setReturnValue('query', $this->result);
        $this->db->setReturnValue('limit', 'SELECT * FROM pages LIMIT 10');
        $this->db->expect('limit', array('*', 10, 9));
        // 9 because LIMIT offset is zero based
        $this->row = array('one', 'two', 'three', 'four');
        $this->query = 'SELECT * FROM pages';
        $this->adapter = new A_Pagination_Adapter_Db($this->db, $this->query);
    }
    public function testGetNumItemsDelegatesToDatasource()
    {
        $this->db->expectOnce('query');
        $this->adapter->getNumItems();
    }
    public function testGetNumItemsReplacesAsteriskWithCount()
    {
        $this->db->expectOnce('query', array('SELECT COUNT(*) AS count FROM pages'));
        $this->adapter->getNumItems();
    }
    public function testGetNumItemsReturnsValueFromDatasource()
    {
        $this->result->setReturnValue('isError', false);
Beispiel #11
0
<?php

Mock::Generate('A_Datetime_Range');
Mock::Generate('A_Datetime_Duration');
class DatetimeTest extends UnitTestCase
{
    function setUp()
    {
    }
    function TearDown()
    {
    }
    function testDatetime_parseDate()
    {
        $datetime = new A_Datetime();
        $datetime->parseDate('2001/12/20');
        $this->assertEqual($datetime->getDate(), '2001-12-20');
        $datetime->parseDate('12//20//2001');
        $this->assertEqual($datetime->getDate(), '2001-12-20');
        $datetime->parseDate('20.12.2001');
        $this->assertEqual($datetime->getDate(), '2001-12-20');
        $datetime->parseDate('12/20/01');
        $this->assertEqual($datetime->getDate(), '2001-12-20');
        $datetime->parseDate('12/20/01');
        $this->assertEqual($datetime->getDate(), '2001-12-20');
        $datetime->parseDate('1/2/01');
        $this->assertEqual($datetime->getDate(), '2001-02-01');
        $datetime->parseDate('020301');
        $this->assertEqual($datetime->getDate(), '2001-03-02');
        $datetime->parseDate('19990706');
        $this->assertEqual($datetime->getDate(), '1999-07-06');
<?php

class DomainObject
{
}
Mock::Generate('DomainObject', 'MockDomainObject');
class Orm_DataMapperTest extends UnitTestCase
{
    public function setUp()
    {
        $db = true;
        $this->mapper = new A_Orm_DataMapper($db, 'MockObject', 'pages');
        $this->mapper->mapMethods('getTitle', 'setTitle')->toColumn('title');
        $this->mapper->mapProperty('description')->toColumn('description', 'items');
        $this->mapper->mapProperty('body')->toColumn(array('body' => 'page_body'));
        $this->object = $this->mapper->load(array('title' => 'Hello', 'description' => 'Cheesy'));
    }
    public function testLoadReturnsCorrectClass()
    {
        $this->assertIsA($this->object, 'MockObject');
    }
    public function testMapMethodsToColumn()
    {
        $this->assertEqual($this->object->getTitle(), 'Hello');
    }
    public function testMapPropertytoColumn()
    {
        $this->assertEqual($this->object->description, 'Cheesy');
    }
    public function testGetTableNames()
    {