コード例 #1
0
 public function testShopPurchaseHandlesNoItemNoQuantity()
 {
     // Inject post request.
     RequestWrapper::inject(new Request([], []));
     $shop = new ShopController();
     $shop_outcome = $shop->buy();
     $this->assertNotEmpty($shop_outcome);
 }
コード例 #2
0
 public function tearDown()
 {
     $this->char = null;
     TestAccountCreateAndDestroy::destroy();
     RequestWrapper::inject(new Request([]));
     $session = SessionFactory::getSession();
     $session->invalidate();
 }
コード例 #3
0
 protected function setUp()
 {
     $get = ['id' => 7, 'ninja_name' => 5, 'some_negative_int' => -444, 'some_int' => 66, 'garbage_field' => 'Robert\'); drop table students; --'];
     $post = ['hidden_post' => 1, 'post_post_field' => 'Bob', 'post_negative_int' => -234, 'post_some_int' => 34, 'post_garbage_field' => 'Robert\'); drop table students; --'];
     $request = new Request($get, $post);
     RequestWrapper::inject($request);
     // Pass a request to be used by tests
 }
コード例 #4
0
 function tearDown()
 {
     removeItem($this->char->id(), self::ITEM);
     TestAccountCreateAndDestroy::destroy();
     RequestWrapper::inject(new Request([]));
     $session = SessionFactory::getSession();
     $session->invalidate();
 }
コード例 #5
0
 protected function setUp()
 {
     $get = ['id' => 7, 'ninja_name' => 5];
     $post = ['hidden_post' => 1, 'some_post_field' => 'Bob'];
     $request = new Request($get, $post);
     RequestWrapper::inject($request);
     // Pass a request to be used by tests
 }
コード例 #6
0
 public function tearDown()
 {
     $this->inventory->remove(self::ITEM);
     TestAccountCreateAndDestroy::destroy();
     RequestWrapper::inject(new Request([]));
     $session = SessionFactory::getSession();
     $session->invalidate();
     parent::tearDown();
 }
コード例 #7
0
 public function setUp()
 {
     parent::setUp();
     SessionFactory::init(new MockArraySessionStorage());
     $char_id = TestAccountCreateAndDestroy::create_testing_account();
     SessionFactory::getSession()->set('player_id', $char_id);
     $request = new Request([], []);
     RequestWrapper::inject($request);
 }
コード例 #8
0
 protected function setUp()
 {
     $this->markTestIncomplete('AccountController::render relies on the DB.');
     SessionFactory::init(new MockArraySessionStorage());
     $get = ['command' => 'change'];
     $request = new Request($get);
     RequestWrapper::inject($request);
     // Pass a request to be used by tests
 }
コード例 #9
0
 public function testSearch()
 {
     $request = new Request(['term' => $this->char->uname, 'limit' => 5], []);
     RequestWrapper::inject($request);
     $result = $this->controller->nw_json('char_search', self::CALLBACK);
     $payload = $this->extractPayload($result);
     $this->assertObjectHasAttribute('char_matches', $payload);
     $this->assertCount(1, $payload->char_matches);
     $this->assertObjectHasAttribute('uname', $payload->char_matches[0]);
     $this->assertObjectHasAttribute('player_id', $payload->char_matches[0]);
 }
コード例 #10
0
 public function testViewingOfPlayerProfileMyselfViewingOwnProfile()
 {
     $viewing_char_id = $this->char->id();
     $request = new Request(['player_id' => $viewing_char_id]);
     RequestWrapper::inject($request);
     $sess = SessionFactory::getSession();
     $sess->set('player_id', $this->char->id());
     $player = new PlayerController();
     $player_outcome = $player->index();
     $this->assertNotEmpty($player_outcome);
 }
