Inheritance: extends PHPUnit_Framework_TestCase
Ejemplo n.º 1
0
 /**
  * Test adding product to cart
  */
 public function testAddToCart()
 {
     if (self::$_photoUrl) {
         $options = $this->_model->getOptions();
         $data = array();
         foreach ($options as $code => $option) {
             if ($option['required']) {
                 $value = reset($option['values']);
                 $data[$code] = $value['id'];
             }
         }
         $data[$this->_photoCode] = self::$_photoUrl;
         $result = $this->_model->addToCart($data);
         $this->assertFalse($result['error']);
         $hash = $result['data'];
         $result = $this->_model->getQuote($hash);
         $this->assertFalse($result['error']);
         $quoteId = $result['data'];
         $store = Mage::getSingleton('core/store')->load($this->_model->getStoreId());
         $quote = Mage::getModel('sales/quote')->setStore($store)->load($quoteId);
         $gotQuote = $quote && $quote->getId() ? true : false;
         $this->assertTrue($gotQuote);
         self::$_quoteId = $quoteId;
     }
 }
Ejemplo n.º 2
0
 static function setUpBeforeClass()
 {
     DB::open(array('master' => true, 'driver' => 'sqlite', 'file' => ':memory:'));
     $sql = sql_split("create table qwerty ( foo char(12), bar char(12) );\n\t\tcreate table foo(id int, name char(12));\n\t\tcreate table bar(id int, name char(12), foo int);\n\t\tcreate table gallery (\n\t\t\tid integer primary key,\n\t\t\ttitle char(48)\n\t\t);\n\t\tcreate table cover (\n\t\t\tid integer primary key,\n\t\t\tgallery integer unique,\n\t\t\ttitle char(48)\n\t\t);\n\t\tcreate table item (\n\t\t\tid integer primary key,\n\t\t\tgallery_id integer,\n\t\t\ttitle char(48)\n\t\t);\n\t\tinsert into gallery (id, title) values (1, 'Gallery One');\n\t\tinsert into cover (id, gallery, title) values (1, 1, 'Cover One');\n\t\tinsert into item (id, gallery_id, title) values (1, 1, 'Item One');\n\t\tinsert into item (id, gallery_id, title) values (2, 1, 'Item Two');\n\t\tinsert into item (id, gallery_id, title) values (3, 1, 'Item Three');\n\t\tinsert into gallery (id, title) values (2, 'Gallery Two');\n\t\tinsert into cover (id, gallery, title) values (2, 2, 'Cover Two');\n\t\tinsert into item (id, gallery_id, title) values (4, 2, 'Item Four');\n\t\tinsert into item (id, gallery_id, title) values (5, 2, 'Item Five');\n\t\tinsert into item (id, gallery_id, title) values (6, 2, 'Item Six');\n\t\tcreate table author (\n\t\t\tid integer primary key,\n\t\t\tname char(32)\n\t\t);\n\t\tcreate table book (\n\t\t\tid integer primary key,\n\t\t\tname char(32)\n\t\t);\n\t\tcreate table book_author (\n\t\t\tbook int not null,\n\t\t\tauthor int not null\n\t\t);\n\t\tinsert into author (id, name) values (1, 'Johnny Fast Fingers');\n\t\tinsert into author (id, name) values (2, 'Frankie Bazzar');\n\t\tinsert into book (id, name) values (1, 'Johnny & Frankie');\n\t\tinsert into book (id, name) values (2, 'Jamaican Me Crazy');\n\t\tinsert into book_author (book, author) values (1, 1);\n\t\tinsert into book_author (book, author) values (1, 2);\n\t\tinsert into book_author (book, author) values (2, 1);\n\t\tinsert into book_author (book, author) values (2, 2);\n\t\tcreate table next_test (\n\t\t\tfieldname int not null\n\t\t);\n\t\t");
     foreach ($sql as $query) {
         DB::execute($query);
     }
     self::$q = new Qwerty();
 }
