/** * Test the display() function * * @return void */ public function testDisplay() { // Setup $content = 'anything'; // Test display() with all null params $this->handler = new RDFa(); $this->assertEquals($this->handler->display(), ''); // Test if the params are reseted after the display() function $this->handler->setType('Article')->content($content)->property('name')->fallback('Thing', 'url')->display(); $this->assertNull($this->handler->getFallbackProperty()); $this->assertNull($this->handler->getFallbackType()); $this->assertNull($this->handler->getProperty()); $this->assertNull($this->handler->getContent()); // Test for a simple display $response = $this->handler->property('url')->display(); $this->assertEquals($response, "property='url'"); // Test for a simple display with $content $response = $this->handler->property('url')->content($content)->display(); $this->assertEquals($response, "<span property='url'>{$content}</span>"); // Test for a simple display if the $content is empty '' $response = $this->handler->enable(true)->content('')->property('name')->display(); $this->assertEquals($response, "<span property='name'></span>"); // Test for a simple 'nested' display $response = $this->handler->property('author')->display(); $this->assertEquals($response, "property='author' vocab='https://schema.org' typeof='Organization'"); // Test for a 'nested' display with $content $response = $this->handler->property('author')->content($content)->display(); $this->assertEquals($response, "<span property='author' vocab='https://schema.org' typeof='Organization'>{$content}</span>"); // Test for a 'nested' display with $content and $Fallback $response = $this->handler->fallback('Person', 'name')->property('author')->content($content)->display(); $this->assertEquals($response, "<span property='author' vocab='https://schema.org' typeof='Person'><span property='name'>{$content}</span></span>"); // Test for a 'nested' display with $Fallback and without $content $response = $this->handler->fallback('Person', 'name')->property('author')->display(); $this->assertEquals($response, "property='author' vocab='https://schema.org' typeof='Person' property='name'"); // Test for a 'meta' display without $content $response = $this->handler->property('datePublished')->display(); $this->assertEquals($response, "property='datePublished'"); // Test for a 'meta' display with $content $content = '01 January 2011'; $response = $this->handler->property('datePublished')->content($content)->display(); $this->assertEquals($response, "<meta property='datePublished' content='{$content}'/>{$content}"); // Test for a 'meta' display with human $content and $machineContent $machineContent = "2011-01-01T00:00:00+00:00"; $response = $this->handler->property('datePublished')->content($content, $machineContent)->display(); $this->assertEquals($response, "<meta property='datePublished' content='{$machineContent}'/>{$content}"); // Test when if fallbacks that the library returns an empty string as specified $response = $this->handler->content('en-GB')->property('doesNotExist')->display('meta', true); $this->assertEquals($response, ''); // Test if the library is disabled $response = $this->handler->enable(false)->content($content)->fallback('Article', 'about')->property('datePublished')->display(); $this->assertEquals($response, $content); // Test if the library is disabled and if it have a $content it must return an empty string $response = $this->handler->enable(false)->content('en-GB')->property('inLanguage')->fallback('Language', 'name')->display('meta', true); $this->assertEquals($response, ''); // Test if the params are reseted after display(), if the library is disabled $this->assertNull($this->handler->getFallbackProperty()); $this->assertNull($this->handler->getFallbackType()); $this->assertNull($this->handler->getProperty()); $this->assertNull($this->handler->getContent()); }
/** * Test the display() function * * @return void * * @since 3.2 */ public function testDisplay() { // Setup $content = 'anything'; // Test display() with all null params $this->handler = new JMicrodata(); $this->assertEquals($this->handler->display(), ''); // Test if the params are reseted after display() $this->handler->setType('Article')->content($content)->property('name')->fallback('Thing', 'url')->display(); $this->assertNull($this->handler->getFallbackProperty()); $this->assertNull($this->handler->getFallbackType()); $this->assertNull($this->handler->getProperty()); $this->assertEmpty($this->handler->getContent()); // Test for a simple display $responce = $this->handler->property('url')->display(); $this->assertEquals($responce, "itemprop='url'"); // Test for a simple display with content $responce = $this->handler->property('url')->content($content)->display(); $this->assertEquals($responce, "<span itemprop='url'>{$content}</span>"); // Test for a simple display if the content is empty '' $responce = $this->handler->enable(true)->content('')->property('name')->display(); $this->assertEquals($responce, "<span itemprop='name'></span>"); // Test for a simple nested display $responce = $this->handler->property('author')->display(); $this->assertEquals($responce, "itemprop='author' itemscope itemtype='https://schema.org/Organization'"); // Test for a nested display with content $responce = $this->handler->property('author')->content($content)->display(); $this->assertEquals($responce, "<span itemprop='author' itemscope itemtype='https://schema.org/Organization'>{$content}</span>"); // Test for a nested display with content and Fallback $responce = $this->handler->fallback('Person', 'name')->property('author')->content($content)->display(); $this->assertEquals($responce, "<span itemprop='author' itemscope itemtype='https://schema.org/Person'><span itemprop='name'>{$content}</span></span>"); // Test for a nested display with Fallback and without content $responce = $this->handler->fallback('Person', 'name')->property('author')->display(); $this->assertEquals($responce, "itemprop='author' itemscope itemtype='https://schema.org/Person' itemprop='name'"); // Test for a meta display without content $responce = $this->handler->property('datePublished')->display(); $this->assertEquals($responce, "itemprop='datePublished'"); // Test for a meta display with content $content = '01 January 2011'; $responce = $this->handler->property('datePublished')->content($content)->display(); $this->assertEquals($responce, "<meta itemprop='datePublished' content='{$content}'/>{$content}"); // Test if the JMicrodata is disabled $responce = $this->handler->enable(false)->content($content)->fallback('Article', 'about')->property('datePublished')->display(); $this->assertEquals($responce, $content); // Test if JMicrodata is disabled and have a $content it must return an empty string $responce = $this->handler->enable(false)->content('en-GB')->property('inLanguage')->fallback('Language', 'name')->display('meta', true); $this->assertEquals($responce, ''); // Test if the params are reseted after display(), if the library is disabled $this->assertNull($this->handler->getFallbackProperty()); $this->assertNull($this->handler->getFallbackType()); $this->assertNull($this->handler->getProperty()); $this->assertNull($this->handler->getContent()); }