[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> pageutils_sectionid.test.php (source)

   1  <?php
   2  
   3  class sectionid_test extends Dokuwikitest
   4  {
   5      /**
   6       * DataProvider
   7       *
   8       * @return Generator|array
   9       * @see testSectionidsAreUnique
  10       */
  11      public function provideTestData(){
  12          // Each test case represents a sequence of sections title
  13          return [
  14              [['A', 'A', 'A1']],
  15              [['A', 'A1', 'A']]
  16          ];
  17      }
  18  
  19      /**
  20       * @dataProvider provideTestData
  21       * @param array $titles
  22       */
  23      function testSectionidsAreUnique($titles)
  24      {
  25          $check = array();
  26          $alreadyGeneratedIds = array();
  27          foreach($titles as $title){
  28              $newId = sectionID($title, $check);
  29              $this->assertNotContains($newId, $alreadyGeneratedIds, "id $newId has been generated twice. The 2nd time it was for the title $title");
  30              $alreadyGeneratedIds []= $newId;
  31          }
  32      }
  33  
  34      /**
  35       * The convention in the code is to pass $check=false when we're not interested in having
  36       * unique sectionID. This test ensures that this type of call is correctly handled
  37       */
  38      function testSectionIDCanBeCalledWithNonArrayCheck(){
  39          $check = false;
  40          $this->assertEquals("abc", sectionID("abc", $check), "Passing \$check=false shouldn't lead to an error");
  41          $this->assertEquals("abc", sectionID("abc", $check), "Passing \$check=false shouldn't try to deduplicate id");
  42      }
  43  }