2015-10-11 18:14:49 +00:00
|
|
|
<?php
|
2015-10-12 15:28:38 +00:00
|
|
|
/**
|
2016-05-07 17:22:09 +00:00
|
|
|
* FuzeWorks.
|
2015-10-12 15:28:38 +00:00
|
|
|
*
|
|
|
|
* The FuzeWorks MVC PHP FrameWork
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 TechFuze
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author TechFuze
|
2016-05-07 17:22:09 +00:00
|
|
|
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
2015-10-12 15:28:38 +00:00
|
|
|
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
2016-05-07 17:22:09 +00:00
|
|
|
*
|
2015-10-12 15:28:38 +00:00
|
|
|
* @link http://fuzeworks.techfuze.net
|
|
|
|
* @since Version 0.0.1
|
2016-05-07 17:22:09 +00:00
|
|
|
*
|
2015-10-12 15:28:38 +00:00
|
|
|
* @version Version 0.0.1
|
|
|
|
*/
|
2015-10-11 18:14:49 +00:00
|
|
|
use \FuzeWorks\Core;
|
|
|
|
use \FuzeWorks\Models;
|
|
|
|
|
|
|
|
/**
|
2016-05-07 17:22:09 +00:00
|
|
|
* Class ModelTest.
|
2015-10-11 18:14:49 +00:00
|
|
|
*
|
|
|
|
* Core model testing suite, will test basic model functionality
|
|
|
|
*/
|
2016-05-07 17:22:09 +00:00
|
|
|
class modelTest extends CoreTestAbstract
|
2015-10-11 18:14:49 +00:00
|
|
|
{
|
|
|
|
/**
|
2016-05-07 17:22:09 +00:00
|
|
|
* Select.
|
2015-10-11 18:14:49 +00:00
|
|
|
*/
|
|
|
|
public function testSelectSimple()
|
|
|
|
{
|
|
|
|
$query = Models::get('sqltable')->select();
|
|
|
|
$this->assertEquals('SELECT * FROM table', $query->getSql());
|
|
|
|
}
|
|
|
|
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testSelectSimpleOneField()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->select('field1');
|
|
|
|
$this->assertEquals('SELECT field1 FROM table', $query->getSql());
|
|
|
|
}
|
|
|
|
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testSelectSimpleTwoFields()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->select('field1', 'field2');
|
|
|
|
$this->assertEquals('SELECT field1, field2 FROM table', $query->getSql());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-07 17:22:09 +00:00
|
|
|
* Delete.
|
2015-10-11 18:14:49 +00:00
|
|
|
*/
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testDeleteSimple()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->delete()->from('table');
|
|
|
|
$this->assertEquals('DELETE FROM table', $query->getSql());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-07 17:22:09 +00:00
|
|
|
* Insert.
|
2015-10-11 18:14:49 +00:00
|
|
|
*/
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testInsertSimple()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->insert(array('field' => 'value'));
|
|
|
|
$this->assertEquals('INSERT INTO table (field) VALUES (?)', $query->getSql());
|
|
|
|
$this->assertEquals(array('value'), $query->getBinds());
|
|
|
|
}
|
|
|
|
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testInsertMultiple()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->insert(array('field1' => 'value1', 'field2' => 'value2'), 'table');
|
|
|
|
$this->assertEquals('INSERT INTO table (field1,field2) VALUES (?,?)', $query->getSql());
|
|
|
|
$this->assertEquals(array('value1', 'value2'), $query->getBinds());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-07 17:22:09 +00:00
|
|
|
* Replace.
|
2015-10-11 18:14:49 +00:00
|
|
|
*/
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testReplaceSimple()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->replace(array('field' => 'value'));
|
|
|
|
$this->assertEquals('REPLACE INTO table (field) VALUES (?)', $query->getSql());
|
|
|
|
$this->assertEquals(array('value'), $query->getBinds());
|
|
|
|
}
|
|
|
|
|
2016-05-07 17:22:09 +00:00
|
|
|
public function testReplaceMultiple()
|
|
|
|
{
|
2015-10-11 18:14:49 +00:00
|
|
|
$query = Models::get('sqltable')->replace(array('field1' => 'value1', 'field2' => 'value2'), 'table');
|
|
|
|
$this->assertEquals('REPLACE INTO table (field1,field2) VALUES (?,?)', $query->getSql());
|
|
|
|
$this->assertEquals(array('value1', 'value2'), $query->getBinds());
|
|
|
|
}
|
2016-05-07 17:22:09 +00:00
|
|
|
}
|