@@ -533,4 +533,89 @@ public function testLoadWrappedLines()
533
533
$ this ->assertEquals ("This is some crazy information about a new way of searching for : the stuff. " .
534
534
"Why do this? Because we can. " , $ testbag2 ->getBagInfoByTag ('External-Description ' )[0 ]);
535
535
}
536
+
537
+ /**
538
+ * Repeat the reading of a bag but with CR instead of LF endings.
539
+ *
540
+ * @covers \whikloj\BagItTools\AbstractManifest::loadFile
541
+ *
542
+ * @see \whikloj\BagItTools\Test\ExtendedBagTest::testLoadExtendedBag()
543
+ */
544
+ public function testLoadExtendedCRLineEndings (): void
545
+ {
546
+ $ this ->tmpdir = $ this ->prepareExtendedTestBag ();
547
+ $ this ->switchLineEndingsTo ("\r" );
548
+
549
+ $ bag = Bag::load ($ this ->tmpdir );
550
+ $ this ->assertTrue ($ bag ->isExtended ());
551
+ $ payloads = $ bag ->getPayloadManifests ();
552
+ $ tags = $ bag ->getTagManifests ();
553
+ $ this ->assertCount (1 , $ payloads );
554
+ $ this ->assertCount (1 , $ tags );
555
+ $ this ->assertArrayHasKey ('sha1 ' , $ payloads );
556
+ $ this ->assertArrayHasKey ('sha1 ' , $ tags );
557
+ $ this ->assertCount (2 , $ payloads ['sha1 ' ]->getHashes ());
558
+ $ this ->assertCount (4 , $ tags ['sha1 ' ]->getHashes ());
559
+ $ this ->assertArrayHasKey ('bagit.txt ' , $ tags ['sha1 ' ]->getHashes ());
560
+ $ this ->assertArrayHasKey ('bag-info.txt ' , $ tags ['sha1 ' ]->getHashes ());
561
+ $ this ->assertArrayHasKey ('manifest-sha1.txt ' , $ tags ['sha1 ' ]->getHashes ());
562
+ $ this ->assertArrayHasKey ('alt_tags/random_tags.txt ' , $ tags ['sha1 ' ]->getHashes ());
563
+ $ this ->assertTrue ($ bag ->hasBagInfoTag ('contact-phone ' ));
564
+ $ this ->assertFalse ($ bag ->hasBagInfoTag ('payload-oxum ' ));
565
+ $ this ->assertFalse ($ bag ->hasBagInfoTag ('bag-size ' ));
566
+ }
567
+
568
+ /**
569
+ * Repeat the reading of a bag but with CRLF instead of just LF endings.
570
+ *
571
+ * @covers \whikloj\BagItTools\AbstractManifest::loadFile
572
+ *
573
+ * @see \whikloj\BagItTools\Test\ExtendedBagTest::testLoadExtendedBag()
574
+ */
575
+ public function testLoadExtendedCRLFLineEndings (): void
576
+ {
577
+ $ this ->tmpdir = $ this ->prepareExtendedTestBag ();
578
+ $ this ->switchLineEndingsTo ("\r\n" );
579
+
580
+ $ bag = Bag::load ($ this ->tmpdir );
581
+ $ this ->assertTrue ($ bag ->isExtended ());
582
+ $ payloads = $ bag ->getPayloadManifests ();
583
+ $ tags = $ bag ->getTagManifests ();
584
+ $ this ->assertCount (1 , $ payloads );
585
+ $ this ->assertCount (1 , $ tags );
586
+ $ this ->assertArrayHasKey ('sha1 ' , $ payloads );
587
+ $ this ->assertArrayHasKey ('sha1 ' , $ tags );
588
+ $ this ->assertCount (2 , $ payloads ['sha1 ' ]->getHashes ());
589
+ $ this ->assertCount (4 , $ tags ['sha1 ' ]->getHashes ());
590
+ $ this ->assertArrayHasKey ('bagit.txt ' , $ tags ['sha1 ' ]->getHashes ());
591
+ $ this ->assertArrayHasKey ('bag-info.txt ' , $ tags ['sha1 ' ]->getHashes ());
592
+ $ this ->assertArrayHasKey ('manifest-sha1.txt ' , $ tags ['sha1 ' ]->getHashes ());
593
+ $ this ->assertArrayHasKey ('alt_tags/random_tags.txt ' , $ tags ['sha1 ' ]->getHashes ());
594
+ $ this ->assertTrue ($ bag ->hasBagInfoTag ('contact-phone ' ));
595
+ $ this ->assertFalse ($ bag ->hasBagInfoTag ('payload-oxum ' ));
596
+ $ this ->assertFalse ($ bag ->hasBagInfoTag ('bag-size ' ));
597
+ }
598
+
599
+ /**
600
+ * Switch the line endings of the test extended bag from \r to
601
+ *
602
+ * @param string $newEnding
603
+ * What to switch the line endings to.
604
+ */
605
+ private function switchLineEndingsTo (string $ newEnding ): void
606
+ {
607
+ $ files = [
608
+ "bagit.txt " ,
609
+ "bag-info.txt " ,
610
+ "manifest-sha1.txt " ,
611
+ "tagmanifest-sha1.txt " ,
612
+ ];
613
+ foreach ($ files as $ file ) {
614
+ $ path = $ this ->tmpdir . DIRECTORY_SEPARATOR . $ file ;
615
+ file_put_contents (
616
+ $ path ,
617
+ str_replace ("\n" , $ newEnding , file_get_contents ($ path ))
618
+ );
619
+ }
620
+ }
536
621
}
0 commit comments