コード例 #11
0
 public function testWorkDoesNothingWithNegativeWorkRequest()
 {
     // Note that this had to have an active logged in character to not just get an ignored result of "0" gold.
     $this->char = TestAccountCreateAndDestroy::char();
     SessionFactory::getSession()->set('player_id', $this->char->id());
     $request = new Request([], ['worked' => -999]);
     RequestWrapper::inject($request);
     $work = new WorkController();
     $work_response = $work->requestWork();
     $earned_gold = $work_response['parts']['earned_gold'];
     $this->assertEquals("0", $earned_gold);
 }
コード例 #12
0
 public function testDeleteWithEmptyPassword()
 {
     RequestWrapper::inject(new Request(['passw' => '']));
     $session = SessionFactory::getSession();
     $failure_count = $session->get('delete_attempts');
     $controller = new AccountController();
     $response = $controller->deleteAccount();
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertNotEmpty($response_data['error']);
     $this->assertGreaterThan($failure_count, $session->get('delete_attempts'));
 }
コード例 #13
0
 public function testWorkDoesNothingWithNegativeWorkRequest()
 {
     // Note that this had to have an active logged in character to not just get an ignored result of "0" gold.
     $this->char = TestAccountCreateAndDestroy::char();
     SessionFactory::getSession()->set('player_id', $this->char->id());
     $request = new Request([], ['worked' => -999]);
     RequestWrapper::inject($request);
     $work = new WorkController();
     $response = $work->requestWork($this->m_dependencies);
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $earned_gold = $response_data['earned_gold'];
     $this->assertEquals("0", $earned_gold);
 }
コード例 #14
0
 public function testAttackWhenDead()
 {
     $attacker = Player::find(SessionFactory::getSession()->get('player_id'));
     $attacker->death();
     $attacker->save();
     $char_id_2 = TestAccountCreateAndDestroy::char_id_2();
     $params = ['target' => $char_id_2];
     $request = Request::create('/attack', 'GET', $params);
     RequestWrapper::inject($request);
     $response = $this->controller->index($this->m_dependencies);
     $this->assertInstanceOf(StreamedViewResponse::class, $response);
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertNotEmpty($response_data['error']);
 }
コード例 #15
0
 public function testOfferOfBadNegativeBribe()
 {
     $request = new Request(['bribe' => -40]);
     RequestWrapper::inject($request);
     $bounty_set = 4444;
     $initial_gold = 7777;
     $this->char->setBounty($bounty_set);
     $this->char->setGold($initial_gold);
     $this->char->save();
     $doshin = new DoshinController();
     $doshin->bribe($this->m_dependencies);
     $final_char = Player::find($this->char->id());
     $this->assertLessThan(7777, $final_char->gold);
     $modified_bounty = $final_char->bounty;
     $this->assertLessThan($bounty_set, $modified_bounty);
     $this->assertGreaterThan(0, $modified_bounty);
 }
コード例 #16
0
 public function testKickAsMember()
 {
     $this->setExpectedException(\RuntimeException::class);
     $char_id_1 = $this->m_dependencies['session']->get('player_id');
     // create new character
     $char_id_2 = TestAccountCreateAndDestroy::char_id_2();
     // add new character to clan
     $this->clan->addMember(Player::find($char_id_2), Player::find($char_id_1));
     // switch session to new character
     $this->m_dependencies['session']->set('player_id', $char_id_2);
     // try to kick
     $request = Request::create('/clan/kick', 'GET', ['kicked' => $char_id_1]);
     RequestWrapper::inject($request);
     $response = $this->controller->kick($this->m_dependencies);
 }
