/**
  * A basic functional test example.
  *
  * @return void
  */
 public function testViewingPopularPuzzles()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'johndoe1']);
     $name = $faker->sentence;
     $width = 10;
     $height = 10;
     $blackSquares = array();
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $puzzleSquares = array();
     $clues = array();
     $args = array('name' => 'My first puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle1 = Puzzle::create($args);
     $args = array('name' => 'My second puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle2 = Puzzle::create($args);
     $args = array('name' => 'My third puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle3 = Puzzle::create($args);
     $args = array('name' => 'My fourth puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle4 = Puzzle::create($args);
     $args = array('name' => 'My fifth puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle5 = Puzzle::create($args);
     /*
     //sqlite doesn't like from_unixtime()
     $this->visit('/puzzles/list')->see('My first puzzle');
     $this->visit('/puzzles/list')->see('My second puzzle');
     $this->visit('/puzzles/list')->see('My third puzzle');
     $this->visit('/puzzles/list')->see('My fourth puzzle');
     $this->visit('/puzzles/list')->see('My fifth puzzle');
     */
 }
示例#2
0
 public function profile()
 {
     $guesses = Puzzle::leftJoin('puzzle_templates', 'puzzle_templates.id', '=', 'puzzles.puzzle_template_id')->join('puzzle_guesses', 'puzzle_guesses.puzzle_id', '=', 'puzzles.id')->selectRaw('puzzles.slug puzzle_slug, puzzles.name puzzle_name, puzzle_templates.slug template_slug')->where('puzzle_guesses.user_id', $this->id)->orderBy('updated_timestamp_utc', 'desc')->get();
     $puzzles = Puzzle::leftJoin('puzzle_templates', 'puzzle_templates.id', '=', 'puzzles.puzzle_template_id')->where('puzzles.user_id', $this->id)->where('puzzles.active', 1)->whereNull('deleted_timestamp_utc')->selectRaw('puzzles.slug puzzle_slug, puzzles.name puzzle_name, puzzle_templates.slug template_slug')->get();
     $templates = PuzzleTemplate::where('active', 1)->where(function ($query) {
         $query->where('user_id', $this->id)->orWhereRaw('id in (select puzzle_template_id from puzzles where user_id = ?)', array($this->id))->orWhereRaw('id in (select puzzles.puzzle_template_id from puzzle_guesses inner join puzzles on puzzle_guesses.puzzle_id = puzzles.id where puzzle_guesses.user_id = ?)', array($this->id));
     })->select('id', 'height', 'width', 'slug', 'name', 'symmetrical', 'user_id')->with('puzzleTemplateSquares')->get();
     foreach ($templates as $template_key => $t) {
         foreach ($t->puzzleTemplateSquares as $k => $s) {
             $square = $templates[$template_key]->puzzleTemplateSquares[$k];
             $row = $square->row;
             $col = $square->col;
             $templates[$template_key]->puzzleTemplateSquares[$row . '-' . $col] = $square;
             unset($templates[$template_key]->puzzleTemplateSquares[$row . '-' . $col]->row);
             unset($templates[$template_key]->puzzleTemplateSquares[$row . '-' . $col]->col);
             unset($templates[$template_key]->puzzleTemplateSquares[$row . '-' . $col]->puzzle_template_id);
             unset($templates[$template_key]->puzzleTemplateSquares[$row . '-' . $col]->id);
             unset($templates[$template_key]->puzzleTemplateSquares[$k]);
         }
         $templates[$t->slug] = $templates[$template_key];
         $templates[$t->slug]['clue_squares'] = $t->clueSquares();
         unset($templates[$template_key]);
     }
     return array('username' => $this->username, 'user_id' => $this->id, 'name' => $this->name, 'profile_image_base_url' => isset($this->twitter->profile_image_url) ? str_replace("_normal.jpeg", "", $this->twitter->profile_image_url) : "", 'templates' => $templates, 'puzzles' => $puzzles, 'attempted_puzzles' => $guesses, 'twitter_handle' => isset($this->twitter->screen_name) ? $this->twitter->screen_name : "");
 }
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testViewingMyIncompletePuzzles()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'gregorypolanco']);
     $name = $faker->sentence;
     $width = 10;
     $height = 10;
     $blackSquares = array();
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $puzzleSquares = array();
     $clues = array();
     $args = array('name' => 'My first puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle1 = Puzzle::create($args);
     $args = array('name' => 'My second puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle2 = Puzzle::create($args);
     $args = array('name' => 'My third puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle3 = Puzzle::create($args);
     $args = array('name' => 'My fourth puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle4 = Puzzle::create($args);
     $args = array('name' => 'My fifth puzzle', 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle5 = Puzzle::create($args);
     $this->actingAs($user)->visit('/incomplete_puzzles')->see('My first puzzle');
     $this->actingAs($user)->visit('/incomplete_puzzles')->see('My second puzzle');
     $this->actingAs($user)->visit('/incomplete_puzzles')->see('My third puzzle');
     $this->actingAs($user)->visit('/incomplete_puzzles')->see('My fourth puzzle');
     $this->actingAs($user)->visit('/incomplete_puzzles')->see('My fifth puzzle');
 }
示例#4
0
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testViewingAClue()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'jondoe1']);
     $name = $faker->sentence;
     $width = $faker->numberBetween(5, 20);
     $height = $faker->numberBetween(5, 20);
     $blackSquares = array();
     for ($i = 1; $i < $faker->numberBetween(2, 20); $i++) {
         $blackSquares[] = $faker->numberBetween(1, $width) . '-' . $faker->numberBetween(1, $height);
     }
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $user->puzzleTemplates()->save($puzzleTemplate);
     $name = $faker->sentence;
     $puzzle_squares = array();
     $ordinal = 1;
     $clues = array();
     for ($row = 1; $row <= $height; $row++) {
         for ($col = 1; $col <= $width; $col++) {
             if (!in_array($row . '-' . $col, $puzzleTemplate->blackSquares())) {
                 $letter = substr($faker->word, 0, 1);
                 $puzzle_squares[] = array('row' => $row, 'col' => $col, 'letter' => $letter, 'square_type' => 'white');
             }
             if ($row == 1 || in_array($row - 1 . '-' . $col, $puzzleTemplate->blackSquares())) {
                 //needs a down clue
                 $clue = new Clue();
                 $clue->clue = $faker->sentence;
                 $clue->ordinal = $ordinal;
                 $clue->direction = 'down';
                 $clues[] = $clue;
             }
             if ($col == 1 || in_array($row . '-' . ($col - 1), $puzzleTemplate->blackSquares())) {
                 //needs an across clue
                 $clue = new Clue();
                 $clue->clue = $faker->sentence;
                 $clue->ordinal = $ordinal;
                 $clue->direction = 'across';
                 $clues[] = $clue;
             }
             if ($row == 1 || in_array($row - 1 . '-' . $col, $puzzleTemplate->blackSquares()) || $col == 1 || in_array($row . '-' . ($col - 1), $puzzleTemplate->blackSquares())) {
                 $ordinal++;
             }
         }
     }
     $args = array('name' => $name, 'user_id' => $user->id, 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzle_squares, 'clues' => $clues);
     $puzzle = Puzzle::create($args);
     $user->puzzles()->save($puzzle);
     $clue_str = $faker->sentence;
     $args = array('puzzle_slug' => $puzzle->slug, 'clue' => $clue_str, 'ordinal' => 1, 'direction' => 'across');
     $clue = Clue::replace($args);
     $this->assertEquals($clue->clue, $clue_str);
     $this->assertEquals($clue->puzzle_id, $puzzle->id);
     $this->visit('/puzzles/' . $puzzle->slug)->see($clue_str);
 }
示例#5
0
 public function testAPuzzleTemplateCanBeCreated()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'janedoe2']);
     $name = $faker->sentence;
     $width = $faker->numberBetween(5, 20);
     $height = $faker->numberBetween(5, 20);
     $blackSquares = array();
     for ($i = 1; $i < $faker->numberBetween(2, 20); $i++) {
         $blackSquares[] = $faker->numberBetween(1, $width) . '-' . $faker->numberBetween(1, $height);
     }
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $this->assertEquals($puzzleTemplate->name, $name);
     $this->assertEquals($puzzleTemplate->width, $width);
     $this->assertEquals($puzzleTemplate->height, $height);
 }
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testViewingAPuzzleTemplate()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'jondoe']);
     $name = $faker->sentence;
     $width = $faker->numberBetween(5, 20);
     $height = $faker->numberBetween(5, 20);
     $blackSquares = array();
     for ($i = 1; $i < $faker->numberBetween(2, 20); $i++) {
         $blackSquares[] = $faker->numberBetween(1, $width) . '-' . $faker->numberBetween(1, $height);
     }
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $user->puzzleTemplates()->save($puzzleTemplate);
     //Disable this test because mysqlite doesn't like 'from_unixtime' or 'concat' :(
     //$this->visit('/puzzle_templates/'.$puzzleTemplate->slug)->see($name);
 }
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testViewingAPuzzle()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'krisbryant']);
     $name = $faker->sentence;
     $width = $faker->numberBetween(5, 20);
     $height = $faker->numberBetween(5, 20);
     $blackSquares = array();
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $user->puzzleTemplates()->save($puzzleTemplate);
     $name = $faker->sentence;
     $puzzleSquares = array();
     $clues = array();
     $args = array('name' => $name, 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle = Puzzle::create($args);
     $this->visit('/puzzles/' . $puzzle->slug)->see($name);
 }
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testViewingSuggestionsForASquare()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'krisbryant']);
     $name = $faker->sentence;
     $width = 10;
     $height = 10;
     $blackSquares = array();
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $user->puzzleTemplates()->save($puzzleTemplate);
     $name = $faker->sentence;
     $firstword = "st";
     $puzzleSquares = array();
     for ($k = 0; $k < strlen($firstword); $k++) {
         $puzzleSquares[] = array('row' => 1, 'col' => $k + 1, 'letter' => substr($firstword, $k, 1), 'square_type' => 'white');
     }
     $clues = array();
     $args = array('name' => $name, 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle = Puzzle::create($args);
     $this->seed();
     //Populate the words and letters tables
     $this->actingAs($user)->visit('/puzzle_squares/suggestion/' . $puzzle->slug . "/1/3")->see("r");
 }
