Skip to content

Commit

Permalink
Added ModelTest
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Hill <dchill42@gmail.com>
  • Loading branch information
dchill42 committed Feb 19, 2014
1 parent f466241 commit 647f22f
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
8 changes: 6 additions & 2 deletions system/core/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@
* @subpackage core
* @link http://xylophone.io/user_guide/general/models.html
*/
class Model {
class Model
{
/** @var object The Xylophone framework singleton */
public $XY;

/** @var array Config params */
public $config;
public $config = array();

/** @var object Database object */
public $db = null;

/**
* Constructor
Expand Down
113 changes: 113 additions & 0 deletions tests/Xylophone/core/ModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Xylophone
*
* An open source HMVC application development framework for PHP 5.3 or newer
* Derived from CodeIgniter, Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
*
* NOTICE OF LICENSE
*
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
* through the world wide web, please send an email to licensing@xylophone.io
* so we can send you a copy immediately.
*
* @package Xylophone
* @author Xylophone Dev Team, EllisLab Dev Team
* @copyright Copyright (c) 2014, Xylophone Team (http://xylophone.io/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://xylophone.io
* @since Version 1.0
* @filesource
*/

/**
* Model Unit Test
*
* @package Xylophone
*/
class ModelTest extends XyTestCase
{
/**
* Test __construct()
*/
public function testConstruct()
{
global $XY;

// Mock Xylophone and Model
$XY = (object)array('core' => 'object');
$model = $this->getMock('Xylophone\core\Model', null, array(), '', false);

// Call __construct() and verify result
$model->__construct();
$this->assertSame($XY, $model->XY);
$this->assertEmpty($model->config);
$this->assertEmpty($model->db);
}

/**
* Test __construct() with a config param
*/
public function testConstructConfig()
{
global $XY;

// Set up arg
$config = 'foo';

// Mock Xylophone and Model
$XY = (object)array('core' => 'object');
$model = $this->getMock('Xylophone\core\Model', null, array(), '', false);

// Call __construct() and verify result
$model->__construct($config);
$this->assertSame($XY, $model->XY);
$this->assertEquals(array($config), $model->config);
}

/**
* Test __construct() with a db connection
*/
public function testConstructDb()
{
global $XY;

// Set up args
$db = (object)array();
$config = array('enable' => true, 'db' => $db);

// Mock Xylophone and Model
$XY = new stdClass();
$model = $this->getMock('Xylophone\core\Model', null, array(), '', false);

// Call __construct() and verify result
$model->__construct($config);
$this->assertEquals($config, $model->config);
$this->assertSame($db, $model->db);
}

/**
* Test __get()
*/
public function testGet()
{
// Set up args
$key = 'someobj';
$val = (object)array('mykey' => 'myval');

// Mock Model and Xylophone
$model = $this->getMock('Xylophone\core\Model', null, array(), '', false);
$model->XY = (object)array($key => $val);

// Verify identity and non-existent member
$this->assertSame($val, $model->$key);
$this->assertNull($model->nonexistent);
}
}

0 comments on commit 647f22f

Please sign in to comment.