Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Drupal\comment\Tests\Views; use Drupal\Component\Serialization\Json; use..

Decoded Output download

<?php

namespace Drupal\comment\Tests\Views;

use Drupal\Component\Serialization\Json;
use Drupal\comment\Entity\Comment;

/**
 * Tests a comment rest export view.
 *
 * @group comment
 */
class CommentRestExportTest extends CommentTestBase {

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = ['test_comment_rest'];

  /**
   * {@inheritdoc}
   */
  public static $modules = ['node', 'comment', 'comment_test_views', 'rest', 'hal'];

  protected function setUp() {
    parent::setUp();
    // Add another anonymous comment.
    $comment = [
      'uid' => 0,
      'entity_id' => $this->nodeUserCommented->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'subject' => 'A lot, apparently',
      'cid' => '',
      'pid' => $this->comment->id(),
      'mail' => '[email protected]',
      'name' => 'bobby tables',
      'hostname' => 'public.example.com',
    ];
    $this->comment = Comment::create($comment);
    $this->comment->save();

    $user = $this->drupalCreateUser(['access comments']);
    $this->drupalLogin($user);
  }


  /**
   * Test comment row.
   */
  public function testCommentRestExport() {
    $this->drupalGetWithFormat(sprintf('node/%d/comments', $this->nodeUserCommented->id()), 'hal_json');
    $this->assertResponse(200);
    $contents = Json::decode($this->getRawContent());
    $this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
    $this->assertEqual($contents[1]['subject'], 'A lot, apparently');
    $this->assertEqual(count($contents), 2);

    // Ensure field-level access is respected - user shouldn't be able to see
    // mail or hostname fields.
    $this->assertNoText('[email protected]');
    $this->assertNoText('public.example.com');
  }

}
 ?>

Did this file decode correctly?

Original Code

<?php

namespace Drupal\comment\Tests\Views;

use Drupal\Component\Serialization\Json;
use Drupal\comment\Entity\Comment;

/**
 * Tests a comment rest export view.
 *
 * @group comment
 */
class CommentRestExportTest extends CommentTestBase {

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = ['test_comment_rest'];

  /**
   * {@inheritdoc}
   */
  public static $modules = ['node', 'comment', 'comment_test_views', 'rest', 'hal'];

  protected function setUp() {
    parent::setUp();
    // Add another anonymous comment.
    $comment = [
      'uid' => 0,
      'entity_id' => $this->nodeUserCommented->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'subject' => 'A lot, apparently',
      'cid' => '',
      'pid' => $this->comment->id(),
      'mail' => '[email protected]',
      'name' => 'bobby tables',
      'hostname' => 'public.example.com',
    ];
    $this->comment = Comment::create($comment);
    $this->comment->save();

    $user = $this->drupalCreateUser(['access comments']);
    $this->drupalLogin($user);
  }


  /**
   * Test comment row.
   */
  public function testCommentRestExport() {
    $this->drupalGetWithFormat(sprintf('node/%d/comments', $this->nodeUserCommented->id()), 'hal_json');
    $this->assertResponse(200);
    $contents = Json::decode($this->getRawContent());
    $this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
    $this->assertEqual($contents[1]['subject'], 'A lot, apparently');
    $this->assertEqual(count($contents), 2);

    // Ensure field-level access is respected - user shouldn't be able to see
    // mail or hostname fields.
    $this->assertNoText('[email protected]');
    $this->assertNoText('public.example.com');
  }

}

Function Calls

None

Variables

None

Stats

MD5 3af9ac3300376312e2910847bfee4253
Eval Count 0
Decode Time 79 ms