示例#9
0
 public static function findActive()
 {
     $pts = PuzzleTemplate::leftjoin('users', 'users.id', '=', 'puzzle_templates.user_id')->selectRaw(self::SELECT_RAW)->where('puzzle_templates.active', 1)->get();
     foreach ($pts as $k => $pt) {
         $pts[$k]->blackSquares = $pt->blackSquares();
         $pts[$k]->clueSquares = $pt->clueSquares();
         unset($pts[$k]->id);
     }
     return $pts;
 }
示例#10
0
 public function getPuzzleTemplate($slug)
 {
     return PuzzleTemplate::findBySlug($slug);
 }
示例#11
0
 public function testGuessingASquare()
 {
     $faker = Faker\Factory::create();
     $user_creator = factory(User::class)->create(['username' => 'jaimegarcia']);
     $user_guesser = factory(User::class)->create(['username' => 'wilmyers']);
     $name = "puzzle template";
     $width = 10;
     $height = 10;
     $blackSquares = array();
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user_creator->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $user_creator->puzzleTemplates()->save($puzzleTemplate);
     $name = "my puzzle";
     $firstword = "st";
     $puzzleSquares = array();
     for ($row = 1; $row <= 10; $row++) {
         for ($col = 1; $col <= 10; $col++) {
             $puzzleSquares[] = array('row' => $row, 'col' => $col, 'letter' => 'a', 'square_type' => 'white');
         }
     }
     $clues = array();
     $args = array('name' => $name, 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user_creator->id);
     $puzzle = Puzzle::create($args);
     $puzzle->activate();
     $guess = "x";
     $args = array('puzzle_slug' => $puzzle->slug, 'row' => 1, 'col' => 1, 'letter' => $guess, 'user_id' => $user_guesser->id);
     $pgs = PuzzleGuessSquare::replace($args);
     $this->actingAs($user_guesser)->visit('/puzzles/' . $puzzle->slug)->see($guess);
 }
