You are here

class RealisticDummyContentTest in Realistic Dummy Content 8

Test Realistic dummy content.

@group realistic_dummy_content

Hierarchy

Expanded class hierarchy of RealisticDummyContentTest

File

api/tests/src/Unit/facade/RealisticDummyContentTest.php, line 19
Define autoload class.

Namespace

Drupal\Tests\realistic_dummy_content_api\Unit\facade
View source
class RealisticDummyContentTest extends UnitTestCase {
  function testIsDummy() {

    // only pure functions should be tested here. The database is not available.
    $user = (object) array();
    $user->mail = 'whatever@example.com.invalid';
    $this
      ->assertTrue(RealisticDummyContent::realistic_dummy_content_api_dummy($user, 'user'), 'User with an email ending in .invalid is considered dummy content');
    $user->mail = 'whatever@example.com';
    $user->devel_generate = TRUE;
    $this
      ->assertTrue(RealisticDummyContent::realistic_dummy_content_api_dummy($user, 'user'), 'User with the devel_generate property set is considered dummy content');
    unset($user->devel_generate);
    $this
      ->assertFalse(RealisticDummyContent::realistic_dummy_content_api_dummy($user, 'user'), 'User with neither an address ending in .invalid nor the devel_generate property set is considered non-dummy');
    $node = (object) array();
    $node->devel_generate = array();
    $this
      ->assertTrue(RealisticDummyContent::realistic_dummy_content_api_dummy($node, 'node'), 'Node with the devel_generate property set to an empty array is considered dummy');
    unset($node->devel_generate);
    $this
      ->assertFALSE(RealisticDummyContent::realistic_dummy_content_api_dummy($node, 'node'), 'Node with the devel_generate not set is considered non-dummy');
  }

  /*
   * Test case for realistic_dummy_content_api.
   */
  public function testSequential() {
    $this
      ->assertSequential(0, 3, 'a', 0);
    $this
      ->assertSequential(0, 3, 'a', 0);
    $this
      ->assertSequential(0, 3, 'b', 1);
    $this
      ->assertSequential(0, 3, 'b', 1);
    $this
      ->assertSequential(0, 3, 'c', 2);
    $this
      ->assertSequential(0, 3, 'c', 2);
    $this
      ->assertSequential(0, 3, 'd', 3);
    $this
      ->assertSequential(0, 2, 'd', 2);
    $this
      ->assertSequential(10, 13, 'd', 10);
    $this
      ->assertSequential(11, 12, 'd', 11);
  }

  /**
   * Helper function to assert that the sequential number generator works.
   *
   * This calls realistic_dummy_content_api_sequential(), making sure that the result
   * is as expected.
   *
   * @param $start
   *   Start number passed to realistic_dummy_content_api_sequential()
   * @param $end
   *   End number passed to realistic_dummy_content_api_sequential()
   * @param $hash
   *   Hash passed to realistic_dummy_content_api_sequential()
   * @param $expected
   *   Expected result which realistic_dummy_content_api_sequential() is expected
   *   to return.
   */
  function assertSequential($start, $end, $hash, $expected) {
    $result = RealisticDummyContent::sequential($start, $end, $hash);
    $this
      ->assertTrue($result == $expected, 'Sequential number is as expected for ' . $start . ', ' . $end . ' with hash ' . $hash . ': [expected] ' . $expected . ' = [result] ' . $result);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RealisticDummyContentTest::assertSequential function Helper function to assert that the sequential number generator works.
RealisticDummyContentTest::testIsDummy function
RealisticDummyContentTest::testSequential public function
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340