public function grade(CodingExecutionResult $result)
 {
     $expected = 'our pets are purrfectly pawesome!';
     $result->assertInputContains('index.php', 'strrev(');
     $result->assertInputContains('index.php', 'strtolower(');
     $result->assertOutputContains($expected);
 }
 public function grade(CodingExecutionResult $result)
 {
     $expected = 'Puppy';
     $result->assertOutputContains($expected);
     $result->assertElementContains('h2', $expected);
     $result->assertInputContains('homepage.twig', 'whatIWantForXmas');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'file_get_contents');
     $result->assertInputContains('index.php', 'json_decode');
     $result->assertElementContains('h3', 'Bacon Bone');
     $result->assertElementContains('h4', 'Bacon-colored');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertElementContains('h3', 'Bacon Bone');
     $result->assertElementContains('h3', 'Tennis Ball');
     $result->assertElementContains('h4', 'Bacon-colored');
     $result->assertElementContains('h4', 'Yellow');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'if');
     $result->assertElementContains('h4', 'Surprise Color');
     $result->assertElementContains('h4', 'Yellow', 'The Tennis ball is printing as `Surprise Color!`, but it *should* be `Yellow`. There\'s a more subtle mistake in the first part of the `if` statement...');
     $result->assertElementContains('h4', 'no color');
 }
 public function grade(CodingExecutionResult $result)
 {
     $expected = 'I luv puppies';
     $result->assertInputContains('index.php', 'echo');
     $result->assertOutputContains($expected);
     $result->assertElementContains('h2', $expected);
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'if');
     $result->assertElementContains('h4', 'Yellow');
     $result->assertElementContains('h4', 'Multiple Colors');
     $result->assertElementContains('h4', 'no color');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertFunctionExists('get_great_pet_toys');
     $result->assertInputContains('lib/functions.php', 'get_great_pet_toys(');
     $result->assertInputContains('index.php', 'require');
     $result->assertElementContains('h3', 'Bacon Bone');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('new_toy.php', '$_POST');
     $result->assertVariableEquals('name', 'Fluffy Pig Stuffed Animal');
     $result->assertVariableEquals('description', 'Your dog will *love* to chew and destroy this adorable pig!');
     $result->assertInputContains('new_toy.php', 'var_dump');
 }
 public function grade(CodingExecutionResult $result)
 {
     $expected = 'I luv kittens';
     $result->assertOutputContains($expected);
     $result->assertElementContains('h2', $expected);
     $result->assertVariableEquals('airpupTag', $expected);
     $result->assertInputContains('index.php', 'echo');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'if');
     $result->assertInputContains('index.php', 'array_key_exists');
     // make sure they're still printing
     $result->assertOutputContains('no color', 'The `Bacon Bone` doesn\'t have a color, so it *should* say "no color" for that toy.');
     $result->assertElementContains('h4', 'Yellow');
 }
 public function grade(CodingExecutionResult $result)
 {
     // sanity checks to make sure they didn't just clear the file
     // mostly, we want them to fix the errors
     $expected = 'I luv kittens';
     $result->assertOutputContains($expected);
     $result->assertElementContains('h2', $expected);
     $result->assertElementContains('h2', 2015);
 }
 public function grade(CodingExecutionResult $result)
 {
     $expected = 'I luv puppies';
     $result->assertInputContains('index.php', 'rand(');
     $result->assertOutputContains($expected);
     $text = trim($result->getCrawler()->filter('h3 span')->text());
     if (!is_numeric($text)) {
         throw new GradingException(sprintf('Are you printing the random number inside the span tag? I see "%s"', $text));
     }
     if ($text > 200 || $text < 100) {
         throw new GradingException(sprintf('Make sure the rand() function only returns numbers between 100 and 200', $text));
     }
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('new_toy.php', 'json_encode', 'Use `json_encode()` in `new_toy.php` to encode the toys array before saving it');
     $result->assertInputContains('new_toy.php', 'file_put_contents', 'Use `file_put_contents()` in `new_toy.php` to save the new JSON string');
     $result->assertInputContains('new_toy.php', 'var_dump', '`var_dump()` the file contents of `toys.json` after saving the new toy');
     $result->assertInputContains('new_toy.php', 'get_great_pet_toys', 'Call `get_great_pet_toys()` first to get the existing toys');
     $result->assertOutputContains('Bacon Bone', 'I don\'t see `Bacon Bone` in `toys.json` - double-check that you\'re keeping the original pets, not replacing them entirely.');
     $result->assertOutputContains('Fluffy Pig Stuffed Animal', 'I don\'t see the new "Fluffy Pig" toy in `toys.json`. Are you adding it to the toys array before calling `json_encode()` and saving the file?');
 }
 /**
  * Execute the code and modify the CodingExecutionResult
  *
  * @param string $rootDir Where all the files have been placed
  * @param string $entryPointFilename
  * @param CodingContext $context
  * @param CodingExecutionResult $result
  */
 public function executeCode($rootDir, $entryPointFilename, CodingContext $context, CodingExecutionResult $result)
 {
     // makes all notices/warning into exceptions, which is good!
     Debug::enable();
     $languageError = null;
     extract($context->getVariables());
     ob_start();
     try {
         require $rootDir . '/' . $entryPointFilename;
     } catch (\ErrorException $e) {
         $message = sprintf('%s in %s on line %s', $e->getMessage(), $e->getFile(), $e->getLine());
         $languageError = $message;
     }
     $contents = ob_get_contents();
     ob_end_clean();
     $result->setOutput($contents);
     $result->setLanguageError(ActivityRunner::cleanError($languageError, $rootDir));
     $result->setDeclaredVariables(get_defined_vars());
 }
 /**
  * Execute the code and modify the CodingExecutionResult
  *
  * @param string $rootDir Where all the files have been placed
  * @param string $entryPointFilename
  * @param CodingContext $context
  * @param CodingExecutionResult $result
  */
 public function executeCode($rootDir, $entryPointFilename, CodingContext $context, CodingExecutionResult $result)
 {
     Debug::enable();
     $errorHandler = TwigErrorHandler::register();
     $twig = $this->getTwigEnvironment($rootDir);
     try {
         $output = $twig->render($entryPointFilename, $context->getVariables());
         $result->setOutput($output);
     } catch (TwigException $error) {
         $result->setLanguageError($error->getMessage());
     } catch (\Twig_Error $error) {
         // not doing anything special here... but in the future, we might
         // fetch more information about line numbers, etc
         $result->setLanguageError($error->getMessage());
     } catch (\Exception $error) {
         $result->setLanguageError($error->getMessage());
     }
     $errorHandler->restore();
 }
 public function grade(CodingExecutionResult $result)
 {
     $crawler = $result->getCrawler()->filter('form');
     if (count($crawler) == 0) {
         throw new GradingException('Did you create a `<form>` tag yet?');
     }
     if ($crawler->attr('action') != '/new_toy.php') {
         throw new GradingException('Make sure your form submits to `/new_toy.php`');
     }
     if (strtolower($crawler->attr('method')) != 'post') {
         throw new GradingException('Make sure your form has a `method` attribute on your `form` set to `POST`');
     }
     $form = $crawler->form();
     if (!$form->has('toy_name')) {
         throw new GradingException('I don\'t see any field with `name="toy_name"`');
     }
     if (!$form->has('description')) {
         throw new GradingException('I don\'t see any field with `name="description"`');
     }
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertFunctionExists('get_great_pet_toys');
     $result->assertInputContains('index.php', 'get_great_pet_toys(');
     $result->assertElementContains('h4', 'Yellow');
     $result->assertElementContains('h4', 'Multiple Colors');
     $result->assertElementContains('h3', 'Bacon Bone');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'file_put_contents');
     $result->assertInputContains('index.php', 'doglife.txt');
     $result->assertInputContains('index.php', 'Dogs rule!');
     $result->assertInputContains('index.php', 'file_get_contents');
     $result->assertElementContains('h2', 'Dogs rule!');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertVariableEquals('waggyPig', array('name' => 'Waggy Pig', 'weight' => 10, 'age' => 7, 'bio' => 'Sleepy white fluffy dog'));
     $result->assertElementContains('h2', 'Waggy Pig');
     // help them out - I reversed the order on the elements
     if ($result->getElementText('.age') == '10') {
         throw new GradingException('Careful! Be sure to print the `age` key in the `.age` element and the
             `weight` key in the `.weight` element. You might have them reversed.');
     }
     $result->assertElementContains('.age', 7);
     $result->assertElementContains('.weight', 10);
     $result->assertElementContains('p', 'Sleepy white fluffy dog');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'foreach');
     $result->assertElementContains('h3', 'Kitty');
     $result->assertElementContains('h3', 'Tiger');
     $result->assertElementContains('h3', 'Jay');
     $buttonCount = substr_count($result->getOutput(), '<button>');
     if ($buttonCount == 0) {
         throw new GradingException('Don\'t forget to add a `<button>Schedule me</button>` inside the `foreach` for each walker!');
     }
     if ($buttonCount == 1) {
         throw new GradingException('I only see 1 `<button>` - make sure to include this *inside* the `foreach` loop so that 3 are printed');
     }
     if ($buttonCount != 3) {
         throw new GradingException('There should be 3 `<button>` element exactly');
     }
 }
 public function executeTwig($templateName, CodingContext $context, CodingExecutionResult $codingExecutionResult)
 {
     $errorHandler = TwigErrorHandler::register();
     try {
         $output = $this->getTwigEnvironment()->render($templateName, $context->getVariables());
         $codingExecutionResult->setOutput($output);
     } catch (TwigException $error) {
         $codingExecutionResult->setLanguageError($error->getMessage());
     } catch (\Twig_Error $error) {
         // not doing anything special here... but in the future, we might
         // fetch more information about line numbers, etc
         $codingExecutionResult->setLanguageError($error->getMessage());
     } catch (\Exception $error) {
         $codingExecutionResult->setLanguageError($error->getMessage());
     }
     $errorHandler->restore();
     return $codingExecutionResult;
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', "\$pets[2]['bio']");
     $result->assertElementContains('h1', 'Breakfast is my favorite!');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertVariableEquals('waggyPig[breed]', 'bichon');
     $result->assertInputContains('index.php', '$waggyPig[', 'Add the `breed` key *after* the `$waggyPig` variable is created using the `[\'breed\']` syntax');
     $result->assertElementContains('.breed', 'bichon');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('new_toy.php', '$_SERVER');
     $result->assertInputContains('new_toy.php', 'HTTP_USER_AGENT');
     $result->assertOutputContains('Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'var_dump(');
     $result->assertOutputContains('Kitty', 'Tiger', 'Jay');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertVariableEquals('dogWalkers', array('Kitty', 'Tiger', 'Jay'));
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('layout/header.php', '<html>');
     $result->assertInputContains('layout/footer.php', '</html>');
     $result->assertInputContains('index.php', '$airpupTagLine =', 'Keep the `$airpupTagLine = ...` code inside `index.php`: that\'s code that is used for just *this* page, and shouldn\'t be in the header');
     $result->assertInputContains('index.php', 'require', 'Don\'t forget to require the `header.php` and `footer.php` files in `index.php` so that it still has the nice layout');
     $result->assertOutputContains('<html>', 'Don\'t forget to require the `header.php` file in `aboutUs.php` so that it has the nice layout');
     $result->assertOutputContains('</html>', 'Don\'t forget to require the `footer.php` file in `aboutUs.php` so that it has the nice layout');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('index.php', 'count');
     $result->assertElementContains('h4', 3, 'I don\'t see the number 3 inside the `<h4>` tag. Are you printing the `count()` there?');
 }
 public function grade(CodingExecutionResult $result)
 {
     $result->assertInputContains('functions.php', 'save_toys(', 'Put the `save_toys` function into `functions.php` for organization');
     $result->assertInputContains('new_toy.php', 'save_toys(', 'Be sure to call the `save_toys()` function from within `new_toy.php`');
 }