示例#12
0
 public function testActivatingAPuzzle()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'anthonyrizzo']);
     $name = $faker->sentence;
     $width = 5;
     $height = 5;
     $blackSquares = array('1-1', '5-5');
     $args = array('name' => $name, 'width' => $width, 'height' => $height, 'blackSquares' => $blackSquares, 'user_id' => $user->id);
     $puzzleTemplate = PuzzleTemplate::create($args);
     $user->puzzleTemplates()->save($puzzleTemplate);
     $name = $faker->sentence;
     $puzzleSquares = array();
     $clues = array();
     $args = array('name' => $name, 'puzzle_template_id' => $puzzleTemplate->id, 'puzzle_squares' => $puzzleSquares, 'clues' => $clues, 'user_id' => $user->id);
     $puzzle = Puzzle::create($args);
     $firstword = "shop";
     $secondword = "shove";
     $thirdword = "wanes";
     $fourthword = "arent";
     $fifthword = "beds";
     for ($k = 0; $k < strlen($firstword); $k++) {
         $args = array('row' => 1, 'col' => $k + 2, 'letter' => substr($firstword, $k, 1), 'puzzle_id' => $puzzle->id);
         PuzzleSquare::replace($args);
     }
     for ($k = 0; $k < strlen($secondword); $k++) {
         $args = array('row' => 2, 'col' => $k + 1, 'letter' => substr($secondword, $k, 1), 'puzzle_id' => $puzzle->id);
         PuzzleSquare::replace($args);
     }
     for ($k = 0; $k < strlen($thirdword); $k++) {
         $args = array('row' => 3, 'col' => $k + 1, 'letter' => substr($thirdword, $k, 1), 'puzzle_id' => $puzzle->id);
         PuzzleSquare::replace($args);
     }
     for ($k = 0; $k < strlen($fourthword); $k++) {
         $args = array('row' => 4, 'col' => $k + 1, 'letter' => substr($fourthword, $k, 1), 'puzzle_id' => $puzzle->id);
         PuzzleSquare::replace($args);
     }
     for ($k = 0; $k < strlen($fifthword); $k++) {
         $args = array('row' => 5, 'col' => $k + 1, 'letter' => substr($fifthword, $k, 1), 'puzzle_id' => $puzzle->id);
         PuzzleSquare::replace($args);
     }
     $clue_str = $faker->sentence;
     $across_clues = array(array('ordinal' => 1, 'clue' => 'Woodworking locale'), array('ordinal' => 5, 'clue' => 'Forcefully move'), array('ordinal' => 6, 'clue' => 'Lessens'), array('ordinal' => 7, 'clue' => '"I\'m right, _____ I?'), array('ordinal' => 8, 'clue' => 'Places for flowers'));
     $down_clues = array(array('ordinal' => 1, 'clue' => 'Unit of stock'), array('ordinal' => 2, 'clue' => 'Sharpened (as skills)'), array('ordinal' => 3, 'clue' => 'Baking appliances'), array('ordinal' => 4, 'clue' => 'Insect'), array('ordinal' => 5, 'clue' => 'Gently Brush'));
     foreach ($across_clues as $clue) {
         $args = array('puzzle_slug' => $puzzle->slug, 'clue' => $clue['clue'], 'ordinal' => $clue['ordinal'], 'direction' => 'across');
         $clue = Clue::replace($args);
     }
     foreach ($down_clues as $clue) {
         $args = array('puzzle_slug' => $puzzle->slug, 'clue' => $clue['clue'], 'ordinal' => $clue['ordinal'], 'direction' => 'down');
         $clue = Clue::replace($args);
     }
     $ret = $puzzle->activate($user);
     $this->assertEquals($puzzle->active, 1);
 }