mirror of
https://github.com/brmlab/brmbiolab_sklad.git
synced 2025-10-30 15:04:02 +01:00
Initial commit
This commit is contained in:
commit
3b93da31de
1004 changed files with 265840 additions and 0 deletions
474
lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
Normal file
474
lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
Normal file
|
|
@ -0,0 +1,474 @@
|
|||
<?php
|
||||
/**
|
||||
* CakeTestCaseTest file
|
||||
*
|
||||
* Test Case for CakeTestCase class
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Controller', 'Controller');
|
||||
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
||||
|
||||
/**
|
||||
* CakeTestCaseTest
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeTestCaseTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
|
||||
|
||||
/**
|
||||
* CakeTestCaseTest::setUpBeforeClass()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass() {
|
||||
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
|
||||
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'FixturizedTestCase.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->Result);
|
||||
unset($this->Reporter);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAssertTags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTagsBasic() {
|
||||
$test = new AssertTagsTestCase('testAssertTagsQuotes');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
$this->assertTrue($result->wasSuccessful());
|
||||
$this->assertEquals(0, $result->failureCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTags works with single and double quotes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTagsQuoting() {
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
||||
$pattern = array(
|
||||
'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = "<span><strong>Text</strong></span>";
|
||||
$pattern = array(
|
||||
'<span',
|
||||
'<strong',
|
||||
'Text',
|
||||
'/strong',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = "<span class='active'><strong>Text</strong></span>";
|
||||
$pattern = array(
|
||||
'span' => array('class'),
|
||||
'<strong',
|
||||
'Text',
|
||||
'/strong',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that assertTags runs quickly.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTagsRuntimeComplexity() {
|
||||
$pattern = array(
|
||||
'div' => array(
|
||||
'attr1' => 'val1',
|
||||
'attr2' => 'val2',
|
||||
'attr3' => 'val3',
|
||||
'attr4' => 'val4',
|
||||
'attr5' => 'val5',
|
||||
'attr6' => 'val6',
|
||||
'attr7' => 'val7',
|
||||
'attr8' => 'val8',
|
||||
),
|
||||
'My div',
|
||||
'/div'
|
||||
);
|
||||
$input = '<div attr8="val8" attr6="val6" attr4="val4" attr2="val2"' .
|
||||
' attr1="val1" attr3="val3" attr5="val5" attr7="val7" />' .
|
||||
'My div' .
|
||||
'</div>';
|
||||
$this->assertTags($input, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* testNumericValuesInExpectationForAssertTags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNumericValuesInExpectationForAssertTags() {
|
||||
$test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
$this->assertTrue($result->wasSuccessful());
|
||||
$this->assertEquals(0, $result->failureCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* testBadAssertTags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBadAssertTags() {
|
||||
$test = new AssertTagsTestCase('testBadAssertTags');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
$this->assertFalse($result->wasSuccessful());
|
||||
$this->assertEquals(1, $result->failureCount());
|
||||
|
||||
$test = new AssertTagsTestCase('testBadAssertTags2');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
$this->assertFalse($result->wasSuccessful());
|
||||
$this->assertEquals(1, $result->failureCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* testLoadFixtures
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadFixtures() {
|
||||
$test = new FixturizedTestCase('testFixturePresent');
|
||||
$manager = $this->getMock('CakeFixtureManager');
|
||||
$manager->fixturize($test);
|
||||
$test->fixtureManager = $manager;
|
||||
$manager->expects($this->once())->method('load');
|
||||
$manager->expects($this->once())->method('unload');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
$this->assertTrue($result->wasSuccessful());
|
||||
$this->assertEquals(0, $result->failureCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* testLoadFixturesOnDemand
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadFixturesOnDemand() {
|
||||
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
||||
$test->autoFixtures = false;
|
||||
$manager = $this->getMock('CakeFixtureManager');
|
||||
$manager->fixturize($test);
|
||||
$test->fixtureManager = $manager;
|
||||
$manager->expects($this->once())->method('loadSingle');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* testLoadFixturesOnDemand
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnoadFixturesAfterFailure() {
|
||||
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
||||
$test->autoFixtures = false;
|
||||
$manager = $this->getMock('CakeFixtureManager');
|
||||
$manager->fixturize($test);
|
||||
$test->fixtureManager = $manager;
|
||||
$manager->expects($this->once())->method('loadSingle');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->errorCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* testThrowException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testThrowException() {
|
||||
$test = new FixturizedTestCase('testThrowException');
|
||||
$test->autoFixtures = false;
|
||||
$manager = $this->getMock('CakeFixtureManager');
|
||||
$manager->fixturize($test);
|
||||
$test->fixtureManager = $manager;
|
||||
$manager->expects($this->once())->method('unload');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(1, $result->errorCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* testSkipIf
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSkipIf() {
|
||||
$test = new FixturizedTestCase('testSkipIfTrue');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(1, $result->skippedCount());
|
||||
|
||||
$test = new FixturizedTestCase('testSkipIfFalse');
|
||||
$result = $test->run();
|
||||
$this->assertEquals(0, $result->skippedCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that CakeTestCase::setUp() backs up values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetupBackUpValues() {
|
||||
$this->assertArrayHasKey('debug', $this->_configure);
|
||||
$this->assertArrayHasKey('Plugin', $this->_pathRestore);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextNotEquals()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextNotEquals() {
|
||||
$one = "\r\nOne\rTwooo";
|
||||
$two = "\nOne\nTwo";
|
||||
$this->assertTextNotEquals($one, $two);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextEquals()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextEquals() {
|
||||
$one = "\r\nOne\rTwo";
|
||||
$two = "\nOne\nTwo";
|
||||
$this->assertTextEquals($one, $two);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextStartsWith()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextStartsWith() {
|
||||
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
||||
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
||||
|
||||
$this->assertStringStartsWith("some\nstring", $stringDirty);
|
||||
$this->assertStringStartsNotWith("some\r\nstring\r\nwith", $stringDirty);
|
||||
$this->assertStringStartsNotWith("some\nstring\nwith", $stringDirty);
|
||||
|
||||
$this->assertTextStartsWith("some\nstring\nwith", $stringDirty);
|
||||
$this->assertTextStartsWith("some\r\nstring\r\nwith", $stringDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextStartsNotWith()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextStartsNotWith() {
|
||||
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
||||
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
||||
|
||||
$this->assertTextStartsNotWith("some\nstring\nwithout", $stringDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextEndsWith()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextEndsWith() {
|
||||
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
||||
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
||||
|
||||
$this->assertTextEndsWith("string\nwith\r\ndifferent\rline endings!", $stringDirty);
|
||||
$this->assertTextEndsWith("string\r\nwith\ndifferent\nline endings!", $stringDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextEndsNotWith()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextEndsNotWith() {
|
||||
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
||||
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
||||
|
||||
$this->assertStringEndsNotWith("different\nline endings", $stringDirty);
|
||||
$this->assertTextEndsNotWith("different\rline endings", $stringDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextContains()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextContains() {
|
||||
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
||||
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
||||
|
||||
$this->assertContains("different", $stringDirty);
|
||||
$this->assertNotContains("different\rline", $stringDirty);
|
||||
|
||||
$this->assertTextContains("different\rline", $stringDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
* test assertTextNotContains()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssertTextNotContains() {
|
||||
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
||||
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
||||
|
||||
$this->assertTextNotContains("different\rlines", $stringDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getMockForModel()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMockForModel() {
|
||||
App::build(array(
|
||||
'Model' => array(
|
||||
CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS
|
||||
)
|
||||
), App::RESET);
|
||||
$Post = $this->getMockForModel('Post');
|
||||
|
||||
$this->assertInstanceOf('Post', $Post);
|
||||
$this->assertNull($Post->save(array()));
|
||||
$this->assertNull($Post->find('all'));
|
||||
$this->assertEquals('posts', $Post->useTable);
|
||||
|
||||
$Post = $this->getMockForModel('Post', array('save'));
|
||||
|
||||
$this->assertNull($Post->save(array()));
|
||||
$this->assertInternalType('array', $Post->find('all'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test getMockForModel() with plugin models
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMockForModelWithPlugin() {
|
||||
App::build(array(
|
||||
'Plugin' => array(
|
||||
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
||||
)
|
||||
), App::RESET);
|
||||
CakePlugin::load('TestPlugin');
|
||||
$this->getMockForModel('TestPlugin.TestPluginAppModel');
|
||||
$TestPluginComment = $this->getMockForModel('TestPlugin.TestPluginComment');
|
||||
|
||||
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
|
||||
$this->assertInstanceOf('TestPluginComment', $result);
|
||||
|
||||
$TestPluginComment = $this->getMockForModel('TestPlugin.TestPluginComment', array('save'));
|
||||
|
||||
$this->assertInstanceOf('TestPluginComment', $TestPluginComment);
|
||||
$TestPluginComment->expects($this->at(0))
|
||||
->method('save')
|
||||
->will($this->returnValue(true));
|
||||
$TestPluginComment->expects($this->at(1))
|
||||
->method('save')
|
||||
->will($this->returnValue(false));
|
||||
$this->assertTrue($TestPluginComment->save(array()));
|
||||
$this->assertFalse($TestPluginComment->save(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* testGetMockForModelModel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMockForModelModel() {
|
||||
$Mock = $this->getMockForModel('Model', array('save'), array('name' => 'Comment'));
|
||||
|
||||
$result = ClassRegistry::init('Comment');
|
||||
$this->assertInstanceOf('Model', $result);
|
||||
|
||||
$Mock->expects($this->at(0))
|
||||
->method('save')
|
||||
->will($this->returnValue(true));
|
||||
$Mock->expects($this->at(1))
|
||||
->method('save')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->assertTrue($Mock->save(array()));
|
||||
$this->assertFalse($Mock->save(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* testGetMockForModelDoesNotExist
|
||||
*
|
||||
* @expectedException MissingModelException
|
||||
* @expectedExceptionMessage Model IDoNotExist could not be found
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMockForModelDoesNotExist() {
|
||||
$this->getMockForModel('IDoNotExist');
|
||||
}
|
||||
}
|
||||
574
lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php
Normal file
574
lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php
Normal file
|
|
@ -0,0 +1,574 @@
|
|||
<?php
|
||||
/**
|
||||
* CakeTestFixture file
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
* @since CakePHP(tm) v 1.2.0.4667
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('DboSource', 'Model/Datasource');
|
||||
App::uses('Model', 'Model');
|
||||
App::uses('CakeTestFixture', 'TestSuite/Fixture');
|
||||
|
||||
/**
|
||||
* CakeTestFixtureTestFixture class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeTestFixtureTestFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* Name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'FixtureTest';
|
||||
|
||||
/**
|
||||
* Table property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $table = 'fixture_tests';
|
||||
|
||||
/**
|
||||
* Fields array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => '255'),
|
||||
'created' => array('type' => 'datetime')
|
||||
);
|
||||
|
||||
/**
|
||||
* Records property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $records = array(
|
||||
array('name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'),
|
||||
array('name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'),
|
||||
array('name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* StringTestFixture class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class StringsTestFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* Name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Strings';
|
||||
|
||||
/**
|
||||
* Table property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $table = 'strings';
|
||||
|
||||
/**
|
||||
* Fields array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => '255'),
|
||||
'email' => array('type' => 'string', 'length' => '255'),
|
||||
'age' => array('type' => 'integer', 'default' => 10)
|
||||
);
|
||||
|
||||
/**
|
||||
* Records property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $records = array(
|
||||
array('name' => 'Mark Doe', 'email' => 'mark.doe@email.com'),
|
||||
array('name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20),
|
||||
array('email' => 'jane.doe@email.com', 'name' => 'Jane Doe', 'age' => 30)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* InvalidTestFixture class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class InvalidTestFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* Name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Invalid';
|
||||
|
||||
/**
|
||||
* Table property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $table = 'invalid';
|
||||
|
||||
/**
|
||||
* Fields array - missing "email" row
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => '255'),
|
||||
'age' => array('type' => 'integer', 'default' => 10)
|
||||
);
|
||||
|
||||
/**
|
||||
* Records property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $records = array(
|
||||
array('name' => 'Mark Doe', 'email' => 'mark.doe@email.com'),
|
||||
array('name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20),
|
||||
array('email' => 'jane.doe@email.com', 'name' => 'Jane Doe', 'age' => 30)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* CakeTestFixtureImportFixture class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeTestFixtureImportFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* Name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'ImportFixture';
|
||||
|
||||
/**
|
||||
* Import property
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $import = array('table' => 'fixture_tests', 'connection' => 'fixture_test_suite');
|
||||
}
|
||||
|
||||
/**
|
||||
* CakeTestFixtureDefaultImportFixture class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeTestFixtureDefaultImportFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* Name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'ImportFixture';
|
||||
}
|
||||
|
||||
/**
|
||||
* FixtureImportTestModel class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class FixtureImportTestModel extends Model {
|
||||
|
||||
public $name = 'FixtureImport';
|
||||
|
||||
public $useTable = 'fixture_tests';
|
||||
|
||||
public $useDbConfig = 'test';
|
||||
|
||||
}
|
||||
|
||||
class FixturePrefixTest extends Model {
|
||||
|
||||
public $name = 'FixturePrefix';
|
||||
|
||||
public $useTable = '_tests';
|
||||
|
||||
public $tablePrefix = 'fixture';
|
||||
|
||||
public $useDbConfig = 'test';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for CakeTestFixture
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeTestFixtureTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$methods = array_diff(get_class_methods('DboSource'), array('enabled'));
|
||||
$methods[] = 'connect';
|
||||
|
||||
$this->criticDb = $this->getMock('DboSource', $methods);
|
||||
$this->criticDb->fullDebug = true;
|
||||
$this->db = ConnectionManager::getDataSource('test');
|
||||
$this->_backupConfig = $this->db->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->criticDb);
|
||||
$this->db->config = $this->_backupConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* testInit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInit() {
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
unset($Fixture->table);
|
||||
$Fixture->init();
|
||||
$this->assertEquals('fixture_tests', $Fixture->table);
|
||||
$this->assertEquals('id', $Fixture->primaryKey);
|
||||
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
$Fixture->primaryKey = 'my_random_key';
|
||||
$Fixture->init();
|
||||
$this->assertEquals('my_random_key', $Fixture->primaryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that init() correctly sets the fixture table when the connection
|
||||
* or model have prefixes defined.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitDbPrefix() {
|
||||
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
|
||||
$db = ConnectionManager::getDataSource('test');
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->drop($db);
|
||||
$Source->create($db);
|
||||
$Source->insert($db);
|
||||
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
$expected = array('id', 'name', 'created');
|
||||
$this->assertEquals($expected, array_keys($Fixture->fields));
|
||||
|
||||
$config = $db->config;
|
||||
$config['prefix'] = 'fixture_test_suite_';
|
||||
ConnectionManager::create('fixture_test_suite', $config);
|
||||
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test', 'records' => true);
|
||||
$Fixture->init();
|
||||
$this->assertEquals(count($Fixture->records), count($Source->records));
|
||||
$Fixture->create(ConnectionManager::getDataSource('fixture_test_suite'));
|
||||
|
||||
$Fixture = new CakeTestFixtureImportFixture();
|
||||
$Fixture->fields = $Fixture->records = $Fixture->table = null;
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
|
||||
$Fixture->init();
|
||||
$this->assertEquals(array('id', 'name', 'created'), array_keys($Fixture->fields));
|
||||
$this->assertEquals('fixture_tests', $Fixture->table);
|
||||
|
||||
$keys = array_flip(ClassRegistry::keys());
|
||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||
|
||||
$Fixture->drop(ConnectionManager::getDataSource('fixture_test_suite'));
|
||||
$Source->drop($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that fixtures don't duplicate the test db prefix.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitDbPrefixDuplication() {
|
||||
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
|
||||
$db = ConnectionManager::getDataSource('test');
|
||||
$backPrefix = $db->config['prefix'];
|
||||
$db->config['prefix'] = 'cake_fixture_test_';
|
||||
ConnectionManager::create('fixture_test_suite', $db->config);
|
||||
$newDb = ConnectionManager::getDataSource('fixture_test_suite');
|
||||
$newDb->config['prefix'] = 'cake_fixture_test_';
|
||||
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($db);
|
||||
$Source->insert($db);
|
||||
|
||||
$Fixture = new CakeTestFixtureImportFixture();
|
||||
$Fixture->fields = $Fixture->records = $Fixture->table = null;
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
|
||||
|
||||
$Fixture->init();
|
||||
$this->assertEquals(array('id', 'name', 'created'), array_keys($Fixture->fields));
|
||||
$this->assertEquals('fixture_tests', $Fixture->table);
|
||||
|
||||
$Source->drop($db);
|
||||
$db->config['prefix'] = $backPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* test init with a model that has a tablePrefix declared.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitModelTablePrefix() {
|
||||
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
|
||||
$this->skipIf(!empty($this->db->config['prefix']), 'Cannot run this test, you have a database connection prefix.');
|
||||
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($this->db);
|
||||
$Source->insert($this->db);
|
||||
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
unset($Fixture->table);
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test', 'records' => false);
|
||||
$Fixture->init();
|
||||
$this->assertEquals('fixture_tests', $Fixture->table);
|
||||
|
||||
$keys = array_flip(ClassRegistry::keys());
|
||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||
|
||||
$Source->drop($this->db);
|
||||
}
|
||||
|
||||
/**
|
||||
* testImport
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testImport() {
|
||||
$testSuiteDb = ConnectionManager::getDataSource('test');
|
||||
$testSuiteConfig = $testSuiteDb->config;
|
||||
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
|
||||
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($newTestSuiteDb);
|
||||
$Source->insert($newTestSuiteDb);
|
||||
|
||||
$Fixture = new CakeTestFixtureDefaultImportFixture();
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
|
||||
$Fixture->init();
|
||||
$this->assertEquals(array('id', 'name', 'created'), array_keys($Fixture->fields));
|
||||
|
||||
$keys = array_flip(ClassRegistry::keys());
|
||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||
|
||||
$Source->drop($newTestSuiteDb);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that importing with records works. Make sure to try with postgres as its
|
||||
* handling of aliases is a workaround at best.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testImportWithRecords() {
|
||||
$testSuiteDb = ConnectionManager::getDataSource('test');
|
||||
$testSuiteConfig = $testSuiteDb->config;
|
||||
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
|
||||
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($newTestSuiteDb);
|
||||
$Source->insert($newTestSuiteDb);
|
||||
|
||||
$Fixture = new CakeTestFixtureDefaultImportFixture();
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array(
|
||||
'model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite', 'records' => true
|
||||
);
|
||||
$Fixture->init();
|
||||
$this->assertEquals(array('id', 'name', 'created'), array_keys($Fixture->fields));
|
||||
$this->assertFalse(empty($Fixture->records[0]), 'No records loaded on importing fixture.');
|
||||
$this->assertTrue(isset($Fixture->records[0]['name']), 'No name loaded for first record');
|
||||
|
||||
$Source->drop($newTestSuiteDb);
|
||||
}
|
||||
|
||||
/**
|
||||
* test create method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreate() {
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
$this->criticDb->expects($this->atLeastOnce())->method('execute');
|
||||
$this->criticDb->expects($this->atLeastOnce())->method('createSchema');
|
||||
$return = $Fixture->create($this->criticDb);
|
||||
$this->assertTrue($this->criticDb->fullDebug);
|
||||
$this->assertTrue($return);
|
||||
|
||||
unset($Fixture->fields);
|
||||
$return = $Fixture->create($this->criticDb);
|
||||
$this->assertFalse($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the insert method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInsert() {
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
$this->criticDb->expects($this->atLeastOnce())
|
||||
->method('insertMulti')
|
||||
->will($this->returnCallback(array($this, 'insertCallback')));
|
||||
|
||||
$return = $Fixture->insert($this->criticDb);
|
||||
$this->assertTrue(!empty($this->insertMulti));
|
||||
$this->assertTrue($this->criticDb->fullDebug);
|
||||
$this->assertTrue($return);
|
||||
$this->assertEquals('fixture_tests', $this->insertMulti['table']);
|
||||
$this->assertEquals(array('name', 'created'), $this->insertMulti['fields']);
|
||||
$expected = array(
|
||||
array('Gandalf', '2009-04-28 19:20:00'),
|
||||
array('Captain Picard', '2009-04-28 19:20:00'),
|
||||
array('Chewbacca', '2009-04-28 19:20:00')
|
||||
);
|
||||
$this->assertEquals($expected, $this->insertMulti['values']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to be used as callback and store the parameters of an insertMulti call
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param string $values
|
||||
* @return bool true
|
||||
*/
|
||||
public function insertCallback($table, $fields, $values) {
|
||||
$this->insertMulti['table'] = $table;
|
||||
$this->insertMulti['fields'] = $fields;
|
||||
$this->insertMulti['values'] = $values;
|
||||
$this->insertMulti['fields_values'] = array();
|
||||
foreach ($values as $record) {
|
||||
$this->insertMulti['fields_values'][] = array_combine($fields, $record);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* test the insert method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInsertStrings() {
|
||||
$Fixture = new StringsTestFixture();
|
||||
$this->criticDb->expects($this->atLeastOnce())
|
||||
->method('insertMulti')
|
||||
->will($this->returnCallback(array($this, 'insertCallback')));
|
||||
|
||||
$return = $Fixture->insert($this->criticDb);
|
||||
$this->assertTrue($this->criticDb->fullDebug);
|
||||
$this->assertTrue($return);
|
||||
$this->assertEquals('strings', $this->insertMulti['table']);
|
||||
$this->assertEquals(array('name', 'email', 'age'), array_values($this->insertMulti['fields']));
|
||||
$expected = array(
|
||||
array('Mark Doe', 'mark.doe@email.com', null),
|
||||
array('John Doe', 'john.doe@email.com', 20),
|
||||
array('Jane Doe', 'jane.doe@email.com', 30),
|
||||
);
|
||||
$this->assertEquals($expected, $this->insertMulti['values']);
|
||||
$expected = array(
|
||||
array(
|
||||
'name' => 'Mark Doe',
|
||||
'email' => 'mark.doe@email.com',
|
||||
'age' => null
|
||||
),
|
||||
array(
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john.doe@email.com',
|
||||
'age' => 20
|
||||
),
|
||||
array(
|
||||
'name' => 'Jane Doe',
|
||||
'email' => 'jane.doe@email.com',
|
||||
'age' => 30
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $this->insertMulti['fields_values']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the insert method with invalid fixture
|
||||
*
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
public function testInsertInvalid() {
|
||||
$Fixture = new InvalidTestFixture();
|
||||
$return = $Fixture->insert($this->criticDb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the drop method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDrop() {
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
$this->criticDb->expects($this->at(1))->method('execute')->will($this->returnValue(true));
|
||||
$this->criticDb->expects($this->at(3))->method('execute')->will($this->returnValue(false));
|
||||
$this->criticDb->expects($this->exactly(2))->method('dropSchema');
|
||||
|
||||
$return = $Fixture->drop($this->criticDb);
|
||||
$this->assertTrue($this->criticDb->fullDebug);
|
||||
$this->assertTrue($return);
|
||||
|
||||
$return = $Fixture->drop($this->criticDb);
|
||||
$this->assertTrue($return);
|
||||
|
||||
unset($Fixture->fields);
|
||||
$return = $Fixture->drop($this->criticDb);
|
||||
$this->assertFalse($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the truncate method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTruncate() {
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
$this->criticDb->expects($this->atLeastOnce())->method('truncate');
|
||||
$Fixture->truncate($this->criticDb);
|
||||
$this->assertTrue($this->criticDb->fullDebug);
|
||||
}
|
||||
}
|
||||
105
lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
Normal file
105
lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* CakeTestSuiteTest
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeTestSuiteTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* testAddTestDirectory
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddTestDirectory() {
|
||||
$testFolder = CORE_TEST_CASES . DS . 'TestSuite';
|
||||
$count = count(glob($testFolder . DS . '*Test.php'));
|
||||
|
||||
$suite = $this->getMock('CakeTestSuite', array('addTestFile'));
|
||||
$suite
|
||||
->expects($this->exactly($count))
|
||||
->method('addTestFile');
|
||||
|
||||
$suite->addTestDirectory($testFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAddTestDirectoryRecursive
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddTestDirectoryRecursive() {
|
||||
$testFolder = CORE_TEST_CASES . DS . 'Cache';
|
||||
$count = count(glob($testFolder . DS . '*Test.php'));
|
||||
$count += count(glob($testFolder . DS . 'Engine' . DS . '*Test.php'));
|
||||
|
||||
$suite = $this->getMock('CakeTestSuite', array('addTestFile'));
|
||||
$suite
|
||||
->expects($this->exactly($count))
|
||||
->method('addTestFile');
|
||||
|
||||
$suite->addTestDirectoryRecursive($testFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAddTestDirectoryRecursiveWithHidden
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddTestDirectoryRecursiveWithHidden() {
|
||||
$this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
|
||||
|
||||
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
|
||||
mkdir($Folder->path . DS . '.svn', 0777, true);
|
||||
touch($Folder->path . DS . '.svn' . DS . 'InHiddenFolderTest.php');
|
||||
touch($Folder->path . DS . 'NotHiddenTest.php');
|
||||
touch($Folder->path . DS . '.HiddenTest.php');
|
||||
|
||||
$suite = $this->getMock('CakeTestSuite', array('addTestFile'));
|
||||
$suite
|
||||
->expects($this->exactly(1))
|
||||
->method('addTestFile');
|
||||
|
||||
$suite->addTestDirectoryRecursive($Folder->pwd());
|
||||
|
||||
$Folder->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* testAddTestDirectoryRecursiveWithNonPhp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddTestDirectoryRecursiveWithNonPhp() {
|
||||
$this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
|
||||
|
||||
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
|
||||
touch($Folder->path . DS . 'BackupTest.php~');
|
||||
touch($Folder->path . DS . 'SomeNotesTest.txt');
|
||||
touch($Folder->path . DS . 'NotHiddenTest.php');
|
||||
|
||||
$suite = $this->getMock('CakeTestSuite', array('addTestFile'));
|
||||
$suite
|
||||
->expects($this->exactly(1))
|
||||
->method('addTestFile');
|
||||
|
||||
$suite->addTestDirectoryRecursive($Folder->pwd());
|
||||
|
||||
$Folder->delete();
|
||||
}
|
||||
}
|
||||
604
lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
Normal file
604
lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
Normal file
|
|
@ -0,0 +1,604 @@
|
|||
<?php
|
||||
/**
|
||||
* ControllerTestCaseTest file
|
||||
*
|
||||
* Test Case for ControllerTestCase class
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
* @since CakePHP v 2.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Controller', 'Controller');
|
||||
App::uses('Model', 'Model');
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
||||
|
||||
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
|
||||
|
||||
if (!class_exists('AppController', false)) {
|
||||
/**
|
||||
* AppController class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class AppController extends Controller {
|
||||
|
||||
/**
|
||||
* helpers property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $uses = array('ControllerPost');
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('Cookie');
|
||||
|
||||
}
|
||||
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
|
||||
define('APP_CONTROLLER_EXISTS', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* PostsController class
|
||||
*/
|
||||
if (!class_exists('PostsController')) {
|
||||
|
||||
/**
|
||||
* Class PostsController
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class PostsController extends AppController {
|
||||
|
||||
/**
|
||||
* Components array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array(
|
||||
'RequestHandler',
|
||||
'Email',
|
||||
'Auth'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ControllerTestCaseTest controller
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class ControllerTestCaseTestController extends AppController {
|
||||
|
||||
/**
|
||||
* Uses array
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
public $uses = array('TestPlugin.TestPluginComment');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* ControllerTestCaseTest
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class ControllerTestCaseTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
|
||||
|
||||
/**
|
||||
* reset environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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)
|
||||
), App::RESET);
|
||||
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
|
||||
$this->Case = $this->getMockForAbstractClass('ControllerTestCase');
|
||||
Router::reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
CakePlugin::unload();
|
||||
$this->Case->controller = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that ControllerTestCase::generate() creates mock objects correctly
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerate() {
|
||||
if (defined('APP_CONTROLLER_EXISTS')) {
|
||||
$this->markTestSkipped('AppController exists, cannot run.');
|
||||
}
|
||||
$Posts = $this->Case->generate('Posts');
|
||||
$this->assertEquals('Posts', $Posts->name);
|
||||
$this->assertEquals('Post', $Posts->modelClass);
|
||||
$this->assertNull($Posts->response->send());
|
||||
|
||||
$Posts = $this->Case->generate('Posts', array(
|
||||
'methods' => array(
|
||||
'render'
|
||||
)
|
||||
));
|
||||
$this->assertNull($Posts->render('index'));
|
||||
|
||||
$Posts = $this->Case->generate('Posts', array(
|
||||
'models' => array('Post'),
|
||||
'components' => array('RequestHandler')
|
||||
));
|
||||
|
||||
$this->assertInstanceOf('Post', $Posts->Post);
|
||||
$this->assertNull($Posts->Post->save(array()));
|
||||
$this->assertNull($Posts->Post->find('all'));
|
||||
$this->assertEquals('posts', $Posts->Post->useTable);
|
||||
$this->assertNull($Posts->RequestHandler->isAjax());
|
||||
|
||||
$Posts = $this->Case->generate('Posts', array(
|
||||
'models' => array(
|
||||
'Post' => true
|
||||
)
|
||||
));
|
||||
$this->assertNull($Posts->Post->save(array()));
|
||||
$this->assertNull($Posts->Post->find('all'));
|
||||
|
||||
$Posts = $this->Case->generate('Posts', array(
|
||||
'models' => array(
|
||||
'Post' => array('save'),
|
||||
)
|
||||
));
|
||||
$this->assertNull($Posts->Post->save(array()));
|
||||
$this->assertInternalType('array', $Posts->Post->find('all'));
|
||||
|
||||
$Posts = $this->Case->generate('Posts', array(
|
||||
'models' => array('Post'),
|
||||
'components' => array(
|
||||
'RequestHandler' => array('isPut'),
|
||||
'Email' => array('send'),
|
||||
'Session'
|
||||
)
|
||||
));
|
||||
$Posts->RequestHandler->expects($this->once())
|
||||
->method('isPut')
|
||||
->will($this->returnValue(true));
|
||||
$this->assertTrue($Posts->RequestHandler->isPut());
|
||||
|
||||
$Posts->Auth->Session->expects($this->any())
|
||||
->method('write')
|
||||
->will($this->returnValue('written!'));
|
||||
$this->assertEquals('written!', $Posts->Auth->Session->write('something'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testGenerateWithComponentConfig
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateWithComponentConfig() {
|
||||
$Tests = $this->Case->generate('TestConfigs', array(
|
||||
));
|
||||
|
||||
$expected = array('some' => 'config');
|
||||
$settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo'));
|
||||
$this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component');
|
||||
|
||||
$Tests = $this->Case->generate('TestConfigs', array(
|
||||
'components' => array(
|
||||
'RequestHandler' => array('isPut')
|
||||
)
|
||||
));
|
||||
|
||||
$expected = array('some' => 'config');
|
||||
$settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo'));
|
||||
$this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ControllerTestCase::generate() using classes from plugins
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateWithPlugin() {
|
||||
$Tests = $this->Case->generate('TestPlugin.Tests', array(
|
||||
'models' => array(
|
||||
'TestPlugin.TestPluginComment'
|
||||
),
|
||||
'components' => array(
|
||||
'TestPlugin.Plugins'
|
||||
)
|
||||
));
|
||||
$this->assertEquals('Tests', $Tests->name);
|
||||
$this->assertInstanceOf('PluginsComponent', $Tests->Plugins);
|
||||
|
||||
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
|
||||
$this->assertInstanceOf('TestPluginComment', $result);
|
||||
|
||||
$Tests = $this->Case->generate('ControllerTestCaseTest', array(
|
||||
'models' => array(
|
||||
'TestPlugin.TestPluginComment' => array('save')
|
||||
)
|
||||
));
|
||||
$this->assertInstanceOf('TestPluginComment', $Tests->TestPluginComment);
|
||||
$Tests->TestPluginComment->expects($this->at(0))
|
||||
->method('save')
|
||||
->will($this->returnValue(true));
|
||||
$Tests->TestPluginComment->expects($this->at(1))
|
||||
->method('save')
|
||||
->will($this->returnValue(false));
|
||||
$this->assertTrue($Tests->TestPluginComment->save(array()));
|
||||
$this->assertFalse($Tests->TestPluginComment->save(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests testAction
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestAction() {
|
||||
$Controller = $this->Case->generate('TestsApps');
|
||||
$this->Case->testAction('/tests_apps/index');
|
||||
$this->assertInternalType('array', $this->Case->controller->viewVars);
|
||||
|
||||
$this->Case->testAction('/tests_apps/set_action');
|
||||
$results = $this->Case->controller->viewVars;
|
||||
$expected = array(
|
||||
'var' => 'string'
|
||||
);
|
||||
$this->assertEquals($expected, $results);
|
||||
|
||||
$result = $this->Case->controller->response->body();
|
||||
$this->assertRegExp('/This is the TestsAppsController index view/', $result);
|
||||
|
||||
$Controller = $this->Case->generate('TestsApps');
|
||||
$this->Case->testAction('/tests_apps/redirect_to');
|
||||
$results = $this->Case->headers;
|
||||
$expected = array(
|
||||
'Location' => 'http://cakephp.org'
|
||||
);
|
||||
$this->assertEquals($expected, $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure testAction() can hit plugin controllers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestActionWithPlugin() {
|
||||
$this->Case->generate('TestPlugin.Tests');
|
||||
$this->Case->testAction('/test_plugin/tests/index');
|
||||
$this->assertEquals('It is a variable', $this->Case->controller->viewVars['test_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests using loaded routes during tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUseRoutes() {
|
||||
Router::connect('/:controller/:action/*');
|
||||
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
|
||||
|
||||
$controller = $this->Case->generate('TestsApps');
|
||||
$controller->Components->load('RequestHandler');
|
||||
$result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'contents'));
|
||||
$result = json_decode($result, true);
|
||||
$expected = array('cakephp' => 'cool');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
|
||||
$result = $this->Case->testAction('/some_alias');
|
||||
$this->assertEquals(5, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests not using loaded routes during tests
|
||||
*
|
||||
* @expectedException MissingActionException
|
||||
* @return void
|
||||
*/
|
||||
public function testSkipRoutes() {
|
||||
Router::connect('/:controller/:action/*');
|
||||
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
|
||||
|
||||
$this->Case->loadRoutes = false;
|
||||
$this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests backwards compatibility with setting the return type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBCSetReturn() {
|
||||
$this->Case->autoMock = true;
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/some_method');
|
||||
$this->assertEquals(5, $result);
|
||||
|
||||
$data = array('var' => 'set');
|
||||
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
||||
'data' => $data,
|
||||
'return' => 'vars'
|
||||
));
|
||||
$this->assertEquals($data, $result['data']);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
||||
'return' => 'view'
|
||||
));
|
||||
$this->assertEquals('This is the TestsAppsController index view string', $result);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
||||
'return' => 'contents'
|
||||
));
|
||||
$this->assertRegExp('/<html/', $result);
|
||||
$this->assertRegExp('/This is the TestsAppsController index view/', $result);
|
||||
$this->assertRegExp('/<\/html>/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sending POST data to testAction
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestActionPostData() {
|
||||
$this->Case->autoMock = true;
|
||||
|
||||
$data = array(
|
||||
'Post' => array(
|
||||
'name' => 'Some Post'
|
||||
)
|
||||
);
|
||||
$this->Case->testAction('/tests_apps_posts/post_var', array(
|
||||
'data' => $data
|
||||
));
|
||||
$this->assertEquals($this->Case->controller->viewVars['data'], $data);
|
||||
$this->assertEquals($this->Case->controller->data, $data);
|
||||
|
||||
$this->Case->testAction('/tests_apps_posts/post_var/named:param', array(
|
||||
'data' => $data
|
||||
));
|
||||
$expected = array(
|
||||
'named' => 'param'
|
||||
);
|
||||
$this->assertEquals($expected, $this->Case->controller->request->named);
|
||||
$this->assertEquals($this->Case->controller->data, $data);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
||||
'return' => 'vars',
|
||||
'method' => 'post',
|
||||
'data' => array(
|
||||
'name' => 'is jonas',
|
||||
'pork' => 'and beans',
|
||||
)
|
||||
));
|
||||
$this->assertEquals(array('name', 'pork'), array_keys($result['data']));
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
|
||||
$this->assertTrue(array_key_exists('posts', $result));
|
||||
$this->assertEquals(4, count($result['posts']));
|
||||
$this->assertTrue($this->Case->controller->request->is('post'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sending GET data to testAction
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestActionGetData() {
|
||||
$this->Case->autoMock = true;
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
|
||||
'method' => 'get',
|
||||
'data' => array(
|
||||
'some' => 'var',
|
||||
'lackof' => 'creativity'
|
||||
)
|
||||
));
|
||||
$this->assertEquals('var', $this->Case->controller->request->query['some']);
|
||||
$this->assertEquals('creativity', $this->Case->controller->request->query['lackof']);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/url_var/var1:value1/var2:val2', array(
|
||||
'return' => 'vars',
|
||||
'method' => 'get',
|
||||
));
|
||||
$this->assertEquals(array('var1', 'var2'), array_keys($result['params']['named']));
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array(
|
||||
'return' => 'vars',
|
||||
'method' => 'get',
|
||||
));
|
||||
$this->assertEquals(array('gogo', 'val2'), $result['params']['pass']);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
|
||||
'return' => 'vars',
|
||||
'method' => 'get',
|
||||
'data' => array(
|
||||
'red' => 'health',
|
||||
'blue' => 'mana'
|
||||
)
|
||||
));
|
||||
$query = $this->Case->controller->request->query;
|
||||
$this->assertTrue(isset($query['red']));
|
||||
$this->assertTrue(isset($query['blue']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that REST actions with XML/JSON input work.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestActionJsonData() {
|
||||
$result = $this->Case->testAction('/tests_apps_posts/input_data', array(
|
||||
'return' => 'vars',
|
||||
'method' => 'post',
|
||||
'data' => '{"key":"value","json":true}'
|
||||
));
|
||||
$this->assertEquals('value', $result['data']['key']);
|
||||
$this->assertTrue($result['data']['json']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests autoMock ability
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoMock() {
|
||||
$this->Case->autoMock = true;
|
||||
$this->Case->testAction('/tests_apps/set_action');
|
||||
$results = $this->Case->controller->viewVars;
|
||||
$expected = array(
|
||||
'var' => 'string'
|
||||
);
|
||||
$this->assertEquals($expected, $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using testAction and not mocking
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNoMocking() {
|
||||
$result = $this->Case->testAction('/tests_apps/some_method');
|
||||
$this->Case->assertEquals(5, $result);
|
||||
|
||||
$data = array('var' => 'set');
|
||||
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
||||
'data' => $data,
|
||||
'return' => 'vars'
|
||||
));
|
||||
$this->assertEquals($data, $result['data']);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
||||
'return' => 'view'
|
||||
));
|
||||
$this->assertEquals('This is the TestsAppsController index view string', $result);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
||||
'return' => 'contents'
|
||||
));
|
||||
$this->assertRegExp('/<html/', $result);
|
||||
$this->assertRegExp('/This is the TestsAppsController index view/', $result);
|
||||
$this->assertRegExp('/<\/html>/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that controllers don't get reused.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNoControllerReuse() {
|
||||
$this->Case->autoMock = true;
|
||||
$result = $this->Case->testAction('/tests_apps/index', array(
|
||||
'data' => array('var' => 'first call'),
|
||||
'method' => 'get',
|
||||
'return' => 'contents',
|
||||
));
|
||||
$this->assertContains('<html', $result);
|
||||
$this->assertContains('This is the TestsAppsController index view', $result);
|
||||
$this->assertContains('first call', $result);
|
||||
$this->assertContains('</html>', $result);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/index', array(
|
||||
'data' => array('var' => 'second call'),
|
||||
'method' => 'get',
|
||||
'return' => 'contents'
|
||||
));
|
||||
$this->assertContains('second call', $result);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps/index', array(
|
||||
'data' => array('var' => 'third call'),
|
||||
'method' => 'get',
|
||||
'return' => 'contents'
|
||||
));
|
||||
$this->assertContains('third call', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple calls to redirect in the same test method don't cause issues.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestActionWithMultipleRedirect() {
|
||||
$this->Case->generate('TestsApps');
|
||||
|
||||
$options = array('method' => 'get');
|
||||
$this->Case->testAction('/tests_apps/redirect_to', $options);
|
||||
$this->Case->testAction('/tests_apps/redirect_to', $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that Components storing response or request objects internally during construct
|
||||
* will always have a fresh reference to those object available
|
||||
*
|
||||
* @return void
|
||||
* @see https://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2705-requesthandler-weird-behavior
|
||||
*/
|
||||
public function testComponentsSameRequestAndResponse() {
|
||||
$this->Case->generate('TestsApps');
|
||||
$options = array('method' => 'get');
|
||||
$this->Case->testAction('/tests_apps/index', $options);
|
||||
$this->assertSame($this->Case->controller->response, $this->Case->controller->RequestHandler->response);
|
||||
$this->assertSame($this->Case->controller->request, $this->Case->controller->RequestHandler->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that testAction() doesn't destroy data in GET & POST
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRestoreGetPost() {
|
||||
$restored = array('new' => 'value');
|
||||
|
||||
$_GET = $restored;
|
||||
$_POST = $restored;
|
||||
|
||||
$this->Case->generate('TestsApps');
|
||||
$options = array('method' => 'get');
|
||||
$this->Case->testAction('/tests_apps/index', $options);
|
||||
|
||||
$this->assertEquals($restored, $_GET);
|
||||
$this->assertEquals($restored, $_POST);
|
||||
}
|
||||
|
||||
}
|
||||
103
lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php
Normal file
103
lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/**
|
||||
* CakeFixtureManager file
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Test.Case.TestSuite.Fixture
|
||||
* @since CakePHP v 2.5
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('DboSource', 'Model/Datasource');
|
||||
App::uses('CakeFixtureManager', 'TestSuite/Fixture');
|
||||
App::uses('UuidFixture', 'Test/Fixture');
|
||||
|
||||
/**
|
||||
* Test Case for CakeFixtureManager class
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class CakeFixtureManagerTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* reset environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->fixtureManager = new CakeFixtureManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->fixtureManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* testLoadTruncatesTable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadTruncatesTable() {
|
||||
$MockFixture = $this->getMock('UuidFixture', array('truncate'));
|
||||
$MockFixture
|
||||
->expects($this->once())
|
||||
->method('truncate')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$fixtureManager = $this->fixtureManager;
|
||||
$fixtureManagerReflection = new ReflectionClass($fixtureManager);
|
||||
|
||||
$loadedProperty = $fixtureManagerReflection->getProperty('_loaded');
|
||||
$loadedProperty->setAccessible(true);
|
||||
$loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture));
|
||||
|
||||
$TestCase = $this->getMock('CakeTestCase');
|
||||
$TestCase->fixtures = array('core.uuid');
|
||||
$TestCase->autoFixtures = true;
|
||||
$TestCase->dropTables = false;
|
||||
|
||||
$fixtureManager->load($TestCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* testLoadSingleTruncatesTable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadSingleTruncatesTable() {
|
||||
$MockFixture = $this->getMock('UuidFixture', array('truncate'));
|
||||
$MockFixture
|
||||
->expects($this->once())
|
||||
->method('truncate')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$fixtureManager = $this->fixtureManager;
|
||||
$fixtureManagerReflection = new ReflectionClass($fixtureManager);
|
||||
|
||||
$fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap');
|
||||
$fixtureMapProperty->setAccessible(true);
|
||||
$fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture));
|
||||
|
||||
$dboMethods = array_diff(get_class_methods('DboSource'), array('enabled'));
|
||||
$dboMethods[] = 'connect';
|
||||
$db = $this->getMock('DboSource', $dboMethods);
|
||||
$db->config['prefix'] = '';
|
||||
|
||||
$fixtureManager->loadSingle('Uuid', $db, false);
|
||||
}
|
||||
}
|
||||
237
lib/Cake/Test/Case/TestSuite/HtmlCoverageReportTest.php
Normal file
237
lib/Cake/Test/Case/TestSuite/HtmlCoverageReportTest.php
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
<?php
|
||||
/**
|
||||
* Test case for HtmlCoverageReport
|
||||
*
|
||||
* PHP5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('HtmlCoverageReport', 'TestSuite/Coverage');
|
||||
App::uses('CakeBaseReporter', 'TestSuite/Reporter');
|
||||
|
||||
/**
|
||||
* Class HtmlCoverageReportTest
|
||||
*
|
||||
* @package Cake.Test.Case.TestSuite
|
||||
*/
|
||||
class HtmlCoverageReportTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
App::build(array(
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
), App::RESET);
|
||||
CakePlugin::load(array('TestPlugin'));
|
||||
$reporter = new CakeBaseReporter();
|
||||
$reporter->params = array('app' => false, 'plugin' => false, 'group' => false);
|
||||
$coverage = array();
|
||||
$this->Coverage = new HtmlCoverageReport($coverage, $reporter);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting the path filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPathFilter() {
|
||||
$this->Coverage->appTest = false;
|
||||
$result = $this->Coverage->getPathFilter();
|
||||
$this->assertEquals(CAKE, $result);
|
||||
|
||||
$this->Coverage->appTest = true;
|
||||
$result = $this->Coverage->getPathFilter();
|
||||
$this->assertEquals(ROOT . DS . APP_DIR . DS, $result);
|
||||
|
||||
$this->Coverage->appTest = false;
|
||||
$this->Coverage->pluginTest = 'TestPlugin';
|
||||
$result = $this->Coverage->getPathFilter();
|
||||
$this->assertEquals(CakePlugin::path('TestPlugin'), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test filtering coverage data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFilterCoverageDataByPathRemovingElements() {
|
||||
$data = array(
|
||||
CAKE . 'dispatcher.php' => array(
|
||||
10 => -1,
|
||||
12 => 1
|
||||
),
|
||||
APP . 'app_model.php' => array(
|
||||
50 => 1,
|
||||
52 => -1
|
||||
)
|
||||
);
|
||||
$this->Coverage->setCoverage($data);
|
||||
$result = $this->Coverage->filterCoverageDataByPath(CAKE);
|
||||
$this->assertTrue(isset($result[CAKE . 'dispatcher.php']));
|
||||
$this->assertFalse(isset($result[APP . 'app_model.php']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test generating HTML reports from file arrays.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateDiff() {
|
||||
$file = array(
|
||||
'line 1',
|
||||
'line 2',
|
||||
'line 3',
|
||||
'line 4',
|
||||
'line 5',
|
||||
'line 6',
|
||||
'line 7',
|
||||
'line 8',
|
||||
'line 9',
|
||||
'line 10',
|
||||
);
|
||||
$coverage = array(
|
||||
1 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
2 => -2,
|
||||
3 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
4 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
5 => -1,
|
||||
6 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
7 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
8 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
9 => -1,
|
||||
10 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff'))
|
||||
);
|
||||
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
||||
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
|
||||
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
|
||||
$this->assertRegExp('/<pre>/', $result);
|
||||
foreach ($file as $i => $line) {
|
||||
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
|
||||
$class = 'covered';
|
||||
if (in_array($i + 1, array(5, 9, 2))) {
|
||||
$class = 'uncovered';
|
||||
}
|
||||
if ($i + 1 === 2) {
|
||||
$class .= ' dead';
|
||||
}
|
||||
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that coverage works with phpunit 3.6 as the data formats from coverage are totally different.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPhpunit36Compatibility() {
|
||||
$file = array(
|
||||
'line 1',
|
||||
'line 2',
|
||||
'line 3',
|
||||
'line 4',
|
||||
'line 5',
|
||||
'line 6',
|
||||
'line 7',
|
||||
'line 8',
|
||||
'line 9',
|
||||
'line 10',
|
||||
);
|
||||
$coverage = array(
|
||||
1 => array('HtmlCoverageReportTest::testGenerateDiff'),
|
||||
2 => null,
|
||||
3 => array('HtmlCoverageReportTest::testGenerateDiff'),
|
||||
4 => array('HtmlCoverageReportTest::testGenerateDiff'),
|
||||
5 => array(),
|
||||
6 => array('HtmlCoverageReportTest::testGenerateDiff'),
|
||||
7 => array('HtmlCoverageReportTest::testGenerateDiff'),
|
||||
8 => array('HtmlCoverageReportTest::testGenerateDiff'),
|
||||
9 => array(),
|
||||
10 => array('HtmlCoverageReportTest::testSomething', 'HtmlCoverageReportTest::testGenerateDiff')
|
||||
);
|
||||
|
||||
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
||||
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
|
||||
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
|
||||
$this->assertRegExp('/<pre>/', $result);
|
||||
foreach ($file as $i => $line) {
|
||||
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
|
||||
$class = 'covered';
|
||||
if (in_array($i + 1, array(5, 9, 2))) {
|
||||
$class = 'uncovered';
|
||||
}
|
||||
if ($i + 1 === 2) {
|
||||
$class .= ' dead';
|
||||
}
|
||||
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test that covering methods show up as title attributes for lines.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCoveredLinesTitleAttributes() {
|
||||
$file = array(
|
||||
'line 1',
|
||||
'line 2',
|
||||
'line 3',
|
||||
'line 4',
|
||||
'line 5',
|
||||
);
|
||||
|
||||
$coverage = array(
|
||||
1 => array(array('id' => 'HtmlCoverageReportTest::testAwesomeness')),
|
||||
2 => -2,
|
||||
3 => array(array('id' => 'HtmlCoverageReportTest::testCakeIsSuperior')),
|
||||
4 => array(array('id' => '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,
|
||||
'Missing method coverage for line 1'
|
||||
);
|
||||
$this->assertTrue(
|
||||
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::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,
|
||||
'Missing method coverage for line 4'
|
||||
);
|
||||
$this->assertTrue(
|
||||
strpos($result, "title=\"\"><span class=\"line-num\">5") !== false,
|
||||
'Coverage report is wrong for line 5'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
CakePlugin::unload();
|
||||
unset($this->Coverage);
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue