public function somethingProvider()
 {
     return array(array('Reply recent change goes to the topic', NS_TOPIC, function ($workflow, $user) {
         $first = PostRevision::create($workflow, $user, 'blah blah', 'wikitext');
         return $first->reply($workflow, $user, 'fofofo', 'wikitext');
     }));
 }
 /**
  * @dataProvider spamProvider
  */
 public function testSpam($message, $expect, $content, $maxLength)
 {
     $title = Title::newFromText('UTPage');
     $user = User::newFromName('127.0.0.1', false);
     $workflow = Workflow::create('topic', $title);
     $topic = PostRevision::create($workflow, $user, 'title content', 'wikitext');
     $reply = $topic->reply($workflow, $user, $content, 'wikitext');
     $spamFilter = new ContentLengthFilter($maxLength);
     $status = $spamFilter->validate($this->getMock('IContextSource'), $reply, null, $title);
     $this->assertEquals($expect, $status->isOK());
 }
 /**
  * There was a bug where all anonymous users got the same
  * user links output, this checks that they are distinct.
  */
 public function testNonRepeatingUserLinksForAnonymousUsers()
 {
     $templating = $this->mockTemplating();
     $user = User::newFromName('127.0.0.1', false);
     $title = Title::newMainPage();
     $workflow = Workflow::create('topic', $title);
     $topicTitle = PostRevision::create($workflow, $user, 'some content', 'wikitext');
     $hidden = $topicTitle->moderate($user, $topicTitle::MODERATED_HIDDEN, 'hide-topic', 'hide and go seek');
     $this->assertContains('Special:Contributions/127.0.0.1', $templating->getUserLinks($hidden), 'User links should include anonymous contributions');
     $hidden = $topicTitle->moderate(User::newFromName('10.0.0.2', false), $topicTitle::MODERATED_HIDDEN, 'hide-topic', 'hide and go seek');
     $this->assertContains('Special:Contributions/10.0.0.2', $templating->getUserLinks($hidden), 'An alternate user should have the correct anonymous contributions');
 }
 public function testSetsRevIdAndPostIdForReplys()
 {
     $state = $this->createState();
     $user = User::newFromName('127.0.0.1', false);
     $title = Title::newMainPage();
     $topicWorkflow = Workflow::create('topic', $title);
     $topicTitle = PostRevision::create($topicWorkflow, $user, 'sing song', 'wikitext');
     $reply = $topicTitle->reply($topicWorkflow, $user, 'fantastic!', 'wikitext');
     $now = time();
     $state->setRevisionTimestamp($reply, $now - 54321);
     $this->assertEquals($now - 54321, $reply->getRevisionId()->getTimestampObj()->getTimestamp(TS_UNIX), 'The first reply revision must have its revision id set appropriatly');
     $this->assertTrue($reply->getPostId()->equals($reply->getRevisionId()), 'The first revision of a reply shares its postId and revId');
 }
 public function testContentLength()
 {
     $content = 'This is a topic title';
     $nextContent = 'Changed my mind';
     $title = Title::newMainPage();
     $user = User::newFromName('127.0.0.1', false);
     $workflow = Workflow::create('topic', $title);
     $topic = PostRevision::create($workflow, $user, $content, 'wikitext');
     $this->assertEquals(0, $topic->getPreviousContentLength());
     $this->assertEquals(mb_strlen($content), $topic->getContentLength());
     $next = $topic->newNextRevision($user, $nextContent, 'wikitext', 'edit-title', $title);
     $this->assertEquals(mb_strlen($content), $next->getPreviousContentLength());
     $this->assertEquals(mb_strlen($nextContent), $next->getContentLength());
 }
 public function testValidateDoesntBlowUp()
 {
     $filter = new ConfirmEdit();
     if (!$filter->enabled()) {
         $this->markTestSkipped('ConfirmEdit is not enabled');
     }
     $user = User::newFromName('127.0.0.1', false);
     $title = Title::newMainPage();
     $workflow = Workflow::create('topic', $title);
     $oldRevision = PostRevision::create($workflow, $user, 'foo', 'wikitext');
     $newRevision = $oldRevision->newNextRevision($user, 'bar', 'wikitext', 'change-type', $title);
     $context = $this->getMock('IContextSource');
     $context->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $status = $filter->validate($context, $newRevision, $oldRevision, $title);
     $this->assertInstanceOf('Status', $status);
     $this->assertTrue($status->isGood());
 }
 /**
  * Creates the objects about to be inserted into storage:
  * * $this->topicWorkflow
  * * $this->topicListEntry
  * * $this->topicTitle
  * * $this->firstPost
  *
  * @throws \MWException
  * @throws \Flow\Exception\FailCommitException
  * @return array Array of [$topicWorkflow, $topicListEntry, $topicTitle, $firstPost]
  */
 protected function create()
 {
     $title = $this->workflow->getArticleTitle();
     $user = $this->context->getUser();
     $topicWorkflow = Workflow::create('topic', $title);
     $topicListEntry = TopicListEntry::create($this->workflow, $topicWorkflow);
     $topicTitle = PostRevision::create($topicWorkflow, $user, $this->submitted['topic'], 'wikitext');
     $firstPost = null;
     if (!empty($this->submitted['content'])) {
         $firstPost = $topicTitle->reply($topicWorkflow, $user, $this->submitted['content'], isset($this->submitted['format']) ? $this->submitted['format'] : 'wikitext');
         $topicTitle->setChildren(array($firstPost));
     }
     return array($topicWorkflow, $topicListEntry, $topicTitle, $firstPost);
 }
 public static function onIRCLineURLProvider()
 {
     // data providers do not run in the same context as the actual test, as such we
     // can't create Title objects because they can have the wrong wikiID.  Instead we
     // pass closures into the test that create the objects within the correct context.
     $newHeader = function (User $user) {
         $title = Title::newFromText('Talk:Hook_test');
         $workflow = Container::get('factory.loader.workflow')->createWorkflowLoader($title)->getWorkflow();
         $header = Header::create($workflow, $user, 'header content', 'wikitext');
         $metadata = array('workflow' => $workflow, 'revision' => $header);
         /** @var OccupationController $occupationController */
         $occupationController = Container::get('occupation_controller');
         // make sure user has rights to create board
         $user->mRights = array_merge($user->getRights(), array('flow-create-board'));
         $occupationController->allowCreation($title, $user);
         $occupationController->ensureFlowRevision(new \Article($title), $workflow);
         Container::get('storage')->put($workflow, $metadata);
         return $metadata;
     };
     $freshTopic = function (User $user) {
         $title = Title::newFromText('Talk:Hook_test');
         $boardWorkflow = Container::get('factory.loader.workflow')->createWorkflowLoader($title)->getWorkflow();
         $topicWorkflow = Workflow::create('topic', $boardWorkflow->getArticleTitle());
         $topicList = TopicListEntry::create($boardWorkflow, $topicWorkflow);
         $topicTitle = PostRevision::create($topicWorkflow, $user, 'some content', 'wikitext');
         $metadata = array('workflow' => $topicWorkflow, 'board-workflow' => $boardWorkflow, 'topic-title' => $topicTitle, 'revision' => $topicTitle);
         /** @var OccupationController $occupationController */
         $occupationController = Container::get('occupation_controller');
         // make sure user has rights to create board
         $user->mRights = array_merge($user->getRights(), array('flow-create-board'));
         $occupationController->allowCreation($title, $user);
         $occupationController->ensureFlowRevision(new \Article($title), $boardWorkflow);
         $storage = Container::get('storage');
         $storage->put($boardWorkflow, $metadata);
         $storage->put($topicWorkflow, $metadata);
         $storage->put($topicList, $metadata);
         $storage->put($topicTitle, $metadata);
         return $metadata;
     };
     $replyToTopic = function (User $user) use($freshTopic) {
         $metadata = $freshTopic($user);
         $firstPost = $metadata['topic-title']->reply($metadata['workflow'], $user, 'ffuts dna ylper', 'wikitext');
         $metadata = array('first-post' => $firstPost, 'revision' => $firstPost) + $metadata;
         Container::get('storage.post')->put($firstPost, $metadata);
         return $metadata;
     };
     return array(array('Freshly created topic', $freshTopic, array('action' => 'history')), array('Reply to topic', $replyToTopic, array('action' => 'history')), array('Edit topic title', function ($user) use($freshTopic) {
         $metadata = $freshTopic($user);
         $title = $metadata['workflow']->getArticleTitle();
         return array('revision' => $metadata['revision']->newNextRevision($user, 'gnihtemos gnihtemos', 'wikitext', 'edit-title', $title)) + $metadata;
     }, array('action' => 'compare-post-revisions')), array('Edit post', function ($user) use($replyToTopic) {
         $metadata = $replyToTopic($user);
         $title = $metadata['workflow']->getArticleTitle();
         return array('revision' => $metadata['revision']->newNextRevision($user, 'IT\'S CAPS LOCKS DAY!', 'wikitext', 'edit-post', $title)) + $metadata;
     }, array('action' => 'compare-post-revisions')), array('Edit board header', function ($user) use($newHeader) {
         $metadata = $newHeader($user);
         $title = $metadata['workflow']->getArticleTitle();
         return array('revision' => $metadata['revision']->newNextRevision($user, 'STILL CAPS LOCKS DAY!', 'wikitext', 'edit-header', $title)) + $metadata;
     }, array('action' => 'compare-header-revisions')), array('Moderate a post', function ($user) use($replyToTopic) {
         $metadata = $replyToTopic($user);
         return array('revision' => $metadata['revision']->moderate($user, $metadata['revision']::MODERATED_DELETED, 'delete-post', 'something about cruise control')) + $metadata;
     }, array('action' => 'history')), array('Moderate a topic', function ($user) use($freshTopic) {
         $metadata = $freshTopic($user);
         return array('revision' => $metadata['revision']->moderate($user, $metadata['revision']::MODERATED_HIDDEN, 'hide-topic', 'adorable kittens')) + $metadata;
     }, array('action' => 'history')));
 }
 /**
  * @param PageImportState $state
  * @param IImportTopic    $importTopic
  * @return TopicImportState
  */
 protected function createTopicState(PageImportState $state, IImportTopic $importTopic)
 {
     $state->logger->info('Importing new topic');
     $topicWorkflow = Workflow::create('topic', $state->boardWorkflow->getArticleTitle());
     $state->setWorkflowTimestamp($topicWorkflow, $this->getFirstRevision($importTopic)->getTimestamp());
     $topicListEntry = TopicListEntry::create($state->boardWorkflow, $topicWorkflow);
     $titleRevisions = $this->importObjectWithHistory($importTopic, function (IObjectRevision $rev) use($state, $topicWorkflow) {
         return PostRevision::create($topicWorkflow, $state->createUser($rev->getAuthor()), $rev->getText(), 'wikitext');
     }, 'edit-title', $state, $topicWorkflow->getArticleTitle());
     $topicState = new TopicImportState($state, $topicWorkflow, end($titleRevisions));
     $topicMetadata = $topicState->getMetadata();
     // This should all match the order in TopicListBlock->commit (board/
     // discussion workflow is inserted before this method is called).
     $state->put($topicWorkflow, $topicMetadata);
     // TLE must be before topic title, otherwise you get an error importing the Topic Title
     // Flow/includes/Data/Index/BoardHistoryIndex.php:
     // No topic list contains topic XXX, called for revision YYY
     $state->put($topicListEntry, $topicMetadata);
     $state->put($titleRevisions, $topicMetadata);
     $state->recordAssociation($topicWorkflow->getId(), $importTopic);
     $state->logger->info('Finished importing topic title with ' . count($titleRevisions) . ' revisions');
     return $topicState;
 }