| @@ 11-122 (lines=112) @@ | ||
| 8 | ||
| 9 | session_start(); |
|
| 10 | ||
| 11 | class TestCompose |
|
| 12 | extends |
|
| 13 | PHPUnit_Framework_TestCase |
|
| 14 | { |
|
| 15 | ||
| 16 | protected $obRegister; |
|
| 17 | protected $obCompose; |
|
| 18 | ||
| 19 | ||
| 20 | public function setUp() |
|
| 21 | { |
|
| 22 | $this->obRegister = new Register(); |
|
| 23 | } |
|
| 24 | ||
| 25 | ||
| 26 | public function test_authRegister() |
|
| 27 | { |
|
| 28 | ||
| 29 | $output = $this->obRegister->authRegister( |
|
| 30 | [ |
|
| 31 | "name" => 'Test', |
|
| 32 | "email" => '[email protected]', |
|
| 33 | "username" => 'test', |
|
| 34 | "mob" => '1234567890', |
|
| 35 | "passRegister" => 'testing' |
|
| 36 | ] |
|
| 37 | ); |
|
| 38 | $output = (array)json_decode($output); |
|
| 39 | $this->assertEquals([ |
|
| 40 | 'location' => 'http://127.0.0.1/openchat/views/account.php' |
|
| 41 | ], $output); |
|
| 42 | $sessionId = session_id(); |
|
| 43 | return $sessionId; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @depends test_authRegister |
|
| 48 | * Testing for the register with empty username |
|
| 49 | */ |
|
| 50 | public function test_authRegister2($sessionId) |
|
| 51 | { |
|
| 52 | $expectedOutput = [ |
|
| 53 | "Compose" => [ |
|
| 54 | "0" => (object)[ |
|
| 55 | "login_id" => "1", |
|
| 56 | "name" => "Test", |
|
| 57 | "email" => "[email protected]", |
|
| 58 | "username" => "test", |
|
| 59 | "mobile" => "1234567890", |
|
| 60 | "login_status" => "0" |
|
| 61 | ] |
|
| 62 | ] |
|
| 63 | ]; |
|
| 64 | ||
| 65 | $output = $this->obRegister->authRegister( |
|
| 66 | [ |
|
| 67 | "name" => 'Test2', |
|
| 68 | "email" => '[email protected]', |
|
| 69 | "username" => 'test2', |
|
| 70 | "mob" => '1234567890', |
|
| 71 | "passRegister" => 'testing' |
|
| 72 | ] |
|
| 73 | ); |
|
| 74 | $output = (array)json_decode($output); |
|
| 75 | $this->assertEquals([ |
|
| 76 | 'location' => 'http://127.0.0.1/openchat/views/account.php' |
|
| 77 | ], $output); |
|
| 78 | $compose = new Compose($sessionId); |
|
| 79 | ||
| 80 | // Matched not found |
|
| 81 | $output = $compose->selectUser((object)["value" => "ank"]); |
|
| 82 | $output = (array)json_decode($output); |
|
| 83 | $this->assertEquals(["Compose" => "Not Found"], $output); |
|
| 84 | ||
| 85 | // For suggestion matched |
|
| 86 | $output = $compose->selectUser((object)["value" => "t"]); |
|
| 87 | $output = (array)json_decode($output); |
|
| 88 | $this->assertEquals($expectedOutput, $output); |
|
| 89 | ||
| 90 | // Not Found |
|
| 91 | $output = $compose->selectUser((object)["value" => ""]); |
|
| 92 | $output = (array)json_decode($output); |
|
| 93 | $this->assertEquals(["Compose" => "Not Found"], $output); |
|
| 94 | ||
| 95 | // Query Failed |
|
| 96 | $output = $compose->selectUser((object)["value" => "'"]); |
|
| 97 | $output = (array)json_decode($output); |
|
| 98 | $this->assertEquals(["Compose" => "Query Failed"], $output); |
|
| 99 | ||
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * @depends test_authRegister |
|
| 104 | * Empty the DB |
|
| 105 | */ |
|
| 106 | public function test_EmptyDB() |
|
| 107 | { |
|
| 108 | $connect = mysqli_connect( |
|
| 109 | getenv('DB_HOST'), |
|
| 110 | getenv('DB_USER'), |
|
| 111 | getenv('DB_PASSWORD'), |
|
| 112 | getenv('DB_NAME') |
|
| 113 | ); |
|
| 114 | $query = "TRUNCATE `login`"; |
|
| 115 | $this->assertTrue($connect->query($query)); |
|
| 116 | $query = "TRUNCATE `profile`"; |
|
| 117 | $this->assertTrue($connect->query($query)); |
|
| 118 | $query = "TRUNCATE `register`"; |
|
| 119 | $this->assertTrue($connect->query($query)); |
|
| 120 | } |
|
| 121 | ||
| 122 | } |
|
| 123 | ||
| @@ 14-125 (lines=112) @@ | ||
| 11 | $dotenv->load(); |
|
| 12 | session_start(); |
|
| 13 | ||
| 14 | class TestSearch |
|
| 15 | extends |
|
| 16 | PHPUnit_Framework_TestCase |
|
| 17 | { |
|
| 18 | ||
| 19 | protected $obRegister; |
|
| 20 | protected $obCompose; |
|
| 21 | ||
| 22 | ||
| 23 | public function setUp() |
|
| 24 | { |
|
| 25 | $this->obRegister = new Register(); |
|
| 26 | } |
|
| 27 | ||
| 28 | ||
| 29 | public function test_authRegister() |
|
| 30 | { |
|
| 31 | ||
| 32 | $output = $this->obRegister->authRegister( |
|
| 33 | [ |
|
| 34 | "name" => 'Test', |
|
| 35 | "email" => '[email protected]', |
|
| 36 | "username" => 'test', |
|
| 37 | "mob" => '1234567890', |
|
| 38 | "passRegister" => 'testing' |
|
| 39 | ] |
|
| 40 | ); |
|
| 41 | $output = (array)json_decode($output); |
|
| 42 | $this->assertEquals([ |
|
| 43 | 'location' => 'http://127.0.0.1/openchat/views/account.php' |
|
| 44 | ], $output); |
|
| 45 | $sessionId = session_id(); |
|
| 46 | return $sessionId; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * @depends test_authRegister |
|
| 51 | * Testing for the register with empty username |
|
| 52 | */ |
|
| 53 | public function test_authRegister2($sessionId) |
|
| 54 | { |
|
| 55 | $expectedOutput = [ |
|
| 56 | "Compose" => [ |
|
| 57 | "0" => (object)[ |
|
| 58 | "login_id" => "1", |
|
| 59 | "name" => "Test", |
|
| 60 | "email" => "[email protected]", |
|
| 61 | "username" => "test", |
|
| 62 | "mobile" => "1234567890", |
|
| 63 | "login_status" => "0" |
|
| 64 | ] |
|
| 65 | ] |
|
| 66 | ]; |
|
| 67 | ||
| 68 | $output = $this->obRegister->authRegister( |
|
| 69 | [ |
|
| 70 | "name" => 'Test2', |
|
| 71 | "email" => '[email protected]', |
|
| 72 | "username" => 'test2', |
|
| 73 | "mob" => '1234567890', |
|
| 74 | "passRegister" => 'testing' |
|
| 75 | ] |
|
| 76 | ); |
|
| 77 | $output = (array)json_decode($output); |
|
| 78 | $this->assertEquals([ |
|
| 79 | 'location' => 'http://127.0.0.1/openchat/views/account.php' |
|
| 80 | ], $output); |
|
| 81 | $search = new Search($sessionId); |
|
| 82 | ||
| 83 | // Matched not found |
|
| 84 | $output = $search->searchItem((object)["value" => "ank"]); |
|
| 85 | $output = (array)json_decode($output); |
|
| 86 | $this->assertEquals(["Search" => "Not Found"], $output); |
|
| 87 | ||
| 88 | // For suggestion matched but not in total messages |
|
| 89 | $output = $search->searchItem((object)["value" => "T"]); |
|
| 90 | $output = (array)json_decode($output); |
|
| 91 | $this->assertEquals(["Search" => "Not Found"], $output); |
|
| 92 | ||
| 93 | // Not Found |
|
| 94 | $output = $search->searchItem((object)["value" => ""]); |
|
| 95 | $output = (array)json_decode($output); |
|
| 96 | $this->assertEquals(["Search" => "Not Found"], $output); |
|
| 97 | ||
| 98 | // Query Failed |
|
| 99 | $output = $search->searchItem((object)["value" => "'"]); |
|
| 100 | $output = (array)json_decode($output); |
|
| 101 | $this->assertEquals(["Search" => "Not Found"], $output); |
|
| 102 | ||
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * @depends test_authRegister |
|
| 107 | * Empty the DB |
|
| 108 | */ |
|
| 109 | public function test_EmptyDB() |
|
| 110 | { |
|
| 111 | $connect = mysqli_connect( |
|
| 112 | getenv('DB_HOST'), |
|
| 113 | getenv('DB_USER'), |
|
| 114 | getenv('DB_PASSWORD'), |
|
| 115 | getenv('DB_NAME') |
|
| 116 | ); |
|
| 117 | $query = "TRUNCATE `login`"; |
|
| 118 | $this->assertTrue($connect->query($query)); |
|
| 119 | $query = "TRUNCATE `profile`"; |
|
| 120 | $this->assertTrue($connect->query($query)); |
|
| 121 | $query = "TRUNCATE `register`"; |
|
| 122 | $this->assertTrue($connect->query($query)); |
|
| 123 | } |
|
| 124 | ||
| 125 | } |
|
| 126 | ||