protected function matchesCriteria(ScribbleFile $scribble, Criteria $criteria) { if (!$scribble) { return false; } if ($criteria->getSlug() !== null) { if ($scribble->getSlug() !== $criteria->getSlug()) { return false; } } // unpublished scribbles only if ($criteria->getMode() === Criteria::MODE_UNPUBLISHED) { if ($scribble->isPublished()) { return false; } } else { if ($criteria->getMode() === Criteria::MODE_ALL) { } else { if (!$scribble->isPublished()) { return false; } } } foreach ($criteria->getTags() as $key => $tag) { if (!$scribble->getTags()->containsKey($key)) { return false; } } if ($criteria->getFind() && !$scribble->find($criteria->getFind())) { return false; } return true; }
public function testLoad() { $file = SCRIBBLE_TESTS_DATA_BASE_DIR_WITH_SUBDIRS . '/markdown-scribble/scribble.md'; $slug = basename(dirname($file)); $scribble = new ScribbleFile(); $scribble->load($file)->setSlug($slug); $this->assertSame('markdown-scribble', $scribble->getSlug()); $this->assertSame('Markdown Scribble', $scribble->getTitle()); $this->assertTrue($scribble->isPublished()); $this->assertTrue($scribble->getTags()->containsKey('markdown')); $this->assertTrue($scribble->getTags()->containsKey('some-other-tag')); $this->assertTrue($scribble->find('heading 3')); $this->assertRegExp('/Heading 3/', $scribble->getContent()); $date = new \DateTime('20120328'); $this->assertSame($date->format('YmdHis'), $scribble->getCreated()->format('YmdHis')); $date = new \DateTime('20120428'); $this->assertSame($date->format('YmdHis'), $scribble->getModified()->format('YmdHis')); // check defaults $this->assertSame('<!--', $scribble->getLeftKeywordDelimiter()); $this->assertSame('-->', $scribble->getRightKeywordDelimiter()); $this->assertSame('<!--', $scribble->getConvertedLeftKeywordDelimiter()); $this->assertSame('-->', $scribble->getConvertedRightKeywordDelimiter()); }