code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function testLog() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
Debugger::log('cool');
$result = file_get_contents(LOGS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
$this->assertPattern('/"cool"/', $result);
unlink(TMP . 'logs' . DS . 'debug.log');
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
$this->assertPattern('/\[main\]/', $result);
$this->assertPattern('/array/', $result);
$this->assertPattern('/"whatever",/', $result);
$this->assertPattern('/"here"/', $result);
} | testLog method
@access public
@return void | testLog | php | Datawalke/Coordino | cake/tests/cases/libs/debugger.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/debugger.test.php | MIT |
function testDump() {
$var = array('People' => array(
array(
'name' => 'joeseph',
'coat' => 'technicolor',
'hair_color' => 'brown'
),
array(
'name' => 'Shaft',
'coat' => 'black',
'hair' => 'black'
)
)
);
ob_start();
Debugger::dump($var);
$result = ob_get_clean();
$expected = "<pre>array(\n\t\"People\" => array()\n)</pre>";
$this->assertEqual($expected, $result);
} | testDump method
@access public
@return void | testDump | php | Datawalke/Coordino | cake/tests/cases/libs/debugger.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/debugger.test.php | MIT |
function testGetInstance() {
$result =& Debugger::getInstance();
$this->assertIsA($result, 'Debugger');
$result =& Debugger::getInstance('DebuggerTestCaseDebugger');
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
$result =& Debugger::getInstance();
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
$result =& Debugger::getInstance('Debugger');
$this->assertIsA($result, 'Debugger');
} | test getInstance.
@access public
@return void | testGetInstance | php | Datawalke/Coordino | cake/tests/cases/libs/debugger.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/debugger.test.php | MIT |
function testNoDbCredentials() {
$config = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'void.cakephp.org',
'login' => 'cakephp-user',
'password' => 'cakephp-password',
'database' => 'cakephp-database',
'prefix' => ''
);
$output = Debugger::exportVar($config);
$expectedArray = array(
'driver' => 'mysql',
'persistent' => false,
'host' => '*****',
'login' => '*****',
'password' => '*****',
'database' => '*****',
'prefix' => ''
);
$expected = Debugger::exportVar($expectedArray);
$this->assertEqual($expected, $output);
} | testNoDbCredentials
If a connection error occurs, the config variable is passed through exportVar
*** our database login credentials such that they are never visible
@access public
@return void | testNoDbCredentials | php | Datawalke/Coordino | cake/tests/cases/libs/debugger.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/debugger.test.php | MIT |
function initialize(&$controller) {
$this->testName = 'BlueberryComponent';
} | initialize method
@access public
@return void | initialize | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function cakeError($method, $messages = array()) {
$error = new TestErrorHandler($method, $messages);
return $error;
} | cakeError method
@access public
@return void | cakeError | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function beforeRender() {
echo $this->Blueberry->testName;
} | beforeRender method
@access public
@return void | beforeRender | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function header($header) {
echo $header;
} | header method
@access public
@return void | header | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function index() {
$this->autoRender = false;
return 'what up';
} | index method
@access public
@return void | index | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function missingWidgetThing() {
echo 'widget thing is missing';
} | custom error message type.
@return void | missingWidgetThing | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function skip() {
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
} | skip method
@access public
@return void | skip | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testSubclassMethodsNotBeingConvertedToError() {
$back = Configure::read('debug');
Configure::write('debug', 2);
ob_start();
$ErrorHandler =& new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing');
Configure::write('debug', 0);
ob_start();
$ErrorHandler =& new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
Configure::write('debug', 0);
ob_start();
$ErrorHandler =& new MyCustomErrorHandler('missingController', array(
'className' => 'Missing', 'message' => 'Page not found'
));
$result = ob_get_clean();
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
Configure::write('debug', $back);
} | test that methods declared in an ErrorHandler subclass are not converted
into error404 when debug == 0
@return void | testSubclassMethodsNotBeingConvertedToError | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testError() {
ob_start();
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found'));
ob_clean();
ob_start();
$TestErrorHandler->error(array(
'code' => 404,
'message' => 'Page not Found',
'name' => "Couldn't find what you were looking for"
));
$result = ob_get_clean();
$this->assertPattern("/<h2>Couldn't find what you were looking for<\/h2>/", $result);
$this->assertPattern('/Page not Found/', $result);
} | testError method
@access public
@return void | testError | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingController() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingController', array('className' => 'PostsController'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
$this->assertPattern('/<em>PostsController<\/em>/', $result);
$this->assertPattern('/BlueberryComponent/', $result);
} | testMissingController method
@access public
@return void | testMissingController | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingAction() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingAction', array('className' => 'PostsController', 'action' => 'index'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Method in PostsController<\/h2>/', $result);
$this->assertPattern('/<em>PostsController::<\/em><em>index\(\)<\/em>/', $result);
ob_start();
$dispatcher = new BlueberryDispatcher('/blueberry/inexistent');
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Method in BlueberryController<\/h2>/', $result);
$this->assertPattern('/<em>BlueberryController::<\/em><em>inexistent\(\)<\/em>/', $result);
$this->assertNoPattern('/Location: (.*)\/users\/login/', $result);
$this->assertNoPattern('/Stopped with status: 0/', $result);
} | testMissingAction method
@access public
@return void | testMissingAction | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testPrivateAction() {
ob_start();
$TestErrorHandler = new TestErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Private Method in PostsController<\/h2>/', $result);
$this->assertPattern('/<em>PostsController::<\/em><em>_secretSauce\(\)<\/em>/', $result);
} | testPrivateAction method
@access public
@return void | testPrivateAction | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingTable() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
$result = ob_get_clean();
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Table<\/h2>/', $result);
$this->assertPattern('/table <em>articles<\/em> for model <em>Article<\/em>/', $result);
} | testMissingTable method
@access public
@return void | testMissingTable | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingDatabase() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingDatabase', array());
$result = ob_get_clean();
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Confirm you have created the file/', $result);
} | testMissingDatabase method
@access public
@return void | testMissingDatabase | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingView() {
restore_error_handler();
ob_start();
$TestErrorHandler = new TestErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
$expected = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$this->assertPattern("/PagesController::/", $expected);
$this->assertPattern("/pages\/about.ctp/", $expected);
} | testMissingView method
@access public
@return void | testMissingView | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingLayout() {
restore_error_handler();
ob_start();
$TestErrorHandler = new TestErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
$expected = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$this->assertPattern("/Missing Layout/", $expected);
$this->assertPattern("/layouts\/my_layout.ctp/", $expected);
} | testMissingLayout method
@access public
@return void | testMissingLayout | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingConnection() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingConnection', array('className' => 'Article'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Article requires a database connection/', $result);
} | testMissingConnection method
@access public
@return void | testMissingConnection | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingHelperFile() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Helper File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
} | testMissingHelperFile method
@access public
@return void | testMissingHelperFile | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingHelperClass() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Helper Class<\/h2>/', $result);
$this->assertPattern('/The helper class <em>MyCustomHelper<\/em> can not be found or does not exist./', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
} | testMissingHelperClass method
@access public
@return void | testMissingHelperClass | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingBehaviorFile() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingBehaviorFile', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Behavior File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
} | test missingBehaviorFile method
@access public
@return void | testMissingBehaviorFile | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingBehaviorClass() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Behavior Class<\/h2>/', $result);
$this->assertPattern('/The behavior class <em>MyCustomBehavior<\/em> can not be found or does not exist./', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
} | test MissingBehaviorClass method
@access public
@return void | testMissingBehaviorClass | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingComponentFile() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Component File<\/h2>/', $result);
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
} | testMissingComponentFile method
@access public
@return void | testMissingComponentFile | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingComponentClass() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Component Class<\/h2>/', $result);
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
} | testMissingComponentClass method
@access public
@return void | testMissingComponentClass | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testMissingModel() {
ob_start();
$TestErrorHandler = new TestErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Model<\/h2>/', $result);
$this->assertPattern('/<em>Article<\/em> could not be found./', $result);
$this->assertPattern('/(\/|\\\)article.php/', $result);
} | testMissingModel method
@access public
@return void | testMissingModel | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testThatCode500Works() {
Configure::write('debug', 0);
ob_start();
$TestErrorHandler = new TestErrorHandler('missingTable', array(
'className' => 'Article',
'table' => 'articles',
'code' => 500
));
$result = ob_get_clean();
$this->assertPattern('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
} | testing that having a code => 500 in the cakeError call makes an
internal server error.
@return void | testThatCode500Works | php | Datawalke/Coordino | cake/tests/cases/libs/error.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/error.test.php | MIT |
function testBasic() {
$file = __FILE__;
$this->File =& new File($file);
$result = $this->File->pwd();
$expecting = $file;
$this->assertEqual($result, $expecting);
$result = $this->File->name;
$expecting = basename(__FILE__);
$this->assertEqual($result, $expecting);
$result = $this->File->info();
$expecting = array(
'dirname' => dirname(__FILE__), 'basename' => basename(__FILE__),
'extension' => 'php', 'filename' =>'file.test'
);
$this->assertEqual($result, $expecting);
$result = $this->File->ext();
$expecting = 'php';
$this->assertEqual($result, $expecting);
$result = $this->File->name();
$expecting = 'file.test';
$this->assertEqual($result, $expecting);
$result = $this->File->md5();
$expecting = md5_file($file);
$this->assertEqual($result, $expecting);
$result = $this->File->md5(true);
$expecting = md5_file($file);
$this->assertEqual($result, $expecting);
$result = $this->File->size();
$expecting = filesize($file);
$this->assertEqual($result, $expecting);
$result = $this->File->owner();
$expecting = fileowner($file);
$this->assertEqual($result, $expecting);
$result = $this->File->group();
$expecting = filegroup($file);
$this->assertEqual($result, $expecting);
$result = $this->File->Folder();
$this->assertIsA($result, 'Folder');
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s File permissions tests not supported on Windows');
$result = $this->File->perms();
$expecting = '0644';
$this->assertEqual($result, $expecting);
} | testBasic method
@access public
@return void | testBasic | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testRead() {
$file = __FILE__;
$this->File =& new File($file);
$result = $this->File->read();
$expecting = file_get_contents(__FILE__);
$this->assertEqual($result, $expecting);
$this->assertTrue(!is_resource($this->File->handle));
$this->File->lock = true;
$result = $this->File->read();
$expecting = file_get_contents(__FILE__);
$this->assertEqual($result, trim($expecting));
$this->File->lock = null;
$data = $expecting;
$expecting = substr($data, 0, 3);
$result = $this->File->read(3);
$this->assertEqual($result, $expecting);
$this->assertTrue(is_resource($this->File->handle));
$expecting = substr($data, 3, 3);
$result = $this->File->read(3);
$this->assertEqual($result, $expecting);
} | testRead method
@access public
@return void | testRead | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testOffset() {
$this->File->close();
$result = $this->File->offset();
$this->assertFalse($result);
$this->assertFalse(is_resource($this->File->handle));
$success = $this->File->offset(0);
$this->assertTrue($success);
$this->assertTrue(is_resource($this->File->handle));
$result = $this->File->offset();
$expecting = 0;
$this->assertIdentical($result, $expecting);
$data = file_get_contents(__FILE__);
$success = $this->File->offset(5);
$expecting = substr($data, 5, 3);
$result = $this->File->read(3);
$this->assertTrue($success);
$this->assertEqual($result, $expecting);
$result = $this->File->offset();
$expecting = 5+3;
$this->assertIdentical($result, $expecting);
} | testOffset method
@access public
@return void | testOffset | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testOpen() {
$this->File->handle = null;
$r = $this->File->open();
$this->assertTrue(is_resource($this->File->handle));
$this->assertTrue($r);
$handle = $this->File->handle;
$r = $this->File->open();
$this->assertTrue($r);
$this->assertTrue($handle === $this->File->handle);
$this->assertTrue(is_resource($this->File->handle));
$r = $this->File->open('r', true);
$this->assertTrue($r);
$this->assertFalse($handle === $this->File->handle);
$this->assertTrue(is_resource($this->File->handle));
} | testOpen method
@access public
@return void | testOpen | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testClose() {
$this->File->handle = null;
$this->assertFalse(is_resource($this->File->handle));
$this->assertTrue($this->File->close());
$this->assertFalse(is_resource($this->File->handle));
$this->File->handle = fopen(__FILE__, 'r');
$this->assertTrue(is_resource($this->File->handle));
$this->assertTrue($this->File->close());
$this->assertFalse(is_resource($this->File->handle));
} | testClose method
@access public
@return void | testClose | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testCreate() {
$tmpFile = TMP.'tests'.DS.'cakephp.file.test.tmp';
$File =& new File($tmpFile, true, 0777);
$this->assertTrue($File->exists());
} | testCreate method
@access public
@return void | testCreate | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testOpeningNonExistantFileCreatesIt() {
$someFile =& new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertEqual($someFile->read(), '');
$someFile->close();
$someFile->delete();
} | testOpeningNonExistantFileCreatesIt method
@access public
@return void | testOpeningNonExistantFileCreatesIt | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testPrepare() {
$string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere";
if (DS == '\\') {
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
} else {
$expected = "some\nvery\ncool\nteststring here\n\n\nfor\n\n\n\n\nhere";
}
$this->assertIdentical(File::prepare($string), $expected);
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
$this->assertIdentical(File::prepare($string, true), $expected);
} | testPrepare method
@access public
@return void | testPrepare | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testReadable() {
$someFile =& new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertTrue($someFile->readable());
$someFile->close();
$someFile->delete();
} | testReadable method
@access public
@return void | testReadable | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testWritable() {
$someFile =& new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertTrue($someFile->writable());
$someFile->close();
$someFile->delete();
} | testWritable method
@access public
@return void | testWritable | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testExecutable() {
$someFile =& new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertFalse($someFile->executable());
$someFile->close();
$someFile->delete();
} | testExecutable method
@access public
@return void | testExecutable | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testLastAccess() {
$someFile =& new File(TMP . 'some_file.txt', false);
$this->assertFalse($someFile->lastAccess());
$this->assertTrue($someFile->open());
$this->assertEqual($someFile->lastAccess(), time());
$someFile->close();
$someFile->delete();
} | testLastAccess method
@access public
@return void | testLastAccess | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testLastChange() {
$someFile =& new File(TMP . 'some_file.txt', false);
$this->assertFalse($someFile->lastChange());
$this->assertTrue($someFile->open('r+'));
$this->assertEqual($someFile->lastChange(), time());
$someFile->write('something');
$this->assertEqual($someFile->lastChange(), time());
$someFile->close();
$someFile->delete();
} | testLastChange method
@access public
@return void | testLastChange | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testWrite() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
};
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
$TmpFile =& new File($tmpFile);
$this->assertFalse(file_exists($tmpFile));
$this->assertFalse(is_resource($TmpFile->handle));
$testData = array('CakePHP\'s', ' test suite', ' was here ...', '');
foreach ($testData as $data) {
$r = $TmpFile->write($data);
$this->assertTrue($r);
$this->assertTrue(file_exists($tmpFile));
$this->assertEqual($data, file_get_contents($tmpFile));
$this->assertTrue(is_resource($TmpFile->handle));
$TmpFile->close();
}
unlink($tmpFile);
} | testWrite method
@access public
@return void | testWrite | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testAppend() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
};
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
$TmpFile =& new File($tmpFile);
$this->assertFalse(file_exists($tmpFile));
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
$data = null;
foreach ($fragments as $fragment) {
$r = $TmpFile->append($fragment);
$this->assertTrue($r);
$this->assertTrue(file_exists($tmpFile));
$data = $data.$fragment;
$this->assertEqual($data, file_get_contents($tmpFile));
$TmpFile->close();
}
} | testAppend method
@access public
@return void | testAppend | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testDelete() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
}
if (!file_exists($tmpFile)) {
touch($tmpFile);
}
$TmpFile =& new File($tmpFile);
$this->assertTrue(file_exists($tmpFile));
$result = $TmpFile->delete();
$this->assertTrue($result);
$this->assertFalse(file_exists($tmpFile));
$TmpFile =& new File('/this/does/not/exist');
$result = $TmpFile->delete();
$this->assertFalse($result);
} | testDelete method
@access public
@return void | testDelete | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testDeleteAfterRead() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
}
if (!file_exists($tmpFile)) {
touch($tmpFile);
}
$file =& new File($tmpFile);
$file->read();
$this->assertTrue($file->delete());
} | Windows has issues unlinking files if there are
active filehandles open.
@return void | testDeleteAfterRead | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testCopy() {
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
$file = __FILE__;
$this->File =& new File($file);
$result = $this->File->copy($dest);
$this->assertTrue($result);
$result = $this->File->copy($dest, true);
$this->assertTrue($result);
$result = $this->File->copy($dest, false);
$this->assertFalse($result);
$this->File->close();
unlink($dest);
$TmpFile =& new File('/this/does/not/exist');
$result = $TmpFile->copy($dest);
$this->assertFalse($result);
$TmpFile->close();
} | testCopy method
@access public
@return void | testCopy | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function _getTmpFile($paintSkip = true) {
$tmpFile = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
if (is_writable(dirname($tmpFile)) && (!file_exists($tmpFile) || is_writable($tmpFile))) {
return $tmpFile;
};
if ($paintSkip) {
$caller = 'test';
if (function_exists('debug_backtrace')) {
$trace = debug_backtrace();
$caller = $trace[1]['function'] . '()';
}
$assertLine = new SimpleStackTrace(array(__FUNCTION__));
$assertLine = $assertLine->traceMethod();
$shortPath = substr($tmpFile, strlen(ROOT));
$message = '[FileTest] Skipping %s because "%s" not writeable!';
$message = sprintf(__($message, true), $caller, $shortPath) . $assertLine;
$this->_reporter->paintSkip($message);
}
return false;
} | getTmpFile method
@param bool $paintSkip
@access protected
@return void | _getTmpFile | php | Datawalke/Coordino | cake/tests/cases/libs/file.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/file.test.php | MIT |
function testBasic() {
$path = dirname(__FILE__);
$Folder =& new Folder($path);
$result = $Folder->pwd();
$this->assertEqual($result, $path);
$result = Folder::addPathElement($path, 'test');
$expected = $path . DS . 'test';
$this->assertEqual($result, $expected);
$result = $Folder->cd(ROOT);
$expected = ROOT;
$this->assertEqual($result, $expected);
$result = $Folder->cd(ROOT . DS . 'non-existent');
$this->assertFalse($result);
} | testBasic method
@access public
@return void | testBasic | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testInPath() {
$path = dirname(dirname(__FILE__));
$inside = dirname($path) . DS;
$Folder =& new Folder($path);
$result = $Folder->pwd();
$this->assertEqual($result, $path);
$result = Folder::isSlashTerm($inside);
$this->assertTrue($result);
$result = $Folder->realpath('tests/');
$this->assertEqual($result, $path . DS .'tests' . DS);
$result = $Folder->inPath('tests' . DS);
$this->assertTrue($result);
$result = $Folder->inPath(DS . 'non-existing' . $inside);
$this->assertFalse($result);
} | testInPath method
@access public
@return void | testInPath | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testCreation() {
$folder =& new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
rmdir(TMP . 'tests' . DS . 'first');
$folder =& new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first');
} | test creation of single and mulitple paths.
@return void | testCreation | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testCreateWithTrailingDs() {
$folder =& new Folder(TMP);
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
$result = $folder->create($path);
$this->assertTrue($result);
$this->assertTrue(is_dir($path), 'Folder was not made');
$folder =& new Folder(TMP . 'tests' . DS . 'trailing');
$this->assertTrue($folder->delete());
} | test that creation of folders with trailing ds works
@return void | testCreateWithTrailingDs | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testRecursiveCreateFailure() {
if ($this->skipIf(DS == '\\', 'Cant perform operations using permissions on windows. %s')) {
return;
}
$path = TMP . 'tests' . DS . 'one';
mkdir($path);
chmod($path, '0444');
$this->expectError();
$folder =& new Folder($path);
$result = $folder->create($path . DS . 'two' . DS . 'three');
$this->assertFalse($result);
chmod($path, '0777');
rmdir($path);
} | test recurisve directory create failure.
@return void | testRecursiveCreateFailure | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testOperations() {
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$result = is_dir($Folder->pwd());
$this->assertTrue($result);
$new = TMP . 'test_folder_new';
$result = $Folder->create($new);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $Folder->copy($copy);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $Folder->copy($copy);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $Folder->chmod($copy, 0755, false);
$this->assertTrue($result);
$result = $Folder->cd($copy);
$this->assertTrue($result);
$mv = TMP . 'test_folder_mv';
$result = $Folder->move($mv);
$this->assertTrue($result);
$mv = TMP . 'test_folder_mv_2';
$result = $Folder->move($mv);
$this->assertTrue($result);
$result = $Folder->delete($new);
$this->assertTrue($result);
$result = $Folder->delete($mv);
$this->assertTrue($result);
$result = $Folder->delete($mv);
$this->assertTrue($result);
$new = APP . 'index.php';
$result = $Folder->create($new);
$this->assertFalse($result);
$expected = $new . ' is a file';
$result = array_pop($Folder->errors());
$this->assertEqual($result, $expected);
$new = TMP . 'test_folder_new';
$result = $Folder->create($new);
$this->assertTrue($result);
$result = $Folder->cd($new);
$this->assertTrue($result);
$result = $Folder->delete();
$this->assertTrue($result);
$Folder =& new Folder('non-existent');
$result = $Folder->pwd();
$this->assertNull($result);
} | testOperations method
@access public
@return void | testOperations | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testChmod() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows');
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$subdir = 'test_folder_new';
$new = TMP . $subdir;
$this->assertTrue($Folder->create($new));
$this->assertTrue($Folder->create($new . DS . 'test1'));
$this->assertTrue($Folder->create($new . DS . 'test2'));
$filePath = $new . DS . 'test1.php';
$File =& new File($filePath);
$this->assertTrue($File->create());
$copy = TMP . 'test_folder_copy';
$this->assertTrue($Folder->chmod($new, 0777, true));
$this->assertEqual($File->perms(), '0777');
$Folder->delete($new);
} | testChmod method
@return void
@access public | testChmod | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testRealPathForWebroot() {
$Folder = new Folder('files/');
$this->assertEqual(realpath('files/'), $Folder->path);
} | testRealPathForWebroot method
@access public
@return void | testRealPathForWebroot | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testZeroAsDirectory() {
$Folder =& new Folder(TMP);
$new = TMP . '0';
$this->assertTrue($Folder->create($new));
$result = $Folder->read(true, true);
$expected = array('0', 'cache', 'logs', 'sessions', 'tests');
$this->assertEqual($expected, $result[0]);
$result = $Folder->read(true, array('.', '..', 'logs', '.svn'));
$expected = array('0', 'cache', 'sessions', 'tests');
$this->assertEqual($expected, $result[0]);
$result = $Folder->delete($new);
$this->assertTrue($result);
} | testZeroAsDirectory method
@access public
@return void | testZeroAsDirectory | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testAddPathElement() {
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
$this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
$this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
} | test Adding path elements to a path
@return void | testAddPathElement | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testFolderRead() {
$Folder =& new Folder(TMP);
$expected = array('cache', 'logs', 'sessions', 'tests');
$result = $Folder->read(true, true);
$this->assertEqual($result[0], $expected);
$Folder->path = TMP . DS . 'non-existent';
$expected = array(array(), array());
$result = $Folder->read(true, true);
$this->assertEqual($result, $expected);
} | testFolderRead method
@access public
@return void | testFolderRead | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testFolderTree() {
$Folder =& new Folder();
$expected = array(
array(
TEST_CAKE_CORE_INCLUDE_PATH . 'config',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding'
),
array(
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0250_02af.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php'
)
);
$result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false);
$this->assertIdentical(array_diff($expected[0], $result[0]), array());
$this->assertIdentical(array_diff($result[0], $expected[0]), array());
$result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false, 'dir');
$this->assertIdentical(array_diff($expected[0], $result), array());
$this->assertIdentical(array_diff($result, $expected[0]), array());
$result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false, 'files');
$this->assertIdentical(array_diff($expected[1], $result), array());
$this->assertIdentical(array_diff($result, $expected[1]), array());
} | testFolderTree method
@access public
@return void | testFolderTree | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testWindowsPath() {
$this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
$this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
$this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
$this->assertTrue(Folder::isWindowsPath('\\\\vmware-host\\Shared Folders\\file'));
} | testWindowsPath method
@access public
@return void | testWindowsPath | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testIsAbsolute() {
$this->assertFalse(Folder::isAbsolute('path/to/file'));
$this->assertFalse(Folder::isAbsolute('cake/'));
$this->assertFalse(Folder::isAbsolute('path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('\\path/to/file'));
$this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('/usr/local'));
$this->assertTrue(Folder::isAbsolute('//path/to/file'));
$this->assertTrue(Folder::isAbsolute('C:\\cake'));
$this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
} | testIsAbsolute method
@access public
@return void | testIsAbsolute | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testIsSlashTerm() {
$this->assertFalse(Folder::isSlashTerm('cake'));
$this->assertTrue(Folder::isSlashTerm('C:\\cake\\'));
$this->assertTrue(Folder::isSlashTerm('/usr/local/'));
} | testIsSlashTerm method
@access public
@return void | testIsSlashTerm | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testSlashTerm() {
$result = Folder::slashTerm('/path/to/file');
$this->assertEqual($result, '/path/to/file/');
} | testStatic method
@access public
@return void | testSlashTerm | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testNormalizePath() {
$path = '/path/to/file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '/');
$path = '\\path\\\to\\\file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '/');
$path = 'C:\\path\\to\\file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '\\');
} | testNormalizePath method
@access public
@return void | testNormalizePath | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testCorrectSlashFor() {
$path = '/path/to/file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '/');
$path = '\\path\\to\\file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '/');
$path = 'C:\\path\to\\file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '\\');
} | correctSlashFor method
@access public
@return void | testCorrectSlashFor | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testInCakePath() {
$Folder =& new Folder();
$Folder->cd(ROOT);
$path = 'C:\\path\\to\\file';
$result = $Folder->inCakePath($path);
$this->assertFalse($result);
$path = ROOT;
$Folder->cd(ROOT);
$result = $Folder->inCakePath($path);
$this->assertFalse($result);
// WHY DOES THIS FAIL ??
$path = DS . 'cake' . DS . 'config';
$Folder->cd(ROOT . DS . 'cake' . DS . 'config');
$result = $Folder->inCakePath($path);
$this->assertTrue($result);
} | testInCakePath method
@access public
@return void | testInCakePath | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testFind() {
$Folder =& new Folder();
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
$result = $Folder->find();
$expected = array('config.php', 'paths.php');
$this->assertIdentical(array_diff($expected, $result), array());
$this->assertIdentical(array_diff($result, $expected), array());
$result = $Folder->find('.*', true);
$expected = array('config.php', 'paths.php');
$this->assertIdentical($result, $expected);
$result = $Folder->find('.*\.php');
$expected = array('config.php', 'paths.php');
$this->assertIdentical(array_diff($expected, $result), array());
$this->assertIdentical(array_diff($result, $expected), array());
$result = $Folder->find('.*\.php', true);
$expected = array('config.php', 'paths.php');
$this->assertIdentical($result, $expected);
$result = $Folder->find('.*ig\.php');
$expected = array('config.php');
$this->assertIdentical($result, $expected);
$result = $Folder->find('paths\.php');
$expected = array('paths.php');
$this->assertIdentical($result, $expected);
$Folder->cd(TMP);
$file = new File($Folder->pwd() . DS . 'paths.php', true);
$Folder->create($Folder->pwd() . DS . 'testme');
$Folder->cd('testme');
$result = $Folder->find('paths\.php');
$expected = array();
$this->assertIdentical($result, $expected);
$Folder->cd($Folder->pwd() . '/..');
$result = $Folder->find('paths\.php');
$expected = array('paths.php');
$this->assertIdentical($result, $expected);
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . DS . 'testme');
$file->delete();
} | testFind method
@access public
@return void | testFind | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testFindRecursive() {
$Folder =& new Folder();
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
$result = $Folder->findRecursive('(config|paths)\.php');
$expected = array(
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php'
);
$this->assertIdentical(array_diff($expected, $result), array());
$this->assertIdentical(array_diff($result, $expected), array());
$result = $Folder->findRecursive('(config|paths)\.php', true);
$expected = array(
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php'
);
$this->assertIdentical($result, $expected);
$Folder->cd(TMP);
$Folder->create($Folder->pwd() . DS . 'testme');
$Folder->cd('testme');
$File =& new File($Folder->pwd() . DS . 'paths.php');
$File->create();
$Folder->cd(TMP . 'sessions');
$result = $Folder->findRecursive('paths\.php');
$expected = array();
$this->assertIdentical($result, $expected);
$Folder->cd(TMP . 'testme');
$File =& new File($Folder->pwd() . DS . 'my.php');
$File->create();
$Folder->cd($Folder->pwd() . '/../..');
$result = $Folder->findRecursive('(paths|my)\.php');
$expected = array(
TMP . 'testme' . DS . 'my.php',
TMP . 'testme' . DS . 'paths.php'
);
$this->assertIdentical(array_diff($expected, $result), array());
$this->assertIdentical(array_diff($result, $expected), array());
$result = $Folder->findRecursive('(paths|my)\.php', true);
$expected = array(
TMP . 'testme' . DS . 'my.php',
TMP . 'testme' . DS . 'paths.php'
);
$this->assertIdentical($result, $expected);
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . DS . 'testme');
$File->delete();
} | testFindRecursive method
@access public
@return void | testFindRecursive | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testConstructWithNonExistantPath() {
$Folder =& new Folder(TMP . 'config_non_existant', true);
$this->assertTrue(is_dir(TMP . 'config_non_existant'));
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . 'config_non_existant');
} | testConstructWithNonExistantPath method
@access public
@return void | testConstructWithNonExistantPath | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testDirSize() {
$Folder =& new Folder(TMP . 'config_non_existant', true);
$this->assertEqual($Folder->dirSize(), 0);
$File =& new File($Folder->pwd() . DS . 'my.php', true, 0777);
$File->create();
$File->write('something here');
$File->close();
$this->assertEqual($Folder->dirSize(), 14);
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . 'config_non_existant');
} | testDirSize method
@access public
@return void | testDirSize | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testDelete() {
$path = TMP . 'folder_delete_test';
$Folder =& new Folder($path, true);
touch(TMP . 'folder_delete_test' . DS . 'file1');
touch(TMP . 'folder_delete_test' . DS . 'file2');
$return = $Folder->delete();
$this->assertTrue($return);
$messages = $Folder->messages();
$errors = $Folder->errors();
$this->assertEqual($errors, array());
$expected = array(
$path . ' created',
$path . DS . 'file1 removed',
$path . DS . 'file2 removed',
$path . ' removed'
);
$this->assertEqual($expected, $messages);
} | testDelete method
@access public
@return void | testDelete | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testCopy() {
$path = TMP . 'folder_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $folder1 . DS . 'folder2';
$folder3 = $path . DS . 'folder3';
$file1 = $folder1 . DS . 'file1.php';
$file2 = $folder2 . DS . 'file2.php';
new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
touch($file1);
touch($file2);
$Folder =& new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$Folder =& new Folder($folder3);
$Folder->delete();
$Folder =& new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$Folder =& new Folder($folder3);
$Folder->delete();
new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
$Folder =& new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
$Folder =& new Folder($path);
$Folder->delete();
} | testCopy method
Verify that directories and files are copied recursively
even if the destination directory already exists.
Subdirectories existing in both destination and source directory
are skipped and not merged or overwritten.
@return void
@access public
@link https://trac.cakephp.org/ticket/6259 | testCopy | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function testMove() {
$path = TMP . 'folder_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $folder1 . DS . 'folder2';
$folder3 = $path . DS . 'folder3';
$file1 = $folder1 . DS . 'file1.php';
$file2 = $folder2 . DS . 'file2.php';
new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
touch($file1);
touch($file2);
$Folder =& new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(is_dir($folder3 . DS . 'folder2'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));
$Folder =& new Folder($folder3);
$Folder->delete();
new Folder($folder1, true);
new Folder($folder2, true);
touch($file1);
touch($file2);
$Folder =& new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(is_dir($folder3 . DS . 'folder2'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));
$Folder =& new Folder($folder3);
$Folder->delete();
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
touch($file1);
touch($file2);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
$Folder =& new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));
$Folder =& new Folder($path);
$Folder->delete();
} | testMove method
Verify that directories and files are moved recursively
even if the destination directory already exists.
Subdirectories existing in both destination and source directory
are skipped and not merged or overwritten.
@return void
@access public
@link https://trac.cakephp.org/ticket/6259 | testMove | php | Datawalke/Coordino | cake/tests/cases/libs/folder.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/folder.test.php | MIT |
function configUri($uri = null) {
return parent::_configUri($uri);
} | Convenience method for testing protected method
@param mixed $uri URI (see {@link _parseUri()})
@return array Current configuration settings | configUri | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function parseUri($uri = null, $base = array()) {
return parent::_parseUri($uri, $base);
} | Convenience method for testing protected method
@param string $uri URI to parse
@param mixed $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
@return array Parsed URI | parseUri | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
return parent::_buildUri($uri, $uriTemplate);
} | Convenience method for testing protected method
@param array $uri A $uri array, or uses $this->config if left empty
@param string $uriTemplate The Uri template/format to use
@return string A fully qualified URL formated according to $uriTemplate | buildUri | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function buildHeader($header, $mode = 'standard') {
return parent::_buildHeader($header, $mode);
} | Convenience method for testing protected method
@param array $header Header to build
@return string Header built from array | buildHeader | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function parseResponse($message) {
return parent::_parseResponse($message);
} | Convenience method for testing protected method
@param string $message Message to parse
@return array Parsed message (with indexed elements such as raw, status, header, body) | parseResponse | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function parseHeader($header) {
return parent::_parseHeader($header);
} | Convenience method for testing protected method
@param array $header Header as an indexed array (field => value)
@return array Parsed header | parseHeader | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function parseQuery($query) {
return parent::_parseQuery($query);
} | Convenience method for testing protected method
@param mixed $query A query string to parse into an array or an array to return directly "as is"
@return array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned. | parseQuery | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function decodeBody($body, $encoding = 'chunked') {
return parent::_decodeBody($body, $encoding);
} | Convenience method for testing protected method
@param string $body A string continaing the body to decode
@param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding
@return mixed Array or false | decodeBody | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function decodeChunkedBody($body) {
return parent::_decodeChunkedBody($body);
} | Convenience method for testing protected method
@param string $body A string continaing the chunked body to decode
@return mixed Array or false | decodeChunkedBody | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
return parent::_buildRequestLine($request, $versionToken);
} | Convenience method for testing protected method
@param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
@param string $versionToken The version token to use, defaults to HTTP/1.1
@return string Request line | buildRequestLine | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function tokenEscapeChars($hex = true, $chars = null) {
return parent::_tokenEscapeChars($hex, $chars);
} | Convenience method for testing protected method
@param boolean $hex true to get them as HEX values, false otherwise
@return array Escape chars | tokenEscapeChars | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function EscapeToken($token, $chars = null) {
return parent::_escapeToken($token, $chars);
} | Convenience method for testing protected method
@param string $token Token to escape
@return string Escaped token | EscapeToken | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function unescapeToken($token, $chars = null) {
return parent::_unescapeToken($token, $chars);
} | Convenience method for testing protected method
@param string $token Token to unescape
@return string Unescaped token | unescapeToken | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function setUp() {
if (!class_exists('MockHttpSocket')) {
Mock::generatePartial('TestHttpSocket', 'MockHttpSocket', array('read', 'write', 'connect'));
Mock::generatePartial('TestHttpSocket', 'MockHttpSocketRequests', array('read', 'write', 'connect', 'request'));
}
$this->Socket =& new MockHttpSocket();
$this->RequestSocket =& new MockHttpSocketRequests();
} | This function sets up a TestHttpSocket instance we are going to use for testing
@access public
@return void | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function tearDown() {
unset($this->Socket, $this->RequestSocket);
} | We use this function to clean up after the test case was executed
@access public
@return void | tearDown | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testConstruct() {
$this->Socket->reset();
$baseConfig = $this->Socket->config;
$this->Socket->expectNever('connect');
$this->Socket->__construct(array('host' => 'foo-bar'));
$baseConfig['host'] = 'foo-bar';
$baseConfig['protocol'] = getprotobyname($baseConfig['protocol']);
$this->assertIdentical($this->Socket->config, $baseConfig);
$this->Socket->reset();
$baseConfig = $this->Socket->config;
$this->Socket->__construct('http://www.cakephp.org:23/');
$baseConfig['host'] = 'www.cakephp.org';
$baseConfig['request']['uri']['host'] = 'www.cakephp.org';
$baseConfig['port'] = 23;
$baseConfig['request']['uri']['port'] = 23;
$baseConfig['protocol'] = getprotobyname($baseConfig['protocol']);
$this->assertIdentical($this->Socket->config, $baseConfig);
$this->Socket->reset();
$this->Socket->__construct(array('request' => array('uri' => 'http://www.cakephp.org:23/')));
$this->assertIdentical($this->Socket->config, $baseConfig);
} | Test that HttpSocket::__construct does what one would expect it to do
@access public
@return void | testConstruct | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testConfigUri() {
$this->Socket->reset();
$r = $this->Socket->configUri('https://bob:[email protected]:23/?query=foo');
$expected = array(
'persistent' => false,
'host' => 'www.cakephp.org',
'protocol' => 'tcp',
'port' => 23,
'timeout' => 30,
'request' => array(
'uri' => array(
'scheme' => 'https'
, 'host' => 'www.cakephp.org'
, 'port' => 23
),
'auth' => array(
'method' => 'Basic'
, 'user' => 'bob'
, 'pass' => 'secret'
),
'cookies' => array(),
)
);
$this->assertIdentical($this->Socket->config, $expected);
$this->assertIdentical($r, $expected);
$r = $this->Socket->configUri(array('host' => 'www.foo-bar.org'));
$expected['host'] = 'www.foo-bar.org';
$expected['request']['uri']['host'] = 'www.foo-bar.org';
$this->assertIdentical($this->Socket->config, $expected);
$this->assertIdentical($r, $expected);
$r = $this->Socket->configUri('http://www.foo.com');
$expected = array(
'persistent' => false,
'host' => 'www.foo.com',
'protocol' => 'tcp',
'port' => 80,
'timeout' => 30,
'request' => array(
'uri' => array(
'scheme' => 'http'
, 'host' => 'www.foo.com'
, 'port' => 80
),
'auth' => array(
'method' => 'Basic'
, 'user' => null
, 'pass' => null
),
'cookies' => array()
)
);
$this->assertIdentical($this->Socket->config, $expected);
$this->assertIdentical($r, $expected);
$r = $this->Socket->configUri('/this-is-broken');
$this->assertIdentical($this->Socket->config, $expected);
$this->assertIdentical($r, false);
$r = $this->Socket->configUri(false);
$this->assertIdentical($this->Socket->config, $expected);
$this->assertIdentical($r, false);
} | Test that HttpSocket::configUri works properly with different types of arguments
@access public
@return void | testConfigUri | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testRequest() {
$this->Socket->reset();
$this->Socket->reset();
$response = $this->Socket->request(true);
$this->assertFalse($response);
$tests = array(
0 => array(
'request' => 'http://www.cakephp.org/?foo=bar'
, 'expectation' => array(
'config' => array(
'persistent' => false
, 'host' => 'www.cakephp.org'
, 'protocol' => 'tcp'
, 'port' => 80
, 'timeout' => 30
, 'request' => array(
'uri' => array (
'scheme' => 'http'
, 'host' => 'www.cakephp.org'
, 'port' => 80,
)
, 'auth' => array(
'method' => 'Basic'
,'user' => null
,'pass' => null
),
'cookies' => array(),
),
)
, 'request' => array(
'method' => 'GET'
, 'uri' => array(
'scheme' => 'http'
, 'host' => 'www.cakephp.org'
, 'port' => 80
, 'user' => null
, 'pass' => null
, 'path' => '/'
, 'query' => array('foo' => 'bar')
, 'fragment' => null
)
, 'auth' => array(
'method' => 'Basic'
, 'user' => null
, 'pass' => null
)
, 'version' => '1.1'
, 'body' => ''
, 'line' => "GET /?foo=bar HTTP/1.1\r\n"
, 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n"
, 'raw' => ""
, 'cookies' => array(),
)
)
)
, 1 => array(
'request' => array(
'uri' => array(
'host' => 'www.cakephp.org'
, 'query' => '?foo=bar'
)
)
)
, 2 => array(
'request' => 'www.cakephp.org/?foo=bar'
)
, 3 => array(
'request' => array('host' => '192.168.0.1', 'uri' => 'http://www.cakephp.org/?foo=bar')
, 'expectation' => array(
'request' => array(
'uri' => array('host' => 'www.cakephp.org')
)
, 'config' => array(
'request' => array(
'uri' => array('host' => 'www.cakephp.org')
)
, 'host' => '192.168.0.1'
)
)
)
, 'reset4' => array(
'request.uri.query' => array()
)
, 4 => array(
'request' => array('header' => array('Foo@woo' => 'bar-value'))
, 'expectation' => array(
'request' => array(
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n"
, 'line' => "GET / HTTP/1.1\r\n"
)
)
)
, 5 => array(
'request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/')
, 'expectation' => array(
'request' => array(
'header' => "Host: foo.com\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n"
)
, 'config' => array(
'host' => 'www.cakephp.org'
)
)
)
, 6 => array(
'request' => array('header' => "Foo: bar\r\n")
, 'expectation' => array(
'request' => array(
'header' => "Foo: bar\r\n"
)
)
)
, 7 => array(
'request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me')
, 'expectation' => array(
'request' => array(
'uri' => array(
'path' => '/search'
, 'query' => array('q' => 'http_socket')
, 'fragment' => 'ignore-me'
)
, 'line' => "GET /search?q=http_socket HTTP/1.1\r\n"
)
)
)
, 'reset8' => array(
'request.uri.query' => array()
)
, 8 => array(
'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
'request' => array(
'method' => 'POST'
, 'uri' => array(
'path' => '/posts/add'
, 'fragment' => null
)
, 'body' => "name=HttpSocket-is-released&date=today"
, 'line' => "POST /posts/add HTTP/1.1\r\n"
, 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
, 'raw' => "name=HttpSocket-is-released&date=today"
)
)
)
, 9 => array(
'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org:8080/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
'config' => array(
'port' => 8080
, 'request' => array(
'uri' => array(
'port' => 8080
)
)
)
, 'request' => array(
'uri' => array(
'port' => 8080
)
, 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
)
)
)
, 10 => array(
'request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
'config' => array(
'port' => 443
, 'request' => array(
'uri' => array(
'scheme' => 'https'
, 'port' => 443
)
)
)
, 'request' => array(
'uri' => array(
'scheme' => 'https'
, 'port' => 443
)
, 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
)
)
)
, 11 => array(
'request' => array(
'method' => 'POST',
'uri' => 'https://www.cakephp.org/posts/add',
'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'),
'cookies' => array('foo' => array('value' => 'bar'))
)
, 'expectation' => array(
'request' => array(
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n",
'cookies' => array(
'foo' => array('value' => 'bar'),
)
)
)
)
);
$expectation = array();
foreach ($tests as $i => $test) {
if (strpos($i, 'reset') === 0) {
foreach ($test as $path => $val) {
$expectation = Set::insert($expectation, $path, $val);
}
continue;
}
if (isset($test['expectation'])) {
$expectation = Set::merge($expectation, $test['expectation']);
}
$this->Socket->request($test['request']);
$raw = $expectation['request']['raw'];
$expectation['request']['raw'] = $expectation['request']['line'].$expectation['request']['header']."\r\n".$raw;
$r = array('config' => $this->Socket->config, 'request' => $this->Socket->request);
$v = $this->assertIdentical($r, $expectation, '%s in test #'.$i.' ');
$expectation['request']['raw'] = $raw;
}
$this->Socket->reset();
$request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'));
$response = $this->Socket->request($request);
$this->assertIdentical($this->Socket->request['body'], "name=HttpSocket-is-released&date=today");
$request = array('uri' => '*', 'method' => 'GET');
$this->expectError(new PatternExpectation('/activate quirks mode/i'));
$response = $this->Socket->request($request);
$this->assertFalse($response);
$this->assertFalse($this->Socket->response);
$this->Socket->reset();
$request = array('uri' => 'htpp://www.cakephp.org/');
$this->Socket->setReturnValue('connect', true);
$this->Socket->setReturnValue('read', false);
$this->Socket->_mock->_call_counts['read'] = 0;
$number = mt_rand(0, 9999999);
$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>Hello, your lucky number is " . $number . "</h1>";
$this->Socket->setReturnValueAt(0, 'read', $serverResponse);
$this->Socket->expect('write', array("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n"));
$this->Socket->expectCallCount('read', 2);
$response = $this->Socket->request($request);
$this->assertIdentical($response, "<h1>Hello, your lucky number is " . $number . "</h1>");
$this->Socket->reset();
$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a cookie test!</h1>";
unset($this->Socket->_mock->_actions->_at['read']);
unset($this->Socket->_mock->_return_sequence['read']);
$this->Socket->_mock->_call_counts['read'] = 0;
$this->Socket->setReturnValueAt(0, 'read', $serverResponse);
$this->Socket->connected = true;
$this->Socket->request($request);
$result = $this->Socket->response['cookies'];
$expect = array(
'foo' => array(
'value' => 'bar'
)
);
$this->assertEqual($result, $expect);
$this->assertEqual($this->Socket->config['request']['cookies'], $expect);
$this->assertFalse($this->Socket->connected);
} | Tests that HttpSocket::request (the heart of the HttpSocket) is working properly.
@access public
@return void | testRequest | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testUrl() {
$this->Socket->reset(true);
$this->assertIdentical($this->Socket->url(true), false);
$url = $this->Socket->url('www.cakephp.org');
$this->assertIdentical($url, 'http://www.cakephp.org/');
$url = $this->Socket->url('https://www.cakephp.org/posts/add');
$this->assertIdentical($url, 'https://www.cakephp.org/posts/add');
$url = $this->Socket->url('http://www.cakephp/search?q=socket', '/%path?%query');
$this->assertIdentical($url, '/search?q=socket');
$this->Socket->config['request']['uri']['host'] = 'bakery.cakephp.org';
$url = $this->Socket->url();
$this->assertIdentical($url, 'http://bakery.cakephp.org/');
$this->Socket->configUri('http://www.cakephp.org');
$url = $this->Socket->url('/search?q=bar');
$this->assertIdentical($url, 'http://www.cakephp.org/search?q=bar');
$url = $this->Socket->url(array('host' => 'www.foobar.org', 'query' => array('q' => 'bar')));
$this->assertIdentical($url, 'http://www.foobar.org/?q=bar');
$url = $this->Socket->url(array('path' => '/supersearch', 'query' => array('q' => 'bar')));
$this->assertIdentical($url, 'http://www.cakephp.org/supersearch?q=bar');
$this->Socket->configUri('http://www.google.com');
$url = $this->Socket->url('/search?q=socket');
$this->assertIdentical($url, 'http://www.google.com/search?q=socket');
$url = $this->Socket->url();
$this->assertIdentical($url, 'http://www.google.com/');
$this->Socket->configUri('https://www.google.com');
$url = $this->Socket->url('/search?q=socket');
$this->assertIdentical($url, 'https://www.google.com/search?q=socket');
$this->Socket->reset();
$this->Socket->configUri('www.google.com:443');
$url = $this->Socket->url('/search?q=socket');
$this->assertIdentical($url, 'https://www.google.com/search?q=socket');
$this->Socket->reset();
$this->Socket->configUri('www.google.com:8080');
$url = $this->Socket->url('/search?q=socket');
$this->assertIdentical($url, 'http://www.google.com:8080/search?q=socket');
} | testUrl method
@access public
@return void | testUrl | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testGet() {
$this->RequestSocket->reset();
$this->RequestSocket->expect('request', a(array('method' => 'GET', 'uri' => 'http://www.google.com/')));
$this->RequestSocket->get('http://www.google.com/');
$this->RequestSocket->expect('request', a(array('method' => 'GET', 'uri' => 'http://www.google.com/?foo=bar')));
$this->RequestSocket->get('http://www.google.com/', array('foo' => 'bar'));
$this->RequestSocket->expect('request', a(array('method' => 'GET', 'uri' => 'http://www.google.com/?foo=bar')));
$this->RequestSocket->get('http://www.google.com/', 'foo=bar');
$this->RequestSocket->expect('request', a(array('method' => 'GET', 'uri' => 'http://www.google.com/?foo=23&foobar=42')));
$this->RequestSocket->get('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23'));
$this->RequestSocket->expect('request', a(array('method' => 'GET', 'uri' => 'http://www.google.com/', 'auth' => array('user' => 'foo', 'pass' => 'bar'))));
$this->RequestSocket->get('http://www.google.com/', null, array('auth' => array('user' => 'foo', 'pass' => 'bar')));
} | testGet method
@access public
@return void | testGet | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testConsecutiveGetResetsAuthCredentials() {
$socket = new MockHttpSocket();
$socket->config['request']['auth'] = array(
'method' => 'Basic',
'user' => 'mark',
'pass' => 'secret'
);
$socket->get('http://mark:[email protected]/test');
$this->assertEqual($socket->request['uri']['user'], 'mark');
$this->assertEqual($socket->request['uri']['pass'], 'secret');
$socket->get('/test2');
$this->assertEqual($socket->request['auth']['user'], 'mark');
$this->assertEqual($socket->request['auth']['pass'], 'secret');
$socket->get('/test3');
$this->assertEqual($socket->request['auth']['user'], 'mark');
$this->assertEqual($socket->request['auth']['pass'], 'secret');
} | test that two consecutive get() calls reset the authentication credentials.
@return void | testConsecutiveGetResetsAuthCredentials | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testPostPutDelete() {
$this->RequestSocket->reset();
foreach (array('POST', 'PUT', 'DELETE') as $method) {
$this->RequestSocket->expect('request', a(array('method' => $method, 'uri' => 'http://www.google.com/', 'body' => array())));
$this->RequestSocket->{low($method)}('http://www.google.com/');
$this->RequestSocket->expect('request', a(array('method' => $method, 'uri' => 'http://www.google.com/', 'body' => array('Foo' => 'bar'))));
$this->RequestSocket->{low($method)}('http://www.google.com/', array('Foo' => 'bar'));
$this->RequestSocket->expect('request', a(array('method' => $method, 'uri' => 'http://www.google.com/', 'body' => null, 'line' => 'Hey Server')));
$this->RequestSocket->{low($method)}('http://www.google.com/', null, array('line' => 'Hey Server'));
}
} | testPostPutDelete method
@access public
@return void | testPostPutDelete | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testParseResponse() {
$this->Socket->reset();
$r = $this->Socket->parseResponse(array('foo' => 'bar'));
$this->assertIdentical($r, array('foo' => 'bar'));
$r = $this->Socket->parseResponse(true);
$this->assertIdentical($r, false);
$r = $this->Socket->parseResponse("HTTP Foo\r\nBar: La");
$this->assertIdentical($r, false);
$tests = array(
'simple-request' => array(
'response' => array(
'status-line' => "HTTP/1.x 200 OK\r\n",
'header' => "Date: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n",
'body' => "<h1>Hello World</h1>\r\n<p>It's good to be html</p>"
)
, 'expectations' => array(
'status.http-version' => 'HTTP/1.x',
'status.code' => 200,
'status.reason-phrase' => 'OK',
'header' => $this->Socket->parseHeader("Date: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n"),
'body' => "<h1>Hello World</h1>\r\n<p>It's good to be html</p>"
)
),
'no-header' => array(
'response' => array(
'status-line' => "HTTP/1.x 404 OK\r\n",
'header' => null,
)
, 'expectations' => array(
'status.code' => 404,
'header' => array()
)
),
'chunked' => array(
'response' => array(
'header' => "Transfer-Encoding: chunked\r\n",
'body' => "19\r\nThis is a chunked message\r\n0\r\n"
),
'expectations' => array(
'body' => "This is a chunked message",
'header' => $this->Socket->parseHeader("Transfer-Encoding: chunked\r\n")
)
),
'enitity-header' => array(
'response' => array(
'body' => "19\r\nThis is a chunked message\r\n0\r\nFoo: Bar\r\n"
),
'expectations' => array(
'header' => $this->Socket->parseHeader("Transfer-Encoding: chunked\r\nFoo: Bar\r\n")
)
),
'enitity-header-combine' => array(
'response' => array(
'header' => "Transfer-Encoding: chunked\r\nFoo: Foobar\r\n"
),
'expectations' => array(
'header' => $this->Socket->parseHeader("Transfer-Encoding: chunked\r\nFoo: Foobar\r\nFoo: Bar\r\n")
)
)
);
$testResponse = array();
$expectations = array();
foreach ($tests as $name => $test) {
$testResponse = array_merge($testResponse, $test['response']);
$testResponse['response'] = $testResponse['status-line'].$testResponse['header']."\r\n".$testResponse['body'];
$r = $this->Socket->parseResponse($testResponse['response']);
$expectations = array_merge($expectations, $test['expectations']);
foreach ($expectations as $property => $expectedVal) {
$val = Set::extract($r, $property);
$this->assertIdentical($val, $expectedVal, 'Test "'.$name.'": response.'.$property.' - %s');
}
foreach (array('status-line', 'header', 'body', 'response') as $field) {
$this->assertIdentical($r['raw'][$field], $testResponse[$field], 'Test response.raw.'.$field.': %s');
}
}
} | testParseResponse method
@access public
@return void | testParseResponse | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testDecodeBody() {
$this->Socket->reset();
$r = $this->Socket->decodeBody(true);
$this->assertIdentical($r, false);
$r = $this->Socket->decodeBody('Foobar', false);
$this->assertIdentical($r, array('body' => 'Foobar', 'header' => false));
$encodings = array(
'chunked' => array(
'encoded' => "19\r\nThis is a chunked message\r\n0\r\n",
'decoded' => array('body' => "This is a chunked message", 'header' => false)
),
'foo-coded' => array(
'encoded' => '!Foobar!',
'decoded' => array('body' => '!Foobar!', 'header' => false),
'error' => new PatternExpectation('/unknown encoding: foo-coded/i')
)
);
foreach ($encodings as $encoding => $sample) {
if (isset($sample['error'])) {
$this->expectError($sample['error']);
}
$r = $this->Socket->decodeBody($sample['encoded'], $encoding);
$this->assertIdentical($r, $sample['decoded']);
if (isset($sample['error'])) {
$this->Socket->quirksMode = true;
$r = $this->Socket->decodeBody($sample['encoded'], $encoding);
$this->assertIdentical($r, $sample['decoded']);
$this->Socket->quirksMode = false;
}
}
} | testDecodeBody method
@access public
@return void | testDecodeBody | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testDecodeChunkedBody() {
$this->Socket->reset();
$r = $this->Socket->decodeChunkedBody(true);
$this->assertIdentical($r, false);
$encoded = "19\r\nThis is a chunked message\r\n0\r\n";
$decoded = "This is a chunked message";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$this->assertIdentical($r['header'], false);
$encoded = "19 \r\nThis is a chunked message\r\n0\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\n";
$decoded = "This is a chunked message\nThat is cool\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$this->assertIdentical($r['header'], false);
$encoded = "19\r\nThis is a chunked message\r\nE;foo-chunk=5\r\n\nThat is cool\n\r\n0\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$this->assertIdentical($r['header'], false);
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$this->assertIdentical($r['header'], array('Foo-Header' => 'bar', 'Cake' => 'PHP'));
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n";
$this->expectError(new PatternExpectation('/activate quirks mode/i'));
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r, false);
$this->Socket->quirksMode = true;
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$this->assertIdentical($r['header'], false);
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertIdentical($r['body'], $decoded);
$this->assertIdentical($r['header'], array('Foo-Header' => 'bar', 'Cake' => 'PHP'));
} | testDecodeChunkedBody method
@access public
@return void | testDecodeChunkedBody | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
function testBuildRequestLine() {
$this->Socket->reset();
$this->expectError(new PatternExpectation('/activate quirks mode/i'));
$r = $this->Socket->buildRequestLine('Foo');
$this->assertIdentical($r, false);
$this->Socket->quirksMode = true;
$r = $this->Socket->buildRequestLine('Foo');
$this->assertIdentical($r, 'Foo');
$this->Socket->quirksMode = false;
$r = $this->Socket->buildRequestLine(true);
$this->assertIdentical($r, false);
$r = $this->Socket->buildRequestLine(array('foo' => 'bar', 'method' => 'foo'));
$this->assertIdentical($r, false);
$r = $this->Socket->buildRequestLine(array('method' => 'GET', 'uri' => 'http://www.cakephp.org/search?q=socket'));
$this->assertIdentical($r, "GET /search?q=socket HTTP/1.1\r\n");
$request = array(
'method' => 'GET',
'uri' => array(
'path' => '/search',
'query' => array('q' => 'socket')
)
);
$r = $this->Socket->buildRequestLine($request);
$this->assertIdentical($r, "GET /search?q=socket HTTP/1.1\r\n");
unset($request['method']);
$r = $this->Socket->buildRequestLine($request);
$this->assertIdentical($r, "GET /search?q=socket HTTP/1.1\r\n");
$r = $this->Socket->buildRequestLine($request, 'CAKE-HTTP/0.1');
$this->assertIdentical($r, "GET /search?q=socket CAKE-HTTP/0.1\r\n");
$request = array('method' => 'OPTIONS', 'uri' => '*');
$r = $this->Socket->buildRequestLine($request);
$this->assertIdentical($r, "OPTIONS * HTTP/1.1\r\n");
$request['method'] = 'GET';
$this->expectError(new PatternExpectation('/activate quirks mode/i'));
$r = $this->Socket->buildRequestLine($request);
$this->assertIdentical($r, false);
$this->expectError(new PatternExpectation('/activate quirks mode/i'));
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
$this->assertIdentical($r, false);
$this->Socket->quirksMode = true;
$r = $this->Socket->buildRequestLine($request);
$this->assertIdentical($r, "GET * HTTP/1.1\r\n");
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
$this->assertIdentical($r, "GET * HTTP/1.1\r\n");
} | testBuildRequestLine method
@access public
@return void | testBuildRequestLine | php | Datawalke/Coordino | cake/tests/cases/libs/http_socket.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/http_socket.test.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.