1 | <?php |
||
17 | class ApprovedDatePropertyAnnotatorTest extends \PHPUnit_Framework_TestCase { |
||
18 | |||
19 | private $databaseLogReader; |
||
20 | |||
21 | protected function setUp(): void { |
||
22 | parent::setUp(); |
||
23 | |||
24 | $this->databaseLogReader = $this->getMockBuilder( '\SMW\ApprovedRevs\DatabaseLogReader' ) |
||
25 | ->disableOriginalConstructor() |
||
26 | ->getMock(); |
||
27 | } |
||
28 | |||
29 | public function testCanConstruct() { |
||
30 | |||
31 | $this->assertInstanceOf( |
||
32 | ApprovedDatePropertyAnnotator::class, |
||
33 | new ApprovedDatePropertyAnnotator( $this->databaseLogReader ) |
||
34 | ); |
||
35 | } |
||
36 | |||
37 | protected static function getDITime( MWTimestamp $time ) { |
||
38 | return new DITime( |
||
39 | DITime::CM_GREGORIAN, |
||
40 | $time->format( 'Y' ), |
||
41 | $time->format( 'm' ), |
||
42 | $time->format( 'd' ), |
||
43 | $time->format( 'H' ), |
||
44 | $time->format( 'i' ) |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | public function testAddAnnotation() { |
||
49 | |||
50 | $now = new MWTimestamp( wfTimestampNow() ); |
||
51 | $time = self::getDITime( $now ); |
||
52 | |||
53 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
||
54 | ->disableOriginalConstructor() |
||
55 | ->getMock(); |
||
56 | |||
57 | $semanticData->expects( $this->once() ) |
||
58 | ->method( 'addPropertyObjectValue' ) |
||
59 | ->with( |
||
60 | $this->anyThing(), |
||
61 | $this->equalTo( $time ) |
||
62 | ); |
||
63 | |||
64 | $annotator = new ApprovedDatePropertyAnnotator( |
||
65 | $this->databaseLogReader |
||
66 | ); |
||
67 | |||
68 | $annotator->setApprovedDate( $now ); |
||
69 | $annotator->addAnnotation( $semanticData ); |
||
70 | } |
||
71 | |||
72 | public function testRemoval() { |
||
73 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
||
74 | ->disableOriginalConstructor() |
||
75 | ->getMock(); |
||
76 | |||
77 | $semanticData->expects( $this->once() ) |
||
78 | ->method( 'removeProperty' ); |
||
79 | |||
80 | $annotator = new ApprovedDatePropertyAnnotator( |
||
81 | $this->databaseLogReader |
||
82 | ); |
||
83 | |||
84 | $annotator->setApprovedDate( false ); |
||
85 | $annotator->addAnnotation( $semanticData ); |
||
86 | } |
||
87 | |||
88 | } |
||
89 |