diff --git a/src/Illuminate/Foundation/Testing/Constraints/FormFieldConstraint.php b/src/Illuminate/Foundation/Testing/Constraints/FormFieldConstraint.php deleted file mode 100644 index 89f513b9ff0f..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/FormFieldConstraint.php +++ /dev/null @@ -1,82 +0,0 @@ -selector = $selector; - $this->value = (string) $value; - } - - /** - * Get the valid elements. - * - * Multiple elements should be separated by commas without spaces. - * - * @return string - */ - abstract protected function validElements(); - - /** - * Get the form field. - * - * @param \Symfony\Component\DomCrawler\Crawler $crawler - * @return \Symfony\Component\DomCrawler\Crawler - * - * @throws \PHPUnit_Framework_ExpectationFailedException - */ - protected function field(Crawler $crawler) - { - $field = $crawler->filter(implode(', ', $this->getElements())); - - if ($field->count() > 0) { - return $field; - } - - $this->fail($crawler, sprintf( - 'There is no %s with the name or ID [%s]', - $this->validElements(), $this->selector - )); - } - - /** - * Get the elements relevant to the selector. - * - * @return array - */ - protected function getElements() - { - $name = str_replace('#', '', $this->selector); - - $id = str_replace(['[', ']'], ['\\[', '\\]'], $name); - - return collect(explode(',', $this->validElements()))->map(function ($element) use ($name, $id) { - return "{$element}#{$id}, {$element}[name='{$name}']"; - })->all(); - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasElement.php b/src/Illuminate/Foundation/Testing/Constraints/HasElement.php deleted file mode 100644 index caf080f69fa3..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasElement.php +++ /dev/null @@ -1,99 +0,0 @@ -selector = $selector; - $this->attributes = $attributes; - } - - /** - * Check if the element is found in the given crawler. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return bool - */ - public function matches($crawler) - { - $elements = $this->crawler($crawler)->filter($this->selector); - - if ($elements->count() == 0) { - return false; - } - - if (empty($this->attributes)) { - return true; - } - - $elements = $elements->reduce(function ($element) { - return $this->hasAttributes($element); - }); - - return $elements->count() > 0; - } - - /** - * Determines if the given element has the attributes. - * - * @param \Symfony\Component\DomCrawler\Crawler $element - * @return bool - */ - protected function hasAttributes(Crawler $element) - { - foreach ($this->attributes as $name => $value) { - if (is_numeric($name)) { - if (is_null($element->attr($value))) { - return false; - } - } else { - if ($element->attr($name) != $value) { - return false; - } - } - } - - return true; - } - - /** - * Returns a string representation of the object. - * - * @return string - */ - public function toString() - { - $message = "the element [{$this->selector}]"; - - if (! empty($this->attributes)) { - $message .= ' with the attributes '.json_encode($this->attributes); - } - - return $message; - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasInElement.php b/src/Illuminate/Foundation/Testing/Constraints/HasInElement.php deleted file mode 100644 index 37bd5f105351..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasInElement.php +++ /dev/null @@ -1,78 +0,0 @@ -text = $text; - $this->element = $element; - } - - /** - * Check if the source or text is found within the element in the given crawler. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return bool - */ - public function matches($crawler) - { - $elements = $this->crawler($crawler)->filter($this->element); - - $pattern = $this->getEscapedPattern($this->text); - - foreach ($elements as $element) { - $element = new Crawler($element); - - if (preg_match("/$pattern/i", $element->html())) { - return true; - } - } - - return false; - } - - /** - * Returns the description of the failure. - * - * @return string - */ - protected function getFailureDescription() - { - return sprintf('[%s] contains %s', $this->element, $this->text); - } - - /** - * Returns the reversed description of the failure. - * - * @return string - */ - protected function getReverseFailureDescription() - { - return sprintf('[%s] does not contain %s', $this->element, $this->text); - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasLink.php b/src/Illuminate/Foundation/Testing/Constraints/HasLink.php deleted file mode 100644 index c5c9add3920d..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasLink.php +++ /dev/null @@ -1,116 +0,0 @@ - tag. - * - * @var string|null - */ - protected $url; - - /** - * Create a new constraint instance. - * - * @param string $text - * @param string|null $url - * @return void - */ - public function __construct($text, $url = null) - { - $this->url = $url; - $this->text = $text; - } - - /** - * Check if the link is found in the given crawler. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return bool - */ - public function matches($crawler) - { - $links = $this->crawler($crawler)->selectLink($this->text); - - if ($links->count() == 0) { - return false; - } - - // If the URL is null we assume the developer only wants to find a link - // with the given text regardless of the URL. So if we find the link - // we will return true. Otherwise, we will look for the given URL. - if ($this->url == null) { - return true; - } - - $absoluteUrl = $this->absoluteUrl(); - - foreach ($links as $link) { - $linkHref = $link->getAttribute('href'); - - if ($linkHref == $this->url || $linkHref == $absoluteUrl) { - return true; - } - } - - return false; - } - - /** - * Add a root if the URL is relative (helper method of the hasLink function). - * - * @return string - */ - protected function absoluteUrl() - { - if (! Str::startsWith($this->url, ['http', 'https'])) { - return URL::to($this->url); - } - - return $this->url; - } - - /** - * Returns the description of the failure. - * - * @return string - */ - public function getFailureDescription() - { - $description = "has a link with the text [{$this->text}]"; - - if ($this->url) { - $description .= " and the URL [{$this->url}]"; - } - - return $description; - } - - /** - * Returns the reversed description of the failure. - * - * @return string - */ - protected function getReverseFailureDescription() - { - $description = "does not have a link with the text [{$this->text}]"; - - if ($this->url) { - $description .= " and the URL [{$this->url}]"; - } - - return $description; - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasSource.php b/src/Illuminate/Foundation/Testing/Constraints/HasSource.php deleted file mode 100644 index 9575490e0e7d..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasSource.php +++ /dev/null @@ -1,47 +0,0 @@ -source = $source; - } - - /** - * Check if the source is found in the given crawler. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return bool - */ - protected function matches($crawler) - { - $pattern = $this->getEscapedPattern($this->source); - - return preg_match("/{$pattern}/i", $this->html($crawler)); - } - - /** - * Returns a string representation of the object. - * - * @return string - */ - public function toString() - { - return "the HTML [{$this->source}]"; - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasText.php b/src/Illuminate/Foundation/Testing/Constraints/HasText.php deleted file mode 100644 index 2310ec1eeee9..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasText.php +++ /dev/null @@ -1,47 +0,0 @@ -text = $text; - } - - /** - * Check if the plain text is found in the given crawler. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return bool - */ - protected function matches($crawler) - { - $pattern = $this->getEscapedPattern($this->text); - - return preg_match("/{$pattern}/i", $this->text($crawler)); - } - - /** - * Returns a string representation of the object. - * - * @return string - */ - public function toString() - { - return "the text [{$this->text}]"; - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasValue.php b/src/Illuminate/Foundation/Testing/Constraints/HasValue.php deleted file mode 100644 index 9be8be9c049c..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasValue.php +++ /dev/null @@ -1,74 +0,0 @@ -crawler($crawler); - - return $this->getInputOrTextAreaValue($crawler) == $this->value; - } - - /** - * Get the value of an input or textarea. - * - * @param \Symfony\Component\DomCrawler\Crawler $crawler - * @return string - * - * @throws \PHPUnit_Framework_ExpectationFailedException - */ - public function getInputOrTextAreaValue(Crawler $crawler) - { - $field = $this->field($crawler); - - return $field->nodeName() == 'input' - ? $field->attr('value') - : $field->text(); - } - - /** - * Return the description of the failure. - * - * @return string - */ - protected function getFailureDescription() - { - return sprintf( - 'the field [%s] contains the expected value [%s]', - $this->selector, $this->value - ); - } - - /** - * Returns the reversed description of the failure. - * - * @return string - */ - protected function getReverseFailureDescription() - { - return sprintf( - 'the field [%s] does not contain the expected value [%s]', - $this->selector, $this->value - ); - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/IsChecked.php b/src/Illuminate/Foundation/Testing/Constraints/IsChecked.php deleted file mode 100644 index 94c62c4556d6..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/IsChecked.php +++ /dev/null @@ -1,60 +0,0 @@ -selector = $selector; - } - - /** - * Get the valid elements. - * - * @return string - */ - protected function validElements() - { - return "input[type='checkbox']"; - } - - /** - * Determine if the checkbox is checked. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return bool - */ - public function matches($crawler) - { - $crawler = $this->crawler($crawler); - - return ! is_null($this->field($crawler)->attr('checked')); - } - - /** - * Return the description of the failure. - * - * @return string - */ - protected function getFailureDescription() - { - return "the checkbox [{$this->selector}] is checked"; - } - - /** - * Returns the reversed description of the failure. - * - * @return string - */ - protected function getReverseFailureDescription() - { - return "the checkbox [{$this->selector}] is not checked"; - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/IsSelected.php b/src/Illuminate/Foundation/Testing/Constraints/IsSelected.php deleted file mode 100644 index fdd643c2a9f4..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/IsSelected.php +++ /dev/null @@ -1,130 +0,0 @@ -crawler($crawler); - - return in_array($this->value, $this->getSelectedValue($crawler)); - } - - /** - * Get the selected value of a select field or radio group. - * - * @param \Symfony\Component\DomCrawler\Crawler $crawler - * @return array - * - * @throws \PHPUnit_Framework_ExpectationFailedException - */ - public function getSelectedValue(Crawler $crawler) - { - $field = $this->field($crawler); - - return $field->nodeName() == 'select' - ? $this->getSelectedValueFromSelect($field) - : [$this->getCheckedValueFromRadioGroup($field)]; - } - - /** - * Get the selected value from a select field. - * - * @param \Symfony\Component\DomCrawler\Crawler $select - * @return array - */ - protected function getSelectedValueFromSelect(Crawler $select) - { - $selected = []; - - foreach ($select->children() as $option) { - if ($option->nodeName === 'optgroup') { - foreach ($option->childNodes as $child) { - if ($child->hasAttribute('selected')) { - $selected[] = $this->getOptionValue($child); - } - } - } elseif ($option->hasAttribute('selected')) { - $selected[] = $this->getOptionValue($option); - } - } - - return $selected; - } - - /** - * Get the selected value from an option element. - * - * @param \DOMElement $option - * @return string - */ - protected function getOptionValue(DOMElement $option) - { - if ($option->hasAttribute('value')) { - return $option->getAttribute('value'); - } - - return $option->textContent; - } - - /** - * Get the checked value from a radio group. - * - * @param \Symfony\Component\DomCrawler\Crawler $radioGroup - * @return string|null - */ - protected function getCheckedValueFromRadioGroup(Crawler $radioGroup) - { - foreach ($radioGroup as $radio) { - if ($radio->hasAttribute('checked')) { - return $radio->getAttribute('value'); - } - } - } - - /** - * Returns the description of the failure. - * - * @return string - */ - protected function getFailureDescription() - { - return sprintf( - 'the element [%s] has the selected value [%s]', - $this->selector, $this->value - ); - } - - /** - * Returns the reversed description of the failure. - * - * @return string - */ - protected function getReverseFailureDescription() - { - return sprintf( - 'the element [%s] does not have the selected value [%s]', - $this->selector, $this->value - ); - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/PageConstraint.php b/src/Illuminate/Foundation/Testing/Constraints/PageConstraint.php deleted file mode 100644 index ac7ed6ee3a80..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/PageConstraint.php +++ /dev/null @@ -1,124 +0,0 @@ -html() : $crawler; - } - - /** - * Make sure we obtain the HTML from the crawler or the response. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return string - */ - protected function text($crawler) - { - return is_object($crawler) ? $crawler->text() : strip_tags($crawler); - } - - /** - * Create a crawler instance if the given value is not already a Crawler. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @return \Symfony\Component\DomCrawler\Crawler - */ - protected function crawler($crawler) - { - return is_object($crawler) ? $crawler : new Crawler($crawler); - } - - /** - * Get the escaped text pattern for the constraint. - * - * @param string $text - * @return string - */ - protected function getEscapedPattern($text) - { - $rawPattern = preg_quote($text, '/'); - - $escapedPattern = preg_quote(e($text), '/'); - - return $rawPattern == $escapedPattern - ? $rawPattern : "({$rawPattern}|{$escapedPattern})"; - } - - /** - * Throw an exception for the given comparison and test description. - * - * @param \Symfony\Component\DomCrawler\Crawler|string $crawler - * @param string $description - * @param \SebastianBergmann\Comparator\ComparisonFailure|null $comparisonFailure - * @return void - * - * @throws \PHPUnit_Framework_ExpectationFailedException - */ - protected function fail($crawler, $description, ComparisonFailure $comparisonFailure = null) - { - $html = $this->html($crawler); - - $failureDescription = sprintf( - "%s\n\n\nFailed asserting that %s", - $html, $this->getFailureDescription() - ); - - if (! empty($description)) { - $failureDescription .= ": {$description}"; - } - - if (trim($html) != '') { - $failureDescription .= '. Please check the content above.'; - } else { - $failureDescription .= '. The response is empty.'; - } - - throw new FailedExpection($failureDescription, $comparisonFailure); - } - - /** - * Get the description of the failure. - * - * @return string - */ - protected function getFailureDescription() - { - return 'the page contains '.$this->toString(); - } - - /** - * Returns the reversed description of the failure. - * - * @return string - */ - protected function getReverseFailureDescription() - { - return 'the page does not contain '.$this->toString(); - } - - /** - * Get a string representation of the object. - * - * Placeholder method to avoid forcing definition of this method. - * - * @return string - */ - public function toString() - { - return ''; - } -} diff --git a/src/Illuminate/Foundation/Testing/Constraints/ReversePageConstraint.php b/src/Illuminate/Foundation/Testing/Constraints/ReversePageConstraint.php deleted file mode 100644 index ed60652ffbb4..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/ReversePageConstraint.php +++ /dev/null @@ -1,57 +0,0 @@ -pageConstraint = $pageConstraint; - } - - /** - * Reverse the original page constraint result. - * - * @param \Symfony\Component\DomCrawler\Crawler $crawler - * @return bool - */ - public function matches($crawler) - { - return ! $this->pageConstraint->matches($crawler); - } - - /** - * Get the description of the failure. - * - * This method will attempt to negate the original description. - * - * @return string - */ - protected function getFailureDescription() - { - return $this->pageConstraint->getReverseFailureDescription(); - } - - /** - * Get a string representation of the object. - * - * @return string - */ - public function toString() - { - return $this->pageConstraint->toString(); - } -}