Skip to content
Permalink
Browse files

Update test case TestSuite folder

  • Loading branch information...
jrbasso committed May 26, 2012
1 parent d2136d2 commit 8ffd67632dd2d1cfa0aecd8caeb8ef28fc39995b
@@ -18,11 +18,16 @@
* @since CakePHP v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Model', 'Model');
App::uses('AppModel', 'Model');
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
namespace Cake\Test\TestCase\TestSuite;
use Cake\TestSuite\TestCase,
Cake\Controller\Controller,
Cake\Model\Model,
Cake\Core\App,
Cake\Core\Configure,
Cake\Core\Plugin,
Cake\Routing\Router,
Cake\Utility\ClassRegistry,
Cake\TestSuite\Reporter\HtmlReporter;
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
@@ -31,60 +36,47 @@
*
* @package Cake.Test.Case.TestSuite
*/
if (!class_exists('AppController', false)) {
class AppController extends Controller {
/**
* AppController class
* helpers property
*
* @package Cake.Test.Case.TestSuite
* @var array
* @access public
*/
class AppController extends Controller {
/**
* helpers property
*
* @var array
* @access public
*/
public $helpers = array('Html');
/**
* uses property
*
* @var array
* @access public
*/
public $uses = array('ControllerPost');
/**
* components property
*
* @var array
* @access public
*/
public $components = array('Cookie');
public $helpers = array('Html');
}
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
define('APP_CONTROLLER_EXISTS', true);
/**
* uses property
*
* @var array
* @access public
*/
public $uses = array('ControllerPost');
/**
* components property
*
* @var array
* @access public
*/
public $components = array('Cookie');
}
/**
* PostsController class
*/
if (!class_exists('PostsController')) {
class PostsController extends AppController {
/**
* Components array
*
* @var array
*/
public $components = array(
'RequestHandler',
'Email',
'Auth'
);
}
class PostsController extends AppController {
/**
* Components array
*
* @var array
*/
public $components = array(
'RequestHandler',
'Auth'
);
}
/**
@@ -106,7 +98,7 @@ class ControllerTestCaseTestController extends AppController {
*
* @package Cake.Test.Case.TestSuite
*/
class ControllerTestCaseTest extends CakeTestCase {
class ControllerTestCaseTest extends TestCase {
/**
* fixtures property
@@ -123,13 +115,15 @@ class ControllerTestCaseTest extends CakeTestCase {
public function setUp() {
parent::setUp();
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS),
'Controller' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Controller' . DS),
'Model' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Model' . DS),
'View' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'View' . DS)
), App::RESET);
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
$this->Case = $this->getMockForAbstractClass('ControllerTestCase');
$this->_ns = Configure::read('App.namespace');
Configure::write('App.namespace', 'TestApp');
Plugin::load(array('TestPlugin', 'TestPluginTwo'));
$this->Case = $this->getMockForAbstractClass('Cake\TestSuite\ControllerTestCase');
Router::reload();
}
@@ -140,7 +134,8 @@ public function setUp() {
*/
public function tearDown() {
parent::tearDown();
CakePlugin::unload();
Configure::write('App.namespace', $this->_ns);
Plugin::unload();
$this->Case->controller = null;
}
@@ -151,7 +146,7 @@ public function testGenerate() {
if (defined('APP_CONTROLLER_EXISTS')) {
$this->markTestSkipped('AppController exists, cannot run.');
}
$Posts = $this->Case->generate('Posts');
$Posts = $this->Case->generate(__NAMESPACE__ . '\PostsController');
$this->assertEquals('Posts', $Posts->name);
$this->assertEquals('Post', $Posts->modelClass);
$this->assertNull($Posts->response->send());
@@ -194,7 +189,6 @@ public function testGenerate() {
'models' => array('Post'),
'components' => array(
'RequestHandler' => array('isPut'),
'Email' => array('send'),
'Session'
)
));
@@ -222,17 +216,17 @@ public function testGenerateWithPlugin() {
)
));
$this->assertEquals('Tests', $Tests->name);
$this->assertInstanceOf('PluginsComponent', $Tests->Plugins);
$this->assertInstanceOf('TestPlugin\Controller\Component\PluginsComponent', $Tests->Plugins);
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
$this->assertInstanceOf('TestPluginComment', $result);
$this->assertInstanceOf('TestPlugin\Model\TestPluginComment', $result);
$Tests = $this->Case->generate('ControllerTestCaseTest', array(
$Tests = $this->Case->generate(__NAMESPACE__ . '\ControllerTestCaseTest', array(
'models' => array(
'TestPlugin.TestPluginComment' => array('save')
)
));
$this->assertInstanceOf('TestPluginComment', $Tests->TestPluginComment);
$this->assertInstanceOf('TestPlugin\Model\TestPluginComment', $Tests->TestPluginComment);
$Tests->TestPluginComment->expects($this->at(0))
->method('save')
->will($this->returnValue(true));
@@ -288,7 +282,7 @@ public function testTestActionWithPlugin() {
*/
public function testUseRoutes() {
Router::connect('/:controller/:action/*');
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
include CAKE . 'Test' . DS . 'TestApp' . DS . 'Config' . DS . 'routes.php';
$controller = $this->Case->generate('TestsApps');
$controller->Components->load('RequestHandler');
@@ -297,19 +291,19 @@ public function testUseRoutes() {
$expected = array('cakephp' => 'cool');
$this->assertEquals($expected, $result);
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
include CAKE . 'Test' . DS . 'TestApp' . DS . 'Config' . DS . 'routes.php';
$result = $this->Case->testAction('/some_alias');
$this->assertEquals(5, $result);
}
/**
* Tests not using loaded routes during tests
*
* @expectedException MissingActionException
* @expectedException Cake\Error\MissingActionException
*/
public function testSkipRoutes() {
Router::connect('/:controller/:action/*');
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
include CAKE . 'Test' . DS . 'TestApp' . DS . 'Config' . DS . 'routes.php';
$this->Case->loadRoutes = false;
$result = $this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
@@ -17,10 +17,14 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('HtmlCoverageReport', 'TestSuite/Coverage');
App::uses('CakeBaseReporter', 'TestSuite/Reporter');
namespace Cake\Test\TestCase\TestSuite;
use Cake\TestSuite\TestCase,
Cake\TestSuite\Coverage\HtmlCoverageReport,
Cake\TestSuite\Reporter\BaseReporter,
Cake\Core\App,
Cake\Core\Plugin;
class HtmlCoverageReportTest extends CakeTestCase {
class HtmlCoverageReportTest extends TestCase {
/**
* setUp
@@ -30,10 +34,10 @@ class HtmlCoverageReportTest extends CakeTestCase {
public function setUp() {
parent::setUp();
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS)
), App::RESET);
CakePlugin::load(array('TestPlugin'));
$reporter = new CakeBaseReporter();
Plugin::load(array('TestPlugin'));
$reporter = new BaseReporter();
$reporter->params = array('app' => false, 'plugin' => false, 'group' => false);
$coverage = array();
$this->Coverage = new HtmlCoverageReport($coverage, $reporter);
@@ -56,7 +60,7 @@ public function testGetPathFilter() {
$this->Coverage->appTest = false;
$this->Coverage->pluginTest = 'TestPlugin';
$result = $this->Coverage->getPathFilter();
$this->assertEquals(CakePlugin::path('TestPlugin'), $result);
$this->assertEquals(Plugin::path('TestPlugin'), $result);
}
/**
@@ -100,16 +104,16 @@ public function testGenerateDiff() {
'line 10',
);
$coverage = array(
1 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
1 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')),
2 => -2,
3 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
4 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
3 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')),
4 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')),
5 => -1,
6 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
7 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
8 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
6 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')),
7 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')),
8 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')),
9 => -1,
10 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff'))
10 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'))
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
@@ -147,16 +151,16 @@ public function testPhpunit36Compatibility() {
'line 10',
);
$coverage = array(
1 => array('HtmlCoverageReportTest::testGenerateDiff'),
1 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
2 => null,
3 => array('HtmlCoverageReportTest::testGenerateDiff'),
4 => array('HtmlCoverageReportTest::testGenerateDiff'),
3 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
4 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
5 => array(),
6 => array('HtmlCoverageReportTest::testGenerateDiff'),
7 => array('HtmlCoverageReportTest::testGenerateDiff'),
8 => array('HtmlCoverageReportTest::testGenerateDiff'),
6 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
7 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
8 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
9 => array(),
10 => array('HtmlCoverageReportTest::testSomething', 'HtmlCoverageReportTest::testGenerateDiff')
10 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testSomething', __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
@@ -191,25 +195,25 @@ public function testCoveredLinesTitleAttributes() {
);
$coverage = array(
1 => array(array('id' => 'HtmlCoverageReportTest::testAwesomeness')),
1 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testAwesomeness')),
2 => -2,
3 => array(array('id' => 'HtmlCoverageReportTest::testCakeIsSuperior')),
4 => array(array('id' => 'HtmlCoverageReportTest::testOther')),
3 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testCakeIsSuperior')),
4 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testOther')),
5 => -1
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertTrue(
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testAwesomeness\n\"><span class=\"line-num\">1") !== false,
strpos($result, "title=\"Covered by:\n" . __NAMESPACE__ . "\HtmlCoverageReportTest::testAwesomeness\n\"><span class=\"line-num\">1") !== false,
'Missing method coverage for line 1'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testCakeIsSuperior\n\"><span class=\"line-num\">3") !== false,
strpos($result, "title=\"Covered by:\n" . __NAMESPACE__ . "\HtmlCoverageReportTest::testCakeIsSuperior\n\"><span class=\"line-num\">3") !== false,
'Missing method coverage for line 3'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testOther\n\"><span class=\"line-num\">4") !== false,
strpos($result, "title=\"Covered by:\n" . __NAMESPACE__ . "\HtmlCoverageReportTest::testOther\n\"><span class=\"line-num\">4") !== false,
'Missing method coverage for line 4'
);
$this->assertTrue(
@@ -224,7 +228,7 @@ public function testCoveredLinesTitleAttributes() {
* @return void
*/
public function tearDown() {
CakePlugin::unload();
Plugin::unload();
unset($this->Coverage);
parent::tearDown();
}
Oops, something went wrong.

0 comments on commit 8ffd676

Please sign in to comment.
You can’t perform that action at this time.