9df6640a by Joshua Tundag

add both usable

1 parent 856753a2
1 vendor/
...\ No newline at end of file ...\ No newline at end of file
...@@ -15,5 +15,8 @@ ...@@ -15,5 +15,8 @@
15 "name": "Joshua", 15 "name": "Joshua",
16 "email": "josh@baytech.ph" 16 "email": "josh@baytech.ph"
17 } 17 }
18 ] 18 ],
19 "require-dev": {
20 "phpunit/phpunit": "^6"
21 }
19 } 22 }
......
1 <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
3 backupGlobals="true"
4 bootstrap="vendor/autoload.php"
5 colors="false">
6 <testsuites>
7 <testsuite name="BTFlags Test Suite">
8 <directory suffix="Test.php">./tests/</directory>
9 </testsuite>
10 </testsuites>
11 </phpunit>
...\ No newline at end of file ...\ No newline at end of file
...@@ -193,7 +193,8 @@ class FlagManager { ...@@ -193,7 +193,8 @@ class FlagManager {
193 $flags = $this->all(); 193 $flags = $this->all();
194 if(!$flags) return []; 194 if(!$flags) return [];
195 $filteredFlags = array_values(array_filter($flags, function($f) use ($flag, $encrypted){ 195 $filteredFlags = array_values(array_filter($flags, function($f) use ($flag, $encrypted){
196 return ($encrypted ? $f['encrypted_name'] : $f['name']) == $flag; 196 if($f['both_usable']) return $f['encrypted_name'] == $flag || $f['name'] == $flag;
197 return (($encrypted && $f['encrypted_name'] == $flag) || (!$encrypted && $f['name']) == $flag);
197 })); 198 }));
198 return count($filteredFlags) ? $filteredFlags[0] : null; 199 return count($filteredFlags) ? $filteredFlags[0] : null;
199 } 200 }
......
1 <?php
2 use PHPUnit\Framework\TestCase;
3
4 final class FlagsTest extends TestCase
5 {
6
7 protected function setUp(){
8 $this->flags = [
9 [
10 "name" => "mode",
11 "is_encrypted" => false,
12 "is_filtered" => false,
13 "encrypted_name" => "15D61712450A686A7F365ADF4FEF581F",
14 "accepted_values" => [
15 [
16 "value" => "live",
17 "encrypted_value" => "D0DBE915091D400BD8EE7F27F0791303"
18 ],
19 [
20 "value" => "test",
21 "encrypted_value" => "098F6BCD4621D373CADE4E832627B4F6"
22 ]
23 ],
24 "combined_values" => "",
25 "has_default" => true,
26 "default" => "D0DBE915091D400BD8EE7F27F0791303",
27 "both_usable" => true,
28 ]
29 ];
30 }
31
32 public function testGetFlags(){
33 $flag = '15D61712450A686A7F365ADF4FEF581F';
34 $encrypted = false;
35 $flags = $this->flags;
36 if(!$flags) return [];
37 $filteredFlags = array_values(array_filter($flags, function($f) use ($flag, $encrypted){
38 if($f['both_usable']) return $f['encrypted_name'] == $flag || $f['name'] == $flag;
39 return (($encrypted && $f['encrypted_name'] == $flag) || (!$encrypted && $f['name']) == $flag);
40 }));
41 $foundFlag = count($filteredFlags) ? $filteredFlags[0] : null;
42
43 $this->assertEquals('mode', $foundFlag['name']);
44 }
45
46 }
...\ No newline at end of file ...\ 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!