|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* micrometa |
|
5
|
|
|
* |
|
6
|
|
|
* @category Jkphl |
|
7
|
|
|
* @package Jkphl\Micrometa |
|
8
|
|
|
* @subpackage Jkphl\Micrometa\Tests\Domain |
|
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
|
10
|
|
|
* @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/*********************************************************************************** |
|
15
|
|
|
* The MIT License (MIT) |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
|
18
|
|
|
* |
|
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
|
21
|
|
|
* the Software without restriction, including without limitation the rights to |
|
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
|
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
|
24
|
|
|
* subject to the following conditions: |
|
25
|
|
|
* |
|
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
27
|
|
|
* copies or substantial portions of the Software. |
|
28
|
|
|
* |
|
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
35
|
|
|
***********************************************************************************/ |
|
36
|
|
|
|
|
37
|
|
|
namespace Jkphl\Micrometa\Tests\Ports; |
|
38
|
|
|
|
|
39
|
|
|
use Jkphl\Micrometa\Ports\Format; |
|
40
|
|
|
use Jkphl\Micrometa\Ports\Item\ItemObjectModelInterface; |
|
41
|
|
|
use Jkphl\Micrometa\Ports\Parser; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Parser tests |
|
45
|
|
|
* |
|
46
|
|
|
* @package Jkphl\Micrometa |
|
47
|
|
|
* @subpackage Jkphl\Micrometa\Tests |
|
48
|
|
|
*/ |
|
49
|
|
|
class ParserTest extends \PHPUnit_Framework_TestCase |
|
50
|
|
|
{ |
|
51
|
|
|
/** |
|
52
|
|
|
* Valid local test HTML document |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
const VALID_HTML_URL = 'http://localhost:1349/valid-test.html'; |
|
57
|
|
|
/** |
|
58
|
|
|
* Valid local test AMP HTML document with JSON-LD |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
const VALID_JSONLD_URL = 'http://localhost:1349/article-json-ld.amp.html'; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Test the LinkRel parser |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testLinkRelParser() |
|
68
|
|
|
{ |
|
69
|
|
|
$parser = new Parser(Format::LINK_REL); |
|
70
|
|
|
$itemObjectModel = $parser(self::VALID_HTML_URL); |
|
71
|
|
|
$this->assertInstanceOf(ItemObjectModelInterface::class, $itemObjectModel); |
|
72
|
|
|
$this->assertEquals(3, count($itemObjectModel->getItems())); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Test the JSON-LD parser |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testJsonLDParser() { |
|
79
|
|
|
$parser = new Parser(Format::JSON_LD); |
|
80
|
|
|
$itemObjectModel = $parser(self::VALID_JSONLD_URL, file_get_contents(dirname(__DIR__).'/Fixture/article-json-ld.amp.html')); |
|
|
|
|
|
|
81
|
|
|
// print_r($itemObjectModel->toObject()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Test the parser facade |
|
86
|
|
|
*/ |
|
87
|
|
|
// public function testParser() |
|
88
|
|
|
// { |
|
89
|
|
|
// $microformatsHtml = \ComposerLocator::getPath('microformats/test').DIRECTORY_SEPARATOR.'tests'. |
|
90
|
|
|
// DIRECTORY_SEPARATOR.'microformats-v2'.DIRECTORY_SEPARATOR.'h-product'.DIRECTORY_SEPARATOR.'aggregate.html'; |
|
91
|
|
|
// $parser = new Parser(Format::MICROFORMATS); |
|
92
|
|
|
// $itemObjectModel = $parser(self::VALID_HTML_URL, file_get_contents($microformatsHtml), Format::ALL); |
|
93
|
|
|
// $this->assertInstanceOf(ItemObjectModelInterface::class, $itemObjectModel); |
|
94
|
|
|
// $this->assertEquals(1, count($itemObjectModel->getItems())); |
|
95
|
|
|
// $item = $itemObjectModel->getFirstItem(); |
|
96
|
|
|
// $this->assertInstanceOf(Item::class, $item); |
|
97
|
|
|
//// $this->assertTrue($item->isOfType('invalid', MicroformatsFactory::MF2_PROFILE_URI.'h-product')); |
|
98
|
|
|
// } |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.