/**
  * Test inserting a new friend that need validation, and try to validate it with the wrong private key for cipher
  *
  * @return void
  */
 public function testValidateFriendFrontErrorEncoding()
 {
     // create a fake request from sample site
     $f = new WpHerissonFriends();
     $e = Encryption::i();
     $e->generateKeyPairs();
     $f->public_key = $e->public;
     $f->url = $this->sampleUrl;
     $f->b_youwant = 1;
     $f->save();
     // Change the key pairs, to create a cipher error
     $e->generateKeyPairs();
     // Check the request is pending
     $friends = WpHerissonFriendsTable::getWhere('url=? and b_youwant=? and is_active=?', array($f->url, 1, 0));
     $this->assertEquals(1, sizeof($friends));
     // encrypt sample url, with sample private key
     $network = new Network();
     $signature = Encryption::i()->privateEncrypt($f->url, $e->private);
     $postData = array('url' => $f->url, 'signature' => $signature);
     // request our installation to validate sample site
     try {
         $content = $network->download(HERISSON_LOCAL_URL . "/validate", $postData);
     } catch (Network\Exception $e) {
         $this->assertEquals(417, $e->getCode());
     }
     // check it's not pending anymore
     $friends = WpHerissonFriendsTable::getWhere('url=? and b_youwant=? and is_active=?', array($f->url, 1, 0));
     $this->assertEquals(1, sizeof($friends));
     // Delete it and check it's not here anymore
     foreach ($friends as $f) {
         $f->delete();
     }
     $friends = WpHerissonFriendsTable::getWhere('url=? and b_youwant=?', array($f->url, 1));
     $this->assertEquals(0, sizeof($friends));
 }