Open Journal Systems  3.3.0
ValidatorControlledVocabTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('lib.pkp.classes.validation.ValidatorControlledVocab');
19 import('lib.pkp.classes.controlledVocab.ControlledVocab');
20 
22 
26  protected function getMockedDAOs() {
27  return array('ControlledVocabDAO');
28  }
29 
33  public function testValidatorControlledVocab() {
34  // Mock a ControlledVocab object
35  $mockControlledVocab = $this->getMockBuilder(ControlledVocab::class)
36  ->setMethods(array('enumerate'))
37  ->getMock();
38  $mockControlledVocab->setId(1);
39  $mockControlledVocab->setAssocType(ASSOC_TYPE_CITATION);
40  $mockControlledVocab->setAssocId(333);
41  $mockControlledVocab->setSymbolic('testVocab');
42 
43  // Set up the mock enumerate() method
44  $mockControlledVocab->expects($this->any())
45  ->method('enumerate')
46  ->will($this->returnValue(array(1 => 'vocab1', 2 => 'vocab2')));
47 
48  // Mock the ControlledVocabDAO
49  $mockControlledVocabDao = $this->getMockBuilder(ControlledVocabDAO::class)
50  ->setMethods(array('getBySymbolic'))
51  ->getMock();
52 
53  // Set up the mock getBySymbolic() method
54  $mockControlledVocabDao->expects($this->any())
55  ->method('getBySymbolic')
56  ->with('testVocab', ASSOC_TYPE_CITATION, 333)
57  ->will($this->returnValue($mockControlledVocab));
58 
59  DAORegistry::registerDAO('ControlledVocabDAO', $mockControlledVocabDao);
60 
61  $validator = new ValidatorControlledVocab('testVocab', ASSOC_TYPE_CITATION, 333);
62  self::assertTrue($validator->isValid('1'));
63  self::assertTrue($validator->isValid('2'));
64  self::assertFalse($validator->isValid('3'));
65  }
66 }
67 
ValidatorControlledVocabTest\testValidatorControlledVocab
testValidatorControlledVocab()
Definition: ValidatorControlledVocabTest.php:33
ValidatorControlledVocabTest
Test class for ValidatorControlledVocab.
Definition: ValidatorControlledVocabTest.php:21
ValidatorControlledVocabTest\getMockedDAOs
getMockedDAOs()
Definition: ValidatorControlledVocabTest.php:26
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
DAORegistry\registerDAO
static registerDAO($name, $dao)
Definition: DAORegistry.inc.php:40
ValidatorControlledVocab
Validation check that checks if value is within a certain set retrieved from the database.
Definition: ValidatorControlledVocab.inc.php:19