Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix win delete #476

Closed
wants to merge 12 commits into from

4 participants

@hans-d

...Windows.

The file is checked before an unlink is tried. (this will make the tests run slower but is prefered over a if (!unlink { chmod; unlink }.
See also: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/

@gwoo gwoo commented on the diff
test/Unit.php
@@ -1010,7 +1015,14 @@ protected function _cleanUp($path = null) {
if ($item->getPathname() === "{$path}/empty" || $iterator->isDot()) {
continue;
}
- ($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname());
+ if ($item->isDir()) {
+ rmdir($item->getPathname());
@gwoo Owner
gwoo added a note

add a continue after this instead of use the else block.

@hans-d
hans-d added a note

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/Unit.php
@@ -1010,7 +1015,14 @@ protected function _cleanUp($path = null) {
if ($item->getPathname() === "{$path}/empty" || $iterator->isDot()) {
continue;
}
- ($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname());
+ if ($item->isDir()) {
+ rmdir($item->getPathname());
+ } else {
+ if (!is_writeable($item->getPathname())) {
@gwoo Owner
gwoo added a note

I would use $item->isWritable() method.

@hans-d
hans-d added a note

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hans-d

ooops... rebasing dit not go well

@hans-d hans-d closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 12, 2012
  1. @toomuchpete

    When checking for 'selected' always cast to a string, because there's…

    toomuchpete authored
    … no other datatype that can be represented uniqely in an html attribute.
  2. @toomuchpete
  3. @toomuchpete
  4. @toomuchpete
  5. @toomuchpete
Commits on May 23, 2012
  1. @hans-d

    Fix unlinking readonly files throwing an Permission denied exception …

    hans-d authored
    …on Windows.
    
    The file is checked before an unlink is tried. (this will make the tests run slower but is prefered over a if (!unlink { chmod; unlink }.
    See also: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/
  2. @toomuchpete @nateabele

    Adding tests for select helper int/string agnosticism

    toomuchpete authored nateabele committed
  3. @hans-d
  4. @nateabele
  5. @hans-d

    Fix unlinking readonly files throwing an Permission denied exception …

    hans-d authored
    …on Windows.
    
    The file is checked before an unlink is tried. (this will make the tests run slower but is prefered over a if (!unlink { chmod; unlink }.
    See also: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/
  6. @hans-d
  7. @hans-d
This page is out of date. Refresh to see the latest.
View
5 template/helper/Form.php
@@ -598,7 +598,7 @@ protected function _selectOptions(array $list, array $scope) {
$selected = (
(is_array($scope['value']) && in_array($value, $scope['value'])) ||
($scope['empty'] && empty($scope['value']) && $value === '') ||
- ($scope['value'] === (is_integer($value) ? (string) $value : $value) )
+ (is_scalar($scope['value']) && ((string) $scope['value'] === (string) $value))
);
$options = $selected ? array('selected' => true) : array();
$params = compact('value', 'title', 'options');
@@ -622,12 +622,13 @@ public function checkbox($name, array $options = array()) {
$defaults = array('value' => '1', 'hidden' => true);
$options += $defaults;
$default = $options['value'];
+ $key = $name;
$out = '';
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
- if (!isset($options['checked']) && ($bound = $this->binding($name)->data)) {
+ if (!isset($options['checked']) && ($bound = $this->binding($key)->data)) {
$options['checked'] = ($bound == $default);
}
if ($scope['hidden']) {
View
14 test/Unit.php
@@ -988,6 +988,11 @@ protected function _arrayPermute($items, $perms = array()) {
* Uses `DIRECTORY_SEPARATOR` as `getPathname()` is used in a a direct
* string comparison. The method may contain slashes and backslashes.
*
+ * If the file to unlink is readonly, it throws a exception (Permission denied) on Windows.
+ * So, the file is checked before an unlink is tried. (this will make the tests run slower
+ * but is prefered over a if (!unlink { chmod; unlink }.
+ * See: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/
+ *
* @param string $path Path to directory with contents to remove. If first
* character is NOT a slash (`/`) or a Windows drive letter (`C:`)
* prepends `LITHIUM_APP_PATH/resources/tmp/`.
@@ -1010,7 +1015,14 @@ protected function _cleanUp($path = null) {
if ($empty || $iterator->isDot()) {
continue;
}
- ($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname());
+ if ($item->isDir()) {
+ rmdir($item->getPathname());
@gwoo Owner
gwoo added a note

add a continue after this instead of use the else block.

@hans-d
hans-d added a note

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ continue;
+ }
+ if (!$item->isWritable()) {
+ chmod($item->getPathname(), 0777);
+ }
+ unlink($item->getPathname());
}
}
View
48 tests/cases/template/helper/FormTest.php
@@ -381,6 +381,18 @@ public function testCheckboxGeneration() {
'checked' => 'checked', 'id' => 'MockFormPostFoo'
))
));
+
+ $document = new Document(array('model' => $this->_model, 'data' => array('subdocument' => array('foo' => true))));
+ $this->form->create($document);
+
+ $result = $this->form->checkbox('subdocument.foo');
+ $this->assertTags($result, array(
+ array('input' => array('type' => 'hidden', 'value' => '', 'name' => 'subdocument[foo]')),
+ array('input' => array(
+ 'type' => 'checkbox', 'value' => '1', 'name' => 'subdocument[foo]',
+ 'checked' => 'checked', 'id' => 'MockFormPostSubdocumentFoo'
+ ))
+ ));
}
public function testCustomCheckbox() {
@@ -600,6 +612,42 @@ public function testSelectGeneration() {
));
}
+ /**
+ * When trying to determine which option of a select box should be selected, we should be
+ * int/string agnostic because it all looks the same in HTML.
+ */
+ public function testSelectTypeAgnosticism() {
+ $taglist = array(
+ 'select' => array('name' => 'numbers', 'id' => 'Numbers'),
+ array('option' => array('value' => '0')),
+ 'Zero',
+ '/option',
+ array('option' => array('value' => '1', 'selected' => 'selected')),
+ 'One',
+ '/option',
+ array('option' => array('value' => '2')),
+ 'Two',
+ '/option',
+ '/select'
+ );
+
+ $result = $this->form->select(
+ 'numbers',
+ array(0 => 'Zero', 1 => 'One', 2 => 'Two'),
+ array('id' => 'Numbers', 'value' => '1')
+ );
+
+ $this->assertTags($result, $taglist);
+
+ $result = $this->form->select(
+ 'numbers',
+ array('0' => 'Zero', '1' => 'One', '2' => 'Two'),
+ array('id' => 'Numbers', 'value' => 1)
+ );
+
+ $this->assertTags($result, $taglist);
+ }
+
public function testSelectWithEmptyOption() {
$result = $this->form->select('numbers', array('zero', 'first', 'second'), array(
'empty' => true
Something went wrong with that request. Please try again.