-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78d062a
commit 223734a
Showing
13 changed files
with
242 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/** | ||
* Unit tests for converting coordinates using static methods in Mappr class | ||
* | ||
* PHP Version 5.5 | ||
* | ||
* @author David P. Shorthouse <davidpshorthouse@gmail.com> | ||
* @link http://github.com/dshorthouse/SimpleMappr | ||
* @license Copyright (C) 2013 David P. Shorthouse | ||
* | ||
*/ | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SimpleMappr\Utility; | ||
|
||
class UtilityTest extends TestCase | ||
{ | ||
use SimpleMapprMixin; | ||
|
||
/** | ||
* Test that a hex color is properly converted to array of RGB. | ||
*/ | ||
public function test_hex() | ||
{ | ||
$color = "#FF1177"; | ||
$converted = Utility::hex2Rgb($color); | ||
$this->assertEquals([255, 17, 119], $converted); | ||
} | ||
|
||
/** | ||
* Test that a filename is cleaned of unrecognized characters. | ||
*/ | ||
public function test_filename1() | ||
{ | ||
$filename = "My@ New()*? ë [Filename]'"; | ||
$cleaned = Utility::cleanFilename($filename, "jpg"); | ||
$this->assertEquals("My_New_ë_Filename_.jpg", $cleaned); | ||
} | ||
|
||
/** | ||
* Test that a filename is cleaned of unrecognized characters. | ||
*/ | ||
public function test_filename2() | ||
{ | ||
$filename = "My Map"; | ||
$cleaned = Utility::cleanFilename($filename, "jpg"); | ||
$this->assertEquals("My_Map.jpg", $cleaned); | ||
} | ||
|
||
/** | ||
* Test that a param is loaded. | ||
*/ | ||
public function test_loadParam() | ||
{ | ||
$req = [ | ||
'points' => '45,-120' | ||
]; | ||
$this->setRequest($req); | ||
$points = Utility::loadParam('points', '75,100'); | ||
$this->assertEquals('45,-120', $points); | ||
} | ||
|
||
/** | ||
* Test that a default value for a param is loaded. | ||
*/ | ||
public function test_loadParam_default() | ||
{ | ||
$req = [ | ||
'stuff' => '45,-120' | ||
]; | ||
$this->setRequest($req); | ||
$points = Utility::loadParam('points', '75,100'); | ||
$this->assertEquals('75,100', $points); | ||
} | ||
|
||
/** | ||
* Test that slashes are added to param value. | ||
*/ | ||
public function test_loadParam_slashes() | ||
{ | ||
$req = [ | ||
'stuff' => "here's Some \" Stuff on a \n new line" | ||
]; | ||
$this->setRequest($req); | ||
$points = Utility::loadParam('stuff', ''); | ||
$this->assertEquals("here\'s Some \\\" Stuff on a \n new line", $points); | ||
} | ||
|
||
/** | ||
* Test that empty lines are removed from a value. | ||
*/ | ||
public function test_removeEmptyLines() | ||
{ | ||
$text = "Here \n is \n\n some \n\n\n stuff"; | ||
$cleaned = Utility::removeEmptyLines($text); | ||
$this->assertEquals("Here \n is \n some \n stuff", $cleaned); | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class HashUser extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* Write your reversible migrations using this method. | ||
* | ||
* More information on writing migrations is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class | ||
* | ||
* The following commands can be used in this method and Phinx will | ||
* automatically reverse them when rolling back: | ||
* | ||
* createTable | ||
* renameTable | ||
* addColumn | ||
* renameColumn | ||
* addIndex | ||
* addForeignKey | ||
* | ||
* Remember to call "create()" or "update()" and NOT "save()" when working | ||
* with the Table class. | ||
*/ | ||
public function up() | ||
{ | ||
$table = $this->table('users'); | ||
$table->addColumn('hash', 'string', array('limit' => 60, 'after' => 'uid')) | ||
->save(); | ||
|
||
$rows = $this->fetchAll('SELECT * FROM users'); | ||
foreach($rows as $row) { | ||
$hash = password_hash($row['identifier'], PASSWORD_DEFAULT); | ||
$this->execute(sprintf("UPDATE users set hash = '%s' WHERE uid = %d", $hash, $row['uid'])); | ||
} | ||
|
||
$table->addIndex(array('hash'), array('unique' => true, 'name' => 'idx_users_hash')) | ||
->save(); | ||
} | ||
|
||
public function down() | ||
{ | ||
$table = $this->table('users'); | ||
$table->removeColumn('hash'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.