Ejemplo n.º 1
0
 public function testIndexOnLogined()
 {
     $this->getWithLogined('/user/pastebin')->assertResponseOk();
     $all = $this->pasteBin->whereUserId($this->twitterId)->whereUserSn($this->twitterScreenName)->get();
     foreach ($all as $pb) {
         $this->see($pb->description)->see($pb->code)->see("/pastebin/show/{$pb->hash}")->see("/user/pastebin/edit/{$pb->hash}")->see("/user/pastebin/delete/{$pb->hash}");
     }
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider newDataProvider
  *
  * @param string      $description
  * @param string      $code
  * @param string      $protect
  * @param string|null $user_id
  * @param string|null $user_sn
  */
 public function testNew($description, $code, $protect, $user_id, $user_sn)
 {
     if (isset($user_id, $user_sn)) {
         $this->withSession(['twitter.login' => true, 'twitter.me.id' => $user_id, 'twitter.me.sn' => $user_sn]);
     }
     $this->visit('/pastebin/new')->see('New PasteBin')->see('/pastebin/new')->see('noindex,nofollow')->dontSee('index,follow')->assertResponseOk();
     $this->see('Description')->type($description, 'description')->see('Code')->type($code, 'code')->see('Permission')->select($protect, 'protect')->see('Create')->press('Create!');
     $hash = $this->pasteBin->whereDescription($description)->whereCode($code)->get()->first()->hash;
     $this->seePageIs("/pastebin/show/{$hash}")->see('作成が完了しました。')->assertResponseOk();
 }
Ejemplo n.º 3
0
 /**
  * Show page (get).
  *
  * @Get("show/{hash}", as="pastebin.show")
  *
  * @param string $hash
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getShow($hash)
 {
     $paste_bin = $this->pasteBin->where('hash', $hash)->get()->first();
     if (!isset($paste_bin)) {
         abort(404);
     }
     $isProtect = $paste_bin->protect === true || $paste_bin->protect === '1';
     $robots = $isProtect ? 'noindex,nofollow' : null;
     $showAlert = $isProtect;
     return view('pastebins.show', compact('paste_bin', 'robots', 'showAlert'));
 }
Ejemplo n.º 4
0
 /**
  * Delete page (post).
  *
  * @Post("delete/{hash}", as="user.pastebin.delete")
  *
  * @param string $hash
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postDelete($hash)
 {
     $pb = $this->pasteBin->whereHash($hash)->get()->first();
     if (!isset($pb)) {
         abort(404);
     }
     if ($pb->user_id !== $this->user_id) {
         return redirect('user/pastebin')->with('message', 'そのメモはあなたのメモではありません。');
     }
     $pb->delete();
     return redirect('user/pastebin')->with('message', '削除しました。');
 }
Ejemplo n.º 5
0
 /**
  * Create sitemap data.
  *
  * @return array
  */
 protected function createSiteMapData()
 {
     $data = [];
     $pasteBin = new M\PasteBin();
     $last = $pasteBin->orderBy('id')->get()->last();
     $data[] = ['loc' => '/pastebin', 'lastmod' => $last->created_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.7'];
     $all = $pasteBin->select(['hash', 'created_at'])->where('protect', '=', false)->get();
     foreach ($all as $p) {
         $data[] = ['loc' => "/pastebin/show/{$p->hash}", 'lastmod' => $p->created_at->format('Y-m-d'), 'changefreq' => 'never', 'priority' => '0.4'];
     }
     $memo = new M\Memo();
     $last = $memo->orderBy('id')->get()->last();
     $data[] = ['loc' => '/memo', 'lastmod' => $last->created_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.7'];
     foreach ($memo->select(['id', 'created_at'])->get() as $m) {
         $data[] = ['loc' => "/memo/show/{$m->id}", 'lastmod' => $m->created_at->format('Y-m-d'), 'changefreq' => 'never', 'priority' => '0.4'];
     }
     foreach ($memo->select('user_sn')->distinct()->get() as $m) {
         $updated_at = $memo->where('user_sn', '=', $m->user_sn)->get()->last()->updated_at;
         $data[] = ['loc' => "/memo/user/{$m->user_sn}", 'lastmod' => $updated_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.4'];
     }
     return $data;
 }
Ejemplo n.º 6
0
 /**
  * pastebin/create API.
  *
  * @Any("create", as="api.pastebin.create")
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function anyCreate()
 {
     try {
         $hash = str_random(5);
         $insert = [];
         foreach (['description', 'code', 'protect'] as $v) {
             $insert[$v] = $this->request($v);
         }
         $insert['hash'] = $hash;
         $validate = $this->pasteBin->insert($insert, ['save' => true]);
         if ($validate === true) {
             $data = $this->pasteBin->where('hash', $hash)->get()->first();
             return $this->onSuccess($data);
         }
         throw new RuntimeException($validate->errors()->first(), 400);
     } catch (Exception $e) {
         return $this->onError($e);
     }
 }
Ejemplo n.º 7
0
 /**
  * Test insert method.
  *
  * @dataProvider insertDataProvider
  *
  * @param mixed $hash
  * @param mixed $description
  * @param mixed $code
  * @param mixed $protect
  * @param mixed $user_id
  * @param mixed $user_sn
  * @param bool  $hasError
  */
 public function testInsert($hash, $description, $code, $protect, $user_id, $user_sn, $hasError)
 {
     $data = compact('hash', 'description', 'code', 'protect', 'user_id', 'user_sn');
     $response = $this->pasteBin->insert($data);
     $this->checkError($response, $hasError);
 }
Ejemplo n.º 8
0
 /**
  * @dataProvider allPasteBinDataProvider
  *
  * @param PasteBin $pasteBin
  */
 public function testShow(PasteBin $pasteBin)
 {
     $this->call('GET', '/api/pastebin/show', ['hash' => $pasteBin->hash]);
     $this->seeJsonEquals($pasteBin->toArray())->assertResponseStatus(200);
 }
Ejemplo n.º 9
0
 /**
  * Update paste bin user_sn.
  *
  * @param $userId
  * @param $userSn
  */
 protected function updatePasteBin($userId, $userSn)
 {
     $memo = new PasteBin();
     $all = $memo->select(['user_sn', 'user_id'])->whereUserId($userId)->get();
     foreach ($all as $pb) {
         if ($pb->user_sn === $userSn) {
             continue;
         }
         $pb->user_sn = $userSn;
         $pb->update();
     }
 }