Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add PHPShortTagsCheck unit tests

  • Loading branch information...
commit 45416ff9343bac88ef80d768cbd369146fee2198 1 parent 1aac1ce
@nickdaugherty nickdaugherty authored
Showing with 71 additions and 0 deletions.
  1. +71 −0 tests/checks/test-PHPShortTagsCheck.php
View
71 tests/checks/test-PHPShortTagsCheck.php
@@ -0,0 +1,71 @@
+<?php
+
+class PHPShortTagsTest extends WP_UnitTestCase {
+ protected $_PHPShortTagsCheck;
+
+ public function setUp() {
+ require_once VIP_SCANNER_DIR . '/checks/PHPShortTagsCheck.php';
+
+ $this->_PHPShortTagsCheck = new PHPShortTagsCheck();
+ }
+
+ public function testValidTags() {
+ $input = array(
+ 'php' => array(
+ 'test.php' => '<?php
+
+ echo "doing things";
+
+ ?>
+ '
+ )
+ );
+
+ $result = $this->_PHPShortTagsCheck->check( $input );
+
+ $errors = $this->_PHPShortTagsCheck->get_errors();
+
+ $error_slugs = wp_list_pluck( $errors, 'slug' );
+
+ $this->assertNotContains( 'php-shorttags', $error_slugs );
+ }
+
+ public function testOpeningShortTags() {
+ $input = array(
+ 'php' => array(
+ 'test.php' => '<?
+
+ echo "doing things";
+ '
+ )
+ );
+
+ $result = $this->_PHPShortTagsCheck->check( $input );
+
+ $errors = $this->_PHPShortTagsCheck->get_errors();
+
+ $error_slugs = wp_list_pluck( $errors, 'slug' );
+
+ $this->assertContains( 'php-shorttags', $error_slugs );
+ }
+
+ public function testOutputShortTags() {
+ $input = array(
+ 'php' => array(
+ 'test.php' => '
+ $foo = "bar";
+
+ <?=$foo; ?>
+ '
+ )
+ );
+
+ $result = $this->_PHPShortTagsCheck->check( $input );
+
+ $errors = $this->_PHPShortTagsCheck->get_errors();
+
+ $error_slugs = wp_list_pluck( $errors, 'slug' );
+
+ $this->assertContains( 'php-shorttags', $error_slugs );
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.