Exemplo n.º 1
0
 /**
  * Tests the getShorten method of the controller
  */
 public function testGetShorten()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $this->call('GET', "ajax/shorten/{$paste->urlkey}/{$paste->hash}");
     $this->assertResponseOk();
 }
Exemplo n.º 2
0
 /**
  * Tests the getFeed method of the controller
  */
 public function testGetFeed()
 {
     $this->initTestStep();
     Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $response = $this->call('GET', 'feed/rss');
     $this->assertResponseOk();
     $this->assertTrue(str_contains($response->headers->get('Content-Type'), 'application/rss+xml'));
 }
Exemplo n.º 3
0
 /**
  * Tests the postRevision method of the controller
  */
 public function testPostRevision()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $this->session(array('paste.revision' => $paste->id));
     $response = $this->call('POST', 'revise', array('id' => $paste->id, 'title' => 'UnitTest::Title', 'data' => 'UnitTest::Revision', 'language' => 'text'));
     $this->assertRedirectedTo($response->getTargetUrl());
     $this->assertEquals(Revision::where('urlkey', $paste->urlkey)->count(), 1);
 }
Exemplo n.º 4
0
 /**
  * Tests the getFlagged method of the controller
  */
 public function testGetFlagged()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $paste->flagged = 1;
     $paste->save();
     $this->call('GET', 'flagged');
     $this->assertResponseOk();
 }
Exemplo n.º 5
0
 /**
  * Tests the postPaste method of the controller
  */
 public function testPostPaste()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $this->call('POST', 'admin/paste', array('search' => $paste->urlkey));
     $this->assertRedirectedTo("admin/paste/{$paste->urlkey}");
 }
Exemplo n.º 6
0
 /**
  * Creates a new paste revision
  *
  * @return \Illuminate\Support\Facades\Redirect
  */
 public function postRevision()
 {
     $oldId = Input::get('id');
     // First and foremost, validate the ID of the revision
     if (Session::get('paste.revision') != $oldId) {
         App::abort(401);
         // Unauthorized
     }
     // Define validation rules. We don't validate the title and language
     // here as we don't allow to change that for a revision. Instead, we
     // will use the data from the old paste
     $validator = Validator::make(Input::all(), array('data' => 'required|auth', 'expire' => 'in:' . Paste::getExpiration('create', TRUE)));
     // Generate anti-spam modules
     $antispam = Antispam::make('paste', 'data');
     // Run validations
     $resultValidation = $validator->passes();
     // Execute antispam services
     $resultAntispam = $antispam->passes();
     if ($resultValidation and $resultAntispam) {
         // Get the paste being revised
         $oldPaste = Paste::findOrFail($oldId);
         // If the old paste's content is same as the revision,
         // we simply redirect to the old paste itself
         if (crc32($oldPaste->data) == crc32(Input::get('data'))) {
             return Redirect::to($oldPaste->urlkey);
         }
         // We use some data from the old paste
         $data = array('project' => $oldPaste->project, 'title' => $oldPaste->title, 'language' => $oldPaste->language, 'private' => NULL, 'password' => NULL, 'attachment' => NULL);
         // Merge it with the input to override the values the user submitted
         Input::merge($data);
         // All set, create the new revision
         $newPaste = Paste::createNew('web', Input::all());
         // We now need to update the revisions table. One entry will be
         // created for this revision. We will also create entries for
         // any past revisions and link it to this new paste
         $revData = array(array('paste_id' => $newPaste->id, 'urlkey' => $oldPaste->urlkey, 'author' => $oldPaste->author, 'timestamp' => $oldPaste->timestamp));
         foreach ($oldPaste->revisions as $revision) {
             $revData[] = array('paste_id' => $newPaste->id, 'urlkey' => $revision->urlkey, 'author' => $revision->author, 'timestamp' => $revision->timestamp);
         }
         // Now insert this batch data to the revisions table
         Revision::insert($revData);
         // Whoa, finally we are done, take the user to the shiny new
         // paste. Since this is a public paste, we don't need the url
         // hash or password shebang
         return Redirect::to($newPaste->urlkey);
     } else {
         // Set the error message as flashdata
         if (!$resultValidation) {
             Session::flash('messages.error', $validator->messages()->all('<p>:message</p>'));
         } else {
             if (!$resultAntispam) {
                 Session::flash('messages.error', $antispam->message());
             }
         }
     }
     return Redirect::to(URL::previous())->withInput();
 }
Exemplo n.º 7
0
 /**
  * Tests the postRevision method of the controller without
  * guest posts enabled
  */
 public function testPostRevisionNoGuest()
 {
     $this->initTestStep(FALSE);
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $this->session(array('paste.revision' => $paste->id));
     $response = $this->call('POST', 'revise', array('id' => $paste->id, 'title' => 'UnitTest::Title', 'data' => 'UnitTest::Revision', 'language' => 'text'));
     $this->assertSessionHas('messages.error');
     $this->assertEquals(Revision::where('urlkey', $paste->urlkey)->count(), 0);
 }
Exemplo n.º 8
0
 /**
  * Creates a new paste via the API
  *
  * @param  string  $mode
  * @return \Illuminate\Support\Facades\View
  */
 public function postCreate($mode)
 {
     $api = API::make($mode);
     // Set custom messages for validation module
     $custom = array('title.max' => 'title_max_30', 'data.required' => 'data_required', 'data.auth' => 'cannot_post', 'data.mbmax' => 'data_too_big', 'language.required' => 'lang_required', 'language.in' => 'lang_invalid', 'expire.integer' => 'expire_integer', 'expire.in' => 'expire_invalid');
     // Define validation rules
     $validator = Validator::make(Input::all(), array('title' => 'max:30', 'data' => 'required|auth|mbmax:' . Site::config('general')->maxPasteSize, 'language' => 'required|in:' . Highlighter::make()->languages(TRUE), 'expire' => 'integer|in:' . Paste::getExpiration('create', TRUE)), $custom);
     // Run validations
     if ($validator->fails()) {
         return $api->error($validator->messages()->first());
     }
     // Set custom messages for the antispam module
     $custom = array('ipban' => 'antispam_ipban', 'stealth' => 'antispam_stealth', 'censor' => 'antispam_censor', 'noflood' => 'antispam_noflood', 'php' => 'antispam_php');
     // Instantiate the antispam module
     $antispam = Antispam::make('api_call', 'data', $custom);
     // Run the anti-spam modules
     if ($antispam->fails()) {
         return $api->error($antispam->message());
     }
     // Create the paste like a boss!
     $paste = Paste::createNew('api', Input::all());
     // All done! Now we need to output the urlkey and hash
     $data = array('urlkey' => $paste->urlkey, 'hash' => $paste->hash);
     // Return the output
     return $api->out('create', $data);
 }
Exemplo n.º 9
0
 /**
  * Tests the getList method of the controller
  * for the XML API
  */
 public function testGetListXml()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $response = $this->call('GET', 'api/xml/list');
     $this->assertResponseOk();
     $this->assertTrue(str_contains($response->headers->get('Content-Type'), 'text/xml'));
 }
Exemplo n.º 10
0
 /**
  * Tests the postComment method of the controller
  */
 public function testPostComment()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     $this->call('POST', 'comment', array('id' => $paste->id, 'comment' => 'UnitTest::Comment'));
     $this->assertFalse($this->app['session.store']->has('messages.error'));
     $this->assertEquals(Comment::where('paste_id', $paste->id)->count(), 1);
 }