コード例 #17
0
 public function testPostResetWithInvalidatedTokenYeildsError()
 {
     $this->nonce = $token = '34838383838';
     PasswordResetRequest::generate($this->account, $token);
     $request = Request::create('/password/post_reset/');
     $request->setMethod('POST');
     $request->request->set('token', $token);
     $password = '******';
     $request->request->set('new_password', $password);
     $request->request->set('password_confirmation', $password);
     $request->request->set('email', $this->account->getActiveEmail());
     RequestWrapper::inject($request);
     // Invalidate the token
     PasswordResetRequest::where('_account_id', '=', $this->account->id())->update(['used' => true]);
     // Now run the controller method to reset!
     $controller = new PasswordController();
     $response = $controller->postReset($this->m_dependencies);
     $this->assertTrue(stripos($response->getTargetUrl(), rawurlencode('Token was invalid')) !== false, 'Url was [' . $response->getTargetUrl() . '] instead of expected not long enough password error url.');
     // Password should be changed.
     $this->assertFalse($this->checkTestPasswordMatches($password), 'Password should not have been changed on a rejection!');
 }
コード例 #18
0
 public function testIndex()
 {
     RequestWrapper::inject(new Request());
     $response = $this->controller->index();
     $this->assertInstanceOf(StreamedViewResponse::class, $response);
 }
コード例 #19
0
 /**
  */
 public function testDojoChangeClassLowTurnsDoesNotError()
 {
     $request = Request::create('/', 'GET', ['requested_identity' => 'crane']);
     RequestWrapper::inject($request);
     $char = Player::find($this->char_id);
     $char->setStrength(400);
     $char->setTurns(0);
     $char->save();
     $this->assertNotEmpty($this->controller->changeClass($this->m_dependencies));
 }
コード例 #20
0
 public function testUseHarmonizeOnSelf()
 {
     $this->char->setTurns(300);
     $this->char->ki = 1000;
     $this->char->level = 20;
     $this->char->harm(floor($this->char->getMaxHealth() / 2));
     $this->char->save();
     $initial_health = $this->char->health;
     $this->assertGreaterThan($initial_health, $this->char->getMaxHealth());
     RequestWrapper::inject(Request::create('/skill/self_use/Harmonize/'));
     $controller = new SkillController();
     $controller->update_timer = false;
     $response = $controller->selfUse();
     $this->assertNotInstanceOf(RedirectResponse::class, $response, 'A redirect was the outcome for the url: ' . ($response instanceof RedirectResponse ? $response->getTargetUrl() : ''));
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertEquals('Harmonize', $response_data['act']);
     $final_char = Player::find($this->char->id());
     $this->assertGreaterThan($initial_health, $final_char->health);
 }
コード例 #21
0
 public function testViewClan()
 {
     RequestWrapper::inject(new Request());
     $response = $this->controller->viewClan($this->m_dependencies);
     $this->assertInstanceOf(StreamedViewResponse::class, $response);
 }
コード例 #22
0
 function testAttemptLoginOfUnconfirmedAccountShouldFail()
 {
     $email = '*****@*****.**';
     // Create a non-autoconfirmed user
     TestAccountCreateAndDestroy::create_testing_account(false, $email);
     RequestWrapper::inject(new Request([]));
     $controller = new LoginController();
     $res = $controller->performLogin($email, $this->test_password);
     $this->assertNotEmpty($res, 'No error returned');
 }
コード例 #23
0
 public function testRandomEncounter()
 {
     $this->controller = new NpcController(['randomness' => function () {
         return 1;
     }]);
     RequestWrapper::inject(Request::create('/npc/attack/peasant'));
     $response = $this->controller->attack($this->m_dependencies);
     $this->assertNotEmpty($response);
 }
コード例 #24
0
 public function testLoginShouldFailOnBlanks()
 {
     $account = Account::findById(TestAccountCreateAndDestroy::account_id());
     $this->assertInstanceOf(Account::class, $account);
     $account->confirmed = 0;
     $account->save();
     $request = new Request([], ['user' => '', 'pass' => '']);
     // TestAccountCreateAndDestroy::$test_password
     RequestWrapper::inject($request);
     $controller = new LoginController();
     $res = $controller->requestLogin($this->m_dependencies);
     $this->assertInstanceOf(RedirectResponse::class, $res);
     $this->assertTrue(stripos($res->getTargetUrl(), 'error') !== false);
 }