Ejemplo n.º 3
0
    /**
     * Test stats API call
     * 
     * @return void
     */
    public function testStats()
    {
        $getCallCount = 0;
        $this->Http->response['status']['code'] = 200;
        // Test normal call
        $params['hash'] = 'R8hVH';
        // cakephp.org
        $expectedParams = array('http://api.bit.ly/stats', array('hash' => 'R8hVH', 'format' => 'json', 'login' => 'testLogin', 'apiKey' => 'testApiKey', 'version' => '2.0.1'));
        ksort($expectedParams[1]);
        $responseData = array('clicks' => 6, 'hash' => 'R8hVH', 'referrers' => array('' => array('direct' => 4), 'twitter.com' => array('/' => 1, '/home' => 1)));
        $response = json_encode(array('errorCode' => 0, 'errorMessage' => '', 'results' => $responseData, 'statusCode' => 'OK'));
        $this->Http->expectAt($getCallCount, 'get', $expectedParams);
        $this->Http->setReturnValueAt($getCallCount++, 'get', $response);
        $result = $this->Model->stats(compact('params'));
        $expected = array('result' => $responseData, 'code' => 200);
        $this->assertEqual($result, $expected);
        // Test XML call
        $expectedParams[1]['format'] = 'xml';
        $response = '<bitly>
			<errorCode>0</errorCode>
			<errorMessage></errorMessage>
			<results>
				<referrers>
					<nodeKeyVal>
						<direct>4</direct>
						<nodeKey><![CDATA[]]></nodeKey>
					</nodeKeyVal>
					<nodeKeyVal>
						<nodeKey><![CDATA[twitter.com]]></nodeKey>
						<nodeKeyVal>
							<nodeValue><![CDATA[1]]></nodeValue>
							<nodeKey><![CDATA[/]]></nodeKey>
						</nodeKeyVal>
						<nodeKeyVal>
							<nodeValue><![CDATA[1]]></nodeValue>
							<nodeKey><![CDATA[/home]]></nodeKey>
						</nodeKeyVal>
					</nodeKeyVal>
				</referrers>
				<hash>R8hVH</hash>
				<clicks>6</clicks>
			</results>
			<statusCode>OK</statusCode>
		</bitly>';
        $this->Http->expectAt($getCallCount, 'get', $expectedParams);
        $this->Http->setReturnValueAt($getCallCount++, 'get', $response);
        $result = $this->Model->stats(array('format' => 'xml', 'params' => $params));
        $expected = array('result' => $responseData, 'code' => 200);
        $this->assertEqual($result, $expected);
        if ($this->__useTestSocket) {
            $this->Http->expectCallCount('get', $getCallCount);
        }
    }
Ejemplo n.º 4
0
 /**
  * Run when initializing
  *
  * @return null
  */
 public static function setUpBeforeClass()
 {
     $file = realpath(dirname(__FILE__) . "/../database/test.sqlite3");
     self::$con = new PDO("sqlite:{$file}");
     // self::$con  = new PDO('mysql:host=localhost;dbname=torm',"torm","torm");
     TORM\Connection::setConnection(self::$con, "test");
     TORM\Connection::setEncoding("UTF-8");
     TORM\Connection::setDriver("sqlite");
     // TORM\Connection::setDriver("mysql");
     TORM\Factory::setFactoriesPath("./factories");
     TORM\Log::enable(false);
     self::$user = new User();
     self::$user->id = 1;
     self::$user->name = "John Doe Jr.";
     self::$user->email = "*****@*****.**";
     self::$user->code = "12345";
     self::$user->level = 1;
 }
Ejemplo n.º 5
0
 /**
  * This method is called before the first test of this test class is run.
  *
  * @since Method available since Release 3.4.0
  */
 public static function setUpBeforeClass()
 {
     self::$config = json_decode(file_get_contents(dirname(__DIR__) . '/config.test.json'), true);
 }
Ejemplo n.º 6
0
 /**
  * Find the test connection
  *
  * @return resource connection
  */
 private static function _connection()
 {
     $file = realpath(dirname(__FILE__) . "/../database/test.sqlite3");
     $database = self::_database();
     echo "Testing using {$database}\n";
     switch ($database) {
         case "sqlite":
             self::$con = new PDO("sqlite:{$file}");
             break;
         case "mysql":
             self::$con = new PDO('mysql:host=localhost;dbname=torm', "torm", "torm");
             break;
         case "postgresql":
             self::$con = new PDO('pgsql:host=localhost;dbname=torm', "torm", "torm");
             break;
         case "oracle":
             self::$con = new PDOOCI\PDO('docker', 'system', 'oracle');
             self::$con->query("alter session set NLS_DATE_FORMAT='YYYY-MM-DD'");
             self::$con->query("alter session set NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'");
     }
     return self::$con;
 }