Ejemplo n.º 1
0
 public function testValidate_()
 {
     $item = new Item();
     $changeOp = $this->getMockBuilder('\\Wikibase\\ChangeOp\\ChangeOp')->disableOriginalConstructor()->getMock();
     $changeOp->expects($this->any())->method('validate')->will($this->returnCallback(function (Item $item) {
         // Fail when the label is already set (by a previous apply call).
         return $item->getFingerprint()->hasLabel('en') ? Result::newError(array()) : Result::newSuccess();
     }));
     $changeOp->expects($this->any())->method('apply')->will($this->returnCallback(function (Item $item) {
         $item->setLabel('en', 'Label');
     }));
     $changeOps = new ChangeOps();
     $changeOps->add($changeOp);
     $changeOps->add($changeOp);
     $result = $changeOps->validate($item);
     $this->assertFalse($result->isValid(), 'Validate must fail with this mock');
     $this->assertTrue($item->isEmpty(), 'Item must still be empty');
 }