Skip to content

Commit

Permalink
Merge branch 'release/3.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaefer committed Apr 12, 2014
2 parents 9d81e8e + 65d5695 commit 293956f
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Config/version.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
Configure::write('Saito.v', '3.5.0');
Configure::write('Saito.v', '3.5.1');

Configure::write('Saito.saitoHomepage', 'http://saito.siezi.com');
21 changes: 21 additions & 0 deletions app/Model/AppModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,25 @@ protected function _setting($name) {
throw new UnexpectedValueException;
}

/**
* Inclusive Validation::range()
*
* @param array $check
* @param float $lower
* @param float $upper
* @return bool
* @see https://github.com/cakephp/cakephp/issues/3304
*/
public function inRange($check, $lower = null, $upper = null) {
$check = reset($check);
if (!is_numeric($check)) {
return false;
}
if (isset($lower) && isset($upper)) {
return ($check >= $lower && $check <= $upper);
}
// fallback to 'parent'
return Validation::range($check, $lower, $upper);
}

}
10 changes: 5 additions & 5 deletions app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ class User extends AppModel {
'message' => '*'
],
'user_place_lat' => [
'numeric' => ['rule' => 'numeric', 'allowEmpty' => true],
'roundedGeoFormat' => ['rule' => '/^\d{1,2}(\.\d{0,4})?$/']
'validLatitude' => ['rule' => ['inRange', -90, 90],
'allowEmpty' => true],
],
'user_place_lng' => [
'numeric' => ['rule' => 'numeric', 'allowEmpty' => true],
'roundedGeoFormat' => ['rule' => '/^\d{1,2}(\.\d{0,4})?$/']
'validLongitude' => ['rule' => ['inRange', -180, 180],
'allowEmpty' => true],
],
'user_place_zoom' => [
'numeric' => ['rule' => ['naturalNumber', 0], 'allowEmpty' => true],
'between' => ['rule' => ['between', 0, 25]]
'between' => ['rule' => ['inRange', 0, 25]]
],
'user_color_actual_posting' => ['rule' => '/^#?[a-f0-9]{0,6}$/i']
];
Expand Down
22 changes: 22 additions & 0 deletions app/Test/Case/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,35 @@ public function testViewSanitation() {
$this->assertTextNotContains('<&Username', $result);
}

public function testMapLinkInMenu() {
$this->generate('Users');
$this->_loginUser(3);

// not enabled, no link
$result = $this->testAction('/users/view/2', ['return' => 'contents']);
$this->assertTextNotContains('/users/map', $result);
$result = $this->testAction('/users/index', ['return' => 'contents']);
$this->assertTextNotContains('/users/map', $result);

// not enabled, link
Configure::write('Saito.Settings.map_enabled', 1);
$result = $this->testAction('/users/view/2', ['return' => 'contents']);
$this->assertTextContains('/users/map', $result);
$result = $this->testAction('/users/index', ['return' => 'contents']);
$this->assertTextContains('/users/map', $result);
}

public function testMapDisabled() {
$this->generate('Users');
$this->_loginUser(3);
$result = $this->testAction('/users/edit/3', ['return' => 'contents']);
$this->assertTextNotContains('class="saito-usermap"', $result);
$this->assertTextNotContains(static::MAPQUEST, $result);

$result = $this->testAction('/users/view/3', ['return' => 'contents']);
$this->assertTextNotContains('class="saito-usermap"', $result);
$this->assertTextNotContains(static::MAPQUEST, $result);

$result = $this->testAction('/users/map', ['return' => 'view']);
$this->assertTextNotContains('class="saito-usermap"', $result);
$this->assertRedirectedTo();
Expand Down
56 changes: 56 additions & 0 deletions app/Test/Case/Model/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,62 @@ public function testSetPassword() {
$this->assertTrue($result);
}

public function testSetPlace() {
$this->User->id = 3;
$success = $this->User->save([
'User' => [
'user_place' => 'Island',
'user_place_lat' => -90.0000,
'user_place_lng' => -180.0000,
'user_place_zoom' => 1
]
]);
$this->assertNotEmpty($success);
$this->User->clear();

$this->User->id = 3;
$success = $this->User->save([
'User' => [
'user_place' => 'Island',
'user_place_lat' => 90.0000,
'user_place_lng' => 180.0000
]
]);
$this->assertNotEmpty($success);
$this->User->clear();

$this->User->id = 3;
$success = $this->User->save([
'User' => [
'user_place' => 'Island',
'user_place_lat' => 90.0001,
'user_place_log' => 180.0001
]
]);
$this->assertFalse($success);
$this->User->clear();

$this->User->id = 3;
$success = $this->User->save(['User' => ['user_place_lat' => -90.0001]]);
$this->assertFalse($success);
$this->User->clear();

$this->User->id = 3;
$success = $this->User->save(['User' => ['user_place_lng' => -180.0001]]);
$this->assertFalse($success);
$this->User->clear();

$this->User->id = 3;
$success = $this->User->save(['User' => ['user_place_zoom' => -1]]);
$this->assertFalse($success);
$this->User->clear();

$this->User->id = 3;
$success = $this->User->save(['User' => ['user_place_zoom' => 26]]);
$this->assertFalse($success);
$this->User->clear();
}

public function testSetUsername() {
$User = $this->getMockForModel('User', ['_dispatchEvent']);
$User->id = 1;
Expand Down
14 changes: 9 additions & 5 deletions app/View/Elements/users/menu.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
'url' => '/users/index',
'title' => __d('page_titles', 'users/index'),
'icon' => 'users'
],
'map' => [
]
];
if (Configure::read('Saito.Settings.map_enabled')) {
$userMenu['map'] = [
'url' => '/users/map',
'title' => __d('page_titles', 'users/map'),
'icon' => 'map-marker'
]
];
];
}
foreach ($userMenu as $m) {
if (strpos($this->here, $m['url']) !== false) {
continue;
Expand All @@ -21,5 +23,7 @@
$m['url'],
['position' => 'right', 'escape' => false]);
}
echo implode($menu);
if (!empty($menu)) {
echo implode($menu);
}
$this->end();

0 comments on commit 293956f

Please sign in to comment.