9df6640a by Joshua Tundag

add both usable

1 parent 856753a2
vendor/
\ No newline at end of file
......@@ -15,5 +15,8 @@
"name": "Joshua",
"email": "josh@baytech.ph"
}
]
],
"require-dev": {
"phpunit/phpunit": "^6"
}
}
......
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
backupGlobals="true"
bootstrap="vendor/autoload.php"
colors="false">
<testsuites>
<testsuite name="BTFlags Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
\ No newline at end of file
......@@ -193,7 +193,8 @@ class FlagManager {
$flags = $this->all();
if(!$flags) return [];
$filteredFlags = array_values(array_filter($flags, function($f) use ($flag, $encrypted){
return ($encrypted ? $f['encrypted_name'] : $f['name']) == $flag;
if($f['both_usable']) return $f['encrypted_name'] == $flag || $f['name'] == $flag;
return (($encrypted && $f['encrypted_name'] == $flag) || (!$encrypted && $f['name']) == $flag);
}));
return count($filteredFlags) ? $filteredFlags[0] : null;
}
......
<?php
use PHPUnit\Framework\TestCase;
final class FlagsTest extends TestCase
{
protected function setUp(){
$this->flags = [
[
"name" => "mode",
"is_encrypted" => false,
"is_filtered" => false,
"encrypted_name" => "15D61712450A686A7F365ADF4FEF581F",
"accepted_values" => [
[
"value" => "live",
"encrypted_value" => "D0DBE915091D400BD8EE7F27F0791303"
],
[
"value" => "test",
"encrypted_value" => "098F6BCD4621D373CADE4E832627B4F6"
]
],
"combined_values" => "",
"has_default" => true,
"default" => "D0DBE915091D400BD8EE7F27F0791303",
"both_usable" => true,
]
];
}
public function testGetFlags(){
$flag = '15D61712450A686A7F365ADF4FEF581F';
$encrypted = false;
$flags = $this->flags;
if(!$flags) return [];
$filteredFlags = array_values(array_filter($flags, function($f) use ($flag, $encrypted){
if($f['both_usable']) return $f['encrypted_name'] == $flag || $f['name'] == $flag;
return (($encrypted && $f['encrypted_name'] == $flag) || (!$encrypted && $f['name']) == $flag);
}));
$foundFlag = count($filteredFlags) ? $filteredFlags[0] : null;
$this->assertEquals('mode', $foundFlag['name']);
}
}
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!