/** * @todo Implement testFire(). */ public function testFire() { $observer = new EventsTestObserver(); $this->object->addListener('fire', array($observer, 'invoke')); $event = new GenericEvent('dontfire', array('a' => 1, 'b' => 2)); $this->object->dispatch('dontfire'); $this->assertEquals(0, $observer->invoked); $event = new GenericEvent('fire', array('a' => 18, 'b' => 81)); $this->object->dispatch('fire', $event); $this->assertEquals(1, $observer->invoked); $this->assertEquals('81', $observer->event['b']); }
public function testOverringDefaultFunctionalityWithEvents() { $log = new Logger('emails'); // should only have a database handler. $this->assertEquals(count($log->getHandlers()), 1); $this->assertEquals(count(Log::getHandlers()), 2); // this should still have the same stream handler from last test. $handler = new \Monolog\Handler\TestHandler(Logger::CRITICAL, false); $listener = Events::addListener('on_logger_create', function ($event) use($handler) { $logger = $event->getLogger(); $formatter = new \Monolog\Formatter\LineFormatter(); $handler->setFormatter($formatter); $logger->pushHandler($handler); return $logger; }); $log2 = new Logger('transactions'); $log3 = new Logger('testing'); $this->assertEquals(count($log2->getHandlers()), 2); $this->assertEquals(count($log3->getHandlers()), 2); $log2->info('This is a test.'); $log2->debug('This is a test.'); $log3->debug('This is a test.'); $log3->critical("oh boy this is big."); $log3->alert("Everything is broken."); $log3->emergency("Get out of bed."); $db = Database::get(); $r = $db->GetAll('select * from Logs'); $this->assertEquals(count($r), 3); // only the non-critical, non-alert, non-emergency items. $this->assertEquals(count($handler->getRecords()), 3); $records = $handler->getRecords(); $this->assertEquals($records[0]['level'], Logger::CRITICAL); $this->assertEquals($records[1]['level'], Logger::ALERT); $this->assertEquals($records[2]['level'], Logger::EMERGENCY); $this->assertEquals($records[2]['message'], 'Get out of bed.'); $listeners = Events::getListeners('on_logger_create'); Events::removeListener('on_logger_create', $listeners[0]); // AND we pop the stream handler from the previous test Log::popHandler(); }
public function testPagePathEvent() { $blog = self::createPage('Blog'); $post1 = self::createPage('Post', $blog); $pathObject = $post1->getCollectionPathObject(); $this->assertInstanceOf('\\Concrete\\Core\\Page\\PagePath', $pathObject); $this->assertEquals('/blog/post', $pathObject->getPagePath()); Events::addListener('on_compute_canonical_page_path', function ($event) { $parent = Page::getByID($event->getPageObject()->getCollectionParentID()); if ($parent->getCollectionPath() == '/blog') { // strip off the handle $path = substr($event->getPagePath(), 0, strrpos($event->getPagePath(), '/')); $path .= '/year/month/day/'; $path .= $event->getPageObject()->getCollectionHandle(); $event->setPagePath($path); } }); $post2 = self::createPage('Another Post', $blog); $this->assertEquals('/blog/year/month/day/another-post', $post2->getCollectionPath()); $post2Object = Page::getByPath('/blog/year/month/day/another-post'); $this->assertEquals(4, $post2Object->getCollectionID()); $addendum = self::createPage('Addendum', $post2Object); $path = $addendum->getCollectionPathObject(); $this->assertInstanceOf('\\Concrete\\Core\\Page\\PagePath', $path); $this->assertEquals('/blog/year/month/day/another-post/addendum', $path->getPagePath()); $home = Page::getByID(1); $addendum->move($home); $this->assertEquals('/addendum', $addendum->getCollectionPath()); }