コード例 #25
0
 public function testPartialHealWithZeroGoldGivesErrorInPageParts()
 {
     $request = new Request(['heal_points' => 999], []);
     RequestWrapper::inject($request);
     $this->char->harm((int) floor($this->char->health / 2));
     // Have to be wounded first.
     $this->char->setGold(0);
     $initial_health = $this->char->health;
     $this->assertGreaterThan(0, $initial_health);
     $this->char->save();
     $this->char->setClass('viper');
     // Default dragon class has chi skill
     $cont = new ShrineController();
     $response = $cont->heal($this->m_dependencies);
     $final_char = Player::find($this->char->id());
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertNotEmpty($response_data['error']);
     $this->assertEquals($initial_health, $final_char->health);
 }
コード例 #26
0
 public function testLatestMessage()
 {
     $request = new Request(['type' => 'latest_message', 'jsoncallback' => self::CALLBACK], []);
     RequestWrapper::inject($request);
     $result = $this->controller->nw_json();
     $payload = $this->extractPayload($result);
     $this->assertObjectHasAttribute('message', $payload);
 }
コード例 #27
0
 public function testShopCannotBuyInvalidItem()
 {
     $pc = Player::findPlayable($this->account->id());
     $pc->gold = $pc->gold + 9999;
     $pc->save();
     $request = new Request([], ['quantity' => 4, 'item' => 'zigzigX']);
     RequestWrapper::inject($request);
     $shop = new ShopController();
     $response = $shop->buy();
     $this->assertNotEmpty($response);
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertFalse($response_data['valid']);
 }
コード例 #28
0
 public function testSuccessfulSignupResultsInNoConfirmation()
 {
     $uname = 'KnownGood';
     $email = '*****@*****.**';
     // Due to the nature of hotmail, hotmail emails are listed
     // such that they will not be preconfirmed.  This leaves an account needing confirmation.
     RequestWrapper::inject(new Request(['key' => 'password1', 'cpass' => 'password1', 'send_email' => $email, 'send_name' => $uname]));
     $controller = new SignupController();
     $response = $controller->signup($this->m_dependencies);
     $account = Account::findByEmail($email);
     $player = Player::findByName($uname);
     $this->assertNotNull($player);
     $this->assertNotNull($account);
     $query_relationship = 'SELECT count(*) FROM account_players WHERE _account_id = :id1 AND _player_id = :id2';
     $account_unconfirmed = null;
     if ($account && $player) {
         $relationship_count = query_item($query_relationship, [':id1' => $account->id(), ':id2' => $player->id()]);
         $account_unconfirmed = !$account->isConfirmed();
     } else {
         $relationship_count = 0;
     }
     $delete_player = 'DELETE FROM players WHERE player_id = :id';
     $delete_account = 'DELETE FROM accounts WHERE account_id = :id';
     $delete_relationship = 'DELETE FROM account_players WHERE _account_id = :id1 OR _player_id = :id2';
     query($delete_player, [':id' => $player->id()]);
     query($delete_account, [':id' => $account->id()]);
     query($delete_relationship, [':id1' => $account->id(), ':id2' => $player->id()]);
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertTrue($response_data['submit_successful'], 'Signup() returned error: ' . $response_data['error']);
     $this->assertEquals($relationship_count, 1);
     $this->assertTrue($account_unconfirmed);
 }
コード例 #29
0
 public function testPartialHealWithZeroGoldGivesErrorInPageParts()
 {
     $request = new Request(['heal_points' => 999], []);
     RequestWrapper::inject($request);
     $this->char->harm(30);
     // Have to be wounded first.
     $this->char->set_gold(0);
     $initial_health = $this->char->health();
     $this->char->save();
     $this->char->setClass('viper');
     // Default dragon class has chi skill
     $cont = new ShrineController();
     $result = $cont->heal();
     $final_char = Player::find($this->char->id());
     $this->assertNotEmpty($result['parts']['error']);
     $this->assertEquals($initial_health, $final_char->health());
 }